code-loader 1.0.181.dev0__py3-none-any.whl → 1.0.181.dev2__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/contract/sim_config.py +13 -0
- code_loader/inner_leap_binder/leapbinder.py +33 -2
- code_loader/inner_leap_binder/leapbinder_decorators.py +4 -4
- code_loader/leaploader.py +17 -21
- {code_loader-1.0.181.dev0.dist-info → code_loader-1.0.181.dev2.dist-info}/METADATA +1 -1
- {code_loader-1.0.181.dev0.dist-info → code_loader-1.0.181.dev2.dist-info}/RECORD +8 -8
- {code_loader-1.0.181.dev0.dist-info → code_loader-1.0.181.dev2.dist-info}/LICENSE +0 -0
- {code_loader-1.0.181.dev0.dist-info → code_loader-1.0.181.dev2.dist-info}/WHEEL +0 -0
|
@@ -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,41 @@ 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
|
+
for sim in self.setup_container.simulations:
|
|
671
|
+
kwargs = sample_sim_params(sim.sim_config)
|
|
672
|
+
kwargs["N"] = 1
|
|
673
|
+
kwargs["seed"] = 0
|
|
674
|
+
_simulation_context["active"] = True
|
|
675
|
+
try:
|
|
676
|
+
preprocess_response = sim.function(**kwargs)
|
|
677
|
+
finally:
|
|
678
|
+
_simulation_context["active"] = False
|
|
679
|
+
if not isinstance(preprocess_response, PreprocessResponse):
|
|
680
|
+
raise Exception(
|
|
681
|
+
"Simulation '{}' returned {} instead of PreprocessResponse".format(
|
|
682
|
+
sim.name, type(preprocess_response).__name__
|
|
683
|
+
)
|
|
684
|
+
)
|
|
685
|
+
preprocess_response.state = DataStateType.additional
|
|
686
|
+
preprocess_response.tl_generated = True
|
|
687
|
+
if not preprocess_response.length or preprocess_response.length < 1:
|
|
688
|
+
raise Exception("Simulation '{}' returned PreprocessResponse with length < 1".format(sim.name))
|
|
689
|
+
for handler in self.setup_container.inputs:
|
|
690
|
+
out1 = handler.function(0, preprocess_response)
|
|
691
|
+
out2 = handler.function(0, preprocess_response)
|
|
692
|
+
if not np.array_equal(out1, out2):
|
|
693
|
+
raise Exception(
|
|
694
|
+
"Simulation '{}': encoder '{}' is non-deterministic — consecutive calls with seed=0 returned different outputs".format(
|
|
695
|
+
sim.name, handler.name
|
|
696
|
+
)
|
|
697
|
+
)
|
|
698
|
+
|
|
669
699
|
def check(self) -> None:
|
|
670
700
|
preprocess_result = self.get_preprocess_result()
|
|
671
701
|
self.check_preprocess(preprocess_result)
|
|
672
702
|
self.check_handlers(preprocess_result)
|
|
703
|
+
self.check_simulations()
|
|
673
704
|
self.validate_ignore_latent_spaces()
|
|
674
705
|
print("Successful!")
|
|
675
706
|
|
|
@@ -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
|
|
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
|
|
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)
|
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 =
|
|
311
|
+
kwargs = sample_sim_params(sim.sim_config)
|
|
325
312
|
kwargs["N"] = 1
|
|
326
|
-
|
|
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,16 +353,16 @@ 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 =
|
|
356
|
+
kwargs = sample_sim_params(sim.sim_config)
|
|
361
357
|
kwargs["N"] = 1
|
|
362
|
-
|
|
363
|
-
kwargs["seed"] = 0
|
|
358
|
+
kwargs["seed"] = 0
|
|
364
359
|
_simulation_context["active"] = True
|
|
365
360
|
try:
|
|
366
361
|
sim_preprocess = sim.function(**kwargs)
|
|
367
362
|
finally:
|
|
368
363
|
_simulation_context["active"] = False
|
|
369
364
|
sim_preprocess.state = DataStateType.additional
|
|
365
|
+
sim_preprocess.tl_generated = True
|
|
370
366
|
result = {}
|
|
371
367
|
for handler in global_leap_binder.setup_container.inputs:
|
|
372
368
|
result[handler.name] = handler.function(0, sim_preprocess)
|
|
@@ -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=
|
|
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=
|
|
25
|
-
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=
|
|
26
|
-
code_loader/leaploader.py,sha256
|
|
24
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=U8uqDm1cilOLcswIDON21UIiaXU0cuElUxAXX7hwZdE,40110
|
|
25
|
+
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=E1j51BO2bzkeMjOazyFN4BhwGveDylk8bToNQ-qU8iM,105732
|
|
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.
|
|
36
|
-
code_loader-1.0.181.
|
|
37
|
-
code_loader-1.0.181.
|
|
38
|
-
code_loader-1.0.181.
|
|
35
|
+
code_loader-1.0.181.dev2.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
36
|
+
code_loader-1.0.181.dev2.dist-info/METADATA,sha256=c8EAS6a_q-ahHHaR4etpqPhswsosFBMogx-Tz9NkDwg,1095
|
|
37
|
+
code_loader-1.0.181.dev2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
38
|
+
code_loader-1.0.181.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|