bsb.simulation package

Submodules

bsb.simulation.simulation module

class bsb.simulation.simulation.ProgressEvent(progression, duration, time)[source]

Bases: object

class bsb.simulation.simulation.Simulation(*args, _parent=None, _key=None, **kwargs)[source]

Bases: object

after_prepare: cfgdict[str, AfterPrepareHook]

Dictionary of hooks to run once the simulation has been prepared, before it runs.

after_simulation: cfgdict[str, AfterSimulationHook]

Dictionary of hooks to run once the simulation has finished and its results have been collected.

cell_models: cfgdict[CellModel]

Dictionary linking the cell population name to its model.

connection_models: cfgdict[ConnectionModel]

Dictionary linking the connection sets name to its model.

devices: cfgdict[DeviceModel]

Dictionary linking the device name to its model.

duration: float

Duration of the simulation in milliseconds.

get_components()[source]
get_connectivity_sets() → Mapping[ConnectionModel, ConnectivitySet][source]
Return type:

Mapping[ConnectionModel, ConnectivitySet]

get_model_of(type: CellType | ConnectionStrategy) → CellModel | ConnectionModel[source]
Parameters:

type (CellType | ConnectionStrategy)

Return type:

CellModel | ConnectionModel

get_node_name()
name: str

Name of the simulation.

scaffold: Scaffold
simulator: str

Simulator name.

bsb.simulation.adapter module

class bsb.simulation.adapter.FixedStepProgressController(simulations, adapter, step=1)[source]

Bases: object

get_next_checkpoint()[source]
run_checkpoint()[source]
use_bar()[source]
class bsb.simulation.adapter.SimulationData(simulation: Simulation, result=None, filename=None, comm=None, simulation_id=None)[source]

Bases: object

Parameters:

simulation (Simulation)

class bsb.simulation.adapter.SimulatorAdapter(comm=None)[source]

Bases: ABC

Parameters:

comm – The mpi4py MPI communicator to use. Only nodes in the communicator will participate in the simulation. The first node will idle as the main node.

collect(results)[source]

Collect the output the simulations that completed.

Returns:

Collected simulation results.

Return type:

list[SimulationResult]

execute_checkpoints(controllers)[source]
get_next_checkpoint()[source]
implement_components(simulation)[source]
load_controllers(simulation)[source]
new_run_id() → str[source]

One identity for a run, agreed by every rank taking part in it.

collective Every rank of comm has to call this, which is why it belongs in prepare: preparing a simulation reads the network and builds it in the simulator, so every rank is there already. A result is handed the answer rather than agreeing one itself, since constructing a result is not collective and must not become so.

Returns:

An identity every rank of this adapter agrees on.

Return type:

str

abstractmethod prepare(simulation, filename=None)[source]

Reset the simulation backend and prepare for the given simulation.

Parameters:

simulation (Simulation) – The simulation configuration to prepare.

Returns:

Prepared simulation data.

Return type:

SimulationData

abstractmethod run(*simulations)[source]

Fire up the prepared adapter.

Parameters:

simulations (Simulation) – One or a list of simulation configurations to simulate.

Returns:

List of simulation results.

Return type:

list[SimulationResult]

run_after_prepare(simulation, simdata)[source]

Run the after_prepare hooks of a simulation on what was prepared.

Parameters:
  • simulation (Simulation) – The simulation configuration that was prepared.

  • simdata (SimulationData) – What the backend built for it.

run_after_simulation(simulations, results)[source]

Run the after_simulation hooks of each simulation on its own result.

Parameters:
  • simulations (list[Simulation]) – The simulation configurations that were run.

  • results (list[SimulationResult]) – The collected result of each simulation, in the same order.

simulate(*simulations, filename=None)[source]

Simulate the given simulations.

Parameters:

simulations (Simulation) – One or a list of simulation configurations to simulate.

Returns:

List of simulation results for each simulation run.

Return type:

list[SimulationResult]

bsb.simulation.cell module

class bsb.simulation.cell.CellModel(*args, _parent=None, _key=None, **kwargs)[source]

Bases: SimulationComponent

Cell models are simulator specific representations of a cell type.

cell_type: CellType

The cell type that this model represents.

get_node_name()
get_placement_set(chunks=None)[source]
parameters: cfgdict[str, CellParameter]

Parameters of the model, computed once per cell when the simulation is loaded.

Keyed by the model parameter they set. A bare value is a constant; a node with a strategy selects a CellParameter.

bsb.simulation.component module

class bsb.simulation.component.SimulationComponent(*args, _parent=None, _key=None, **kwargs)[source]

Bases: RngConsumer

get_node_name()
implement(adapter, simulation, simdata)[source]

Method called when simulation is being set up. Can be used for components to set themselves up and store the context they need to operate.

name: str

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

property simulation

bsb.simulation.connection module

class bsb.simulation.connection.ConnectionModel(*args, _parent=None, _key=None, **kwargs)[source]

Bases: SimulationComponent

get_connectivity_set()[source]
get_node_name()
parameters: cfgdict[str, ConnectionParameter]

Parameters of the model, computed once per connection when the simulation is loaded.

Keyed by the model parameter they set. A bare value is a constant; a node with a strategy selects a ConnectionParameter.

tag: str

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

bsb.simulation.device module

class bsb.simulation.device.DeviceModel(*args, _parent=None, _key=None, **kwargs)[source]

Bases: SimulationComponent

get_node_name()
implement(adapter, simulation, simdata)[source]

Method called when simulation is being set up. Can be used for components to set themselves up and store the context they need to operate.

bsb.simulation.parameter module

class bsb.simulation.parameter.CellParameter(*args, _parent=None, _key=None, **kwargs)[source]

Bases: Parameter

A parameter computed once per cell of a placement set.

abstractmethod compute(simulation: Simulation, ps: PlacementSet) → ndarray[source]

Compute one value per cell in ps, in placement set order.

Parameters:
  • simulation (Simulation) – The simulation being prepared.

  • ps (PlacementSet) – The placement set of the cell model this is configured on.

Returns:

One value per cell.

Return type:

ndarray

get_node_name()
strategy

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.parameter.ConnectionParameter(*args, _parent=None, _key=None, **kwargs)[source]

Bases: Parameter

A parameter computed once per connection of a connectivity set.

abstractmethod compute(simulation: Simulation, cs: ConnectivitySet, pre_locs: ndarray, post_locs: ndarray) → ndarray[source]

Compute one value per connection, in the order the locations are given.

Parameters:
  • simulation (Simulation) – The simulation being prepared.

  • cs (ConnectivitySet) – The connectivity set of the connection model this is configured on.

  • pre_locs (ndarray) – Presynaptic locations, as (cell, branch, point) rows.

  • post_locs (ndarray) – Postsynaptic locations, as (cell, branch, point) rows.

Returns:

One value per connection.

Return type:

ndarray

get_node_name()
strategy

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.parameter.Constant(*args, _parent=None, _key=None, **kwargs)[source]

Bases: Parameter

A parameter that yields one value, whatever it is asked to compute over.

Written as a bare value ({"C_m": 250.0}) rather than as a node, and accepted wherever a parameter of any arity is; it ignores the arguments it is handed.

compute(*args, **kwargs)[source]
get_node_name()
value

The value to assign.

class bsb.simulation.parameter.DistanceDelayParameter(*args, _parent=None, _key=None, **kwargs)[source]

Bases: ConnectionParameter

Transmission delay derived from the distance between the connected somata.

The delay is the soma-to-soma distance divided by the axonal conduction speed, floored at the simulation’s resolution so no connection is asked to deliver faster than the simulation can step.

axon_speed: float

Axonal conduction speed, in the network’s spatial units per millisecond.

compute(simulation, cs, pre_locs, post_locs)[source]

Compute one value per connection, in the order the locations are given.

Parameters:
  • simulation – The simulation being prepared.

  • cs – The connectivity set of the connection model this is configured on.

  • pre_locs – Presynaptic locations, as (cell, branch, point) rows.

  • post_locs – Postsynaptic locations, as (cell, branch, point) rows.

Returns:

One value per connection.

get_node_name()
property simulation

The simulation this parameter is configured on.

Walked by type rather than by counting parents, because how deeply a parameter sits is the model’s business, not this parameter’s.

class bsb.simulation.parameter.Parameter(*args, _parent=None, _key=None, **kwargs)[source]

Bases: ABC

Base class for anything that answers “what is the value of this model parameter?”.

A parameter is configured like any other node and computes its values when the simulation is loaded. What it is computed over is what varies, so this base declares no compute signature; each arity below declares its own, and a parameter is only accepted where its arity fits.

It is an abc.ABC without abstract methods on purpose: subclasses need the abstract machinery for the compute they each declare, and inheriting it from here is what keeps one metaclass across the whole hierarchy.

get_node_name()
name: str

Name of the model parameter this computes, taken from its configuration key.

class bsb.simulation.parameter.PointParameter(*args, _parent=None, _key=None, **kwargs)[source]

Bases: Parameter

A parameter computed once per point of a cell’s morphology.

Points are addressed the way BSB addresses morphologies everywhere else, as (branch, point). How a simulator discretises a morphology is its own concern; an adapter maps points onto whatever its backend builds.

abstractmethod compute(simulation: Simulation, ps: PlacementSet, cell_id: int, morphology: Morphology) → ndarray[source]

Compute one value per point of morphology, in flattened branch order.

Parameters:
  • simulation (Simulation) – The simulation being prepared.

  • ps (PlacementSet) – The placement set the cell belongs to.

  • cell_id (int) – Index of the cell within ps.

  • morphology (Morphology) – The cell’s morphology.

Returns:

One value per morphology point.

Return type:

ndarray

get_node_name()
strategy

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.parameter.constant_parameter[source]

Bases: TypeHandler

Cast a configuration value to a Constant.

The narrow counterpart of parameters_of_type, for notations documented as holding constants. It refuses a computed parameter rather than silently accepting one, so constants keeps meaning what it says and the wider parameters block is the one place a strategy belongs.

bsb.simulation.parameter.expand_to(n, value)[source]

One value for each of n, out of whatever a parameter computed.

A parameter that yields a single value stands for that value repeated, which is all a constant is: the degenerate case of a parameter that does not vary. Anything that already has a length has to have the right one.

Parameters:
  • n – How many values are needed.

  • value – What the parameter computed.

Returns:

n values.

Raises:

ValueError – If value is neither one value nor n of them.

class bsb.simulation.parameter.parameters_of_type(base=<class 'bsb.simulation.parameter.Parameter'>)[source]

Bases: TypeHandler

Cast a configuration value to a Parameter of a given arity.

Keeps the shorthands a value can be written in, and homogenizes them into parameter nodes so consumers only ever deal with one thing:

  • a bare value becomes a Constant;

  • a node with a strategy key is cast to that strategy of base;

  • an already-constructed parameter passes through.

Casting through a type handler, rather than typing the attribute as base itself, is what lets one Constant be accepted at every arity without needing a separate constant class per arity.

bsb.simulation.postprocessing module

class bsb.simulation.postprocessing.AfterPrepareHook(*args, _parent=None, _key=None, **kwargs)[source]

Bases: ABC, RngConsumer

Hook that runs once the simulation it is configured on has been prepared, before it is run.

Its counterpart to AfterSimulationHook: this one sees the simulation the backend has just built and can still change it, where that one sees what the run produced.

The hook runs on every node that took part in preparing the simulation, so a hook that writes output is responsible for its own MPI awareness, through adapter.comm.

get_node_name()
name: str

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

abstractmethod postprocess(adapter: SimulatorAdapter, simulation: Simulation, simdata: SimulationData)[source]

Process the prepared simulation.

Parameters:
  • adapter (SimulatorAdapter) – Adapter that prepared the simulation.

  • simulation (Simulation) – Simulation configuration that was prepared.

  • simdata (SimulationData) – What the backend built for it: its populations, connections and devices.

strategy

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.postprocessing.AfterSimulationHook(*args, _parent=None, _key=None, **kwargs)[source]

Bases: ABC, RngConsumer

Hook that runs after the simulation it is configured on has finished and its results have been collected.

The hook runs on every node that took part in the simulation, so hooks that write output are responsible for their own MPI awareness, through adapter.comm.

get_node_name()
name: str

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

abstractmethod postprocess(adapter: SimulatorAdapter, simulation: Simulation, result: SimulationResult)[source]

Process the outcome of the simulation.

Parameters:
  • adapter (SimulatorAdapter) – Adapter that ran the simulation. The simulator is still set up at this point, so backend state can be inspected here.

  • simulation (Simulation) – Simulation configuration that was run.

  • result (SimulationResult) – Collected results of the simulation.

strategy

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

bsb.simulation.results module

class bsb.simulation.results.NetworkRecording(device: str | None, kind: str | None, direction: str | None, signal: Any, target: RecordedCell | RecordedPoint | RecordedSynapse | RecordedDevice | None = None, run: SimulationRun | None = None)[source]

Bases: Recording

A recording traced back to the network it was simulated on.

Parameters:
run: SimulationRun | None = None

The run that made the recording.

target: RecordedCell | RecordedPoint | RecordedSynapse | RecordedDevice | None = None

What was recorded: a RecordedCell, RecordedPoint, RecordedSynapse or RecordedDevice, depending on the recording’s kind. None for a kind this BSB does not know.

class bsb.simulation.results.RecordedCell(id: int, model: str, _placement: Any)[source]

Bases: object

A cell of the network, as a recording addresses it.

Parameters:
property cell_type: CellType

The network’s cell type of the cell.

id: int

Id of the cell in the placement set of its cell type.

model: str

Name of the cell model the cell was simulated with.

property morphology: Morphology | None

The morphology of the cell as it is in the network: rotated by the cell’s rotation and moved to its position. A copy, so changing it changes nothing in the network. None when its placement set stores no morphologies.

property placement_set: PlacementSet

The placement set of that cell type.

property position: numpy.ndarray | None

Position of the cell, or None when its placement set stores none.

property rotation: scipy.spatial.transform.Rotation | None

The rotation of the cell’s morphology in the network, or None when its placement set stores no rotations.

class bsb.simulation.results.RecordedDevice(name: str, kind: str | None, configuration: dict | None)[source]

Bases: object

The device a recording of the device itself belongs to.

Parameters:
  • name (str)

  • kind (str | None)

  • configuration (dict | None)

configuration: dict | None

The configuration of the device, as the simulation ran with it, or None if the run recorded no configuration.

kind: str | None

The kind of device, as configured.

name: str

Name of the device.

class bsb.simulation.results.RecordedPoint(cell: RecordedCell, branch: int, point: int, arc: float | None = None)[source]

Bases: object

A point on the morphology of a cell of the network, as a recording addresses it.

Parameters:
arc: float | None = None

Where on the branch, as a fraction of the branch’s length, or None when the location is the point itself.

branch: int

Index of the branch in the cell’s morphology.

cell: RecordedCell

The cell the point is on.

point: int

Index of the point on that branch.

property position: numpy.ndarray | None

Where the location is in the network, on the cell’s morphology as the cell is placed. None when the network stores no morphologies or positions for the cell.

class bsb.simulation.results.RecordedSynapse(post: RecordedPoint, pre: RecordedPoint | None, synapse_type: str, connectivity_set: str | None)[source]

Bases: object

A synapse between two cells of the network, as a recording addresses it.

Parameters:
connectivity_set: str | None

Name of the connectivity set of the connection, if any.

property position: numpy.ndarray | None

Where the synapse is in the network: its location on the postsynaptic cell.

post: RecordedPoint

Where the synapse is on its postsynaptic cell.

pre: RecordedPoint | None

Where the connection the synapse belongs to starts on its presynaptic cell, or None for a synapse that belongs to no connection.

synapse_type: str

Name of the synapse type.

class bsb.simulation.results.Recording(device: str | None, kind: str | None, direction: str | None, signal: Any)[source]

Bases: object

One recorded Neo object and what it says about itself.

Every recording names the device that made it, what kind of thing it recorded, and whether the device observed it or injected it, whatever backend ran the simulation and whichever Neo container it landed in. What it recorded is addressed by the annotations of its kind, never by a simulator’s own ids.

Parameters:
  • device (str | None)

  • kind (str | None)

  • direction (str | None)

  • signal (Any)

property annotations: dict

All annotations of the Neo object, including those of its kind.

device: str | None

Name of the device that produced the recording.

direction: str | None

"record" when the device observed it, or "stimulate" when it injected it.

property is_spike_train: bool
kind: str | None

What kind of thing was recorded: cell, point, synapse or device.

signal: Any

The Neo object itself, a SpikeTrain or an AnalogSignal.

class bsb.simulation.results.ResultsReader(network: Scaffold, blocks: list[neo.core.Block])[source]

Bases: object

The results in a file, read together with the network they were simulated on.

Made by read_results(), which verifies every run in the file against the network before handing one out.

Parameters:
property configuration: dict | None

The configuration of the simulation, when the file holds a single run.

property devices: list[str]

Names of the devices that recorded, across the runs.

network

The network the simulations ran on.

property provenance: dict | None

The provenance of the run, when the file holds a single run.

recordings(device: str | None = None, kind: str | None = None) → Iterator[NetworkRecording][source]

Iterate the recordings of every run, each with what it recorded in the network, and the run that made it.

Parameters:
  • device (str | None) – Only yield recordings made by this device.

  • kind (str | None) – Only yield recordings of this kind.

Returns:

The recordings, run by run, in the order they were written.

Return type:

Iterator[NetworkRecording]

runs

The runs in the file, in the order they were written.

property simulation: Simulation | None

The network’s simulation that ran, when the file holds a single run.

class bsb.simulation.results.SimulationRecorder(device)[source]

Bases: object

property device_kind

The kind of device this recorder belongs to, as it is configured.

property device_name

The name of the device this recorder belongs to.

flush(segment: neo.core.Segment)[source]
Parameters:

segment (neo.core.Segment)

class bsb.simulation.results.SimulationResult(simulation, filename=None, comm=None, simulation_id=None)[source]

Bases: object

The results of one simulation, and the provenance of the run that made them.

Under MPI each rank writes its own part and rank 0 merges them into the file that was asked for, because neither nixio nor an HDF5 attribute supports concurrent writers. The parts are an implementation detail: a run ends with one file, and finalize is what makes that true.

Parameters:
  • comm – The communicator whose ranks share this run, which is the adapter’s. It decides who takes part in finalize and which parts it expects to find, so an adapter given a sub-communicator has to hand it on rather than let this fall back to the world.

  • simulation_id – The identity of the run, which every rank writing a part of it has to agree on, or the parts cannot be recognised as belonging together. An adapter agrees one with SimulatorAdapter.new_run_id and passes it here. Constructing this without one is for a result that stands alone: a fresh identity is made up locally, since there is nobody to agree with.

add(recorder)[source]

Add a recorder, which every checkpoint asks to flush what it recorded.

Parameters:

recorder (SimulationRecorder) – The recorder. It has to belong to a device, which is what every one of its recordings names as the device that made it.

property block
create_recorder(flush: Callable[[neo.core.Segment], None], device)[source]

Add a recorder that flushes with a function.

Parameters:
  • flush (Callable[[neo.core.Segment], None]) – Appends what was recorded since the last checkpoint to the segment it is given, annotated with what it recorded.

  • device – The device the recordings belong to.

Returns:

The recorder.

Return type:

SimulationRecorder

finalize() → None[source]

Turn the per-rank parts into the one file the run was asked for.

Every rank waits until all parts are written, then rank 0 merges them and removes the parts. A failed merge leaves them in place: they are the only copy of a completed run’s results.

Return type:

None

flush()[source]
write(filename, mode='ow')[source]
class bsb.simulation.results.SimulationRun(reader: ResultsReader, block: neo.core.Block)[source]

Bases: object

One run of a simulation in a results file, read with the network it ran on.

Parameters:
block

The Neo block holding the results of the run.

configuration

The configuration tree of the simulation, as it ran.

devices

Names of the devices that recorded, in the order they were first written.

property name: str

Name of the simulation that ran.

provenance

The provenance of the run: its seed, duration, resolution, ranks, …

recordings(device: str | None = None, kind: str | None = None) → Iterator[NetworkRecording][source]

Iterate the recordings of the run, each with what it recorded in the network.

Parameters:
  • device (str | None) – Only yield recordings made by this device.

  • kind (str | None) – Only yield recordings of this kind.

Returns:

The recordings, in the order they were written.

Return type:

Iterator[NetworkRecording]

property run_index: int | None

Which run of this simulation in the file it is, counting from 0.

property simulation: Simulation | None

The network’s simulation of this name, or None if the network has none.

The network’s configuration may have been changed since the run; the configuration the simulation ran with is configuration.

bsb.simulation.results.cell_annotations(cell_model, cell_id: int, direction: str) → dict[source]

Annotations of a recording of a whole cell.

Parameters:
  • cell_model (CellModel) – The cell model the cell was simulated with.

  • cell_id (int) – Id of the cell in the placement set of the cell model’s cell type.

  • direction (str) – "record" when the device observes what it records, or "stimulate" when it injects it.

Returns:

The annotations to pass to the Neo object.

Return type:

dict

bsb.simulation.results.device_annotations(direction: str) → dict[source]

Annotations of a recording of the device itself, which addresses nothing in the network: a signal the device computes, rather than one it takes from a cell.

Parameters:

direction (str) – "record" when the device observes what it records, or "stimulate" when it injects it.

Returns:

The annotations to pass to the Neo object.

Return type:

dict

bsb.simulation.results.iter_recordings(source, device: str | None = None, kind: str | None = None, cell_model: str | None = None, cell_id: int | None = None) → Iterator[Recording][source]

Iterate the recordings of a block, a segment, or a list of either.

Parameters:
  • source – What to read: a neo.core.Block, a neo.core.Segment, or an iterable of either.

  • device (str | None) – Only yield recordings made by this device.

  • kind (str | None) – Only yield recordings of this kind.

  • cell_model (str | None) – Only yield recordings on cells of this cell model. A synapse is on its postsynaptic cell.

  • cell_id (int | None) – Only yield recordings on cells with this id. A cell id is only unique within its cell model, so pass cell_model along to single out one cell.

Returns:

The recordings, in the order they were written.

Return type:

Iterator[Recording]

bsb.simulation.results.merge_rank_results(parts, filename) → None[source]

Concatenate per-rank results into one file.

Ranks record disjoint cells, so a merge is a concatenation and never has to reconcile two accounts of the same recording. Segments are matched on their checkpoint_index, which is what makes them line up across parts: a checkpoint is one segment holding every rank’s share of it.

That matching is why this holds a simulation’s merged recordings in memory before writing them: a segment cannot be written until every part that has a share of it has been read. Peak memory is therefore one simulation’s results, not the whole file, and each part is closed as soon as it has been merged.

Parameters:
  • parts – The per-rank files, in rank order.

  • filename – The file to write.

Return type:

None

bsb.simulation.results.multiplex_channels(targets: list[dict]) → tuple[dict, dict][source]

Annotations for a single analog signal recording every target in targets as one channel each, in the same order.

Parameters:

targets (list[dict]) – Per-target annotations, one call per target, in channel order.

Returns:

A (baseline, array_annotations) pair: baseline annotations for the multiplexed AnalogSignal, and its array_annotations, one array per key, each of length len(targets).

Return type:

tuple[dict, dict]

bsb.simulation.results.multiplex_targets(targets: list[dict]) → dict[source]

Annotations for a single spike train recording every target in targets, as a roster: one flat list per key that varies across targets, encoded as a single annotation. Pair with a bsb_target_index array annotation, one entry per spike, indexing into the roster in the order given, so a single SpikeTrain can speak for every target it watches – including ones that never fire, which the roster still names.

The roster is encoded with encode_annotation() rather than written as one flat-list annotation per key: nixio collapses a property holding a single value back to a bare scalar on read, which a roster of exactly one target would trip on if its lists were written directly.

Parameters:

targets (list[dict]) – Per-target annotations, as cell_annotations(), point_annotations() or synapse_annotations() give them, one call per target, in roster order.

Returns:

Annotations to pass to the multiplexed SpikeTrain.

Return type:

dict

bsb.simulation.results.point_annotations(cell_model, cell_id: int, branch: int, point: int, arc: float, direction: str) → dict[source]

Annotations of a recording at a point on a cell’s morphology.

Parameters:
  • cell_model (CellModel) – The cell model the cell was simulated with.

  • cell_id (int) – Id of the cell in the placement set of the cell model’s cell type.

  • branch (int) – Index of the branch in the cell’s morphology.

  • point (int) – Index of the point on that branch.

  • arc (float) – Where on the stretch following that point the recording is, as a fraction of the branch’s length.

  • direction (str) – "record" when the device observes what it records, or "stimulate" when it injects it.

Returns:

The annotations to pass to the Neo object.

Return type:

dict

bsb.simulation.results.rank_part_path(filename, rank: int) → Path[source]

Where one rank writes its share of a run’s results.

Parts live in a sibling directory of the file they will become, so the finished result keeps the path it was asked for.

Parameters:
  • filename – The final results file.

  • rank (int) – The rank writing this part.

Returns:

Path of that rank’s part.

Return type:

Path

bsb.simulation.results.read_provenance(block: neo.core.Block) → dict | None[source]

Read the provenance of the run that produced a block of results.

An unrecognised schema version warns and returns what is there rather than refusing: the recordings themselves are plain neo and readable regardless, and refusing a file over metadata written by a newer BSB would keep someone from results that are perfectly intact.

Parameters:

block (neo.core.Block) – Block of results.

Returns:

The provenance bundle, or None if the block carries none.

Return type:

dict | None

bsb.simulation.results.read_results(network: str | os.PathLike | Scaffold, results: str | os.PathLike) → ResultsReader[source]

Read a results file together with the network it was simulated on.

Every run in the file is verified before anything is returned. A run of another network raises a ResultsMismatchError: analysed against the wrong network it would give plausible nonsense. A network that was written to after a run warns, because its positions or labels may have moved since, and a run that recorded no network identity warns that it cannot be verified.

Parameters:
  • network (str | os.PathLike | Scaffold) – Path of the network file, or an opened network. A path is opened like from_storage() opens it, which every rank of an MPI run takes part in: under MPI, read on every rank or pass an opened network.

  • results (str | os.PathLike) – Path of the results file.

Returns:

A reader of the results, whose recordings name the network’s cells.

Raises:
Return type:

ResultsReader

bsb.simulation.results.read_simulation_config(block: neo.core.Block) → dict | None[source]

Read the configuration of the simulation that produced a block of results.

Parameters:

block (neo.core.Block) – Block of results, either taken from a SimulationResult or read back out of a results file.

Returns:

The configuration tree of the simulation, or None if the block carries none. A file written before the configuration was encoded carries only the tree’s top-level keys, which are returned as they were found, after a warning: the values were never written and cannot be recovered.

Return type:

dict | None

bsb.simulation.results.synapse_annotations(post, synapse_type: str, direction: str, pre=None, connectivity_set=None) → dict[source]

Annotations of a recording of a synapse, between the cell it is on and the cell of the connection it belongs to.

Parameters:
  • post (tuple[CellModel, int, int, int, float]) – Where the synapse is: the cell model, cell id, branch, point, and arc of the location on the postsynaptic cell.

  • synapse_type (str) – Name of the synapse type.

  • direction (str) – "record" when the device observes what it records, or "stimulate" when it injects it.

  • pre (tuple[CellModel, int, int, int] | None) – Where the connection starts: the cell model, cell id, branch and point of the location on the presynaptic cell. None for a synapse that belongs to no connection.

  • connectivity_set – Name of the connectivity set of the connection.

Returns:

The annotations to pass to the Neo object.

Return type:

dict

bsb.simulation.targetting module

class bsb.simulation.targetting.BranchLocTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: LabelTargetting

get_locations(cell)[source]
get_node_name()
x

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.targetting.ByIdTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: FractionFilter, CellTargetting

Targets all given identifiers.

get_node_name()
get_targets(adapter, simulation, simdata)[source]
ids: dict[str, list[int]]

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.targetting.ByLabelTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: CellModelFilter, FractionFilter, CellTargetting

Targets all given labels.

get_node_name()
get_targets(adapter, simulation, simdata)[source]
labels: list[str]

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.targetting.CellModelFilter[source]

Bases: object

cell_models: list[CellModel]
get_targets(adapter, simulation, simdata)[source]
class bsb.simulation.targetting.CellModelTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: CellModelFilter, FractionFilter, CellTargetting

Targets all cells of certain cell models.

cell_models: list[CellModel]
get_node_name()
get_targets(adapter, simulation, simdata)[source]
class bsb.simulation.targetting.CellTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: Targetting

get_node_name()
get_targets(adapter, simulation, simdata)[source]
type: Literal['cell'] | Literal['connection']
class bsb.simulation.targetting.ConnectionTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: Targetting

get_node_name()
get_targets(adapter, simulation, simdata)[source]
type: Literal['cell'] | Literal['connection']
class bsb.simulation.targetting.CylindricalTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: CellModelFilter, FractionFilter, CellTargetting

Targets all cells in a cylinder along specified axis.

axis: Literal['x', 'y', 'z']

Main axis of the cylinder.

get_node_name()
get_targets(adapter, simulation, simdata)[source]

Target all or certain cells within a cylinder of specified radius.

origin: ndarray[float]

Coordinates of the base of the cylinder for each non main axis.

radius: float

Radius of the cylinder.

class bsb.simulation.targetting.FractionFilter[source]

Bases: object

count

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

static filter(f)[source]
fraction

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

satisfy_fractions(targets)[source]
class bsb.simulation.targetting.LabelTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: LocationTargetting

get_locations(cell)[source]
get_node_name()
labels
class bsb.simulation.targetting.LocationTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: object

get_locations(cell)[source]
get_node_name()
strategy

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.targetting.RepresentativesTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: CellModelFilter, FractionFilter, CellTargetting

Targets all identifiers of certain cell types.

get_node_name()
get_targets(adapter, simulation, simdata)[source]
n: int

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.targetting.SomaTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: LocationTargetting

Targets every location of a cell that its morphology labels soma.

get_locations(cell)[source]
get_node_name()
class bsb.simulation.targetting.SphericalTargetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: CellModelFilter, FractionFilter, CellTargetting

Targets all cells in a sphere.

get_node_name()
get_targets(adapter, simulation, simdata)[source]

Target all or certain cells within a sphere of specified radius.

origin: list[float]

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

radius: float

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

class bsb.simulation.targetting.Targetting(*args, _parent=None, _key=None, **kwargs)[source]

Bases: RngConsumer

get_node_name()
get_targets(adapter, simulation, simdata)[source]
strategy

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

type: Literal['cell', 'connection']

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

Module contents

class bsb.simulation.SimulationBackendPlugin(Adapter: bsb.simulation.adapter.SimulatorAdapter, Simulation: bsb.simulation.simulation.Simulation)[source]

Bases: object

Parameters:
Adapter: SimulatorAdapter
Simulation: Simulation
bsb.simulation.get_simulation_adapter(name: str, comm=None)[source]

Return the adapter corresponding to the given simulator name.

Parameters:
  • name (str) – Name of the simulator.

  • comm – The mpi4py MPI communicator to use. Only nodes in the communicator will participate in the simulation. The first node will idle as the main node.