sierra-research 1.3.6__py3-none-any.whl → 1.5.0__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.
Files changed (254) hide show
  1. sierra/__init__.py +3 -3
  2. sierra/core/__init__.py +3 -3
  3. sierra/core/batchroot.py +223 -0
  4. sierra/core/cmdline.py +681 -1057
  5. sierra/core/compare.py +11 -0
  6. sierra/core/config.py +96 -88
  7. sierra/core/engine.py +306 -0
  8. sierra/core/execenv.py +380 -0
  9. sierra/core/expdef.py +11 -0
  10. sierra/core/experiment/__init__.py +1 -0
  11. sierra/core/experiment/bindings.py +150 -101
  12. sierra/core/experiment/definition.py +414 -245
  13. sierra/core/experiment/spec.py +83 -85
  14. sierra/core/exproot.py +44 -0
  15. sierra/core/generators/__init__.py +10 -0
  16. sierra/core/generators/experiment.py +528 -0
  17. sierra/core/generators/generator_factory.py +138 -137
  18. sierra/core/graphs/__init__.py +23 -0
  19. sierra/core/graphs/bcbridge.py +94 -0
  20. sierra/core/graphs/heatmap.py +245 -324
  21. sierra/core/graphs/pathset.py +27 -0
  22. sierra/core/graphs/schema.py +77 -0
  23. sierra/core/graphs/stacked_line.py +341 -0
  24. sierra/core/graphs/summary_line.py +506 -0
  25. sierra/core/logging.py +3 -2
  26. sierra/core/models/__init__.py +3 -1
  27. sierra/core/models/info.py +19 -0
  28. sierra/core/models/interface.py +52 -122
  29. sierra/core/pipeline/__init__.py +2 -5
  30. sierra/core/pipeline/pipeline.py +228 -126
  31. sierra/core/pipeline/stage1/__init__.py +10 -0
  32. sierra/core/pipeline/stage1/pipeline_stage1.py +45 -31
  33. sierra/core/pipeline/stage2/__init__.py +10 -0
  34. sierra/core/pipeline/stage2/pipeline_stage2.py +8 -11
  35. sierra/core/pipeline/stage2/runner.py +401 -0
  36. sierra/core/pipeline/stage3/__init__.py +12 -0
  37. sierra/core/pipeline/stage3/gather.py +321 -0
  38. sierra/core/pipeline/stage3/pipeline_stage3.py +37 -84
  39. sierra/core/pipeline/stage4/__init__.py +12 -2
  40. sierra/core/pipeline/stage4/pipeline_stage4.py +36 -354
  41. sierra/core/pipeline/stage5/__init__.py +12 -0
  42. sierra/core/pipeline/stage5/pipeline_stage5.py +33 -208
  43. sierra/core/pipeline/yaml.py +48 -0
  44. sierra/core/plugin.py +529 -62
  45. sierra/core/proc.py +11 -0
  46. sierra/core/prod.py +11 -0
  47. sierra/core/ros1/__init__.py +5 -1
  48. sierra/core/ros1/callbacks.py +22 -21
  49. sierra/core/ros1/cmdline.py +59 -88
  50. sierra/core/ros1/generators.py +159 -175
  51. sierra/core/ros1/variables/__init__.py +3 -0
  52. sierra/core/ros1/variables/exp_setup.py +122 -116
  53. sierra/core/startup.py +106 -76
  54. sierra/core/stat_kernels.py +4 -5
  55. sierra/core/storage.py +13 -32
  56. sierra/core/trampoline.py +30 -0
  57. sierra/core/types.py +116 -71
  58. sierra/core/utils.py +103 -106
  59. sierra/core/variables/__init__.py +1 -1
  60. sierra/core/variables/base_variable.py +12 -17
  61. sierra/core/variables/batch_criteria.py +387 -481
  62. sierra/core/variables/builtin.py +135 -0
  63. sierra/core/variables/exp_setup.py +19 -39
  64. sierra/core/variables/population_size.py +72 -76
  65. sierra/core/variables/variable_density.py +44 -68
  66. sierra/core/vector.py +1 -1
  67. sierra/main.py +256 -88
  68. sierra/plugins/__init__.py +119 -0
  69. sierra/plugins/compare/__init__.py +14 -0
  70. sierra/plugins/compare/graphs/__init__.py +19 -0
  71. sierra/plugins/compare/graphs/cmdline.py +120 -0
  72. sierra/plugins/compare/graphs/comparator.py +291 -0
  73. sierra/plugins/compare/graphs/inter_controller.py +531 -0
  74. sierra/plugins/compare/graphs/inter_scenario.py +297 -0
  75. sierra/plugins/compare/graphs/namecalc.py +53 -0
  76. sierra/plugins/compare/graphs/outputroot.py +73 -0
  77. sierra/plugins/compare/graphs/plugin.py +147 -0
  78. sierra/plugins/compare/graphs/preprocess.py +172 -0
  79. sierra/plugins/compare/graphs/schema.py +37 -0
  80. sierra/plugins/engine/__init__.py +14 -0
  81. sierra/plugins/engine/argos/__init__.py +18 -0
  82. sierra/plugins/{platform → engine}/argos/cmdline.py +144 -151
  83. sierra/plugins/{platform/argos/variables → engine/argos/generators}/__init__.py +5 -0
  84. sierra/plugins/engine/argos/generators/engine.py +394 -0
  85. sierra/plugins/engine/argos/plugin.py +393 -0
  86. sierra/plugins/{platform/argos/generators → engine/argos/variables}/__init__.py +5 -0
  87. sierra/plugins/engine/argos/variables/arena_shape.py +183 -0
  88. sierra/plugins/engine/argos/variables/cameras.py +240 -0
  89. sierra/plugins/engine/argos/variables/constant_density.py +112 -0
  90. sierra/plugins/engine/argos/variables/exp_setup.py +82 -0
  91. sierra/plugins/{platform → engine}/argos/variables/physics_engines.py +83 -87
  92. sierra/plugins/engine/argos/variables/population_constant_density.py +178 -0
  93. sierra/plugins/engine/argos/variables/population_size.py +115 -0
  94. sierra/plugins/engine/argos/variables/population_variable_density.py +123 -0
  95. sierra/plugins/engine/argos/variables/rendering.py +108 -0
  96. sierra/plugins/engine/ros1gazebo/__init__.py +18 -0
  97. sierra/plugins/engine/ros1gazebo/cmdline.py +175 -0
  98. sierra/plugins/{platform/ros1robot → engine/ros1gazebo}/generators/__init__.py +5 -0
  99. sierra/plugins/engine/ros1gazebo/generators/engine.py +125 -0
  100. sierra/plugins/engine/ros1gazebo/plugin.py +404 -0
  101. sierra/plugins/engine/ros1gazebo/variables/__init__.py +15 -0
  102. sierra/plugins/engine/ros1gazebo/variables/population_size.py +214 -0
  103. sierra/plugins/engine/ros1robot/__init__.py +18 -0
  104. sierra/plugins/engine/ros1robot/cmdline.py +159 -0
  105. sierra/plugins/{platform/ros1gazebo → engine/ros1robot}/generators/__init__.py +4 -0
  106. sierra/plugins/engine/ros1robot/generators/engine.py +95 -0
  107. sierra/plugins/engine/ros1robot/plugin.py +410 -0
  108. sierra/plugins/{hpc/local → engine/ros1robot/variables}/__init__.py +5 -0
  109. sierra/plugins/engine/ros1robot/variables/population_size.py +146 -0
  110. sierra/plugins/execenv/__init__.py +11 -0
  111. sierra/plugins/execenv/hpc/__init__.py +18 -0
  112. sierra/plugins/execenv/hpc/adhoc/__init__.py +18 -0
  113. sierra/plugins/execenv/hpc/adhoc/cmdline.py +30 -0
  114. sierra/plugins/execenv/hpc/adhoc/plugin.py +131 -0
  115. sierra/plugins/execenv/hpc/cmdline.py +137 -0
  116. sierra/plugins/execenv/hpc/local/__init__.py +18 -0
  117. sierra/plugins/execenv/hpc/local/cmdline.py +31 -0
  118. sierra/plugins/execenv/hpc/local/plugin.py +145 -0
  119. sierra/plugins/execenv/hpc/pbs/__init__.py +18 -0
  120. sierra/plugins/execenv/hpc/pbs/cmdline.py +30 -0
  121. sierra/plugins/execenv/hpc/pbs/plugin.py +121 -0
  122. sierra/plugins/execenv/hpc/slurm/__init__.py +18 -0
  123. sierra/plugins/execenv/hpc/slurm/cmdline.py +30 -0
  124. sierra/plugins/execenv/hpc/slurm/plugin.py +133 -0
  125. sierra/plugins/execenv/prefectserver/__init__.py +18 -0
  126. sierra/plugins/execenv/prefectserver/cmdline.py +66 -0
  127. sierra/plugins/execenv/prefectserver/dockerremote/__init__.py +18 -0
  128. sierra/plugins/execenv/prefectserver/dockerremote/cmdline.py +66 -0
  129. sierra/plugins/execenv/prefectserver/dockerremote/plugin.py +132 -0
  130. sierra/plugins/execenv/prefectserver/flow.py +66 -0
  131. sierra/plugins/execenv/prefectserver/local/__init__.py +18 -0
  132. sierra/plugins/execenv/prefectserver/local/cmdline.py +29 -0
  133. sierra/plugins/execenv/prefectserver/local/plugin.py +133 -0
  134. sierra/plugins/{hpc/adhoc → execenv/robot}/__init__.py +1 -0
  135. sierra/plugins/execenv/robot/turtlebot3/__init__.py +18 -0
  136. sierra/plugins/execenv/robot/turtlebot3/plugin.py +204 -0
  137. sierra/plugins/expdef/__init__.py +14 -0
  138. sierra/plugins/expdef/json/__init__.py +14 -0
  139. sierra/plugins/expdef/json/plugin.py +504 -0
  140. sierra/plugins/expdef/xml/__init__.py +14 -0
  141. sierra/plugins/expdef/xml/plugin.py +386 -0
  142. sierra/{core/hpc → plugins/proc}/__init__.py +1 -1
  143. sierra/plugins/proc/collate/__init__.py +15 -0
  144. sierra/plugins/proc/collate/cmdline.py +47 -0
  145. sierra/plugins/proc/collate/plugin.py +271 -0
  146. sierra/plugins/proc/compress/__init__.py +18 -0
  147. sierra/plugins/proc/compress/cmdline.py +47 -0
  148. sierra/plugins/proc/compress/plugin.py +123 -0
  149. sierra/plugins/proc/decompress/__init__.py +18 -0
  150. sierra/plugins/proc/decompress/plugin.py +96 -0
  151. sierra/plugins/proc/imagize/__init__.py +15 -0
  152. sierra/plugins/proc/imagize/cmdline.py +49 -0
  153. sierra/plugins/proc/imagize/plugin.py +270 -0
  154. sierra/plugins/proc/modelrunner/__init__.py +16 -0
  155. sierra/plugins/proc/modelrunner/plugin.py +250 -0
  156. sierra/plugins/proc/statistics/__init__.py +15 -0
  157. sierra/plugins/proc/statistics/cmdline.py +64 -0
  158. sierra/plugins/proc/statistics/plugin.py +390 -0
  159. sierra/plugins/{hpc → prod}/__init__.py +1 -0
  160. sierra/plugins/prod/graphs/__init__.py +18 -0
  161. sierra/plugins/prod/graphs/cmdline.py +269 -0
  162. sierra/plugins/prod/graphs/collate.py +279 -0
  163. sierra/plugins/prod/graphs/inter/__init__.py +13 -0
  164. sierra/plugins/prod/graphs/inter/generate.py +83 -0
  165. sierra/plugins/prod/graphs/inter/heatmap.py +86 -0
  166. sierra/plugins/prod/graphs/inter/line.py +134 -0
  167. sierra/plugins/prod/graphs/intra/__init__.py +15 -0
  168. sierra/plugins/prod/graphs/intra/generate.py +202 -0
  169. sierra/plugins/prod/graphs/intra/heatmap.py +74 -0
  170. sierra/plugins/prod/graphs/intra/line.py +114 -0
  171. sierra/plugins/prod/graphs/plugin.py +103 -0
  172. sierra/plugins/prod/graphs/targets.py +63 -0
  173. sierra/plugins/prod/render/__init__.py +18 -0
  174. sierra/plugins/prod/render/cmdline.py +72 -0
  175. sierra/plugins/prod/render/plugin.py +282 -0
  176. sierra/plugins/storage/__init__.py +5 -0
  177. sierra/plugins/storage/arrow/__init__.py +18 -0
  178. sierra/plugins/storage/arrow/plugin.py +38 -0
  179. sierra/plugins/storage/csv/__init__.py +9 -0
  180. sierra/plugins/storage/csv/plugin.py +12 -5
  181. sierra/version.py +3 -2
  182. sierra_research-1.5.0.dist-info/METADATA +238 -0
  183. sierra_research-1.5.0.dist-info/RECORD +186 -0
  184. {sierra_research-1.3.6.dist-info → sierra_research-1.5.0.dist-info}/WHEEL +1 -2
  185. sierra/core/experiment/xml.py +0 -454
  186. sierra/core/generators/controller_generator_parser.py +0 -34
  187. sierra/core/generators/exp_creator.py +0 -351
  188. sierra/core/generators/exp_generators.py +0 -142
  189. sierra/core/graphs/scatterplot2D.py +0 -109
  190. sierra/core/graphs/stacked_line_graph.py +0 -249
  191. sierra/core/graphs/stacked_surface_graph.py +0 -220
  192. sierra/core/graphs/summary_line_graph.py +0 -369
  193. sierra/core/hpc/cmdline.py +0 -142
  194. sierra/core/models/graphs.py +0 -87
  195. sierra/core/pipeline/stage2/exp_runner.py +0 -286
  196. sierra/core/pipeline/stage3/imagizer.py +0 -149
  197. sierra/core/pipeline/stage3/run_collator.py +0 -317
  198. sierra/core/pipeline/stage3/statistics_calculator.py +0 -478
  199. sierra/core/pipeline/stage4/graph_collator.py +0 -319
  200. sierra/core/pipeline/stage4/inter_exp_graph_generator.py +0 -240
  201. sierra/core/pipeline/stage4/intra_exp_graph_generator.py +0 -317
  202. sierra/core/pipeline/stage4/model_runner.py +0 -168
  203. sierra/core/pipeline/stage4/rendering.py +0 -283
  204. sierra/core/pipeline/stage4/yaml_config_loader.py +0 -103
  205. sierra/core/pipeline/stage5/inter_scenario_comparator.py +0 -328
  206. sierra/core/pipeline/stage5/intra_scenario_comparator.py +0 -989
  207. sierra/core/platform.py +0 -493
  208. sierra/core/plugin_manager.py +0 -369
  209. sierra/core/root_dirpath_generator.py +0 -241
  210. sierra/plugins/hpc/adhoc/plugin.py +0 -125
  211. sierra/plugins/hpc/local/plugin.py +0 -81
  212. sierra/plugins/hpc/pbs/__init__.py +0 -9
  213. sierra/plugins/hpc/pbs/plugin.py +0 -126
  214. sierra/plugins/hpc/slurm/__init__.py +0 -9
  215. sierra/plugins/hpc/slurm/plugin.py +0 -130
  216. sierra/plugins/platform/__init__.py +0 -9
  217. sierra/plugins/platform/argos/__init__.py +0 -9
  218. sierra/plugins/platform/argos/generators/platform_generators.py +0 -383
  219. sierra/plugins/platform/argos/plugin.py +0 -337
  220. sierra/plugins/platform/argos/variables/arena_shape.py +0 -145
  221. sierra/plugins/platform/argos/variables/cameras.py +0 -243
  222. sierra/plugins/platform/argos/variables/constant_density.py +0 -136
  223. sierra/plugins/platform/argos/variables/exp_setup.py +0 -113
  224. sierra/plugins/platform/argos/variables/population_constant_density.py +0 -175
  225. sierra/plugins/platform/argos/variables/population_size.py +0 -102
  226. sierra/plugins/platform/argos/variables/population_variable_density.py +0 -132
  227. sierra/plugins/platform/argos/variables/rendering.py +0 -104
  228. sierra/plugins/platform/ros1gazebo/__init__.py +0 -9
  229. sierra/plugins/platform/ros1gazebo/cmdline.py +0 -213
  230. sierra/plugins/platform/ros1gazebo/generators/platform_generators.py +0 -137
  231. sierra/plugins/platform/ros1gazebo/plugin.py +0 -335
  232. sierra/plugins/platform/ros1gazebo/variables/__init__.py +0 -10
  233. sierra/plugins/platform/ros1gazebo/variables/population_size.py +0 -204
  234. sierra/plugins/platform/ros1robot/__init__.py +0 -9
  235. sierra/plugins/platform/ros1robot/cmdline.py +0 -175
  236. sierra/plugins/platform/ros1robot/generators/platform_generators.py +0 -112
  237. sierra/plugins/platform/ros1robot/plugin.py +0 -373
  238. sierra/plugins/platform/ros1robot/variables/__init__.py +0 -10
  239. sierra/plugins/platform/ros1robot/variables/population_size.py +0 -146
  240. sierra/plugins/robot/__init__.py +0 -9
  241. sierra/plugins/robot/turtlebot3/__init__.py +0 -9
  242. sierra/plugins/robot/turtlebot3/plugin.py +0 -194
  243. sierra_research-1.3.6.data/data/share/man/man1/sierra-cli.1 +0 -2349
  244. sierra_research-1.3.6.data/data/share/man/man7/sierra-examples.7 +0 -488
  245. sierra_research-1.3.6.data/data/share/man/man7/sierra-exec-envs.7 +0 -331
  246. sierra_research-1.3.6.data/data/share/man/man7/sierra-glossary.7 +0 -285
  247. sierra_research-1.3.6.data/data/share/man/man7/sierra-platforms.7 +0 -358
  248. sierra_research-1.3.6.data/data/share/man/man7/sierra-usage.7 +0 -725
  249. sierra_research-1.3.6.data/data/share/man/man7/sierra.7 +0 -78
  250. sierra_research-1.3.6.dist-info/METADATA +0 -500
  251. sierra_research-1.3.6.dist-info/RECORD +0 -133
  252. sierra_research-1.3.6.dist-info/top_level.txt +0 -1
  253. {sierra_research-1.3.6.dist-info → sierra_research-1.5.0.dist-info}/entry_points.txt +0 -0
  254. {sierra_research-1.3.6.dist-info → sierra_research-1.5.0.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,30 @@
1
+ #
2
+ # Copyright 2025 John Harwell, All rights reserved.
3
+ #
4
+ # SPDX-License Identifier: MIT
5
+ #
6
+
7
+ # Core packages
8
+ import typing as tp
9
+ import argparse
10
+
11
+ # 3rd party packages
12
+
13
+ # Project packages
14
+ from sierra.core import plugin as pm
15
+
16
+
17
+ def cmdline_parser(
18
+ plugin: str, parents: tp.List[argparse.ArgumentParser], stages: tp.List[int]
19
+ ) -> tp.Optional[argparse.ArgumentParser]:
20
+ """
21
+ Dispatches cmdline parser creation to selected plugin.
22
+
23
+ If the selected plugin does not define a cmdline, None is returned.
24
+ """
25
+ path = "{0}.cmdline".format(plugin)
26
+ if pm.module_exists(path):
27
+ module = pm.module_load_tiered(path)
28
+ return module.build(parents, stages).parser
29
+
30
+ return None
sierra/core/types.py CHANGED
@@ -1,14 +1,21 @@
1
1
  # Copyright 2021 John Harwell, All rights reserved.
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- """Custom types defined by SIERRA for more readable type hints.
5
-
6
- """
4
+ """Custom types defined by SIERRA for more readable type hints."""
7
5
  # Core packages
8
6
  import typing as tp
9
- from types import ModuleType
7
+ import sys
8
+ from types import ModuleType # noqa: F401 pylint: disable=unused-import
9
+ from dataclasses import dataclass
10
10
  import pathlib
11
11
 
12
+ # 2024-12-03 [JRH]: Once SIERRA moves to 3.10+ this (and many other instances)
13
+ # can be replaced unilaterally with tp.TypeAlias.
14
+ if sys.version_info < (3, 10):
15
+ from typing_extensions import TypeAlias
16
+ else:
17
+ from typing import TypeAlias
18
+
12
19
  # 3rd party packages
13
20
 
14
21
  # Project packages
@@ -17,71 +24,109 @@ import pathlib
17
24
  # Type Definitions
18
25
  ################################################################################
19
26
 
20
- Cmdopts = tp.Dict[str, tp.Any]
21
- YAMLDict = tp.Dict[str, tp.Any]
22
- SimpleDict = tp.Dict[str, tp.Union[str, int]]
23
-
24
- StrDict = tp.Dict[str, str]
25
- IntDict = tp.Dict[str, int]
26
- CLIArgSpec = tp.Dict[str, tp.Any]
27
- PathList = tp.List[pathlib.Path]
28
-
29
-
30
- class ShellCmdSpec():
31
- def __init__(self,
32
- cmd: str,
33
- shell: bool,
34
- wait: bool,
35
- env: tp.Optional[bool] = False) -> None:
36
- self.cmd = cmd
37
- self.shell = shell
38
- self.wait = wait
39
- self.env = env
40
-
41
-
42
- class YAMLConfigFileSpec():
43
- def __init__(self,
44
- main: str,
45
- controllers: str,
46
- models: str,
47
- stage5: str) -> None:
48
- self.main = main
49
- self.controllers = controllers
50
- self.models = models
51
- self.stage5 = stage5
52
-
53
-
54
- class ParsedNodefileSpec():
55
- def __init__(self,
56
- hostname: str,
57
- n_cores: int,
58
- login: str,
59
- port: int) -> None:
60
- self.hostname = hostname
61
- self.n_cores = n_cores
62
- self.login = login
63
- self.port = port
64
-
65
-
66
- class OSPackagesSpec():
67
- def __init__(self,
68
- kernel: str,
69
- name: str,
70
- pkgs: tp.Dict[str, bool]) -> None:
71
- self.kernel = kernel
72
- self.name = name
73
- self.pkgs = pkgs
74
-
75
-
76
- class StatisticsSpec():
77
- def __init__(self,
78
- exts: StrDict) -> None:
79
- self.exts = exts
80
-
81
-
82
- __api__ = [
83
- 'ShellCmdSpec',
84
- 'YAMLConfigFileSpec',
85
- 'ParsedNodefileSpec',
86
- 'OSPackagesSpec'
27
+ Cmdopts: TypeAlias = tp.Dict[str, tp.Any]
28
+ """Dictionary of parsed cmdline options."""
29
+
30
+ YAMLDict: TypeAlias = tp.Union[None, bool, str, float, int, tp.Dict[str, "YAMLDict"]]
31
+ """Parsed YAML dictionary."""
32
+
33
+ SimpleDict: TypeAlias = tp.Dict[str, tp.Union[str, int]]
34
+ """Dictionary str -> {str|int} mappings."""
35
+
36
+ # 2024-12-03 [JRH]: Once SIERRA moves to 3.10+ this (and many other instances)
37
+ # can be replaced with the '|' syntax, which is much nicer. Also the TypeAlias
38
+ # import from extensions won't be needed/will be part of the tying module.
39
+ JSON: TypeAlias = tp.Union[dict[str, "JSON"], list["JSON"], str, int, float, bool, None]
40
+ """Dictionary of parsed JSON."""
41
+
42
+ StrDict: TypeAlias = tp.Dict[str, str]
43
+ """Dictionary containing str -> str mappings."""
44
+
45
+ IntDict: TypeAlias = tp.Dict[str, int]
46
+ """Dictionary containing str -> int mappings."""
47
+
48
+ CLIArgSpec: TypeAlias = tp.Dict[str, tp.Any]
49
+ """Dictionary containing str -> anything mappings for parsing stuff from the
50
+ cmdline into components."""
51
+
52
+ PathList: TypeAlias = tp.List[pathlib.Path]
53
+ """List of paths."""
54
+
55
+
56
+ @dataclass
57
+ class ShellCmdSpec:
58
+ """
59
+ Dataclass containing info to run shell cmds.
60
+
61
+ Contains:
62
+
63
+ - The cmd to run. This should end in a ';' so that multiple commands can
64
+ be specified to run in sequence.
65
+
66
+ - Whether or not it should be strictly run in a shell via
67
+ ``shell=True``.
68
+
69
+ - Whether to wait for it to finish before returning.
70
+
71
+ - Whether to inherit the environment from the calling process.
72
+ """
73
+
74
+ cmd: str
75
+ shell: bool
76
+ wait: bool
77
+ env: tp.Optional[bool] = False
78
+
79
+
80
+ @dataclass
81
+ class YAMLConfigFileSpec:
82
+ """Spec for all the .yaml files available for :term:`Projects <Project>`."""
83
+
84
+ main: str
85
+ graphs: str
86
+ collate: str
87
+ controllers: str
88
+ scenarios: str
89
+ models: str
90
+
91
+
92
+ @dataclass
93
+ class ParsedNodefileSpec:
94
+ """Per line in a GNU parallel style nodefil, containing info a single resource."""
95
+
96
+ hostname: str
97
+ n_cores: int
98
+ login: str
99
+ port: int
100
+
101
+
102
+ @dataclass
103
+ class OSPackagesSpec:
104
+ """Info about what packages are required/optional on a given OS."""
105
+
106
+ kernel: str
107
+ name: str
108
+ pkgs: tp.Dict[str, bool]
109
+
110
+
111
+ @dataclass
112
+ class StatisticsSpec:
113
+ """Spec mapping file types of statistics to file extensions to contain said stats."""
114
+
115
+ exts: StrDict
116
+
117
+
118
+ __all__ = [
119
+ "ShellCmdSpec",
120
+ "YAMLConfigFileSpec",
121
+ "ParsedNodefileSpec",
122
+ "OSPackagesSpec",
123
+ "StatisticsSpec",
124
+ "Cmdopts",
125
+ "YAMLDict",
126
+ "SimpleDict",
127
+ "JSON",
128
+ "StrDict",
129
+ "IntDict",
130
+ "CLIArgSpec",
131
+ "PathList",
87
132
  ]
sierra/core/utils.py CHANGED
@@ -2,9 +2,7 @@
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
4
 
5
- """Miscellaneous bits used in mutiple places but that don't fit anywhere else.
6
-
7
- """
5
+ """Miscellaneous bits used in mutiple places but that don't fit anywhere else."""
8
6
 
9
7
  # Core packages
10
8
  import typing as tp
@@ -21,15 +19,16 @@ from retry import retry
21
19
 
22
20
  # Project packages
23
21
  from sierra.core.vector import Vector3D
24
- from sierra.core.experiment import xml, definition
22
+ from sierra.core.experiment import definition
25
23
  from sierra.core import types, config
26
- from sierra.core import plugin_manager as pm
24
+ from sierra.core import plugin as pm
27
25
 
28
26
 
29
- class ArenaExtent():
27
+ class ArenaExtent:
30
28
  """Representation of a 2D or 3D section/chunk/volume of the arena."""
29
+
31
30
  @staticmethod
32
- def from_corners(ll: Vector3D, ur: Vector3D) -> 'ArenaExtent':
31
+ def from_corners(ll: Vector3D, ur: Vector3D) -> "ArenaExtent":
33
32
  """Initialize an extent via LL and UR corners.
34
33
 
35
34
  As opposed to an origin and a set of dimensions.
@@ -64,11 +63,11 @@ class ArenaExtent():
64
63
  return self._origin
65
64
 
66
65
  def __str__(self) -> str:
67
- return str(self.dims) + '@' + str(self._origin)
66
+ return str(self.dims) + "@" + str(self._origin)
68
67
 
69
68
 
70
- class Sigmoid():
71
- """
69
+ class Sigmoid:
70
+ r"""
72
71
  Sigmoid activation function.
73
72
 
74
73
  .. math::
@@ -89,7 +88,7 @@ class Sigmoid():
89
88
  return 1.0 / (1 + np.exp(-self.x)) # type: ignore
90
89
 
91
90
 
92
- class ReLu():
91
+ class ReLu:
93
92
  r"""
94
93
  Rectified Linear Unit (ReLU) activation function.
95
94
 
@@ -118,8 +117,7 @@ def scale_minmax(minval: float, maxval: float, val: float) -> float:
118
117
  return -1.0 + (val - minval) * (1 - (-1)) / (maxval - minval)
119
118
 
120
119
 
121
- def dir_create_checked(path: tp.Union[pathlib.Path, str],
122
- exist_ok: bool) -> None:
120
+ def dir_create_checked(path: tp.Union[pathlib.Path, str], exist_ok: bool) -> None:
123
121
  """Create a directory idempotently.
124
122
 
125
123
  If the directory exists and it shouldn't, raise an error.
@@ -158,51 +156,46 @@ def path_exists(path: tp.Union[pathlib.Path, str]) -> bool:
158
156
  return max(set(res), key=res.count)
159
157
 
160
158
 
161
- def get_primary_axis(criteria,
162
- primary_axis_bc: tp.List,
163
- cmdopts: types.Cmdopts) -> int:
159
+ def get_primary_axis(criteria, primary_axis_bc: tp.List, cmdopts: types.Cmdopts) -> int:
164
160
  """
165
161
  Determine axis in a bivariate batch criteria is the primary axis.
166
162
 
167
163
  This is obtained on a per-query basis depending on the query context, or can
168
164
  be overriden on the cmdline.
169
165
  """
170
- if cmdopts['plot_primary_axis'] == 0:
166
+ if cmdopts["plot_primary_axis"] == 0:
171
167
  return 0
172
168
 
173
- if cmdopts['plot_primary_axis'] == 1:
169
+ if cmdopts["plot_primary_axis"] == 1:
174
170
  return 1
175
171
 
176
- if any(isinstance(criteria.criteria1, elt) for elt in primary_axis_bc):
172
+ if any(isinstance(criteria.criterias[1], elt) for elt in primary_axis_bc):
177
173
  return 0
178
174
 
179
175
  return 1
180
176
 
181
177
 
182
- def exp_range_calc(cmdopts: types.Cmdopts,
183
- root_dir: pathlib.Path,
184
- criteria) -> types.PathList:
178
+ def exp_range_calc(
179
+ exp_range: str, root_dir: pathlib.Path, dirnames: tp.List[str]
180
+ ) -> types.PathList:
185
181
  """
186
182
  Get the range of experiments to run/do stuff with. SUPER USEFUL.
187
183
  """
188
- exp_all = [root_dir / d for d in criteria.gen_exp_names(cmdopts)]
184
+ exp_all = [root_dir / d for d in dirnames]
189
185
 
190
- exp_range = cmdopts['exp_range']
186
+ if exp_range is not None:
187
+ min_exp = int(exp_range.split(":")[0])
188
+ max_exp = int(exp_range.split(":")[1])
189
+ assert (
190
+ min_exp <= max_exp
191
+ ), f"Min batch exp >= max batch exp({min_exp} vs. {max_exp})"
191
192
 
192
- if cmdopts['exp_range'] is not None:
193
- min_exp = int(exp_range.split(':')[0])
194
- max_exp = int(exp_range.split(':')[1])
195
- assert min_exp <= max_exp, \
196
- f"Min batch exp >= max batch exp({min_exp} vs. {max_exp})"
197
-
198
- return exp_all[min_exp: max_exp + 1]
193
+ return exp_all[min_exp : max_exp + 1]
199
194
 
200
195
  return exp_all
201
196
 
202
197
 
203
- def exp_include_filter(inc_spec: tp.Optional[str],
204
- target: tp.List,
205
- n_exps: int):
198
+ def exp_include_filter(inc_spec: tp.Optional[str], target: tp.List, n_exps: int):
206
199
  """Calculate which experiments to include in a calculation for something.
207
200
 
208
201
  Take a input list of experiment numbers to include, and returns the sublist
@@ -216,9 +209,9 @@ def exp_include_filter(inc_spec: tp.Optional[str],
216
209
  start = None
217
210
  end = None
218
211
  else:
219
- r = inc_spec.split(':')
212
+ r = inc_spec.split(":")
220
213
  start = int(r[0])
221
- if r[1] == '':
214
+ if r[1] == "":
222
215
  end = len(target)
223
216
  else:
224
217
  end = int(r[1])
@@ -229,8 +222,9 @@ def exp_include_filter(inc_spec: tp.Optional[str],
229
222
  return target[slice(start, end, None)]
230
223
 
231
224
 
232
- def bivar_exp_labels_calc(exp_dirs: types.PathList) -> tp.Tuple[tp.List[str],
233
- tp.List[str]]:
225
+ def bivar_exp_labels_calc(
226
+ exp_dirs: types.PathList,
227
+ ) -> tp.Tuple[tp.List[str], tp.List[str]]:
234
228
  """
235
229
  Calculate the labels for bivariant experiment graphs.
236
230
  """
@@ -241,7 +235,7 @@ def bivar_exp_labels_calc(exp_dirs: types.PathList) -> tp.Tuple[tp.List[str],
241
235
  xlabels_set = set()
242
236
  ylabels_set = set()
243
237
  for e in exp_dirs:
244
- pair = e.name.split('+')
238
+ pair = e.name.split("+")
245
239
  xlabels_set.add(pair[0])
246
240
  ylabels_set.add(pair[1])
247
241
 
@@ -251,27 +245,28 @@ def bivar_exp_labels_calc(exp_dirs: types.PathList) -> tp.Tuple[tp.List[str],
251
245
  return (xlabels, ylabels)
252
246
 
253
247
 
254
- def apply_to_expdef(var,
255
- exp_def: definition.XMLExpDef) -> tp.Tuple[tp.Optional[xml.TagRmList],
256
- tp.Optional[xml.TagAddList],
257
- tp.Optional[xml.AttrChangeSet]]:
248
+ def apply_to_expdef(var, exp_def: definition.BaseExpDef) -> tp.Tuple[
249
+ tp.Optional[definition.ElementRmList],
250
+ tp.Optional[definition.ElementAddList],
251
+ tp.Optional[definition.AttrChangeSet],
252
+ ]:
258
253
  """
259
- Apply a generated XML modifictions to an experiment definition.
254
+ Apply a generated expdef modifictions to an experiment definition.
260
255
 
261
256
  In this order:
262
257
 
263
- #. Remove existing XML tags
264
- #. Add new XML tags
265
- #. Change existing XML attributes
258
+ #. Remove existing expdef elements
259
+ #. Add new expdef elements
260
+ #. Change existing expdef element attributes
266
261
  """
267
- rmsl = var.gen_tag_rmlist() # type: tp.List[xml.TagRmList]
268
- addsl = var.gen_tag_addlist() # type: tp.List[xml.TagAddList]
269
- chgsl = var.gen_attr_changelist() # type: tp.List[xml.AttrChangeSet]
262
+ rmsl = var.gen_tag_rmlist() # type: tp.List[definition.ElementRmList]
263
+ addsl = var.gen_element_addlist() # type: tp.List[definition.ElementAddList]
264
+ chgsl = var.gen_attr_changelist() # type: tp.List[definition.AttrChangeSet]
270
265
 
271
266
  if rmsl:
272
267
  rms = rmsl[0]
273
268
  for r in rms:
274
- exp_def.tag_remove(r.path, r.tag)
269
+ exp_def.element_remove(r.path, r.tag)
275
270
  else:
276
271
  rms = None
277
272
 
@@ -279,7 +274,7 @@ def apply_to_expdef(var,
279
274
  adds = addsl[0]
280
275
  for a in adds:
281
276
  assert a.path is not None, "Can't add tag {a.tag} with no parent"
282
- exp_def.tag_add(a.path, a.tag, a.attr, a.allow_dup)
277
+ exp_def.element_add(a.path, a.tag, a.attr, a.allow_dup)
283
278
  else:
284
279
  adds = None
285
280
 
@@ -293,11 +288,13 @@ def apply_to_expdef(var,
293
288
  return rms, adds, chgs
294
289
 
295
290
 
296
- def pickle_modifications(adds: tp.Optional[xml.TagAddList],
297
- chgs: tp.Optional[xml.AttrChangeSet],
298
- path: pathlib.Path) -> None:
291
+ def pickle_modifications(
292
+ adds: tp.Optional[definition.ElementAddList],
293
+ chgs: tp.Optional[definition.AttrChangeSet],
294
+ path: pathlib.Path,
295
+ ) -> None:
299
296
  """
300
- After applying XML modifications, pickle changes for later retrieval.
297
+ After applying expdef modifications, pickle changes for later retrieval.
301
298
  """
302
299
  if adds is not None:
303
300
  adds.pickle(path)
@@ -306,29 +303,31 @@ def pickle_modifications(adds: tp.Optional[xml.TagAddList],
306
303
  chgs.pickle(path)
307
304
 
308
305
 
309
- def exp_template_path(cmdopts: types.Cmdopts,
310
- batch_input_root: pathlib.Path,
311
- dirname: str) -> pathlib.Path:
306
+ def exp_template_path(
307
+ cmdopts: types.Cmdopts, batch_input_root: pathlib.Path, dirname: str
308
+ ) -> pathlib.Path:
312
309
  """Calculate the path to the template input file in the batch experiment root.
313
310
 
314
- The file at this path will be Used as the de-facto template for generating
315
- per-run input files.
311
+ The file at this path will be Used as the de-facto template for generating
312
+ per-run input files.
316
313
 
317
314
  """
318
- template = pathlib.Path(cmdopts['template_input_file'])
315
+ template = pathlib.Path(cmdopts["expdef_template"])
319
316
  return batch_input_root / dirname / template.stem
320
317
 
321
318
 
322
- def get_n_robots(main_config: types.YAMLDict,
323
- cmdopts: types.Cmdopts,
324
- exp_input_root: pathlib.Path,
325
- exp_def: definition.XMLExpDef) -> int:
319
+ def get_n_agents(
320
+ main_config: types.YAMLDict,
321
+ cmdopts: types.Cmdopts,
322
+ exp_input_root: pathlib.Path,
323
+ exp_def: definition.BaseExpDef,
324
+ ) -> int:
326
325
  """
327
- Get the # robots used for a specific :term:`Experiment`.
326
+ Get the # agents used for a specific :term:`Experiment`.
328
327
  """
329
- module = pm.pipeline.get_plugin_module(cmdopts['platform'])
328
+ module1 = pm.pipeline.get_plugin_module(cmdopts["engine"])
330
329
 
331
- # Get # robots to send to shell cmds generator. We try:
330
+ # Get # agents to send to shell cmds generator. We try:
332
331
  #
333
332
  # 1. Getting it from the current experiment definition, which contains all
334
333
  # changes to the template input file EXCEPT those from batch criteria,
@@ -336,29 +335,28 @@ def get_n_robots(main_config: types.YAMLDict,
336
335
  #
337
336
  # 2. Getting it from the pickled experiment definition (i.e., from the
338
337
  # batch criteria which was used for this experiment).
339
- n_robots = module.population_size_from_def(exp_def,
340
- main_config,
341
- cmdopts)
342
- if n_robots <= 0:
343
- pkl_def = definition.unpickle(exp_input_root / config.kPickleLeaf)
344
- n_robots = module.population_size_from_pickle(pkl_def,
345
- main_config,
346
- cmdopts)
338
+ n_agents = module1.population_size_from_def(exp_def, main_config, cmdopts)
339
+
340
+ module2 = pm.pipeline.get_plugin_module(cmdopts["expdef"])
347
341
 
348
- assert n_robots > 0, "n_robots must be > 0"
342
+ if n_agents <= 0:
343
+ pkl_def = module2.unpickle(exp_input_root / config.kPickleLeaf)
344
+ n_agents = module1.population_size_from_pickle(pkl_def, main_config, cmdopts)
349
345
 
350
- return n_robots
346
+ assert n_agents > 0, "n_agents must be > 0"
347
+
348
+ return n_agents
351
349
 
352
350
 
353
351
  def df_fill(df: pd.DataFrame, policy: str) -> pd.DataFrame:
354
352
  """
355
353
  Fill missing cells in a dataframe according to the specified fill policy.
356
354
  """
357
- if policy == 'none':
355
+ if policy == "none":
358
356
  return df
359
- elif policy == 'pad':
360
- return df.fillna(method='pad')
361
- elif policy == 'zero':
357
+ elif policy == "pad":
358
+ return df.fillna(method="pad")
359
+ elif policy == "zero":
362
360
  return df.fillna(value=0)
363
361
  else:
364
362
  raise RuntimeError(f"Bad fill policy {policy}")
@@ -372,20 +370,19 @@ def pickle_dump(obj: object, f) -> None:
372
370
  def gen_scenario_spec(cmdopts: types.Cmdopts, **kwargs) -> tp.Dict[str, tp.Any]:
373
371
  # scenario is passed in kwargs during stage 5 (can't be passed via
374
372
  # --scenario in general )
375
- scenario = kwargs.get('scenario', cmdopts['scenario'])
376
-
377
- sgp = pm.module_load_tiered(project=cmdopts['project'],
378
- path='generators.scenario_generator_parser')
379
- kw = sgp.ScenarioGeneratorParser().to_dict(scenario)
373
+ scenario = kwargs.get("scenario", cmdopts["scenario"])
380
374
 
381
- return kw
375
+ module = pm.module_load_tiered(
376
+ project=cmdopts["project"], path="generators.scenario"
377
+ )
378
+ return module.to_dict(scenario)
382
379
 
383
380
 
384
381
  def sphinx_ref(ref: str) -> str:
385
382
  try:
386
383
  # This is kind of a hack...
387
384
  if __sphinx_build_man__: # type: ignore
388
- parts = ref.split('.')
385
+ parts = ref.split(".")
389
386
  stripped = parts[-1]
390
387
  return stripped[:-1]
391
388
 
@@ -395,25 +392,25 @@ def sphinx_ref(ref: str) -> str:
395
392
  return ref
396
393
 
397
394
 
398
- utf8open = functools.partial(open, encoding='UTF-8')
395
+ utf8open = functools.partial(open, encoding="UTF-8")
399
396
  """
400
397
  Explictly specify that the type of file being opened is UTF-8, which is should
401
398
  be for almost everything in SIERRA.
402
399
  """
403
400
 
404
- __api__ = [
405
- 'ArenaExtent',
406
- 'Sigmoid',
407
- 'ReLu',
408
- 'dir_create_checked',
409
- 'path_exists',
410
- 'get_primary_axis',
411
- 'exp_range_calc',
412
- 'exp_include_filter',
413
- 'apply_to_expdef',
414
- 'pickle_modifications',
415
- 'exp_template_path',
416
- 'get_n_robots',
417
- 'df_fill',
418
- 'utf8open',
401
+ __all__ = [
402
+ "ArenaExtent",
403
+ "Sigmoid",
404
+ "ReLu",
405
+ "dir_create_checked",
406
+ "path_exists",
407
+ "get_primary_axis",
408
+ "exp_range_calc",
409
+ "exp_include_filter",
410
+ "apply_to_expdef",
411
+ "pickle_modifications",
412
+ "exp_template_path",
413
+ "get_n_agents",
414
+ "df_fill",
415
+ "utf8open",
419
416
  ]
@@ -1,4 +1,4 @@
1
1
  # Copyright 2018 John Harwell, All rights reserved.
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- from sierra.core.variables import batch_criteria
4
+ """Container module for things related to variables."""