pycopancore.runners.runner module

class Runner(model, *, termination_calls=None)[source]

Bases: _AbstractRunner

Runner-class, it owns the run function which calculates trajectories.

Equations might be of type ODE, explicit, step and event, as stated in the process_types package.

_current_iteration = None

counter for expression evaluation cache

apply_explicits(t)[source]

Apply all Explicit processes.

Parameters:

t (float) – Model time

get_rhs_array(t, value_array)[source]

Return RHS of composite ODE system as an array.

Will be passed to scipy.ode class.

Parameters:
  • t (float) – Model time

  • value_array (array) – array of variable values

Returns:

array of derivatives in same order as value_array

Return type:

array

run(*, t_0=0, t_1, dt, exclusions=None, max_resolution=False, add_to_output=None)[source]

Run the model for a specified time interval.

Run the model by simulating all processes in the right order in a way depending on process type (ODE integration, time stepping, etc.).

Parameters:
  • t_0 (float, optional) – Starting time (default: 0)

  • t_1 (float) – End time

  • dt (float) – Maximal interval between output time points

  • exclusions (list) – List with Variables, that shan’t be included into the output trajectory_dict

Returns:

trajectory_dict – Model trajectory in requested time interval. Keys: ‘t’ (contains the list of time points)

and each Variable object simulated.

Value of trajectory_dict[var]: dict with

key: entity or taxon, value: list of variable values in same order as time points.

Return type:

dict

save_to_traj(targets, add_to_output, max_resolution, dt)[source]

Save simulation results to output dictionary.

Update self.trajectory_dict for some targets.

Parameters:
  • targets (list) – list of targets (variables or dotconstructs) to save

  • add_to_output (list or None) – optional additional list

terminate()[source]

Determine if the runner should stop.

Apply all callables specified in self.termination_calls on their respective instances. If one of them indicates a termination condition by returning True, then return True. Else return False.

Returns:

True if the runner should stop according to one of the callables in self.termination_calls. False, if there are no such callables or if they all return False.

Return type:

boolean