gillespy2.solvers.cpp package

Subpackages

Submodules

gillespy2.solvers.cpp.c_decoder module

class gillespy2.solvers.cpp.c_decoder.BasicSimDecoder(trajectories: ndarray)[source]

Bases: SimDecoder

Simple decoder which returns the results as a complete string.

get_output()[source]

Returns the fully-populated NumPy array containing the completed simulation data. Assumes that the subprocess has already completed.

Returns:

Tuple containing the 3D NumPy array of results, and the time stopped.

read(output: BufferedReader, **kwargs)[source]

Accepts a buffered reader from stdout of a subprocess. Contents of the given reader are processed and made available through get_output().

Blocks until the output of the buffered reader has been read completely.

Parameters:

output (io.BufferedReader) – Reader provided from the stdout member of an open Popen class.

class gillespy2.solvers.cpp.c_decoder.IterativeSimDecoder(trajectories: ndarray, callback=None)[source]

Bases: SimDecoder

Output decoder for processing the output at regular intervals. An IterativeSimDecoder object can be provided a callback. Each time a new timestep is received and processed, the callback is invoked,

and is provided with the timestep value and output time.

Intended for handling just-in-time output.

get_output() tuple[numpy.ndarray, int][source]

Returns the fully-populated NumPy array containing the completed simulation data. Assumes that the subprocess has already completed.

Returns:

Tuple containing the 3D NumPy array of results, and the time stopped.

read(output: BufferedReader, page_size=256, **kwargs)[source]

Read and process output from the provided buffer, one timestep at a time. Any registered callbacks will be invoked on each iteration of output processing.

Blocks until the output of the buffered reader has been read completely.

Parameters:
  • output (io.BufferedReader) – Reader provided from the stdout member of an open Popen class.

  • page_size – Suggested value for number of bytes to read from the simulation on each pass.

Smaller values may result in more consistent callback times, at the cost of performance. Larger values may result in better overall performance, at the cost of sporadic callback times. :type page_size: int

Returns:

Total number of bytes read

with_callback(callback: Callable[[int, ndarray], None]) IterativeSimDecoder[source]

Provide a callback function to be invoked on each timestep. Accepts a function with the signature:

def callback(float, numpy.ndarray)

The first value (float) is the time value for the given timestep entry. The second value (NumPy array) is the simulation state for that timestep. Return values are ignored.

Parameters:

callback (Callable[[int, numpy.ndarray], None]) – Function to be invoked on each timestep.

Returns:

Pass-through for IterativeSimDecoder.

class gillespy2.solvers.cpp.c_decoder.SimDecoder(trajectories: ndarray)[source]

Bases: ABC

Abstract simulation decoder class. For solvers to handle output in a custom way, this decoder class will be implemented. Expects the output to be read from a buffered IO reader.

Parameters:

trajectories (numpy.array) – 3D array to output simulation data to.

classmethod create_default(num_trajectories: int, num_timesteps: int, num_species: int) SimDecoder[source]

Creates a new instance of the calling class, using a NumPy array with a predefined shape. Calling this method is preferred over calling the constructor directly.

Parameters:
  • num_trajectories (int) – Number of trajectories expected in the simulation output.

  • num_timesteps (int) – Number of timesteps expected in the simulation output.

  • num_species (int) – Number of species expected in the simulation output.

Returns:

An instance of the decoder object, automatically populated with a valid output array.

abstract get_output() tuple[numpy.ndarray, int][source]

Returns the fully-populated NumPy array containing the completed simulation data. Assumes that the subprocess has already completed.

Returns:

Tuple containing the 3D NumPy array of results, and the time stopped.

abstract read(output: BufferedReader, **kwargs)[source]

Accepts a buffered reader from stdout of a subprocess. Contents of the given reader are processed and made available through get_output().

Blocks until the output of the buffered reader has been read completely.

Parameters:

output (io.BufferedReader) – Reader provided from the stdout member of an open Popen class.

gillespy2.solvers.cpp.c_solver module

class gillespy2.solvers.cpp.c_solver.CSolver(model: Optional[Model] = None, output_directory: Optional[str] = None, delete_directory: bool = True, resume=None, variable: bool = False)[source]

Bases: object

This class implements base behavior that will be needed for C++ solver implementees.

Parameters:
  • model (Model) – The Model to simulate.

  • output_directory (str) – The working output directory.

  • delete_directory (bool) – If True then the output_directory will be deleted upon completetion.

  • resume – Resume data from a previous simulation run.

  • variable (bool) – Indicates whether the simulation should be variable.

rc = 0
class gillespy2.solvers.cpp.c_solver.SimulationReturnCode(value)[source]

Bases: IntEnum

An enumeration.

DONE = 0
FAILED = -1
PAUSED = 33

gillespy2.solvers.cpp.ode_c_solver module

class gillespy2.solvers.cpp.ode_c_solver.ODECSolver(model: Optional[Model] = None, output_directory: Optional[str] = None, delete_directory: bool = True, resume=None, variable: bool = False)[source]

Bases: GillesPySolver, CSolver

This Solver produces the deterministic continuous solution via Ordinary Differential Equations. Uses integrators from SUNDIALS to perform calculations used to produce solutions.

build_engine: BuildEngine
classmethod get_solver_settings()[source]

Returns a list of arguments supported by odc_c_solver.run. :returns: Tuple of strings, denoting all keyword argument for this solvers run() method. :rtype: tuple

static get_supported_integrator_options()[source]

Get the supported integrator options

name = 'ODECSolver'
run(model: Model = None, t: int = None, number_of_trajectories: int = 1, timeout: int = 0, increment: int = None, seed: int = None, debug: bool = False, profile: bool = False, variables={}, resume=None, live_output: str = None, live_output_options: dict = {}, integrator_options: dict[str, float] = None, **kwargs)[source]
Parameters:
  • model (gillespy2.Model) – The model on which the solver will operate. (Deprecated)

  • t (int) – End time of simulation.

  • number_of_trajectories (int) – Number of trajectories to simulate. This is deterministic and will always have same results.

  • timeout (int) – If set, if simulation takes longer than timeout, will exit.

  • increment (float) – Time step increment for plotting.

  • seed (int) – The random seed for the simulation. Optional, defaults to None.

  • variables (dict) – Dictionary of species and their data that will override existing species data.

  • resume (gillespy2.Results) – Result of a previously run simulation, to be resumed.

  • live_output (str) – The type of output to be displayed by solver. Can be “progress”, “text”, or “graph”.

  • live_output_options (dict) – Dictionary that contains options for live_output. By default {“interval”:1}. “interval” specifies seconds between displaying. “clear_output” specifies if display should be refreshed with each display.

Returns:

A result object containing the results of the simulation.

Return type:

gillespy2.Results

target = 'ode'

gillespy2.solvers.cpp.ssa_c_solver module

class gillespy2.solvers.cpp.ssa_c_solver.SSACSolver(model: Optional[Model] = None, output_directory: Optional[str] = None, delete_directory: bool = True, resume=None, variable: bool = False)[source]

Bases: GillesPySolver, CSolver

This solver produces simulations of systems via Stochastic Simulation Algorithm.

build_engine: BuildEngine
classmethod get_solver_settings()[source]

Returns a list of arguments supported by ssa_c_solver.run. :returns: Tuple of strings, denoting all keyword argument for this solvers run() method. :rtype: tuple

name = 'SSACSolver'
run(model: Optional[Model] = None, t: Optional[int] = None, number_of_trajectories: int = 1, timeout: int = 0, increment: Optional[int] = None, seed: Optional[int] = None, debug: bool = False, profile: bool = False, variables={}, resume=None, live_output: Optional[str] = None, live_output_options: dict = {}, **kwargs)[source]

Call out and run the solver. Collect the results.

Parameters:
  • model (gillespy.Model) – The model on which the solver will operate.

  • t (int) – The end time of the solver

  • number_of_trajectories (int) – The number of times to sample the chemical master equation. Each trajectory will be returned at the end of the simulation.

  • increment (float) – The time step of the solution

  • seed (int) – The random seed for the simulation. Defaults to None.

  • debug (bool) – Set to True to provide additional debug information about the simulation.

Returns:

Simulation trajectories.

target = 'ssa'

gillespy2.solvers.cpp.tau_hybrid_c_solver module

class gillespy2.solvers.cpp.tau_hybrid_c_solver.TauHybridCSolver(model=None, output_directory=None, delete_directory=True, resume=None, variable=False, constant_tau_stepsize=None)[source]

Bases: GillesPySolver, CSolver

This solver uses a root-finding interpretation of the direct SSA method, along with ODE solvers to simulate ODE and Stochastic systems interchangeably or simultaneously.

class ErrorStatus(value)[source]

Bases: IntEnum

An enumeration.

INTEGRATOR_FAILED = 3
INVALID_AFTER_SSA = 4
LOOP_OVER_INTEGRATE = 2
NEGATIVE_STATE_AT_BEGINING_OF_STEP = 6
NEGATIVE_STATE_NO_SSA_REACTION = 5
UNKNOWN = 1
build_engine: BuildEngine
classmethod get_solver_settings()[source]

Returns a list of arguments supported by tau_hybrid_c_solver.run. :return: Tuple of strings, denoting all keyword argument for this solvers run() method. :rtype: tuple

classmethod get_supported_features()[source]

Get the set of supported features.

classmethod get_supported_integrator_options() Set[str][source]

Get the supported integrator options

name = 'TauHybridCSolver'
run(model: Model = None, t: int = None, number_of_trajectories: int = 1, timeout: int = 0, increment: int = None, seed: int = None, debug: bool = False, profile: bool = False, variables={}, resume=None, live_output: str = None, live_output_options: dict = {}, tau_step: int = 0.03, tau_tol=0.03, integrator_options: dict[str, float] = None, use_root_finding=False, **kwargs)[source]
Parameters:
  • model (gillespy2.Model) – The model on which the solver will operate. (Deprecated)

  • t (int) – End time of simulation.

  • number_of_trajectories (int) – Number of trajectories to simulate. By default number_of_trajectories = 1.

  • timeout (int) – If set, if simulation takes longer than timeout, will exit.

  • increment (float) – Time step increment for plotting.

  • seed (int) – The random seed for the simulation. Optional, defaults to None.

  • variables (dict) – Dictionary of species and their data that will override existing species data.

  • resume (gillespy2.Results) – Result of a previously run simulation, to be resumed.

  • live_output (str) – The type of output to be displayed by solver. Can be “progress”, “text”, or “graph”.

  • live_output_options (dict) – dictionary contains options for live_output. By default {“interval”:1}. “interval” specifies seconds between displaying. “clear_output” specifies if display should be refreshed with each display.

  • tau_tol – Tolerance level for Tau leaping algorithm. Larger tolerance values will

result in larger tau steps. Default value is 0.03. :type tau_tol: float

Returns:

A result object containing the results of the simulation.

Return type:

gillespy2.Results

target = 'hybrid'

gillespy2.solvers.cpp.tau_leaping_c_solver module

class gillespy2.solvers.cpp.tau_leaping_c_solver.TauLeapingCSolver(model=None, output_directory=None, delete_directory=True, resume=None, variable=False, constant_tau_stepsize=None)[source]

Bases: GillesPySolver, CSolver

A Tau Leaping solver for GillesPy2 models. This solver uses an algorithm that calculates multiple reactions in a single step over a given tau step size. The change in propensities over this step are bounded by relative change in state, yielding greatly improved run-time performance with very little trade-off in accuracy.

build_engine: BuildEngine
classmethod get_solver_settings()[source]

Returns a list of arguments supported by tau_leaping_c_solver.run. :returns: Tuple of strings, denoting all keyword argument for this solvers run() method. :rtype: tuple

name = 'TauLeapingCSolver'
run(model: Optional[Model] = None, t: Optional[int] = None, number_of_trajectories: int = 1, timeout: int = 0, increment: Optional[int] = None, seed: Optional[int] = None, debug: bool = False, profile: bool = False, variables={}, resume=None, live_output: Optional[str] = None, live_output_options: dict = {}, tau_tol=0.03, constant_tau_stepsize=None, **kwargs)[source]
Parameters:
  • model (gillespy2.Model) – The model on which the solver will operate. (Deprecated)

  • t (int) – End time of simulation.

  • number_of_trajectories (int) – Number of trajectories to simulate. By default number_of_trajectories = 1.

  • timeout (int) – If set, if simulation takes longer than timeout, will exit.

  • increment (float) – Time step increment for plotting.

  • seed (int) – The random seed for the simulation. Optional, defaults to None.

  • variables (dict) – Dictionary of species and their data that will override existing species data.

  • resume (gillespy2.Results) – Result of a previously run simulation, to be resumed.

  • live_output (str) – The type of output to be displayed by solver. Can be “progress”, “text”, or “graph”.

  • live_output_options (dict) – dictionary contains options for live_output. By default {“interval”:1}. “interval” specifies seconds between displaying. “clear_output” specifies if display should be refreshed with each display.

  • tau_tol – Tolerance level for Tau leaping algorithm. Larger tolerance values will

result in larger tau steps. Default value is 0.03. :type tau_tol: float

Parameters:

constant_tau_stepsize – If set, overrides the automatic stepsize selection and uses the given value as the stepsize on each step.

Returns:

A result object containing the results of the simulation

Return type:

gillespy2.Results

target = 'tau_leap'

Module contents

class gillespy2.solvers.cpp.ODECSolver(model: Optional[Model] = None, output_directory: Optional[str] = None, delete_directory: bool = True, resume=None, variable: bool = False)[source]

Bases: GillesPySolver, CSolver

This Solver produces the deterministic continuous solution via Ordinary Differential Equations. Uses integrators from SUNDIALS to perform calculations used to produce solutions.

build_engine: BuildEngine
classmethod get_solver_settings()[source]

Returns a list of arguments supported by odc_c_solver.run. :returns: Tuple of strings, denoting all keyword argument for this solvers run() method. :rtype: tuple

static get_supported_integrator_options()[source]

Get the supported integrator options

name = 'ODECSolver'
run(model: Model = None, t: int = None, number_of_trajectories: int = 1, timeout: int = 0, increment: int = None, seed: int = None, debug: bool = False, profile: bool = False, variables={}, resume=None, live_output: str = None, live_output_options: dict = {}, integrator_options: dict[str, float] = None, **kwargs)[source]
Parameters:
  • model (gillespy2.Model) – The model on which the solver will operate. (Deprecated)

  • t (int) – End time of simulation.

  • number_of_trajectories (int) – Number of trajectories to simulate. This is deterministic and will always have same results.

  • timeout (int) – If set, if simulation takes longer than timeout, will exit.

  • increment (float) – Time step increment for plotting.

  • seed (int) – The random seed for the simulation. Optional, defaults to None.

  • variables (dict) – Dictionary of species and their data that will override existing species data.

  • resume (gillespy2.Results) – Result of a previously run simulation, to be resumed.

  • live_output (str) – The type of output to be displayed by solver. Can be “progress”, “text”, or “graph”.

  • live_output_options (dict) – Dictionary that contains options for live_output. By default {“interval”:1}. “interval” specifies seconds between displaying. “clear_output” specifies if display should be refreshed with each display.

Returns:

A result object containing the results of the simulation.

Return type:

gillespy2.Results

target = 'ode'
class gillespy2.solvers.cpp.SSACSolver(model: Optional[Model] = None, output_directory: Optional[str] = None, delete_directory: bool = True, resume=None, variable: bool = False)[source]

Bases: GillesPySolver, CSolver

This solver produces simulations of systems via Stochastic Simulation Algorithm.

build_engine: BuildEngine
classmethod get_solver_settings()[source]

Returns a list of arguments supported by ssa_c_solver.run. :returns: Tuple of strings, denoting all keyword argument for this solvers run() method. :rtype: tuple

name = 'SSACSolver'
run(model: Optional[Model] = None, t: Optional[int] = None, number_of_trajectories: int = 1, timeout: int = 0, increment: Optional[int] = None, seed: Optional[int] = None, debug: bool = False, profile: bool = False, variables={}, resume=None, live_output: Optional[str] = None, live_output_options: dict = {}, **kwargs)[source]

Call out and run the solver. Collect the results.

Parameters:
  • model (gillespy.Model) – The model on which the solver will operate.

  • t (int) – The end time of the solver

  • number_of_trajectories (int) – The number of times to sample the chemical master equation. Each trajectory will be returned at the end of the simulation.

  • increment (float) – The time step of the solution

  • seed (int) – The random seed for the simulation. Defaults to None.

  • debug (bool) – Set to True to provide additional debug information about the simulation.

Returns:

Simulation trajectories.

target = 'ssa'
class gillespy2.solvers.cpp.TauHybridCSolver(model=None, output_directory=None, delete_directory=True, resume=None, variable=False, constant_tau_stepsize=None)[source]

Bases: GillesPySolver, CSolver

This solver uses a root-finding interpretation of the direct SSA method, along with ODE solvers to simulate ODE and Stochastic systems interchangeably or simultaneously.

class ErrorStatus(value)[source]

Bases: IntEnum

An enumeration.

INTEGRATOR_FAILED = 3
INVALID_AFTER_SSA = 4
LOOP_OVER_INTEGRATE = 2
NEGATIVE_STATE_AT_BEGINING_OF_STEP = 6
NEGATIVE_STATE_NO_SSA_REACTION = 5
UNKNOWN = 1
build_engine: BuildEngine
classmethod get_solver_settings()[source]

Returns a list of arguments supported by tau_hybrid_c_solver.run. :return: Tuple of strings, denoting all keyword argument for this solvers run() method. :rtype: tuple

classmethod get_supported_features()[source]

Get the set of supported features.

classmethod get_supported_integrator_options() Set[str][source]

Get the supported integrator options

name = 'TauHybridCSolver'
run(model: Model = None, t: int = None, number_of_trajectories: int = 1, timeout: int = 0, increment: int = None, seed: int = None, debug: bool = False, profile: bool = False, variables={}, resume=None, live_output: str = None, live_output_options: dict = {}, tau_step: int = 0.03, tau_tol=0.03, integrator_options: dict[str, float] = None, use_root_finding=False, **kwargs)[source]
Parameters:
  • model (gillespy2.Model) – The model on which the solver will operate. (Deprecated)

  • t (int) – End time of simulation.

  • number_of_trajectories (int) – Number of trajectories to simulate. By default number_of_trajectories = 1.

  • timeout (int) – If set, if simulation takes longer than timeout, will exit.

  • increment (float) – Time step increment for plotting.

  • seed (int) – The random seed for the simulation. Optional, defaults to None.

  • variables (dict) – Dictionary of species and their data that will override existing species data.

  • resume (gillespy2.Results) – Result of a previously run simulation, to be resumed.

  • live_output (str) – The type of output to be displayed by solver. Can be “progress”, “text”, or “graph”.

  • live_output_options (dict) – dictionary contains options for live_output. By default {“interval”:1}. “interval” specifies seconds between displaying. “clear_output” specifies if display should be refreshed with each display.

  • tau_tol – Tolerance level for Tau leaping algorithm. Larger tolerance values will

result in larger tau steps. Default value is 0.03. :type tau_tol: float

Returns:

A result object containing the results of the simulation.

Return type:

gillespy2.Results

target = 'hybrid'
class gillespy2.solvers.cpp.TauLeapingCSolver(model=None, output_directory=None, delete_directory=True, resume=None, variable=False, constant_tau_stepsize=None)[source]

Bases: GillesPySolver, CSolver

A Tau Leaping solver for GillesPy2 models. This solver uses an algorithm that calculates multiple reactions in a single step over a given tau step size. The change in propensities over this step are bounded by relative change in state, yielding greatly improved run-time performance with very little trade-off in accuracy.

build_engine: BuildEngine
classmethod get_solver_settings()[source]

Returns a list of arguments supported by tau_leaping_c_solver.run. :returns: Tuple of strings, denoting all keyword argument for this solvers run() method. :rtype: tuple

name = 'TauLeapingCSolver'
run(model: Optional[Model] = None, t: Optional[int] = None, number_of_trajectories: int = 1, timeout: int = 0, increment: Optional[int] = None, seed: Optional[int] = None, debug: bool = False, profile: bool = False, variables={}, resume=None, live_output: Optional[str] = None, live_output_options: dict = {}, tau_tol=0.03, constant_tau_stepsize=None, **kwargs)[source]
Parameters:
  • model (gillespy2.Model) – The model on which the solver will operate. (Deprecated)

  • t (int) – End time of simulation.

  • number_of_trajectories (int) – Number of trajectories to simulate. By default number_of_trajectories = 1.

  • timeout (int) – If set, if simulation takes longer than timeout, will exit.

  • increment (float) – Time step increment for plotting.

  • seed (int) – The random seed for the simulation. Optional, defaults to None.

  • variables (dict) – Dictionary of species and their data that will override existing species data.

  • resume (gillespy2.Results) – Result of a previously run simulation, to be resumed.

  • live_output (str) – The type of output to be displayed by solver. Can be “progress”, “text”, or “graph”.

  • live_output_options (dict) – dictionary contains options for live_output. By default {“interval”:1}. “interval” specifies seconds between displaying. “clear_output” specifies if display should be refreshed with each display.

  • tau_tol – Tolerance level for Tau leaping algorithm. Larger tolerance values will

result in larger tau steps. Default value is 0.03. :type tau_tol: float

Parameters:

constant_tau_stepsize – If set, overrides the automatic stepsize selection and uses the given value as the stepsize on each step.

Returns:

A result object containing the results of the simulation

Return type:

gillespy2.Results

target = 'tau_leap'