1 Meld: A Logical Approach to Programming Ensembles A Thesis Proposal by Michael Ashley-Rollman Committee: Seth Goldstein (co-chair, CMU) Frank Pfenning.

Presentation on theme: "1 Meld: A Logical Approach to Programming Ensembles A Thesis Proposal by Michael Ashley-Rollman Committee: Seth Goldstein (co-chair, CMU) Frank Pfenning."— Presentation transcript:

1 Meld: A Logical Approach to Programming Ensembles A Thesis Proposal by Michael Ashley-Rollman Committee: Seth Goldstein (co-chair, CMU) Frank Pfenning (co-chair, CMU) David Andersen (CMU) Peter Lee (CMU) Radhika Nagpal (Harvard)

2 Ensembles Definition: An ensemble is a massively distributed system in which the topology changes over time

3 Ensemble Examples Internet ZebraNet Sensor Networks Claytronics

4 Gates-Hillman Shape Change ~10 million simulated robots ~100 lines of Meld code

5 Localization ~8 thousand simulated robots ~250 lines of Meld code

6 Rainbow See Blinky Blocks! ~5 blinky blocks ~10 lines of Meld code

7 Ensemble Constraints Distributed system Made up of many nodes Computation and storage must be distributed Individual nodes have limited resources CPU, memory, power, bandwidth Neighbor to neighbor communications only

8 Thesis Statement Logic programming is well-suited for ensemble programming. It permits us to express algorithms in a way that can be run efficiently and reasoned about easily.

9 In support of this Thesis I will: Design and implement a logic programming language for ensembles (called Meld) Preliminary version is implemented Works in simulation and on Blinky Blocks Demonstrate proving correctness properties of Meld programs

10 Outline Ensembles Meld By Example Other Examples Proving Properties Plan of Attack

11 Walk Example Suppose we have a robotic system where the robots can move around one another How can we get them to a particular location (e.g. 4)? st 4 0 321 st 4 0 321

12 Walk Example Rule1: dist(S, DS) :- at(S, PS), destination(PD), DS = |PS-PD|. Rule2: farther(S, T) :- neighbor(S, T), dist(S, DS), dist(T,DT), DS >= DT. Rule3: moveAround(S,T,P) :- farther(S,T), vacant(T,P), dist(S,DS), destination(PD), DS > |P-PD|.

13 Walk Example destination( ) at(s, ) at(t, ) neighbor(s,t) neighbor(t,s) vacant(t, )... st 4 0 321

14 Walk Example dist(S, DS) :- at(S, PS), destination(PD), DS = |PS-PD|.

15 Walk Example dist(S, DS) :- at(S, PS), destination(PD), DS = |PS-PD|. dist(s, DS) :- at(s, ), destination(PD), DS = | -PD|.

16 Walk Example dist(S, DS) :- at(S, PS), destination(PD), DS = |PS-PD|. dist(s, DS) :- at(s, ), destination(PD), DS = | -PD|. dist(s, DS) :- at(s, ), destination( ), DS = | - |.

17 Walk Example dist(S, DS) :- at(S, PS), destination(PD), DS = |PS-PD|. dist(s, DS) :- at(s, ), destination(PD), DS = | -PD|. dist(s, DS) :- at(s, ), destination( ), DS = | - |. dist(s, 4) :- at(s, ), destination( ), 4 = | - |.

18 Walk Example destination( ) at(s, ) at(t, ) neighbor(s,t) neighbor(t,s) vacant(t, ) dist(s, 4) dist(t, 3)... st 4 0 321

19 Walk Example farther(S, T) :- neighbor(S, T), dist(S, DS), dist(T,DT), DS >= DT.

20 Walk Example farther(S, T) :- neighbor(S, T), dist(S, DS), dist(T,DT), DS >= DT. farther(s, t) :- neighbor(s, t), dist(s, DS), dist(T,DT), DS >= DT.

21 Walk Example farther(S, T) :- neighbor(S, T), dist(S, DS), dist(T,DT), DS >= DT. farther(s, t) :- neighbor(s, t), dist(s, DS), dist(T,DT), DS >= DT. farther(s, t) :- neighbor(s, t), dist(s, 4), dist(t,DT), 4 >= DT.

22 Walk Example farther(S, T) :- neighbor(S, T), dist(S, DS), dist(T,DT), DS >= DT. farther(s, t) :- neighbor(s, t), dist(s, DS), dist(T,DT), DS >= DT. farther(s, t) :- neighbor(s, t), dist(s, 4), dist(t,DT), 4 >= DT. farther(s, t) :- neighbor(s, t), dist(s, 4), dist(t,3), 4 >= 3.

23 Walk Example farther(S, T) :- neighbor(S, T), dist(S, DS), dist(T,DT), DS >= DT. farther(s, t) :- neighbor(s, t), dist(s, DS), dist(T,DT), DS >= DT. farther(s, t) :- neighbor(s, t), dist(s, 4), dist(t,DT), 4 >= DT. farther(s, t) :- neighbor(s, t), dist(s, 4), dist(t,3), 4 >= 3.

24 Walk Example destination( ) at(s, ) at(t, ) neighbor(s,t) neighbor(t,s) vacant(t, ) dist(s, 4) dist(t, 3) farther(s,t)... st 4 0 321

25 Walk Example moveAround(S,T,P) :- farther(S,T), vacant(T,P), dist(S,DS), destination(PD), DS > |P-PD|.

26 Walk Example moveAround(S,T,P) :- farther(S,T), vacant(T,P), dist(S,DS), destination(PD), DS > |P-PD|. moveAround(s,t,P) :- farther(s,t), vacant(t,P), dist(s,DS), destination(PD), DS > |P-PD|.

27 Walk Example moveAround(S,T,P) :- farther(S,T), vacant(T,P), dist(S,DS), destination(PD), DS > |P-PD|. moveAround(s,t,P) :- farther(s,t), vacant(t,P), dist(s,DS), destination(PD), DS > |P-PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,DS), destination(PD), DS > | -PD|.

28 Walk Example moveAround(S,T,P) :- farther(S,T), vacant(T,P), dist(S,DS), destination(PD), DS > |P-PD|. moveAround(s,t,P) :- farther(s,t), vacant(t,P), dist(s,DS), destination(PD), DS > |P-PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,DS), destination(PD), DS > | -PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,4), destination(PD), 4 > | -PD|.

29 Walk Example moveAround(S,T,P) :- farther(S,T), vacant(T,P), dist(S,DS), destination(PD), DS > |P-PD|. moveAround(s,t,P) :- farther(s,t), vacant(t,P), dist(s,DS), destination(PD), DS > |P-PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,DS), destination(PD), DS > | -PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,4), destination(PD), 4 > | -PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,4), destination( ), 4 > | - |.

30 Walk Example moveAround(S,T,P) :- farther(S,T), vacant(T,P), dist(S,DS), destination(PD), DS > |P-PD|. moveAround(s,t,P) :- farther(s,t), vacant(t,P), dist(s,DS), destination(PD), DS > |P-PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,DS), destination(PD), DS > | -PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,4), destination(PD), 4 > | -PD|. moveAround(s,t, ) :- farther(s,t), vacant(t, ), dist(s,4), destination( ), 4 > | - |.

31 Walk Example moveAround(s,t, ) is an action, not a fact Causes robot s to move to st 4 0 321 st 4 0 321

32 Walk Example

33 Logic Programs are Parallel The logic programming representation is implicitly parallel We can derive facts in any order we like, modulo dependencies

34 Walk Example Rule1: dist(S, DS) :- at(S, PS), destination(PD), DS = |PS-PD|. Rule2: farther(S, T) :- neighbor(S, T), dist(S, DS), dist(T,DT), DS >= DT. Rule3: moveAround(S,T,P) :- farther(S,T), vacant(T,P), dist(S,DS), destination(PD), DS > |P-PD|.

35 Other Approaches Some target very specific ensembles – OSL, most wireless sensor network languages Most do not attempt to use logic programming, despite it being a natural match (only LDP, P2) Some are at a significantly lower level (Proto, Hood, etc.)

36 Outline Ensembles Meld By Example Other Examples Proving Properties Plan of Attack

37 Distance Vector Routing type dist(module, module, min ). type ?msg(module, module, string). dist(S, S, 0). dist(S, T, D+1) :- neighbor(S,U), dist(U,T,D). ?msg(U,T,M) :- ?msg(S,T,M), dist(S,T,D), neighbor(S,U), dist(U,T,D-1).

38 Distance Vector Routing ?Msg is a linear fact in the sense of linear logic Linear facts are removed when used ?Msg is deleted from the database when it is sent to the next node

39 Distance Vector Routing c b a dist(a,c,2) dist(a,b,1) ?msg(a,c, “hi”) dist(c,a,2) dist(c,b,1) dist(b,c,1) dist(b,a,1)

40 Distance Vector Routing c b a dist(a,c,2) dist(a,b,1) dist(c,a,2) dist(c,b,1) dist(b,c,1) dist(b,a,1) ?msg(b,c, “hi”)

41 Distance Vector Routing c b a dist(a,c,2) dist(a,b,1) dist(c,a,2) dist(c,b,1) ?msg(c,c, “hi”) dist(b,c,1) dist(b,a,1)

42 Rainbow type level(catom, max int). level(N, 0) :- vacant(N, Bottom). level(N, H) :- neighbor(N, X, SIDE), level(X, H), SIDE != Top, SIDE != Bottom. level(N, BH + 1) :- neighbor(N, X, Bottom), level(X, BH). level(N, TH - 1) :- neighbor(N, X, Top), level(X, TH). setColor2(N, COLOR) :- level(N, COLOR).

43 Gates-Hillman Shape Change type create(cat om, point). type destroy(ca tom, catom). type give(cato m, catom). type resources (catom, int). extern int inTargetS hape(poin t). type in(catom). type out(catom ). type state(cato m, min int). type parent(cat om, catom, int). type child(cato m, catom). type false(cato m, catom). type possibleP arent(cato m, first catom, min int). type notChild(c atom, catom). in(Module) :- position(M odule, Spot), 1 = inTargetS hape(Spot ). possiblePar ent(Modul e2, Module1, Dist2) :- neighbor(M odule1, Module2, _), state(Modul e2, Path), Path = 1, parent(Mod ule1, _, Dist1), Dist2 = Dist1 + 1. possiblePar ent(Modul e2, Module1, Dist) :- neighbor(M odule1, Module2, _), state(Modul e2, Path), Path = 1, state(Modul e1, Final), Final = 0, Dist = 1. child(Modul e2, Module1) :- neighbor( Module1, Module2, _), possiblePar ent(Modul e1, Module2, _). parent(Mod ule1, Module2, Dist) :- neighbor( Module2, Module1, _), child(Modul e2, Module1), possiblePar ent(Modul e1, Module2, Dist). notChild(M odule1, Module2) :- neighbor(M odule1, Module2, _), parent(Mod ule2, Module3, Dist2), parent(Mod ule1, _, Dist1), Dist2 <= Dist1 + 1, Module1 != Module3. out(Module) :- position (Module, Spot), 0 = inTargetSha pe(Spot). state(Modul e, Neutral) :- position (Module, _), Neutral = 2. state(Modul e2, Path) :- neighbo r(Module1, Module2, _), state(M odule1, Final), Final = 0, out(Mo dule2), Path = 1. state(Modul e2, Path) :- neighbo r(Module1, Module2, _), state(M odule1, Path), Path = 1. state(Modul e2, Final) :- neighbo r(Module1, Module2, _), state(M odule1, Final), Final = 0, in(Mod ule2). notChild(Mo dule1, Module2) :- neighbor(M odule1, Module2, _), state(Modul e2, Final), Final = 0. destroy(Mod ule1, Module2) :- state(Modul e1, Path), Path = 1, neighbor(M odule1, Module2, _), resources(M odule1, Destroy), Destroy = 0, resources(M odule2, Destroy), Destroy = 0, forall neighbor(M odule1, N, _) notChild(Mo dule1, N), forall child(Modul e1, Child) false(Modul e1, Child). give(Module 1, Module2) :- neighbor(M odule1, Module2, _), resources(M odule1, Create), Create = 1, resources(M odule2, Destroy), Destroy = 0. create(Mod ule, Spot) :- state(Modul e, Final), 0 = Final, // in final state vacant(Mod ule, Spot), 1 = inTargetSha pe(Spot), resources(M odule, Create), 1 = Create.

44 Outline Ensembles Meld By Example Other Examples Proving Properties Plan of Attack

45 Proving Program Properties Observations Actions Resources (Linear Facts) Facts Meld program state can be viewed as sets of true things

46 Proving Program Properties Running a Meld program is following a set of rules for changing the state

47 Proving Program Properties We can prove properties of Meld programs by assuming a set of observations and showing that a particular fact or action will be derived For walk we can show that if we have two adjacent robots, we can derive either farther(s,t) or farther(t,s) and, therefore, a moveAround action. By induction, we reach the destination. st 4 0 321

48 Proving Program Properties Using the preliminary formal semantics of Meld, I have proved correctness properties for the shape change algorithm The algorithm stays within the union of the original ensemble and the target shape The algorithm can always make progress  No deadlocks, livelocks, etc. The algorithm completes in finite steps

49 Outline Ensembles Meld By Example Other Examples Proving Properties Plan of Attack

50 (1) Formal Meld Semantics Have a preliminary formal semantics Need to update semantics to add linearity Need to understand logical foundations of Meld

51 (2) Meld Implementation Have initial implementation in simulation and on Blinky Blocks Runs 1 order of magnitude slower than hand-coded C++ programs Scales the same as hand-coded C++ programs

52 I/O is most likely bottleneck Equivalent messaging to hand-coded C++ programs (2) Meld Implementation

53 (2) Meld Implementation Need to add support for linearity to implementation Requires that some rules be run atomically  Use transactions! Requires new method for localizing rules

54 (3) Proofs of Program Properties Have proofs of correctness for shape change Does not make use of linearity Need proofs of correctness for Localization Need proofs of correctness for Blinky Block games

55 (4) Thesis Thesis Document Thesis Defense (May 2012?)

56 Questions?

57 Backup

Concise Programs Meld programs typically 20-30x shorter than C++ 58

Efficient Messaging Equal messaging in simple cases Better messaging in complex cases 59

Instructions Per Module 10x in worst case –Still naive compiler implementation 1.9x better on most complex program 60

Equivalent in worst case Much better on most complex program Scaling 61

Download ppt "1 Meld: A Logical Approach to Programming Ensembles A Thesis Proposal by Michael Ashley-Rollman Committee: Seth Goldstein (co-chair, CMU) Frank Pfenning."

Similar presentations