Skip to content

Formal analysis of the execution and initialization of block diagrams of dynamical systems.

Notifications You must be signed in to change notification settings

BlockScience/dynamical-block-diagrams

Repository files navigation

This research and code explores how block diagrams of dynamical systems can be executed by a computer program.

  • dynamical-block-diagrams.pdf formalizes the problem and provides algorithms for executing and validating diagrams.
  • cadCAD.jl contains a software implementation of the execution algorithms.

To see a demo predator-prey simulation, install UnicodePlots (echo 'using Pkg; Pkg.add("UnicodePlots")' | julia), then run

% julia predator-prey.jl
      ┌────────────────────────────────────────┐
   30 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠀⠀⠀⠀⠀⠀│
      │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡆⠀⠀⠀⠀⠀│
      │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⡇⠀⠀⠀⠀⠀│
      │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡞⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⠀⠀│
      │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⠀⠀│
      │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⠀⠀│
      │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⠀⠀│
      │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡇⡇⠀⠀⠀⠀⠀│
      │⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠁⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⡏⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⡇⠀⠀⠀⠀⠀│
      │⣄⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⡇⢸⣄⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⣧⡀⠀⠀⠀⠀│
      │⣿⡀⠀⠀⠀⠀⠀⠀⠀⢸⠀⣷⣇⠀⠀⠀⠀⠀⠀⠀⠀⡇⢸⣸⡀⠀⠀⠀⠀⠀⠀⠀⢸⠀⡇⣇⠀⠀⠀⠀│
      │⡇⢧⠀⠀⠀⠀⠀⠀⠀⡞⠀⣿⢸⡀⠀⠀⠀⠀⠀⠀⢸⠁⢸⡇⣇⠀⠀⠀⠀⠀⠀⠀⡏⠀⣿⢸⡀⠀⠀⠀│
      │⡇⠘⡆⠀⠀⠀⠀⠀⠀⡇⠀⣿⠀⢳⠀⠀⠀⠀⠀⠀⣸⠀⣸⡇⠘⡆⠀⠀⠀⠀⠀⢀⡇⢀⣿⠀⢧⠀⠀⠀│
      │⡇⠀⠙⣆⠀⠀⠀⠀⣸⠁⢸⢹⠀⠈⢳⡀⠀⠀⠀⢀⡇⠀⡇⡇⠀⠙⣆⠀⠀⠀⠀⣸⠀⢸⢸⠀⠈⢳⡀⠀│
    0 │⢳⣀⣀⣈⣓⣦⣤⣴⣃⣀⡼⠘⣆⣀⣀⣙⣲⣤⣤⣞⣀⣠⠇⢳⣀⣀⣈⣓⣦⣤⣴⣃⣀⡞⠘⣆⣀⣀⣙⣲│
      └────────────────────────────────────────┘
      ⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀1 000 000

spinner.jl and consensus-networks.jl contain two other example models.

The rest of this document is an overview of the problem and goes into more detail about the examples.

What are these fish doing?

At the level of detail we're interested in, each fish considers where it is, where the shark is, and decides where to move next. The shark does the same thing looking for the fish. Here's an illustration:

What do we need to know to start simulating this? Knowing only the initial position of the fish is insufficient, as to calculate the next position of the fish we need to know the position of the shark. The same can be said about knowing only the initial position of the shark. So, to simulate this system we need to know the initial position of the fish and shark.

Now its night time. These fish are avoiding the dots, but they can't see very well.

Each fish considers where it is, what dots are in its vision, and decides where to move next. The dots consider where they are and don't move. Determining what dots are in a fish's vision requires knowing where the fish is and where the dots are. Here's an illustration:

But what if we also provide the initial vision? If it isn't consistent with the initial position of the fish, the system will behave strangely. The drawing below shows a fish who's vision isn't initialized at the correct position.

So we'd like to know, given a drawing like the ones above:

  1. When are the initial values sufficient to execute it?
  2. What initial values can lead to inconsistencies?
  3. How can a drawing like the ones above be executed efficiently by a computer program?

To answer these questions I needed to use math, which can be found in dynamical-block-diagrams.pdf. I then implemented the math in cadCAD.jl, to run it:

  1. Install The Julia Programming Language.
  2. Install UnicodePlots by running echo 'using Pkg; Pkg.add("UnicodePlots")' | julia.

There are two examples avaliable. The first example simulates a point being spun around the origin (specification here), but there is a percularity in the system! which causes the point's distance from the origin to decrease over time. Can you find it? To run the simulation and plot the distance from the origin over time, run

% julia spinner.jl
       ┌─────────────────────────────────────────────┐
   500 │⠓⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠙⢦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠈⠳⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
     0 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠲⣄⣀⣀⣀⣀⣀⣀⣀⣀│
       └─────────────────────────────────────────────┘
       ⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀1 000

The second example simulates a consensus network with twenty agents based on Consensus and Cooperation in Networked Multi-Agent Systems by Reza Olfati-Saber, J. Alex Fax, and Richard M. Murray. Each agent starts with a value, and the agents communicate with their neighbors to try and all agree on a single value. For more details see Carolina Riascos's writeup.

julia consensus-network.jl
       ┌────────────────────────────────────────┐
   500 │⣿⣿⣿⡞⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⠿⣿⣿⣽⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⢀⡽⣿⣿⣮⣿⣦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⡿⡞⠀⠀⢉⢿⣻⢿⣿⣿⣷⣶⣶⣦⣤⣤⣤⣤⣤⣤⣤⣤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤│
       │⡇⡇⠀⣰⡿⠛⠉⢉⣠⠴⠒⠋⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⠀⣼⡿⠁⣠⠖⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⣸⣹⠃⡴⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⡇⣏⡞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⢱⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⡿⣸⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⡇⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       │⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
   200 │⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
       └────────────────────────────────────────┘
       ⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀1 000

Future work will document and come up with a nice API for running your own simulations. For now the code is a research prototype and you can see the API in the example files.

About

Formal analysis of the execution and initialization of block diagrams of dynamical systems.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published