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

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.

post_prepare: cfglist[Callable[[Simulation, Any], None]]

List of hook functions to call after the simulation has been prepared.

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)[source]

Bases: object

Parameters:
result: SimulationResult
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]
abstractmethod prepare(simulation)[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]

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

Simulate the given simulations.

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

  • post_prepare – Optional callable to run after the simulations’ preparation.

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: cfglist[Parameter]

The parameters of the model.

bsb.simulation.component module

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

Bases: object

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()
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.Parameter(*args, _parent=None, _key=None, **kwargs)[source]

Bases: object

get_node_name()
type

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

value: ParameterValue

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

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

Bases: object

get_node_name()
type

Base implementation of all the different configuration attributes.

Call the factory function attr() instead.

bsb.simulation.results module

class bsb.simulation.results.Recording(ps_name: str, cell_id: int, device: str, name: str, units: str, kind: type, data: object, annotations: dict)[source]

Bases: object

Flat view of a single recorded Neo object inside a .nio block.

Parameters:
annotations: dict
cell_id: int
data: object
device: str
kind: type
name: str
ps_name: str
units: str
class bsb.simulation.results.SimulationRecorder(device=None, meta: dict | None = None)[source]

Bases: object

A recorder appends Neo objects to a segment on each flush. It is also inspectable at runtime, before anything is written to file: device_name links it back to the device that created it, and meta exposes recorder-level metadata. This lets a controller (e.g. an LFP probe) find the recorders of the devices it manages during a flush and query their metadata, such as recorder.meta("lfp_source_geometry").

Parameters:

meta (dict | None)

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

segment (neo.core.Segment)

meta(property: str | None = None, default=None)[source]

Query recorder-level metadata. With a property name return that entry (or default); with no argument return a copy of the whole metadata mapping.

Parameters:

property (str | None)

set_meta(property: str, value) None[source]

Set a recorder-level metadata entry.

Parameters:

property (str)

Return type:

None

class bsb.simulation.results.SimulationResult(simulation)[source]

Bases: object

add(recorder)[source]
analog_signal(*, data, units, sampling_period, name: str, ps_name: str, cell_id: int, cell_model, device, recording_kind: str = 'cell', **fields)[source]

Build a AnalogSignal carrying the layered bsb_* annotations.

The annotations come in two layers, all as flat sibling keys. The baseline identifies what is doing the recording and ties the object back to its run: bsb_device_name, bsb_device_kind, bsb_recording_kind, bsb_simulation_id, bsb_segment_id. The recording-kind layer, selected by recording_kind, declares what is being recorded; this helper fills the "cell" anchor (bsb_ps_name, bsb_cell_id, bsb_cell_model) shared by the cell, compartment and synapse kinds.

Neo’s native fields carry the recorded quantity: name is the label (e.g. "V_m", "I_syn") and units the dimension.

Any extra fields are namespaced as first-class bsb_<key> annotations alongside the baseline, so a kind that records a compartment passes section=..., arc=... and gets bsb_section / bsb_arc.

Parameters:
  • name (str)

  • ps_name (str)

  • cell_id (int)

  • recording_kind (str)

property analogsignals
create_recorder(flush: Callable[[neo.core.Segment], None], *, device=None, meta: dict | None = None)[source]

Register flush as a recorder. Pass device to link the recorder back to it (sets recorder.device_name) and meta to expose recorder-level metadata queryable at runtime via recorder.meta(...).

Parameters:
flush()[source]
mark_finished(*, finished_at: str | None = None, wall_seconds: float | None = None) None[source]
Parameters:
  • finished_at (str | None)

  • wall_seconds (float | None)

Return type:

None

mark_started(started_at: str | None = None) None[source]
Parameters:

started_at (str | None)

Return type:

None

property segment_id: str | None

UUID of the segment currently being flushed (set during flush).

set_simulator(name: str, version: str | None = None, **extra) None[source]

Adapters call this in prepare so simulator metadata lands on the Block.

Parameters:
  • name (str)

  • version (str | None)

Return type:

None

spike_train(*, times, ps_name: str, cell_id: int, cell_model, device, t_stop, units: str = 'ms', recording_kind: str = 'cell', **fields)[source]

Build a SpikeTrain carrying the baseline bsb_* annotations plus the "cell"-target fields. See analog_signal() for the annotation layering and how fields extends it.

Convenience only: BSB does not validate or require recorders to use it. Recorders are free to emit any Neo objects they want, in any quantity.

Parameters:
  • ps_name (str)

  • cell_id (int)

  • units (str)

  • recording_kind (str)

property spiketrains
stimulus_train(*, times, device, target_count: int, t_stop, units: str = 'ms')[source]

Build a stimulator SpikeTrain: the device’s own emitted spikes, not a recording of a cell. It carries the baseline bsb_* annotations with bsb_recording_kind="stimulus" and bsb_target_count, but no cell anchor (no bsb_ps_name / bsb_cell_id), so iter_recordings() skips it.

Parameters:
  • target_count (int)

  • units (str)

write(filename, mode)[source]
bsb.simulation.results.iter_recordings(block) Iterator[Recording][source]

Yield one Recording per Neo object across all segments.

Skips Neo objects that lack a bsb_ps_name annotation (e.g. third-party plugin output that does not follow the convention).

Return type:

Iterator[Recording]

bsb.simulation.results.read_nio(path: str) neo.core.Block[source]

Open a .nio file and return its Block.

Parameters:

path (str)

Return type:

neo.core.Block

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', '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', '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

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: object

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.