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-29_12:33:48')

C. Run the simulation

[6]:
denest.run(PARAMS_DIR/'tree_paths.yml', output_dir=output_dir)
2020-06-29 12:33:48,296 [denest] INFO:

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

2020-06-29 12:33:48,297 [denest] INFO: Loading parameter file paths from data/params/tree_paths.yml
2020-06-29 12:33:48,300 [denest] INFO: Finished loading parameter file paths
2020-06-29 12:33:48,302 [denest] INFO: Loading parameters files:
['./network_tree.yml',
 './simulation.yml',
 './session_models.yml',
 './kernel.yml']
2020-06-29 12:33:48,393 [denest] INFO: Initializing simulation...
2020-06-29 12:33:48,422 [denest.utils.validation] INFO: Object `simulation`: params: using default value for optional parameters:
{'input_dir': 'input'}
2020-06-29 12:33:48,425 [denest.simulation] INFO: Initializing NEST kernel and seeds...
2020-06-29 12:33:48,426 [denest.simulation] INFO:   Resetting NEST kernel...
2020-06-29 12:33:48,433 [denest.simulation] INFO:   Setting NEST kernel status...
2020-06-29 12:33:48,435 [denest.simulation] INFO:     Calling `nest.SetKernelStatus({'resolution': 0.5, 'overwrite_files': True})`
2020-06-29 12:33:48,438 [denest.simulation] INFO:     Calling `nest.SetKernelStatus({'data_path': 'data/outputs/2020-06-29_12:33:48/data', 'grng_seed': 11, 'rng_seeds': range(12, 13)})
2020-06-29 12:33:48,439 [denest.simulation] INFO:   Finished setting NEST kernel status
2020-06-29 12:33:48,446 [denest.simulation] INFO:   Installing external modules...
2020-06-29 12:33:48,457 [denest.simulation] INFO:   Finished installing external modules
2020-06-29 12:33:48,501 [denest.simulation] INFO: Finished initializing kernel
2020-06-29 12:33:48,506 [denest.simulation] INFO: Build N=3 session models
2020-06-29 12:33:48,516 [denest.simulation] INFO: Build N=4 sessions
2020-06-29 12:33:48,520 [denest.session] INFO: Creating session "00_warmup"
2020-06-29 12:33:48,524 [denest.utils.validation] INFO: Object `00_warmup`: params: using default value for optional parameters:
{'reset_network': False, 'synapse_changes': [], 'unit_changes': []}
2020-06-29 12:33:48,525 [denest.session] INFO: Creating session "01_3_spikes"
2020-06-29 12:33:48,535 [denest.utils.validation] INFO: Object `01_3_spikes`: params: using default value for optional parameters:
{'reset_network': False, 'synapse_changes': []}
2020-06-29 12:33:48,546 [denest.session] INFO: Creating session "02_2_spikes"
2020-06-29 12:33:48,552 [denest.utils.validation] INFO: Object `02_2_spikes`: params: using default value for optional parameters:
{'reset_network': False, 'synapse_changes': []}
2020-06-29 12:33:48,554 [denest.session] INFO: Creating session "03_3_spikes"
2020-06-29 12:33:48,555 [denest.utils.validation] INFO: Object `03_3_spikes`: params: using default value for optional parameters:
{'reset_network': False, 'synapse_changes': []}
2020-06-29 12:33:48,559 [denest.simulation] INFO: Sessions: ['00_warmup', '01_3_spikes', '02_2_spikes', '03_3_spikes']
2020-06-29 12:33:48,564 [denest.simulation] INFO: Building network.
2020-06-29 12:33:48,599 [denest.network] INFO: Build N=2 ``Model`` objects
2020-06-29 12:33:48,601 [denest.network] INFO: Build N=2 ``SynapseModel`` objects
2020-06-29 12:33:48,603 [denest.network] INFO: Build N=3 ``Model`` objects
2020-06-29 12:33:48,607 [denest.network] INFO: Build N=2 ``Layer`` or ``InputLayer`` objects.
2020-06-29 12:33:48,614 [denest.utils.validation] INFO: Object `proj_2_GABAA`: params: using default value for optional parameters:
{'type': 'topological'}
2020-06-29 12:33:48,617 [denest.utils.validation] INFO: Object `proj_1_AMPA`: params: using default value for optional parameters:
{'type': 'topological'}
2020-06-29 12:33:48,621 [denest.network] INFO: Build N=2 ``ProjectionModel`` objects
2020-06-29 12:33:48,634 [denest.network] INFO: Build N=3 ``TopoProjection`` objects
2020-06-29 12:33:48,640 [denest.network] INFO: Build N=2 population recorders.
2020-06-29 12:33:48,642 [denest.network] INFO: Build N=1 projection recorders.
2020-06-29 12:33:48,643 [denest.simulation] INFO: Creating network.
2020-06-29 12:33:48,646 [denest.network] INFO: Creating neuron models...
100%|██████████| 2/2 [00:00<00:00, 1164.11it/s]
2020-06-29 12:33:48,669 [denest.network] INFO: Creating synapse models...
100%|██████████| 2/2 [00:00<00:00, 1291.15it/s]
2020-06-29 12:33:48,681 [denest.network] INFO: Creating recorder models...
100%|██████████| 3/3 [00:00<00:00, 1236.16it/s]
2020-06-29 12:33:48,693 [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, 10.22it/s]
2020-06-29 12:33:48,902 [denest.network] INFO: Creating population recorders...
100%|██████████| 2/2 [00:00<00:00, 53.88it/s]
2020-06-29 12:33:48,943 [denest.network] INFO: Creating projection recorders...
100%|██████████| 1/1 [00:00<00:00, 90.04it/s]
2020-06-29 12:33:48,983 [denest.network] INFO: Connecting layers...
100%|██████████| 3/3 [00:00<00:00, 365.27it/s]
2020-06-29 12:33:49,012 [denest.network] INFO: Network size (including recorders and parrot neurons):
Number of nodes: 206
Number of projections: 6650
2020-06-29 12:33:49,021 [denest.simulation] INFO: Finished creating network
2020-06-29 12:33:49,023 [denest.simulation] INFO: Saving simulation metadata...
2020-06-29 12:33:49,028 [denest.simulation] INFO: Creating output directory: data/outputs/2020-06-29_12:33:48
2020-06-29 12:33:49,031 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-29_12:33:48
2020-06-29 12:33:49,036 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-29_12:33:48
2020-06-29 12:33:49,040 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-29_12:33:48/data
2020-06-29 12:33:49,042 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-29_12:33:48/data
2020-06-29 12:33:49,046 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-29_12:33:48/data
2020-06-29 12:33:49,054 [denest.io.save] INFO: Clearing directory: data/outputs/2020-06-29_12:33:48
2020-06-29 12:33:49,129 [denest.simulation] INFO: Finished saving simulation metadata
2020-06-29 12:33:49,134 [denest] INFO: Finished initializing simulation
2020-06-29 12:33:49,150 [denest] INFO: Running simulation...
2020-06-29 12:33:49,160 [denest.simulation] INFO: Running 4 sessions...
2020-06-29 12:33:49,162 [denest.simulation] INFO: Running session: '00_warmup'...
2020-06-29 12:33:49,167 [denest.session] INFO: Initializing session...
2020-06-29 12:33:49,172 [denest.network.recorders] INFO:   Setting status for recorder my_multimeter_l1_l1_exc: {'start': 100.0}
2020-06-29 12:33:49,176 [denest.network.recorders] INFO:   Setting status for recorder my_spike_detector_input_layer_parrot_neuron: {'start': 100.0}
2020-06-29 12:33:49,177 [denest.network.recorders] INFO:   Setting status for recorder weight_recorder_proj_1_AMPA-l1-l1_exc-l1-l1_inh: {'start': 100.0}
2020-06-29 12:33:49,186 [denest.session] INFO: Setting `origin` flag to `0.0` for all stimulation devices in ``InputLayers`` for session `00_warmup`
2020-06-29 12:33:49,200 [denest.session] INFO: Finished initializing session

2020-06-29 12:33:49,201 [denest.session] INFO: Running session '00_warmup' for 100 ms
2020-06-29 12:33:49,500 [denest.session] INFO: Finished running session
2020-06-29 12:33:49,502 [denest.session] INFO: Session '00_warmup' virtual running time: 100 ms
2020-06-29 12:33:49,503 [denest.session] INFO: Session '00_warmup' real running time: 0h:00m:00s
2020-06-29 12:33:49,505 [denest.simulation] INFO: Done running session '00_warmup'
2020-06-29 12:33:49,508 [denest.simulation] INFO: Running session: '01_3_spikes'...
2020-06-29 12:33:49,518 [denest.session] INFO: Initializing session...
2020-06-29 12:33:49,520 [denest.session] INFO: Setting `origin` flag to `100.0` for all stimulation devices in ``InputLayers`` for session `01_3_spikes`
2020-06-29 12:33:49,526 [denest.utils.validation] INFO: Object `Unit changes dictionary`: params: using default value for optional parameters:
{'change_type': 'constant', 'from_array': False}
2020-06-29 12:33:49,529 [denest.network.layers] INFO: Layer='input_layer', pop='spike_generator': Applying 'constant' change, param='spike_times', from single value')
2020-06-29 12:33:49,678 [denest.session] INFO: Finished initializing session

2020-06-29 12:33:49,680 [denest.session] INFO: Running session '01_3_spikes' for 100 ms
2020-06-29 12:33:49,858 [denest.session] INFO: Finished running session
2020-06-29 12:33:49,859 [denest.session] INFO: Session '01_3_spikes' virtual running time: 100 ms
2020-06-29 12:33:49,860 [denest.session] INFO: Session '01_3_spikes' real running time: 0h:00m:00s
2020-06-29 12:33:49,861 [denest.simulation] INFO: Done running session '01_3_spikes'
2020-06-29 12:33:49,863 [denest.simulation] INFO: Running session: '02_2_spikes'...
2020-06-29 12:33:49,865 [denest.session] INFO: Initializing session...
2020-06-29 12:33:49,866 [denest.session] INFO: Setting `origin` flag to `200.0` for all stimulation devices in ``InputLayers`` for session `02_2_spikes`
2020-06-29 12:33:49,873 [denest.utils.validation] INFO: Object `Unit changes dictionary`: params: using default value for optional parameters:
{'change_type': 'constant', 'from_array': False}
2020-06-29 12:33:49,877 [denest.network.layers] INFO: Layer='input_layer', pop='spike_generator': Applying 'constant' change, param='spike_times', from single value')
2020-06-29 12:33:49,939 [denest.session] INFO: Finished initializing session

2020-06-29 12:33:49,940 [denest.session] INFO: Running session '02_2_spikes' for 100 ms
2020-06-29 12:33:50,059 [denest.session] INFO: Finished running session
2020-06-29 12:33:50,060 [denest.session] INFO: Session '02_2_spikes' virtual running time: 100 ms
2020-06-29 12:33:50,060 [denest.session] INFO: Session '02_2_spikes' real running time: 0h:00m:00s
2020-06-29 12:33:50,062 [denest.simulation] INFO: Done running session '02_2_spikes'
2020-06-29 12:33:50,063 [denest.simulation] INFO: Running session: '03_3_spikes'...
2020-06-29 12:33:50,075 [denest.session] INFO: Initializing session...
2020-06-29 12:33:50,077 [denest.session] INFO: Setting `origin` flag to `300.0` for all stimulation devices in ``InputLayers`` for session `03_3_spikes`
2020-06-29 12:33:50,081 [denest.utils.validation] INFO: Object `Unit changes dictionary`: params: using default value for optional parameters:
{'change_type': 'constant', 'from_array': False}
2020-06-29 12:33:50,082 [denest.network.layers] INFO: Layer='input_layer', pop='spike_generator': Applying 'constant' change, param='spike_times', from single value')
2020-06-29 12:33:50,176 [denest.session] INFO: Finished initializing session

2020-06-29 12:33:50,176 [denest.session] INFO: Running session '03_3_spikes' for 100 ms
2020-06-29 12:33:50,271 [denest.session] INFO: Finished running session
2020-06-29 12:33:50,273 [denest.session] INFO: Session '03_3_spikes' virtual running time: 100 ms
2020-06-29 12:33:50,275 [denest.session] INFO: Session '03_3_spikes' real running time: 0h:00m:00s
2020-06-29 12:33:50,277 [denest.simulation] INFO: Done running session '03_3_spikes'
2020-06-29 12:33:50,278 [denest.simulation] INFO: Finished running simulation
2020-06-29 12:33:50,280 [denest] INFO: Finished running simulation
2020-06-29 12:33:50,281 [denest] INFO: Total simulation virtual time: 400.0 ms
2020-06-29 12:33:50,283 [denest] INFO: Total simulation real time: 0h:00m:01s
2020-06-29 12:33:50,289 [denest] INFO: Simulation output written to: /Users/tom/docker/nets-dev/docs/source/tutorials/data/outputs/2020-06-29_12:33:48

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

[7]:
print(output_dir)
!ls {output_dir}
data/outputs/2020-06-29_12:33:48
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