Skip to content

Commit

Permalink
Write gids without offset in complexity file for load balancing: Whol…
Browse files Browse the repository at this point in the history
…eCell
  • Loading branch information
jorblancoa committed Apr 4, 2024
1 parent 25f54c6 commit 510e46e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions neurodamus/cell_distributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_cellref(self, gid):
"""
if self._binfo:
# are we in load balance mode? must replace gid with spgid
gid = self._binfo.thishost_gid(gid)
gid = self._binfo.thishost_gid(gid - self._local_nodes.offset)
return self._pc.gid2obj(gid)

# Methods for compat with hoc
Expand Down Expand Up @@ -242,7 +242,7 @@ def _load_nodes_balance(self, loader_f, load_balancer):
self._binfo = load_balancer.load_balance_info(target_spec)
# self._binfo has gidlist, but gids can appear multiple times
all_gids = numpy.unique(
self._binfo.gids.as_numpy().astype("uint32") - self._local_nodes.offset
self._binfo.gids.as_numpy().astype("uint32")
)
total_cells = len(all_gids)
gidvec, me_infos, full_size = loader_f(self._circuit_conf, all_gids)
Expand Down Expand Up @@ -355,19 +355,21 @@ def _init_cell_network(self):
self._init_rng()
pc = self._pc

for final_gid, cell in self._gid2cell.items():
for gid, cell in self._gid2cell.items():
cell.re_init_rng(self._ionchannel_seed)
nc = cell.connect2target(None) # Netcon doesnt require being stored
raw_gid = gid - self._local_nodes.offset

if self._binfo:
gid_i = int(self._binfo.gids.indwhere("==", final_gid))
gid_i = int(self._binfo.gids.indwhere("==", raw_gid))
cb = self._binfo.bilist.object(self._binfo.cbindex.x[gid_i])
# multisplit cells call cb.multisplit() instead
if cb.subtrees.count() > 0:
cb.multisplit(nc, self._binfo.msgid, pc, pc.id())
cell.gid = final_gid
cell.gid = raw_gid
continue

final_gid = raw_gid if self._binfo else gid
pc.set_gid2node(final_gid, pc.id())
pc.cell(final_gid, nc)
cell.gid = final_gid # update the cell.gid last (RNGs had to use the base gid)
Expand Down Expand Up @@ -488,7 +490,7 @@ def get_cellref(self, gid):
manager = self._find_manager(gid)
if manager._binfo:
# are we in load balance mode? must replace gid with spgid
gid = manager._binfo.thishost_gid(gid)
gid = manager._binfo.thishost_gid(gid - manager.local_nodes.offset)
return self._pc.gid2obj(gid)

def getSpGid(self, gid):
Expand All @@ -502,7 +504,7 @@ def getSpGid(self, gid):
"""
manager = self._find_manager(gid)
if manager._binfo:
return manager._binfo.thishost_gid(gid)
return manager._binfo.thishost_gid(gid - manager.local_nodes.offset)
return gid

def getPopulationInfo(self, gid):
Expand Down Expand Up @@ -670,7 +672,7 @@ def _reuse_cell_complexity(self, target_spec: TargetSpec) -> bool:
return False

logging.info("Attempt reusing cx files from other targets...")
target_gids = self._get_target_gids(target_spec)
target_gids = self._get_target_raw_gids(target_spec)
cx_other = {}

for previous_target in self._cx_targets:
Expand Down Expand Up @@ -712,7 +714,7 @@ def _cx_valid(self, target_spec) -> bool:
return False

if target_spec: # target provided, otherwise everything
target_gids = self._get_target_gids(target_spec)
target_gids = self._get_target_raw_gids(target_spec)
if not self._cx_contains_gids(cx_filename, target_gids):
logging.warning(" => %s invalid: changed target definition!", cx_filename)
return False
Expand Down Expand Up @@ -889,8 +891,8 @@ def _write_msdat_dict(fp, cx_dict, gids=None):
fp.write(line) # raw lines, include \n

# -
def _get_target_gids(self, target_spec) -> numpy.ndarray:
return self._target_manager.get_target(target_spec).get_gids()
def _get_target_raw_gids(self, target_spec) -> numpy.ndarray:
return self._target_manager.get_target(target_spec).get_raw_gids()

def load_balance_info(self, target_spec):
""" Loads a load-balance info for a given target.
Expand Down

0 comments on commit 510e46e

Please sign in to comment.