hpcflow 0.1.15__py3-none-any.whl → 0.2.0a271__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.
- hpcflow/__init__.py +2 -11
- hpcflow/__pyinstaller/__init__.py +5 -0
- hpcflow/__pyinstaller/hook-hpcflow.py +40 -0
- hpcflow/_version.py +1 -1
- hpcflow/app.py +43 -0
- hpcflow/cli.py +2 -461
- hpcflow/data/demo_data_manifest/__init__.py +3 -0
- hpcflow/data/demo_data_manifest/demo_data_manifest.json +6 -0
- hpcflow/data/jinja_templates/test/test_template.txt +8 -0
- hpcflow/data/programs/hello_world/README.md +1 -0
- hpcflow/data/programs/hello_world/hello_world.c +87 -0
- hpcflow/data/programs/hello_world/linux/hello_world +0 -0
- hpcflow/data/programs/hello_world/macos/hello_world +0 -0
- hpcflow/data/programs/hello_world/win/hello_world.exe +0 -0
- hpcflow/data/scripts/__init__.py +1 -0
- hpcflow/data/scripts/bad_script.py +2 -0
- hpcflow/data/scripts/demo_task_1_generate_t1_infile_1.py +8 -0
- hpcflow/data/scripts/demo_task_1_generate_t1_infile_2.py +8 -0
- hpcflow/data/scripts/demo_task_1_parse_p3.py +7 -0
- hpcflow/data/scripts/do_nothing.py +2 -0
- hpcflow/data/scripts/env_specifier_test/input_file_generator_pass_env_spec.py +4 -0
- hpcflow/data/scripts/env_specifier_test/main_script_test_pass_env_spec.py +8 -0
- hpcflow/data/scripts/env_specifier_test/output_file_parser_pass_env_spec.py +4 -0
- hpcflow/data/scripts/env_specifier_test/v1/input_file_generator_basic.py +4 -0
- hpcflow/data/scripts/env_specifier_test/v1/main_script_test_direct_in_direct_out.py +7 -0
- hpcflow/data/scripts/env_specifier_test/v1/output_file_parser_basic.py +4 -0
- hpcflow/data/scripts/env_specifier_test/v2/main_script_test_direct_in_direct_out.py +7 -0
- hpcflow/data/scripts/generate_t1_file_01.py +7 -0
- hpcflow/data/scripts/import_future_script.py +7 -0
- hpcflow/data/scripts/input_file_generator_basic.py +3 -0
- hpcflow/data/scripts/input_file_generator_basic_FAIL.py +3 -0
- hpcflow/data/scripts/input_file_generator_test_stdout_stderr.py +8 -0
- hpcflow/data/scripts/main_script_test_direct_in.py +3 -0
- hpcflow/data/scripts/main_script_test_direct_in_direct_out.py +6 -0
- hpcflow/data/scripts/main_script_test_direct_in_direct_out_2.py +6 -0
- hpcflow/data/scripts/main_script_test_direct_in_direct_out_2_fail_allowed.py +6 -0
- hpcflow/data/scripts/main_script_test_direct_in_direct_out_2_fail_allowed_group.py +7 -0
- hpcflow/data/scripts/main_script_test_direct_in_direct_out_3.py +6 -0
- hpcflow/data/scripts/main_script_test_direct_in_direct_out_all_iters_test.py +15 -0
- hpcflow/data/scripts/main_script_test_direct_in_direct_out_env_spec.py +7 -0
- hpcflow/data/scripts/main_script_test_direct_in_direct_out_labels.py +8 -0
- hpcflow/data/scripts/main_script_test_direct_in_group_direct_out_3.py +6 -0
- hpcflow/data/scripts/main_script_test_direct_in_group_one_fail_direct_out_3.py +6 -0
- hpcflow/data/scripts/main_script_test_direct_sub_param_in_direct_out.py +6 -0
- hpcflow/data/scripts/main_script_test_hdf5_in_obj.py +12 -0
- hpcflow/data/scripts/main_script_test_hdf5_in_obj_2.py +12 -0
- hpcflow/data/scripts/main_script_test_hdf5_in_obj_group.py +12 -0
- hpcflow/data/scripts/main_script_test_hdf5_out_obj.py +11 -0
- hpcflow/data/scripts/main_script_test_json_and_direct_in_json_out.py +14 -0
- hpcflow/data/scripts/main_script_test_json_in_json_and_direct_out.py +17 -0
- hpcflow/data/scripts/main_script_test_json_in_json_out.py +14 -0
- hpcflow/data/scripts/main_script_test_json_in_json_out_labels.py +16 -0
- hpcflow/data/scripts/main_script_test_json_in_obj.py +12 -0
- hpcflow/data/scripts/main_script_test_json_out_FAIL.py +3 -0
- hpcflow/data/scripts/main_script_test_json_out_obj.py +10 -0
- hpcflow/data/scripts/main_script_test_json_sub_param_in_json_out_labels.py +16 -0
- hpcflow/data/scripts/main_script_test_shell_env_vars.py +12 -0
- hpcflow/data/scripts/main_script_test_std_out_std_err.py +6 -0
- hpcflow/data/scripts/output_file_parser_basic.py +3 -0
- hpcflow/data/scripts/output_file_parser_basic_FAIL.py +7 -0
- hpcflow/data/scripts/output_file_parser_test_stdout_stderr.py +8 -0
- hpcflow/data/scripts/parse_t1_file_01.py +4 -0
- hpcflow/data/scripts/script_exit_test.py +5 -0
- hpcflow/data/template_components/__init__.py +1 -0
- hpcflow/data/template_components/command_files.yaml +26 -0
- hpcflow/data/template_components/environments.yaml +13 -0
- hpcflow/data/template_components/parameters.yaml +14 -0
- hpcflow/data/template_components/task_schemas.yaml +139 -0
- hpcflow/data/workflows/workflow_1.yaml +5 -0
- hpcflow/examples.ipynb +1037 -0
- hpcflow/sdk/__init__.py +149 -0
- hpcflow/sdk/app.py +4266 -0
- hpcflow/sdk/cli.py +1479 -0
- hpcflow/sdk/cli_common.py +385 -0
- hpcflow/sdk/config/__init__.py +5 -0
- hpcflow/sdk/config/callbacks.py +246 -0
- hpcflow/sdk/config/cli.py +388 -0
- hpcflow/sdk/config/config.py +1410 -0
- hpcflow/sdk/config/config_file.py +501 -0
- hpcflow/sdk/config/errors.py +272 -0
- hpcflow/sdk/config/types.py +150 -0
- hpcflow/sdk/core/__init__.py +38 -0
- hpcflow/sdk/core/actions.py +3857 -0
- hpcflow/sdk/core/app_aware.py +25 -0
- hpcflow/sdk/core/cache.py +224 -0
- hpcflow/sdk/core/command_files.py +814 -0
- hpcflow/sdk/core/commands.py +424 -0
- hpcflow/sdk/core/element.py +2071 -0
- hpcflow/sdk/core/enums.py +221 -0
- hpcflow/sdk/core/environment.py +256 -0
- hpcflow/sdk/core/errors.py +1043 -0
- hpcflow/sdk/core/execute.py +207 -0
- hpcflow/sdk/core/json_like.py +809 -0
- hpcflow/sdk/core/loop.py +1320 -0
- hpcflow/sdk/core/loop_cache.py +282 -0
- hpcflow/sdk/core/object_list.py +933 -0
- hpcflow/sdk/core/parameters.py +3371 -0
- hpcflow/sdk/core/rule.py +196 -0
- hpcflow/sdk/core/run_dir_files.py +57 -0
- hpcflow/sdk/core/skip_reason.py +7 -0
- hpcflow/sdk/core/task.py +3792 -0
- hpcflow/sdk/core/task_schema.py +993 -0
- hpcflow/sdk/core/test_utils.py +538 -0
- hpcflow/sdk/core/types.py +447 -0
- hpcflow/sdk/core/utils.py +1207 -0
- hpcflow/sdk/core/validation.py +87 -0
- hpcflow/sdk/core/values.py +477 -0
- hpcflow/sdk/core/workflow.py +4820 -0
- hpcflow/sdk/core/zarr_io.py +206 -0
- hpcflow/sdk/data/__init__.py +13 -0
- hpcflow/sdk/data/config_file_schema.yaml +34 -0
- hpcflow/sdk/data/config_schema.yaml +260 -0
- hpcflow/sdk/data/environments_spec_schema.yaml +21 -0
- hpcflow/sdk/data/files_spec_schema.yaml +5 -0
- hpcflow/sdk/data/parameters_spec_schema.yaml +7 -0
- hpcflow/sdk/data/task_schema_spec_schema.yaml +3 -0
- hpcflow/sdk/data/workflow_spec_schema.yaml +22 -0
- hpcflow/sdk/demo/__init__.py +3 -0
- hpcflow/sdk/demo/cli.py +242 -0
- hpcflow/sdk/helper/__init__.py +3 -0
- hpcflow/sdk/helper/cli.py +137 -0
- hpcflow/sdk/helper/helper.py +300 -0
- hpcflow/sdk/helper/watcher.py +192 -0
- hpcflow/sdk/log.py +288 -0
- hpcflow/sdk/persistence/__init__.py +18 -0
- hpcflow/sdk/persistence/base.py +2817 -0
- hpcflow/sdk/persistence/defaults.py +6 -0
- hpcflow/sdk/persistence/discovery.py +39 -0
- hpcflow/sdk/persistence/json.py +954 -0
- hpcflow/sdk/persistence/pending.py +948 -0
- hpcflow/sdk/persistence/store_resource.py +203 -0
- hpcflow/sdk/persistence/types.py +309 -0
- hpcflow/sdk/persistence/utils.py +73 -0
- hpcflow/sdk/persistence/zarr.py +2388 -0
- hpcflow/sdk/runtime.py +320 -0
- hpcflow/sdk/submission/__init__.py +3 -0
- hpcflow/sdk/submission/enums.py +70 -0
- hpcflow/sdk/submission/jobscript.py +2379 -0
- hpcflow/sdk/submission/schedulers/__init__.py +281 -0
- hpcflow/sdk/submission/schedulers/direct.py +233 -0
- hpcflow/sdk/submission/schedulers/sge.py +376 -0
- hpcflow/sdk/submission/schedulers/slurm.py +598 -0
- hpcflow/sdk/submission/schedulers/utils.py +25 -0
- hpcflow/sdk/submission/shells/__init__.py +52 -0
- hpcflow/sdk/submission/shells/base.py +229 -0
- hpcflow/sdk/submission/shells/bash.py +504 -0
- hpcflow/sdk/submission/shells/os_version.py +115 -0
- hpcflow/sdk/submission/shells/powershell.py +352 -0
- hpcflow/sdk/submission/submission.py +1402 -0
- hpcflow/sdk/submission/types.py +140 -0
- hpcflow/sdk/typing.py +194 -0
- hpcflow/sdk/utils/arrays.py +69 -0
- hpcflow/sdk/utils/deferred_file.py +55 -0
- hpcflow/sdk/utils/hashing.py +16 -0
- hpcflow/sdk/utils/patches.py +31 -0
- hpcflow/sdk/utils/strings.py +69 -0
- hpcflow/tests/api/test_api.py +32 -0
- hpcflow/tests/conftest.py +123 -0
- hpcflow/tests/data/__init__.py +0 -0
- hpcflow/tests/data/benchmark_N_elements.yaml +6 -0
- hpcflow/tests/data/benchmark_script_runner.yaml +26 -0
- hpcflow/tests/data/multi_path_sequences.yaml +29 -0
- hpcflow/tests/data/workflow_1.json +10 -0
- hpcflow/tests/data/workflow_1.yaml +5 -0
- hpcflow/tests/data/workflow_1_slurm.yaml +8 -0
- hpcflow/tests/data/workflow_1_wsl.yaml +8 -0
- hpcflow/tests/data/workflow_test_run_abort.yaml +42 -0
- hpcflow/tests/jinja_templates/test_jinja_templates.py +161 -0
- hpcflow/tests/programs/test_programs.py +180 -0
- hpcflow/tests/schedulers/direct_linux/test_direct_linux_submission.py +12 -0
- hpcflow/tests/schedulers/sge/test_sge_submission.py +36 -0
- hpcflow/tests/schedulers/slurm/test_slurm_submission.py +14 -0
- hpcflow/tests/scripts/test_input_file_generators.py +282 -0
- hpcflow/tests/scripts/test_main_scripts.py +1361 -0
- hpcflow/tests/scripts/test_non_snippet_script.py +46 -0
- hpcflow/tests/scripts/test_ouput_file_parsers.py +353 -0
- hpcflow/tests/shells/wsl/test_wsl_submission.py +14 -0
- hpcflow/tests/unit/test_action.py +1066 -0
- hpcflow/tests/unit/test_action_rule.py +24 -0
- hpcflow/tests/unit/test_app.py +132 -0
- hpcflow/tests/unit/test_cache.py +46 -0
- hpcflow/tests/unit/test_cli.py +172 -0
- hpcflow/tests/unit/test_command.py +377 -0
- hpcflow/tests/unit/test_config.py +195 -0
- hpcflow/tests/unit/test_config_file.py +162 -0
- hpcflow/tests/unit/test_element.py +666 -0
- hpcflow/tests/unit/test_element_iteration.py +88 -0
- hpcflow/tests/unit/test_element_set.py +158 -0
- hpcflow/tests/unit/test_group.py +115 -0
- hpcflow/tests/unit/test_input_source.py +1479 -0
- hpcflow/tests/unit/test_input_value.py +398 -0
- hpcflow/tests/unit/test_jobscript_unit.py +757 -0
- hpcflow/tests/unit/test_json_like.py +1247 -0
- hpcflow/tests/unit/test_loop.py +2674 -0
- hpcflow/tests/unit/test_meta_task.py +325 -0
- hpcflow/tests/unit/test_multi_path_sequences.py +259 -0
- hpcflow/tests/unit/test_object_list.py +116 -0
- hpcflow/tests/unit/test_parameter.py +243 -0
- hpcflow/tests/unit/test_persistence.py +664 -0
- hpcflow/tests/unit/test_resources.py +243 -0
- hpcflow/tests/unit/test_run.py +286 -0
- hpcflow/tests/unit/test_run_directories.py +29 -0
- hpcflow/tests/unit/test_runtime.py +9 -0
- hpcflow/tests/unit/test_schema_input.py +372 -0
- hpcflow/tests/unit/test_shell.py +129 -0
- hpcflow/tests/unit/test_slurm.py +39 -0
- hpcflow/tests/unit/test_submission.py +502 -0
- hpcflow/tests/unit/test_task.py +2560 -0
- hpcflow/tests/unit/test_task_schema.py +182 -0
- hpcflow/tests/unit/test_utils.py +616 -0
- hpcflow/tests/unit/test_value_sequence.py +549 -0
- hpcflow/tests/unit/test_values.py +91 -0
- hpcflow/tests/unit/test_workflow.py +827 -0
- hpcflow/tests/unit/test_workflow_template.py +186 -0
- hpcflow/tests/unit/utils/test_arrays.py +40 -0
- hpcflow/tests/unit/utils/test_deferred_file_writer.py +34 -0
- hpcflow/tests/unit/utils/test_hashing.py +65 -0
- hpcflow/tests/unit/utils/test_patches.py +5 -0
- hpcflow/tests/unit/utils/test_redirect_std.py +50 -0
- hpcflow/tests/unit/utils/test_strings.py +97 -0
- hpcflow/tests/workflows/__init__.py +0 -0
- hpcflow/tests/workflows/test_directory_structure.py +31 -0
- hpcflow/tests/workflows/test_jobscript.py +355 -0
- hpcflow/tests/workflows/test_run_status.py +198 -0
- hpcflow/tests/workflows/test_skip_downstream.py +696 -0
- hpcflow/tests/workflows/test_submission.py +140 -0
- hpcflow/tests/workflows/test_workflows.py +564 -0
- hpcflow/tests/workflows/test_zip.py +18 -0
- hpcflow/viz_demo.ipynb +6794 -0
- hpcflow-0.2.0a271.dist-info/LICENSE +375 -0
- hpcflow-0.2.0a271.dist-info/METADATA +65 -0
- hpcflow-0.2.0a271.dist-info/RECORD +237 -0
- {hpcflow-0.1.15.dist-info → hpcflow-0.2.0a271.dist-info}/WHEEL +4 -5
- hpcflow-0.2.0a271.dist-info/entry_points.txt +6 -0
- hpcflow/api.py +0 -490
- hpcflow/archive/archive.py +0 -307
- hpcflow/archive/cloud/cloud.py +0 -45
- hpcflow/archive/cloud/errors.py +0 -9
- hpcflow/archive/cloud/providers/dropbox.py +0 -427
- hpcflow/archive/errors.py +0 -5
- hpcflow/base_db.py +0 -4
- hpcflow/config.py +0 -233
- hpcflow/copytree.py +0 -66
- hpcflow/data/examples/_config.yml +0 -14
- hpcflow/data/examples/damask/demo/1.run.yml +0 -4
- hpcflow/data/examples/damask/demo/2.process.yml +0 -29
- hpcflow/data/examples/damask/demo/geom.geom +0 -2052
- hpcflow/data/examples/damask/demo/load.load +0 -1
- hpcflow/data/examples/damask/demo/material.config +0 -185
- hpcflow/data/examples/damask/inputs/geom.geom +0 -2052
- hpcflow/data/examples/damask/inputs/load.load +0 -1
- hpcflow/data/examples/damask/inputs/material.config +0 -185
- hpcflow/data/examples/damask/profiles/_variable_lookup.yml +0 -21
- hpcflow/data/examples/damask/profiles/damask.yml +0 -4
- hpcflow/data/examples/damask/profiles/damask_process.yml +0 -8
- hpcflow/data/examples/damask/profiles/damask_run.yml +0 -5
- hpcflow/data/examples/damask/profiles/default.yml +0 -6
- hpcflow/data/examples/thinking.yml +0 -177
- hpcflow/errors.py +0 -2
- hpcflow/init_db.py +0 -37
- hpcflow/models.py +0 -2595
- hpcflow/nesting.py +0 -9
- hpcflow/profiles.py +0 -455
- hpcflow/project.py +0 -81
- hpcflow/scheduler.py +0 -322
- hpcflow/utils.py +0 -103
- hpcflow/validation.py +0 -166
- hpcflow/variables.py +0 -543
- hpcflow-0.1.15.dist-info/METADATA +0 -168
- hpcflow-0.1.15.dist-info/RECORD +0 -45
- hpcflow-0.1.15.dist-info/entry_points.txt +0 -8
- hpcflow-0.1.15.dist-info/top_level.txt +0 -1
- /hpcflow/{archive → data/jinja_templates}/__init__.py +0 -0
- /hpcflow/{archive/cloud → data/programs}/__init__.py +0 -0
- /hpcflow/{archive/cloud/providers → data/workflows}/__init__.py +0 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from textwrap import dedent
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
import pytest
|
|
7
|
+
import requests
|
|
8
|
+
|
|
9
|
+
from hpcflow.app import app as hf
|
|
10
|
+
from hpcflow.sdk.core.test_utils import P1_parameter_cls as P1
|
|
11
|
+
from hpcflow.sdk.core.utils import read_YAML_str
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from hpcflow.sdk.core.parameters import Parameter
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.fixture
|
|
18
|
+
def null_config(tmp_path: Path):
|
|
19
|
+
if not hf.is_config_loaded:
|
|
20
|
+
hf.load_config(config_dir=tmp_path)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@pytest.fixture
|
|
24
|
+
def param_p1(null_config) -> Parameter:
|
|
25
|
+
return hf.Parameter("p1")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_fix_trailing_path_delimiter(param_p1: Parameter):
|
|
29
|
+
iv1 = hf.InputValue(parameter=param_p1, value=101, path="a.")
|
|
30
|
+
iv2 = hf.InputValue(parameter=param_p1, value=101, path="a")
|
|
31
|
+
assert iv1.path == iv2.path
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_fix_single_path_delimiter(param_p1: Parameter):
|
|
35
|
+
iv1 = hf.InputValue(parameter=param_p1, value=101, path=".")
|
|
36
|
+
iv2 = hf.InputValue(parameter=param_p1, value=101)
|
|
37
|
+
assert iv1.path == iv2.path
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_normalised_path_without_path(param_p1: Parameter):
|
|
41
|
+
iv1 = hf.InputValue(parameter=param_p1, value=101)
|
|
42
|
+
assert iv1.normalised_path == "inputs.p1"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_normalised_path_with_single_element_path(param_p1: Parameter):
|
|
46
|
+
iv1 = hf.InputValue(parameter=param_p1, value=101, path="a")
|
|
47
|
+
assert iv1.normalised_path == "inputs.p1.a"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_normalised_path_with_multi_element_path(param_p1: Parameter):
|
|
51
|
+
iv1 = hf.InputValue(parameter=param_p1, value=101, path="a.b")
|
|
52
|
+
assert iv1.normalised_path == "inputs.p1.a.b"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_normalised_path_with_empty_path(param_p1: Parameter):
|
|
56
|
+
iv1 = hf.InputValue(parameter=param_p1, value=101, path="")
|
|
57
|
+
assert iv1.normalised_path == "inputs.p1"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_resource_spec_get_param_path(null_config) -> None:
|
|
61
|
+
rs1 = hf.ResourceSpec()
|
|
62
|
+
assert rs1.normalised_path == "resources.any"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_resource_spec_get_param_path_scope_any_with_single_kwarg(null_config) -> None:
|
|
66
|
+
rs1 = hf.ResourceSpec(scratch="local")
|
|
67
|
+
assert rs1.normalised_path == "resources.any"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_resources_spec_get_param_path_scope_main(null_config) -> None:
|
|
71
|
+
rs1 = hf.ResourceSpec(scope=hf.ActionScope.main())
|
|
72
|
+
assert rs1.normalised_path == "resources.main"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_resources_spec_get_param_path_scope_with_kwargs(null_config) -> None:
|
|
76
|
+
rs1 = hf.ResourceSpec(scope=hf.ActionScope.input_file_generator(file="file1"))
|
|
77
|
+
assert rs1.normalised_path == "resources.input_file_generator[file=file1]"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_resources_spec_get_param_path_scope_with_no_kwargs(null_config) -> None:
|
|
81
|
+
rs1 = hf.ResourceSpec(scope=hf.ActionScope.input_file_generator())
|
|
82
|
+
assert rs1.normalised_path == "resources.input_file_generator"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_input_value_from_json_like_class_method_attribute_is_set(null_config) -> None:
|
|
86
|
+
parameter_typ = "p1c"
|
|
87
|
+
cls_method = "from_data"
|
|
88
|
+
json_like = {"parameter": f"{parameter_typ}::{cls_method}", "value": {"a": 101}}
|
|
89
|
+
inp_val = hf.InputValue.from_json_like(json_like, shared_data=hf.template_components)
|
|
90
|
+
assert inp_val.parameter.typ == parameter_typ
|
|
91
|
+
assert inp_val.value_class_method == cls_method
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_value_sequence_from_json_like_class_method_attribute_is_set(null_config) -> None:
|
|
95
|
+
parameter_typ = "p1"
|
|
96
|
+
cls_method = "from_data"
|
|
97
|
+
json_like = {
|
|
98
|
+
"path": f"inputs.{parameter_typ}::{cls_method}",
|
|
99
|
+
"values": [101],
|
|
100
|
+
"nesting_order": 0,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
val_seq = hf.ValueSequence.from_json_like(
|
|
104
|
+
json_like, shared_data=hf.template_components
|
|
105
|
+
)
|
|
106
|
+
assert val_seq.value_class_method == cls_method
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_path_attributes(null_config) -> None:
|
|
110
|
+
inp = hf.InputValue(parameter="p1", value=101, path="a.b")
|
|
111
|
+
assert inp.labelled_type == "p1"
|
|
112
|
+
assert inp.normalised_path == "inputs.p1.a.b"
|
|
113
|
+
assert inp.normalised_inputs_path == "p1.a.b"
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_path_attributes_with_label_arg(null_config) -> None:
|
|
117
|
+
inp = hf.InputValue(parameter="p1", value=101, path="a.b", label="1")
|
|
118
|
+
assert inp.labelled_type == "p1[1]"
|
|
119
|
+
assert inp.normalised_path == "inputs.p1[1].a.b"
|
|
120
|
+
assert inp.normalised_inputs_path == "p1[1].a.b"
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_path_attributes_with_label_arg_cast(null_config) -> None:
|
|
124
|
+
inp = hf.InputValue(parameter="p1", value=101, path="a.b", label=1)
|
|
125
|
+
assert inp.labelled_type == "p1[1]"
|
|
126
|
+
assert inp.normalised_path == "inputs.p1[1].a.b"
|
|
127
|
+
assert inp.normalised_inputs_path == "p1[1].a.b"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_from_json_like(null_config) -> None:
|
|
131
|
+
inp = hf.InputValue.from_json_like(
|
|
132
|
+
json_like={"parameter": "p1", "value": 101},
|
|
133
|
+
shared_data=hf.template_components,
|
|
134
|
+
)
|
|
135
|
+
assert inp.parameter.typ == hf.Parameter("p1").typ
|
|
136
|
+
assert inp.value == 101
|
|
137
|
+
assert inp.label == ""
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_from_json_like_with_label(null_config) -> None:
|
|
141
|
+
inp = hf.InputValue.from_json_like(
|
|
142
|
+
json_like={"parameter": "p1[1]", "value": 101},
|
|
143
|
+
shared_data=hf.template_components,
|
|
144
|
+
)
|
|
145
|
+
assert inp.parameter.typ == hf.Parameter("p1").typ
|
|
146
|
+
assert inp.value == 101
|
|
147
|
+
assert inp.label == "1"
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_value_is_dict_check_success(null_config) -> None:
|
|
151
|
+
# Parameter("p1c") has an associated `ParameterValue` class, so data should be a dict:
|
|
152
|
+
hf.InputValue("p1c", {"a": 101})
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def test_value_is_dict_check_raise(null_config) -> None:
|
|
156
|
+
# Parameter("p1c") has an associated `ParameterValue` class so data should be a dict:
|
|
157
|
+
with pytest.raises(ValueError):
|
|
158
|
+
hf.InputValue("p1c", 101)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def test_value_is_dict_check_no_raise_if_sub_parameter(null_config):
|
|
162
|
+
# Parameter("p1c") has an associated `ParameterValue` class, but the specified value
|
|
163
|
+
# is for some sub-data:
|
|
164
|
+
hf.InputValue("p1c", path="a", value=101)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@pytest.mark.xfail(
|
|
168
|
+
condition=sys.platform == "darwin",
|
|
169
|
+
raises=requests.exceptions.HTTPError,
|
|
170
|
+
reason=(
|
|
171
|
+
"GHA MacOS runners use the same IP address, so we get rate limited when "
|
|
172
|
+
"retrieving demo data from GitHub."
|
|
173
|
+
),
|
|
174
|
+
)
|
|
175
|
+
def test_demo_data_value(null_config) -> None:
|
|
176
|
+
name = "text_file.txt"
|
|
177
|
+
assert hf.InputValue("p1", value=f"<<demo_data_file:{name}>>").value == str(
|
|
178
|
+
hf.demo_data_cache_dir.joinpath(name)
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_input_value_from_yaml_and_json_like_various(null_config):
|
|
183
|
+
|
|
184
|
+
seed = 9871389
|
|
185
|
+
es_all = [
|
|
186
|
+
dedent(
|
|
187
|
+
"""\
|
|
188
|
+
inputs:
|
|
189
|
+
p1: 1
|
|
190
|
+
"""
|
|
191
|
+
),
|
|
192
|
+
dedent(
|
|
193
|
+
f"""\
|
|
194
|
+
inputs:
|
|
195
|
+
p1[A]: 1
|
|
196
|
+
"""
|
|
197
|
+
),
|
|
198
|
+
dedent(
|
|
199
|
+
f"""\
|
|
200
|
+
inputs:
|
|
201
|
+
p1.b: 20
|
|
202
|
+
"""
|
|
203
|
+
),
|
|
204
|
+
dedent(
|
|
205
|
+
f"""\
|
|
206
|
+
inputs:
|
|
207
|
+
p1[A].b: 1
|
|
208
|
+
"""
|
|
209
|
+
),
|
|
210
|
+
dedent(
|
|
211
|
+
f"""\
|
|
212
|
+
inputs:
|
|
213
|
+
p1c::from_data:
|
|
214
|
+
b: 1
|
|
215
|
+
c: 2
|
|
216
|
+
"""
|
|
217
|
+
),
|
|
218
|
+
dedent(
|
|
219
|
+
f"""\
|
|
220
|
+
inputs:
|
|
221
|
+
p1c[A]::from_data:
|
|
222
|
+
b: 1
|
|
223
|
+
c: 2
|
|
224
|
+
"""
|
|
225
|
+
),
|
|
226
|
+
dedent(
|
|
227
|
+
f"""\
|
|
228
|
+
inputs:
|
|
229
|
+
p1::from_normal:
|
|
230
|
+
loc: 1.4
|
|
231
|
+
scale: 0.1
|
|
232
|
+
seed: {seed}
|
|
233
|
+
"""
|
|
234
|
+
),
|
|
235
|
+
dedent(
|
|
236
|
+
f"""\
|
|
237
|
+
inputs:
|
|
238
|
+
p1[A]::from_normal:
|
|
239
|
+
loc: 1.4
|
|
240
|
+
scale: 0.1
|
|
241
|
+
seed: {seed}
|
|
242
|
+
"""
|
|
243
|
+
),
|
|
244
|
+
dedent(
|
|
245
|
+
f"""\
|
|
246
|
+
inputs:
|
|
247
|
+
p1.b::from_normal:
|
|
248
|
+
loc: 1.4
|
|
249
|
+
scale: 0.1
|
|
250
|
+
seed: {seed}
|
|
251
|
+
"""
|
|
252
|
+
),
|
|
253
|
+
dedent(
|
|
254
|
+
f"""\
|
|
255
|
+
inputs:
|
|
256
|
+
p1[A].b::from_normal:
|
|
257
|
+
loc: 1.4
|
|
258
|
+
scale: 0.1
|
|
259
|
+
seed: {seed}
|
|
260
|
+
"""
|
|
261
|
+
),
|
|
262
|
+
]
|
|
263
|
+
|
|
264
|
+
es_JSONs = [read_YAML_str(es_i) for es_i in es_all]
|
|
265
|
+
es = [
|
|
266
|
+
hf.ElementSet.from_json_like(
|
|
267
|
+
es_json_i,
|
|
268
|
+
shared_data=hf.template_components,
|
|
269
|
+
)
|
|
270
|
+
for es_json_i in es_JSONs
|
|
271
|
+
]
|
|
272
|
+
inps = [es_i.inputs[0] for es_i in es]
|
|
273
|
+
|
|
274
|
+
assert (
|
|
275
|
+
inps[0]
|
|
276
|
+
== hf.InputValue.from_json_like(
|
|
277
|
+
{"parameter": "p1", "value": 1},
|
|
278
|
+
shared_data=hf.template_components,
|
|
279
|
+
)
|
|
280
|
+
== hf.InputValue(hf.Parameter("p1"), value=1)
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
assert (
|
|
284
|
+
inps[1]
|
|
285
|
+
== hf.InputValue.from_json_like(
|
|
286
|
+
{"parameter": "p1[A]", "value": 1},
|
|
287
|
+
shared_data=hf.template_components,
|
|
288
|
+
)
|
|
289
|
+
== hf.InputValue(hf.Parameter("p1"), label="A", value=1)
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
assert (
|
|
293
|
+
inps[2]
|
|
294
|
+
== hf.InputValue.from_json_like(
|
|
295
|
+
{"parameter": "p1.b", "value": 20},
|
|
296
|
+
shared_data=hf.template_components,
|
|
297
|
+
)
|
|
298
|
+
== hf.InputValue(hf.Parameter("p1"), path="b", value=20)
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
assert (
|
|
302
|
+
inps[3]
|
|
303
|
+
== hf.InputValue.from_json_like(
|
|
304
|
+
{"parameter": "p1[A].b", "value": 1},
|
|
305
|
+
shared_data=hf.template_components,
|
|
306
|
+
)
|
|
307
|
+
== hf.InputValue(hf.Parameter("p1"), label="A", path="b", value=1)
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
assert (
|
|
311
|
+
inps[4]
|
|
312
|
+
== hf.InputValue.from_json_like(
|
|
313
|
+
{"parameter": "p1c::from_data", "value": {"b": 1, "c": 2}},
|
|
314
|
+
shared_data=hf.template_components,
|
|
315
|
+
)
|
|
316
|
+
== hf.InputValue(
|
|
317
|
+
hf.Parameter("p1c"), value={"b": 1, "c": 2}, value_class_method="from_data"
|
|
318
|
+
)
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
assert (
|
|
322
|
+
inps[5]
|
|
323
|
+
== hf.InputValue.from_json_like(
|
|
324
|
+
{"parameter": "p1c[A]::from_data", "value": {"b": 1, "c": 2}},
|
|
325
|
+
shared_data=hf.template_components,
|
|
326
|
+
)
|
|
327
|
+
== hf.InputValue(
|
|
328
|
+
hf.Parameter("p1c"),
|
|
329
|
+
label="A",
|
|
330
|
+
value={"b": 1, "c": 2},
|
|
331
|
+
value_class_method="from_data",
|
|
332
|
+
)
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
kwargs = {"loc": 1.4, "scale": 0.1, "seed": seed}
|
|
336
|
+
assert (
|
|
337
|
+
inps[6]
|
|
338
|
+
== hf.InputValue.from_json_like(
|
|
339
|
+
{
|
|
340
|
+
"parameter": "p1::from_normal",
|
|
341
|
+
"value": kwargs,
|
|
342
|
+
},
|
|
343
|
+
shared_data=hf.template_components,
|
|
344
|
+
)
|
|
345
|
+
== hf.InputValue.from_normal(
|
|
346
|
+
hf.Parameter("p1"),
|
|
347
|
+
**kwargs,
|
|
348
|
+
)
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
assert (
|
|
352
|
+
inps[7]
|
|
353
|
+
== hf.InputValue.from_json_like(
|
|
354
|
+
{
|
|
355
|
+
"parameter": "p1[A]::from_normal",
|
|
356
|
+
"value": kwargs,
|
|
357
|
+
},
|
|
358
|
+
shared_data=hf.template_components,
|
|
359
|
+
)
|
|
360
|
+
== hf.InputValue.from_normal(
|
|
361
|
+
hf.Parameter("p1"),
|
|
362
|
+
label="A",
|
|
363
|
+
**kwargs,
|
|
364
|
+
)
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
assert (
|
|
368
|
+
inps[8]
|
|
369
|
+
== hf.InputValue.from_json_like(
|
|
370
|
+
{
|
|
371
|
+
"parameter": "p1.b::from_normal",
|
|
372
|
+
"value": kwargs,
|
|
373
|
+
},
|
|
374
|
+
shared_data=hf.template_components,
|
|
375
|
+
)
|
|
376
|
+
== hf.InputValue.from_normal(
|
|
377
|
+
hf.Parameter("p1"),
|
|
378
|
+
path="b",
|
|
379
|
+
**kwargs,
|
|
380
|
+
)
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
assert (
|
|
384
|
+
inps[9]
|
|
385
|
+
== hf.InputValue.from_json_like(
|
|
386
|
+
{
|
|
387
|
+
"parameter": "p1[A].b::from_normal",
|
|
388
|
+
"value": kwargs,
|
|
389
|
+
},
|
|
390
|
+
shared_data=hf.template_components,
|
|
391
|
+
)
|
|
392
|
+
== hf.InputValue.from_normal(
|
|
393
|
+
hf.Parameter("p1"),
|
|
394
|
+
label="A",
|
|
395
|
+
path="b",
|
|
396
|
+
**kwargs,
|
|
397
|
+
)
|
|
398
|
+
)
|