SlideShare a Scribd company logo
Scafi: Scala with Computational Fields
Roberto Casadei
PhD Student in CS&Eng
roby.casadei@unibo.it
Department of Computer Science and Engineering (DISI)
Alma Mater Studiorum – Università of Bologna
March 6, 2018
R. Casadei Intro SCAFI ACP Analysis 1/69
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
3 Analysis for an Aggregate Computing Platform (ACP)
R. Casadei Intro SCAFI ACP Analysis 2/69
Problem: design/programming CASs
Collective/Complex Adaptive Systems (CASs)
Structure: Environment + (Mobile, Large-scale) Networks of { people + devices }
Global interpretation: embedded devices collectively form a “diffused”
computational system
R. Casadei Intro SCAFI ACP Analysis 3/69
Towards an approach to CAS development
Issues ⇒ approach
• Large-scale ⇒ decentralised coordination
• Situatedness + distributed autonomy ⇒ substantial unpredictability ⇒ self-*
• Complex collective behavior ⇒ good abstractions, layered approach,
compositionality
Shifting the mindset: from local to global
• Declarativeness and the global viewpoint
• Crowd-aware services
• Failure recovery of enterprise services
• Distributed monitoring and reacting (e.g., temperature, fire)
• Expected global behavior vs. traditional device-centric interface
⇒ Aggregate Programming [1]: a paradigm for programming whole aggregates of
devices.
R. Casadei Intro SCAFI ACP Analysis 4/69
Aggregate programming
From the local/device-centric viewpoint to the global/aggregate viewpoint
Aggregate programming: what
Goal: programming the collective behaviour of aggregates (of devices) ⇒
global-to-local
Aggregate programming: how
Prominent approach (generalizing over several prior approaches and strategies [2])
founded on field calculus and self-org patterns
Computational fields as unifying abstraction of local/global viewpoints
R. Casadei Intro SCAFI ACP Analysis 5/69
Aggregate Programming Stack
R. Casadei Intro SCAFI ACP Analysis 6/69
Aggregate (computing) systems & Execution model
Structure ⇒ (network/graph)
A set of devices (aka nodes/points/things).
Each device is able to communicate with a subset of devices known as its
neighbourhood.
Dynamics
Each device is given the same aggregate program and works at async /
partially-sync rounds:
(1) Retrieve context
⇐ Messages from neighbours
⇐ Sensor values
(2) Aggregate program execution
⇒ export (a tree-like repr of computation) + output (result of last expr in body)
(3) Broadcast export to neighbourhood
(4) Execute actuators
R. Casadei Intro SCAFI ACP Analysis 7/69
Aggregate Computing (AC) » how
Repeated execution
Provides reactivity and incremental adaptivity
Broadcast + aligned interaction
Allows the construction of a “local” context for computation
R. Casadei Intro SCAFI ACP Analysis 8/69
Scala Fields Example Howto
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
Scala Fields
Example
Howto: operational instructions
3 Analysis for an Aggregate Computing Platform (ACP)
R. Casadei Intro SCAFI ACP Analysis 9/69
Scala Fields Example Howto
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
Scala Fields
Example
Howto: operational instructions
3 Analysis for an Aggregate Computing Platform (ACP)
Platforms
Requirements
Analysis
Current framework: SCAFI platform
R. Casadei Intro SCAFI ACP Analysis 10/69
Scala Fields Example Howto
SCAFI: Scala with Computational Fields
Goal: bring Aggregate Computing to the field of mainstream software development
What
SCAFI [7] is an integrated framework for building systems with aggregate
programming.
• Scala-internal DSL for expressing aggregate computations.
• Linguistic support + execution support (interpreter/VM)
• Correct, complete, efficient impl. of the Higher-Order Field Calculus
semantics [forte2015]
• Distributed platform for execution of aggregate systems.
• Support for multiple architectural styles and system configurations.
• Actor-based implementation (based on Akka).
R. Casadei Intro SCAFI ACP Analysis 11/69
Scala Fields Example Howto
Some papers about or involving scafi
“Towards Aggregate Programming in Scala”
Casadei and Viroli 2016 [7]
“Simulating Large-scale Aggregate MASs with Alchemist and Scala”
Casadei, Pianini, and Viroli 2016 [5]
“On Execution Platforms for Large-Scale Aggregate Computing”
Viroli, Casadei, and Pianini 2016 [9]
“Programming Actor-based Collective Adaptive Systems”
Casadei and Viroli 2016 [6]
“Combining Trust and Aggregate Computing”
Casadei, Aldini, and Viroli 2018 [4]
R. Casadei Intro SCAFI ACP Analysis 12/69
Scala Fields Example Howto
Computational fields [8]
• (Abstract interpretation) Mapping space-time to computational objects
• (Concrete interpretation) Mapping devices to values: φ : δ →
• “Distributed” data structure working as the global abstraction
• The bridge abstraction between local behavior and global behavior
Discrete systems as an approximation of
spacetime
R. Casadei Intro SCAFI ACP Analysis 13/69
Scala Fields Example Howto
Field/aggregate computations
Global viewpoint
• Aggregate interpretation
• Natural/denotational semantics
• Program: computation over whole fields
• Output (at a given time): system-wide
snapshot of a computational field
• Geometric view: properties of
collections of points
Local viewpoint
• Device-centric interpretation
• Operational semantics
• Program: steps of a single device
• Output (at a given time): latest value
yielded by the device
• Geometric view: properties of a single
point
R. Casadei Intro SCAFI ACP Analysis 14/69
Scala Fields Example Howto
So, what is an aggregate program?
• The global program
– "Local programs" obtained via global-to-local mapping
• May take the form of field calculus programs (in the representation given by
some PL)
– Actually, the field calculus is like FJ for Java, or the lambda calculus for Haskell
• An aggregate program consists of
1) A set of function definitions
2) A body of expressions.
• Example: an aggregate program in SCAFI
class MyProgram extends AggregateProgram with MyAPI {
def isSource = sense[Boolean]("source")
// Entry point for execution
override def main() = gradient(isSource)
}
:– Each device of the aggregate system is given an instance of MyProgram.
– Each device repeatedly runs the main method at async rounds of execution.
R. Casadei Intro SCAFI ACP Analysis 15/69
Scala Fields Example Howto
Computing with fields
Expressing aggregate/field computations in SCAFI
trait Constructs {
def rep[A](init: A)(fun: (A) => A): A
def nbr[A](expr: => A): A
def foldhood[A](init: => A)(acc: (A,A)=>A)(expr: => A): A
def aggregate[A](f: => A): A
// Not primitive, but foundational
def sense[A](name: LSNS): A
def nbrvar[A](name: NSNS): A
def branch[A](cond: => Boolean)(th: => A)(el: => A): A
}
:• Mechanisms for context-sensitiveness: nbr, nbrvar, sense
• Mechanisms for field evolution: rep
• Mechanisms for interaction: nbr
• Mechanisms for field domain restriction and partitioning: aggregate, branch
• Reference formal system: field calculus [forte2015, 8]
R. Casadei Intro SCAFI ACP Analysis 16/69
Scala Fields Example Howto
Simple fields
0
(x)=>x+1
true t<0,1>
Constant, uniform field: 5
– Local view: evaluates to 5 in the context of a single device
– Global view: yields a uniform constant field that holds 5 at any point (i.e., at any
device)
Constant, non-uniform field: mid()
– mid() is a built-in function that returns the ID of the running device
R. Casadei Intro SCAFI ACP Analysis 17/69
Scala Fields Example Howto
rep: dynamically evolving fields
def rep[A](init: A)(fun: (A) => A): A
rep
0
(x)=>x+1
t
v0
t
v1
..
rep(0){(x)=>x+1}
// Initially 0; state is incremented at each round
rep(0){ _+1 }
:
– Notice: the frequency of computation can vary over time and from device to
device
– In general, the resulting field will be heterogeneous in time and space
R. Casadei Intro SCAFI ACP Analysis 18/69
Scala Fields Example Howto
nbr: interaction, communication, observation
def nbr[A](expr: => A): A
def foldhood[A](init: => A)(acc: (A,A)=>A)(expr: => A): A
nbr de
nbr{e}
φd=[d1→v1,..,dn→vn]
– Local view: nbr returns a field from neighbors to their corresponding value of the
given expr e
– Global view: a field of fields
– Needs to be reduced using a *hood operation
– foldhood works by retrieving the value of expr for each neighbour and then
folding over the resulting structure as you’d expect from FP.
foldhood(0)(_+_){ nbr{1} }
:
R. Casadei Intro SCAFI ACP Analysis 19/69
Scala Fields Example Howto
Context-sensitiveness and sensors
Local context:
1) The export of the previous computation
2) Messages received from neighbours
3) Values perceived from the physical/software environment
Sensing
def sense[A](name: LSNS): A
def nbrvar[A](name: NSNS): A
// Query a local sensor
sense[Double]("temperature")
// Compute the maximum distance from neighbours
foldhood(Double.MinValue)(max(_,_)){ // Also: maxHood {...}
nbrvar[Double](NBR_RANGE_NAME)
}
:– nbr queries a local sensor; nbrvar queries a "neighbouring sensor"
("environmental probe")
R. Casadei Intro SCAFI ACP Analysis 20/69
Scala Fields Example Howto
Field domain restriction
Alignment
• Aggregate computations can be represented as a trees
• Device exports are "paths" along these trees
• When two devices execute the same tree node, they are said to be aligned
• Interaction is possible only between aligned devices
Use cases for branch
• Partitioning the space into subspaces performing subcomputations
• Regulating admissible interactions (i.e., further restricting the neighbourhood)
def branch[A](cond: => Boolean)(th: => A)(el: => A): A
branch(sense[Boolean]("flag")){
compute(...) // sub-computation
}{
Double.MaxValue // stable value (i.e., not computing)
}
:
R. Casadei Intro SCAFI ACP Analysis 21/69
Scala Fields Example Howto
Functions
Two kinds of functions in SCAFI:
1) "Normal" Scala functions: serve as units for encapsulating behavior/logic
def foldhoodMinus[A](init: => A)(acc: (A,A) => A)(ex: => A): A =
foldhood(init)(acc){ mux(mid()==nbr(mid())){ init }{ ex } }
def isSource = sense[Boolean]("source")
:
2) First-class "aggregate" functions [forte2015] – which also work as units for
alignment
def aggregate[A](f: => A): A
def branch[A](cond: => Boolean)(th: => A)(el: => A): A =
mux(cond, ()=>aggregate{ th }, ()=>aggregate{ el })()
:
R. Casadei Intro SCAFI ACP Analysis 22/69
Scala Fields Example Howto
Example: the gradient [beal2008fastgradients]
def nbrRange = nbrvar[Double](NBR_RANGE_NAME)
def gradient(source: Boolean): Double =
rep(Double.PositiveInfinity){ distance =>
mux(source) {
0.0
}{
minHood { nbr{distance} + nbrRange }
}
}
:
R. Casadei Intro SCAFI ACP Analysis 23/69
Scala Fields Example Howto
Example: the channel I
Each device is given the same aggregate program:
class ChannelProgram extends AggregateProgram with ChannelAPI {
def main = channel(isSource, isDestination, width)
}
:
def channel(src: Boolean, dest: Boolean, width: Double) =
distTo(src) + distTo(dest) <= distBetween(src,dest) + width
:
R. Casadei Intro SCAFI ACP Analysis 24/69
Scala Fields Example Howto
Example: the channel II
trait ChannelAPI extends Language with Builtins {
def channel(src: Boolean, dest: Boolean, width: Double) =
distanceTo(src) + distanceTo(dest) <= distBetween(src, dest) + width
def G[V:OB](src: Boolean, field: V, acc: V=>V, metric: =>Double): V =
rep( (Double.MaxValue, field) ){ dv =>
mux(src) { (0.0, field) } {
minHoodMinus {
val (d, v) = nbr { (dv._1, dv._2) }
(d + metric, acc(v))
}
}
}._2
def broadcast[V:OB](source: Boolean, field: V): V =
G[V](source, field, x=>x, nbrRange())
def distanceTo(source: Boolean): Double =
G[Double](source, 0, _ + nbrRange(), nbrRange())
def distBetween(source: Boolean, target: Boolean): Double =
broadcast(source, distanceTo(target))
def nbrRange(): Double = nbrvar[Double](NBR_RANGE_NAME)
def isSource = sense[Boolean]("source"); def isDestination = sense[Boolean]("destination
")
}
:
R. Casadei Intro SCAFI ACP Analysis 25/69
Scala Fields Example Howto
Scaling with complexity
General coordination operators [10]
• Gradient-cast: accumulates values “outward” along a gradient starting from
source nodes.
def G[V:OB](src: Boolean, init: V,
acc: V=>V, metric: =>Double): V
:
• Converge-cast: collects data distributed across space “inward” by accumulating
values from edge nodes to sink nodes down a “potential” field.
def C[V:OB](potential: V, acc: (V,V)=>V, local: V, Null: V): V
:
• Time-decay: supports information summarisation across time.
def T[V:Numeric](initial: V, floor: V, decay: V=>V): V
:
• Sparse-choice: supports creation of partitions and selection of sparse subsets
of devices in space
def S(grain: Double, metric: => Double): Boolean
:
R. Casadei Intro SCAFI ACP Analysis 26/69
Scala Fields Example Howto
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
Scala Fields
Example
Howto: operational instructions
3 Analysis for an Aggregate Computing Platform (ACP)
Platforms
Requirements
Analysis
Current framework: SCAFI platform
R. Casadei Intro SCAFI ACP Analysis 27/69
Scala Fields Example Howto
Aggregate Computing (AC) » what
Goal: programming the collective behaviour of aggregates of devices
Main ideas
Macro-level programming with automatic macro-micro bridging
Declarativity
Support for “engineered emergence”
Composition of aggregate behaviour with predictable dynamics
Layers of reusable abstractions
Abstraction from interaction-level and platform-level issues
Inherent adaptivity
Inherent resiliency
Operational flexibility
R. Casadei Intro SCAFI ACP Analysis 28/69
Scala Fields Example Howto
Compositionality in AC: example
trait DistributedSum extends AggregateProgram {
def distribSum(size:Double, metric: =>Double, v:Double): Double =
???
}
trait Broadcast extends BlockG with ... { s: AggregateProgram =>
def broadcast[V: Bounded](src: Boolean, value: V): V =
G(src, value)(x => x, nbrRange)
}
trait SumCollect extends BlockC with ... { s: AggregateProgram =>
def sumCollect(target: Boolean, value: Double): Double =
C(value)(distanceTo(target,nbrRange))(_+_,0)
}
:
Distributed sum
Split the space into regions with grain size
Calculate the mean of field v in each region
Collect the values and the number of nodes in the region
Compute the average
Propagate the computed value
R. Casadei Intro SCAFI ACP Analysis 29/69
Scala Fields Example Howto
Compositionality in AC: example
trait DistributedSum extends AggregateProgram
with BlockG with BlockC with BlockS
with Broadcast with SumCollect with Utilities
{
def distribSum(size:Double, metric: =>Double, v:Double): Double = {
val leaders = S(size, metric)
???
}
}
:
R. Casadei Intro SCAFI ACP Analysis 29/69
Scala Fields Example Howto
Compositionality in AC: example
trait DistributedSum extends AggregateProgram
with BlockG with BlockC with BlockS
with Broadcast with SumCollect with Utilities
{
def distribSum(size:Double, metric: =>Double, v:Double): Double = {
val leaders = S(size, metric)
val potential = distanceTo(leaders, metric)
???
}
}
:
R. Casadei Intro SCAFI ACP Analysis 29/69
Scala Fields Example Howto
Compositionality in AC: example
trait DistributedSum extends AggregateProgram ... with SumCollect {
def distribSum(size:Double, metric: =>Double, v:Double): Double = {
val leaders = S(size, metric)
val potential = distanceTo(leaders, metric)
val collection = sumCollect(leaders, v)
val count = sumCollect(leaders, 1.0)
val avg = collection / count
}
}
:
R. Casadei Intro SCAFI ACP Analysis 29/69
Scala Fields Example Howto
Compositionality in AC: example
trait DistributedSum extends AggregateProgram ... with Broadcast {
def distribSum(size:Double, metric: =>Double, v:Double): Double = {
val leaders = S(size, metric)
val potential = distanceTo(leaders, metric)
val collection = sumCollect(leaders, v)
val count = sumCollect(leaders, 1.0)
val avg = collection / count
broadcast(leaders, avg)
}
}
:
R. Casadei Intro SCAFI ACP Analysis 29/69
Scala Fields Example Howto
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
Scala Fields
Example
Howto: operational instructions
3 Analysis for an Aggregate Computing Platform (ACP)
Platforms
Requirements
Analysis
Current framework: SCAFI platform
R. Casadei Intro SCAFI ACP Analysis 30/69
Scala Fields Example Howto
Engineering CAS applications with AC platforms
R. Casadei Intro SCAFI ACP Analysis 31/69
Scala Fields Example Howto
SCAFI: state-of-art
R. Casadei Intro SCAFI ACP Analysis 32/69
Scala Fields Example Howto
Practical information
Repository URL: http://github.com/scafi/scafi
GitHub Pages page: https://scafi.github.io/
Maven Central artifacts
// Gradle
compile group: ’it.unibo.apice.scafiteam’, name: ’scafi-simulator-
gui_2.12’, version: ’0.2.0’
// SBT
libraryDependencies += "it.unibo.apice.scafiteam" %% "scafi-simulator-
gui" % "0.2.0"
:
R. Casadei Intro SCAFI ACP Analysis 33/69
Scala Fields Example Howto
Playing with scafi in IntelliJ
1) git clone http://github.com/scafi/scafi && cd scafi
2) git checkout develop (or another branch s.t. feature-aligned-map)
3) Open Intellij, File -> Open -> select scafi root directory
Select Java SDK
IntelliJ should prompt you with the list of modules to import
Right click on GUI simulation
examples and select Run
May take some time to download
dependencies and build
R. Casadei Intro SCAFI ACP Analysis 34/69
Scala Fields Example Howto
IntelliJ: some notions
Some notions of IntelliJ
Doc: https://www.jetbrains.com/help/idea/
Project: an organizational unit representing a complete SW solution
Project metadata stored as a set of XML files within .idea directory
Module: discrete unit of functionality, in the context of a project, which you can
compile, run, test and debug independently
Configuration info stored in a .iml file located (by default) in the module’s content root
folder.
The .idea directory (except workspace.xml) and .iml files should be version
controlled.
To develop an application, you need a SDK (e.g., Java or Android SDK)—to be
installed apart ant then configured in IntelliJ.
Working with Scala leverages a Scala plugin
R. Casadei Intro SCAFI ACP Analysis 35/69
Scala Fields Example Howto
Scafi: orient yourself in the codebase
Points of interest
Interpreter: Module core; component it.unibo.scafi.core.Semantics
Standard library: Module stdlib
Code examples: Module demos
Distributed systems: folders demos/ or examples/
Plain simulations: examples/DemoSequence.scala
GUI-based simulations: folder sims/
Unfinalised complex libs: folder lib/
Simulator core: Module simulator; pkg it.unibo.scafi.simulation
Semantics tests: [core]/test
Functional tests: [tests]/test
For details on the architecture of scafi, refer to [3]
R. Casadei Intro SCAFI ACP Analysis 36/69
Scala Fields Example Howto
Scafi and Alchemist I
Scafi is shipped with Alchemist (since v.6.0.0)
Example project (from [4]):
https://bitbucket.org/metaphori/trusted-ac-experiments
Differences wrt Protelis
incarnation: scafi # Instead of ’protelis’
pools:
- pool: &program
- time-distribution: 1
type: Event
actions:
- type: RunScafiProgram # Not ’RunProtelisProgram’
parameters: [gradient, 20]
:
R. Casadei Intro SCAFI ACP Analysis 37/69
Scala Fields Example Howto
Scafi and Alchemist II
And there’ll be some .scala in classpath with file as follows
import it.unibo.alchemist.model.scafi.ScafiIncarnationForAlchemist._
trait ScafiAlchemistSupport { self: AggregateProgram =>
def env = sense[NodeManager]("manager")
}
class gradient extends AggregateProgram with ScafiAlchemistSupport {
override def main(): Double = {
val someParam = env.get[Double]("parameter")
env.put[Double]("someKey", 77.7)
???
}
}
:
Import the scafi-Alchemist incarnation (line 1)
Create a class that extends AggregateProgram and defines main()
R. Casadei Intro SCAFI ACP Analysis 38/69
Platforms Requirements Analysis Current framework: SCAFI platform
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
3 Analysis for an Aggregate Computing Platform (ACP)
Platforms
Requirements
Analysis
Current framework: SCAFI platform
R. Casadei Intro SCAFI ACP Analysis 39/69
Platforms Requirements Analysis Current framework: SCAFI platform
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
Scala Fields
Example
Howto: operational instructions
3 Analysis for an Aggregate Computing Platform (ACP)
Platforms
Requirements
Analysis
Current framework: SCAFI platform
R. Casadei Intro SCAFI ACP Analysis 40/69
Platforms Requirements Analysis Current framework: SCAFI platform
The starting point of any engineering process
A vision that must be made concrete / top-down or bottom-up
R. Casadei Intro SCAFI ACP Analysis 41/69
Platforms Requirements Analysis Current framework: SCAFI platform
Applications as the interface to the needs
Abstractly defined until some concrete underlying technology is identified
R. Casadei Intro SCAFI ACP Analysis 42/69
Platforms Requirements Analysis Current framework: SCAFI platform
Aggregate Computing: bridging the gap to SASO systems
Supports the development and execution of Aggregate Computing applications
R. Casadei Intro SCAFI ACP Analysis 43/69
Platforms Requirements Analysis Current framework: SCAFI platform
Zooming the AC layer
R. Casadei Intro SCAFI ACP Analysis 44/69
Platforms Requirements Analysis Current framework: SCAFI platform
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
Scala Fields
Example
Howto: operational instructions
3 Analysis for an Aggregate Computing Platform (ACP)
Platforms
Requirements
Analysis
Current framework: SCAFI platform
R. Casadei Intro SCAFI ACP Analysis 45/69
Platforms Requirements Analysis Current framework: SCAFI platform
Requirements for an Aggregate Computing platform
High-level, Functional
FR1 Support the specification and configuration of AGGREGATE-SYSTEMs
FR2 Support the runtime execution of AGGREGATE-APPLICATIONs
High-level, Non-functional
NR1 Scalability to a large number of NODEs
NR2 Reliability
An AGGREGATE-SYSTEM made of unreliable INFRASTRUCTURAL-COMPONENTs and
unreliable NODEs should be able to continue operation even in face of faults.
R. Casadei Intro SCAFI ACP Analysis 46/69
Platforms Requirements Analysis Current framework: SCAFI platform
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
Scala Fields
Example
Howto: operational instructions
3 Analysis for an Aggregate Computing Platform (ACP)
Platforms
Requirements
Analysis
Current framework: SCAFI platform
R. Casadei Intro SCAFI ACP Analysis 47/69
Platforms Requirements Analysis Current framework: SCAFI platform
Requirements analysis
Approach: informal but systematic (cartesian)
Give names to things
Refine meaning and relationships
Explore in (mentally simulated) use, adopt perspectives and visualize
(Then, formalize early, when enough committed)
AGGREGATE-LOGIC: the representation-independent view of some
aggregate-level behaviour in space/time
AGGREGATE-PROGRAM: an AGGREGATE-LOGIC expressed in some executable
representation
AGGREGATE-SYSTEM: a set of networked NODEs supporting the collective
execution of AGGREGATE-PROGRAMs
AGGREGATE-APPLICATION: a particular AGGREGATE-LOGIC running on a certain
AGGREGATE-SYSTEM, aimed at solving some problem in some context
R. Casadei Intro SCAFI ACP Analysis 48/69
Platforms Requirements Analysis Current framework: SCAFI platform
High-level, logical, informal model
Starting point for a systematic characterisation of our (fuzzy) class of systems
We think of no specific application/system, but a range of applications/systems
to support/drive analysis and be concrete
R. Casadei Intro SCAFI ACP Analysis 49/69
Platforms Requirements Analysis Current framework: SCAFI platform
Structure / Interaction / Behaviour decomposition
(Logical) Structure
DEVICEs (aka NODEs, AGENTs)
Have an identity (UID)
Have SENSORs and ACTUATORs
(Logical) Behaviour/Interaction
A DEVICE can only directly communicate with the DEVICEs of its
NEIGHBOURHOOD
A DEVICE computes its part of AGGREGATE-LOGIC on a round-by-round basis
Steps of a round of execution
1) Retrieve the device’s CONTEXT (SENSOR-DATA, NBR-DATA)
2) Execute LOCAL-AGGREGATE-LOGIC to produce OUTPUT + EXPORT
3) Broadcast EXPORT to NEIGHBOURHOOD
4) Feed ACTUATORS with OUTPUT
This characterization is mainly logical and “standard”
Many questions arise: who? what? where? when? how?
R. Casadei Intro SCAFI ACP Analysis 50/69
Platforms Requirements Analysis Current framework: SCAFI platform
Analysis » execution rounds I
SCHEDULING-POLICY: who decides when a round has to be executed?
A SCHEDULER (owned by a device or external)
Construction of the CONTEXT using up-to-date SENSOR-DATA and NBR-DATA
Ideally, we’d like to separate the time/frequency in which these information are
collected from the time in which they are received
Retrieval of SENSOR-DATA: request/response to device’s SENSOR or sampling of
an incoming SENSOR-DATA-STREAM
Note: location data (e.g., GPS coords) may need to be sent to the
TOPOLOGY-MANAGER
Retrieval of NBR-DATA: request/response to a FIELD-MANAGER or sampling of an
incoming NBR-DATA-STREAM
Who actually executes the AGGREGATE-LOGIC for a given DEVICE?
An AGGREGATE-LOGIC-EXECUTOR (owned by a device or external)
R. Casadei Intro SCAFI ACP Analysis 51/69
Platforms Requirements Analysis Current framework: SCAFI platform
Analysis » execution rounds II
Broadcast of EXPORT to NEIGHBOURHOOD
By the DEVICE itself (if it knows how to reach its NEIGHBOURHOOD)
But the DEVICE’s awareness of communication is questionable
“No matter who you are! I know where you are” [zambonelli2004spatial]
The DEVICE may simply send its computation descriptors (EXPORTs) to the
FIELD-MANAGER
The FIELD-MANAGER in turn may delegate the task to an EXPORT-PROPAGATOR
which must then know the NEIGHBOURHOODs and how to reach them
Invocation of ACTUATORs
In general, we may have ACTUATION-DATA-STREAMs directed to ACTUATORs
which may be controlled by (but still decoupled from) rounds.
R. Casadei Intro SCAFI ACP Analysis 52/69
Platforms Requirements Analysis Current framework: SCAFI platform
Analysis » neighbourhood
NBR-POLICY: how is NEIGHBOURHOOD determined?
May be communication-determined (i.e., my neighbours are those I can reach)
May be spatially-determined (i.e., derived from the devices’ position in space)
May be ad-hoc (i.e., application-specific)
Who owns the knowledge of a device’s NEIGHBOURHOOD?
A TOPOLOGY-MANAGER (owned by a device or external)
Who uses the knowledge of a device’s NEIGHBOURHOOD?
The EXPORT-PROPAGATOR
Properties of NEIGHBOURHOOD
It is usually dynamic
Can be asymmetric
R. Casadei Intro SCAFI ACP Analysis 53/69
Platforms Requirements Analysis Current framework: SCAFI platform
Analysis » configuration
How do components locate (the address of) other components?
DEVICEs should be addressable to support e.g. peer-to-peer interaction or the
the delivery of ACTUATION-DATA
The mappings between DEVICEs’ UIDs and their ADDRESS may be kept in a
REGISTRY
Devices should also be given some CONFIGURATION data – so that they know the
ADDRESS of required services
How do AGGREGATE-LOGIC-EXECUTOR obtain the AGGREGATE-LOGIC to execute?
Can be provided at deployment or configuration time
R. Casadei Intro SCAFI ACP Analysis 54/69
Platforms Requirements Analysis Current framework: SCAFI platform
Logical components emerging from analysis (dev-centric)
It comes natural to assign many responsibilities to the DEVICEs (cf., p2p setup)..
R. Casadei Intro SCAFI ACP Analysis 55/69
Platforms Requirements Analysis Current framework: SCAFI platform
Logical components emerging from analysis (sys-centric)
It comes natural to consider DEVICEs only as situated contexts..
R. Casadei Intro SCAFI ACP Analysis 56/69
Platforms Requirements Analysis Current framework: SCAFI platform
Many kinds of deployments
Such flexibility demands for fluid responsibilities
R. Casadei Intro SCAFI ACP Analysis 57/69
Platforms Requirements Analysis Current framework: SCAFI platform
The data perspective
Data payloads
SENSOR-DATA: map from sensor UIDs to sensor values
ACTUATION-DATA: map from actuator UIDs to actuation values
NBR-DATA (i.e., EXPORTS): map from neighbour UIDs to exports
CONTEXT-DATA = SENSOR-DATA + NBR-DATA
Control data
SCHEDULE-DATA (i.e., TICKs)
...
Configuration data
Deployment data, addresses, ...
...
Analysis from a data (flow) perspective
» On an app-specific basis, analysis of Volume-Velocity-Variety-Veracity
» Further analysis: persistent vs. transient data
» Further analysis: replication, partitioning, ...
» Analysis of data flow can help architectural design (cf., reactive architectures)
R. Casadei Intro SCAFI ACP Analysis 58/69
Platforms Requirements Analysis Current framework: SCAFI platform
Outline
1 Introduction: Aggregate Computing
2 SCAFI: Practical Aggregate Programming in Scala
Scala Fields
Example
Howto: operational instructions
3 Analysis for an Aggregate Computing Platform (ACP)
Platforms
Requirements
Analysis
Current framework: SCAFI platform
R. Casadei Intro SCAFI ACP Analysis 59/69
Platforms Requirements Analysis Current framework: SCAFI platform
SCAFI: state-of-art
R. Casadei Intro SCAFI ACP Analysis 60/69
Platforms Requirements Analysis Current framework: SCAFI platform
AC Platform: state-of-art
Key features
Actor-based (Akka)
Two styles
a) fully decentralised (P2P)
b) server-based (mediating interactions)
Simple object-oriented API façade
Easy configuration (file, cmd-line, programmatically)
Limitations (work-in-progress)
Not ready for use across the Internet
Serialization issues and constrained architecture due to nested design
Tightly coupled with SCAFI-core
R. Casadei Intro SCAFI ACP Analysis 61/69
Platforms Requirements Analysis Current framework: SCAFI platform
AC actor platform: overview
R. Casadei Intro SCAFI ACP Analysis 62/69
Platforms Requirements Analysis Current framework: SCAFI platform
AC actor platform: building
R. Casadei Intro SCAFI ACP Analysis 63/69
Platforms Requirements Analysis Current framework: SCAFI platform
AC actor platform: modular actor design
R. Casadei Intro SCAFI ACP Analysis 64/69
Platforms Requirements Analysis Current framework: SCAFI platform
AC actor platform: styles
R. Casadei Intro SCAFI ACP Analysis 65/69
Platforms Requirements Analysis Current framework: SCAFI platform
Quick platform setup
// STEP 1: CHOOSE INCARNATION
import it.unibo.scafi.incarnations.{ BasicActorP2P => Platform }
// STEP 2: DEFINE AGGREGATE PROGRAM SCHEMA
class Demo_AggregateProgram extends Platform.AggregateProgram {
override def main(): Any = foldhood(0){_ + _}(1)
}
// STEP 3: DEFINE MAIN PROGRAM
object Demo_MainProgram extends Platform.CmdLineMain
:
1) Demo_MainProgram -h 127.0.0.1 -p 9000
-e 1:2,4,5;2;3 --subsystems
127.0.0.1:9500:4:5
--program "demos.Demo_AggregateProgram"
2) Demo_MainProgram -h 127.0.0.1 -p 9500
-e 4;5:4
--program "demos.Demo_AggregateProgram"
:
R. Casadei Intro SCAFI ACP Analysis 66/69
Platforms Requirements Analysis Current framework: SCAFI platform
Manual node setup
// STEP 1: CHOOSE INCARNATION
import scafi.incarnations.{ BasicActorP2P => Platform }
import Platform.{AggregateProgram,Settings,PlatformConfig}
// STEP 2: DEFINE AGGREGATE PROGRAM SCHEMA
class Program extends AggregateProgram with CrowdAPI {
// Specify a "dangerous density" aggregate computation
override def main(): Any = crowdWarning(...)
}
// STEP 3: PLATFORM SETUP
val settings = Settings()
val platform = PlatformConfig.setupPlatform(settings)
// STEP 4: NODE SETUP
val sys = platform.newAggregateApplication()
val dm = sys.newDevice(id = Utils.newId(),
program = Program,
neighbours = Utils.discoverNbrs())
val devActor = dm.actorRef // get underlying actor
:
R. Casadei Intro SCAFI ACP Analysis 67/69
References I
Jacob Beal, Danilo Pianini, and Mirko Viroli. “Aggregate Programming for the Internet of Things”.
In: IEEE Computer (2015). ISSN: 1364-503X.
Jacob Beal et al. “Organizing the Aggregate: Languages for Spatial Computing”. In: CoRR
abs/1202.5509 (2012).
Roberto Casadei. “Aggregate Programming in Scala: a Core Library and Actor-Based Platform for
Distributed Computational Fields”. MA thesis. URL:
http://amslaurea.unibo.it/id/eprint/10341.
Roberto Casadei, Alessandro Aldini, and Mirko Viroli. “Combining Trust and Aggregate Computing”.
In: Software Engineering and Formal Methods. Ed. by Antonio Cerone and Marco Roveri. Cham:
Springer International Publishing, 2018, pp. 507–522. ISBN: 978-3-319-74781-1.
Roberto Casadei, Danilo Pianini, and Mirko Viroli. “Simulating Large-scale Aggregate MASs with
Alchemist and Scala”. In: Proceedings of the Federated Conference on Computer Science and
Information Systems (FedCSIS 2016). Ed. by Maria Ganzha, Leszek Maciaszek, and
Marcin Paprzycki. Gdansk, Poland: IEEE Computer Society Press, 2016.
Roberto Casadei and Mirko Viroli. “Programming Actor-based Collective Adaptive Systems”. In:
AGERE16 workshop. To appear. ACM SIGPLAN. 2016.
R. Casadei Appendix References 68/69
References II
Roberto Casadei and Mirko Viroli. “Towards Aggregate Programming in Scala”. In: First Workshop
on Programming Models and Languages for Distributed Computing. PMLDC ’16. Rome, Italy: ACM,
2016, 5:1–5:7. ISBN: 978-1-4503-4775-4. DOI: 10.1145/2957319.2957372. URL:
http://doi.acm.org/10.1145/2957319.2957372.
Ferruccio Damiani, Mirko Viroli, and Jacob Beal. “A type-sound calculus of computational fields”.
In: Science of Computer Programming 117 (2016), pp. 17 –44. ISSN: 0167-6423. DOI:
http://dx.doi.org/10.1016/j.scico.2015.11.005. URL:
http://www.sciencedirect.com/science/article/pii/S0167642315003573.
Mirko Viroli, Roberto Casadei, and Danilo Pianini. “On Execution Platforms for Large-Scale
Aggregate Computing”. In: 3rd International Workshop on Collective Adaptation in Very Large
Scale Ubicomp (VLSU): Towards a Superorganism of Wearables - UbiComp. Heidelberg, Germany,
2016.
Mirko Viroli et al. “Efficient Engineering of Complex Self-Organising Systems by Self-Stabilising
Fields”. In: IEEE Self-Adaptive and Self-Organizing Systems 2015. IEEE, 2015, pp. 81–90. DOI:
10.1109/SASO.2015.16.
R. Casadei Appendix References 69/69

More Related Content

PDF
A Programming Framework for Collective Adaptive Ecosystems
PDF
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
PDF
Collective Abstractions and Platforms for Large-Scale Self-Adaptive IoT
PDF
Tuple-Based Coordination in Large-Scale Situated Systems
PDF
Aggregate Computing Platforms: Bridging the Gaps
PDF
Bridging the Pervasive Computing Gap: An Aggregate Perspective
PDF
On Execution Platforms for Large-Scale Aggregate Computing
PDF
Coordinating Computation at the Edge: a Decentralized, Self-organizing, Spati...
A Programming Framework for Collective Adaptive Ecosystems
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
Collective Abstractions and Platforms for Large-Scale Self-Adaptive IoT
Tuple-Based Coordination in Large-Scale Situated Systems
Aggregate Computing Platforms: Bridging the Gaps
Bridging the Pervasive Computing Gap: An Aggregate Perspective
On Execution Platforms for Large-Scale Aggregate Computing
Coordinating Computation at the Edge: a Decentralized, Self-organizing, Spati...

What's hot (20)

PDF
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
PDF
From Field-based Coordination to Aggregate Computing
PDF
REDUCING RENDER TIME IN RAY TRACING BY PIXEL AVERAGING
PDF
Reducing Render Time in Ray Tracing by Pixel Averaging
PDF
A novel technique for speech encryption based on k-means clustering and quant...
PPTX
Distributed approximate spectral clustering for large scale datasets
PDF
ViT (Vision Transformer) Review [CDM]
PDF
End-to-End Object Detection with Transformers
PPTX
Beyond The Euclidean Distance: Creating effective visual codebooks using the ...
PDF
Dg34662666
PPTX
Clustering
PPTX
Fcv rep darrell
PDF
BigDL webinar - Deep Learning Library for Spark
PDF
computer networking
PPT
Chapter 3 pc
PDF
SPAR 2015 - Civil Maps Presentation by Sravan Puttagunta
PDF
Recurrent Instance Segmentation (UPC Reading Group)
PDF
B046050711
PDF
Unsupervised Deep Learning (D2L1 Insight@DCU Machine Learning Workshop 2017)
PDF
Interpretability of Convolutional Neural Networks - Eva Mohedano - UPC Barcel...
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
From Field-based Coordination to Aggregate Computing
REDUCING RENDER TIME IN RAY TRACING BY PIXEL AVERAGING
Reducing Render Time in Ray Tracing by Pixel Averaging
A novel technique for speech encryption based on k-means clustering and quant...
Distributed approximate spectral clustering for large scale datasets
ViT (Vision Transformer) Review [CDM]
End-to-End Object Detection with Transformers
Beyond The Euclidean Distance: Creating effective visual codebooks using the ...
Dg34662666
Clustering
Fcv rep darrell
BigDL webinar - Deep Learning Library for Spark
computer networking
Chapter 3 pc
SPAR 2015 - Civil Maps Presentation by Sravan Puttagunta
Recurrent Instance Segmentation (UPC Reading Group)
B046050711
Unsupervised Deep Learning (D2L1 Insight@DCU Machine Learning Workshop 2017)
Interpretability of Convolutional Neural Networks - Eva Mohedano - UPC Barcel...
Ad

Similar to Scafi: Scala with Computational Fields (20)

PDF
Practical Aggregate Programming in Scala
PDF
Programming Actor-based Collective Adaptive Systems
PDF
Towards Automated Engineering for Collective Adaptive Systems: Vision and Res...
PDF
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
PDF
NVIDIA HPC ソフトウエア斜め読み
PDF
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
PDF
On Context-Orientation in Aggregate Programming
PDF
MapReduce Algorithm Design
PDF
IEEE P2P 2013 - Bootstrapping Skynet: Calibration and Autonomic Self-Control ...
PPTX
Large-scale Recommendation Systems on Just a PC
PPTX
Apache spark sneha challa- google pittsburgh-aug 25th
PDF
Aggregate Programming in Scala
PDF
St Petersburg R user group meetup 2, Parallel R
PDF
Declarative Macro-Programming of Collective Systems with Aggregate Computing:...
PDF
Scala+data
PDF
Aggregate Processes in Field Calculus
PDF
High-Performance Graph Analysis and Modeling
PPT
Download It
PPTX
Eclipse Con Europe 2014 How to use DAWN Science Project
PDF
Data Science
Practical Aggregate Programming in Scala
Programming Actor-based Collective Adaptive Systems
Towards Automated Engineering for Collective Adaptive Systems: Vision and Res...
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
NVIDIA HPC ソフトウエア斜め読み
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
On Context-Orientation in Aggregate Programming
MapReduce Algorithm Design
IEEE P2P 2013 - Bootstrapping Skynet: Calibration and Autonomic Self-Control ...
Large-scale Recommendation Systems on Just a PC
Apache spark sneha challa- google pittsburgh-aug 25th
Aggregate Programming in Scala
St Petersburg R user group meetup 2, Parallel R
Declarative Macro-Programming of Collective Systems with Aggregate Computing:...
Scala+data
Aggregate Processes in Field Calculus
High-Performance Graph Analysis and Modeling
Download It
Eclipse Con Europe 2014 How to use DAWN Science Project
Data Science
Ad

More from Roberto Casadei (16)

PDF
Integrating Collective Computing and the Social Internet of Things for Smart ...
PDF
Software Engineering Methods for Artificial Collective Intelligence
PDF
Programming (and Learning) Self-Adaptive & Self-Organising Behaviour with Sca...
PDF
A Presentation of My Research Activity
PDF
Aggregate Computing Research: an Overview
PDF
Introduction to the 1st DISCOLI workshop on distributed collective intelligence
PDF
FScaFi: A Core Calculus for Collective Adaptive Systems Programming
PDF
6th eCAS workshop on Engineering Collective Adaptive Systems
PDF
Augmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
PDF
Pulverisation in Cyber-Physical Systems: Engineering the Self-Organising Logi...
PDF
Testing: an Introduction and Panorama
PDF
Engineering Resilient Collaborative Edge-enabled IoT
PDF
AWS and Serverless Computing
PDF
The Rust Programming Language: an Overview
PDF
Akka Remoting and Clustering: an Introduction
PDF
Akka Actors: an Introduction
Integrating Collective Computing and the Social Internet of Things for Smart ...
Software Engineering Methods for Artificial Collective Intelligence
Programming (and Learning) Self-Adaptive & Self-Organising Behaviour with Sca...
A Presentation of My Research Activity
Aggregate Computing Research: an Overview
Introduction to the 1st DISCOLI workshop on distributed collective intelligence
FScaFi: A Core Calculus for Collective Adaptive Systems Programming
6th eCAS workshop on Engineering Collective Adaptive Systems
Augmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
Pulverisation in Cyber-Physical Systems: Engineering the Self-Organising Logi...
Testing: an Introduction and Panorama
Engineering Resilient Collaborative Edge-enabled IoT
AWS and Serverless Computing
The Rust Programming Language: an Overview
Akka Remoting and Clustering: an Introduction
Akka Actors: an Introduction

Recently uploaded (20)

PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Construction Project Organization Group 2.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Digital Logic Computer Design lecture notes
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
DOCX
573137875-Attendance-Management-System-original
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
composite construction of structures.pdf
PDF
PPT on Performance Review to get promotions
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Welding lecture in detail for understanding
PPT
Mechanical Engineering MATERIALS Selection
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Sustainable Sites - Green Building Construction
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
additive manufacturing of ss316l using mig welding
Construction Project Organization Group 2.pptx
Internet of Things (IOT) - A guide to understanding
Digital Logic Computer Design lecture notes
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
573137875-Attendance-Management-System-original
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
UNIT 4 Total Quality Management .pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
composite construction of structures.pdf
PPT on Performance Review to get promotions
Operating System & Kernel Study Guide-1 - converted.pdf
Welding lecture in detail for understanding
Mechanical Engineering MATERIALS Selection
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Sustainable Sites - Green Building Construction
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
R24 SURVEYING LAB MANUAL for civil enggi

Scafi: Scala with Computational Fields

  • 1. Scafi: Scala with Computational Fields Roberto Casadei PhD Student in CS&Eng [email protected] Department of Computer Science and Engineering (DISI) Alma Mater Studiorum – Università of Bologna March 6, 2018 R. Casadei Intro SCAFI ACP Analysis 1/69
  • 2. Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala 3 Analysis for an Aggregate Computing Platform (ACP) R. Casadei Intro SCAFI ACP Analysis 2/69
  • 3. Problem: design/programming CASs Collective/Complex Adaptive Systems (CASs) Structure: Environment + (Mobile, Large-scale) Networks of { people + devices } Global interpretation: embedded devices collectively form a “diffused” computational system R. Casadei Intro SCAFI ACP Analysis 3/69
  • 4. Towards an approach to CAS development Issues ⇒ approach • Large-scale ⇒ decentralised coordination • Situatedness + distributed autonomy ⇒ substantial unpredictability ⇒ self-* • Complex collective behavior ⇒ good abstractions, layered approach, compositionality Shifting the mindset: from local to global • Declarativeness and the global viewpoint • Crowd-aware services • Failure recovery of enterprise services • Distributed monitoring and reacting (e.g., temperature, fire) • Expected global behavior vs. traditional device-centric interface ⇒ Aggregate Programming [1]: a paradigm for programming whole aggregates of devices. R. Casadei Intro SCAFI ACP Analysis 4/69
  • 5. Aggregate programming From the local/device-centric viewpoint to the global/aggregate viewpoint Aggregate programming: what Goal: programming the collective behaviour of aggregates (of devices) ⇒ global-to-local Aggregate programming: how Prominent approach (generalizing over several prior approaches and strategies [2]) founded on field calculus and self-org patterns Computational fields as unifying abstraction of local/global viewpoints R. Casadei Intro SCAFI ACP Analysis 5/69
  • 6. Aggregate Programming Stack R. Casadei Intro SCAFI ACP Analysis 6/69
  • 7. Aggregate (computing) systems & Execution model Structure ⇒ (network/graph) A set of devices (aka nodes/points/things). Each device is able to communicate with a subset of devices known as its neighbourhood. Dynamics Each device is given the same aggregate program and works at async / partially-sync rounds: (1) Retrieve context ⇐ Messages from neighbours ⇐ Sensor values (2) Aggregate program execution ⇒ export (a tree-like repr of computation) + output (result of last expr in body) (3) Broadcast export to neighbourhood (4) Execute actuators R. Casadei Intro SCAFI ACP Analysis 7/69
  • 8. Aggregate Computing (AC) » how Repeated execution Provides reactivity and incremental adaptivity Broadcast + aligned interaction Allows the construction of a “local” context for computation R. Casadei Intro SCAFI ACP Analysis 8/69
  • 9. Scala Fields Example Howto Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala Scala Fields Example Howto: operational instructions 3 Analysis for an Aggregate Computing Platform (ACP) R. Casadei Intro SCAFI ACP Analysis 9/69
  • 10. Scala Fields Example Howto Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala Scala Fields Example Howto: operational instructions 3 Analysis for an Aggregate Computing Platform (ACP) Platforms Requirements Analysis Current framework: SCAFI platform R. Casadei Intro SCAFI ACP Analysis 10/69
  • 11. Scala Fields Example Howto SCAFI: Scala with Computational Fields Goal: bring Aggregate Computing to the field of mainstream software development What SCAFI [7] is an integrated framework for building systems with aggregate programming. • Scala-internal DSL for expressing aggregate computations. • Linguistic support + execution support (interpreter/VM) • Correct, complete, efficient impl. of the Higher-Order Field Calculus semantics [forte2015] • Distributed platform for execution of aggregate systems. • Support for multiple architectural styles and system configurations. • Actor-based implementation (based on Akka). R. Casadei Intro SCAFI ACP Analysis 11/69
  • 12. Scala Fields Example Howto Some papers about or involving scafi “Towards Aggregate Programming in Scala” Casadei and Viroli 2016 [7] “Simulating Large-scale Aggregate MASs with Alchemist and Scala” Casadei, Pianini, and Viroli 2016 [5] “On Execution Platforms for Large-Scale Aggregate Computing” Viroli, Casadei, and Pianini 2016 [9] “Programming Actor-based Collective Adaptive Systems” Casadei and Viroli 2016 [6] “Combining Trust and Aggregate Computing” Casadei, Aldini, and Viroli 2018 [4] R. Casadei Intro SCAFI ACP Analysis 12/69
  • 13. Scala Fields Example Howto Computational fields [8] • (Abstract interpretation) Mapping space-time to computational objects • (Concrete interpretation) Mapping devices to values: φ : δ → • “Distributed” data structure working as the global abstraction • The bridge abstraction between local behavior and global behavior Discrete systems as an approximation of spacetime R. Casadei Intro SCAFI ACP Analysis 13/69
  • 14. Scala Fields Example Howto Field/aggregate computations Global viewpoint • Aggregate interpretation • Natural/denotational semantics • Program: computation over whole fields • Output (at a given time): system-wide snapshot of a computational field • Geometric view: properties of collections of points Local viewpoint • Device-centric interpretation • Operational semantics • Program: steps of a single device • Output (at a given time): latest value yielded by the device • Geometric view: properties of a single point R. Casadei Intro SCAFI ACP Analysis 14/69
  • 15. Scala Fields Example Howto So, what is an aggregate program? • The global program – "Local programs" obtained via global-to-local mapping • May take the form of field calculus programs (in the representation given by some PL) – Actually, the field calculus is like FJ for Java, or the lambda calculus for Haskell • An aggregate program consists of 1) A set of function definitions 2) A body of expressions. • Example: an aggregate program in SCAFI class MyProgram extends AggregateProgram with MyAPI { def isSource = sense[Boolean]("source") // Entry point for execution override def main() = gradient(isSource) } :– Each device of the aggregate system is given an instance of MyProgram. – Each device repeatedly runs the main method at async rounds of execution. R. Casadei Intro SCAFI ACP Analysis 15/69
  • 16. Scala Fields Example Howto Computing with fields Expressing aggregate/field computations in SCAFI trait Constructs { def rep[A](init: A)(fun: (A) => A): A def nbr[A](expr: => A): A def foldhood[A](init: => A)(acc: (A,A)=>A)(expr: => A): A def aggregate[A](f: => A): A // Not primitive, but foundational def sense[A](name: LSNS): A def nbrvar[A](name: NSNS): A def branch[A](cond: => Boolean)(th: => A)(el: => A): A } :• Mechanisms for context-sensitiveness: nbr, nbrvar, sense • Mechanisms for field evolution: rep • Mechanisms for interaction: nbr • Mechanisms for field domain restriction and partitioning: aggregate, branch • Reference formal system: field calculus [forte2015, 8] R. Casadei Intro SCAFI ACP Analysis 16/69
  • 17. Scala Fields Example Howto Simple fields 0 (x)=>x+1 true t<0,1> Constant, uniform field: 5 – Local view: evaluates to 5 in the context of a single device – Global view: yields a uniform constant field that holds 5 at any point (i.e., at any device) Constant, non-uniform field: mid() – mid() is a built-in function that returns the ID of the running device R. Casadei Intro SCAFI ACP Analysis 17/69
  • 18. Scala Fields Example Howto rep: dynamically evolving fields def rep[A](init: A)(fun: (A) => A): A rep 0 (x)=>x+1 t v0 t v1 .. rep(0){(x)=>x+1} // Initially 0; state is incremented at each round rep(0){ _+1 } : – Notice: the frequency of computation can vary over time and from device to device – In general, the resulting field will be heterogeneous in time and space R. Casadei Intro SCAFI ACP Analysis 18/69
  • 19. Scala Fields Example Howto nbr: interaction, communication, observation def nbr[A](expr: => A): A def foldhood[A](init: => A)(acc: (A,A)=>A)(expr: => A): A nbr de nbr{e} φd=[d1→v1,..,dn→vn] – Local view: nbr returns a field from neighbors to their corresponding value of the given expr e – Global view: a field of fields – Needs to be reduced using a *hood operation – foldhood works by retrieving the value of expr for each neighbour and then folding over the resulting structure as you’d expect from FP. foldhood(0)(_+_){ nbr{1} } : R. Casadei Intro SCAFI ACP Analysis 19/69
  • 20. Scala Fields Example Howto Context-sensitiveness and sensors Local context: 1) The export of the previous computation 2) Messages received from neighbours 3) Values perceived from the physical/software environment Sensing def sense[A](name: LSNS): A def nbrvar[A](name: NSNS): A // Query a local sensor sense[Double]("temperature") // Compute the maximum distance from neighbours foldhood(Double.MinValue)(max(_,_)){ // Also: maxHood {...} nbrvar[Double](NBR_RANGE_NAME) } :– nbr queries a local sensor; nbrvar queries a "neighbouring sensor" ("environmental probe") R. Casadei Intro SCAFI ACP Analysis 20/69
  • 21. Scala Fields Example Howto Field domain restriction Alignment • Aggregate computations can be represented as a trees • Device exports are "paths" along these trees • When two devices execute the same tree node, they are said to be aligned • Interaction is possible only between aligned devices Use cases for branch • Partitioning the space into subspaces performing subcomputations • Regulating admissible interactions (i.e., further restricting the neighbourhood) def branch[A](cond: => Boolean)(th: => A)(el: => A): A branch(sense[Boolean]("flag")){ compute(...) // sub-computation }{ Double.MaxValue // stable value (i.e., not computing) } : R. Casadei Intro SCAFI ACP Analysis 21/69
  • 22. Scala Fields Example Howto Functions Two kinds of functions in SCAFI: 1) "Normal" Scala functions: serve as units for encapsulating behavior/logic def foldhoodMinus[A](init: => A)(acc: (A,A) => A)(ex: => A): A = foldhood(init)(acc){ mux(mid()==nbr(mid())){ init }{ ex } } def isSource = sense[Boolean]("source") : 2) First-class "aggregate" functions [forte2015] – which also work as units for alignment def aggregate[A](f: => A): A def branch[A](cond: => Boolean)(th: => A)(el: => A): A = mux(cond, ()=>aggregate{ th }, ()=>aggregate{ el })() : R. Casadei Intro SCAFI ACP Analysis 22/69
  • 23. Scala Fields Example Howto Example: the gradient [beal2008fastgradients] def nbrRange = nbrvar[Double](NBR_RANGE_NAME) def gradient(source: Boolean): Double = rep(Double.PositiveInfinity){ distance => mux(source) { 0.0 }{ minHood { nbr{distance} + nbrRange } } } : R. Casadei Intro SCAFI ACP Analysis 23/69
  • 24. Scala Fields Example Howto Example: the channel I Each device is given the same aggregate program: class ChannelProgram extends AggregateProgram with ChannelAPI { def main = channel(isSource, isDestination, width) } : def channel(src: Boolean, dest: Boolean, width: Double) = distTo(src) + distTo(dest) <= distBetween(src,dest) + width : R. Casadei Intro SCAFI ACP Analysis 24/69
  • 25. Scala Fields Example Howto Example: the channel II trait ChannelAPI extends Language with Builtins { def channel(src: Boolean, dest: Boolean, width: Double) = distanceTo(src) + distanceTo(dest) <= distBetween(src, dest) + width def G[V:OB](src: Boolean, field: V, acc: V=>V, metric: =>Double): V = rep( (Double.MaxValue, field) ){ dv => mux(src) { (0.0, field) } { minHoodMinus { val (d, v) = nbr { (dv._1, dv._2) } (d + metric, acc(v)) } } }._2 def broadcast[V:OB](source: Boolean, field: V): V = G[V](source, field, x=>x, nbrRange()) def distanceTo(source: Boolean): Double = G[Double](source, 0, _ + nbrRange(), nbrRange()) def distBetween(source: Boolean, target: Boolean): Double = broadcast(source, distanceTo(target)) def nbrRange(): Double = nbrvar[Double](NBR_RANGE_NAME) def isSource = sense[Boolean]("source"); def isDestination = sense[Boolean]("destination ") } : R. Casadei Intro SCAFI ACP Analysis 25/69
  • 26. Scala Fields Example Howto Scaling with complexity General coordination operators [10] • Gradient-cast: accumulates values “outward” along a gradient starting from source nodes. def G[V:OB](src: Boolean, init: V, acc: V=>V, metric: =>Double): V : • Converge-cast: collects data distributed across space “inward” by accumulating values from edge nodes to sink nodes down a “potential” field. def C[V:OB](potential: V, acc: (V,V)=>V, local: V, Null: V): V : • Time-decay: supports information summarisation across time. def T[V:Numeric](initial: V, floor: V, decay: V=>V): V : • Sparse-choice: supports creation of partitions and selection of sparse subsets of devices in space def S(grain: Double, metric: => Double): Boolean : R. Casadei Intro SCAFI ACP Analysis 26/69
  • 27. Scala Fields Example Howto Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala Scala Fields Example Howto: operational instructions 3 Analysis for an Aggregate Computing Platform (ACP) Platforms Requirements Analysis Current framework: SCAFI platform R. Casadei Intro SCAFI ACP Analysis 27/69
  • 28. Scala Fields Example Howto Aggregate Computing (AC) » what Goal: programming the collective behaviour of aggregates of devices Main ideas Macro-level programming with automatic macro-micro bridging Declarativity Support for “engineered emergence” Composition of aggregate behaviour with predictable dynamics Layers of reusable abstractions Abstraction from interaction-level and platform-level issues Inherent adaptivity Inherent resiliency Operational flexibility R. Casadei Intro SCAFI ACP Analysis 28/69
  • 29. Scala Fields Example Howto Compositionality in AC: example trait DistributedSum extends AggregateProgram { def distribSum(size:Double, metric: =>Double, v:Double): Double = ??? } trait Broadcast extends BlockG with ... { s: AggregateProgram => def broadcast[V: Bounded](src: Boolean, value: V): V = G(src, value)(x => x, nbrRange) } trait SumCollect extends BlockC with ... { s: AggregateProgram => def sumCollect(target: Boolean, value: Double): Double = C(value)(distanceTo(target,nbrRange))(_+_,0) } : Distributed sum Split the space into regions with grain size Calculate the mean of field v in each region Collect the values and the number of nodes in the region Compute the average Propagate the computed value R. Casadei Intro SCAFI ACP Analysis 29/69
  • 30. Scala Fields Example Howto Compositionality in AC: example trait DistributedSum extends AggregateProgram with BlockG with BlockC with BlockS with Broadcast with SumCollect with Utilities { def distribSum(size:Double, metric: =>Double, v:Double): Double = { val leaders = S(size, metric) ??? } } : R. Casadei Intro SCAFI ACP Analysis 29/69
  • 31. Scala Fields Example Howto Compositionality in AC: example trait DistributedSum extends AggregateProgram with BlockG with BlockC with BlockS with Broadcast with SumCollect with Utilities { def distribSum(size:Double, metric: =>Double, v:Double): Double = { val leaders = S(size, metric) val potential = distanceTo(leaders, metric) ??? } } : R. Casadei Intro SCAFI ACP Analysis 29/69
  • 32. Scala Fields Example Howto Compositionality in AC: example trait DistributedSum extends AggregateProgram ... with SumCollect { def distribSum(size:Double, metric: =>Double, v:Double): Double = { val leaders = S(size, metric) val potential = distanceTo(leaders, metric) val collection = sumCollect(leaders, v) val count = sumCollect(leaders, 1.0) val avg = collection / count } } : R. Casadei Intro SCAFI ACP Analysis 29/69
  • 33. Scala Fields Example Howto Compositionality in AC: example trait DistributedSum extends AggregateProgram ... with Broadcast { def distribSum(size:Double, metric: =>Double, v:Double): Double = { val leaders = S(size, metric) val potential = distanceTo(leaders, metric) val collection = sumCollect(leaders, v) val count = sumCollect(leaders, 1.0) val avg = collection / count broadcast(leaders, avg) } } : R. Casadei Intro SCAFI ACP Analysis 29/69
  • 34. Scala Fields Example Howto Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala Scala Fields Example Howto: operational instructions 3 Analysis for an Aggregate Computing Platform (ACP) Platforms Requirements Analysis Current framework: SCAFI platform R. Casadei Intro SCAFI ACP Analysis 30/69
  • 35. Scala Fields Example Howto Engineering CAS applications with AC platforms R. Casadei Intro SCAFI ACP Analysis 31/69
  • 36. Scala Fields Example Howto SCAFI: state-of-art R. Casadei Intro SCAFI ACP Analysis 32/69
  • 37. Scala Fields Example Howto Practical information Repository URL: http://github.com/scafi/scafi GitHub Pages page: https://scafi.github.io/ Maven Central artifacts // Gradle compile group: ’it.unibo.apice.scafiteam’, name: ’scafi-simulator- gui_2.12’, version: ’0.2.0’ // SBT libraryDependencies += "it.unibo.apice.scafiteam" %% "scafi-simulator- gui" % "0.2.0" : R. Casadei Intro SCAFI ACP Analysis 33/69
  • 38. Scala Fields Example Howto Playing with scafi in IntelliJ 1) git clone http://github.com/scafi/scafi && cd scafi 2) git checkout develop (or another branch s.t. feature-aligned-map) 3) Open Intellij, File -> Open -> select scafi root directory Select Java SDK IntelliJ should prompt you with the list of modules to import Right click on GUI simulation examples and select Run May take some time to download dependencies and build R. Casadei Intro SCAFI ACP Analysis 34/69
  • 39. Scala Fields Example Howto IntelliJ: some notions Some notions of IntelliJ Doc: https://www.jetbrains.com/help/idea/ Project: an organizational unit representing a complete SW solution Project metadata stored as a set of XML files within .idea directory Module: discrete unit of functionality, in the context of a project, which you can compile, run, test and debug independently Configuration info stored in a .iml file located (by default) in the module’s content root folder. The .idea directory (except workspace.xml) and .iml files should be version controlled. To develop an application, you need a SDK (e.g., Java or Android SDK)—to be installed apart ant then configured in IntelliJ. Working with Scala leverages a Scala plugin R. Casadei Intro SCAFI ACP Analysis 35/69
  • 40. Scala Fields Example Howto Scafi: orient yourself in the codebase Points of interest Interpreter: Module core; component it.unibo.scafi.core.Semantics Standard library: Module stdlib Code examples: Module demos Distributed systems: folders demos/ or examples/ Plain simulations: examples/DemoSequence.scala GUI-based simulations: folder sims/ Unfinalised complex libs: folder lib/ Simulator core: Module simulator; pkg it.unibo.scafi.simulation Semantics tests: [core]/test Functional tests: [tests]/test For details on the architecture of scafi, refer to [3] R. Casadei Intro SCAFI ACP Analysis 36/69
  • 41. Scala Fields Example Howto Scafi and Alchemist I Scafi is shipped with Alchemist (since v.6.0.0) Example project (from [4]): https://bitbucket.org/metaphori/trusted-ac-experiments Differences wrt Protelis incarnation: scafi # Instead of ’protelis’ pools: - pool: &program - time-distribution: 1 type: Event actions: - type: RunScafiProgram # Not ’RunProtelisProgram’ parameters: [gradient, 20] : R. Casadei Intro SCAFI ACP Analysis 37/69
  • 42. Scala Fields Example Howto Scafi and Alchemist II And there’ll be some .scala in classpath with file as follows import it.unibo.alchemist.model.scafi.ScafiIncarnationForAlchemist._ trait ScafiAlchemistSupport { self: AggregateProgram => def env = sense[NodeManager]("manager") } class gradient extends AggregateProgram with ScafiAlchemistSupport { override def main(): Double = { val someParam = env.get[Double]("parameter") env.put[Double]("someKey", 77.7) ??? } } : Import the scafi-Alchemist incarnation (line 1) Create a class that extends AggregateProgram and defines main() R. Casadei Intro SCAFI ACP Analysis 38/69
  • 43. Platforms Requirements Analysis Current framework: SCAFI platform Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala 3 Analysis for an Aggregate Computing Platform (ACP) Platforms Requirements Analysis Current framework: SCAFI platform R. Casadei Intro SCAFI ACP Analysis 39/69
  • 44. Platforms Requirements Analysis Current framework: SCAFI platform Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala Scala Fields Example Howto: operational instructions 3 Analysis for an Aggregate Computing Platform (ACP) Platforms Requirements Analysis Current framework: SCAFI platform R. Casadei Intro SCAFI ACP Analysis 40/69
  • 45. Platforms Requirements Analysis Current framework: SCAFI platform The starting point of any engineering process A vision that must be made concrete / top-down or bottom-up R. Casadei Intro SCAFI ACP Analysis 41/69
  • 46. Platforms Requirements Analysis Current framework: SCAFI platform Applications as the interface to the needs Abstractly defined until some concrete underlying technology is identified R. Casadei Intro SCAFI ACP Analysis 42/69
  • 47. Platforms Requirements Analysis Current framework: SCAFI platform Aggregate Computing: bridging the gap to SASO systems Supports the development and execution of Aggregate Computing applications R. Casadei Intro SCAFI ACP Analysis 43/69
  • 48. Platforms Requirements Analysis Current framework: SCAFI platform Zooming the AC layer R. Casadei Intro SCAFI ACP Analysis 44/69
  • 49. Platforms Requirements Analysis Current framework: SCAFI platform Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala Scala Fields Example Howto: operational instructions 3 Analysis for an Aggregate Computing Platform (ACP) Platforms Requirements Analysis Current framework: SCAFI platform R. Casadei Intro SCAFI ACP Analysis 45/69
  • 50. Platforms Requirements Analysis Current framework: SCAFI platform Requirements for an Aggregate Computing platform High-level, Functional FR1 Support the specification and configuration of AGGREGATE-SYSTEMs FR2 Support the runtime execution of AGGREGATE-APPLICATIONs High-level, Non-functional NR1 Scalability to a large number of NODEs NR2 Reliability An AGGREGATE-SYSTEM made of unreliable INFRASTRUCTURAL-COMPONENTs and unreliable NODEs should be able to continue operation even in face of faults. R. Casadei Intro SCAFI ACP Analysis 46/69
  • 51. Platforms Requirements Analysis Current framework: SCAFI platform Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala Scala Fields Example Howto: operational instructions 3 Analysis for an Aggregate Computing Platform (ACP) Platforms Requirements Analysis Current framework: SCAFI platform R. Casadei Intro SCAFI ACP Analysis 47/69
  • 52. Platforms Requirements Analysis Current framework: SCAFI platform Requirements analysis Approach: informal but systematic (cartesian) Give names to things Refine meaning and relationships Explore in (mentally simulated) use, adopt perspectives and visualize (Then, formalize early, when enough committed) AGGREGATE-LOGIC: the representation-independent view of some aggregate-level behaviour in space/time AGGREGATE-PROGRAM: an AGGREGATE-LOGIC expressed in some executable representation AGGREGATE-SYSTEM: a set of networked NODEs supporting the collective execution of AGGREGATE-PROGRAMs AGGREGATE-APPLICATION: a particular AGGREGATE-LOGIC running on a certain AGGREGATE-SYSTEM, aimed at solving some problem in some context R. Casadei Intro SCAFI ACP Analysis 48/69
  • 53. Platforms Requirements Analysis Current framework: SCAFI platform High-level, logical, informal model Starting point for a systematic characterisation of our (fuzzy) class of systems We think of no specific application/system, but a range of applications/systems to support/drive analysis and be concrete R. Casadei Intro SCAFI ACP Analysis 49/69
  • 54. Platforms Requirements Analysis Current framework: SCAFI platform Structure / Interaction / Behaviour decomposition (Logical) Structure DEVICEs (aka NODEs, AGENTs) Have an identity (UID) Have SENSORs and ACTUATORs (Logical) Behaviour/Interaction A DEVICE can only directly communicate with the DEVICEs of its NEIGHBOURHOOD A DEVICE computes its part of AGGREGATE-LOGIC on a round-by-round basis Steps of a round of execution 1) Retrieve the device’s CONTEXT (SENSOR-DATA, NBR-DATA) 2) Execute LOCAL-AGGREGATE-LOGIC to produce OUTPUT + EXPORT 3) Broadcast EXPORT to NEIGHBOURHOOD 4) Feed ACTUATORS with OUTPUT This characterization is mainly logical and “standard” Many questions arise: who? what? where? when? how? R. Casadei Intro SCAFI ACP Analysis 50/69
  • 55. Platforms Requirements Analysis Current framework: SCAFI platform Analysis » execution rounds I SCHEDULING-POLICY: who decides when a round has to be executed? A SCHEDULER (owned by a device or external) Construction of the CONTEXT using up-to-date SENSOR-DATA and NBR-DATA Ideally, we’d like to separate the time/frequency in which these information are collected from the time in which they are received Retrieval of SENSOR-DATA: request/response to device’s SENSOR or sampling of an incoming SENSOR-DATA-STREAM Note: location data (e.g., GPS coords) may need to be sent to the TOPOLOGY-MANAGER Retrieval of NBR-DATA: request/response to a FIELD-MANAGER or sampling of an incoming NBR-DATA-STREAM Who actually executes the AGGREGATE-LOGIC for a given DEVICE? An AGGREGATE-LOGIC-EXECUTOR (owned by a device or external) R. Casadei Intro SCAFI ACP Analysis 51/69
  • 56. Platforms Requirements Analysis Current framework: SCAFI platform Analysis » execution rounds II Broadcast of EXPORT to NEIGHBOURHOOD By the DEVICE itself (if it knows how to reach its NEIGHBOURHOOD) But the DEVICE’s awareness of communication is questionable “No matter who you are! I know where you are” [zambonelli2004spatial] The DEVICE may simply send its computation descriptors (EXPORTs) to the FIELD-MANAGER The FIELD-MANAGER in turn may delegate the task to an EXPORT-PROPAGATOR which must then know the NEIGHBOURHOODs and how to reach them Invocation of ACTUATORs In general, we may have ACTUATION-DATA-STREAMs directed to ACTUATORs which may be controlled by (but still decoupled from) rounds. R. Casadei Intro SCAFI ACP Analysis 52/69
  • 57. Platforms Requirements Analysis Current framework: SCAFI platform Analysis » neighbourhood NBR-POLICY: how is NEIGHBOURHOOD determined? May be communication-determined (i.e., my neighbours are those I can reach) May be spatially-determined (i.e., derived from the devices’ position in space) May be ad-hoc (i.e., application-specific) Who owns the knowledge of a device’s NEIGHBOURHOOD? A TOPOLOGY-MANAGER (owned by a device or external) Who uses the knowledge of a device’s NEIGHBOURHOOD? The EXPORT-PROPAGATOR Properties of NEIGHBOURHOOD It is usually dynamic Can be asymmetric R. Casadei Intro SCAFI ACP Analysis 53/69
  • 58. Platforms Requirements Analysis Current framework: SCAFI platform Analysis » configuration How do components locate (the address of) other components? DEVICEs should be addressable to support e.g. peer-to-peer interaction or the the delivery of ACTUATION-DATA The mappings between DEVICEs’ UIDs and their ADDRESS may be kept in a REGISTRY Devices should also be given some CONFIGURATION data – so that they know the ADDRESS of required services How do AGGREGATE-LOGIC-EXECUTOR obtain the AGGREGATE-LOGIC to execute? Can be provided at deployment or configuration time R. Casadei Intro SCAFI ACP Analysis 54/69
  • 59. Platforms Requirements Analysis Current framework: SCAFI platform Logical components emerging from analysis (dev-centric) It comes natural to assign many responsibilities to the DEVICEs (cf., p2p setup).. R. Casadei Intro SCAFI ACP Analysis 55/69
  • 60. Platforms Requirements Analysis Current framework: SCAFI platform Logical components emerging from analysis (sys-centric) It comes natural to consider DEVICEs only as situated contexts.. R. Casadei Intro SCAFI ACP Analysis 56/69
  • 61. Platforms Requirements Analysis Current framework: SCAFI platform Many kinds of deployments Such flexibility demands for fluid responsibilities R. Casadei Intro SCAFI ACP Analysis 57/69
  • 62. Platforms Requirements Analysis Current framework: SCAFI platform The data perspective Data payloads SENSOR-DATA: map from sensor UIDs to sensor values ACTUATION-DATA: map from actuator UIDs to actuation values NBR-DATA (i.e., EXPORTS): map from neighbour UIDs to exports CONTEXT-DATA = SENSOR-DATA + NBR-DATA Control data SCHEDULE-DATA (i.e., TICKs) ... Configuration data Deployment data, addresses, ... ... Analysis from a data (flow) perspective » On an app-specific basis, analysis of Volume-Velocity-Variety-Veracity » Further analysis: persistent vs. transient data » Further analysis: replication, partitioning, ... » Analysis of data flow can help architectural design (cf., reactive architectures) R. Casadei Intro SCAFI ACP Analysis 58/69
  • 63. Platforms Requirements Analysis Current framework: SCAFI platform Outline 1 Introduction: Aggregate Computing 2 SCAFI: Practical Aggregate Programming in Scala Scala Fields Example Howto: operational instructions 3 Analysis for an Aggregate Computing Platform (ACP) Platforms Requirements Analysis Current framework: SCAFI platform R. Casadei Intro SCAFI ACP Analysis 59/69
  • 64. Platforms Requirements Analysis Current framework: SCAFI platform SCAFI: state-of-art R. Casadei Intro SCAFI ACP Analysis 60/69
  • 65. Platforms Requirements Analysis Current framework: SCAFI platform AC Platform: state-of-art Key features Actor-based (Akka) Two styles a) fully decentralised (P2P) b) server-based (mediating interactions) Simple object-oriented API façade Easy configuration (file, cmd-line, programmatically) Limitations (work-in-progress) Not ready for use across the Internet Serialization issues and constrained architecture due to nested design Tightly coupled with SCAFI-core R. Casadei Intro SCAFI ACP Analysis 61/69
  • 66. Platforms Requirements Analysis Current framework: SCAFI platform AC actor platform: overview R. Casadei Intro SCAFI ACP Analysis 62/69
  • 67. Platforms Requirements Analysis Current framework: SCAFI platform AC actor platform: building R. Casadei Intro SCAFI ACP Analysis 63/69
  • 68. Platforms Requirements Analysis Current framework: SCAFI platform AC actor platform: modular actor design R. Casadei Intro SCAFI ACP Analysis 64/69
  • 69. Platforms Requirements Analysis Current framework: SCAFI platform AC actor platform: styles R. Casadei Intro SCAFI ACP Analysis 65/69
  • 70. Platforms Requirements Analysis Current framework: SCAFI platform Quick platform setup // STEP 1: CHOOSE INCARNATION import it.unibo.scafi.incarnations.{ BasicActorP2P => Platform } // STEP 2: DEFINE AGGREGATE PROGRAM SCHEMA class Demo_AggregateProgram extends Platform.AggregateProgram { override def main(): Any = foldhood(0){_ + _}(1) } // STEP 3: DEFINE MAIN PROGRAM object Demo_MainProgram extends Platform.CmdLineMain : 1) Demo_MainProgram -h 127.0.0.1 -p 9000 -e 1:2,4,5;2;3 --subsystems 127.0.0.1:9500:4:5 --program "demos.Demo_AggregateProgram" 2) Demo_MainProgram -h 127.0.0.1 -p 9500 -e 4;5:4 --program "demos.Demo_AggregateProgram" : R. Casadei Intro SCAFI ACP Analysis 66/69
  • 71. Platforms Requirements Analysis Current framework: SCAFI platform Manual node setup // STEP 1: CHOOSE INCARNATION import scafi.incarnations.{ BasicActorP2P => Platform } import Platform.{AggregateProgram,Settings,PlatformConfig} // STEP 2: DEFINE AGGREGATE PROGRAM SCHEMA class Program extends AggregateProgram with CrowdAPI { // Specify a "dangerous density" aggregate computation override def main(): Any = crowdWarning(...) } // STEP 3: PLATFORM SETUP val settings = Settings() val platform = PlatformConfig.setupPlatform(settings) // STEP 4: NODE SETUP val sys = platform.newAggregateApplication() val dm = sys.newDevice(id = Utils.newId(), program = Program, neighbours = Utils.discoverNbrs()) val devActor = dm.actorRef // get underlying actor : R. Casadei Intro SCAFI ACP Analysis 67/69
  • 72. References I Jacob Beal, Danilo Pianini, and Mirko Viroli. “Aggregate Programming for the Internet of Things”. In: IEEE Computer (2015). ISSN: 1364-503X. Jacob Beal et al. “Organizing the Aggregate: Languages for Spatial Computing”. In: CoRR abs/1202.5509 (2012). Roberto Casadei. “Aggregate Programming in Scala: a Core Library and Actor-Based Platform for Distributed Computational Fields”. MA thesis. URL: http://amslaurea.unibo.it/id/eprint/10341. Roberto Casadei, Alessandro Aldini, and Mirko Viroli. “Combining Trust and Aggregate Computing”. In: Software Engineering and Formal Methods. Ed. by Antonio Cerone and Marco Roveri. Cham: Springer International Publishing, 2018, pp. 507–522. ISBN: 978-3-319-74781-1. Roberto Casadei, Danilo Pianini, and Mirko Viroli. “Simulating Large-scale Aggregate MASs with Alchemist and Scala”. In: Proceedings of the Federated Conference on Computer Science and Information Systems (FedCSIS 2016). Ed. by Maria Ganzha, Leszek Maciaszek, and Marcin Paprzycki. Gdansk, Poland: IEEE Computer Society Press, 2016. Roberto Casadei and Mirko Viroli. “Programming Actor-based Collective Adaptive Systems”. In: AGERE16 workshop. To appear. ACM SIGPLAN. 2016. R. Casadei Appendix References 68/69
  • 73. References II Roberto Casadei and Mirko Viroli. “Towards Aggregate Programming in Scala”. In: First Workshop on Programming Models and Languages for Distributed Computing. PMLDC ’16. Rome, Italy: ACM, 2016, 5:1–5:7. ISBN: 978-1-4503-4775-4. DOI: 10.1145/2957319.2957372. URL: http://doi.acm.org/10.1145/2957319.2957372. Ferruccio Damiani, Mirko Viroli, and Jacob Beal. “A type-sound calculus of computational fields”. In: Science of Computer Programming 117 (2016), pp. 17 –44. ISSN: 0167-6423. DOI: http://dx.doi.org/10.1016/j.scico.2015.11.005. URL: http://www.sciencedirect.com/science/article/pii/S0167642315003573. Mirko Viroli, Roberto Casadei, and Danilo Pianini. “On Execution Platforms for Large-Scale Aggregate Computing”. In: 3rd International Workshop on Collective Adaptation in Very Large Scale Ubicomp (VLSU): Towards a Superorganism of Wearables - UbiComp. Heidelberg, Germany, 2016. Mirko Viroli et al. “Efficient Engineering of Complex Self-Organising Systems by Self-Stabilising Fields”. In: IEEE Self-Adaptive and Self-Organizing Systems 2015. IEEE, 2015, pp. 81–90. DOI: 10.1109/SASO.2015.16. R. Casadei Appendix References 69/69