Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b54c0b9
updated site
Olimaol Jan 12, 2024
f159e7d
updated site
Olimaol Jan 12, 2024
62216ae
Merge branch 'master' of https://github.com/Olimaol/CompNeuroPy into …
Olimaol Jan 15, 2024
2e9f30e
OptNeuron check types without warning
Olimaol Jan 15, 2024
1c827f6
OptNeuron TODO
Olimaol Jan 15, 2024
eb34c46
OptNeuron: started deap implementation
Olimaol Jan 16, 2024
657a782
OptNeuron: implemented cma optimization
Olimaol Jan 17, 2024
d487a99
documentated deap implementation
Olimaol Jan 18, 2024
1977727
removed site
Olimaol Jan 18, 2024
5633d62
Add documentation link for olimaol_develop branch
Olimaol Jan 18, 2024
c85af4f
new Corbit neuron
Olimaol Jan 19, 2024
5d22e74
fixed bug in PlotRecordings
Olimaol Jan 19, 2024
09124df
CompNeuroModel: silent compilation
Olimaol Jan 23, 2024
385f60d
Merge branch 'olimaol_develop' of https://github.com/Olimaol/CompNeur…
Olimaol Jan 23, 2024
a580025
.
Olimaol Jan 23, 2024
1ad482e
.
Olimaol Jan 23, 2024
94ff8bd
new class VClampParamSearch
Olimaol Jan 24, 2024
ecf1bf6
extra_functions:
Olimaol Jan 25, 2024
01d7264
VClampParamSearch:
Olimaol Jan 25, 2024
8a0b398
CompNeuroExp:
Olimaol Jan 26, 2024
c7cba58
VClampParamSearch, OptNeuron:
Olimaol Jan 29, 2024
1ebc53d
added syn current to fit Corbit
Olimaol Jan 29, 2024
441dc94
extra_functions new: interactive plot
Olimaol Jan 31, 2024
ddc867a
added new dependencies
Olimaol Jan 31, 2024
9624d88
.
Olimaol Jan 31, 2024
110e362
restructured simulation functions
Olimaol Jan 31, 2024
0dee828
fixed cma sampler clipping
Olimaol Jan 31, 2024
d10ac19
deap cma: added source solutions
Olimaol Feb 1, 2024
c3d59b9
started implementing benchmark izhikevich
Olimaol Feb 1, 2024
a88ffb1
CompNeuroExp:
Olimaol Feb 2, 2024
7160930
OptNeuron:
Olimaol Feb 2, 2024
244bf59
working on benchmark izh opt neuron
Olimaol Feb 2, 2024
8059183
added run_script_parallel
Olimaol Feb 5, 2024
8942310
benchmark for cuneus
Olimaol Feb 5, 2024
3c306da
continue with benchmark
Olimaol Feb 6, 2024
61a97ad
finished anova_between_groups
Olimaol Feb 7, 2024
49f291b
added attr simulation functions to init
Olimaol Feb 29, 2024
0a3bc87
Merge branch 'olimaol_develop' of https://github.com/Olimaol/CompNeur…
Olimaol Feb 29, 2024
0ea5452
added efel_loss to init, small documentation/type hints changes
Olimaol Feb 29, 2024
f5a1089
Merge branch 'olimaol_develop' of https://github.com/Olimaol/CompNeur…
Olimaol Feb 29, 2024
b4c33db
updated efel loss
Olimaol Mar 1, 2024
e7d6b9d
added pip-chill to dependencies, extended create_data_raw_folder func…
Olimaol Mar 1, 2024
c19dca2
added pingouin to dependencies
Olimaol Mar 1, 2024
8ef66b1
added efel to dependencies
Olimaol Mar 5, 2024
903a175
Small formating and commenting things for docs
Olimaol Mar 6, 2024
0c19f0e
added tqdm to dependencies
Olimaol Mar 7, 2024
cf0abac
Update test_before_update_master.yml
Olimaol Mar 7, 2024
766363f
Update test_before_update_master.yml
Olimaol Mar 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test_before_update_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install pytest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ dist/
!docs/*
!site/*
*.pkl
*json
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Assisting package for computational neuroscience with ANNarchy ([GitHub](https:/
The documentation is available online at:
[https://olimaol.github.io/CompNeuroPy/](https://olimaol.github.io/CompNeuroPy/)

The documentation for olimaol_develop branch is available at:
[https://compneuropy.github.io/CompNeuroPy/](https://compneuropy.github.io/CompNeuroPy/)

### Authors

* Oliver Maith (oli_maith@gmx.de)
3 changes: 3 additions & 0 deletions docs/additional/statistic_functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
::: CompNeuroPy.statistic_functions
options:
show_root_heading: false
67 changes: 43 additions & 24 deletions docs/examples/experiment.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class MyExp(CompNeuroExp):
resets the model and monitors
results():
returns a results object
store_model_state():
stores the state of the model used for reset
reset_model_state():
resets the stored model state
"""

def __init__(
Expand Down Expand Up @@ -90,6 +94,8 @@ class MyExp(CompNeuroExp):
"""
### call reset at the beginning of the experiment to ensure that the model
### is in the same state at the beginning of each experiment run
### we stored the state that the membrane potential is -90 before (see below)
### this can be seen in the results plots
self.reset()

### also always start the monitors, they are stopped automatically at the end
Expand All @@ -101,17 +107,18 @@ class MyExp(CompNeuroExp):
get_population(self.model.populations[0]).E_L = E_L

### SIMULATION START
sim_step.run()
sim_ramp.run()
### if you want to reset the model, you should use the objects reset()
### it's the same as the ANNarchy reset + it resets the CompNeuroMonitors
### creating a new chunk, optionally not changing the parameters
### creating a new chunk, optionally not changing the parameters (but still the
### dynamic variables)
self.reset(parameters=False)
sim_ramp.run()
sim_step.run()
### SIMULATION END

### optional: store anything you want in the data dict, for example information
### about the simulations
self.data["sim"] = [sim_step.simulation_info(), sim_ramp.simulation_info()]
self.data["sim"] = [sim_ramp.simulation_info(), sim_step.simulation_info()]
self.data["population_name"] = self.model.populations[0]
self.data["time_step"] = dt()

Expand All @@ -128,16 +135,7 @@ if __name__ == "__main__":
monitors = CompNeuroMonitors({model.populations[0]: ["v"]})

### define some simulations e.g. using CompNeuroSim
sim_step = CompNeuroSim(
simulation_function=current_step,
simulation_kwargs={
"pop": model.populations[0],
"t1": 500,
"t2": 500,
"a1": 0,
"a2": 50,
},
)
### in the experiment we 1st conduct a ramp simulation
sim_ramp = CompNeuroSim(
simulation_function=current_ramp,
simulation_kwargs={
Expand All @@ -148,10 +146,30 @@ if __name__ == "__main__":
"n": 50,
},
)
### and 2nd a step simulation
sim_step = CompNeuroSim(
simulation_function=current_step,
simulation_kwargs={
"pop": model.populations[0],
"t1": 500,
"t2": 500,
"a1": 0,
"a2": 50,
},
)

### init and run the experiment
my_exp = MyExp(monitors=monitors, model=model, sim_step=sim_step, sim_ramp=sim_ramp)

### demonstration of the store_model_state function
### the current state of the model is the compilation state, e.g. v should be -68
print(f"Compilation state v = {get_population(model.populations[0]).v}")
### the reset function of CompNeuroExp resets to the compilation state by default
### but you can also store the state of model compartments and reset to this state
### here for example we store that the membrane potential is -90
get_population(model.populations[0]).v = -90.0
my_exp.store_model_state(compartment_list=model.populations)

### one use case is to run an experiment multiple times e.g. with different
### parameters
results_run1 = my_exp.run()
Expand All @@ -160,7 +178,7 @@ if __name__ == "__main__":
### plot of the membrane potential from the first and second chunk using results
### experiment run 1
PlotRecordings(
figname="example_experiment_sim_step.png",
figname="example_experiment_sim_ramp.png",
recordings=results_run1.recordings,
recording_times=results_run1.recording_times,
chunk=0,
Expand All @@ -173,7 +191,7 @@ if __name__ == "__main__":
},
)
PlotRecordings(
figname="example_experiment_sim_ramp.png",
figname="example_experiment_sim_step.png",
recordings=results_run1.recordings,
recording_times=results_run1.recording_times,
chunk=1,
Expand All @@ -187,7 +205,7 @@ if __name__ == "__main__":
)
### experiment run 2
PlotRecordings(
figname="example_experiment2_sim_step.png",
figname="example_experiment2_sim_ramp.png",
recordings=results_run2.recordings,
recording_times=results_run2.recording_times,
chunk=0,
Expand All @@ -200,7 +218,7 @@ if __name__ == "__main__":
},
)
PlotRecordings(
figname="example_experiment2_sim_ramp.png",
figname="example_experiment2_sim_step.png",
recordings=results_run2.recordings,
recording_times=results_run2.recording_times,
chunk=1,
Expand Down Expand Up @@ -234,29 +252,30 @@ if __name__ == "__main__":
```console
$ python experiment.py
ANNarchy 4.7 (4.7.3b) on linux (posix).
Compiling ... OK
Generate fig example_experiment_sim_step.png... Done

Compilation state v = [-68.]
Generate fig example_experiment_sim_ramp.png... Done

Generate fig example_experiment2_sim_step.png... Done
Generate fig example_experiment_sim_step.png... Done

Generate fig example_experiment2_sim_ramp.png... Done

Generate fig example_experiment2_sim_step.png... Done


run1:
data:
sim: [<CompNeuroPy.generate_simulation.SimInfo object at 0x7f4798dfb700>, <CompNeuroPy.generate_simulation.SimInfo object at 0x7f4798dfad40>]
sim: [<CompNeuroPy.generate_simulation.SimInfo object at 0x7f71f8cd1f00>, <CompNeuroPy.generate_simulation.SimInfo object at 0x7f71f8cd1fc0>]
population_name: HH_Bischop
time_step: 0.01
mon_dict:
HH_Bischop: ['v']

run2:
data:
sim: [<CompNeuroPy.generate_simulation.SimInfo object at 0x7f4798dfb700>, <CompNeuroPy.generate_simulation.SimInfo object at 0x7f4798dfad40>]
sim: [<CompNeuroPy.generate_simulation.SimInfo object at 0x7f71f9181570>, <CompNeuroPy.generate_simulation.SimInfo object at 0x7f71f8c5a8c0>]
population_name: HH_Bischop
time_step: 0.01
mon_dict:
HH_Bischop: ['v']

```
77 changes: 43 additions & 34 deletions docs/examples/opt_neuron.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ from CompNeuroPy.opt_neuron import OptNeuron
import numpy as np
from ANNarchy import Neuron, dt


### in this example we want to fit an ANNarchy neuron model to some data (which ca be
### somehow obtained by simulating the neuron and recording variables) for this example,
### we have the following simple neuron model
### we have the following simple neuron model, you must not use the :population flag
### for the parameters!
my_neuron = Neuron(
parameters="""
I_app = 0
a = 0 : population
b = 0 : population
a = 0
b = 0
""",
equations="""
r = a*I_app + b
Expand Down Expand Up @@ -88,12 +88,14 @@ class my_exp(CompNeuroExp):

For using the CompNeuroExp for OptNeuron, the run function should have
one argument which is the name of the population which is automatically created
by OptNeuron, containing a single neuron of the model which should be optimized.
by OptNeuron, containing a single or multiple neurons of the neuron model which
should be optimized. Thus, the run function should be able to run the experiment
with a single or multiple neurons in the given population!

Args:
population_name (str):
name of the population which contains a single neuron, this will be
automatically provided by OptNeuron
name of the population with neurons of the tuned neuron model, this will
be automatically provided by OptNeuron

Returns:
results (CompNeuroExp._ResultsCl):
Expand All @@ -107,11 +109,6 @@ class my_exp(CompNeuroExp):
data (dict):
dict with optional data stored during the experiment
"""
### For OptNeuron you have to reset the model and monitors at the beginning of
### the run function! Do not reset the parameters, otherwise the optimization
### will not work!
self.reset(parameters=False)

### you have to start monitors within the run function, otherwise nothing will
### be recorded
self.monitors.start()
Expand All @@ -133,9 +130,16 @@ class my_exp(CompNeuroExp):
monitor_object=self.monitors,
)

### run the simulation, remember setting parameters=False in the reset function!
### run the simulation
sim_step.run()
self.reset(parameters=False)
### Here we reset the model and monitors, creating a new chunk for the next sim
### use the self.reset() function to reset the model and monitors!
### OptNeuron sets the parameters (defined in the variables_bounds dict) of the
### neuron model before each run.
### By using the reset function of the CompNeuroExp class you reset the model to
### this state (all varaiables/parameters not defined in variable bounds are
### reset to compile state)
self.reset()
sim_step.run({"a2": 10})

### optional: store anything you want in the data dict. For example infomration
Expand Down Expand Up @@ -169,6 +173,8 @@ def get_loss(results_ist: CompNeuroExp._ResultsCl, results_soll):
### results_ist, we do not use all available information here, but you could
rec_ist = results_ist.recordings
pop_ist = results_ist.data["population_name"]

### the get_loss function should always calculate the loss for neuron rank 0!
neuron = 0

### get the data for calculating the loss from the results_soll
Expand Down Expand Up @@ -206,12 +212,12 @@ def main():
results_soll=experimental_data["results_soll"],
time_step=experimental_data["time_step"],
compile_folder_name="annarchy_opt_neuron_example_from_data",
method="hyperopt",
method="deap",
record=["r"],
)

### run the optimization, define how often the experiment should be repeated
fit = opt.run(max_evals=1000, results_file_name="best_from_data")
fit = opt.run(max_evals=100, results_file_name="best_from_data")

### print optimized parameters, we should get around a=0.8 and b=2
print("a", fit["a"])
Expand All @@ -231,10 +237,10 @@ OptNeuron: Initialize OptNeuron... do not create anything with ANNarchy before!
OptNeuron: WARNING: attributes ['I_app', 'r'] are not used/initialized.
checking neuron_models, experiment, get_loss...Done

100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:45<00:00, 21.99trial/s, best loss: 0.31922683758789056]
a 0.7609542202637395
b 2.171783070482363
['a', 'b', 'loss', 'all_loss', 'std', 'results', 'results_soll']
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:03<00:00, 26.66gen/s, best loss: 0.00000]
a 0.8000000007960777
b 1.9999999939091158
['a', 'b', 'logbook', 'deap_pop', 'loss', 'all_loss', 'std', 'results', 'results_soll']
```

## Optimize neuron model from other neuron model
Expand Down Expand Up @@ -262,15 +268,15 @@ from run_opt_neuron_from_data import my_neuron as simple_neuron
complex_neuron = Neuron(
parameters="""
I_app = 0
f = 6.0542364610842572e-002 : population
e = 3.7144041714209490e+000 : population
d = -4.9446336126026436e-001 : population
c = 9.0909599124334911e-002 : population
b = -4.4497411506061648e-003 : population
a = -6.2239117460540167e-005 : population
m0 = 1
m1 = 2
m2 = 3
n0 = 1
n1 = 0
n2 = -1
""",
equations="""
r = a*I_app**5 + b*I_app**4 + c*I_app**3 + d*I_app**2 + e*I_app**1 + f
r = m0*I_app + n0 + m1*I_app + n1 + m2*I_app + n2
""",
)

Expand Down Expand Up @@ -302,6 +308,9 @@ def get_loss(
pop_ist = results_ist.data["population_name"]
rec_soll = results_soll.recordings
pop_soll = results_soll.data["population_name"]

### the get_loss function should always calculate the loss for neuron rank 0! For
### both, the target and the optimized neuron model.
neuron = 0

### get the data for calculating the loss from the recordings of the
Expand Down Expand Up @@ -333,14 +342,14 @@ def main():
target_neuron_model=complex_neuron,
time_step=1,
compile_folder_name="annarchy_opt_neuron_example_from_neuron",
method="hyperopt",
method="deap",
record=["r"],
)

### run the optimization, define how often the experiment should be repeated
fit = opt.run(max_evals=1000, results_file_name="best_from_neuron")
fit = opt.run(max_evals=100, results_file_name="best_from_neuron")

### print optimized parameters, we should get around a=2.8 and b=0.28
### print optimized parameters, we should get around a=6 and b=0
print("a", fit["a"])
print("b", fit["b"])
print(list(fit.keys()))
Expand All @@ -358,8 +367,8 @@ OptNeuron: Initialize OptNeuron... do not create anything with ANNarchy before!
OptNeuron: WARNING: attributes ['I_app', 'r'] are not used/initialized.
checking neuron_models, experiment, get_loss...Done

100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:47<00:00, 21.10trial/s, best loss: 0.5607444520201438]
a 2.8009641859311354
b 0.22697565003968234
['a', 'b', 'loss', 'all_loss', 'std', 'results', 'results_soll']
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:03<00:00, 26.96gen/s, best loss: 0.00000]
a 5.99999999677215
b 2.8379565285300652e-08
['a', 'b', 'logbook', 'deap_pop', 'loss', 'all_loss', 'std', 'results', 'results_soll']
```
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Documentation for CompNeuroPy

CompNeuroPy is an assisting Python package for working with ANNarchy ([GitHub](https://github.com/ANNarchy/ANNarchy), [documentation](https://annarchy.github.io/), [DOI](https://doi.org/10.5281/zenodo.6415039)). It is intended to help structure simulations with computational neuroscience models in a modular way and to make them more easily replicable.
People who want to start working with ANNarchy are strongly recommended to first learn exclusively the functionality of ANNarchy. CompNeuroPy uses very few features of ANNarchy at this time. But also adds various special features.
People who want to start working with ANNarchy are strongly recommended to first learn exclusively the functionality of ANNarchy. CompNeuroPy uses very few features of ANNarchy at this time. But also adds various special features.

- v1.0.0: [![DOI](https://zenodo.org/badge/422217136.svg)](https://zenodo.org/doi/10.5281/zenodo.10497610)
4 changes: 3 additions & 1 deletion docs/main/define_experiment.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
::: CompNeuroPy.experiment.CompNeuroExp
::: CompNeuroPy.experiment.CompNeuroExp
### Full Example
A full example is available in the [Examples](../examples/experiment.md).
Loading