Public API¶
The Pype9 public API consists of seven classes required to create simulations
of individual neurons or neural networks described in NineML. All classes in
the public API have an abstract base class in the pype9.simulate.common
module and matching derived simulator-specific classes in the
pype9.simulate.neuron
and pype9.simulate.nest
modules.
As the simulator-specific classes have the same signatures as those in the base module only the base module classes are described here.
Simulation¶
-
class
pype9.simulate.common.simulation.
Simulation
(dt, t_start=0.0 * s, seed=None, properties_seed=None, min_delay=1.0 * ms, max_delay=10.0 * ms, code_generator=None, build_base_dir=None, **options)[source]¶ Base class of all simulation classes that prepares and runs the simulator kernel. All simulator objects must be created within the context of a Simulation instance.
with Simulation(dt=0.1 * un.ms, seed=12345) as sim: # Design simulation here
The simulation is advanced using the
run
methodwith Simulation(dt=0.1 * un.ms, seed=12345) as sim: # Create simulator objects here sim.run(100.0 * un.ms)
After the simulation context exits all objects in the simulator backend are destroyed (unless an exception is thrown) and only recordings can be reliably accessed from the “dead” Pype9 objects.
Parameters: - dt (nineml.Quantity (time)) – The resolution of the simulation
- t_start (nineml.Quantity (time)) – The time to start the simulation from
- seed (int | None) – The seed with which to construct the cell/network properties. NB: This seed will only reproduce constant results if the number of MPI nodes is constant
- properties_seed (int | None) – The seed used for random number generator used to set properties and generate connectivity. If not provided it will be derived from the ‘seed’ argument. NB: This seed will only reproduce constant results if the number of MPI nodes is constant
- min_delay (nineml.Quantity (time) | None) – The minimum delay in the network. If None the min delay will be calculated from the first network to be created (if a single cell then it will be the same as the timestep)
- max_delay (nineml.Quantity (time) | None) – The maximum delay in the network. If None the max delay will be calculated from the first network to be created (if a single cell then it will be the same as the timestep)
- options (dict(str, object)) – Options passed to the simulator-specific methods
CellMetaClass¶
-
class
pype9.simulate.common.cells.
CellMetaClass
(component_class, **kwargs)[source]¶ Metaclass for creating simulator-specific cell classes from 9ML Dynamics classes. Instantiating a CellMetaClass with a
nineml.Dynamics
instance will generate, compile and load the required simulator-specific code and create a class that can be used to instantiate dynamics objects.Parameters: - component_class (nineml.Dynamics) – The 9ML component class to create the Cell class for
- name (str) – The name of the cell class, which is used for the generated simulator code. If None, the name of the component_class is used. Note, names must be unique among classes loaded within the same simulation script.
Cell¶
-
class
pype9.simulate.common.cells.
Cell
(*args, **kwargs)[source]¶ Base class for all cell classes created from the CellMetaClass. It defines all methods that can be called on cell model objects.
Parameters: - prototype (DynamicsProperties) – A dynamics properties object used as the “prototype” for the cell
- regime (str) – Name of regime the cell will be initiated in
- kwargs (dict(str, nineml.Quantity)) – Properties and initial state variables to initiate the cell with. These will override properties/initial-values in the prototype
-
connect
(self, sender, send_port_name, receive_port_name, delay, properties=[])[source]¶ Connects an event send port from other into an event receive port in the cell
Parameters: - sender (pype9.simulator.base.cells.Cell) – The sending cell to connect the from
- send_port_name (str) – Name of the port in the sending cell to connect to
- receive_port_name (str) – Name of the receive port in the current cell to connect from
- delay (nineml.Quantity (time)) – The delay of the connection
- properties (list(nineml.Property)) – The connection properties of the event port
-
play
(self, port_name, signal, properties=[])[source]¶ Plays an analog signal or train of events into a port of the cell
Parameters:
-
record
(self, port_name, t_start=None)[source]¶ Specify the recording of a send port or state-variable before the simulation.
-
record_regime
(self)[source]¶ Returns the current regime at each timestep. Periods spent in each regimes can be retrieved with the
regime_epochs
method.
Network¶
-
class
pype9.simulate.common.network.
Network
(nineml_model, build_mode='lazy', **kwargs)[source]¶ Constructs a network simulation, generating and compiling dynamics classes as required (depending on the ‘build_mode’ option). The populations and projections of the network are flattened so that the synapse projections are included in the cell dynamics and the connection groups are just static connections.
Parameters: nineml_model (nineml.Network | nineml.Document | URL) – A 9ML-Python model of a network (or Document containing populations and projections for 9MLv1) or a URL referring to a 9ML model. -
component_array
(self, name)[source]¶ Returns the component array matching the given name
Parameters: name (str) – Name of the component array
-
component_arrays
¶ Iterate through component arrays
-
connection_group
(self, name)[source]¶ Returns the connection group matching the given name
Parameters: name (str) – Name of the component array
-
connection_groups
¶ Iterate through connection_groups
-
selection
(self, name)[source]¶ Returns the selection matching the given name
Parameters: name (str) – Name of the selection
-
selections
¶ Iterate through selections
-
ComponentArray¶
-
class
pype9.simulate.common.network.
ComponentArray
(nineml_model, build_mode='lazy', **kwargs)[source]¶ Component array object corresponds to a NineML type to be introduced in NineMLv2 (see https://github.com/INCF/nineml/issues/46), which consists of a dynamics class and a size. Populations and the synapses on incoming projections.
Parameters: - nineml_model (nineml.ComponentArray) – Component array nineml
- build_mode (str) – The build/compilation strategy for rebuilding the generated code, can be one of ‘lazy’, ‘force’, ‘build_only’, ‘require’.
-
play
(self, port_name, signal, properties=[])[source]¶ Plays an analog signal or train of events into a port of the dynamics array.
Parameters:
Selection¶
-
class
pype9.simulate.common.network.
Selection
(nineml_model, *component_arrays)[source]¶ A selection of cells from one or multiple component arrays. Used to connect ConnectionGroup.
Parameters: - nineml_model (nineml.Selection) – The NineML Selection object
- component_arrays (list(nineml.ComponentArray)) – List of component arrays included in the selection.
ConnectionGroup¶
-
class
pype9.simulate.common.network.
ConnectionGroup
(nineml_model, source, destination)[source]¶ ConnectionGroup object corresponds to a NineML type to be introduced in NineMLv2 (see https://github.com/INCF/nineml/issues/46), which consists of a dynamics class and a size. Only consists of references to ports on the source and destination ComponentArrays|Selections and connectivity.
Parameters: - nineml_model (nineml.ConnectionGroup) – Component array nineml
- source (ComponentArray) – Source component array
- destination (ComponentArray) – Destination component array