03 Simulation Campaign

Sometimes it may be useful to directly open a Simulation Campaign, to work on the simulations.

In these cases it’s possible to use the class SimulationCampaign as shown in the following code:

from blueetl.campaign.config import SimulationCampaign

config_file = "../data/simulation-campaign/config.json"
campaign = SimulationCampaign.load(config_file)

You can then access some attributes:

campaign.name
'49b28d57-9b72-4e29-995e-d5494b3c30d3'
campaign.attrs
{'path_prefix': '/home/docs/checkouts/readthedocs.org/user_builds/blueetl/checkouts/stable/doc/source/data/simulation-campaign',
 'blue_config_template': 'simulation_sonata.tmpl',
 'tstop': 100,
 'circuit_config': '/home/docs/checkouts/readthedocs.org/user_builds/blueetl/checkouts/stable/doc/source/data/circuit/circuit_config.json'}

You can also get the number of simulations, or iterate over the simulations. Each yielded simulation is a SimulationRow object, that can be used to access the attributes of the simulation.

len(campaign)
2
for sim in campaign:
    print(sim.index, sim)
0 SimulationRow(index=0, path='/home/docs/checkouts/readthedocs.org/user_builds/blueetl/checkouts/stable/doc/source/data/simulation-campaign/0/simulation_config.json', conditions={'seed': 334630})
1 SimulationRow(index=1, path='/home/docs/checkouts/readthedocs.org/user_builds/blueetl/checkouts/stable/doc/source/data/simulation-campaign/1/simulation_config.json', conditions={'seed': 174404})

You can access the simulations by index:

campaign[0]
SimulationRow(index=0, path='/home/docs/checkouts/readthedocs.org/user_builds/blueetl/checkouts/stable/doc/source/data/simulation-campaign/0/simulation_config.json', conditions={'seed': 334630})
campaign[1]
SimulationRow(index=1, path='/home/docs/checkouts/readthedocs.org/user_builds/blueetl/checkouts/stable/doc/source/data/simulation-campaign/1/simulation_config.json', conditions={'seed': 174404})

You can list the conditions (i.e. the parameters) of the simulation campaign as a list of names, or as a Pandas DataFrame:

campaign.condition_names
['seed']
campaign.conditions
seed
0 334630
1 174404

You can check if the campaign has been generated using coupled coordinates or not (see bbp-workflow for more details):

campaign.is_coupled()
False

You can check if the underlying simulations are in SONATA format, or BBP:

campaign.is_sonata()
True

You can also get a copy of the campaign as a Pandas DataFrame:

campaign.get()
seed simulation_path
0 334630 /home/docs/checkouts/readthedocs.org/user_buil...
1 174404 /home/docs/checkouts/readthedocs.org/user_buil...

You can filter the simulations by any condition, using the same syntax provided by the Pandas accessor etl.q provided by blueetl.

campaign.get(seed=334630)
seed simulation_path
0 334630 /home/docs/checkouts/readthedocs.org/user_buil...
campaign.get({"seed": 334630})
seed simulation_path
0 334630 /home/docs/checkouts/readthedocs.org/user_buil...

Alternatively, you can get just the ids of the simulations, using the same syntax for the filter:

campaign.ids(seed=334630)
array([0])
campaign.ids({"seed": 334630})
array([0])

If we want to open single simulations instead of running the analysis of the campaign with blueetl, we can use any available tool.

For example, using bluepysnap:

from bluepysnap import Simulation

sim_row = campaign[0]
print(sim_row)

sim = Simulation(sim_row.path)
print(sim)
print(sim.circuit)
SimulationRow(index=0, path='/home/docs/checkouts/readthedocs.org/user_builds/blueetl/checkouts/stable/doc/source/data/simulation-campaign/0/simulation_config.json', conditions={'seed': 334630})
<bluepysnap.simulation.Simulation object at 0x7f99a384b490>
<bluepysnap.circuit.Circuit object at 0x7f99a3854d10>