From a9650ada807f1551f97ad0d903dbae541bbf3195 Mon Sep 17 00:00:00 2001 From: Weina Ji Date: Tue, 5 Nov 2024 13:56:50 +0100 Subject: [PATCH] SimulationConfig: use names for integration_method (#376) --- include/bbp/sonata/config.h | 4 ++-- python/bindings.cpp | 4 ++-- python/generated/docstrings.h | 10 +++++----- python/tests/test_config.py | 2 +- src/config.cpp | 11 ++++++----- tests/data/config/simulation_config.json | 2 +- tests/test_config.cpp | 3 ++- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/bbp/sonata/config.h b/include/bbp/sonata/config.h index ab1bc819..bf671e25 100644 --- a/include/bbp/sonata/config.h +++ b/include/bbp/sonata/config.h @@ -263,7 +263,7 @@ class SONATA_API SimulationConfig * Parameters defining global simulation settings for spike reports */ struct Run { - enum class IntegrationMethod { invalid = -1, euler, nicholson, nicholson_ion }; + enum class IntegrationMethod { invalid = -1, euler, crank_nicolson, crank_nicolson_ion }; static constexpr double DEFAULT_spikeThreshold = -30.0; static constexpr IntegrationMethod DEFAULT_IntegrationMethod = IntegrationMethod::euler; @@ -281,7 +281,7 @@ class SONATA_API SimulationConfig /// The spike detection threshold. Default is -30mV double spikeThreshold = DEFAULT_spikeThreshold; /// Selects the NEURON/CoreNEURON integration method. This parameter sets the NEURON - /// global variable h.secondorder. Default 0 ('euler') + /// global variable h.secondorder, default is "euler". IntegrationMethod integrationMethod = DEFAULT_IntegrationMethod; /// A non-negative integer used for seeding noise stimuli and any other future stochastic /// stimuli, default is 0. diff --git a/python/bindings.cpp b/python/bindings.cpp index 9508d4ae..14a13e3e 100644 --- a/python/bindings.cpp +++ b/python/bindings.cpp @@ -646,8 +646,8 @@ PYBIND11_MODULE(_libsonata, m) { py::enum_(run, "IntegrationMethod") .value("euler", SimulationConfig::Run::IntegrationMethod::euler) - .value("nicholson", SimulationConfig::Run::IntegrationMethod::nicholson) - .value("nicholson_ion", SimulationConfig::Run::IntegrationMethod::nicholson_ion); + .value("crank_nicolson", SimulationConfig::Run::IntegrationMethod::crank_nicolson) + .value("crank_nicolson_ion", SimulationConfig::Run::IntegrationMethod::crank_nicolson_ion); py::class_ output(simConf, "Output", diff --git a/python/generated/docstrings.h b/python/generated/docstrings.h index cb368eeb..37a40abb 100644 --- a/python/generated/docstrings.h +++ b/python/generated/docstrings.h @@ -1157,13 +1157,13 @@ static const char *__doc_bbp_sonata_SimulationConfig_Run = R"doc(Parameters defi static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod = R"doc()doc"; -static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod_euler = R"doc()doc"; +static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod_crank_nicolson = R"doc()doc"; -static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod_invalid = R"doc()doc"; +static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod_crank_nicolson_ion = R"doc()doc"; -static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod_nicholson = R"doc()doc"; +static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod_euler = R"doc()doc"; -static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod_nicholson_ion = R"doc()doc"; +static const char *__doc_bbp_sonata_SimulationConfig_Run_IntegrationMethod_invalid = R"doc()doc"; static const char *__doc_bbp_sonata_SimulationConfig_Run_dt = R"doc(Integration step duration in milliseconds)doc"; @@ -1171,7 +1171,7 @@ static const char *__doc_bbp_sonata_SimulationConfig_Run_electrodesFile = R"doc( static const char *__doc_bbp_sonata_SimulationConfig_Run_integrationMethod = R"doc(Selects the NEURON/CoreNEURON integration method. This parameter sets -the NEURON global variable h.secondorder. Default 0 ('euler'))doc"; +the NEURON global variable h.secondorder, default is "euler".)doc"; static const char *__doc_bbp_sonata_SimulationConfig_Run_ionchannelSeed = R"doc(A non-negative integer used for seeding stochastic ion channels, diff --git a/python/tests/test_config.py b/python/tests/test_config.py index 753dc3e3..94b83888 100644 --- a/python/tests/test_config.py +++ b/python/tests/test_config.py @@ -413,7 +413,7 @@ def test_basic(self): self.assertEqual(self.config.run.random_seed, 201506) self.assertEqual(self.config.run.spike_threshold, -35.5) self.assertEqual(self.config.run.integration_method, - SimulationConfig.Run.IntegrationMethod.nicholson_ion) + SimulationConfig.Run.IntegrationMethod.crank_nicolson_ion) self.assertEqual(self.config.run.stimulus_seed, 111) self.assertEqual(self.config.run.ionchannel_seed, 222) self.assertEqual(self.config.run.minis_seed, 333) diff --git a/src/config.cpp b/src/config.cpp index 9e046af1..2974d604 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -58,11 +58,12 @@ NLOHMANN_JSON_SERIALIZE_ENUM(SimulationConfig::Conditions::SpikeLocation, {SimulationConfig::Conditions::SpikeLocation::soma, "soma"}, {SimulationConfig::Conditions::SpikeLocation::AIS, "AIS"}}) -NLOHMANN_JSON_SERIALIZE_ENUM(SimulationConfig::Run::IntegrationMethod, - {{SimulationConfig::Run::IntegrationMethod::invalid, nullptr}, - {SimulationConfig::Run::IntegrationMethod::euler, 0}, - {SimulationConfig::Run::IntegrationMethod::nicholson, 1}, - {SimulationConfig::Run::IntegrationMethod::nicholson_ion, 2}}) +NLOHMANN_JSON_SERIALIZE_ENUM( + SimulationConfig::Run::IntegrationMethod, + {{SimulationConfig::Run::IntegrationMethod::invalid, nullptr}, + {SimulationConfig::Run::IntegrationMethod::euler, "euler"}, + {SimulationConfig::Run::IntegrationMethod::crank_nicolson, "crank_nicolson"}, + {SimulationConfig::Run::IntegrationMethod::crank_nicolson_ion, "crank_nicolson_ion"}}) NLOHMANN_JSON_SERIALIZE_ENUM(SimulationConfig::Output::SpikesSortOrder, {{SimulationConfig::Output::SpikesSortOrder::invalid, nullptr}, diff --git a/tests/data/config/simulation_config.json b/tests/data/config/simulation_config.json index de2af14e..42e579c7 100644 --- a/tests/data/config/simulation_config.json +++ b/tests/data/config/simulation_config.json @@ -25,7 +25,7 @@ "ionchannel_seed": 222, "minis_seed": 333, "synapse_seed": 444, - "integration_method" : 2, + "integration_method" : "crank_nicolson_ion", "forward_skip": 500, "electrodes_file": "$ELECTRODES_DIR/electrode_weights.h5", "spike_threshold": -35.5 diff --git a/tests/test_config.cpp b/tests/test_config.cpp index d4485b4f..d168a270 100644 --- a/tests/test_config.cpp +++ b/tests/test_config.cpp @@ -310,7 +310,8 @@ TEST_CASE("SimulationConfig") { CHECK(config.getRun().dt == 0.025); CHECK(config.getRun().randomSeed == 201506); CHECK(config.getRun().spikeThreshold == -35.5); - CHECK(config.getRun().integrationMethod == SimulationConfig::Run::IntegrationMethod::nicholson_ion); + CHECK(config.getRun().integrationMethod == + SimulationConfig::Run::IntegrationMethod::crank_nicolson_ion); CHECK(config.getRun().stimulusSeed == 111); CHECK(config.getRun().ionchannelSeed == 222); CHECK(config.getRun().minisSeed == 333);