Skip to content

Commit

Permalink
fix: group chunks for placement from different partitions to avoid du…
Browse files Browse the repository at this point in the history
…plicates (#880)
  • Loading branch information
drodarie authored Sep 2, 2024
1 parent 209185b commit 903434b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
9 changes: 5 additions & 4 deletions bsb/placement/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ def queue(self, pool, chunk_size):
*(pool.get_submissions_of(strat) for strat in self.get_deps())
)
)
for p in self.partitions:
chunks = p.to_chunks(chunk_size)
for chunk in chunks:
job = pool.queue_placement(self, Chunk(chunk, chunk_size), deps=deps)
chunks = np.unique(
np.concatenate([p.to_chunks(chunk_size) for p in self.partitions]), axis=0
)
for chunk in chunks:
job = pool.queue_placement(self, Chunk(chunk, chunk_size), deps=deps)

def is_entities(self):
return "entities" in self.__class__.__dict__ and self.__class__.entities
Expand Down
18 changes: 16 additions & 2 deletions tests/test_placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,28 @@ class TestPlacementStrategies(
def test_random_placement(self):
cfg = get_test_config("single")
network = Scaffold(cfg, self.storage)
network.compile(clear=True)
ps = network.get_placement_set("test_cell")
self.assertEqual(40, len(ps), "fixed count random placement broken")

def test_regression_issue_879(self):
"""
If different partitions share chunks, these chunks should be dealt
only once by the placement strategy.
"""
cfg = get_test_config("single")
cfg.partitions.add("test_layer2", {"thickness": 50.0})
cfg.placement["test_placement"] = dict(
strategy="bsb.placement.RandomPlacement",
cell_types=["test_cell"],
partitions=["test_layer"],
partitions=["test_layer", "test_layer2"],
)
network = Scaffold(cfg, self.storage)
network.compile(clear=True)
ps = network.get_placement_set("test_cell")
self.assertEqual(40, len(ps), "fixed count random placement broken")
self.assertEqual(
40, len(ps), "multi partitions fixed count random placement broken"
)

def test_fixed_pos(self):
cfg = Configuration.default(
Expand Down

0 comments on commit 903434b

Please sign in to comment.