simulator.formula¶
Formulas of the math of PEtab over the selections of roadrunner.
A formula is a string of the math of PEtab whose symbols are selections of
roadrunner: S is the amount of a species, [S] its concentration and time
the time. The brackets are not math, so [S] is replaced by an identifier
before the formula is parsed and mapped back afterwards; so is an identifier
with a dot, the parameter of a PK observable, e.g. hctz.cmax.
A formula is compiled to a numpy function once and cached, a CompiledFormula
is not pickled: a plan keeps the formula as a string.
The formulas of observables extend the math by four reductions over the time
of one simulation, see reduce_formula and evaluate_reduced: max(x) and
min(x) with a single argument (with two or more they are the elementwise
functions of PEtab), mean(x), the time weighted mean, and at(x, t), the
value at a time. A value is an array whose last axis is the time of a
simulation, so a scan of many simulations reduces every simulation on its
own. The formulas of data share reduce_formula and have only max and
min, which reduce a labelled array along its dimension of the time or of
the rows of a dataset by name, see sbmlsim.data.evaluate_function.
CompiledFormula
dataclass
¶
A formula compiled to a numpy function of its symbols.
Attributes:
| Name | Type | Description |
|---|---|---|
formula |
str
|
the formula as it was given. |
symbols |
tuple[str, ...]
|
the selections the formula reads, sorted. |
evaluate
¶
Evaluate the formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Sequence[float]
|
the values of the symbols, in the order of |
required |
Returns:
| Type | Description |
|---|---|
float
|
The value of the formula. |
apply
¶
Evaluate the formula on values of any type numpy operates on.
Unlike evaluate, the result is not converted to a float, arrays and
the quantities of pint keep their shape and their units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Sequence[Any]
|
the values of the symbols, in the order of |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The value of the formula. |
evaluate_array
¶
Evaluate the formula on arrays of the values of its symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Sequence[ndarray]
|
the values of the symbols, in the order of |
required |
size
|
int
|
the number of values, which a formula without symbols needs. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The |
Reduction
dataclass
¶
A reduction over the time of a simulation, see reduce_formula.
Attributes:
| Name | Type | Description |
|---|---|---|
symbol |
str
|
the identifier which stands for its value in the formula. |
function |
str
|
|
arguments |
tuple[str, ...]
|
the formulas of its arguments, which read the symbols of the reductions inside of them. |
ReducedFormula
dataclass
¶
A formula whose reductions are replaced by symbols, see reduce_formula.
Attributes:
| Name | Type | Description |
|---|---|---|
formula |
str
|
the formula as it was given. |
outer |
str
|
the formula with every reduction replaced by its symbol. |
reductions |
tuple[Reduction, ...]
|
the reductions, an inner one before the one whose argument it is. |
outer_symbols
property
¶
Get the identifiers the formula reads outside of its reductions.
compile_formula
cached
¶
Compile a formula, see the module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
the formula. |
required |
Returns:
| Type | Description |
|---|---|
CompiledFormula
|
The compiled formula. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the formula is not valid math of PEtab. |
reduce_formula
cached
¶
Find the reductions of a formula, see the module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
the formula. |
required |
Returns:
| Type | Description |
|---|---|
ReducedFormula
|
The formula with its reductions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the parentheses are not balanced, a reduction has not its number of arguments or a part of the formula is not valid math. |
evaluate_reduced
¶
Evaluate a formula with reductions over the time of every simulation.
A value is a number, a numpy array or a quantity of pint. The last axis of
an array is the time of a simulation and the axes before it are the
simulations, e.g. (n_points, n_rows) padded with NaN in a worker or
(*dims, time) of a scan. A number, or an array whose last
axis has one element, is a value per simulation, which is constant in
time. A reduction keeps its axis with one element, so its value broadcasts
against the timecourses, and keeps the unit of its argument:
max(x),min(x): the largest and the smallest value, ignoringNaN;mean(x): the trapezoidal integral divided by the time between the first and the last time point, the value itself for a single time point; the two time points of the states before and after a change at its time are an interval without time, which adds nothing;at(x, t): the value at the timet, a number or a value per simulation, interpolated linearly; the value after a change or an event of the model at its time, toward the state before a change at a time before it (time points at mosttoleranceapart are a jump, seesbmlsim.result.timecourse.grid_weights) andNaNoutside of the time points.
The times which are not finite, the padding (NaN) and the steady state
after the end (inf), are no time points of a reduction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
the formula. |
required |
values
|
Mapping[str, Any]
|
the values of its identifiers. |
required |
time
|
ndarray | None
|
the time points of the timecourses, of their shape; |
None
|
tolerance
|
float | ndarray
|
the resolution of the time of every simulation, a number or
an array of the shape of the simulations, e.g. |
0.0
|
changes
|
Sequence[ndarray] | None
|
the times of the changes after the start of every
simulation, in the order of the simulations flattened, see
|
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The value of the formula. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the formula is not valid, reads an identifier without a
value, reduces a timecourse with |