Skip to content

Commit

Permalink
SimulationConfig: node_sets_file default is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
WeinaJi committed Sep 19, 2023
1 parent c04ed23 commit 8ffb36d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
3 changes: 1 addition & 2 deletions include/bbp/sonata/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,7 @@ class SONATA_API SimulationConfig
const SimulationConfig::SimulatorType& getTargetSimulator() const;

/**
* Returns the path of node sets file overriding node_sets_file provided in _network,
* default is empty in case of no setting in _network
* Returns the path of node sets file, default is empty
*/
const std::string& getNodeSetsFile() const noexcept;

Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def test_basic(self):
os.path.abspath(os.path.join(PATH, 'config/circuit_config.json')))
self.assertEqual(self.config.target_simulator.name, 'CORENEURON');
circuit_conf = CircuitConfig.from_file(self.config.network);
self.assertEqual(self.config.node_sets_file, circuit_conf.node_sets_path);
self.assertEqual(self.config.node_sets_file, '');
self.assertEqual(self.config.node_set, 'Column');

self.assertEqual(self.config.list_input_names,
Expand Down
15 changes: 3 additions & 12 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,20 +1090,11 @@ class SimulationConfig::Parser
}

std::string parseNodeSetsFile() const noexcept {
std::string val;
if (_json.contains("node_sets_file")) {
val = _json["node_sets_file"];
return toAbsolute(_basePath, val);
} else {
try {
const auto circuitFile = parseNetwork();
const auto conf = CircuitConfig::fromFile(circuitFile);
return conf.getNodeSetsPath();
} catch (...) {
// Don't throw CircuitConfig exceptions in SimulationConfig and return empty string
return val;
}
return toAbsolute(_basePath, _json["node_sets_file"]);
}

return {};
}

nonstd::optional<std::string> parseNodeSet() const {
Expand Down
7 changes: 4 additions & 3 deletions tests/test_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ TEST_CASE("SimulationConfig") {
const auto network = fs::absolute(basePath / fs::path("circuit_config.json"));
CHECK(config.getNetwork() == network.lexically_normal());
CHECK(config.getTargetSimulator() == SimulationConfig::SimulatorType::CORENEURON);
const auto circuit_conf = CircuitConfig::fromFile(config.getNetwork());
CHECK(config.getNodeSetsFile() == circuit_conf.getNodeSetsPath());
CHECK(config.getNodeSetsFile() == "");
CHECK(config.getNodeSet() == "Column");

using InputType = SimulationConfig::InputBase::InputType;
Expand Down Expand Up @@ -619,6 +618,7 @@ TEST_CASE("SimulationConfig") {
"$CIRCUIT_DIR": "./circuit"
},
"network": "$CIRCUIT_DIR/circuit_config.json",
"node_sets_file": "user_nodesets_file.json",
"run": {
"random_seed": 12345,
"dt": 0.05,
Expand All @@ -631,7 +631,8 @@ TEST_CASE("SimulationConfig") {
const auto network = fs::absolute(basePath / "circuit" / fs::path("circuit_config.json"));
CHECK(config.getNetwork() == network.lexically_normal());
CHECK(config.getTargetSimulator() == SimulationConfig::SimulatorType::NEURON); // default
CHECK(config.getNodeSetsFile() == ""); // network file is not readable so default empty
CHECK(config.getNodeSetsFile() ==
fs::absolute(basePath / fs::path("user_nodesets_file.json")).lexically_normal());
CHECK(config.getNodeSet() == nonstd::nullopt); // default
CHECK(config.getRun().stimulusSeed == 0);
CHECK(config.getRun().ionchannelSeed == 0);
Expand Down

0 comments on commit 8ffb36d

Please sign in to comment.