Propagators Edward Kmett Yow! LambdaJam 2016 Semilattices - - PowerPoint PPT Presentation

propagators
SMART_READER_LITE
LIVE PREVIEW

Propagators Edward Kmett Yow! LambdaJam 2016 Semilattices - - PowerPoint PPT Presentation

Propagators Edward Kmett Yow! LambdaJam 2016 Semilattices Commutative: a Commutative: a b = b a Associative: (a b) c = a (b c) Associative: (a Idempotent: a a = a Idempotent:


slide-1
SLIDE 1

Propagators

Edward Kmett Yow! LambdaJam 2016

slide-2
SLIDE 2
slide-3
SLIDE 3
  • Commutative: a
  • Associative: (a
  • Idempotent: a
  • Unital: a

Semilattices

  • Commutative: a ⋁ b = b ⋁ a
  • Associative: (a ⋁ b) ⋁ c = a ⋁ (b ⋁ c)
  • Idempotent: a ⋁ a = a
  • Unital: a ⋁ ⟘ = ⟘ ⋁ a
slide-4
SLIDE 4

Semilattices and Order

  • Ordering: a ⩽ b = ∃c. a ⋁ c = b
slide-5
SLIDE 5

Hasse Diagrams

  • Covering: a ⋖ b = a ⩽ b ⋏ ∄c.a ⩽ c ⩽ b
slide-6
SLIDE 6

Power Sets

slide-7
SLIDE 7

Concept Lattices

man adult woman male female boy girl child ⟘ ⟙

slide-8
SLIDE 8
slide-9
SLIDE 9

Monotonicity

  • Monotonicity: a ⩽ b implies f(a) ⩽ f(b)

Every function in Haskell is monotone

slide-10
SLIDE 10

A between join-semilattices. A propagators for hyperedges, and join- semilattices for nodes. A propagator is a monotone function between join-semilattices. A propagator network is a hypergraph with propagators for hyperedges, and join- semilattices for nodes.

What is a Propagator?

10

slide-11
SLIDE 11

Naïve Propagation

  • Whenever we a node gains information queue all

propagators that lead out of that node to fire.

  • When a propagator fires, calculate its output and

then join them with the values in the targets.

  • Repeat.
slide-12
SLIDE 12

Why Propagate?

  • If every semilattice is finite, then naïve propagation

terminates and yields a deterministic result, regardless of scheduling strategy, redundant firings, or evaluation order.

slide-13
SLIDE 13

“Computer scientists commonly choose models which have bottoms, but prefer them topless.”

slide-14
SLIDE 14

Ascending Chain Condition

  • Ascending Chain Condition (ACC):



 Given a1 ⩽ a2 ⩽ a3 ⩽ …
 
 There exists n such that an = an+1 = an+2 = …



 
 
 
 Every strictly ascending sequence of elements terminates.

slide-15
SLIDE 15

Why Propagate?

  • If every semilattice satisfies an ascending chain

condition, then naïve propagation terminates and yields a deterministic result, regardless of scheduling strategy, redundant firings, or evaluation order.

slide-16
SLIDE 16
slide-17
SLIDE 17

Promises, Promises

slide-18
SLIDE 18

Filters
 (Upward Closed Sets)

slide-19
SLIDE 19

Threshold Reads

slide-20
SLIDE 20

LVish

Lets you:

  • fork :: Par a -> Par ()
  • Create L-Vars
  • Write to Lattice Variables
  • Perform Threshold Reads
slide-21
SLIDE 21

Inflationary Writes Suffice

  • Inflationary: f(x) ⩾ x



 
 
 
 
 
 
 


slide-22
SLIDE 22

Building Propagators

Par computations yield monotone effects

slide-23
SLIDE 23

The Problem with I-Vars

Problem: Par does not play nice. readIVar :: IVar s a -> Par s a but we we want readIVar :: IVar s a -> a Par doesn’t mix well with lazy IO or even laziness in general.
 
 Solution: Build Par with MVars, not a fancy work-stealing deque.

slide-24
SLIDE 24

The Problem with M-Vars

Problem: Too much overhead! Solution: We can build capability-local MVars by hacking up custom primitives and get most of the performance of the unthreaded runtime system while threaded.

slide-25
SLIDE 25

The Problem with L-Vars

Problem: Too many listeners get awoken upon every update! Solution: Decompose them into smaller LVars and finer-grained tasks.

slide-26
SLIDE 26

Breaking Apart L-Vars

  • L-Vars are a sort of filtered channel, the lattice is the filter.
  • We an implement the interesting ones out of a very small

set of core primitives and more threads, reducing contention:

  • Maps from keys to listeners or other lattices for fast

publish-subscribe

  • CmRDT style bump-counters with an integer priority

queue of listeners.

  • These suffice to implement all of the standard CRDTs!
slide-27
SLIDE 27

Building the Primitives

We just need to build a whole new class of wait-free (except for GC), population-oblivious, but capability- aware algorithms in order to execute these primitives efficiently as the number of cores rise! (Out of scope for this talk)

slide-28
SLIDE 28

Decomposing 
 Threshold Reads

T F ⟘ T F ⟘ T F ⟘

slide-29
SLIDE 29

Propagator Applications

Promises SAT Solving Datalog CvRDTs Constraint Programming Unification Interval Arithmetic Integer Linear Programming Cone Programming Hybrid Constraint Linear Programming Functional Reactive Programming Probabilistic Programming Provenance Tracking Incremental Programming unamb …

slide-30
SLIDE 30

Transferring Results

Idea: Steal the features that make dedicated solvers for each of these specialized domains fast and apply them to the other domains!

slide-31
SLIDE 31

SAT Solving

  • Since around 2001, most SAT Solvers use

techniques evolved in zChaff and since honed in solvers such as miniSAT.

  • The techniques we want to steal are:
  • Conflict Directed Clause Learning
  • The Two Watched Literal Scheme
slide-32
SLIDE 32

SAT Solving

(x ⋁ ¬y ⋁ z) ⋀ (¬x ⋁ y ⋁ ¬z) ⋀ (x ⋁ ¬z ⋁ w) Unit Propagation: (x) implies x = True Empty Clauses: () implies we need to learn a clause and backtrack.

slide-33
SLIDE 33

n-Watched Literal Wake-Up

  • Many Propagators do nothing until all but (n-1) of

their inputs are non-⊥: 
 
 p(…,⊥,…) = ⊥

  • Track only n known-to-be ⊥ arguments, only trigger

the propagator when those arguments increase, not when any argument increases.

slide-34
SLIDE 34

n-Watched Literal Collection

When all of the inputs of a propagator are covered by top, the propagator can never fire again and can be removed from the network.
 
 p(x1,x2,…,xn)
 ∀n. xn ⋖ ⟙

  • Covering: a ⋖ b = a ⩽ b ⋏ ∄c.a ⩽ c ⩽ b
slide-35
SLIDE 35

Constraint Programming

  • x ∈ {1..5}
  • y ∈ {1..5}
  • x <= y
  • Establish “arc consistency”
  • Guess and backtrack like SAT
slide-36
SLIDE 36

AC-3

Input: A set of variables X A set of domains D(x) for each variable x in X. D(x) contains vx0, vx1... vxn, the possible values of x A set of unary constraints R1(x) on variable x that must be satisfied A set of binary constraints R2(x, y) on variables x and y that must be satisfied function ac3 (X, D, R1, R2) for each x in X D(x) := { x in D(x) | R1(x) } worklist := { (x, y) | there exists a relation R2(x, y) or a relation R2(y, x) } do select any arc (x, y) from worklist worklist := worklist - (x, y) if arc-reduce (x, y) if D(x) is empty return failure else worklist := worklist + { (z, x) | z != y and there exists a relation R2(x, z) or a relation R2(z, x) } while worklist not empty function arc-reduce (x, y) bool change = false for each vx in D(x) find a value vy in D(y) such that vx and vy satisfy the constraint R2(x, y) if there is no such vy { D(x) := D(x) - vx change := true } return change

slide-37
SLIDE 37

Constraint Programming

  • The classic algorithm for establishing arc

consistency (AC-3) is a form of propagation.

  • Unit propagation is a special case.
slide-38
SLIDE 38

Datalog: Naïve Evaluation

ancestor(X,Y) :- parent(X,Y) ancestor(X,Z) :- ancestor(X,Y), parent(X,Z) parent(bob, nancy). parent(nancy, drew). parent(dan, nancy).

slide-39
SLIDE 39

Datalog: Seminaïve Evaluation

ancestor(X,Y) :- parent(X,Y) ancestor(X,Z) :- ancestor(X,Y), parent(X,Z) Δn-1ancestor(X,Z) :- Δnancestor(X,Y), parent(X,Z) ancestor 1 2 1 2 parent

slide-40
SLIDE 40

Implementing Δ

  • We need to store a Δ since the last time we fired each
  • utbound propagator.
  • If no obvious scheme is available, there is a universal

construction good for cells with many outbound propagators.

  • Build a mutable tree of outbound propagators, tracking

monoidal annotations in the tree. Δ is a prefix sum. Merge updates into the tree on the left.

  • Optimize this further to share leaves when there is no

update in between.

slide-41
SLIDE 41

Topological Ordering

  • Evaluating propagators in topological order

maximizes the size of the Δs used, reducing the number of times we join against full tables.

  • Adding propagators or nodes to the network requires

us to be able to compute a dynamic topological

  • rdering. This requires Θ(√n) time per update to

store perfectly, but we don’t need perfection.

  • I conjecture there is a k-optimal evaluation strategy,

for a small k.

slide-42
SLIDE 42

Stratification

  • Datalog can be extended with “stratified negation”
  • r more generally with arbitrary “stratified

aggregation” operations.

  • These special edges aren’t allowed to participate in

a cycle in the graph. If they do, blow up the world.

  • These special “stratifying” propagators need not be

monotone.

slide-43
SLIDE 43

CALM Conjecture

“A program has an eventually consistent, coordination-free execution strategy if and only if it is expressible in (monotonic) Datalog”

— Joe Hellerstein (Consistency and Logical Modularity)

slide-44
SLIDE 44

Datalog Lessons

  • Seminaïve Evaluation
  • Topological Ordering
  • Stratification
  • Different justification for global termination.
  • The CALM Conjecture
slide-45
SLIDE 45

CRDTs

  • Convergent replicated data types can be viewed a

living in a distributed propagator network.

  • Lindsey Kuper and Chris Meiklejohn (among
  • thers) have been exploring this design space.
slide-46
SLIDE 46

Further Topics

  • Pure threshold reads let us rederive and generalize

Conal Elliott’s work on unamb

  • We can build a form of lazy sequential

computations that can make more computations demand driven, which also always build monotone propagators.

slide-47
SLIDE 47

.

?

Any Questions

slide-48
SLIDE 48

Resources

  • http://web.mit.edu/~axch/www/art.pdf
  • https://www.cs.indiana.edu/~lkuper/papers/lvars-fhpc13.pdf
  • https://lasp-lang.org/
  • https://github.com/ekmett/propagators
  • https://github.com/ekmett/models
  • https://github.com/ekmett/concurrent
  • https://github.com/ekmett/promises
  • https://hackage.haskell.org/package/unamb
slide-49
SLIDE 49

Extra Slides

slide-50
SLIDE 50

Wait-Freedom

  • bstruction-free. finite time if nobody else is running

lock-free. some worker finishes in finite time wait free. every worker finishes in finite time wait free bounded O(f(n)). every worker finishes in time O(f(n)) time when there are n workers. wait free population oblivious is wait free bounded O(1)

slide-51
SLIDE 51

Provenance Tracking