Skip to content

Commit

Permalink
Simulation config: synapse_replay input files must be .h5 and remove …
Browse files Browse the repository at this point in the history
…the source key (#351)
  • Loading branch information
Weina Ji authored Mar 21, 2024
1 parent 0f7b4e4 commit 033abe3
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
4 changes: 1 addition & 3 deletions include/bbp/sonata/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,8 @@ class SONATA_API SimulationConfig
struct InputHyperpolarizing: public InputBase {};

struct InputSynapseReplay: public InputBase {
/// The location of the file with the spike info for injection
/// The location of the file with the spike info for injection, file extension must be .h5
std::string spikeFile;
/// The node set to replay spikes from
std::string source;
};

struct InputSeclamp: public InputBase {
Expand Down
5 changes: 1 addition & 4 deletions python/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,7 @@ PYBIND11_MODULE(_libsonata, m) {
"SynapseReplay")
.def_readonly("spike_file",
&SimulationConfig::InputSynapseReplay::spikeFile,
DOC_SIMULATIONCONFIG(InputSynapseReplay, spikeFile))
.def_readonly("source",
&SimulationConfig::InputSynapseReplay::source,
DOC_SIMULATIONCONFIG(InputSynapseReplay, source));
DOC_SIMULATIONCONFIG(InputSynapseReplay, spikeFile));

py::class_<SimulationConfig::InputSeclamp, SimulationConfig::InputBase>(simConf, "Seclamp")
.def_readonly("voltage",
Expand Down
6 changes: 3 additions & 3 deletions python/generated/docstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,9 @@ static const char *__doc_bbp_sonata_SimulationConfig_InputSubthreshold_percentLe

static const char *__doc_bbp_sonata_SimulationConfig_InputSynapseReplay = R"doc()doc";

static const char *__doc_bbp_sonata_SimulationConfig_InputSynapseReplay_source = R"doc(The node set to replay spikes from)doc";

static const char *__doc_bbp_sonata_SimulationConfig_InputSynapseReplay_spikeFile = R"doc(The location of the file with the spike info for injection)doc";
static const char *__doc_bbp_sonata_SimulationConfig_InputSynapseReplay_spikeFile =
R"doc(The location of the file with the spike info for injection, file
extension must be .h5)doc";

static const char *__doc_bbp_sonata_SimulationConfig_ModificationBase = R"doc()doc";

Expand Down
22 changes: 20 additions & 2 deletions python/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,7 @@ def test_basic(self):
self.assertEqual(self.config.input('ex_replay').duration, 40000)
self.assertEqual(self.config.input('ex_replay').node_set, "Column")
self.assertEqual(self.config.input('ex_replay').spike_file,
os.path.abspath(os.path.join(PATH, 'config/replay.dat')))
self.assertEqual(self.config.input('ex_replay').source, "ML_afferents")
os.path.abspath(os.path.join(PATH, 'config/replay.h5')))
self.assertEqual(self.config.input('ex_extracellular_stimulation').node_set, 'Column')

self.assertEqual(self.config.input('ex_abs_shotnoise').input_type.name, "conductance")
Expand Down Expand Up @@ -675,3 +674,22 @@ def test_simulation_config_failures(self):
"""
SimulationConfig(contents, "./")
self.assertEqual(e.exception.args, ('`connection_overrides` must be an array', ))

with self.assertRaises(SonataError) as e:
contents = """
{
"run": { "random_seed": 12345, "dt": 0.05, "tstop": 1000 },
"inputs" : {
"ex_replay": {
"input_type": "spikes",
"module": "synapse_replay",
"delay": 0.0,
"duration": 40000.0,
"spike_file": "replay.dat",
"node_set": "Column"
}
}
}
"""
SimulationConfig(contents, "./")
self.assertEqual(e.exception.args, ('Replay spike_file should be a SONATA h5 file', ))
5 changes: 4 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,11 @@ SimulationConfig::Input parseInputModule(const nlohmann::json& valueIt,
SimulationConfig::InputSynapseReplay ret;
parseCommon(ret);
parseMandatory(valueIt, "spike_file", debugStr, ret.spikeFile);
parseOptional(valueIt, "source", ret.source);
ret.spikeFile = toAbsolute(basePath, ret.spikeFile);
const auto extension = fs::path(ret.spikeFile).extension().string();
if (extension != ".h5") {
throw SonataError("Replay spike_file should be a SONATA h5 file");
}
return ret;
}
case Module::seclamp: {
Expand Down
5 changes: 2 additions & 3 deletions tests/data/config/simulation_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,15 @@
"module": "synapse_replay",
"delay": 0.0,
"duration": 40000.0,
"spike_file": "replay.dat",
"source": "ML_afferents",
"spike_file": "replay.h5",
"node_set": "Column"
},
"ex_extracellular_stimulation": {
"input_type": "extracellular_stimulation",
"module": "synapse_replay",
"delay": 0.0,
"duration": 40000.0,
"spike_file": "replay.dat",
"spike_file": "replay.h5",
"node_set": "Column"
},
"ex_OU": {
Expand Down
24 changes: 22 additions & 2 deletions tests/test_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ TEST_CASE("SimulationConfig") {
CHECK(input.delay == 0);
CHECK(input.duration == 40000);
CHECK(input.nodeSet == "Column");
CHECK(endswith(input.spikeFile, "replay.dat"));
CHECK(input.source == "ML_afferents");
CHECK(endswith(input.spikeFile, "replay.h5"));
}
{
const auto input = nonstd::get<SimulationConfig::InputSeclamp>(config.getInput("ex_seclamp"));
Expand Down Expand Up @@ -1200,5 +1199,26 @@ TEST_CASE("SimulationConfig") {
})";
CHECK_THROWS_AS(SimulationConfig(contents, "./"), SonataError);
}
{
// Replay with a non-h5 file
auto contents = R"({
"run": {
"random_seed": 12345,
"dt": 0.05,
"tstop": 1000
},
"inputs" : {
"ex_replay": {
"input_type": "spikes",
"module": "synapse_replay",
"delay": 0.0,
"duration": 40000.0,
"spike_file": "replay.dat",
"node_set": "Column"
}
}
})";
CHECK_THROWS_AS(SimulationConfig(contents, "./"), SonataError);
}
}
}

0 comments on commit 033abe3

Please sign in to comment.