Skip to content

Commit

Permalink
fix unnecessary warning when simulation uses same node sets file as c…
Browse files Browse the repository at this point in the history
…ircuit (#237)
  • Loading branch information
joni-herttuainen authored Oct 17, 2023
1 parent 0cc9bf4 commit 95fa737
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
10 changes: 6 additions & 4 deletions bluepysnap/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ def simulator(self):
def node_sets(self):
"""Returns the NodeSets object bound to the simulation."""
try:
node_sets = NodeSets.from_file(self.circuit.to_libsonata.node_sets_path)
path = self.circuit.to_libsonata.node_sets_path
except BluepySnapError: # Error raised if circuit can not be instantiated
node_sets = NodeSets.from_dict({})
path = ""

if path := self.to_libsonata.node_sets_file:
overwritten = node_sets.update(NodeSets.from_file(path))
node_sets = NodeSets.from_file(path) if path else NodeSets.from_dict({})

if self.to_libsonata.node_sets_file != path:
overwritten = node_sets.update(NodeSets.from_file(self.to_libsonata.node_sets_file))
_warn_on_overwritten_node_sets(overwritten)

return node_sets
Expand Down
26 changes: 24 additions & 2 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@


def test__warn_on_overwritten_node_sets():
test_module._warn_on_overwritten_node_sets

# No warnings if no overwritten
with warnings.catch_warnings():
warnings.simplefilter("error")
Expand Down Expand Up @@ -83,6 +81,30 @@ def test_all():
assert isinstance(rep["default"], PopulationCompartmentReport)


def test_no_warning_when_shared_node_sets_path():
with copy_test_data(config="simulation_config.json") as (_, config_path):
circuit = test_module.Simulation(config_path).circuit
circuit_node_sets_path = circuit.to_libsonata.node_sets_path

# set simulation node set path = circuit node set path
with edit_config(config_path) as config:
config["node_sets_file"] = circuit_node_sets_path

# Should not raise
with warnings.catch_warnings():
warnings.simplefilter("error")
test_module.Simulation(config_path).node_sets

# if node_sets_file is not defined, libsonata should use the same path as the circuit
with edit_config(config_path) as config:
config.pop("node_sets_file")

# Should not raise either
with warnings.catch_warnings():
warnings.simplefilter("error")
test_module.Simulation(config_path).node_sets


def test_unknown_report():
with copy_test_data(config="simulation_config.json") as (_, config_path):
with edit_config(config_path) as config:
Expand Down

0 comments on commit 95fa737

Please sign in to comment.