code-loader 1.0.180.dev3__py3-none-any.whl → 1.0.180.dev5__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.
@@ -13,6 +13,8 @@ from code_loader.contract.sim_config import SimConfig
13
13
 
14
14
  custom_latent_space_attribute = "custom_latent_space"
15
15
 
16
+ _simulation_context: dict = {"active": False}
17
+
16
18
 
17
19
  @dataclass
18
20
  class PreprocessResponse:
@@ -62,14 +64,14 @@ class PreprocessResponse:
62
64
  raise Exception("length is deprecated, please use sample_ids instead.")
63
65
 
64
66
  if self.state is None:
65
- from code_loader.inner_leap_binder.leapbinder_decorators import store_warning_by_param
66
- store_warning_by_param(
67
- param_name="PreprocessResponse.state",
68
- user_func_name="tensorleap_preprocess",
69
- default_value=str("specific order"),
70
- link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/preprocess-function",
71
- )
72
-
67
+ if not _simulation_context["active"]:
68
+ from code_loader.inner_leap_binder.leapbinder_decorators import store_warning_by_param
69
+ store_warning_by_param(
70
+ param_name="PreprocessResponse.state",
71
+ user_func_name="tensorleap_preprocess",
72
+ default_value=str("specific order"),
73
+ link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/preprocess-function",
74
+ )
73
75
  else:
74
76
  assert isinstance(self.state, DataStateType), f"PreprocessResponse.state must be of type {DataStateType.__name__} but got {type(self.state)}"
75
77
 
@@ -1424,7 +1424,7 @@ def tensorleap_simulation(name: str, sim_params: dict):
1424
1424
  leap_binder.set_simulation(user_function, name, sim_params)
1425
1425
 
1426
1426
  if not _call_from_tl_platform:
1427
- add_table_row(f"tensorleap_simulation:{name} (optional)")
1427
+ register_sim(name)
1428
1428
 
1429
1429
  def _validate_input_args(*args, **kwargs):
1430
1430
  assert len(args) == 0, (
@@ -1442,29 +1442,40 @@ def tensorleap_simulation(name: str, sim_params: dict):
1442
1442
  f"{user_function.__name__}() validation failed: "
1443
1443
  f"Expected return type PreprocessResponse. Got {type(result).__name__}."
1444
1444
  )
1445
- assert result.state == DataStateType.additional, (
1446
- f"{user_function.__name__}() validation failed: "
1447
- f"Simulation must return a PreprocessResponse with state=DataStateType.additional. "
1448
- f"Got state={result.state!r}."
1449
- )
1450
1445
 
1451
1446
  def inner(*args, **kwargs):
1452
1447
  if not _call_from_tl_platform:
1453
- set_current('tensorleap_simulation')
1454
- _validate_input_args(*args, **kwargs)
1455
- result = user_function(*args, **kwargs)
1456
- _validate_result(result)
1457
- result.tl_generated = True
1458
- if not _call_from_tl_platform:
1459
- update_env_params_func(f"tensorleap_simulation:{name}", "v")
1448
+ set_current('tensorleap simulation')
1460
1449
  try:
1461
- emit_integration_event_once(AnalyticsEvent.SIMULATION_INTEGRATION_TEST, {
1462
- 'simulation_name': name,
1463
- 'sim_params_count': len(sim_params)
1464
- })
1465
- except Exception as e:
1466
- logger.debug(f"Failed to emit simulation integration test event: {e}")
1467
- return result
1450
+ from code_loader.contract.datasetclasses import _simulation_context
1451
+ _validate_input_args(*args, **kwargs)
1452
+ _simulation_context["active"] = True
1453
+ try:
1454
+ result = user_function(*args, **kwargs)
1455
+ finally:
1456
+ _simulation_context["active"] = False
1457
+ _validate_result(result)
1458
+ if result.state is not None and result.state != DataStateType.additional:
1459
+ logger.warning(
1460
+ f"{user_function.__name__}() returned state={result.state!r}; "
1461
+ f"overriding to DataStateType.additional."
1462
+ )
1463
+ result.state = DataStateType.additional
1464
+ result.tl_generated = True
1465
+ try:
1466
+ emit_integration_event_once(AnalyticsEvent.SIMULATION_INTEGRATION_TEST, {
1467
+ 'simulation_name': name,
1468
+ 'sim_params_count': len(sim_params)
1469
+ })
1470
+ except Exception as e:
1471
+ logger.debug(f"Failed to emit simulation integration test event: {e}")
1472
+ if not _call_from_tl_platform:
1473
+ mark_sim_result(name, True)
1474
+ return result
1475
+ except Exception:
1476
+ if not _call_from_tl_platform:
1477
+ mark_sim_result(name, False)
1478
+ raise
1468
1479
 
1469
1480
  return inner
1470
1481
 
@@ -2092,6 +2103,9 @@ def tensorleap_status_table():
2092
2103
  def _print_table():
2093
2104
  _print_param_default_warnings()
2094
2105
 
2106
+ for msg in _sim_messages:
2107
+ print(f"\n⚠️ {msg}")
2108
+
2095
2109
  if not started_from("leap_integration.py"):
2096
2110
  return
2097
2111
 
@@ -2144,12 +2158,41 @@ def tensorleap_status_table():
2144
2158
  else:
2145
2159
  _set_status(name, CROSS)
2146
2160
 
2161
+ _sim_tracking: dict = {}
2162
+ _sim_messages: list = []
2163
+
2164
+ def register_sim(sim_name: str):
2165
+ if not _sim_tracking:
2166
+ table.append({"name": "tensorleap simulation (optional)", "Added to integration": UNKNOWN})
2167
+ _sim_tracking[sim_name] = "registered"
2168
+
2169
+ def mark_sim_result(sim_name: str, passed: bool):
2170
+ _sim_tracking[sim_name] = "passed" if passed else "failed"
2171
+
2172
+ def _resolve_sim_row():
2173
+ if not _sim_tracking:
2174
+ return
2175
+ row = _find_row("tensorleap simulation")
2176
+ if not row:
2177
+ return
2178
+ failed = [n for n, s in _sim_tracking.items() if s == "failed"]
2179
+ not_called = [n for n, s in _sim_tracking.items() if s == "registered"]
2180
+ if failed:
2181
+ row["Added to integration"] = CROSS
2182
+ _sim_messages.append(f"Simulation(s) failed validation: {', '.join(sorted(failed))}")
2183
+ elif not_called:
2184
+ row["Added to integration"] = UNKNOWN
2185
+ _sim_messages.append(f"Simulation(s) not called in integration test: {', '.join(sorted(not_called))}")
2186
+ else:
2187
+ row["Added to integration"] = CHECK
2188
+
2147
2189
  def run_on_exit():
2148
2190
  if _finalizer_called["done"]:
2149
2191
  return
2150
2192
  _finalizer_called["done"] = True
2151
2193
  if not _crashed["value"]:
2152
2194
  _mark_unknowns_as_cross()
2195
+ _resolve_sim_row()
2153
2196
 
2154
2197
  _print_table()
2155
2198
 
@@ -2164,17 +2207,14 @@ def tensorleap_status_table():
2164
2207
  traceback.print_exception(exc_type, exc_value, exc_traceback)
2165
2208
  run_on_exit()
2166
2209
 
2167
- def add_table_row(name: str):
2168
- table.append({"name": name, "Added to integration": UNKNOWN})
2169
-
2170
2210
  atexit.register(run_on_exit)
2171
2211
  sys.excepthook = handle_exception
2172
2212
 
2173
- return set_current, update_env_params, add_table_row
2213
+ return set_current, update_env_params, register_sim, mark_sim_result
2174
2214
 
2175
2215
 
2176
2216
  if not _call_from_tl_platform:
2177
- set_current, update_env_params_func, add_table_row = tensorleap_status_table()
2217
+ set_current, update_env_params_func, register_sim, mark_sim_result = tensorleap_status_table()
2178
2218
 
2179
2219
 
2180
2220
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.180.dev3
3
+ Version: 1.0.180.dev5
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
1
  LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
2
2
  code_loader/__init__.py,sha256=outxRQ0M-zMfV0QGVJmAed5qWfRmyD0TV6-goEGAzBw,406
3
3
  code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- code_loader/contract/datasetclasses.py,sha256=KefWGK04SDGQe4KjwBCnP14LO7sO7esS5vYmevFZW_A,10321
4
+ code_loader/contract/datasetclasses.py,sha256=vph0ox6ia9ve3mCVy27ad7koyiClqYzVPCzcHzMp2I4,10445
5
5
  code_loader/contract/enums.py,sha256=2q-IV_5g9lLE306DIbWA1c0tn5IhDtxsKxyV1x_Lreg,1671
6
6
  code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
7
7
  code_loader/contract/mapping.py,sha256=sWJhpng-IkOzQnWQdMT5w2ZZ3X1Z_OOzSwCLXIS7oxE,1446
@@ -22,7 +22,7 @@ code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZ
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
24
  code_loader/inner_leap_binder/leapbinder.py,sha256=Avt4lQv4mehoEOlH7UyF7Wna_GGJWSAF6r55qUk1MYE,38497
25
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=QoWaNdHdh3XQDYXRqvnSS0S3FzKWB-6jbsE6Mq6hl0U,104111
25
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=dUZZf_SgcS9BJ2-ZEMOQWPucKHzlyl7CI1W699KtjsE,105735
26
26
  code_loader/leaploader.py,sha256=vz812i2a0-9UTqsxNx9z0lqJlLt4BWGsPwl4E4lWjZ4,33022
27
27
  code_loader/leaploaderbase.py,sha256=NJGaas8S6JeHYSsKkMSutyfcSKdK9jXTic7BcjC5uNc,6303
28
28
  code_loader/mixpanel_tracker.py,sha256=rNwRmFifNbdUoqLQvvhhgpKczWpWiEmd8MfyJe27sxw,9131
@@ -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.180.dev3.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
- code_loader-1.0.180.dev3.dist-info/METADATA,sha256=e742DymYsZVynEaCgd7V8Fsx4hyNnJJO7aM0mfB55Ls,1095
37
- code_loader-1.0.180.dev3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- code_loader-1.0.180.dev3.dist-info/RECORD,,
35
+ code_loader-1.0.180.dev5.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
+ code_loader-1.0.180.dev5.dist-info/METADATA,sha256=vTd4e5_mtmvSuDNXvV3D8U6VhQ-8Qe4xLSWUb9gHS1g,1095
37
+ code_loader-1.0.180.dev5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
+ code_loader-1.0.180.dev5.dist-info/RECORD,,