# Simulations¶

## From recipe to simulation¶

To build a simulation the following concepts are needed:

The workflow to build a simulation is to first generate an arbor.domain_decomposition based on the arbor.recipe and arbor.context describing the distribution of the model over the local and distributed hardware resources (see Domain Decomposition). Then, the simulation is build using this arbor.domain_decomposition.

import arbor

# Get a communication context (with 4 threads, no GPU)
context = arbor.context(threads=4, gpu_id=None)

# Initialise a recipe of user defined type my_recipe with 100 cells.
n_cells = 100
recipe = my_recipe(n_cells)

# Get a description of the partition of the model over the cores.
decomp = arbor.partition_load_balance(recipe, context)

# Instatitate the simulation.
sim = arbor.simulation(recipe, decomp, context)

# Run the simulation for 2000 ms with time stepping of 0.025 ms
tSim = 2000
dt = 0.025
sim.run(tSim, dt)

class arbor.simulation

The executable form of a model. A simulation is constructed from a recipe, and then used to update and monitor the model state.

Simulations take the following inputs:

The constructor takes

Simulations provide an interface for executing and interacting with the model:

• Advance the model state from one time to another and reset the model state to its original state before simulation was started.
• Sample the simulation state during the execution (e.g. compartment voltage and current) and generate spike output by using an I/O interface.

Constructor:

simulation(recipe, domain_decomposition, context)

Initialize the model described by an arbor.recipe, with cells and network distributed according to arbor.domain_decomposition, and computational resources described by arbor.context.

Updating Model State:

reset()

Reset the state of the simulation to its initial state.

run(tfinal, dt)

Run the simulation from current simulation time to tfinal, with maximum time step size dt.

Parameters: tfinal – The final simulation time [ms]. dt – The time step size [ms].
set_binning_policy(policy, bin_interval)

Set the binning policy for event delivery, and the binning time interval bin_interval if applicable [ms].

Parameters: policy – The binning policy of type binning. bin_interval – The binning time interval [ms].

Types:

class binning

Enumeration for event time binning policy.

none

No binning policy.

regular

Round time down to multiple of binning interval.

following

Round times down to previous event if within binning interval.

## Recording spikes¶

In order to analyze the simulation output spikes can be recorded.

Types:

class arbor.spike
spike()

Construct a spike.

source

The spike source (type: arbor.cell_member).

time

The spike time [ms].

class arbor.spike_recorder
spike_recorder()

Initialize the spike recorder.

spikes

The recorded spikes (type: spike).

I/O interface:

arbor.attach_spike_recorder(sim)

Attach a spike recorder to an arbor simulation sim. The recorder that is returned will record all spikes generated after it has been attached (spikes generated before attaching are not recorded).

import arbor

# Instatitate the simulation.
sim = arbor.simulation(recipe, decomp, context)

# Build the spike recorder
recorder = arbor.attach_spike_recorder(sim)

# Run the simulation for 2000 ms with time stepping of 0.025 ms
tSim = 2000
dt = 0.025
sim.run(tSim, dt)

# Print the spikes and according spike time
for s in recorder.spikes:
print(s)

>>> <arbor.spike: source (0,0), time 2.15168 ms>
>>> <arbor.spike: source (1,0), time 14.5235 ms>
>>> <arbor.spike: source (2,0), time 26.9051 ms>
>>> <arbor.spike: source (3,0), time 39.4083 ms>
>>> <arbor.spike: source (4,0), time 51.9081 ms>
>>> <arbor.spike: source (5,0), time 64.2902 ms>
>>> <arbor.spike: source (6,0), time 76.7706 ms>
>>> <arbor.spike: source (7,0), time 89.1529 ms>
>>> <arbor.spike: source (8,0), time 101.641 ms>
>>> <arbor.spike: source (9,0), time 114.125 ms>