Skip to content

Commit

Permalink
Adding PointNet example with plastic synapses (and recordings)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaeldai committed Dec 27, 2023
1 parent 741b639 commit 990024e
Show file tree
Hide file tree
Showing 22 changed files with 389 additions and 0 deletions.
67 changes: 67 additions & 0 deletions examples/point_stdp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# PointNet simulation with plastic synapses


## Running:
To run a simulation, install bmtk and run the following:
```
$ python run_pointnet.py config.simulation_iclamp.json
```
If successful, will create a *output* directory containing log, spike trains and recorded cell variables.

## The Network:
The network files have already been built and stored as SONATA files in the *network/* directory. The bmtk Builder
script used to create the network files is *build_network.py*. To adjust the parameters and/or topology of the network
change this file and run:
```
$ python build_network.py
```
This will overwrite the existing files in the network directory. Note that there is some randomness in how the network
is built, so expect (slightly) different simulation results everytime the network is rebuilt.

## Simulation Parameters
Parameters to run the simulation, including run-time, inputs, recorded variables, and networks are stored in config.json
and can modified with a text editor.

## Plotting results
```
$ python plot_output.py config.simulation_iclamp.json
```

## Perturbation simulations
The file ```config_pertubration.json``` uses the same network (recurrent connections + feedforward inputs) as before. However
is designed to also simulate the effects of optogenetic or current clamp inhibition and excitation on a subset of the cells.
To run this example:
```bash
$ python run_pointnet.py config_perturbations.json
```

The only difference between this simulation and the original is in the **inputs** section in the config. To simulate the
perturbations we use a current clamp input to make cells 20 through 39 overly excitatory:
```json
"exc_perturbation": {
"input_type": "current_clamp",
"module": "IClamp",
"node_set": {
"population": "cortex",
"node_ids": [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]
},
"amp": 230.0,
"delay": 1.0,
"duration": 3000.0
},
```

For cells 40 through 49 we can use a negative current to depress the cell activity
```json
"inh_perturbation": {
"input_type": "current_clamp",
"module": "IClamp",
"node_set": {
"population": "cortex",
"node_ids": [40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
},
"amp": -230.0,
"delay": 1.0,
"duration": 3000.0
}
```
90 changes: 90 additions & 0 deletions examples/point_stdp/build_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import os, sys

from bmtk.builder import NetworkBuilder
from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator


def build_network():
# target cells recieve inputs with plastic synapses
net_sources = NetworkBuilder('targets')
net_sources.add_nodes(
N=3,
model_type='point_neuron',
model_template='nest:iaf_psc_delta',
dynamics_params='iaf_psc_delta_exc.json'
)
net_sources.build()
net_sources.save(output_dir='network')

# source cells that synapse onto targets
net_feedforward = NetworkBuilder('sources')
net_feedforward.add_nodes(
N=2,
model_type='point_neuron',
model_template='nest:iaf_psc_delta',
dynamics_params='iaf_psc_delta_exc.json'
)

# connection 1: cells 0 --> 0
net_feedforward.add_edges(
source=net_feedforward.nodes(node_id=0),
target=net_sources.nodes(node_id=0),
connection_rule=1,
syn_weight=15.0,
delay=1.0,
dynamics_params='stdp_exc_1.json',
model_template='stdp_synapse'
)

# connection: cells 1 --> 1
net_feedforward.add_edges(
source=net_feedforward.nodes(node_id=1),
target=net_sources.nodes(node_id=1),
connection_rule=1,
syn_weight=15.0,
delay=1.0,
dynamics_params='stdp_exc_2.json',
model_template='stdp_synapse'
)

# connection: cells [0, 1] --> 2
net_feedforward.add_edges(
source=net_feedforward.nodes(),
target=net_sources.nodes(node_id=2),
connection_rule=1,
syn_weight=15.0,
delay=1.0,
dynamics_params='stdp_exc_3.json',
model_template='stdp_synapse'
)

net_feedforward.build()
net_feedforward.save(output_dir='network')

# virtual inputs into feedforward cells
net_virts = NetworkBuilder('virtual')
net_virts.add_nodes(
N=10,
model_type='virtual'
)
net_virts.add_edges(
target=net_feedforward.nodes(),
connection_rule=1,
syn_weight=4.2,
delay=1.5,
dynamics_params='static_exc.json',
model_template='static_synapse'
)
net_virts.build()
net_virts.save(output_dir='network')


def generate_virt_spikes():
psg = PoissonSpikeGenerator()
psg.add(node_ids='network/virtual_nodes.h5', firing_rate=20.0, times=(0.0, 5.0), population='virtual')
psg.to_sonata('inputs/virtual_spikes.h5')


if __name__ == '__main__':
build_network()
generate_virt_spikes()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
86 changes: 86 additions & 0 deletions examples/point_stdp/config.simulation_iclamp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"manifest": {
"$BASE_DIR": "${configdir}",
"$NETWORK_DIR": "$BASE_DIR/network",
"$MODELS_DIR": "$BASE_DIR/components",
"$OUTPUT_DIR": "$BASE_DIR/output_iclamp"
},

"run": {
"tstop": 5000.0,
"dt": 0.01
},

"inputs": {
"current_clamp_steps": {
"input_type": "current_clamp",
"module": "IClamp",
"node_set": {"population": "sources", "node_id": [0]},
"amp": [380.0, 500.0, 600.0],
"delay": [500.0, 2000.0, 3500.0],
"duration": [1000.0, 1000.0, 1000.0]
},
"current_clamp_1": {
"input_type": "current_clamp",
"module": "IClamp",
"node_set": {"population": "sources", "node_id": [1]},
"amp": 450.0,
"delay": 500.0,
"duration": 4000.0
}
},

"reports": {
"membrane_potential": {
"cells": {
"population": "sources"
},
"variable_name": "V_m",
"module": "multimeter_report",
"sections": "soma",
"enabled": true
},
"weight_recorder_1": {
"module": "weight_recorder",
"nest_model": "stdp_synapse",
"model_template": "stdp_synapse_recorder",
"file_name": "stdp_weights.csv",
"enabled": true
}
},

"output": {
"log_file": "log.txt",
"spikes_file": "spikes.h5",
"spikes_file_csv": "spikes.csv",
"output_dir": "$OUTPUT_DIR",
"overwrite_output_dir": true,
"quiet_simulator": true
},

"target_simulator":"NEST",

"components": {
"point_neuron_models_dir": "$MODELS_DIR/cell_models",
"synaptic_models_dir": "$MODELS_DIR/synaptic_models"
},

"networks": {
"nodes": [
{
"nodes_file": "$NETWORK_DIR/targets_nodes.h5",
"node_types_file": "$NETWORK_DIR/targets_node_types.csv"
},
{
"nodes_file": "$NETWORK_DIR/sources_nodes.h5",
"node_types_file": "$NETWORK_DIR/sources_node_types.csv"
}
],
"edges": [
{
"edges_file": "$NETWORK_DIR/sources_targets_edges.h5",
"edge_types_file": "$NETWORK_DIR/sources_targets_edge_types.csv"
}
]
}
}
85 changes: 85 additions & 0 deletions examples/point_stdp/config.simulation_virtual.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"manifest": {
"$BASE_DIR": "${configdir}",
"$NETWORK_DIR": "$BASE_DIR/network",
"$MODELS_DIR": "$BASE_DIR/components",
"$OUTPUT_DIR": "$BASE_DIR/output_virtual",
"$INPUT_DIR": "$BASE_DIR/inputs"
},

"run": {
"tstop": 5000.0,
"dt": 0.01
},

"inputs": {
"thalamus_spikes": {
"input_type": "spikes",
"module": "sonata",
"input_file": "$INPUT_DIR/virtual_spikes.h5",
"node_set": "virtual"
}
},

"reports": {
"membrane_potential": {
"cells": {
"population": "sources"
},
"variable_name": "V_m",
"module": "multimeter_report",
"sections": "soma",
"enabled": true
},
"weight_recorder_1": {
"module": "weight_recorder",
"nest_model": "stdp_synapse",
"model_template": "stdp_synapse_recorder",
"file_name": "stdp_weights.csv",
"enabled": true
}
},

"output": {
"log_file": "log.txt",
"spikes_file": "spikes.h5",
"spikes_file_csv": "spikes.csv",
"output_dir": "$OUTPUT_DIR",
"overwrite_output_dir": true,
"quiet_simulator": true
},

"target_simulator":"NEST",

"components": {
"point_neuron_models_dir": "$MODELS_DIR/cell_models",
"synaptic_models_dir": "$MODELS_DIR/synaptic_models"
},

"networks": {
"nodes": [
{
"nodes_file": "$NETWORK_DIR/targets_nodes.h5",
"node_types_file": "$NETWORK_DIR/targets_node_types.csv"
},
{
"nodes_file": "$NETWORK_DIR/sources_nodes.h5",
"node_types_file": "$NETWORK_DIR/sources_node_types.csv"
},
{
"nodes_file": "$NETWORK_DIR/virtual_nodes.h5",
"node_types_file": "$NETWORK_DIR/virtual_node_types.csv"
}
],
"edges": [
{
"edges_file": "$NETWORK_DIR/sources_targets_edges.h5",
"edge_types_file": "$NETWORK_DIR/sources_targets_edge_types.csv"
},
{
"edges_file": "$NETWORK_DIR/virtual_sources_edges.h5",
"edge_types_file": "$NETWORK_DIR/virtual_sources_edge_types.csv"
}
]
}
}
Binary file added examples/point_stdp/inputs/virtual_spikes.h5
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/point_stdp/network/sources_node_types.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_type_id model_template model_type dynamics_params
100 nest:iaf_psc_delta point_neuron iaf_psc_delta_exc.json
Binary file added examples/point_stdp/network/sources_nodes.h5
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/point_stdp/network/sources_targets_edge_types.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
edge_type_id target_query source_query delay model_template syn_weight dynamics_params
100 node_id=='0' node_id=='0' 1.0 stdp_synapse_recorder 15.0 stdp_exc_1.json
101 node_id=='1' node_id=='1' 1.0 stdp_synapse_recorder 15.0 stdp_exc_2.json
102 node_id=='2' * 1.0 stdp_synapse_recorder 15.0 stdp_exc_1.json
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/point_stdp/network/targets_node_types.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_type_id model_template model_type dynamics_params
100 nest:iaf_psc_delta point_neuron iaf_psc_delta_exc.json
Binary file added examples/point_stdp/network/targets_nodes.h5
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/point_stdp/network/virtual_node_types.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_type_id model_type
100 virtual
Binary file added examples/point_stdp/network/virtual_nodes.h5
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/point_stdp/network/virtual_sources_edge_types.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
edge_type_id target_query source_query delay model_template syn_weight dynamics_params
100 * * 1.5 static_synapse 4.2 static_exc.json
Binary file not shown.
19 changes: 19 additions & 0 deletions examples/point_stdp/plot_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os, sys
import matplotlib.pyplot as plt

from bmtk.analyzer.compartment import plot_traces
from bmtk.analyzer.spike_trains import plot_raster


def plot_results(config_file):
plot_raster(config_file=config_file, show=False, population='sources')
plot_raster(config_file=config_file, show=False, population='targets')
plot_traces(config_file=config_file, report_name='membrane_potential')
plt.show()


if __name__ == '__main__':
if os.path.basename(__file__) != sys.argv[-1]:
plot_results(sys.argv[-1])
else:
plot_results('config.simulation_iclamp.json')
Loading

0 comments on commit 990024e

Please sign in to comment.