Self-Adjusting Computation Robert Harper Carnegie Mellon University (With Umut Acar and Guy Blelloch)

Slides:



Advertisements
Similar presentations
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Advertisements

Justification-based TMSs (JTMS) JTMS utilizes 3 types of nodes, where each node is associated with an assertion: 1.Premises. Their justifications (provided.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
an incremental version of A*
Fast Algorithms For Hierarchical Range Histogram Constructions
1 Program Slicing Purvi Patel. 2 Contents Introduction What is program slicing? Principle of dependences Variants of program slicing Slicing classifications.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Chapter 6: Design of Expert Systems
CS 312 Spring 2004 Lecture 18 Environment Model. Substitution Model Represents computation as doing substitutions for bound variables at reduction of.
Transaction Management and Concurrency Control
Hashing Text Read Weiss, §5.1 – 5.5 Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions Collision.
Convex Hull Algorithms for Dynamic Data Kanat Tangwongsan Joint work with Guy Blelloch and Umut Acar (TTI-C)
Teaching Geometric Algorithms to Gracefully “Walk” and “Jump” Kanat Tangwongsan ALADDIN 2005 Joint work with Umut Acar, Guy Blelloch, and Jorge Vittes.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Data Warehouse View Maintenance Presented By: Katrina Salamon For CS561.
Maria-Cristina Marinescu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology A Synthesis Algorithm for Modular Design of.
Maria-Cristina Marinescu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology High-level Specification and Efficient Implementation.
Reverse Engineering State Machines by Interactive Grammar Inference Neil Walkinshaw, Kirill Bogdanov, Mike Holcombe, Sarah Salahuddin.
Managing Software Quality
Parallel Programming Models Basic question: what is the “right” way to write parallel programs –And deal with the complexity of finding parallelism, coarsening.
© SERG Dependable Software Systems (Mutation) Dependable Software Systems Topics in Mutation Testing and Program Perturbation Material drawn from [Offutt.
Chapters 7, 8, & 9 Quiz 3 Review 1. 2 Algorithms Algorithm A set of unambiguous instructions for solving a problem or subproblem in a finite amount of.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Compiler Construction
Stephen P. Carl - CS 2421 Recursion Reading : Chapter 4.
Software Development Cycle What is Software? Instructions (computer programs) that when executed provide desired function and performance Data structures.
SE: CHAPTER 7 Writing The Program
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
CSC 221: Recursion. Recursion: Definition Function that solves a problem by relying on itself to compute the correct solution for a smaller version of.
1 HASHING Course teacher: Moona Kanwal. 2 Hashing Mathematical concept –To define any number as set of numbers in given interval –To cut down part of.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Automated Patch Generation Adapted from Tevfik Bultan’s Lecture.
Homogeneous tuples What are they? –S 2 = S x S –S n = S x S x … x S Cardinalities –#(S 2 )= (#S) 2 –#(S n )= (#S) n –#(S 0 )= (#S) 0 =1 What is S 0 ? –It.
Requirements Engineering
Review of Parnas’ Criteria for Decomposing Systems into Modules Zheng Wang, Yuan Zhang Michigan State University 04/19/2002.
Streaming Big Data with Self-Adjusting Computation Umut A. Acar, Yan Chen DDFP January 2014 SNU IDB Lab. Namyoon Kim.
(c) , University of Washington18a-1 CSC 143 Java Searching and Recursion N&H Chapters 13, 17.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Mutation Testing Breaking the application to test it.
Sequential Processing to Update a File Please use speaker notes for additional information!
SQL Triggers, Functions & Stored Procedures Programming Operations.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
MANAGEMENT INFORMATION SYSTEM
All-pairs Shortest paths Transitive Closure
Regression Testing with its types
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2017.
Transaction Management and Concurrency Control
CS 326 Programming Languages, Concepts and Implementation
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Organization of Programming Languages
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Winter 2013.
Structural testing, Path Testing
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2013.
August 20, 2002 (joint work with Umut Acar, and Guy Blelloch)
Fault Injection: A Method for Validating Fault-tolerant System
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Autumn 2018.
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
UNIT V Run Time Environments.
June 12, 2003 (joint work with Umut Acar, and Guy Blelloch)
Regression Testing.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2019.
Presentation transcript:

Self-Adjusting Computation Robert Harper Carnegie Mellon University (With Umut Acar and Guy Blelloch)

The Problem Given a static algorithm, obtain a dynamic, or incremental, version. –Maintain a sorted list under insertions and deletions –Maintain a convex hull under motions of the points. –Maintain semantics of a program under edits.

Example: Sorting Input: Output: 5, 1, 4, 2, 31, 2, 3, 4, 55, 1, 2, 31, 2, 3, 5

Dynamic Algorithms There is a large body of work on dynamic / incremental algorithms. –Specific techniques for specific problems. Our interest is in general methods, rather than ad hoc solutions. –Applying them to a variety of problems. –Understanding when these methods apply.

Self-Adjusting Computation Self-adjusting computation is a method for “dynamizing” a static algorithm. –Start with a static algorithm for a problem. –Make it robust under specified changes. Goal: “fast” response to “small” change. –“Fast” and “small” are problem-specific! –As ever, the analysis can be difficult.

Self-Adjusting Computation Generalizes incremental computation. –Attribute grammars, circuit models assume static control dependencies. –SAC permits dynamic dependencies. Combines algorithmic and programming language techniques. –Linguistic tools to ensure correctness relative to static algorithm. –Algorithmic techniques for efficient implementation.

Self-Adjusting Computation Adaptivity: Propagate the effects on the output of a change to the input. Selective Memoization: Reuse old results, provided they are valid after change. Adaptive Memoization: Reuse old results, even though they may not be valid after change.

Model of Computation Purely functional programming model. –Data structures are persistent. –No implicit side effects or mutation. Imperative model of change. –Run on initial input to obtain output. –Make modifications to the input. –Propagate changes to the output.

Model of Computation Steps of Execution Stages of Revision (pure/persistent) (impure/ephemeral)

A Simple Example: Map data cell = nil | cons of int £ list and list = cell fun map (l:list) = map’(l) and map’(c) = case c of nil ) nil | cons (h, t) ) cons (h+10, map t)

Static Version of Map Running map on the input list … … yields the new output list

Dynamic Version of Map To permit insertions and deletions, lists are made modifiable: data cell = nil | cons of int £ list and list = cell mod

Dynamic Version of Map Insertion changes a modifiable:

Dynamic Version of Map We’d like to obtain the result …

Dynamic Version of Map Can we update the result in O(1) time? –Make one new call to map. –Splice new cell into “old” result. Yes, using self-adjusting computation! –Adaptivity: call map on the new node. –Memoization: re-synchronize with suffix.

Adaptivity Overview To make map adaptive, ensure that –Changes invalidate results that depend on the modified value. –Computations dependent on a change are re-run with the “new” value. Two key ideas: –Make access to modifiables explicit. –Maintain dependencies dynamically.

Adaptive Map data cell = nil | cons of int £ list and list = cell mod fun map (l:list) = mod (let mod c = l in write(map’ c)) and map’ c = case c of nil ) nil | cons (h, t) ) cons (h+10, map t) Allocate new modifiable Read old modifiable Write new modifiable

Adaptive Map Modification to input: Modified cell is argument of map’, which must be re-run.

Adaptive Map Associated output is invalidated, and suffix is re-created. Result of map’ written here

Adaptive Programming Crux: dependencies among modifiables. –Writing a modifiable invalidates any computation that reads it. –One read can be contained within another. Dependencies are fully dynamic! –Cells are allocated dynamically. –Reads affect control flow.

Adaptive Programming Change propagation consists of –Re-running readers of changed cells. –Updating dependencies during re-run. To ensure correctness, –All dependencies must be accurately tracked. –Containment ordering must be maintained. Linguistic tools enforce these requirements!

Type System for Adaptivity The type  mod is a modality. –From lax modal logic. –And therefore forms a monad. Two modes of expression: –Stable: ordinary functional code, not affected by changes. –Changeable: affected by change, will be written to another modifiable.

Type System for Adaptivity Elimination form for  mod: let mod x:  = s in c end –Read modifiable given by s. –Bind value to x: , evaluate c. Makes dependencies explicit: –Records read of given modifiable. –Re-run c with new x if changed. –Reads within c are contained in this read.

Type System for Adaptivity Execution maintains a trace of adaptive events. –Creation of a modifiable. –Writes to a modifiable. –Reads of a modifiable. Containment is recorded using Sleator-Dietz order maintenance algorithm. –Associate time intervals with events. –Re-run reader within the “old” time interval. –Requires arbitrary fractionation of time steps.

Adaptive Map Responds to insertion in linear time:

Memoizing Map For constant-time update, we must re- synchronize with the old result. –Results after insertion point remain valid despite change. –Re-use, rather than recompute, to save time. Selective memoization is a general technique for achieving this.

Selective Memoization Standard memoization is data-driven. –Associate with a function f a finite set of ordered pairs (x, f(x)). –Consult memo table before call, update memo table after call. Cannot handle partial dependencies. –Eg, read only first 10 elements of an array. –Eg, use an approximation of input.

Selective Memoization Selective memoization is control-driven. –Guided by the exploration of the input. –Sensitive to approximations. Associate results with control paths. –“Have I been here before?” –Control path records dependencies of output on input.

Memoized Adaptive Map fun map (l:list) = mod (let mod c = l in write(map’ c)) and memo map’ c = mcase c of nil ) return (nil) | cons (h, t) ) let !h’=h and !t’=t in return(cons (h’+10, map t’)) Depends on nil/cons, head, and tail. Depends only on nil/cons.

Memoized Adaptive Map With selective memoization we obtain Constant-time update after insertion

Memoized Programming Selective memoization requires an accurate record of I/O dependencies. –Which aspects of the input are relevant to the output? –Sensitive to dynamic control flow. Linguistic support provides –Specification of approximations. –Accurate maintenance of dependencies.

Type System for Memoization Based on S4 modal logic for necessity. –Truth assumptions: restricted variables. –Validity assumptions: ordinary variables. Modality !  means value is necessary. –!(int £ int) : both components necessary –!int £ !int : either, neither, or both parts needed, depending on control flow.

Type System for Memoization Key idea: variables are classified as restricted or unrestricted. –Arguments to memoized functions are restricted. –Results of memoized functions may not involve restricted variables. –Elimination form for !  binds an unrestricted variable. Ensures that relevant portion of input must be explicitly “touched” to record dependency.

Selective Memoization fun map (l:list) = … and memo map’ c = mcase c of nil ) return (nil) | cons (h, t) ) let !h’=h and !t’=t in return(cons (h’+10, map t’)) Restricted Unrestricted

Adaptive Memoization Effectiveness of memoization depends on preserving identity. –Modifiables compare “by reference”. –Copying a modifiable impedes re-use. This conflicts with the functional programming model. –Eg, functional insertions copy structure. –Undermines effectiveness of memoization.

Adaptive Memoization Consider again applying map to: We obtain the new modifiable list

Adaptive Memoization Now functionally insert an element:

Adaptive Memoization Running map on result yields

Adaptive Memoization Subsequent runs propagate the effect:

Adaptive Memoization Ideally, we’d re-use the “old” prefix! But what justifies this?

Memoization and Adaptivity Consider a memoized “copy” function: fun copy (!m : int mod) = return (mod (let mod x = m in x)) What happens if we modify m? –Value might change “under our feet”. –But adaptivity restores correctness!

Memoization and Adaptivity Initial run of copy: Calls to copy at later stages return “old” cell, which is updated by adaptivity

Adaptive Memoization Permit inaccurate memoization. –Allows recovery of “old” cells. –Cached result will be incorrect. Adapt incorrect result to restore correctness. –Use change propagation to revise answer. –Only sensible in conjunction with adaptivity!

Adaptive Memoization fun map (l:list) = … and memo map’ c = mcase c of nil ) return (nil) | cons (h, t) ) let !h’=h in let ?t’=t in return(cons (h’+10, map t’)) Do not record dependency! Memo match only on nil/cons and head.

Adaptively Memoized Map On the initial input … Map yields the output …

Adaptively Memoized Map After a functional update, the input is

Adaptively Memoized Map Now maps yields the inaccurate result: Memo matches on head value 2, yielding old result, with incorrect tail Result of map Tail is incorrect!

Adaptively Memoized Map Restore accuracy by self-assignment:

Adaptively Memoized Map Change to input propagates to output

Some Results Quicksort: expected O(lg n) update after insert or delete at a random position. Mergesort: expected O(lg n) update after insert or delete. Tree Contraction: O(lg n) update after adding or deleting an edge. Kinetic Quickhull: O(lg n) per event measured.

Ongoing Work When can an algorithm be dynamized? –Consider edit distance between traces for a class of input changes. –Small edit distance suggests we can build a dynamic version using SAC. What is a good semantic model? –Current methods are rather ad hoc. –Are there better models?

Conclusion Self-adjusting computation is a powerful method for building dynamic algorithms. –Systematic methodology. –Simple correctness criteria. –Easy to implement. The interplay between linguistic and algorithmic methods is vital! – is also a powerful algorithmic tool!

Questions?