code-loader 1.0.193.dev5__py3-none-any.whl → 1.0.195__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
code_loader/leaploader.py CHANGED
@@ -568,8 +568,8 @@ class LeapLoader(LeapLoaderBase):
568
568
  return handler.input_shapes
569
569
 
570
570
  def run_simulation(self, sim_name, params=None, n_samples=1, seed=0,
571
- sample_ids=None, extend_preprocess=True):
572
- # type: (str, Optional[Dict[str, Any]], int, int, Optional[List[str]], bool) -> Dict[str, Any]
571
+ sample_ids=None, extend_preprocess=True, allow_partial=False):
572
+ # type: (str, Optional[Dict[str, Any]], int, int, Optional[List[str]], bool, bool) -> Dict[str, Any]
573
573
  # extend_preprocess=True (default): also extend preprocess_result[additional] with the
574
574
  # new synthetic sample_ids (producer-side behavior — synthetic worker needs this for
575
575
  # enumeration / data_length tracking). Pass False from consumer-side populators that
@@ -596,19 +596,30 @@ class LeapLoader(LeapLoaderBase):
596
596
  for sample_id in original_sample_ids:
597
597
  for handler in global_leap_binder.setup_container.inputs:
598
598
  per_encoder[handler.name].append(handler.function(sample_id, sim_preprocess))
599
- encoded = {name: np.stack(arrays) for name, arrays in per_encoder.items()}
599
+ encoded = {
600
+ name: np.stack(arrays) if arrays else np.empty((0,), dtype=np.float32)
601
+ for name, arrays in per_encoder.items()
602
+ }
600
603
  if sample_ids is not None:
601
- if len(sample_ids) != len(original_sample_ids):
602
- raise ValueError(
603
- "sample_ids length ({}) does not match simulation output length ({})".format(
604
- len(sample_ids), len(original_sample_ids)
605
- )
606
- )
607
604
  for sid in sample_ids:
608
605
  if not isinstance(sid, str):
609
606
  raise TypeError(
610
607
  "All sample_ids must be of type str. Got: {}".format(type(sid))
611
608
  )
609
+ if len(sample_ids) != len(original_sample_ids):
610
+ if not allow_partial:
611
+ raise ValueError(
612
+ "sample_ids length ({}) does not match simulation output length ({})".format(
613
+ len(sample_ids), len(original_sample_ids)
614
+ )
615
+ )
616
+ n_bound = min(len(sample_ids), len(original_sample_ids))
617
+ sample_ids = list(sample_ids)[:n_bound]
618
+ original_sample_ids = original_sample_ids[:n_bound]
619
+ # Over-generation trims sample_ids/original_sample_ids above but encoded was
620
+ # stacked from the full simulation output; slice it too so the encoded batch dim
621
+ # stays 1:1 with the returned sample_ids.
622
+ encoded = {name: arr[:n_bound] for name, arr in encoded.items()}
612
623
  for synth_id, original_local_id in zip(sample_ids, original_sample_ids):
613
624
  self._synthetic_lookup[synth_id] = (sim_preprocess, original_local_id)
614
625
  if extend_preprocess:
@@ -618,6 +629,19 @@ class LeapLoader(LeapLoaderBase):
618
629
  returned_sample_ids = original_sample_ids
619
630
  return {"encoded": encoded, "sample_ids": returned_sample_ids}
620
631
 
632
+ def prune_synthetic_lookup(self, keep_ids):
633
+ # type: (List[str]) -> None
634
+ # Keep only the given synthetic sample_ids in the in-memory lookup and
635
+ # drop the rest, so preprocess responses don't accumulate across many
636
+ # run_simulation calls (e.g. a synthetic calibration loop keeps only its
637
+ # running top-K trials). Keep-set semantics (rather than evict-list) so
638
+ # the caller can bound the lookup to a known-good set each iteration
639
+ # without tracking everything it ever generated.
640
+ keep = set(keep_ids)
641
+ self._synthetic_lookup = {
642
+ sid: entry for sid, entry in self._synthetic_lookup.items() if sid in keep
643
+ }
644
+
621
645
  def _extend_additional_preprocess(self, new_sample_ids: List[str]) -> None:
622
646
  if self._preprocess_result_cached is None:
623
647
  self._preprocess_result()
@@ -159,8 +159,13 @@ class LeapLoaderBase:
159
159
  pass
160
160
 
161
161
  @abstractmethod
162
- def run_simulation(self, sim_name, params=None, n_samples=1, seed=0, sample_ids=None):
163
- # type: (str, Optional[Dict[str, Any]], int, int, Optional[List[str]]) -> Dict[str, Any]
162
+ def run_simulation(self, sim_name, params=None, n_samples=1, seed=0, sample_ids=None,
163
+ extend_preprocess=True, allow_partial=False):
164
+ # type: (str, Optional[Dict[str, Any]], int, int, Optional[List[str]], bool, bool) -> Dict[str, Any]
165
+ pass
166
+
167
+ def prune_synthetic_lookup(self, keep_ids):
168
+ # type: (List[str]) -> None
164
169
  pass
165
170
 
166
171
  def is_custom_latent_space(self) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.193.dev5
3
+ Version: 1.0.195
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -23,8 +23,8 @@ code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaS
23
23
  code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
24
24
  code_loader/inner_leap_binder/leapbinder.py,sha256=D-ahDW-1ZiB9wqPkiIMz8eOD6p_Z3spm5b_Mi8y0af0,48340
25
25
  code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=7hUDsG2YrRh_HgLmVidTvwi8xr4eH70r2MWmSWfY6aY,143870
26
- code_loader/leaploader.py,sha256=Q2f_NE81tjdY97DlxiMEiXDQ3rY1PgqVLKb_Liuk5g0,69634
27
- code_loader/leaploaderbase.py,sha256=2UPunTcEZRs99cbFXkNDWdFrs5nQ7EG_T2qwZBepEXY,6788
26
+ code_loader/leaploader.py,sha256=kYD2jousMGb0wEG9HdhzFYjRAekVYXMfZxX1S28tdns,71025
27
+ code_loader/leaploaderbase.py,sha256=f6LsJeCAktTFU9U_c3NXddwOZjjchLtvbxl4eKMdwGc,6966
28
28
  code_loader/mixpanel_tracker.py,sha256=rNwRmFifNbdUoqLQvvhhgpKczWpWiEmd8MfyJe27sxw,9131
29
29
  code_loader/plot_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  code_loader/plot_functions/plot_functions.py,sha256=2DC-zlVaN13P4VNx5d8csgs80C6SisaeP1-Kq2LW7iM,16075
@@ -32,7 +32,7 @@ code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6Lz
32
32
  code_loader/utils.py,sha256=SPDQ4_f67hOIOgTfaTGlwBfbnusPrzH1OBYDLEndyr8,4413
33
33
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  code_loader/visualizers/default_visualizers.py,sha256=onRnLE_TXfgLN4o52hQIOOhUcFexGlqJ3xSpQDVLuZM,2604
35
- code_loader-1.0.193.dev5.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
- code_loader-1.0.193.dev5.dist-info/METADATA,sha256=E1TUgiZTHN72FSPmsNeAW0oEMaq6kejhO4mIUO_YOmU,1095
37
- code_loader-1.0.193.dev5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- code_loader-1.0.193.dev5.dist-info/RECORD,,
35
+ code_loader-1.0.195.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
+ code_loader-1.0.195.dist-info/METADATA,sha256=O8O5OzK_eoALrJ7NsN8PALLoW8fyZQ5lK7SUnf5Vgw4,1090
37
+ code_loader-1.0.195.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
+ code_loader-1.0.195.dist-info/RECORD,,