Skip to content

Commit

Permalink
Parse synapse mod variables in conditions/mechanisms section (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeinaJi authored Jul 12, 2022
1 parent 15adaae commit e0cdaf7
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 12 deletions.
7 changes: 7 additions & 0 deletions include/bbp/sonata/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
namespace bbp {
namespace sonata {

using variantValueType = nonstd::variant<bool, std::string, int, double>;

/**
* Stores population-specific network information.
*/
Expand Down Expand Up @@ -241,6 +243,11 @@ class SONATA_API SimulationConfig
/// Enable legacy behavior to randomize the GABA_A rise time in the helper functions.
/// Default is false
bool randomizeGabaRiseTime;
/// Properties to assign values to variables in synapse MOD files.
/// The format is a dictionary with keys being the SUFFIX names and values being
/// dictionaries of variables' names and values.
std::unordered_map<std::string, std::unordered_map<std::string, variantValueType>>
mechanisms;
};
/**
* List of report parameters collected during the simulation
Expand Down
5 changes: 4 additions & 1 deletion python/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,10 @@ PYBIND11_MODULE(_libsonata, m) {
DOC_SIMULATIONCONFIG(Conditions, minisSingleVesicle))
.def_readonly("randomize_gaba_rise_time",
&SimulationConfig::Conditions::randomizeGabaRiseTime,
DOC_SIMULATIONCONFIG(Conditions, randomizeGabaRiseTime));
DOC_SIMULATIONCONFIG(Conditions, randomizeGabaRiseTime))
.def_readonly("mechanisms",
&SimulationConfig::Conditions::mechanisms,
DOC_SIMULATIONCONFIG(Conditions, mechanisms));

py::class_<SimulationConfig::Report> report(m, "Report", "Parameters of a report");
report
Expand Down
49 changes: 41 additions & 8 deletions python/generated/docstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ R"doc(Extracellular calcium concentration, being applied to the synapse
uHill parameter in order to scale the U parameter of synapses. Default
is None.)doc";

static const char *__doc_bbp_sonata_SimulationConfig_Conditions_mechanisms =
R"doc(Properties to assign values to variables in synapse MOD files. The
format is a dictionary with keys being the SUFFIX names and values
being dictionaries of variables' names and values.)doc";

static const char *__doc_bbp_sonata_SimulationConfig_Conditions_minisSingleVesicle =
R"doc(Limit spontaneous release to single vesicle when true. Default is
false)doc";
Expand Down Expand Up @@ -875,19 +880,43 @@ static const char *__doc_bbp_sonata_SimulationConfig_Report_variableName = R"doc

static const char *__doc_bbp_sonata_SimulationConfig_Run = R"doc(Parameters defining global simulation settings for spike reports)doc";

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_invalid = 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_nicholson_ion = R"doc()doc";

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

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

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

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

static const char *__doc_bbp_sonata_SimulationConfig_Run_dt = R"doc(Integration step duration in milliseconds)doc";

static const char *__doc_bbp_sonata_SimulationConfig_Run_randomSeed = R"doc(Random seed)doc";
static const char *__doc_bbp_sonata_SimulationConfig_Run_forwardSkip =
R"doc(Run without Stimulus or Reports for given duration prior to t=0 using
a timestep computed as dt=0.1*forward_skip. Default = None)doc";

static const char *__doc_bbp_sonata_SimulationConfig_Run_tstop = R"doc(Biological simulation end time in milliseconds)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";

static const char *__doc_bbp_sonata_SimulationConfig_Run_spikeThreshold = R"doc(The spike detection threshold. Default is -30mV)doc";
static const char *__doc_bbp_sonata_SimulationConfig_Run_randomSeed = R"doc(Random seed)doc";

static const char *__doc_bbp_sonata_SimulationConfig_Run_spikeLocation = R"doc(The spike detection location. Can be either ‘soma’ or 'AIS'. Default is 'soma')doc";
static const char *__doc_bbp_sonata_SimulationConfig_Run_spikeLocation =
R"doc(The spike detection location. Can be either ‘soma’ or 'AIS'. Default
is 'soma')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";
static const char *__doc_bbp_sonata_SimulationConfig_Run_spikeThreshold = R"doc(The spike detection threshold. Default is -30mV)doc";

static const char *__doc_bbp_sonata_SimulationConfig_Run_forwardSkip = R"doc(Run without Stimulus or Reports for given duration prior to t=0 using a timestep computed as dt=0.1*forward_skip. Default = None)doc";
static const char *__doc_bbp_sonata_SimulationConfig_Run_tstop = R"doc(Biological simulation end time in milliseconds)doc";

static const char *__doc_bbp_sonata_SimulationConfig_SimulationConfig =
R"doc(Parses a SONATA JSON simulation configuration file.
Expand All @@ -910,6 +939,8 @@ static const char *__doc_bbp_sonata_SimulationConfig_conditions = R"doc()doc";

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

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

static const char *__doc_bbp_sonata_SimulationConfig_fromFile =
R"doc(Loads a SONATA JSON simulation config file from disk and returns a
CircuitConfig object which parses it.
Expand All @@ -930,6 +961,10 @@ R"doc(Returns the given connection parameters
SonataError if the given connection name does not correspond with
any existing connection.)doc";

static const char *__doc_bbp_sonata_SimulationConfig_getExpandedJSON =
R"doc(Returns the configuration file JSON whose variables have been expanded
by the manifest entries.)doc";

static const char *__doc_bbp_sonata_SimulationConfig_getInput =
R"doc(Returns the given input parameters.
Expand Down Expand Up @@ -967,8 +1002,6 @@ R"doc(Returns the name of simulator, default = NEURON

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

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

static const char *__doc_bbp_sonata_SimulationConfig_listConnectionOverrideNames = R"doc(Returns the names of the connection_overrides)doc";

static const char *__doc_bbp_sonata_SimulationConfig_listInputNames = R"doc(Returns the names of the reports)doc";
Expand Down
4 changes: 4 additions & 0 deletions python/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ def test_basic(self):
self.assertEqual(self.config.conditions.extracellular_calcium, None)
self.assertEqual(self.config.conditions.minis_single_vesicle, False)
self.assertEqual(self.config.conditions.randomize_gaba_rise_time, False)
self.assertEqual(self.config.conditions.mechanisms, {'ProbAMPANMDA_EMS': {'property2': -1,
'property1': False},
'GluSynapse': {'property4': 'test',
'property3': 0.025}})

self.assertEqual(self.config.list_report_names,
{ "axonal_comp_centers", "cell_imembrane", "compartment", "soma" })
Expand Down
36 changes: 35 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,40 @@ SimulationConfig::Input parseInputModule(const nlohmann::json& valueIt,
}
}

void parseConditionsMechanisms(
const nlohmann::json& it,
std::unordered_map<std::string, std::unordered_map<std::string, variantValueType>>& buf) {
const auto mechIt = it.find("mechanisms");
if (mechIt == it.end()) {
return;
}
for (auto& scopeIt : mechIt->items()) {
std::unordered_map<std::string, variantValueType> map_vars;
for (auto& varIt : scopeIt.value().items()) {
variantValueType res_val;
switch (varIt.value().type()) {
case nlohmann::json::value_t::boolean:
res_val = varIt.value().get<bool>();
break;
case nlohmann::json::value_t::string:
res_val = varIt.value().get<std::string>();
break;
case nlohmann::json::value_t::number_float:
res_val = varIt.value().get<double>();
break;
case nlohmann::json::value_t::number_integer:
case nlohmann::json::value_t::number_unsigned:
res_val = varIt.value().get<int>();
break;
default:
throw SonataError("Value type not supported");
}
map_vars.insert({varIt.key(), res_val});
}
buf.insert({scopeIt.key(), map_vars});
}
}

} // namespace

class CircuitConfig::Parser
Expand Down Expand Up @@ -845,7 +879,7 @@ class SimulationConfig::Parser
"randomize_gaba_rise_time",
result.randomizeGabaRiseTime,
{false});

parseConditionsMechanisms(*conditionsIt, result.mechanisms);
return result;
}

Expand Down
14 changes: 12 additions & 2 deletions tests/data/config/simulation_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@
"spikes_sort_order": "by_id"
},
"conditions": {
"celsius": 35.0,
"synapses_init_deleted": false
"celsius": 35.0,
"synapses_init_depleted": false,
"mechanisms": {
"ProbAMPANMDA_EMS": {
"property1": false,
"property2": -1
},
"GluSynapse" : {
"property3": 0.025,
"property4": "test"
}
}
},
"inputs": {
"ex_linear": {
Expand Down
8 changes: 8 additions & 0 deletions tests/test_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ TEST_CASE("SimulationConfig") {
CHECK(config.getConditions().extracellularCalcium == nonstd::nullopt);
CHECK(config.getConditions().minisSingleVesicle == false);
CHECK(config.getConditions().randomizeGabaRiseTime == false);
CHECK(config.getConditions().mechanisms.size() == 2);
auto itr = config.getConditions().mechanisms.find("ProbAMPANMDA_EMS");
CHECK(itr != config.getConditions().mechanisms.end());
CHECK(nonstd::get<bool>(itr->second.find("property1")->second) == false);
CHECK(nonstd::get<int>(itr->second.find("property2")->second) == -1);
itr = config.getConditions().mechanisms.find("GluSynapse");
CHECK(nonstd::get<double>(itr->second.find("property3")->second) == 0.025);
CHECK(nonstd::get<std::string>(itr->second.find("property4")->second) == "test");

CHECK_THROWS_AS(config.getReport("DoesNotExist"), SonataError);

Expand Down

0 comments on commit e0cdaf7

Please sign in to comment.