BMI wrapper for PySB-assembled models (indra.assemblers.pysb.bmi_wrapper)

This module allows creating a Basic Modeling Interface (BMI) model from and automatically assembled PySB model. The BMI model can be instantiated within a simulation workflow system where it is simulated together with other models.

class indra.assemblers.pysb.bmi_wrapper.BMIModel(model, inputs=None, stop_time=1000, outside_name_map=None)[source]

This class represents a BMI model wrapping a model assembled by INDRA.

Parameters
  • model (pysb.Model) – A PySB model assembled by INDRA to be wrapped in BMI.

  • inputs (Optional[list[str]]) – A list of variable names that are considered to be inputs to the model meaning that they are read from other models. Note that designating a variable as input means that it must be provided by another component during the simulation.

  • stop_time (int) – The stopping time for this model, controlling the time units up to which the model is simulated.

  • outside_name_map (dict) – A dictionary mapping outside variables names to inside variable names (i.e. ones that are in the wrapped model)

export_into_python()[source]

Write the model into a pickle and create a module that loads it.

The model basically exports itself as a pickle file and a Python file is then written which loads the pickle file. This allows importing the model in the simulation workflow.

finalize()[source]

Finish the simulation and clean up resources as needed.

get_attribute(att_name)[source]

Return the value of a given attribute.

Atrributes include: model_name, version, author_name, grid_type, time_step_type, step_method, time_units

Parameters

att_name (str) – The name of the attribute whose value should be returned.

Returns

value – The value of the attribute

Return type

str

get_current_time()[source]

Return the current time point that the model is at during simulation

Returns

time – The current time point

Return type

float

get_input_var_names()[source]

Return a list of variables names that can be set as input.

Returns

var_names – A list of variable names that can be set from the outside

Return type

list[str]

get_output_var_names()[source]

Return a list of variables names that can be read as output.

Returns

var_names – A list of variable names that can be read from the outside

Return type

list[str]

get_start_time()[source]

Return the initial time point of the model.

Returns

start_time – The initial time point of the model.

Return type

float

get_status()[source]

Return the current status of the model.

get_time_step()[source]

Return the time step associated with model simulation.

Returns

dt – The time step for model simulation

Return type

float

get_time_units()[source]

Return the time units of the model simulation.

Returns

units – The time unit of simulation as a string

Return type

str

get_value(var_name)[source]

Return the value of a given variable.

Parameters

var_name (str) – The name of the variable whose value should be returned

Returns

value – The value of the given variable in the current state

Return type

float

get_values(var_name)[source]

Return the value of a given variable.

Parameters

var_name (str) – The name of the variable whose value should be returned

Returns

value – The value of the given variable in the current state

Return type

float

get_var_name(var_name)[source]

Return the internal variable name given an outside variable name.

Parameters

var_name (str) – The name of the outside variable to map

Returns

internal_var_name – The internal name of the corresponding variable

Return type

str

get_var_rank(var_name)[source]

Return the matrix rank of the given variable.

Parameters

var_name (str) – The name of the variable whose rank should be returned

Returns

rank – The dimensionality of the variable, 0 for scalar, 1 for vector, etc.

Return type

int

get_var_type(var_name)[source]

Return the type of a given variable.

Parameters

var_name (str) – The name of the variable whose type should be returned

Returns

unit – The type of the variable as a string

Return type

str

get_var_units(var_name)[source]

Return the units of a given variable.

Parameters

var_name (str) – The name of the variable whose units should be returned

Returns

unit – The units of the variable

Return type

str

initialize(cfg_file=None, mode=None)[source]

Initialize the model for simulation, possibly given a config file.

Parameters

cfg_file (Optional[str]) – The name of the configuration file to load, optional.

make_repository_component()[source]

Return an XML string representing this BMI in a workflow.

This description is required by EMELI to discover and load models.

Returns

xml – String serialized XML representation of the component in the model repository.

Return type

str

set_value(var_name, value)[source]

Set the value of a given variable to a given value.

Parameters
  • var_name (str) – The name of the variable in the model whose value should be set.

  • value (float) – The value the variable should be set to

set_values(var_name, value)[source]

Set the value of a given variable to a given value.

Parameters
  • var_name (str) – The name of the variable in the model whose value should be set.

  • value (float) – The value the variable should be set to

update(dt=None)[source]

Simulate the model for a given time interval.

Parameters

dt (Optional[float]) – The time step to simulate, if None, the default built-in time step is used.