hpcflow 0.1.9__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 -462
- 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.9.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 -458
- hpcflow/archive/archive.py +0 -308
- hpcflow/archive/cloud/cloud.py +0 -47
- hpcflow/archive/cloud/errors.py +0 -9
- hpcflow/archive/cloud/providers/dropbox.py +0 -432
- hpcflow/archive/errors.py +0 -5
- hpcflow/base_db.py +0 -4
- hpcflow/config.py +0 -232
- 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 -2549
- hpcflow/nesting.py +0 -9
- hpcflow/profiles.py +0 -455
- hpcflow/project.py +0 -81
- hpcflow/scheduler.py +0 -323
- hpcflow/utils.py +0 -103
- hpcflow/validation.py +0 -167
- hpcflow/variables.py +0 -544
- hpcflow-0.1.9.dist-info/METADATA +0 -168
- hpcflow-0.1.9.dist-info/RECORD +0 -45
- hpcflow-0.1.9.dist-info/entry_points.txt +0 -8
- hpcflow-0.1.9.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,87 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Schema management.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
from collections.abc import Mapping, Sequence
|
|
7
|
+
from typing import Any, Generic, Protocol, TypeVar
|
|
8
|
+
from valida import Schema as ValidaSchema # type: ignore
|
|
9
|
+
from hpcflow.sdk.core.utils import open_text_resource
|
|
10
|
+
|
|
11
|
+
T = TypeVar("T")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ValidatedData(Protocol, Generic[T]):
|
|
15
|
+
"""
|
|
16
|
+
Typed profile of ``valida.ValidatedData``.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def is_valid(self) -> bool: ...
|
|
21
|
+
|
|
22
|
+
def get_failures_string(self) -> str: ...
|
|
23
|
+
|
|
24
|
+
cast_data: T
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class PreparedConditionCallable(Protocol):
|
|
28
|
+
"""
|
|
29
|
+
Typed profile of ``valida.PreparedConditionCallable``.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def name(self) -> str: ...
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def args(self) -> tuple[str, ...]: ...
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Condition(Protocol):
|
|
40
|
+
"""
|
|
41
|
+
Typed profile of ``valida.Condition``.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def callable(self) -> PreparedConditionCallable: ...
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Rule(Protocol):
|
|
49
|
+
"""
|
|
50
|
+
Typed profile of ``valida.Rule``.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def condition(self) -> Condition: ...
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def path(self) -> object: ...
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Schema(Protocol):
|
|
61
|
+
"""
|
|
62
|
+
Typed profile of ``valida.Schema``.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
def validate(self, data: T) -> ValidatedData[T]: ...
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def rules(self) -> Sequence[Rule]: ...
|
|
69
|
+
|
|
70
|
+
def add_schema(self, schema: Schema, root_path: Any = None) -> None: ...
|
|
71
|
+
|
|
72
|
+
def to_tree(self, **kwargs) -> Sequence[Mapping[str, str]]: ...
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_schema(filename) -> Schema:
|
|
76
|
+
"""
|
|
77
|
+
Get a valida `Schema` object from the embedded data directory.
|
|
78
|
+
|
|
79
|
+
Parameter
|
|
80
|
+
---------
|
|
81
|
+
schema: str
|
|
82
|
+
The name of the schema file within the resources package
|
|
83
|
+
(:py:mod:`hpcflow.sdk.data`).
|
|
84
|
+
"""
|
|
85
|
+
with open_text_resource("hpcflow.sdk.data", filename) as fh:
|
|
86
|
+
schema_dat = fh.read()
|
|
87
|
+
return ValidaSchema.from_yaml(schema_dat)
|
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
"""Module containing code for generating numerical input and sequence values from various
|
|
2
|
+
class methods."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import TypeVar, Type, TYPE_CHECKING, overload, ClassVar, Any, cast
|
|
10
|
+
from typing_extensions import Self
|
|
11
|
+
import re
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
from hpcflow.sdk.core.utils import linspace_rect, process_string_nodes
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from ..app import BaseApp
|
|
19
|
+
from hpcflow.sdk.core.parameters import SchemaInput, Parameter
|
|
20
|
+
|
|
21
|
+
T = TypeVar("T", bound="ValuesMixin")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def process_demo_data_strings(app: BaseApp, value: Any) -> Any:
|
|
25
|
+
demo_pattern = re.compile(r"\<\<demo_data_file:(.*)\>\>")
|
|
26
|
+
|
|
27
|
+
def string_processor(str_in: str) -> str:
|
|
28
|
+
str_out = demo_pattern.sub(
|
|
29
|
+
repl=lambda x: str(app.get_demo_data_file_path(x[1])),
|
|
30
|
+
string=str_in,
|
|
31
|
+
)
|
|
32
|
+
return str_out
|
|
33
|
+
|
|
34
|
+
return process_string_nodes(value, string_processor)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _get_seed(seed: int | list[int] | None) -> int | list[int]:
|
|
38
|
+
"""For methods that use a random seed, if the seed is not set, set it randomly so it
|
|
39
|
+
can be recorded within the method args for reproducibility."""
|
|
40
|
+
return int(cast("int", np.random.SeedSequence().entropy)) if seed is None else seed
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ValuesMixin(ABC):
|
|
44
|
+
|
|
45
|
+
_app: ClassVar[BaseApp]
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
@abstractmethod
|
|
49
|
+
def _process_mixin_args(cls, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
|
|
50
|
+
|
|
51
|
+
@abstractmethod
|
|
52
|
+
def _remember_values_method_args(self, name: str, args: dict[str, Any]) -> Self: ...
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def _values_from_linear_space(
|
|
56
|
+
cls: Type[T], start: float, stop: float, num: int, **kwargs
|
|
57
|
+
) -> list[float]:
|
|
58
|
+
return np.linspace(start, stop, num=num, **kwargs).tolist()
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def _values_from_geometric_space(
|
|
62
|
+
cls, start: float, stop: float, num: int, **kwargs
|
|
63
|
+
) -> list[float]:
|
|
64
|
+
return np.geomspace(start, stop, num=num, **kwargs).tolist() # type: ignore # mypy bug for numpy~2.2.4 https://github.com/numpy/numpy/issues/27944
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def _values_from_log_space(
|
|
68
|
+
cls, start: float, stop: float, num: int, base: float = 10.0, **kwargs
|
|
69
|
+
) -> list[float]:
|
|
70
|
+
return np.logspace(start, stop, num=num, base=base, **kwargs).tolist() # type: ignore # mypy bug for numpy~2.2.4 https://github.com/numpy/numpy/issues/27944
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def _values_from_range(
|
|
74
|
+
cls, start: int | float, stop: int | float, step: int | float, **kwargs
|
|
75
|
+
) -> list[float]:
|
|
76
|
+
return np.arange(start, stop, step, **kwargs).tolist() # type: ignore # mypy bug for numpy~2.2.4 https://github.com/numpy/numpy/issues/27944
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def _values_from_file(cls, file_path: str | Path) -> list[str]:
|
|
80
|
+
with Path(file_path).open("rt") as fh:
|
|
81
|
+
return [line.strip() for line in fh.readlines()]
|
|
82
|
+
|
|
83
|
+
@classmethod
|
|
84
|
+
def _values_from_rectangle(
|
|
85
|
+
cls,
|
|
86
|
+
start: Sequence[float],
|
|
87
|
+
stop: Sequence[float],
|
|
88
|
+
num: Sequence[int],
|
|
89
|
+
coord: int | tuple[int, int] | None = None,
|
|
90
|
+
include: Sequence[str] | None = None,
|
|
91
|
+
**kwargs,
|
|
92
|
+
) -> list[float]:
|
|
93
|
+
vals = linspace_rect(start=start, stop=stop, num=num, include=include, **kwargs)
|
|
94
|
+
if coord is not None:
|
|
95
|
+
return vals[coord].tolist()
|
|
96
|
+
else:
|
|
97
|
+
return (vals.T).tolist() # type: ignore # mypy bug for numpy~2.2.4 https://github.com/numpy/numpy/issues/27944
|
|
98
|
+
|
|
99
|
+
@classmethod
|
|
100
|
+
def _values_from_numpy_distribution(
|
|
101
|
+
cls,
|
|
102
|
+
method_name: str,
|
|
103
|
+
shape: int | Sequence[int] | None,
|
|
104
|
+
seed: int | list[int],
|
|
105
|
+
**kwargs,
|
|
106
|
+
) -> list[float] | float:
|
|
107
|
+
kwargs["size"] = shape
|
|
108
|
+
rng = np.random.default_rng(seed)
|
|
109
|
+
method = getattr(rng, method_name)
|
|
110
|
+
out = method(**kwargs)
|
|
111
|
+
if shape is None:
|
|
112
|
+
return out
|
|
113
|
+
else:
|
|
114
|
+
return out.tolist() # type: ignore # mypy bug for numpy~2.2.4 https://github.com/numpy/numpy/issues/27944
|
|
115
|
+
|
|
116
|
+
@overload
|
|
117
|
+
@classmethod
|
|
118
|
+
def _values_from_uniform(
|
|
119
|
+
cls, shape: int | Sequence[int], **kwargs
|
|
120
|
+
) -> list[float]: ...
|
|
121
|
+
|
|
122
|
+
@overload
|
|
123
|
+
@classmethod
|
|
124
|
+
def _values_from_uniform(cls, shape: None, **kwargs) -> float: ...
|
|
125
|
+
|
|
126
|
+
@classmethod
|
|
127
|
+
def _values_from_uniform(
|
|
128
|
+
cls, shape: int | Sequence[int] | None, **kwargs
|
|
129
|
+
) -> float | list[float]:
|
|
130
|
+
return cls._values_from_numpy_distribution("uniform", **kwargs)
|
|
131
|
+
|
|
132
|
+
@classmethod
|
|
133
|
+
def _from_linear_space(
|
|
134
|
+
cls: Type[T],
|
|
135
|
+
start: float,
|
|
136
|
+
stop: float,
|
|
137
|
+
num: int,
|
|
138
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
139
|
+
path: str | None = None,
|
|
140
|
+
nesting_order: float = 0,
|
|
141
|
+
label: str | int | None = None,
|
|
142
|
+
value_class_method: str | None = None,
|
|
143
|
+
**kwargs,
|
|
144
|
+
) -> T:
|
|
145
|
+
"""
|
|
146
|
+
Build a sequence from a NumPy linear space.
|
|
147
|
+
"""
|
|
148
|
+
args = {"start": start, "stop": stop, "num": num, **kwargs}
|
|
149
|
+
obj = cls(
|
|
150
|
+
**cls._process_mixin_args(
|
|
151
|
+
cls._values_from_linear_space(**args),
|
|
152
|
+
parameter=parameter,
|
|
153
|
+
path=path,
|
|
154
|
+
nesting_order=nesting_order,
|
|
155
|
+
label=label,
|
|
156
|
+
value_class_method=value_class_method,
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
return obj._remember_values_method_args("from_linear_space", args)
|
|
160
|
+
|
|
161
|
+
@classmethod
|
|
162
|
+
def _from_geometric_space(
|
|
163
|
+
cls: Type[T],
|
|
164
|
+
start: float,
|
|
165
|
+
stop: float,
|
|
166
|
+
num: int,
|
|
167
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
168
|
+
path: str | None = None,
|
|
169
|
+
nesting_order: float = 0,
|
|
170
|
+
endpoint=True,
|
|
171
|
+
label: str | int | None = None,
|
|
172
|
+
value_class_method: str | None = None,
|
|
173
|
+
**kwargs,
|
|
174
|
+
) -> T:
|
|
175
|
+
"""
|
|
176
|
+
Build a sequence from a NumPy geometric space.
|
|
177
|
+
"""
|
|
178
|
+
args = {"start": start, "stop": stop, "num": num, "endpoint": endpoint, **kwargs}
|
|
179
|
+
obj = cls(
|
|
180
|
+
**cls._process_mixin_args(
|
|
181
|
+
cls._values_from_geometric_space(**args),
|
|
182
|
+
parameter=parameter,
|
|
183
|
+
path=path,
|
|
184
|
+
nesting_order=nesting_order,
|
|
185
|
+
label=label,
|
|
186
|
+
value_class_method=value_class_method,
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
return obj._remember_values_method_args("from_geometric_space", args)
|
|
190
|
+
|
|
191
|
+
@classmethod
|
|
192
|
+
def _from_log_space(
|
|
193
|
+
cls: Type[T],
|
|
194
|
+
start: float,
|
|
195
|
+
stop: float,
|
|
196
|
+
num: int,
|
|
197
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
198
|
+
path: str | None = None,
|
|
199
|
+
nesting_order: float = 0,
|
|
200
|
+
base=10.0,
|
|
201
|
+
endpoint=True,
|
|
202
|
+
label: str | int | None = None,
|
|
203
|
+
value_class_method: str | None = None,
|
|
204
|
+
**kwargs,
|
|
205
|
+
) -> T:
|
|
206
|
+
"""
|
|
207
|
+
Build a sequence from a NumPy logarithmic space.
|
|
208
|
+
"""
|
|
209
|
+
args = {
|
|
210
|
+
"start": start,
|
|
211
|
+
"stop": stop,
|
|
212
|
+
"num": num,
|
|
213
|
+
"endpoint": endpoint,
|
|
214
|
+
"base": base,
|
|
215
|
+
**kwargs,
|
|
216
|
+
}
|
|
217
|
+
obj = cls(
|
|
218
|
+
**cls._process_mixin_args(
|
|
219
|
+
cls._values_from_log_space(**args),
|
|
220
|
+
parameter=parameter,
|
|
221
|
+
path=path,
|
|
222
|
+
nesting_order=nesting_order,
|
|
223
|
+
label=label,
|
|
224
|
+
value_class_method=value_class_method,
|
|
225
|
+
)
|
|
226
|
+
)
|
|
227
|
+
return obj._remember_values_method_args("from_log_space", args)
|
|
228
|
+
|
|
229
|
+
@classmethod
|
|
230
|
+
def _from_range(
|
|
231
|
+
cls: Type[T],
|
|
232
|
+
start: float,
|
|
233
|
+
stop: float,
|
|
234
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
235
|
+
path: str | None = None,
|
|
236
|
+
nesting_order: float = 0,
|
|
237
|
+
step: int | float = 1,
|
|
238
|
+
label: str | int | None = None,
|
|
239
|
+
value_class_method: str | None = None,
|
|
240
|
+
**kwargs,
|
|
241
|
+
) -> T:
|
|
242
|
+
"""
|
|
243
|
+
Build a sequence from a range.
|
|
244
|
+
"""
|
|
245
|
+
args = {"start": start, "stop": stop, "step": step, **kwargs}
|
|
246
|
+
if isinstance(step, int):
|
|
247
|
+
values = cls._values_from_range(**args)
|
|
248
|
+
else:
|
|
249
|
+
# Use linspace for non-integer step, as recommended by Numpy:
|
|
250
|
+
values = cls._values_from_linear_space(
|
|
251
|
+
start=start,
|
|
252
|
+
stop=stop,
|
|
253
|
+
num=int((stop - start) / step),
|
|
254
|
+
endpoint=False,
|
|
255
|
+
**kwargs,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
obj = cls(
|
|
259
|
+
**cls._process_mixin_args(
|
|
260
|
+
values,
|
|
261
|
+
parameter=parameter,
|
|
262
|
+
path=path,
|
|
263
|
+
nesting_order=nesting_order,
|
|
264
|
+
label=label,
|
|
265
|
+
value_class_method=value_class_method,
|
|
266
|
+
)
|
|
267
|
+
)
|
|
268
|
+
return obj._remember_values_method_args("from_range", args)
|
|
269
|
+
|
|
270
|
+
@classmethod
|
|
271
|
+
def _from_file(
|
|
272
|
+
cls: Type[T],
|
|
273
|
+
file_path: str | Path,
|
|
274
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
275
|
+
path: str | None = None,
|
|
276
|
+
nesting_order: float = 0,
|
|
277
|
+
label: str | int | None = None,
|
|
278
|
+
value_class_method: str | None = None,
|
|
279
|
+
**kwargs,
|
|
280
|
+
) -> T:
|
|
281
|
+
"""
|
|
282
|
+
Build a sequence from a simple file.
|
|
283
|
+
"""
|
|
284
|
+
args = {"file_path": process_demo_data_strings(cls._app, file_path), **kwargs}
|
|
285
|
+
obj = cls(
|
|
286
|
+
**cls._process_mixin_args(
|
|
287
|
+
cls._values_from_file(**args),
|
|
288
|
+
parameter=parameter,
|
|
289
|
+
path=path,
|
|
290
|
+
nesting_order=nesting_order,
|
|
291
|
+
label=label,
|
|
292
|
+
value_class_method=value_class_method,
|
|
293
|
+
)
|
|
294
|
+
)
|
|
295
|
+
return obj._remember_values_method_args("from_file", args)
|
|
296
|
+
|
|
297
|
+
@classmethod
|
|
298
|
+
def _from_load_txt(
|
|
299
|
+
cls: Type[T],
|
|
300
|
+
file_path: str | Path,
|
|
301
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
302
|
+
path: str | None = None,
|
|
303
|
+
nesting_order: float = 0,
|
|
304
|
+
label: str | int | None = None,
|
|
305
|
+
value_class_method: str | None = None,
|
|
306
|
+
**kwargs,
|
|
307
|
+
) -> T:
|
|
308
|
+
"""
|
|
309
|
+
Load an array from a text file with Numpy.
|
|
310
|
+
"""
|
|
311
|
+
args = {"fname": process_demo_data_strings(cls._app, file_path), **kwargs}
|
|
312
|
+
obj = cls(
|
|
313
|
+
**cls._process_mixin_args(
|
|
314
|
+
np.loadtxt(**args),
|
|
315
|
+
parameter=parameter,
|
|
316
|
+
path=path,
|
|
317
|
+
nesting_order=nesting_order,
|
|
318
|
+
label=label,
|
|
319
|
+
value_class_method=value_class_method,
|
|
320
|
+
)
|
|
321
|
+
)
|
|
322
|
+
return obj._remember_values_method_args("_from_load_txt", args)
|
|
323
|
+
|
|
324
|
+
@classmethod
|
|
325
|
+
def _from_rectangle(
|
|
326
|
+
cls: Type[T],
|
|
327
|
+
start: Sequence[float],
|
|
328
|
+
stop: Sequence[float],
|
|
329
|
+
num: Sequence[int],
|
|
330
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
331
|
+
path: str | None = None,
|
|
332
|
+
coord: int | None = None,
|
|
333
|
+
include: list[str] | None = None,
|
|
334
|
+
nesting_order: float = 0,
|
|
335
|
+
label: str | int | None = None,
|
|
336
|
+
value_class_method: str | None = None,
|
|
337
|
+
**kwargs,
|
|
338
|
+
) -> T:
|
|
339
|
+
"""
|
|
340
|
+
Build a sequence from coordinates to cover the perimeter of a rectangle.
|
|
341
|
+
|
|
342
|
+
Parameters
|
|
343
|
+
----------
|
|
344
|
+
coord:
|
|
345
|
+
Which coordinate to use. Either 0, 1, or `None`, meaning each value will be
|
|
346
|
+
both coordinates.
|
|
347
|
+
include
|
|
348
|
+
If specified, include only the specified edges. Choose from "top", "right",
|
|
349
|
+
"bottom", "left".
|
|
350
|
+
"""
|
|
351
|
+
args = {
|
|
352
|
+
"start": start,
|
|
353
|
+
"stop": stop,
|
|
354
|
+
"num": num,
|
|
355
|
+
"coord": coord,
|
|
356
|
+
"include": include,
|
|
357
|
+
**kwargs,
|
|
358
|
+
}
|
|
359
|
+
obj = cls(
|
|
360
|
+
**cls._process_mixin_args(
|
|
361
|
+
cls._values_from_rectangle(**args),
|
|
362
|
+
parameter=parameter,
|
|
363
|
+
path=path,
|
|
364
|
+
nesting_order=nesting_order,
|
|
365
|
+
label=label,
|
|
366
|
+
value_class_method=value_class_method,
|
|
367
|
+
)
|
|
368
|
+
)
|
|
369
|
+
return obj._remember_values_method_args("from_rectangle", args)
|
|
370
|
+
|
|
371
|
+
@classmethod
|
|
372
|
+
def _from_uniform(
|
|
373
|
+
cls: Type[T],
|
|
374
|
+
shape: int | Sequence[int] | None,
|
|
375
|
+
low: float = 0.0,
|
|
376
|
+
high: float = 1.0,
|
|
377
|
+
seed: int | list[int] | None = None,
|
|
378
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
379
|
+
path: str | None = None,
|
|
380
|
+
nesting_order: float = 0,
|
|
381
|
+
label: str | int | None = None,
|
|
382
|
+
value_class_method: str | None = None,
|
|
383
|
+
**kwargs,
|
|
384
|
+
) -> T:
|
|
385
|
+
"""
|
|
386
|
+
Build a sequence from a uniform random number generator.
|
|
387
|
+
"""
|
|
388
|
+
args = {
|
|
389
|
+
"low": low,
|
|
390
|
+
"high": high,
|
|
391
|
+
"shape": shape,
|
|
392
|
+
"seed": _get_seed(seed),
|
|
393
|
+
**kwargs,
|
|
394
|
+
}
|
|
395
|
+
obj = cls(
|
|
396
|
+
**cls._process_mixin_args(
|
|
397
|
+
cls._values_from_numpy_distribution("uniform", **args),
|
|
398
|
+
parameter=parameter,
|
|
399
|
+
path=path,
|
|
400
|
+
nesting_order=nesting_order,
|
|
401
|
+
label=label,
|
|
402
|
+
value_class_method=value_class_method,
|
|
403
|
+
)
|
|
404
|
+
)
|
|
405
|
+
return obj._remember_values_method_args("from_uniform", args)
|
|
406
|
+
|
|
407
|
+
@classmethod
|
|
408
|
+
def _from_normal(
|
|
409
|
+
cls: Type[T],
|
|
410
|
+
shape: int | Sequence[int] | None,
|
|
411
|
+
loc: float = 0.0,
|
|
412
|
+
scale: float = 1.0,
|
|
413
|
+
seed: int | list[int] | None = None,
|
|
414
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
415
|
+
path: str | None = None,
|
|
416
|
+
nesting_order: float = 0,
|
|
417
|
+
label: str | int | None = None,
|
|
418
|
+
value_class_method: str | None = None,
|
|
419
|
+
**kwargs,
|
|
420
|
+
) -> T:
|
|
421
|
+
"""
|
|
422
|
+
Build a sequence from a uniform random number generator.
|
|
423
|
+
"""
|
|
424
|
+
args = {
|
|
425
|
+
"loc": loc,
|
|
426
|
+
"scale": scale,
|
|
427
|
+
"shape": shape,
|
|
428
|
+
"seed": _get_seed(seed),
|
|
429
|
+
**kwargs,
|
|
430
|
+
}
|
|
431
|
+
obj = cls(
|
|
432
|
+
**cls._process_mixin_args(
|
|
433
|
+
cls._values_from_numpy_distribution("normal", **args),
|
|
434
|
+
parameter=parameter,
|
|
435
|
+
path=path,
|
|
436
|
+
nesting_order=nesting_order,
|
|
437
|
+
label=label,
|
|
438
|
+
value_class_method=value_class_method,
|
|
439
|
+
)
|
|
440
|
+
)
|
|
441
|
+
return obj._remember_values_method_args("from_normal", args)
|
|
442
|
+
|
|
443
|
+
@classmethod
|
|
444
|
+
def _from_log_normal(
|
|
445
|
+
cls: Type[T],
|
|
446
|
+
shape: int | Sequence[int] | None,
|
|
447
|
+
mean: float = 0.0,
|
|
448
|
+
sigma: float = 1.0,
|
|
449
|
+
seed: int | list[int] | None = None,
|
|
450
|
+
parameter: Parameter | SchemaInput | str | None = None,
|
|
451
|
+
path: str | None = None,
|
|
452
|
+
nesting_order: float = 0,
|
|
453
|
+
label: str | int | None = None,
|
|
454
|
+
value_class_method: str | None = None,
|
|
455
|
+
**kwargs,
|
|
456
|
+
) -> T:
|
|
457
|
+
"""
|
|
458
|
+
Build a sequence from a log-normal random number generator.
|
|
459
|
+
"""
|
|
460
|
+
args = {
|
|
461
|
+
"mean": mean,
|
|
462
|
+
"sigma": sigma,
|
|
463
|
+
"shape": shape,
|
|
464
|
+
"seed": _get_seed(seed),
|
|
465
|
+
**kwargs,
|
|
466
|
+
}
|
|
467
|
+
obj = cls(
|
|
468
|
+
**cls._process_mixin_args(
|
|
469
|
+
cls._values_from_numpy_distribution("lognormal", **args),
|
|
470
|
+
parameter=parameter,
|
|
471
|
+
path=path,
|
|
472
|
+
nesting_order=nesting_order,
|
|
473
|
+
label=label,
|
|
474
|
+
value_class_method=value_class_method,
|
|
475
|
+
)
|
|
476
|
+
)
|
|
477
|
+
return obj._remember_values_method_args("from_log_normal", args)
|