Version control the parameter files

Here we learn a nice little trick to version-control the parameter files while tracking the simulation output directories for all the versions of the network.

[1]:
import denest
import nest
import yaml
from pathlib import Path
from pprint import pprint
[2]:
PARAMS_DIR = Path('./data/params')  # Where all the parameter files are
DATA_DIR = Path('./data/outputs')  # Where all the simulation output directories are

1. Turn PARAMS_DIR into a git directory

2. Make modifications to the parameters

3. Run a simulation with the modified parameter files and track the output directory

A. Generate a unique output directory name

For example, using the current date and time:

[3]:
from datetime import datetime

output_dir_name = datetime.now().strftime("%Y-%m-%d_%H:%M:%S")

output_dir = Path(DATA_DIR)/output_dir_name
output_dir
[3]:
PosixPath('data/outputs/2020-06-30_13:47:32')

C. Run the simulation

[6]:
denest.run(PARAMS_DIR/'tree_paths.yml', output_dir=output_dir)
2020-06-30 13:47:32,953 [denest] INFO:

=== RUNNING SIMULATION ========================================================

2020-06-30 13:47:32,956 [denest] INFO: Loading parameter file paths from data/params/tree_paths.yml
2020-06-30 13:47:32,984 [denest] INFO: Finished loading parameter file paths
2020-06-30 13:47:32,989 [denest] INFO: Loading parameters files:
['./network_tree.yml',
 './simulation.yml',
 './session_models.yml',
 './kernel.yml']
2020-06-30 13:47:33,080 [denest] INFO: Initializing simulation...
2020-06-30 13:47:33,113 [denest.utils.validation] INFO: Object `simulation`: params: using default value for optional parameters:
{'input_dir': 'input'}
2020-06-30 13:47:33,115 [denest.simulation] INFO: Initializing NEST kernel and seeds...
2020-06-30 13:47:33,116 [denest.simulation] INFO:   Resetting NEST kernel...
2020-06-30 13:47:33,279 [denest.simulation] INFO:   Setting NEST kernel status...
2020-06-30 13:47:33,299 [denest.simulation] INFO:     Calling `nest.SetKernelStatus({'resolution': 0.5, 'overwrite_files': True})`
2020-06-30 13:47:33,302 [denest.simulation] INFO:     Calling `nest.SetKernelStatus({'data_path': 'data/outputs/2020-06-30_13:47:32/data', 'grng_seed': 11, 'rng_seeds': range(12, 13)})
2020-06-30 13:47:33,305 [denest.simulation] INFO:   Finished setting NEST kernel status
2020-06-30 13:47:33,309 [denest.simulation] INFO:   Installing external modules...
2020-06-30 13:47:33,342 [denest.simulation] INFO:   Finished installing external modules
2020-06-30 13:47:33,343 [denest.simulation] INFO: Finished initializing kernel
2020-06-30 13:47:33,344 [denest.simulation] INFO: Build N=3 session models
2020-06-30 13:47:33,349 [denest.simulation] INFO: Build N=4 sessions
2020-06-30 13:47:33,361 [denest.session] INFO: Creating session "00_warmup"
2020-06-30 13:47:33,365 [denest.utils.validation] INFO: Object `00_warmup`: params: using default value for optional parameters:
{'reset_network': False, 'synapse_changes': [], 'unit_changes': []}
2020-06-30 13:47:33,370 [denest.session] INFO: Creating session "01_3_spikes"
2020-06-30 13:47:33,375 [denest.utils.validation] INFO: Object `01_3_spikes`: params: using default value for optional parameters:
{'reset_network': False, 'synapse_changes': []}
2020-06-30 13:47:33,379 [denest.session] INFO: Creating session "02_2_spikes"
2020-06-30 13:47:33,381 [denest.utils.validation] INFO: Object `02_2_spikes`: params: using default value for optional parameters:
{'reset_network': False, 'synapse_changes': []}
2020-06-30 13:47:33,388 [denest.session] INFO: Creating session "03_3_spikes"
2020-06-30 13:47:33,394 [denest.utils.validation] INFO: Object `03_3_spikes`: params: using default value for optional parameters:
{'reset_network': False, 'synapse_changes': []}
2020-06-30 13:47:33,401 [denest.simulation] INFO: Sessions: ['00_warmup', '01_3_spikes', '02_2_spikes', '03_3_spikes']
2020-06-30 13:47:33,406 [denest.simulation] INFO: Building network.
2020-06-30 13:47:33,427 [denest.network] INFO: Build N=2 ``Model`` objects
2020-06-30 13:47:33,433 [denest.network] INFO: Build N=2 ``SynapseModel`` objects
2020-06-30 13:47:33,436 [denest.network] INFO: Build N=3 ``Model`` objects
2020-06-30 13:47:33,442 [denest.network] INFO: Build N=2 ``Layer`` or ``InputLayer`` objects.
2020-06-30 13:47:33,444 [denest.utils.validation] INFO: Object `proj_1_AMPA`: params: using default value for optional parameters:
{'type': 'topological'}
2020-06-30 13:47:33,448 [denest.utils.validation] INFO: Object `proj_2_GABAA`: params: using default value for optional parameters:
{'type': 'topological'}
2020-06-30 13:47:33,453 [denest.network] INFO: Build N=2 ``ProjectionModel`` objects
2020-06-30 13:47:33,459 [denest.network] INFO: Build N=3 ``TopoProjection`` objects
2020-06-30 13:47:33,464 [denest.network] INFO: Build N=2 population recorders.
2020-06-30 13:47:33,467 [denest.network] INFO: Build N=1 projection recorders.
2020-06-30 13:47:33,469 [denest.simulation] INFO: Creating network.
2020-06-30 13:47:33,475 [denest.network] INFO: Creating neuron models...
100%|██████████| 2/2 [00:00<00:00, 496.90it/s]
2020-06-30 13:47:33,512 [denest.network] INFO: Creating synapse models...
100%|██████████| 2/2 [00:00<00:00, 678.36it/s]
2020-06-30 13:47:33,522 [denest.network] INFO: Creating recorder models...
100%|██████████| 3/3 [00:00<00:00, 1294.67it/s]
2020-06-30 13:47:33,547 [denest.network] INFO: Creating layers...
  0%|          | 0/2 [00:00<?, ?it/s]/Users/tom/nest/nest-simulator-2.20.0/lib/python3.7/site-packages/nest/lib/hl_api_helper.py:127: UserWarning:
GetNodes is deprecated and will be removed in NEST 3.0. Use             GIDCollection instead.
100%|██████████| 2/2 [00:00<00:00,  7.59it/s]
2020-06-30 13:47:33,823 [denest.network] INFO: Creating population recorders...
100%|██████████| 2/2 [00:00<00:00, 57.99it/s]
2020-06-30 13:47:33,870 [denest.network] INFO: Creating projection recorders...
100%|██████████| 1/1 [00:00<00:00, 90.88it/s]
2020-06-30 13:47:33,910 [denest.network] INFO: Connecting layers...
100%|██████████| 3/3 [00:00<00:00, 62.17it/s]
2020-06-30 13:47:34,027 [denest.network] INFO: Network size (including recorders and parrot neurons):
Number of nodes: 206
Number of projections: 6650
2020-06-30 13:47:34,087 [denest.simulation] INFO: Finished creating network
2020-06-30 13:47:34,094 [denest.simulation] INFO: Saving simulation metadata...
2020-06-30 13:47:34,106 [denest.simulation] INFO: Creating output directory: data/outputs/2020-06-30_13:47:32
2020-06-30 13:47:34,145 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-30_13:47:32
2020-06-30 13:47:34,161 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-30_13:47:32
2020-06-30 13:47:34,177 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-30_13:47:32/data
2020-06-30 13:47:34,189 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-30_13:47:32/data
2020-06-30 13:47:34,193 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-30_13:47:32/data
2020-06-30 13:47:34,195 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-30_13:47:32
2020-06-30 13:47:34,311 [denest.simulation] INFO: Finished saving simulation metadata
2020-06-30 13:47:34,315 [denest] INFO: Finished initializing simulation
2020-06-30 13:47:34,375 [denest] INFO: Running simulation...
2020-06-30 13:47:34,377 [denest.simulation] INFO: Running 4 sessions...
2020-06-30 13:47:34,379 [denest.simulation] INFO: Running session: '00_warmup'...
2020-06-30 13:47:34,383 [denest.session] INFO: Initializing session...
2020-06-30 13:47:34,396 [denest.network.recorders] INFO:   Setting status for recorder my_multimeter_l1_l1_exc: {'start': 100.0}
2020-06-30 13:47:34,401 [denest.network.recorders] INFO:   Setting status for recorder my_spike_detector_input_layer_parrot_neuron: {'start': 100.0}
2020-06-30 13:47:34,408 [denest.network.recorders] INFO:   Setting status for recorder weight_recorder_proj_1_AMPA-l1-l1_exc-l1-l1_inh: {'start': 100.0}
2020-06-30 13:47:34,414 [denest.session] INFO: Setting `origin` flag to `0.0` for all stimulation devices in ``InputLayers`` for session `00_warmup`
2020-06-30 13:47:34,418 [denest.session] INFO: Finished initializing session

2020-06-30 13:47:34,421 [denest.session] INFO: Running session '00_warmup' for 100 ms
2020-06-30 13:47:34,627 [denest.session] INFO: Finished running session
2020-06-30 13:47:34,630 [denest.session] INFO: Session '00_warmup' virtual running time: 100 ms
2020-06-30 13:47:34,727 [denest.session] INFO: Session '00_warmup' real running time: 0h:00m:00s
2020-06-30 13:47:34,732 [denest.simulation] INFO: Done running session '00_warmup'
2020-06-30 13:47:34,734 [denest.simulation] INFO: Running session: '01_3_spikes'...
2020-06-30 13:47:34,756 [denest.session] INFO: Initializing session...
2020-06-30 13:47:34,759 [denest.session] INFO: Setting `origin` flag to `100.0` for all stimulation devices in ``InputLayers`` for session `01_3_spikes`
2020-06-30 13:47:34,767 [denest.utils.validation] INFO: Object `Unit changes dictionary`: params: using default value for optional parameters:
{'change_type': 'constant', 'from_array': False}
2020-06-30 13:47:34,769 [denest.network.layers] INFO: Layer='input_layer', pop='spike_generator': Applying 'constant' change, param='spike_times', from single value')
2020-06-30 13:47:34,902 [denest.session] INFO: Finished initializing session

2020-06-30 13:47:34,904 [denest.session] INFO: Running session '01_3_spikes' for 100 ms
2020-06-30 13:47:35,115 [denest.session] INFO: Finished running session
2020-06-30 13:47:35,116 [denest.session] INFO: Session '01_3_spikes' virtual running time: 100 ms
2020-06-30 13:47:35,117 [denest.session] INFO: Session '01_3_spikes' real running time: 0h:00m:00s
2020-06-30 13:47:35,118 [denest.simulation] INFO: Done running session '01_3_spikes'
2020-06-30 13:47:35,120 [denest.simulation] INFO: Running session: '02_2_spikes'...
2020-06-30 13:47:35,125 [denest.session] INFO: Initializing session...
2020-06-30 13:47:35,126 [denest.session] INFO: Setting `origin` flag to `200.0` for all stimulation devices in ``InputLayers`` for session `02_2_spikes`
2020-06-30 13:47:35,159 [denest.utils.validation] INFO: Object `Unit changes dictionary`: params: using default value for optional parameters:
{'change_type': 'constant', 'from_array': False}
2020-06-30 13:47:35,161 [denest.network.layers] INFO: Layer='input_layer', pop='spike_generator': Applying 'constant' change, param='spike_times', from single value')
2020-06-30 13:47:35,251 [denest.session] INFO: Finished initializing session

2020-06-30 13:47:35,252 [denest.session] INFO: Running session '02_2_spikes' for 100 ms
2020-06-30 13:47:35,469 [denest.session] INFO: Finished running session
2020-06-30 13:47:35,470 [denest.session] INFO: Session '02_2_spikes' virtual running time: 100 ms
2020-06-30 13:47:35,471 [denest.session] INFO: Session '02_2_spikes' real running time: 0h:00m:00s
2020-06-30 13:47:35,474 [denest.simulation] INFO: Done running session '02_2_spikes'
2020-06-30 13:47:35,477 [denest.simulation] INFO: Running session: '03_3_spikes'...
2020-06-30 13:47:35,506 [denest.session] INFO: Initializing session...
2020-06-30 13:47:35,511 [denest.session] INFO: Setting `origin` flag to `300.0` for all stimulation devices in ``InputLayers`` for session `03_3_spikes`
2020-06-30 13:47:35,525 [denest.utils.validation] INFO: Object `Unit changes dictionary`: params: using default value for optional parameters:
{'change_type': 'constant', 'from_array': False}
2020-06-30 13:47:35,526 [denest.network.layers] INFO: Layer='input_layer', pop='spike_generator': Applying 'constant' change, param='spike_times', from single value')
2020-06-30 13:47:35,606 [denest.session] INFO: Finished initializing session

2020-06-30 13:47:35,607 [denest.session] INFO: Running session '03_3_spikes' for 100 ms
2020-06-30 13:47:35,716 [denest.session] INFO: Finished running session
2020-06-30 13:47:35,716 [denest.session] INFO: Session '03_3_spikes' virtual running time: 100 ms
2020-06-30 13:47:35,717 [denest.session] INFO: Session '03_3_spikes' real running time: 0h:00m:00s
2020-06-30 13:47:35,722 [denest.simulation] INFO: Done running session '03_3_spikes'
2020-06-30 13:47:35,727 [denest.simulation] INFO: Finished running simulation
2020-06-30 13:47:35,745 [denest] INFO: Finished running simulation
2020-06-30 13:47:35,757 [denest] INFO: Total simulation virtual time: 400.0 ms
2020-06-30 13:47:35,762 [denest] INFO: Total simulation real time: 0h:00m:02s
2020-06-30 13:47:35,769 [denest] INFO: Simulation output written to: /Users/tom/docker/nets-dev/docs/source/tutorials/data/outputs/2020-06-30_13:47:32

The simulation output was saved in the unique output directory created.

[7]:
print(output_dir)
!ls {output_dir}
data/outputs/2020-06-30_13:47:32
data               parameter_tree.yml session_times.yml  versions.txt

The PARAMS_DIR/output symlink points to the actual output directory.

[8]:
!ls {PARAMS_DIR/'output/'}
data               parameter_tree.yml session_times.yml  versions.txt

4. Commit the PARAMS_DIR with the updated params and output symlimk