Skip to content

feat: main libraries porting from ScaFi (2)#249

Open
cric96 wants to merge 12 commits into
masterfrom
libraries-porting
Open

feat: main libraries porting from ScaFi (2)#249
cric96 wants to merge 12 commits into
masterfrom
libraries-porting

Conversation

@cric96

@cric96 cric96 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

No description provided.

cric96 and others added 12 commits June 22, 2026 17:46
…ities

Add three minimal sensor capability traits mirroring DistanceSensor:
TimeSensor (deltaTime/timestamp), LagSensor[Lag] (senseLag), and
RandomGenerator (nextRandom), each with a static using-based facade and
unit tests covering facade delegation, SharedData iteration, and random
range/advancement. Implements migration task 01.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…elector, mergeHood

Port the genuinely-missing FieldUtils primitives: argmin/argmax neighbour
selectors (excluding self, with tie-breaking by device id) and key-wise
map merging. Document idiomatic scafi3 replacements for legacy sumHood,
anyHood, everyHood, reifyField, etc. Exported from All.scala. Implements
migration task 02.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t blocks

Implements migration/03: roundCounter, remember, constant, keep, keepTrue,
captureChange, countChanges, goesUp, goesDown, delay, once — all built on
evolve with no captured vars and no default arguments (overloads instead).
Also fixes wildcard import violations in sensor tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…stanceBetween, channel

Implements migration/05: gradientCast, sensorGradientCast, broadcast, sensorBroadcast,
distanceBetween, channel, sensorChannel — all built on share + distanceTo + minHoodSelector.
Uses decomposed approach (separate potential and value shares) to keep Format constraint on
V alone. 8 network-convergence and single-device tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…CastLibrary sensor variants

- TimeLibrary: decay, timer, limitedMemory, cyclicTimer/WithDecay,
  sharedTimerWithDecay[Format,T], clock, impulsesEvery,
  exponentialBackoffFilter, sharedTimer, recentlyTrue, evaporation,
  cyclicFunction — no default args, no TimeUnit, FiniteDuration-safe.
- GradientCastLibrary: replace sensor* prefix functions with same-name
  overloads (gradientCast/broadcast/distanceBetween/channel). Internal
  cross-calls route through a single private castImpl to avoid Scala 3
  overload-resolution failures on path-dependent SharedData types.
- Export TimeLibrary from All.scala.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ibrary (migration/06)

Port hopGradient, crfGradient, bisGradient and flexGradient plus the
meanCounter helper, each with sensor* overloads. Fix an alignment bug
where the source branch returned before neighborValues/senseLag, so the
gradient never propagated and stayed at the Infinity sentinel: hoist all
neighbour communication above the source branch (mirroring distanceTo).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port the collection operator: collect, findParent/findParentOpt, and the
collectCount/Mean/Maps/Sets/IntoSet/ValuesByDevices reducers. Abstract
DeviceId is handled via Ordering/UpperBounded context bounds and a
DeviceId codec for parent-pointer gossip.

Fold neighbour contributions via withoutSelf: the full-field iterator
reflects the live alignment scope (not the field's captured devices) and
collapses neighbours that share a value, which would undercount sums.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…igration/08)

Port the S block: sparseChoice/breakUsingUids/randomUid/minId. Devices
compete via UIDs (random seed, deviceId) latched by evolve; a device
abdicates to a lower nearby UID, "near" decided by distanceTo against
grain. UIDs ordered lexicographically; grain/2 checks done by doubling
to keep D a plain Numeric. neighborValues hoisted above the branch for
alignment; self folded explicitly to avoid the full-field iterator.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ted (migration/10)

Add ConditionalExportLanguage/Context — a snapshot/rollback primitive that gates
exchange-state participation so devices outside a process bubble remain invisible
to in-bubble neighbours (equivalent to legacy vm.newExportStack + mergeExport /
discardExport).  Wire it into ExchangeAggregateContext and OutboundMessage.

ProcessLibrary implements:
  - ProcessStatus enum (External / Bubble / Output / Terminated)
  - ProcessOutput[+R] case class
  - sspawn: dynamic, keyed spatial bubbles with per-key conditionallyExport gating
    and gossip-based handleTermination propagation
  - replicated: time-rotating window of replicates process instances driven by
    sharedTimerWithDecay

14 new tests; 191/191 pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e API ergonomics

- sspawn -> spawn, with the process as a trailing lambda so call sites
  read like a control structure: spawn(generation, args) { key => a => ... }
- add ProcessOutput smart constructors (output/bubble/external/terminated)
- replicated reshaped to replicated(period, replicates, argument)(proc)
  and now evaluates proc unconditionally so replicas stay aligned
- keep the K key and A args as distinct process inputs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Mechanical only: import reordering, line rewrapping, end markers, and
stray-whitespace cleanup. No behavioral changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Shrink ConnectWithinDistance radius (5 -> 0.2) and grid/point spacing to
0.1 so the example deploys in a compact coordinate range.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cric96 cric96 requested a review from nicolasfara June 25, 2026 13:03
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.06494% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.29%. Comparing base (d96fbc8) to head (f9f1fe3).

Files with missing lines Patch % Lines
...it/unibo/scafi/libraries/GradientCastLibrary.scala 58.33% 15 Missing ⚠️
...a/it/unibo/scafi/libraries/CollectionLibrary.scala 66.66% 12 Missing ⚠️
.../src/main/scala/it/unibo/scafi/libraries/All.scala 0.00% 7 Missing ⚠️
...ala/it/unibo/scafi/libraries/GradientLibrary.scala 90.27% 7 Missing ⚠️
...n/scala/it/unibo/scafi/libraries/TimeLibrary.scala 90.90% 4 Missing ⚠️
...cala/it/unibo/scafi/libraries/ProcessLibrary.scala 96.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #249      +/-   ##
==========================================
+ Coverage   59.76%   68.29%   +8.53%     
==========================================
  Files          58       69      +11     
  Lines         758     1066     +308     
  Branches       54       85      +31     
==========================================
+ Hits          453      728     +275     
- Misses        305      338      +33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mergify

mergify Bot commented Jun 25, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant