Tellurium Nitro

Your tellurium code, on a Rust engine.

Change one import line. A 1000-species, 3400-reaction model that took 30.9 s to load now loads in 0.30 s, and control coefficients come out exact instead of estimated.

The red line in the left margin is regular tellurium loading that model, drawn to the full height of this page. Nitro's black mark stops near the top. Scroll to see where the red one ends.

S1 → S2 · k1 = 0.5 · S1(0) = 10 S1 10.00S2 0.00
r = te.loada('S1 -> S2; k1*S1; k1 = 0.5; S1 = 10')
r.simulate(0, 10, 100)

Where the time goes, measured

Each task ran in a fresh process. Same models, same settings, regular tellurium 2.2.13.1 with libroadrunner 2.10.0 against Nitro.

regular telluriumload, 1000 species
0.0 s
nitroload, 1000 species
0.00 s
same model, same machine  103× faster
TaskRegularNitroFaster by
Load a 1000-species, 3400-reaction model30.9 s0.30 s103x
Simulate that model, simulate(0, 100, 1000)284 ms38 ms7.5x
Simulate a 40-species model1.14 ms0.22 ms5.2x
Roadrunner's own sosbench models0.02 to 5.3 ms0.01 to 2.8 ms1.9 to 2.3x
Steady state, 40-species model244 ms0.029 ms8,407x
Flux control coefficients, 40-species model590 ms0.017 ms34,228x
Time-series sensitivities, 86 parameters9.31 s14.8 ms631x
Control coefficients for 200 parameter sets251 s1.87 ms134,024x

Measured by the author on one Apple M5 Pro laptop (18 cores). Plain time courses gain 2 to 8x because roadrunner was already efficient there. The huge numbers come from steady states, control coefficients and sensitivities, where roadrunner rebuilds the model or nudges every parameter and re-solves. To check on your own machine and your own model, run python rrs/check.py.

Find your case

You run parameter scans or fit parameters

r.simulateBatch takes a list of values per parameter and runs one simulation for each, on every core, in one call. The model itself is left unchanged.

results = r.simulateBatch(
    {'k1': [0.1, 0.5, 1.0, 2.0]}, 0, 10, 100)
results.shape   # (4, 100, 3): runs x points x columns

You compute control coefficients

Nitro works them out with exact derivatives instead of finite differences: error around 1e-11 instead of 4e-8. For many parameter sets at once, te.controlCoefficients returns all of them in one batched solve.

res = te.controlCoefficients(
    r, {'k1': np.linspace(0.5, 3, 500)})
res['fcc'].shape  # (500, reactions, reactions)

You run sensitivity analysis

Forward sensitivities use exact parameter derivatives and spread the parameters across your cores. 86 parameters went from 9.31 s to 14.8 ms.

s = r.timeSeriesSensitivities(0, 50, 101)

Roadrunner refuses your model

Models with delay(), algebraic rules or fast reactions run. Two of roadrunner's own benchmark models that stop with CV_TOO_MUCH_WORK finish on Nitro, matching a high-precision reference to 1e-8.

r = te.loadSBMLModel('model_with_delay.xml')
r.simulate(0, 100, 1000)   # runs

Your model is big

Nitro reads SBML straight into the engine and compiles only what it needs, so a 1000-species model is ready in about a third of a second instead of half a minute. Good for anyone loading many models, or one large one over and over.

r = te.loada(open('synthetic_1000_species.ant').read())
# 0.30 s on the test laptop

You call roadrunner from C, C++, MATLAB or Julia

The repo builds libroadrunner_nitro_c_api, a C library with the same 350 function names as libroadrunner's C API, using libroadrunner's own headers. It needs no Python, libroadrunner or libsbml. Built and tested on macOS so far.

cargo build --release -p roadrunner_nitro_c_api
cc -I capi/include my_program.c \
   -L target/release -lroadrunner_nitro_c_api

You're on an iGEM team writing your Model page

Write your circuit in Antimony the way the tellurium tutorials show, then scan promoter strengths, degradation rates and inducer levels in one simulateBatch call instead of a for-loop. Steady states and control coefficients tell you which part to tune first.

r = te.loada('''
  J1: -> mRNA; ktx*IPTG^n/(K^n + IPTG^n)
  J2: mRNA -> ; dm*mRNA
  ktx = 2; K = 0.5; n = 2; dm = 0.1; IPTG = 1
''')
r.simulateBatch({'IPTG': [0, 0.1, 0.5, 1, 5]}, 0, 200, 400)

You also do flux balance analysis

te.fba(model) solves flux balance problems from an SBML fbc model. It passes all 34 flux balance cases in the SBML Test Suite.

out = te.fba('ecoli_core.xml')

Install it next to your current tellurium

Nitro installs under its own names (tellurium_nitro, roadrunner_nitro), so your existing tellurium stays as it is. It is not on PyPI yet, and it compiles from source, so you need Rust. Tested on macOS with Apple Silicon. Linux and Windows should work but nobody has confirmed it yet.

  1. Install Rust once: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh (on Windows, run rustup-init.exe from rustup.rs).
  2. Get the code and make a fresh environment:
    git clone https://github.com/gshinkim/tellurium-nitro.git
    cd tellurium-nitro
    python3 -m venv .venv && source .venv/bin/activate
    pip install --upgrade pip
    pip install .
    pip install ./rrs
  3. Check it: python -c "import tellurium_nitro as te; print(te.turbo())" prints True.
  4. Compare against your setup: python rrs/check.py prints both engines' results and timings.

Try it on one of your models

I'm Gio, a high-school student in Washington, and I built Nitro to make the analysis I do with tellurium fast. It has only been tested on my own laptop, so the most useful thing you can do is run your model on it and tell me what happened: the timing, a wrong answer, or a model it chokes on.

Open an issue on github.com/gshinkim/tellurium-nitro. Linux and Windows reports help the most.

Or mail me at gshinkim@gmail.com. The rest of what I make is at gio.kim.