Skip to content

simulator.executor_copasi

The executor of COPASI runs a plan on a model of COPASI.

It has the semantics of the executor of roadrunner, see sbmlsim.simulator.executor, so the results of both engines are comparable:

  1. The model is initialized with the pre-initialization values, see CopasiSBMLModel.initialize, which sets the initial state as loaded back first, so nothing of an earlier simulation is left, also no event of the model which was pending at its end.
  2. The events whose trigger is false before the time 0 and true in the initial state fire at the start, in the initial state before a change at the start, with the events they trigger, see start_events; with a presimulation at its start, the time 0. The output at the start has the state after them, as in roadrunner and AMICI.
  3. A presimulation integrates from the time 0 until the rates of change vanish, see steady_state.
  4. The interval is split at the times of the changes. At the start of a segment the changes of its time are applied, every value evaluated with the state at that time before any target is set, see sbmlsim.simulator.changes.apply_changes; after a change after the start (or at the start after a presimulation) the events whose triggers the change made true fire, which COPASI does not see, see sbmlsim.simulator.changes.fire_events. At the start COPASI evaluates the triggers of the events in the initial state, as roadrunner after its reset, so a change at the start does not fire an event.
  5. COPASI integrates (LSODA) in absolute time: the first segment from the state the model is initialized to, every later one continues from the state the one before it ended in (processRaw(False)); the states of the triggers are set from the current values before every run (resetEventsFound), since COPASI does not see the values the executor sets between two runs, see check_supported for the delayed events. LSODA finds no crossing of a comparison whose root function is exactly 0 when it starts, so before a run from a state in which a comparison of a trigger is exactly at its threshold with its value as written, e.g. X > 2 after a change which sets X = 2, or time > 2 from a change at 2, the comparisons at their threshold are shifted by a little (CopasiSBMLModel.shift_comparisons) and the event fires when the comparison turns, right after the start or after a plateau, as in roadrunner; so are the ones which an event of the model sets to their threshold in a run, which is then integrated again in pieces (_TimeCourse._integrate). A delayed event COPASI has scheduled stays pending across the runs, and one closer after the start of a run than LSODA integrates, e.g. at the end after the stop before it, fires at its time from the state at the start (_TimeCourse.steps). The output of OutputMode.TIMES is the plan times of the segment, of OutputMode.INTEGRATOR the steps of LSODA, which have an event of the model as two rows at its time, the states before and after it. A change after the start, the one at the end included, has two rows at its time, the state before the change, which ends the segment before it, and the state after it, which starts the next one.
  6. A segment of a model with events stops just before its end, see sbmlsim.simulator.executor.segment_stop, so an event of the model at the time of a change fires after the change; a segment too short for LSODA, whose condition is the one of CVODE, is not integrated, its state is the one at its start, see sbmlsim.simulator.executor.integrable.
  7. An event of the model within the resolution of the time after the end is at the end, see _TimeCourse.event_at_the_end: the steps of the integrator have it as two rows, an output time at the end the state after it. The steady state after the end starts after it.

Steps 4, 6 and 7 are the segments of sbmlsim.simulator.segments, which the executor of AMICI shares.

Known differences to roadrunner:

  • roadrunner evaluates the triggers of the events when the model is initialized, at the time 0, also for a simulation from a negative start; COPASI evaluates them at the start.
  • An event whose trigger is false before the time 0 and which a pre-initialization makes true, e.g. a dose dose > 0 with dose set before the initialization, fires at the start in COPASI and AMICI, as in libroadrunner after resetAll and in the SBML Test Suite; the executor of roadrunner does not fire it (#439).
  • roadrunner fires a delayed event of the model late in the steps of the integrator, at the end of the next step of CVODE (roadrunner #1382); COPASI at its time.
  • roadrunner keeps an event pending after the steps of the integrator found its root after the end, which the executor of roadrunner applies after the run (apply_pending_step_event); COPASI keeps none.
  • roadrunner integrates a model which does not read the time in local time, every segment from its time 0; COPASI integrates every model in absolute time.
  • An event whose trigger becomes true within the rounding of the state one unit in the last place before the end (e.g. X >= 8 of X' = 1 from 2 at the end 6) fires before it in roadrunner, whose steps have one row at the end, the state after it; COPASI fires it at the end, its steps have the states before and after it at the end.
  • A model with a delayed event (an SBML delay of an event) is refused in a simulation with a change after the start or a presimulation (NotImplementedError): COPASI keeps a delayed event pending across the values the executor sets between two runs, and setting the states of the triggers from them brings back an event whose trigger a change made false, or loses one which a crossing after the change schedules, which roadrunner cancels and schedules. Without such writes COPASI simulates the delayed events itself.
  • An event of the model which sets a comparison of a trigger exactly to its threshold in an integration of COPASI, e.g. E: X = 0 and G: X > 0: the run is walked again in pieces which end one resolution of the time after the events of the model, so G fires up to that much later than in roadrunner, see _TimeCourse._integrate. In a model with a delayed event a crossing COPASI missed this way raises, one which is undone by the end of the run is not seen.
  • A comparison of a trigger which a change sets to its threshold turns up to one resolution of the time late, at least by two units in the last place of its threshold over the rate of its operands, see CopasiSBMLModel._threshold_shift. One on a plateau, whose operands do not move when the run starts, is shifted by at least the absolute tolerance of LSODA: at a threshold 0, operands which rise more slowly than that tolerance per unit of the time after the plateau turn late, e.g. 1.8e-3 at a rate of 1e-9, where the operands are below the tolerance and roadrunner fires late as well.
  • LSODA in COPASI fails a run with an event in it whose critical time it rounds behind the end (TCRIT (=R1) behind TOUT (=R2)); such a run is integrated again in halves, see _TimeCourse._once.
  • roadrunner does not fire an event whose trigger, e.g. X > 0.5 && X < 0.8, is true only within one step of CVODE, which finds the roots of both comparisons in it; COPASI fires it.
  • The steps of LSODA in COPASI can fail on a delayed event whose time LSODA has stepped past when it becomes its critical time (TCRIT behind TCUR), which raises a RuntimeError with the message of COPASI; an output of times integrates such a model.
  • COPASI integrates with LSODA and one absolute tolerance for every state, see CopasiSBMLModel.set_integrator_settings; the steps of the integrator differ between the engines, the rows at the changes, at the events and at the end correspond.

The delay csymbol is refused when the model is loaded, see CopasiSBMLModel.

execute

execute(plan, model, selections)

Run a plan on a model of COPASI.

The contract of sbmlsim.simulator.executor.execute: the output has two rows at the time of a change after the start, the state before the change and the state after it, and the steps of the integrator have two at an event of the model, see the module.

Parameters:

Name Type Description Default
plan Plan

the plan, compiled against the model.

required
model CopasiSBMLModel

the model.

required
selections Sequence[str]

the columns of the result, time is added as the first column if it is missing.

required

Returns:

Type Description
TimecourseResult

The result, with the time shifted by plan.time_shift.

Raises:

Type Description
SteadyStateError

if the presimulation does not reach a steady state.

RuntimeError

if COPASI fails to integrate, with its message.

start_events

start_events(model, time)

Fire the events whose trigger is false before the time 0 and true at the start.

roadrunner fires them at the start in the initial state, with the events they trigger in the order of their priorities, before a change at the start, so the output at the start has the state after them; COPASI does not fire them, their triggers are true before the time 0 in the SBML it loads, see CopasiSBMLModel.start_events. Also an event which a pre-initialization makes true, e.g. a dose dose > 0, fires, which the executor of roadrunner does not (#439).

Parameters:

Name Type Description Default
model CopasiSBMLModel

the model, initialized.

required
time float

the time of the start.

required

check_supported

check_supported(plan, model)

Refuse a plan which COPASI does not simulate as roadrunner.

execute checks every plan, and Simulator.run the plan of the first point of every simulation and model before it runs a point, see sbmlsim.simulator.engines.check_plan.

COPASI multiplies the stoichiometries of the species with a conversion factor by the value of the factor when it imports the model, see sbmlsim.model.model_copasi._compile_conversion_factors, so a plan which sets a conversion factor or an entity its initial assignment reads (CopasiSBMLModel.conversion_factors), before the initialization or at a time, is refused.

COPASI keeps the events of the model with a delay pending across the runs of a plan, and the states of the triggers are set from the values the executor writes between two runs (resetEventsFound), which brings a pending event back whose trigger a change made false, or loses the one a crossing after the change schedules, where roadrunner cancels and schedules them. A model with a delayed event is simulated natively in a plan without such writes, without a change after the start and without a presimulation.

Raises:

Type Description
UnsupportedModelError

a NotImplementedError, for a plan which sets a conversion factor or an entity its initial assignment reads, and for a model with a delayed event and a plan with a change after the start or a presimulation.

steady_state

steady_state(model, plan, start=0.0)

Integrate a model until its rates of change vanish, see sbmlsim.simulator.segments.steady_state.

Parameters:

Name Type Description Default
model CopasiSBMLModel

the model in the state the integration starts from.

required
plan SteadyStatePlan

the steady state.

required
start float

the time the integration starts at.

0.0

Returns:

Type Description
float

The time the steady state was reached at.

Raises:

Type Description
SteadyStateError

if the steady state is not reached by max_time.

RuntimeError

if COPASI fails to integrate, with its message.