Andrej Janchevski commited on
Commit
b609540
·
1 Parent(s): cd5136e

fix(coins): rebuild machines array when cached .npz has wrong length

Browse files

Stale machines_*.npz files on disk can have a different length than the
current Leiden partition's num_communities, causing an IndexError during
COINs experiment preparation. Rebuild machines = zeros(num_communities+2)
in both _load_all_loaders and the cached-loader path in
_load_coins_experiment to match the website's single-device setup.

src/backend/api/services/registry.py CHANGED
@@ -467,6 +467,17 @@ class ModelRegistry:
467
  seed=seed, device="cpu", val_size=0.01, test_size=0.02,
468
  community_method="leiden", leiden_resolution=leiden_resolution,
469
  )
 
 
 
 
 
 
 
 
 
 
 
470
  self.loaders[dataset_id] = loader
471
  # Share this loader with _load_coins_experiment so experiments for the
472
  # same (dataset, seed, leiden_resolution) reuse it instead of reloading
@@ -704,6 +715,13 @@ class ModelRegistry:
704
  loader_key = (dataset_id, seed, leiden_resolution)
705
  if loader_key in self._coins_loaders:
706
  cached_loader = self._coins_loaders[loader_key]
 
 
 
 
 
 
 
707
  experiment.loader = cached_loader
708
  # Temporarily replace load_graph with a no-op: prepare() will find all
709
  # required attributes (num_nodes, communities, graph_indexes, …) already set.
 
467
  seed=seed, device="cpu", val_size=0.01, test_size=0.02,
468
  community_method="leiden", leiden_resolution=leiden_resolution,
469
  )
470
+ # Rebuild machines from the current num_communities: cached machines_*.npz
471
+ # files on disk can be stale relative to the current subgraphing output
472
+ # (different num_communities), and the website always runs num_machines=1.
473
+ import numpy as np
474
+ expected_len = loader.num_communities + 2
475
+ if len(loader.machines) != expected_len:
476
+ logger.warning(
477
+ "Stale machines.npz for %s: len=%d but num_communities+2=%d; rebuilding",
478
+ dataset_id, len(loader.machines), expected_len,
479
+ )
480
+ loader.machines = np.zeros(expected_len, dtype=int)
481
  self.loaders[dataset_id] = loader
482
  # Share this loader with _load_coins_experiment so experiments for the
483
  # same (dataset, seed, leiden_resolution) reuse it instead of reloading
 
715
  loader_key = (dataset_id, seed, leiden_resolution)
716
  if loader_key in self._coins_loaders:
717
  cached_loader = self._coins_loaders[loader_key]
718
+ # Defensive: ensure machines length matches current num_communities.
719
+ # _load_all_loaders already does this, but any future code path that
720
+ # populates _coins_loaders directly could skip it.
721
+ import numpy as np
722
+ expected_len = cached_loader.num_communities + 2
723
+ if len(cached_loader.machines) != expected_len:
724
+ cached_loader.machines = np.zeros(expected_len, dtype=int)
725
  experiment.loader = cached_loader
726
  # Temporarily replace load_graph with a no-op: prepare() will find all
727
  # required attributes (num_nodes, communities, graph_indexes, …) already set.