Skip to content

Commit

Permalink
Remove v3 attrs from simulation stub (#796)
Browse files Browse the repository at this point in the history
* Remove v3 attrs from simulation stub

* Update simulation.rst

* Update parameter_sweep.py

* Update simulation.rst

* fix formatting
  • Loading branch information
Helveg committed Mar 5, 2024
1 parent a7044cc commit 85ec28c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 54 deletions.
43 changes: 14 additions & 29 deletions docs/simulation/simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
Simulating networks
###################

.. The BSB manages simulations by deferring as soon as possible to the simulation backends.
.. Each simulator has good reasons to make their design choices, befitting of their
.. simulation paradigm. These choices lead to divergence in how simulations are described,
.. and each simulator has their own niche functions. This means that if you are already
.. familiar with a simulator, writing simulation config should feel familiar, on top of that
.. the BSB is able to offer you access to each simulator's full set of features. The downside
.. is that you're required to write a separate simulation config block per backend.
..
.. Now, let's get started.
Simulations can be run through the CLI tool, or through the ``bsb`` library for more
Simulations can be run through the CLI:

.. code-block:: bash
bsb simulate my_network.hdf5 my_sim_name
or through the ``bsb`` library for more
control. When using the CLI, the framework sets up a "hands off" simulation workflow:

* Read the network file
Expand All @@ -24,13 +20,7 @@ control. When using the CLI, the framework sets up a "hands off" simulation work
* Run the simulation
* Collect all the output

.. code-block:: bash
bsb simulate my_network.hdf5 my_sim_name
When you use the library, you can set up more complex workflows. For example a parameter
sweep that loops and modifies the release probability of the AMPA synapse in the
cerebellar granule cell:
When you use the library, you can set up more complex workflows, such as parameter sweeps:

.. literalinclude:: ../../examples/simulation/parameter_sweep.py
:language: python
Expand Down Expand Up @@ -247,21 +237,18 @@ NEURON
Cell models
-----------

A cell model is described by loading external ``arborize.CellModel`` classes:
By default the NEURON adapter uses an ``ArborizedCellModel``, which loads
external ``arborize`` definition to instantiate cells.

.. code-block:: json
{
"cell_models": {
"cell_type_A": {
"model": "dbbs_models.GranuleCell",
"record_soma": true,
"record_spikes": true
"model": "dbbs_models.GranuleCell"
},
"cell_type_B": {
"model": "dbbs_models.PurkinjeCell",
"record_soma": true,
"record_spikes": true
"model": "dbbs_models.PurkinjeCell"
}
}
}
Expand Down Expand Up @@ -290,11 +277,9 @@ can be referenced by name:
Devices
-------

In NEURON an assortment of devices is provided by the BSB to send input, or
record output.
Devices send input, or record output.

In addition to voltage and spike recording we'll place a spike generator and a
voltage clamp:
Here we'll place a spike generator and a voltage clamp:

.. code-block:: json
Expand Down
36 changes: 11 additions & 25 deletions examples/simulation/parameter_sweep.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# A module with cerebellar cell models
import dbbs_models

# A module to read HDF5 data
import h5py

Expand All @@ -9,35 +6,24 @@

from bsb.core import from_storage

# Read the network file
network = from_storage("my_network.hdf5")


# This decorator runs each call to the function in isolation
# on a separate process. Does not work with MPI.
@nrnsub.isolate
def sweep(param):
# Get an adapter to the simulation
adapter = network.create_adapter("my_sim_name")
# Modify the parameter to sweep
dbbs_models.GranuleCell.synapses["AMPA"]["U"] = param
# Prepare simulator & instantiate all the cells and connections
simulation = adapter.prepare()
# Open the network file
network = from_storage("my_network.hdf5")

# (Optionally perform more custom operations before the simulation here.)
# Here you can set whatever simulation parameter you want.
network.simulations.my_sim.devices.my_stim.rate = param

# Run the simulation
adapter.simulate(simulation)

# (Optionally perform more operations or even additional simulation steps here.)

# Collect all results in an HDF5 file and get the path to it.
result_file = adapter.collect_output()
return result_file
results = network.run_simulation("my_sim")
# Tjese are the recorded spiketrains and signals
print(results.spiketrains)
print(results.analogsignals)


for i in range(11):
# Sweep parameter from 0 to 1 in 0.1 increments
result_file = sweep(i / 10)

# Analyze each run's results here
with h5py.File(result_file, "r") as results:
print("What did I record?", list(results["recorders"].keys()))
sweep(i / 10)

0 comments on commit 85ec28c

Please sign in to comment.