Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/src/main/resources/it/unibo/scafi/gradient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ incarnation: scafi3

network-model:
type: ConnectWithinDistance
parameters: [ 5 ]
parameters: [ 0.2 ]

_pool: &program
- time-distribution: 1
Expand All @@ -20,14 +20,14 @@ launcher:

deployments:
- type: Point
parameters: [ -1, -1 ]
parameters: [ 0.1, -0.1 ]
programs:
- *program
contents:
- molecule: source
concentration: true
- type: Grid
parameters: [ 0, 0, 3, 3, 1, 1 ]
parameters: [ 0, 0, 3, 3, 0.1, 0.1 ]
programs:
- *program
contents:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.unibo.scafi.context.common

import it.unibo.scafi.language.common.ConditionalExportLanguage
import it.unibo.scafi.message.OutboundMessage

/**
* Concrete implementation of [[ConditionalExportLanguage]] that delegates to [[OutboundMessage.withRollbackUnless]].
*/
trait ConditionalExportContext extends ConditionalExportLanguage:
self: OutboundMessage =>

override def conditionallyExport[T](keep: T => Boolean)(body: () => T): T =
withRollbackUnless(keep)(body())
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.unibo.scafi.context.xc

import it.unibo.scafi.context.AggregateContext
import it.unibo.scafi.context.common.BranchingContext
import it.unibo.scafi.context.common.{ BranchingContext, ConditionalExportContext }
import it.unibo.scafi.language.xc.{ ExchangeLanguage, FieldBasedSharedData }
import it.unibo.scafi.language.xc.calculus.ExchangeCalculus
import it.unibo.scafi.message.{ CodableFromTo, Import, InboundMessage, OutboundMessage, ValueTree }
Expand All @@ -18,6 +18,7 @@ trait ExchangeAggregateContext[ID](
override val selfMessagesFromPreviousRound: ValueTree,
) extends AggregateContext,
BranchingContext,
ConditionalExportContext,
ExchangeLanguage,
ExchangeCalculus,
FieldBasedSharedData,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package it.unibo.scafi.language.common

/**
* Language capability for conditionally including a sub-computation in the outbound message. When `keep` returns
* `false` the exchange state written by `body` is rolled back so that aligned neighbours do not see this device's state
* for the discarded scope.
*
* This is the scafi3 equivalent of the legacy `exportConditionally` / `vm.newExportStack` + `mergeExport` /
* `discardExport` mechanism, and is the primitive required for correct `spawn` semantics (devices outside a process
* bubble must not pollute alignment inside the bubble).
*/
trait ConditionalExportLanguage:

/**
* Runs `body` and, if `keep(result)` is `false`, rolls back every exchange write produced by `body` so that
* neighbours do not see this device's state for the body's alignment scope. The result is always returned regardless.
*
* @param keep
* predicate on the body's result; `false` ⇒ discard this round's export
* @param body
* the computation to run (and conditionally export)
* @tparam T
* result type
* @return
* the result of `body` whether kept or discarded
*/
def conditionallyExport[T](keep: T => Boolean)(body: () => T): T
end ConditionalExportLanguage
7 changes: 7 additions & 0 deletions scafi3-core/src/main/scala/it/unibo/scafi/libraries/All.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import it.unibo.scafi.utils.boundaries.CommonBoundaries
*/
object All:
export BranchingLibrary.{ *, given }
export CollectionLibrary.{ *, given }
export CommonLibrary.{ *, given }
export ExchangeCalculusLibrary.{ *, given }
export FieldCalculusLibrary.{ *, given }
export FieldUtilsLibrary.{ *, given }
export FoldingLibrary.{ *, given }
export GradientCastLibrary.{ *, given }
export GradientLibrary.{ *, given }
export MathLibrary.{ *, given }
export ProcessLibrary.{ *, given }
export SparseChoiceLibrary.{ *, given }
export StateLibrary.{ *, given }
export TimeLibrary.{ *, given }
export CommonBoundaries.{ *, given }
export cats.syntax.all.*
Loading
Loading