SlideShare a Scribd company logo
Roberto Casadei
Aggregate Programming in Scala:

a Core Library and Actor-based Platform 

for Distributed Computational Fields
Presentation Summary
Part I — Introduction
Part II — Background: Aggregate Programming
• Spatial computing and space-time programming
• Computational fields and field calculus
• Aggregate programming
Part III — Background: Scala for Library Development
• Advanced features
• Advanced techniques
Part IV — Development of scafi
• Project
• Design
• Implementation
Part V — Evaluation
• Evaluation
• Demo
• Conclusion and contributions
Context
Context: development of complex artificial systems
• Scenarios: pervasive computing, IoT, smart-*
• Characteristics: large-scale, complex dynamics, situatedness
• Challenges: unpredictability, scalability, robustness, …
Inadequacy of traditional approaches
• Centralisations, open-loop, fully bottom-up, device-centric …
Requirements
• Decentralised design
• Self-adaptativeness
• Balance of top-down and bottom-up problem solving
Introduction
Spatial Computing
Space-oriented computation — Thematic areas:
A. Intensive computing
B. Computation embedded in space
C. Space computation
Computing “somewhere” [Duckham13]
• Location-related information
• Spatial constraints to communication
Space-time programming [PTRSL-15]
• Computation expressed in terms of properties 

of the physical time and space in which it occurs
• Spatial abstractions
Discrete system vs. continuous space-time
The Computational Field CalculusComputing with fields
Local vs Global viewpoint
Globally, input fields are manipulated and produce output
Locally, nodes compute a “program” to globally achieve t
source destination
gradient distancegradient
<=
+
dilate
width
37
10
Mirko Viroli (Universit`a di Bologna) ISAC10 – SpatialComputing a.a.
Computational fields
• Mapping space-time to computational objects


Field calculus [ESOCC-13]
• Basis set of operators
• Minimal expressive model
• Space-time universal


Higher-order field calculus [SIP-15]
• First-class distributed functions
• Code mobility
Aggregate Programming [IEEEComp-15]
Programming the collective behaviour of aggregates
Viewpoints
• Local viewpoint (device-centric view)
• Global viewpoint (aggregate view)
Global-to-local mapping
• The code running on each device is generated from the aggregate-level
specification
Prominent approach founded on field calculus and self-org patterns
Composable self-organisation
• Self-stabilisation
• Building blocks for resilient coordination
Aggregate Programming Stack
Picture
from [IEEEComp-15]
Aggregate Programming Toolchain
State-of-art: Protelis + Alchemist
• External DSL
• Focus on simulation














Technological gap: there is no aggregate programming framework
aimed at the construction of real-world applications integrated in a
mainstream language
➡ scafi (scala with computational fields)
• Initial design and logic of the field calculus interpreter by prof. Viroli
Towards a tool-chain for aggregate computing
Field Calculus
Protelis
Xtext parsing
Static analysis Interpreter
Alchemist
Platforms
Formal
foundation
Programming
Language
Language
tools
Simulation
Execution
Properties
Proto Lang
Proto Sim
Libraries
Mirko Viroli (UNIBO) Aggregate Programming for VLS Ubicomp VLSUbicomp 2015
The Scala programming language
Scala as general-purpose, multi-paradigm JVM language
• Java integration
• Smooth integration of OOP and FP
• Expressive type system (with type inference)
Scala in the real world
• Increasing adoption in the industry
• Used by: Twitter, Amazon, LinkedIn, Netflix, Coursera, …
• Killer apps: Akka, Apache Spark, Play…
Scala for Library Development — Features
• Typical FP features
• First-class functions, lambdas, closures, HOFs, laziness, …
• Traits and mix-in composition
• Advanced typing
• Self-types, abstract types, …
• Generic programming support
• Implicit system
• Syntactic sugar
Scala for Library Development — Techniques
• “Pimp-my-library” pattern
• Type classes
• Components and dependency injection
• Cake pattern
• Family polymorphism
• Fluent API / Internal DSL development
context("Collections") {

describe("properties on lists") {

List(1, 2, 2, 3, 3, 3) should contain inOrderOnly (1, 2, 3)

List(1, 2, 3) should contain theSameElementsInOrderAs TreeSet(3, 2, 1)

List("a","b","c") should (contain oneOf("b","d")

and not contain value (7))

List(1, 2, 3) shouldBe sorted

List(1, 2, 3) should have size 3

}

}
scafi: Requirements and Goals
Scala-based framework for aggregate programming
• Project consolidation
• Version control, project automation
• Unit and functional tests
• Internal DSL and related VM for field calculus
• Correct, complete, reasonably performant
• Reuse of Scala typing
• Aggregate functions
• Aggregate programming platform
• Distributed
• Code mobility
• Non-functional requirements
• Ease of use
• Flexibility
scafi: Problem Analysis and Abstraction gap
DSL — Issues
• Implementation of field calculus constructs as method calls
• Integration with the Scala type system
Distributed platform — Issues
• Fault-tolerance
• Naming
• Concurrency
• Communication
• Synchronisation
scafi: Design
Aggregate Programming in Scala
Language
trait Language { self: Core =>



trait Constructs {

def nbr[A](expr: => A): A

def rep[A](init: A)

(fun: (A) => A): A

def branch[A](cond: => Boolean)

(th: => A)

(el: => A): A

def foldhood[A](init: => A)

(aggr: (A,A)=>A)

(expr: => A): A

def aggregate[A](f: => A): A


def sense[A](name: LSNS): A

def nbrvar[A](name: NSNS): A
def mid(): ID

def neighbour(): Option[ID]

}


}
trait MyLib { self: Constructs with Builtins =>
def nbrRange: Double = nbrvar[Double](NBR_RANGE_NAME)



def G[V: OrderingFoldable](src: Boolean, field: V, 

acc: V => V, metric: => Double): V = 

rep( (Double.MaxValue, field) ){

dv => mux(src) { (0.0, field) } {

minHoodPlus { 

val (d, v) = nbr { (dv._1, dv._2) }

(d + metric, acc(v)) }

}

}._2



def distTo(source:Boolean): Double = 

G[Double](source,0, _ + nbrRange, nbrRange)



def broadcast[V: OrderingFoldable](src:Boolean, field: V): V =

G[V](src,field, x=>x , nbrRange)



def distBetween(src:Boolean, target:Boolean): Double =

broadcast(src, distanceTo(target))



def channel(src:Boolean, target:Boolean, width:Double): Boolean =

distTo(src) + distTo(target) <= distBetween(src,target) + width

}
Channel and self-stabilisation
Aggregate Programming in Scala
scafi: three points on implementation
Component-based design
• Implemented via traits and family polymorphism
Actor-based distributed platform
• Akka (core + remoting)
• Composition of reactive behaviour 

+ trait stacking
Code mobility (proof of concept)
• Missing classes detected on message deserialisation
trait ComputationDeviceActor
extends BaseDeviceActor

with BasicActorBehavior

with SensingBehavior

with SensorManagementBehavior

with ActuatorManagementBehavior

with BaseNbrManagementBehavior { … }
Example: p2p, ad-hoc net


// 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”
Example: server-based, mobile spatial net (i)
import it.unibo.scafi.distrib.actor.server.{SpatialPlatform => SpatialServerBasedActorPlatform}

import it.unibo.scafi.incarnations.BasicAbstractActorIncarnation

import it.unibo.scafi.space.{Point2D, BasicSpatialAbstraction}



object Demo3_Platform extends BasicAbstractActorIncarnation

with SpatialServerBasedActorPlatform

with BasicSpatialAbstraction with Serializable {

override val LocationSensorName: String = "LOCATION_SENSOR"

override type P = Point2D



override def buildNewSpace[E](elems: Iterable[(E,P)]): SPACE[E] =

new Basic3DSpace(elems.toMap) { override val proximityThreshold = 1.1 }

}



// STEP 2: DEFINE AGGREGATE PROGRAM SCHEMA

class Demo3_AggregateProgram extends Demo3_Platform.AggregateProgram {

def hopGradient(source: Boolean): Double = {

rep(Double.PositiveInfinity){

hops => { mux(source) { 0.0 } { 1+minHood(nbr { hops }) } }

}

}

def main() = hopGradient(sense("source"))

}
Example: server-based, mobile spatial net (ii)
// STEP 3: DEFINE MAIN PROGRAMS

object Demo3_ServerMain extends Demo3_Platform.ServerCmdLineMain {

override def refineSettings(s: Demo3_Platform.Settings) = {

s.copy(profile = s.profile.copy(

serverGuiActorProps = tm => Some(ServerGUIActor.props(Demo3_Platform, tm))

))

}

}
object Demo4_MainProgram extends Demo3_Platform.CmdLineMain {

override def refineSettings(s: Demo3_Platform.Settings) = {

s.copy(profile = s.profile.copy(

devGuiActorProps = ref => Some(DevGUIActor.props(Demo3_Platform, ref))

))

}



override def onDeviceStarted(dm: Demo3_Platform.DeviceManager,

sys: Demo3_Platform.SystemFacade) = {

dm.addSensorValue(Demo3_Platform.LocationSensorName, 

Point2D(dm.selfId%5,(dm.selfId/5.0).floor))

dm.addSensorValue("source", dm.selfId==4)

dm.start

}

}
Example: server-based, mobile spatial net (iii)
Evaluation
Project consolidation
Field calculus support
Complete
Correct
Higher-order FC with first-class distributed functions
Distributed platform
Flexibility, extension points
Predefined profiles
API
Usability, ease of use
Basic spatial computing support
Code mobility
Conclusion
Key goals have been achieved
Of course, there is still room for improvement
• General refactoring
• Long-run implications of the component-based design
• Code mobility — from PoC to sound implementation
• Serialisation issues related to inner classes; closure cleaning; …
• Actor-based platform testing
• Documentation
Related activities
• scafi on Alchemist
• scafi on Android
• scafi on the cloud
References
[IEEEComp-15] Jacob Beal, Danilo Pianini, and Mirko Viroli. Aggregate Programming
for the Internet of Things. IEEE Computer, 48(9):22–30, 2015
[Duckham13]  Matt Duckham. Decentralized Spatial Computing - Foundations of
Geosensor Networks. Springer, 2013.
[PTRSL-15]  Jacob Beal and Mirko Viroli. Space–Time Programming. Philosophical
Transactions of the Royal Society of London A: Mathematical, Physical and Engineering
Sciences, 373(2046), 2015.
[ESOCC-13]  Mirko Viroli, Ferruccio Damiani, and Jacob Beal. A calculus of
computational fields. In Carlos Canal and Massimo Villari, editors, ESOCC
Workshops, volume 393 of Communications in Computer and Information Science,
pages 114–128. Springer, 2013.
[SIP-15]  Ferruccio Damiani, Mirko Viroli, Danilo Pianini, and Jacob Beal. Code mobil-
ity meets self-organisation: A higher-order calculus of computational fields. In
Formal Techniques for Distributed Objects, Components, and Systems, volume 9039 of
Lecture Notes in Computer Science, pages 113–128. Springer International Publishing,
2015.

More Related Content

What's hot (19)

PDF
20160520 what youneedtoknowaboutlambdas
shinolajla
 
PDF
Introduction to functional programming (In Arabic)
Omar Abdelhafith
 
PPT
Oscon keynote: Working hard to keep it simple
Martin Odersky
 
PDF
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Ruslan Shevchenko
 
PPTX
Monadic genetic kernels in Scala
Patrick Nicolas
 
PDF
Java 8
vilniusjug
 
PPTX
Functional programming
Christian Hujer
 
PPT
Devoxx
Martin Odersky
 
PPTX
ScalaDays 2013 Keynote Speech by Martin Odersky
Typesafe
 
ODP
Knolx session
Knoldus Inc.
 
PDF
Functional Programming Patterns for the Pragmatic Programmer
Raúl Raja Martínez
 
PDF
Scala introduction
vito jeng
 
PDF
Python Programming - IX. On Randomness
Ranel Padon
 
PPTX
Kotlin
YeldosTanikin
 
PDF
Python Programming - VII. Customizing Classes and Operator Overloading
Ranel Padon
 
ODP
Functional Programming With Scala
Knoldus Inc.
 
PDF
Functional programming in scala
Stratio
 
PPT
Introduction to Functional Programming in JavaScript
tmont
 
PDF
Advance Scala - Oleg Mürk
Planet OS
 
20160520 what youneedtoknowaboutlambdas
shinolajla
 
Introduction to functional programming (In Arabic)
Omar Abdelhafith
 
Oscon keynote: Working hard to keep it simple
Martin Odersky
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Ruslan Shevchenko
 
Monadic genetic kernels in Scala
Patrick Nicolas
 
Java 8
vilniusjug
 
Functional programming
Christian Hujer
 
ScalaDays 2013 Keynote Speech by Martin Odersky
Typesafe
 
Knolx session
Knoldus Inc.
 
Functional Programming Patterns for the Pragmatic Programmer
Raúl Raja Martínez
 
Scala introduction
vito jeng
 
Python Programming - IX. On Randomness
Ranel Padon
 
Python Programming - VII. Customizing Classes and Operator Overloading
Ranel Padon
 
Functional Programming With Scala
Knoldus Inc.
 
Functional programming in scala
Stratio
 
Introduction to Functional Programming in JavaScript
tmont
 
Advance Scala - Oleg Mürk
Planet OS
 

Viewers also liked (9)

PPTX
Protect Your WordPress From The Inside Out
SiteGround.com
 
PDF
spatialNET Tutorial - Object Creation_v0.1
Riyaz Kallumkal EIT, PMP
 
ODP
Effective unit testing
Roberto Casadei
 
PDF
On Execution Platforms for Large-Scale Aggregate Computing
Roberto Casadei
 
PDF
Haskell
Roberto Casadei
 
PDF
Towards Aggregate Programming in Scala
Roberto Casadei
 
PDF
Programming in Scala: Notes
Roberto Casadei
 
PDF
Programming Actor-based Collective Adaptive Systems
Roberto Casadei
 
PPTX
Scaling out logistic regression with Spark
Barak Gitsis
 
Protect Your WordPress From The Inside Out
SiteGround.com
 
spatialNET Tutorial - Object Creation_v0.1
Riyaz Kallumkal EIT, PMP
 
Effective unit testing
Roberto Casadei
 
On Execution Platforms for Large-Scale Aggregate Computing
Roberto Casadei
 
Towards Aggregate Programming in Scala
Roberto Casadei
 
Programming in Scala: Notes
Roberto Casadei
 
Programming Actor-based Collective Adaptive Systems
Roberto Casadei
 
Scaling out logistic regression with Spark
Barak Gitsis
 
Ad

Similar to Aggregate Programming in Scala (20)

PDF
ScaFi-Web, A Web-Based application for Field-based Coordination
Gianluca Aguzzi
 
PDF
Scafi: Scala with Computational Fields
Roberto Casadei
 
PDF
A Programming Framework for Collective Adaptive Ecosystems
Roberto Casadei
 
PDF
Simulating Large-scale Aggregate MASs with Alchemist and Scala
Danilo Pianini
 
PDF
Engineering the Aggregate - Talk at Software Engineering for Intelligent and ...
Danilo Pianini
 
PDF
Declarative Macro-Programming of Collective Systems with Aggregate Computing:...
Roberto Casadei
 
PDF
From Field-based Coordination to Aggregate Computing
Roberto Casadei
 
PDF
Aggregate Computing Research: an Overview
Roberto Casadei
 
PDF
Aggregate Computing Platforms: Bridging the Gaps
Roberto Casadei
 
PDF
Arvindsujeeth scaladays12
Skills Matter Talks
 
PDF
Building blocks for aggregate programming of self-organising applications
FoCAS Initiative
 
PDF
FScaFi: A Core Calculus for Collective Adaptive Systems Programming
Roberto Casadei
 
PDF
Programming (and Learning) Self-Adaptive & Self-Organising Behaviour with Sca...
Roberto Casadei
 
PDF
eCAS 2021: Towards Pulverised Architectures for Collective Adaptive Systems t...
Gianluca Aguzzi
 
PDF
Practical Aggregate Programming with Protelis @ SASO2017
Danilo Pianini
 
PDF
Scala in Model-Driven development for Apparel Cloud Platform
Tomoharu ASAMI
 
PDF
Towards Automated Engineering for Collective Adaptive Systems: Vision and Res...
Roberto Casadei
 
PDF
Bridging the Pervasive Computing Gap: An Aggregate Perspective
Roberto Casadei
 
PDF
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
Roberto Casadei
 
PPTX
Apache Hadoop India Summit 2011 Keynote talk "Programming Abstractions for Sm...
Yahoo Developer Network
 
ScaFi-Web, A Web-Based application for Field-based Coordination
Gianluca Aguzzi
 
Scafi: Scala with Computational Fields
Roberto Casadei
 
A Programming Framework for Collective Adaptive Ecosystems
Roberto Casadei
 
Simulating Large-scale Aggregate MASs with Alchemist and Scala
Danilo Pianini
 
Engineering the Aggregate - Talk at Software Engineering for Intelligent and ...
Danilo Pianini
 
Declarative Macro-Programming of Collective Systems with Aggregate Computing:...
Roberto Casadei
 
From Field-based Coordination to Aggregate Computing
Roberto Casadei
 
Aggregate Computing Research: an Overview
Roberto Casadei
 
Aggregate Computing Platforms: Bridging the Gaps
Roberto Casadei
 
Arvindsujeeth scaladays12
Skills Matter Talks
 
Building blocks for aggregate programming of self-organising applications
FoCAS Initiative
 
FScaFi: A Core Calculus for Collective Adaptive Systems Programming
Roberto Casadei
 
Programming (and Learning) Self-Adaptive & Self-Organising Behaviour with Sca...
Roberto Casadei
 
eCAS 2021: Towards Pulverised Architectures for Collective Adaptive Systems t...
Gianluca Aguzzi
 
Practical Aggregate Programming with Protelis @ SASO2017
Danilo Pianini
 
Scala in Model-Driven development for Apparel Cloud Platform
Tomoharu ASAMI
 
Towards Automated Engineering for Collective Adaptive Systems: Vision and Res...
Roberto Casadei
 
Bridging the Pervasive Computing Gap: An Aggregate Perspective
Roberto Casadei
 
Self-Organisation Programming: a Functional Reactive Macro Approach (FRASP) [...
Roberto Casadei
 
Apache Hadoop India Summit 2011 Keynote talk "Programming Abstractions for Sm...
Yahoo Developer Network
 
Ad

More from Roberto Casadei (20)

PDF
Integrating Collective Computing and the Social Internet of Things for Smart ...
Roberto Casadei
 
PDF
Software Engineering Methods for Artificial Collective Intelligence
Roberto Casadei
 
PDF
A Presentation of My Research Activity
Roberto Casadei
 
PDF
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
Roberto Casadei
 
PDF
Introduction to the 1st DISCOLI workshop on distributed collective intelligence
Roberto Casadei
 
PDF
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
Roberto Casadei
 
PDF
6th eCAS workshop on Engineering Collective Adaptive Systems
Roberto Casadei
 
PDF
Augmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
Roberto Casadei
 
PDF
Tuple-Based Coordination in Large-Scale Situated Systems
Roberto Casadei
 
PDF
Pulverisation in Cyber-Physical Systems: Engineering the Self-Organising Logi...
Roberto Casadei
 
PDF
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
Roberto Casadei
 
PDF
Testing: an Introduction and Panorama
Roberto Casadei
 
PDF
On Context-Orientation in Aggregate Programming
Roberto Casadei
 
PDF
Engineering Resilient Collaborative Edge-enabled IoT
Roberto Casadei
 
PDF
Aggregate Processes in Field Calculus
Roberto Casadei
 
PDF
AWS and Serverless Computing
Roberto Casadei
 
PDF
Coordinating Computation at the Edge: a Decentralized, Self-organizing, Spati...
Roberto Casadei
 
PDF
The Rust Programming Language: an Overview
Roberto Casadei
 
PDF
Akka Remoting and Clustering: an Introduction
Roberto Casadei
 
PDF
Akka Actors: an Introduction
Roberto Casadei
 
Integrating Collective Computing and the Social Internet of Things for Smart ...
Roberto Casadei
 
Software Engineering Methods for Artificial Collective Intelligence
Roberto Casadei
 
A Presentation of My Research Activity
Roberto Casadei
 
Programming Distributed Collective Processes for Dynamic Ensembles and Collec...
Roberto Casadei
 
Introduction to the 1st DISCOLI workshop on distributed collective intelligence
Roberto Casadei
 
Digital Twins, Virtual Devices, and Augmentations for Self-Organising Cyber-P...
Roberto Casadei
 
6th eCAS workshop on Engineering Collective Adaptive Systems
Roberto Casadei
 
Augmented Collective Digital Twins for Self-Organising Cyber-Physical Systems
Roberto Casadei
 
Tuple-Based Coordination in Large-Scale Situated Systems
Roberto Casadei
 
Pulverisation in Cyber-Physical Systems: Engineering the Self-Organising Logi...
Roberto Casadei
 
Collective Adaptive Systems as Coordination Media: The Case of Tuples in Spac...
Roberto Casadei
 
Testing: an Introduction and Panorama
Roberto Casadei
 
On Context-Orientation in Aggregate Programming
Roberto Casadei
 
Engineering Resilient Collaborative Edge-enabled IoT
Roberto Casadei
 
Aggregate Processes in Field Calculus
Roberto Casadei
 
AWS and Serverless Computing
Roberto Casadei
 
Coordinating Computation at the Edge: a Decentralized, Self-organizing, Spati...
Roberto Casadei
 
The Rust Programming Language: an Overview
Roberto Casadei
 
Akka Remoting and Clustering: an Introduction
Roberto Casadei
 
Akka Actors: an Introduction
Roberto Casadei
 

Recently uploaded (20)

PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Import Data Form Excel to Tally Services
Tally xperts
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 

Aggregate Programming in Scala

  • 1. Roberto Casadei Aggregate Programming in Scala:
 a Core Library and Actor-based Platform 
 for Distributed Computational Fields
  • 2. Presentation Summary Part I — Introduction Part II — Background: Aggregate Programming • Spatial computing and space-time programming • Computational fields and field calculus • Aggregate programming Part III — Background: Scala for Library Development • Advanced features • Advanced techniques Part IV — Development of scafi • Project • Design • Implementation Part V — Evaluation • Evaluation • Demo • Conclusion and contributions
  • 4. Context: development of complex artificial systems • Scenarios: pervasive computing, IoT, smart-* • Characteristics: large-scale, complex dynamics, situatedness • Challenges: unpredictability, scalability, robustness, … Inadequacy of traditional approaches • Centralisations, open-loop, fully bottom-up, device-centric … Requirements • Decentralised design • Self-adaptativeness • Balance of top-down and bottom-up problem solving Introduction
  • 5. Spatial Computing Space-oriented computation — Thematic areas: A. Intensive computing B. Computation embedded in space C. Space computation Computing “somewhere” [Duckham13] • Location-related information • Spatial constraints to communication Space-time programming [PTRSL-15] • Computation expressed in terms of properties 
 of the physical time and space in which it occurs • Spatial abstractions Discrete system vs. continuous space-time
  • 6. The Computational Field CalculusComputing with fields Local vs Global viewpoint Globally, input fields are manipulated and produce output Locally, nodes compute a “program” to globally achieve t source destination gradient distancegradient <= + dilate width 37 10 Mirko Viroli (Universit`a di Bologna) ISAC10 – SpatialComputing a.a. Computational fields • Mapping space-time to computational objects 
 Field calculus [ESOCC-13] • Basis set of operators • Minimal expressive model • Space-time universal 
 Higher-order field calculus [SIP-15] • First-class distributed functions • Code mobility
  • 7. Aggregate Programming [IEEEComp-15] Programming the collective behaviour of aggregates Viewpoints • Local viewpoint (device-centric view) • Global viewpoint (aggregate view) Global-to-local mapping • The code running on each device is generated from the aggregate-level specification Prominent approach founded on field calculus and self-org patterns Composable self-organisation • Self-stabilisation • Building blocks for resilient coordination
  • 9. Aggregate Programming Toolchain State-of-art: Protelis + Alchemist • External DSL • Focus on simulation 
 
 
 
 
 
 
 Technological gap: there is no aggregate programming framework aimed at the construction of real-world applications integrated in a mainstream language ➡ scafi (scala with computational fields) • Initial design and logic of the field calculus interpreter by prof. Viroli Towards a tool-chain for aggregate computing Field Calculus Protelis Xtext parsing Static analysis Interpreter Alchemist Platforms Formal foundation Programming Language Language tools Simulation Execution Properties Proto Lang Proto Sim Libraries Mirko Viroli (UNIBO) Aggregate Programming for VLS Ubicomp VLSUbicomp 2015
  • 10. The Scala programming language Scala as general-purpose, multi-paradigm JVM language • Java integration • Smooth integration of OOP and FP • Expressive type system (with type inference) Scala in the real world • Increasing adoption in the industry • Used by: Twitter, Amazon, LinkedIn, Netflix, Coursera, … • Killer apps: Akka, Apache Spark, Play…
  • 11. Scala for Library Development — Features • Typical FP features • First-class functions, lambdas, closures, HOFs, laziness, … • Traits and mix-in composition • Advanced typing • Self-types, abstract types, … • Generic programming support • Implicit system • Syntactic sugar
  • 12. Scala for Library Development — Techniques • “Pimp-my-library” pattern • Type classes • Components and dependency injection • Cake pattern • Family polymorphism • Fluent API / Internal DSL development context("Collections") {
 describe("properties on lists") {
 List(1, 2, 2, 3, 3, 3) should contain inOrderOnly (1, 2, 3)
 List(1, 2, 3) should contain theSameElementsInOrderAs TreeSet(3, 2, 1)
 List("a","b","c") should (contain oneOf("b","d")
 and not contain value (7))
 List(1, 2, 3) shouldBe sorted
 List(1, 2, 3) should have size 3
 }
 }
  • 13. scafi: Requirements and Goals Scala-based framework for aggregate programming • Project consolidation • Version control, project automation • Unit and functional tests • Internal DSL and related VM for field calculus • Correct, complete, reasonably performant • Reuse of Scala typing • Aggregate functions • Aggregate programming platform • Distributed • Code mobility • Non-functional requirements • Ease of use • Flexibility
  • 14. scafi: Problem Analysis and Abstraction gap DSL — Issues • Implementation of field calculus constructs as method calls • Integration with the Scala type system Distributed platform — Issues • Fault-tolerance • Naming • Concurrency • Communication • Synchronisation
  • 17. Language trait Language { self: Core =>
 
 trait Constructs {
 def nbr[A](expr: => A): A
 def rep[A](init: A)
 (fun: (A) => A): A
 def branch[A](cond: => Boolean)
 (th: => A)
 (el: => A): A
 def foldhood[A](init: => A)
 (aggr: (A,A)=>A)
 (expr: => A): A
 def aggregate[A](f: => A): A 
 def sense[A](name: LSNS): A
 def nbrvar[A](name: NSNS): A def mid(): ID
 def neighbour(): Option[ID]
 } 
 } trait MyLib { self: Constructs with Builtins => def nbrRange: Double = nbrvar[Double](NBR_RANGE_NAME)
 
 def G[V: OrderingFoldable](src: Boolean, field: V, 
 acc: V => V, metric: => Double): V = 
 rep( (Double.MaxValue, field) ){
 dv => mux(src) { (0.0, field) } {
 minHoodPlus { 
 val (d, v) = nbr { (dv._1, dv._2) }
 (d + metric, acc(v)) }
 }
 }._2
 
 def distTo(source:Boolean): Double = 
 G[Double](source,0, _ + nbrRange, nbrRange)
 
 def broadcast[V: OrderingFoldable](src:Boolean, field: V): V =
 G[V](src,field, x=>x , nbrRange)
 
 def distBetween(src:Boolean, target:Boolean): Double =
 broadcast(src, distanceTo(target))
 
 def channel(src:Boolean, target:Boolean, width:Double): Boolean =
 distTo(src) + distTo(target) <= distBetween(src,target) + width
 }
  • 20. scafi: three points on implementation Component-based design • Implemented via traits and family polymorphism Actor-based distributed platform • Akka (core + remoting) • Composition of reactive behaviour 
 + trait stacking Code mobility (proof of concept) • Missing classes detected on message deserialisation trait ComputationDeviceActor extends BaseDeviceActor
 with BasicActorBehavior
 with SensingBehavior
 with SensorManagementBehavior
 with ActuatorManagementBehavior
 with BaseNbrManagementBehavior { … }
  • 21. Example: p2p, ad-hoc net 
 // 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”
  • 22. Example: server-based, mobile spatial net (i) import it.unibo.scafi.distrib.actor.server.{SpatialPlatform => SpatialServerBasedActorPlatform}
 import it.unibo.scafi.incarnations.BasicAbstractActorIncarnation
 import it.unibo.scafi.space.{Point2D, BasicSpatialAbstraction}
 
 object Demo3_Platform extends BasicAbstractActorIncarnation
 with SpatialServerBasedActorPlatform
 with BasicSpatialAbstraction with Serializable {
 override val LocationSensorName: String = "LOCATION_SENSOR"
 override type P = Point2D
 
 override def buildNewSpace[E](elems: Iterable[(E,P)]): SPACE[E] =
 new Basic3DSpace(elems.toMap) { override val proximityThreshold = 1.1 }
 }
 
 // STEP 2: DEFINE AGGREGATE PROGRAM SCHEMA
 class Demo3_AggregateProgram extends Demo3_Platform.AggregateProgram {
 def hopGradient(source: Boolean): Double = {
 rep(Double.PositiveInfinity){
 hops => { mux(source) { 0.0 } { 1+minHood(nbr { hops }) } }
 }
 }
 def main() = hopGradient(sense("source"))
 }
  • 23. Example: server-based, mobile spatial net (ii) // STEP 3: DEFINE MAIN PROGRAMS
 object Demo3_ServerMain extends Demo3_Platform.ServerCmdLineMain {
 override def refineSettings(s: Demo3_Platform.Settings) = {
 s.copy(profile = s.profile.copy(
 serverGuiActorProps = tm => Some(ServerGUIActor.props(Demo3_Platform, tm))
 ))
 }
 } object Demo4_MainProgram extends Demo3_Platform.CmdLineMain {
 override def refineSettings(s: Demo3_Platform.Settings) = {
 s.copy(profile = s.profile.copy(
 devGuiActorProps = ref => Some(DevGUIActor.props(Demo3_Platform, ref))
 ))
 }
 
 override def onDeviceStarted(dm: Demo3_Platform.DeviceManager,
 sys: Demo3_Platform.SystemFacade) = {
 dm.addSensorValue(Demo3_Platform.LocationSensorName, 
 Point2D(dm.selfId%5,(dm.selfId/5.0).floor))
 dm.addSensorValue("source", dm.selfId==4)
 dm.start
 }
 }
  • 24. Example: server-based, mobile spatial net (iii)
  • 25. Evaluation Project consolidation Field calculus support Complete Correct Higher-order FC with first-class distributed functions Distributed platform Flexibility, extension points Predefined profiles API Usability, ease of use Basic spatial computing support Code mobility
  • 26. Conclusion Key goals have been achieved Of course, there is still room for improvement • General refactoring • Long-run implications of the component-based design • Code mobility — from PoC to sound implementation • Serialisation issues related to inner classes; closure cleaning; … • Actor-based platform testing • Documentation Related activities • scafi on Alchemist • scafi on Android • scafi on the cloud
  • 27. References [IEEEComp-15] Jacob Beal, Danilo Pianini, and Mirko Viroli. Aggregate Programming for the Internet of Things. IEEE Computer, 48(9):22–30, 2015 [Duckham13]  Matt Duckham. Decentralized Spatial Computing - Foundations of Geosensor Networks. Springer, 2013. [PTRSL-15]  Jacob Beal and Mirko Viroli. Space–Time Programming. Philosophical Transactions of the Royal Society of London A: Mathematical, Physical and Engineering Sciences, 373(2046), 2015. [ESOCC-13]  Mirko Viroli, Ferruccio Damiani, and Jacob Beal. A calculus of computational fields. In Carlos Canal and Massimo Villari, editors, ESOCC Workshops, volume 393 of Communications in Computer and Information Science, pages 114–128. Springer, 2013. [SIP-15]  Ferruccio Damiani, Mirko Viroli, Danilo Pianini, and Jacob Beal. Code mobil- ity meets self-organisation: A higher-order calculus of computational fields. In Formal Techniques for Distributed Objects, Components, and Systems, volume 9039 of Lecture Notes in Computer Science, pages 113–128. Springer International Publishing, 2015.