amici.importers.pysb

PySB Import

This module provides all necessary functionality to import a model specified in the pysb.core.Model format.

Functions

pysb_model_from_path(pysb_model_file)

Load a PySB model module and return the pysb.core.Model instance.

pysb2amici(model[, output_dir, ...])

Generate AMICI C++ files for the provided model.

pysb2jax(model[, output_dir, ...])

Generate AMICI jax files for the provided model.

amici.importers.pysb.pysb2amici(model, output_dir=None, *, observation_model=None, fixed_parameters=None, verbose=False, assume_pow_positivity=False, compiler=None, compute_conservation_laws=True, compile=True, simplify=<function _default_simplify>, cache_simplify=False, generate_sensitivity_code=True, model_name=None, pysb_model_has_obs_and_noise=False, _events=None)[source]

Generate AMICI C++ files for the provided model.

Warning

PySB models with Compartments

When importing a PySB model with pysb.core.Compartments, BioNetGen scales reaction fluxes with the compartment size. Instead of using the respective symbols, the compartment size Parameter or Expression is evaluated when generating equations. This may lead to unexpected results if the compartment size parameter is changed for AMICI simulations.

Parameters:
  • model (pysb.core.Model) – PySB model, model.name will determine the name of the generated module.

  • output_dir (str | pathlib.Path | None) – The directory where the generated model code is stored. Will be created if it does not exist.

  • observation_model (list[amici.importers.utils.MeasurementChannel]) – The different measurement channels that make up the observation model, see also amici.importers.utils.MeasurementChannel. The ID is expected to be the name of a pysb.core.Expression or pysb.core.Observable in the provided model that should be mapped to an observable. sigma is expected to be the name of a pysb.core.Expression to be mapped to the scale parameter of the noise distribution. MeasurementChannel.formula is expected to be None. Event-observables are not supported.

  • fixed_parameters (list[str]) – list of pysb.core.Parameter to be excluded from sensitivity analysis.

  • verbose (int | bool) – verbosity level for logging, True/False default to logging.DEBUG/logging.ERROR

  • assume_pow_positivity (bool) – if set to True, a special pow function is used to avoid problems with state variables that may become negative due to numerical errors

  • compiler (str) – Absolute path to the compiler executable to be used to build the Python extension, e.g. /usr/bin/clang.

  • compute_conservation_laws (bool) – if set to True, conservation laws are automatically computed and applied such that the state-jacobian of the ODE right-hand-side has full rank. This option should be set to True when using the Newton algorithm to compute steady states

  • compile (bool) – If True, build the python module for the generated model. If false, just generate the source code.

  • simplify (collections.abc.Callable) – If not None, this function will be used to simplify symbolic derivative expressions. Receives sympy expressions as only argument. To apply multiple simplifications, wrap them in a lambda expression.

  • cache_simplify (bool) – Whether to cache calls to the simplify method. Note that there are possible issues with PySB models: https://github.com/AMICI-dev/AMICI/pull/1672

  • generate_sensitivity_code (bool) – if set to False, code for sensitivity computation will not be generated

  • model_name (str | None) – Name for the generated model module. If None, pysb.core.Model.name will be used.

  • pysb_model_has_obs_and_noise (bool) – if set to True, the pysb model is expected to have extra observables and noise variables added

Return type:

amici._installation.amici.Model | None

Returns:

If compile is True and compilation was successful, an instance of the generated model class, otherwise None.

amici.importers.pysb.pysb2jax(model, output_dir=None, *, observation_model=None, verbose=False, compute_conservation_laws=True, simplify=<function _default_simplify>, cache_simplify=False, model_name=None, pysb_model_has_obs_and_noise=False)[source]

Generate AMICI jax files for the provided model.

Warning

PySB models with Compartments

When importing a PySB model with pysb.Compartments, BioNetGen scales reaction fluxes with the compartment size. Instead of using the respective symbols, the compartment size Parameter or Expression is evaluated when generating equations. This may lead to unexpected results if the compartment size parameter is changed for AMICI simulations.

Parameters:
  • model (pysb.core.Model) – PySB model, model.name will determine the name of the generated module.

  • output_dir (str | pathlib.Path | None) – The directory where the generated model code is stored. Will be created if it does not exist.

  • observation_model (list[amici.importers.utils.MeasurementChannel]) – The different measurement channels that make up the observation model, see also amici.importers.utils.MeasurementChannel. The ID is expected to be the name of a pysb.core.Expression or pysb.core.Observable in the provided model that should be mapped to an observable. sigma is expected to be the name of a pysb.core.Expression to be mapped to the scale parameter of the noise distribution. MeasurementChannel.formula is expected to be None. Event-observables are not supported.

  • verbose (int | bool) – verbosity level for logging, True/False default to logging.DEBUG/logging.ERROR

  • compute_conservation_laws (bool) – if set to True, conservation laws are automatically computed and applied such that the state-jacobian of the ODE right-hand-side has full rank. This option should be set to True when using the Newton algorithm to compute steady states.

  • simplify (collections.abc.Callable) – If not None, this function will be used to simplify symbolic derivative expressions. Receives sympy expressions as only argument. To apply multiple simplifications, wrap them in a lambda expression.

  • cache_simplify (bool) – Whether to cache calls to the simplify method. Note that there are possible issues with PySB models: https://github.com/AMICI-dev/AMICI/pull/1672

  • model_name (str | None) – Name for the generated model module. If None, pysb.core.Model.name will be used.

  • pysb_model_has_obs_and_noise (bool) – If set to True, the pysb model is expected to have extra observables and noise variables added.

amici.importers.pysb.pysb_model_from_path(pysb_model_file)[source]

Load a PySB model module and return the pysb.core.Model instance.

Parameters:

pysb_model_file (str | pathlib.Path) – Full or relative path to the PySB model module

Return type:

pysb.core.Model

Returns:

The pysb Model instance