Skip to main content

# Systems

`systems` is a set of tools for describing, running and visualizing
[systems diagrams](https://lethain.com/systems-thinking/).


Installation directions are below, and then get started by [working through the tutorial](./docs/tutorial.md)
or reading through the [Jupyter notebook example](../notebooks/hiring.ipynb) example.

For a more in-depth look at the system syntax, please read [the syntax specification](./docs/spec.md).

## Quickest start

Follow the installation instructions below, then write a system definition
such as:

Start(10)
Start > Middle @ 2
Middle > End

You can then evaluate your system (use `--csv` for an importable format):

cat tmp.txt | systems-run -r 3

Start Middle End
0 10 0 0
1 8 2 0
2 6 3 1
3 4 4 2

See [the tutorial](./docs/tutorial.md) for more detailed starting information.

## Jupyter notebooks

Likely the easiest way to iterate on a model is within a Jupyter notebook.
See an [example notebook here](./notebooks/hiring.ipynb).
[Read this blog post for more installation details](https://lethain.com/systems-jupyter-notebook/).

## Installation

To install via PyPi:

pip install systems

To install for local development:

git clone https://github.com/lethain/systems.git
cd systems
python3 -m venv ./env
source ./env/bin/activate
python setup.py develop

Run tests via:

python3 -m unittest tests/test_*.py

Or run a single test via:

python3 tests/test_parse.py TestParse.test_parse_complex_formula

Please open an Github issue if you run into any problems!

## Using the command line tools

There are four command line tools that you'll use when creating and debugging
systems/

`systems-run` is used to run models:

$ cat examples/hiring.txt | systems-run -r 3
PhoneScreens Onsites Offers Hires Employees Departures
0 0 0 0 0 5 0
1 25 0 0 0 5 0
2 25 12 0 0 5 0
3 25 12 6 0 5 0

`systems-viz` is used to visualize models into [Graphviz](https://www.graphviz.org/):

$ cat examples/hiring.txt | systems-viz
// Parsed
digraph {
rankdir=LR
0 [label=Candidates]
1 [label=PhoneScreens]
// etc, etc, some other stuff
}

Typically you'll pipe the output of `systems-viz` into `dot`, for example

$ cat examples/hiring.txt | systems-viz | dot -Tpng -o tmp.png

`systems-format` reads in a model, tokenizes it and formats the tokens
into properly formatted results. This is similar to `gofmt`, and could
be used for ensuring a consistent house formatting style for your diagrams.
(It was primarily implemented to support generating human readable error
messages instead of surfacing the tokens to humans when errors arise.)

$ cat examples/hiring.txt | systems-fmt
[Candidates] > PhoneScreens @ 25
PhoneScreens > Onsites @ 0.5
# etc etc

`systems-lex` generates the tokens for a given system file.
This is typically most useful when you're extending the lexer
to support new types of functionality, but can also be useful
for other kinds of debugging:

$ cat examples/hiring.txt | systems-lex
('lines',
[('line',
1,
[('comment', '# wrap with [] to indicate an infinite stock that')]),
('line', 2, [('comment', "# isn't included in each table")]),
('line', 3, [('comment', '# integers are implicitly steady rates')]),
('line',
4,
[('infinite_stock', 'Candidates', ('params', [])),
('flow_direction', '>'),
('stock', 'PhoneScreens', ('params', ())),
('flow_delimiter', '@'),
('flow', '', ('params', (('formula', [('whole', '25')]),)))]),
...
]
)


## Error messages

The parser will do its best to give you a useful error message.
For example, if you're missing delimiters:

cat examples/no_delim.txt | systems-run
line 1 is missing delimiter '>': "[a] < b @ 25"

At worst, it will give you the line number and line that is
creating an issue:

cat examples/invalid_flow.txt | systems-run
line 1 could not be parsed: "a > b @ 0..2"

## Uploading distribution

If you are trying to install this on PyPi, the steps are roughly:

python3 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade wheel
python3 -m pip install --user --upgrade twine
python3 setup.py sdist bdist_wheel
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

That should more or less work. :)


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

systems-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

systems-0.1.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file systems-0.1.0.tar.gz.

File metadata

  • Download URL: systems-0.1.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

File hashes

Hashes for systems-0.1.0.tar.gz
Algorithm Hash digest
SHA256 73f299c024d8295fd6ff6df0bf4e18df67530912067e1d8dfe4baa489316621d
MD5 aecc3347c472cad9de7b04d1534cc2d5
BLAKE2b-256 9da5ff64ceed64442d12f95d01fbdedd33d21025e187363c4d43dd121e13750e

See more details on using hashes here.

File details

Details for the file systems-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: systems-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

File hashes

Hashes for systems-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7384871175debcdc2c7cd9f2972fe4b39a81fdbae2a563e6bd574a2dbe90562
MD5 e8e500a28227deacc28d79806f051569
BLAKE2b-256 4a47cad0d9393e7dc6b0079a0a8712e5f27a31d1ae69bb1ddfd462e29a76b0be

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page