Skip to content

Convention A: scipy-style function

Convention A is for Python functions with signature func(t, y, p) or func(t, y).

Example file

Create decay_function.py:

state_vars = ["x"]
param_names = ["k"]
initial_conditions = {"x": 1.0}
parameter_values = {"k": 0.2}


def model(t, y, p):
    x = y[0]
    k = p[0]
    dx = -k * x
    return [dx]

Convert with CLI

ode2sbml convert decay_function.py --output decay.xml --format sbml

The CLI detects the callable named model and maps y[0] to x, p[0] to k, and the returned derivative to the rate rule for x.

Required metadata

state_vars is mandatory for Convention A. param_names, initial_conditions, and parameter_values should also be defined for reliable conversion.

Convert with Python

from decay_function import model, state_vars, param_names, initial_conditions, parameter_values
from ode2sbml import from_function, to_sbml

ir = from_function(
    func=model,
    state_vars=state_vars,
    param_names=param_names,
    initial_conditions=initial_conditions,
    parameter_values=parameter_values,
    model_id="decay_function",
)

to_sbml(ir, "decay.xml")

Keep RHS simple

The AST parser handles assignments and returned derivative names. Avoid hidden state mutation, closures, loops that construct derivatives dynamically, or NumPy-only expressions inside the RHS.