Skip to content

Commit

Permalink
closes #763. prevent redo=[...]
Browse files Browse the repository at this point in the history
  • Loading branch information
Helveg committed Nov 7, 2023
1 parent 9556b1b commit e25ef21
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
10 changes: 9 additions & 1 deletion bsb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,15 @@ def compile(
c_strats = self.get_connectivity(skip=skip, only=only)
todo_list_str = ", ".join(s.name for s in itertools.chain(p_strats, c_strats))
report(f"Compiling the following strategies: {todo_list_str}", level=2)
if (
bool(clear) is not clear
or bool(redo) is not redo
or bool(append) is not append
):
raise InputError(
"`clear`, `redo` and `append` are strictly boolean flags. "
"Pass the strategies to run to the skip/only options instead."
)
if sum((bool(clear), bool(redo), bool(append))) > 1:
raise InputError("`clear`, `redo` and `append` are mutually exclusive.")
if existed:
Expand All @@ -372,7 +381,6 @@ def compile(
t = time.time()
self.run_pipelines()
if not skip_placement:
placement_todo = ", ".join(s.name for s in p_strats)
report(f"Starting placement strategies: {placement_todo}", level=2)
self.run_placement(p_strats, pipelines=False)
if not skip_after_placement:
Expand Down
59 changes: 58 additions & 1 deletion tests/test_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
from bsb.core import Scaffold, from_storage
from bsb.config import from_json
from bsb.config import from_json, Configuration
from bsb.exceptions import InputError
from bsb.unittest import NetworkFixture, RandomStorageFixture, get_config_path


Expand Down Expand Up @@ -64,5 +65,61 @@ def test_multi_celltypes(self):
)
self.assertEqual(16, len(cs), "alltoall => 4x4 = 16")


class TestRedoCompilation(
RandomStorageFixture, NetworkFixture, unittest.TestCase, engine_name="hdf5"
):
def test_redo_issue752(self):
# `redo` was untested
self.network.compile(redo=True, only=["connection"])

def test_redo_issue763(self):
# Test that users are protected against removing data by incorrect usage of
# `append`/`redo`
cfg = Configuration.default(
**{
"name": "test",
"partitions": {
"layer": {"thickness": 50.0, "stack_index": 0},
},
"cell_types": {
"cell": {
"spatial": {
"radius": 1,
"count": 1,
},
},
},
"placement": {
"layer_placement": {
"strategy": "bsb.placement.FixedPositions",
"partitions": ["layer"],
"cell_types": ["cell"],
"positions": [[0, 0, 0]],
}
},
"connectivity": {
"cell_to_cell": {
"strategy": "bsb.connectivity.AllToAll",
"presynaptic": {"cell_types": ["cell"]},
"postsynaptic": {"cell_types": ["cell"]},
},
},
}
)

network = Scaffold(cfg)
network.compile(clear=True)
self.assertEqual(
1,
len(network.cell_types.cell.get_placement_set()),
"test setup should place 1 cell",
)
with self.assertRaises(InputError, msg="should error incorrect usage"):
network.compile(redo=["cell_to_cell"])
network.compile(redo=True, only=["cell_to_cell"])
self.assertEqual(
1,
len(network.cell_types.cell.get_placement_set()),
"redoing a conn strat should not affect the placement",
)

0 comments on commit e25ef21

Please sign in to comment.