code-loader 1.0.181.dev1__py3-none-any.whl → 1.0.181.dev3__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.
@@ -66,6 +66,19 @@ def _parse_bounds(name: str, metadata_type: DatasetMetadataType, bounds_raw: Dic
66
66
  raise ValueError(f"Parameter '{name}' has unsupported metadata type: {metadata_type}.")
67
67
 
68
68
 
69
+ def sample_sim_params(sim_config: SimConfig) -> Dict[str, Any]:
70
+ params: Dict[str, Any] = {}
71
+ for name, param_config in sim_config.items():
72
+ bounds = param_config.bounds
73
+ if isinstance(bounds, FloatBounds):
74
+ params[name] = (bounds.min + bounds.max) / 2.0
75
+ elif isinstance(bounds, IntBounds):
76
+ params[name] = int((bounds.min + bounds.max) / 2)
77
+ else: # CategoricalBounds
78
+ params[name] = bounds.values[0]
79
+ return params
80
+
81
+
69
82
  def parse_sim_config(raw: Dict[str, Any]) -> SimConfig:
70
83
  if not raw:
71
84
  raise ValueError("sim_config must have at least one parameter.")
@@ -13,7 +13,7 @@ from code_loader.contract.datasetclasses import SectionCallableInterface, InputH
13
13
  CustomMultipleReturnCallableInterfaceMultiArgs, DatasetBaseHandler, custom_latent_space_attribute, \
14
14
  RawInputsForHeatmap, VisualizerHandlerData, MetricHandlerData, CustomLossHandlerData, SamplePreprocessResponse, \
15
15
  ElementInstanceMasksHandler, InstanceCallableInterface, CustomLatentSpaceHandler, InstanceMetricHandler, \
16
- SimulationHandler
16
+ SimulationHandler, _simulation_context
17
17
  from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection, DatasetMetadataType
18
18
  from code_loader.contract.mapping import NodeConnection, NodeMapping, NodeMappingType
19
19
  from code_loader.contract.responsedataclasses import DatasetTestResultPayload, LeapAnalysisConfiguration
@@ -21,7 +21,7 @@ from code_loader.contract.visualizer_classes import map_leap_data_type_to_visual
21
21
  from code_loader.default_losses import loss_name_to_function
22
22
  from code_loader.default_metrics import metrics_names_to_functions_and_direction
23
23
  from code_loader.utils import to_numpy_return_wrapper, get_shape, to_numpy_return_masks_wrapper
24
- from code_loader.contract.sim_config import parse_sim_config
24
+ from code_loader.contract.sim_config import parse_sim_config, sample_sim_params
25
25
  from code_loader.visualizers.default_visualizers import DefaultVisualizer, \
26
26
  default_graph_visualizer, \
27
27
  default_image_visualizer, default_horizontal_bar_visualizer, default_word_visualizer, \
@@ -666,10 +666,45 @@ class LeapBinder:
666
666
  continue
667
667
  test_result = self.check_handler(preprocess_response, test_result, dataset_base_handler, state)
668
668
 
669
+ def check_simulations(self) -> None:
670
+ from code_loader.inner_leap_binder.leapbinder_decorators import _call_from_tl_platform
671
+ if not _call_from_tl_platform:
672
+ from code_loader.inner_leap_binder.leapbinder_decorators import set_current
673
+ set_current("tensorleap simulation")
674
+ for sim in self.setup_container.simulations:
675
+ kwargs = sample_sim_params(sim.sim_config)
676
+ kwargs["N"] = 1
677
+ kwargs["seed"] = 0
678
+ _simulation_context["active"] = True
679
+ try:
680
+ preprocess_response = sim.function(**kwargs)
681
+ finally:
682
+ _simulation_context["active"] = False
683
+ if not isinstance(preprocess_response, PreprocessResponse):
684
+ raise Exception(
685
+ "Simulation '{}' returned {} instead of PreprocessResponse".format(
686
+ sim.name, type(preprocess_response).__name__
687
+ )
688
+ )
689
+ preprocess_response.state = DataStateType.additional
690
+ preprocess_response.tl_generated = True
691
+ if not preprocess_response.length or preprocess_response.length < 1:
692
+ raise Exception("Simulation '{}' returned PreprocessResponse with length < 1".format(sim.name))
693
+ for handler in self.setup_container.inputs:
694
+ out1 = handler.function(0, preprocess_response)
695
+ out2 = handler.function(0, preprocess_response)
696
+ if not np.array_equal(out1, out2):
697
+ raise Exception(
698
+ "Simulation '{}': encoder '{}' is non-deterministic — consecutive calls with seed=0 returned different outputs".format(
699
+ sim.name, handler.name
700
+ )
701
+ )
702
+
669
703
  def check(self) -> None:
670
704
  preprocess_result = self.get_preprocess_result()
671
705
  self.check_preprocess(preprocess_result)
672
706
  self.check_handlers(preprocess_result)
707
+ self.check_simulations()
673
708
  self.validate_ignore_latent_spaces()
674
709
  print("Successful!")
675
710
 
@@ -1403,22 +1403,22 @@ def tensorleap_simulation(name: str, sim_params: dict):
1403
1403
  def decorating_function(user_function: Callable[..., PreprocessResponse]):
1404
1404
  sig = inspect.signature(user_function)
1405
1405
  func_params = set(sig.parameters.keys())
1406
- expected_params = set(sim_params.keys()) | {"N"}
1406
+ expected_params = set(sim_params.keys()) | {"N", "seed"}
1407
1407
 
1408
1408
  missing = expected_params - func_params
1409
1409
  if missing:
1410
1410
  raise Exception(
1411
1411
  f"{user_function.__name__}() registration failed: "
1412
1412
  f"Missing required parameters: {missing}. "
1413
- f"Function must accept all sim_params params plus 'N'."
1413
+ f"Function must accept all sim_params params plus 'N' and 'seed'."
1414
1414
  )
1415
1415
 
1416
- extra = func_params - expected_params - {"seed"}
1416
+ extra = func_params - expected_params
1417
1417
  if extra:
1418
1418
  raise Exception(
1419
1419
  f"{user_function.__name__}() registration failed: "
1420
1420
  f"Unexpected parameters: {extra}. "
1421
- f"Function must only accept sim_params params plus 'N' and optionally 'seed'."
1421
+ f"Function must only accept sim_params params plus 'N' and 'seed'."
1422
1422
  )
1423
1423
 
1424
1424
  leap_binder.set_simulation(user_function, name, sim_params)
@@ -2175,6 +2175,8 @@ def tensorleap_status_table():
2175
2175
  row = _find_row("tensorleap simulation")
2176
2176
  if not row:
2177
2177
  return
2178
+ if row["Added to integration"] == CROSS:
2179
+ return
2178
2180
  failed = [n for n, s in _sim_tracking.items() if s == "failed"]
2179
2181
  not_called = [n for n, s in _sim_tracking.items() if s == "registered"]
2180
2182
  if failed:
code_loader/leaploader.py CHANGED
@@ -23,7 +23,7 @@ from code_loader.contract.responsedataclasses import DatasetIntegParseResult, Da
23
23
  DatasetPreprocess, DatasetSetup, DatasetInputInstance, DatasetOutputInstance, DatasetMetadataInstance, \
24
24
  VisualizerInstance, PredictionTypeInstance, ModelSetup, CustomLayerInstance, MetricInstance, CustomLossInstance, \
25
25
  EngineFileContract, SimulationInstance
26
- from code_loader.contract.sim_config import FloatBounds, IntBounds, CategoricalBounds
26
+ from code_loader.contract.sim_config import FloatBounds, IntBounds, CategoricalBounds, sample_sim_params
27
27
  from code_loader.inner_leap_binder import global_leap_binder
28
28
  from code_loader.inner_leap_binder.leapbinder import mapping_runtime_mode_env_var_mame
29
29
  from code_loader.leaploaderbase import LeapLoaderBase
@@ -38,19 +38,6 @@ def _serialize_sim_bounds(bounds) -> dict:
38
38
  raise ValueError(f"Unknown bounds type: {type(bounds)}")
39
39
 
40
40
 
41
- def _sample_sim_params(sim_config):
42
- # type: (Dict[str, Any]) -> Dict[str, Any]
43
- params = {}
44
- for name, param_config in sim_config.items():
45
- bounds = param_config.bounds
46
- if isinstance(bounds, FloatBounds):
47
- params[name] = (bounds.min + bounds.max) / 2.0
48
- elif isinstance(bounds, IntBounds):
49
- params[name] = int((bounds.min + bounds.max) / 2)
50
- else: # CategoricalBounds
51
- params[name] = bounds.values[0]
52
- return params
53
-
54
41
 
55
42
  class LeapLoader(LeapLoaderBase):
56
43
  def __init__(self, code_path: str, code_entry_name: str):
@@ -321,22 +308,31 @@ class LeapLoader(LeapLoaderBase):
321
308
  for sim in global_leap_binder.setup_container.simulations:
322
309
  test_result = DatasetTestResultPayload(sim.name)
323
310
  try:
324
- kwargs = _sample_sim_params(sim.sim_config)
311
+ kwargs = sample_sim_params(sim.sim_config)
325
312
  kwargs["N"] = 1
326
- if "seed" in inspect.signature(sim.function).parameters:
327
- kwargs["seed"] = 0
313
+ kwargs["seed"] = 0
328
314
  _simulation_context["active"] = True
329
315
  try:
330
316
  preprocess_response = sim.function(**kwargs)
331
317
  finally:
332
318
  _simulation_context["active"] = False
333
- preprocess_response.state = DataStateType.additional
334
319
  if not isinstance(preprocess_response, PreprocessResponse):
335
320
  raise TypeError(
336
321
  "Expected PreprocessResponse, got {}".format(type(preprocess_response).__name__)
337
322
  )
323
+ preprocess_response.state = DataStateType.additional
324
+ preprocess_response.tl_generated = True
338
325
  if preprocess_response.length < 1:
339
326
  raise ValueError("Simulation returned PreprocessResponse with length < 1")
327
+ for handler in global_leap_binder.setup_container.inputs:
328
+ out1 = handler.function(0, preprocess_response)
329
+ out2 = handler.function(0, preprocess_response)
330
+ if not np.array_equal(out1, out2):
331
+ raise ValueError(
332
+ "Encoder '{}' is non-deterministic: consecutive calls with seed=0 returned different outputs".format(
333
+ handler.name
334
+ )
335
+ )
340
336
  except Exception as e:
341
337
  line_number, file_name, stacktrace = get_root_exception_file_and_line_number()
342
338
  test_result.display[TestingSectionEnum.Errors.name] = (
@@ -357,10 +353,9 @@ class LeapLoader(LeapLoaderBase):
357
353
  )
358
354
  if sim is None:
359
355
  raise ValueError("No simulation registered with name '{}'".format(sim_name))
360
- kwargs = _sample_sim_params(sim.sim_config)
356
+ kwargs = sample_sim_params(sim.sim_config)
361
357
  kwargs["N"] = 1
362
- if "seed" in inspect.signature(sim.function).parameters:
363
- kwargs["seed"] = 0
358
+ kwargs["seed"] = 0
364
359
  _simulation_context["active"] = True
365
360
  try:
366
361
  sim_preprocess = sim.function(**kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.181.dev1
3
+ Version: 1.0.181.dev3
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -6,7 +6,7 @@ code_loader/contract/enums.py,sha256=2q-IV_5g9lLE306DIbWA1c0tn5IhDtxsKxyV1x_Lreg
6
6
  code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
7
7
  code_loader/contract/mapping.py,sha256=sWJhpng-IkOzQnWQdMT5w2ZZ3X1Z_OOzSwCLXIS7oxE,1446
8
8
  code_loader/contract/responsedataclasses.py,sha256=5VFgGjRubMW8ItMPils3rkBNejunCGLaa192AIi-xko,4925
9
- code_loader/contract/sim_config.py,sha256=tWgM3n2_UTP8HnWBUFYLY928ya1ezFWhMOOU9c3WsHU,3002
9
+ code_loader/contract/sim_config.py,sha256=le8KMALZiP0WU4UcuKnTOSWBW2rNjpnWYfII502NqDM,3493
10
10
  code_loader/contract/visualizer_classes.py,sha256=Wz9eItmoRaKEHa3p0aW0Ypxx4_xUmaZyLBznnTuxwi0,15425
11
11
  code_loader/default_losses.py,sha256=NoOQym1106bDN5dcIk56Elr7ZG5quUHArqfP5-Nyxyo,1139
12
12
  code_loader/default_metrics.py,sha256=2XSlyNw_XLDGSJDoz5W_Evi5wbL0dhwq24pPr15vSPc,5025
@@ -21,9 +21,9 @@ code_loader/experiment_api/types.py,sha256=MY8xFARHwdVA7p4dxyhD60ShmttgTvb4qdp1o
21
21
  code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZJEqBqc,3304
22
22
  code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
23
23
  code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
24
- code_loader/inner_leap_binder/leapbinder.py,sha256=Avt4lQv4mehoEOlH7UyF7Wna_GGJWSAF6r55qUk1MYE,38497
25
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=dUZZf_SgcS9BJ2-ZEMOQWPucKHzlyl7CI1W699KtjsE,105735
26
- code_loader/leaploader.py,sha256=KNXcT07A2FkeaxsRknKrZIhmcE-IkKRuwBJ-Frh9jk0,36342
24
+ code_loader/inner_leap_binder/leapbinder.py,sha256=xu0K72zS4b3Nkc7OqcYV0CJ-LNgkZ979RyDL0EVSuqM,40381
25
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=94D0fcUlrYV9h-Q4E16d8Cac6uFleNV3If3AKlKOWuE,105800
26
+ code_loader/leaploader.py,sha256=-uN0T8x563uTJfq51f3osory8aON6MMBf1tpdT1Ox5I,36314
27
27
  code_loader/leaploaderbase.py,sha256=0JMwslRs6w7psIkj4pTjYHd_pSio3vt5H-X0Lar2nBI,6428
28
28
  code_loader/mixpanel_tracker.py,sha256=rNwRmFifNbdUoqLQvvhhgpKczWpWiEmd8MfyJe27sxw,9131
29
29
  code_loader/plot_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -32,7 +32,7 @@ code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6Lz
32
32
  code_loader/utils.py,sha256=YecipkdTA-VcE9F0RQcY9cFnY8P3AksPnHM2Db7xUSk,3972
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.181.dev1.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
- code_loader-1.0.181.dev1.dist-info/METADATA,sha256=UnNBbbp7L7zC7NxpR3VdVmHiRBXr2LyJlSC5q_PTRRo,1095
37
- code_loader-1.0.181.dev1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- code_loader-1.0.181.dev1.dist-info/RECORD,,
35
+ code_loader-1.0.181.dev3.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
+ code_loader-1.0.181.dev3.dist-info/METADATA,sha256=c-fjPMP1vvj24a7thpF3vs_248IScUU31Rk073QU7xQ,1095
37
+ code_loader-1.0.181.dev3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
+ code_loader-1.0.181.dev3.dist-info/RECORD,,