Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/devices #5

Merged
merged 8 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
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
89 changes: 88 additions & 1 deletion tests/test_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import nest
import numpy as np
from bsb import BootError, ConfigurationError
from bsb import BootError, CastError, ConfigurationError
from bsb.config import Configuration
from bsb.core import Scaffold
from bsb.services import MPI
Expand Down Expand Up @@ -345,3 +345,90 @@ def test_dc_generator(self):
v_ms[int(50 / resolution) + 1 : int(60 / resolution) + 1] > -70,
"Current injected should raise membrane potential",
)

def test_nest_randomness(self):
nest.ResetKernel()
nest.resolution = 0.1
nest.rng_seed = 1234
# gif_cond_exp implements a random spiking process.
# So it's perfect to test the seed
A = nest.Create(
"gif_cond_exp",
1,
params={"I_e": 200.0, "V_m": nest.random.normal(mean=-70, std=20.0)},
)
spikeA = nest.Create("spike_recorder")
nest.Connect(A, spikeA)
nest.Simulate(1000.0)
spike_times_nest = spikeA.get("events")["times"]
print(spike_times_nest)
drodarie marked this conversation as resolved.
Show resolved Hide resolved

conf = {
"name": "test",
"storage": {"engine": "hdf5"},
"network": {"x": 1, "y": 1, "z": 1},
"partitions": {"B": {"type": "layer", "thickness": 1}},
"cell_types": {"A": {"spatial": {"radius": 1, "count": 1}}},
"placement": {
"placement_A": {
"strategy": "bsb.placement.strategy.FixedPositions",
"cell_types": ["A"],
"partitions": ["B"],
"positions": [[1, 1, 1]],
}
},
"connectivity": {},
"after_connectivity": {},
"simulations": {
"test": {
"simulator": "nest",
"duration": 1000,
"resolution": 0.1,
"seed": 1234,
"cell_models": {
"A": {
"model": "gif_cond_exp",
"constants": {
"I_e": 200.0,
"V_m": {
"distribution": "normal",
"mean": -70,
"std": 20.0,
},
},
}
},
"connection_models": {},
"devices": {
"record_A_spikes": {
"device": "spike_recorder",
"delay": 0.5,
"targetting": {
"strategy": "cell_model",
"cell_models": ["A"],
},
}
},
}
},
}
cfg = Configuration(conf)
netw = Scaffold(cfg, self.storage)
netw.compile()
results = netw.run_simulation("test")
spike_times_bsb = results.spiketrains[0]
self.assertClose(np.array(spike_times_nest), np.array(spike_times_bsb))
self.assertEqual(
cfg.__tree__()["simulations"]["test"]["cell_models"]["A"]["constants"]["V_m"],
{
"distribution": "normal",
"mean": -70,
"std": 20.0,
},
)
# Test with an unknown distribution
conf["simulations"]["test"]["cell_models"]["A"]["constants"]["V_m"][
"distribution"
] = "bean"
with self.assertRaises(CastError):
Configuration(conf)
drodarie marked this conversation as resolved.
Show resolved Hide resolved
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.