Using Sumatra to Manage Numerical Simulations

Daniel Wheeler

May 14, 2013

"Automate away ability to make dumb mistakes. Don't use human based process.",
Tim Clem, Github bigwig, SciPy 2012

Example

1
2
3
4
5
6
## script.py
import time
import sys
wait = float(sys.argv[1])
print 'waiting for ' + str(wait) + '(s)'
time.sleep(wait)

A Workflow

$ python script.py 6
waiting for 6(s)
$ edit script.py ## Add another argument ...
$ python script.py 4 1
waiting for 5(s)

No history.


$ cp script.py script-old.py
$ edit script.py ## Make some changes ...
$ cp script-old.py script-older.py
$ cp script.py script-old.py

Invent scheme for version control.


Version Control

Initialize repository.

$ git init
Initialized empty Git repository in ...

Store a version of the code.

$ git add script.py
$ git commit script.py -m "First commit."
[master (root-commit) 2f12eae] First commit
 1 files changed, 20 insertions(+), 0 deletions(-)
 create mode 100644 script.py

Version Control

Edit and run as before.

$ edit script.py ## Add another argument ...
$ python script.py 4 4
waiting for 8(s)

Store the new version.

$ git add script.py
$ git ci script.py -m "Add another argument ..."
[master 250e0a9] Add another argument ...
 1 files changed, 4 insertions(+), 2 deletions(-)

Version Control

History.

$ git log
250e0a989a19 Add another argument ...
2f12eaef785b First commit.

Query history.

$ git diff 2f12ea..250e0a
-wait = float(sys.argv[1]) 
+wait = float(sys.argv[1]) + \
+    float(sys.argv[2])

Simulation Management

Version control is good, but no record of simulations.

$ python script.py 4 4 ## no record
waiting for 8(s)


Invent scheme for recording simulations.

$ ## record event
$ python script.py 4 4 > output0 
$ git add output0
$ git ci output0 -m "Adding output file."

Version control does not record events.

Sumatra

Create Sumatra repository.

$ smt init sumatrademo
Sumatra project successfully set up
$ smt configure --executable=python \
    --main=script.py

Run simulation using Sumatra.

$ smt run 2 1 ## python script.py 2 1
waiting for 3.0(s)
No data produced.
Created record store

Sumatra

View record.

$ smt list --long
----------------------------------------------
Label            : 622fbd437c4a
Timestamp        : 2013-05-08 12:07:15.8991...
Duration         : 3.02781295776
Repository       : GitRepository at /users/...
Main_File        : script.py
Version          : 250e0a989a19
Script_Arguments : 2 1
Executable       : Python (version: 2.6.6) ...
Launch_Mode      : serial
User             : Daniel Wheeler <daniel.w...

Modify Code

import fipy to view dependencies.

1
2
3
4
5
6
7
8
9
10
## script.py
import time
import sys

import fipy

wait = float(sys.argv[1]) + \
    float(sys.argv[2])
print 'waiting for ' + str(wait) + '(s)'
time.sleep(wait)

Sumatra Web Interface

Andrew Davison

Eats his own dog food.

Why do I like Sumatra?

Doesn't require a wholesale change to the way I work.


This

$ python script.py 3 2

versus this

$ smt run 3 2

Issues


Active Research Example

IPython Notebook and Sumatra

Why is IPython Notebook a Big Deal?


Embed live code with documentation on the web!!!



Dynamic, not static



but sometimes we need static

Blogging

http://wd15.github.io/2013/05/07/extremefill2d/

API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import sumatra as smt
import time
## create record
project = smt.load_project()
record = project.new_record(parameters, ...)
record.datastore.root = '/path/to/data'
## run simulation
runMySimulation(parameters,
                record.datastore.root)
## save record
record.output_data = \
    record.datastore.find_new_data()
project.add_record(record)
project.save()

Future Work