sierra-research 1.3.11__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.11.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 -251
  191. sierra/core/graphs/stacked_surface_graph.py +0 -220
  192. sierra/core/graphs/summary_line_graph.py +0 -371
  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 -320
  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.11.data/data/share/man/man1/sierra-cli.1 +0 -2349
  244. sierra_research-1.3.11.data/data/share/man/man7/sierra-examples.7 +0 -508
  245. sierra_research-1.3.11.data/data/share/man/man7/sierra-exec-envs.7 +0 -331
  246. sierra_research-1.3.11.data/data/share/man/man7/sierra-glossary.7 +0 -285
  247. sierra_research-1.3.11.data/data/share/man/man7/sierra-platforms.7 +0 -358
  248. sierra_research-1.3.11.data/data/share/man/man7/sierra-usage.7 +0 -729
  249. sierra_research-1.3.11.data/data/share/man/man7/sierra.7 +0 -78
  250. sierra_research-1.3.11.dist-info/METADATA +0 -492
  251. sierra_research-1.3.11.dist-info/RECORD +0 -133
  252. sierra_research-1.3.11.dist-info/top_level.txt +0 -1
  253. {sierra_research-1.3.11.dist-info → sierra_research-1.5.0.dist-info}/entry_points.txt +0 -0
  254. {sierra_research-1.3.11.dist-info → sierra_research-1.5.0.dist-info/licenses}/LICENSE +0 -0
@@ -1,34 +0,0 @@
1
- # Copyright 2018 London Lowmanstone, John Harwell, All rights reserved.
2
- #
3
- # SPDX-License-Identifier: MIT
4
- #
5
- import typing as tp
6
- import argparse
7
-
8
-
9
- class ControllerGeneratorParser:
10
- """Parse the controller generator specification from cmdline arguments.
11
-
12
- Used later to create generator classes to make modifications to template
13
- input files.
14
-
15
- Format for pair is: ``<category>.<controller>``.
16
-
17
- Return:
18
-
19
- Parsed controller specification, the generator is missing from the command
20
- line altogether; this can occur if the user is only running stage [4,5],
21
- and is not an error. In that case, None is returned.
22
-
23
- """
24
-
25
- def __call__(self, args: argparse.Namespace) -> tp.Optional[str]:
26
- if args.controller is None:
27
- return None
28
-
29
- return args.controller # type: ignore
30
-
31
-
32
- __api__ = [
33
- 'ControllerGeneratorParser'
34
- ]
@@ -1,351 +0,0 @@
1
- # Copyright 2018 John Harwell, All rights reserved.
2
- #
3
- # SPDX-License-Identifier: MIT
4
- """Experiment creation classes.
5
-
6
- Experiment creation takes an experiment definition `generated` by classes in
7
- ``exp_generators.py`` and writes the experiment to the filesystem.
8
-
9
- """
10
-
11
- # Core packages
12
- import os
13
- import random
14
- import copy
15
- import logging
16
- import time
17
- import pickle
18
- import pathlib
19
-
20
- # 3rd party packages
21
-
22
- # Project packages
23
- from sierra.core.variables import batch_criteria as bc
24
- from sierra.core import config, utils, types, platform
25
- import sierra.core.plugin_manager as pm
26
- from sierra.core.generators.exp_generators import BatchExpDefGenerator
27
- from sierra.core.experiment import bindings, definition
28
-
29
-
30
- class ExpCreator:
31
- """Instantiate a generated experiment from an experiment definition.
32
-
33
- Takes generated :term:`Experiment` definitions and writes them to the
34
- filesystem.
35
-
36
- Attributes:
37
-
38
- template_ipath: Absolute path to the template XML configuration file.
39
-
40
- exp_input_root: Absolute path to experiment directory where generated
41
- XML input files for this experiment should be written.
42
-
43
- exp_output_root: Absolute path to root directory for run outputs
44
- for this experiment.
45
-
46
- cmdopts: Dictionary containing parsed cmdline options.
47
-
48
- """
49
-
50
- def __init__(self,
51
- cmdopts: types.Cmdopts,
52
- criteria: bc.BatchCriteria,
53
- template_ipath: pathlib.Path,
54
- exp_input_root: pathlib.Path,
55
- exp_output_root: pathlib.Path,
56
- exp_num: int) -> None:
57
-
58
- # filename of template file, sans extension and parent directory path
59
- self.template_stem = template_ipath.resolve().stem
60
-
61
- # where the generated config and command files should be stored
62
- self.exp_input_root = exp_input_root
63
-
64
- # where experimental outputs should be stored
65
- self.exp_output_root = exp_output_root
66
-
67
- self.cmdopts = cmdopts
68
- self.criteria = criteria
69
- self.exp_num = exp_num
70
- self.logger = logging.getLogger(__name__)
71
-
72
- # If random seeds where previously generated, use them if configured
73
- self.seeds_fpath = self.exp_input_root / config.kRandomSeedsLeaf
74
- self.preserve_seeds = self.cmdopts['preserve_seeds']
75
- self.random_seeds = None
76
-
77
- if self.preserve_seeds:
78
- if utils.path_exists(self.seeds_fpath):
79
- with open(self.seeds_fpath, 'rb') as f:
80
- self.random_seeds = pickle.load(f)
81
-
82
- if self.random_seeds is not None:
83
- if len(self.random_seeds) == self.cmdopts['n_runs']:
84
- self.logger.debug("Using existing random seeds for experiment")
85
- elif len(self.random_seeds) != self.cmdopts['n_runs']:
86
- # OK to overwrite the saved random seeds--they changed the
87
- # experiment definition.
88
- self.logger.warning(("Experiment definition changed: # random "
89
- "seeds (% s) != --n-runs (%s): create new "
90
- "seeds"),
91
- len(self.random_seeds),
92
- self.cmdopts['n_runs'])
93
- self.preserve_seeds = False
94
-
95
- if not self.preserve_seeds or self.random_seeds is None:
96
- self.logger.debug("Generating new random seeds for experiment")
97
- self.random_seeds = random.sample(range(0, int(time.time())),
98
- self.cmdopts["n_runs"])
99
-
100
- # where the commands file will be stored
101
- self.commands_fpath = self.exp_input_root / \
102
- config.kGNUParallel['cmdfile_stem']
103
-
104
- def from_def(self, exp_def: definition.XMLExpDef):
105
- """Create all experimental runs by writing input files to filesystem.
106
-
107
- The passed :class:`~sierra.core.experiment.definition.XMLExpDef` object
108
- contains all changes that should be made to all runs in the
109
- experiment. Additional changes to create a set of unique runs from which
110
- distributions of system behavior can be meaningfully computed post-hoc
111
- are added.
112
-
113
- """
114
- # Clear out commands file if it exists
115
- configurer = platform.ExpConfigurer(self.cmdopts)
116
- commands_fpath = self.commands_fpath.with_suffix(
117
- config.kGNUParallel['cmdfile_ext'])
118
- if configurer.cmdfile_paradigm() == 'per-exp' and utils.path_exists(commands_fpath):
119
- commands_fpath.unlink()
120
-
121
- n_robots = utils.get_n_robots(self.criteria.main_config,
122
- self.cmdopts,
123
- self.exp_input_root,
124
- exp_def)
125
- generator = platform.ExpRunShellCmdsGenerator(self.cmdopts,
126
- self.criteria,
127
- n_robots,
128
- self.exp_num)
129
-
130
- # Create all experimental runs
131
- for run_num in range(self.cmdopts['n_runs']):
132
- per_run = copy.deepcopy(exp_def)
133
- self._create_exp_run(per_run, generator, run_num)
134
-
135
- # Perform experiment level configuration AFTER all runs have been
136
- # generated in the experiment, in case the configuration depends on the
137
- # generated launch files.
138
- platform.ExpConfigurer(self.cmdopts).for_exp(self.exp_input_root)
139
-
140
- # Save seeds
141
- if not utils.path_exists(self.seeds_fpath) or not self.preserve_seeds:
142
- if utils.path_exists(self.seeds_fpath):
143
- os.remove(self.seeds_fpath)
144
- with open(self.seeds_fpath, 'ab') as f:
145
- utils.pickle_dump(self.random_seeds, f)
146
-
147
- def _create_exp_run(self,
148
- run_exp_def: definition.XMLExpDef,
149
- cmds_generator,
150
- run_num: int) -> None:
151
- run_output_dir = "{0}_run{1}_output".format(self.template_stem, run_num)
152
-
153
- # If the project defined per-run configuration, apply
154
- # it. Otherwise, just apply the configuration in the SIERRA core.
155
- per_run = pm.module_load_tiered(project=self.cmdopts['project'],
156
- path='generators.exp_generators')
157
-
158
- run_output_root = self.exp_output_root / run_output_dir
159
- stem_path = self._get_launch_file_stempath(run_num)
160
-
161
- per_run.ExpRunDefUniqueGenerator(run_num,
162
- run_output_root,
163
- stem_path,
164
- self.random_seeds[run_num],
165
- self.cmdopts).generate(run_exp_def)
166
-
167
- # Write out the experimental run launch file
168
- run_exp_def.write(stem_path)
169
-
170
- # Perform any necessary programmatic (i.e., stuff you can do in python
171
- # and don't need a shell for) per-run configuration.
172
- configurer = platform.ExpConfigurer(self.cmdopts)
173
- configurer.for_exp_run(self.exp_input_root, run_output_root)
174
-
175
- ext = config.kGNUParallel['cmdfile_ext']
176
- if configurer.cmdfile_paradigm() == 'per-exp':
177
- # Update GNU Parallel commands file with the command for the
178
- # configured experimental run.
179
- fpath = f"{self.commands_fpath}{ext}"
180
- with utils.utf8open(fpath, 'a') as cmds_file:
181
- self._update_cmds_file(cmds_file,
182
- cmds_generator,
183
- 'per-exp',
184
- run_num,
185
- self._get_launch_file_stempath(run_num),
186
- 'slave')
187
- elif configurer.cmdfile_paradigm() == 'per-run':
188
- # Write new GNU Parallel commands file with the commends for the
189
- # experimental run.
190
- master_fpath = f"{self.commands_fpath}_run{run_num}_master{ext}"
191
- slave_fpath = f"{self.commands_fpath}_run{run_num}_slave{ext}"
192
-
193
- self.logger.trace("Updating slave cmdfile %s", # type: ignore
194
- slave_fpath)
195
- with utils.utf8open(slave_fpath, 'w') as cmds_file:
196
- self._update_cmds_file(cmds_file,
197
- cmds_generator,
198
- 'per-run',
199
- run_num,
200
- self._get_launch_file_stempath(run_num),
201
- 'slave')
202
-
203
- self.logger.trace("Updating master cmdfile %s", # type: ignore
204
- master_fpath)
205
- with utils.utf8open(master_fpath, 'w') as cmds_file:
206
- self._update_cmds_file(cmds_file,
207
- cmds_generator,
208
- 'per-run',
209
- run_num,
210
- self._get_launch_file_stempath(run_num),
211
- 'master')
212
-
213
- def _get_launch_file_stempath(self, run_num: int) -> pathlib.Path:
214
- """File is named as ``<template input file stem>_run<run_num>``.
215
- """
216
- leaf = "{0}_run{1}".format(self.template_stem, run_num)
217
- return self.exp_input_root / leaf
218
-
219
- def _update_cmds_file(self,
220
- cmds_file,
221
- cmds_generator: bindings.IExpRunShellCmdsGenerator,
222
- paradigm: str,
223
- run_num: int,
224
- launch_stem_path: pathlib.Path,
225
- for_host: str) -> None:
226
- """Add command to launch a given experimental run to the command file.
227
-
228
- """
229
- pre_specs = cmds_generator.pre_run_cmds(for_host,
230
- launch_stem_path,
231
- run_num)
232
- assert all(spec.shell for spec in pre_specs),\
233
- "All pre-exp commands are run in a shell"
234
- pre_cmds = [spec.cmd for spec in pre_specs]
235
- self.logger.trace("Pre-experiment cmds: %s", pre_cmds) # type: ignore
236
-
237
- exec_specs = cmds_generator.exec_run_cmds(for_host,
238
- launch_stem_path,
239
- run_num)
240
- assert all(spec.shell for spec in exec_specs),\
241
- "All exec-exp commands are run in a shell"
242
- exec_cmds = [spec.cmd for spec in exec_specs]
243
- self.logger.trace("Exec-experiment cmds: %s", exec_cmds) # type: ignore
244
-
245
- post_specs = cmds_generator.post_run_cmds(for_host)
246
- assert all(spec.shell for spec in post_specs),\
247
- "All post-exp commands are run in a shell"
248
- post_cmds = [spec.cmd for spec in post_specs]
249
- self.logger.trace("Post-experiment cmds: %s", post_cmds) # type: ignore
250
-
251
- if len(pre_cmds + exec_cmds + post_cmds) == 0:
252
- self.logger.debug("Skipping writing %s cmds file: no cmds",
253
- for_host)
254
- return
255
-
256
- # If there is 1 cmdfile per experiment, then the pre- and post-exec cmds
257
- # need to be prepended and appended to the exec cmds on a per-line
258
- # basis. If there is 1 cmdfile per experimental run, then its the same
259
- # thing, BUT we need to break the exec cmds over multiple lines in the
260
- # cmdfile.
261
- if paradigm == 'per-exp':
262
- line = ' '.join(pre_cmds + exec_cmds + post_cmds) + '\n'
263
- cmds_file.write(line)
264
- elif paradigm == 'per-run':
265
- for e in exec_cmds:
266
- line = ' '.join(pre_cmds + [e] + post_cmds) + '\n'
267
- cmds_file.write(line)
268
- else:
269
- raise ValueError(f"Bad paradigm {paradigm}")
270
-
271
-
272
- class BatchExpCreator:
273
- """Instantiate a :term:`Batch Experiment`.
274
-
275
- Calls :class:`~sierra.core.generators.exp_creator.ExpCreator` on each
276
- experimental definition in the batch
277
-
278
- Attributes:
279
-
280
- batch_config_template: Absolute path to the root template XML
281
- configuration file.
282
-
283
- batch_input_root: Root directory for all generated XML input files all
284
- experiments should be stored (relative to current dir
285
- or absolute). Each experiment will get a directory
286
- within this root to store the xml input files for the
287
- experimental runs comprising an experiment; directory
288
- name determined by the batch criteria used.
289
-
290
- batch_output_root: Root directory for all experiment outputs. Each
291
- experiment will get a directory 'exp<n>' in this
292
- directory for its outputs.
293
-
294
- criteria: :class:`~sierra.core.variables.batch_criteria.BatchCriteria`
295
- derived object instance created from cmdline definition.
296
-
297
- """
298
-
299
- def __init__(self,
300
- criteria: bc.BatchCriteria,
301
- cmdopts: types.Cmdopts) -> None:
302
-
303
- self.batch_config_template = pathlib.Path(cmdopts['template_input_file'])
304
- self.batch_input_root = pathlib.Path(cmdopts['batch_input_root'])
305
- self.batch_output_root = pathlib.Path(cmdopts['batch_output_root'])
306
- self.criteria = criteria
307
- self.cmdopts = cmdopts
308
- self.logger = logging.getLogger(__name__)
309
-
310
- def create(self, generator: BatchExpDefGenerator) -> None:
311
- utils.dir_create_checked(self.batch_input_root,
312
- self.cmdopts['exp_overwrite'])
313
-
314
- # Scaffold the batch experiment, creating experiment directories and
315
- # writing template XML input files for each experiment in the batch with
316
- # changes from the batch criteria added.
317
- exp_def = definition.XMLExpDef(input_fpath=self.batch_config_template,
318
- write_config=None)
319
-
320
- self.criteria.scaffold_exps(exp_def, self.cmdopts)
321
-
322
- # Pickle experiment definitions in the actual batch experiment
323
- # directory for later retrieval.
324
- self.criteria.pickle_exp_defs(self.cmdopts)
325
-
326
- # Run batch experiment generator (must be after scaffolding so the
327
- # per-experiment template files are in place).
328
- defs = generator.generate_defs()
329
-
330
- assert len(defs) > 0, "No XML modifications generated?"
331
-
332
- for i, defi in enumerate(defs):
333
- self.logger.debug(
334
- "Applying generated scenario+controller changes to exp%s",
335
- i)
336
- expi = self.criteria.gen_exp_names(self.cmdopts)[i]
337
- exp_output_root = self.batch_output_root / expi
338
- exp_input_root = self.batch_input_root / expi
339
-
340
- ExpCreator(self.cmdopts,
341
- self.criteria,
342
- self.batch_config_template,
343
- exp_input_root,
344
- exp_output_root,
345
- i).from_def(defi)
346
-
347
-
348
- __api__ = [
349
- 'ExpCreator',
350
- 'BatchExpCreator',
351
- ]
@@ -1,142 +0,0 @@
1
- # Copyright 2018 London Lowmanstone, John Harwell, All rights reserved.
2
- #
3
- # SPDX-License-Identifier: MIT
4
- """Experiment generation classes.
5
-
6
- Experiment generation modifies the
7
- :class:`~sierra.core.experiment.definition.XMLExpDef` object built from
8
- the specified batch criteria as follows:
9
-
10
- - Platform-specific modifications common to all batch experiments
11
- - Project-specific modifications common to all batch experiments
12
- - Modifications generated by the selected controller+scenario
13
-
14
- NOTE:: Generated definitions from batch criteria are not handled here; they are
15
- already generated to scaffold the batch experiment when experiment
16
- generation is run.
17
-
18
- """
19
-
20
- # Core packages
21
- import typing as tp
22
- import logging
23
- import pathlib
24
-
25
- # 3rd party packages
26
-
27
- # Project packages
28
- import sierra.core.generators.generator_factory as gf
29
- from sierra.core.experiment import spec, definition
30
- from sierra.core import types
31
- import sierra.core.variables.batch_criteria as bc
32
-
33
-
34
- class BatchExpDefGenerator:
35
- """Generate experiment definitions for a :term:`Batch Experiment`.
36
-
37
- Does not create the batch experiment after generation.
38
-
39
- Attributes:
40
-
41
- batch_config_template: Absolute path to the root template XML
42
- configuration file.
43
-
44
- batch_input_root: Root directory for all generated XML input files all
45
- experiments should be stored (relative to current
46
- dir or absolute). Each experiment will get a
47
- directory within this root to store the xml input
48
- files for the set of :term:`Experimental Runs
49
- <Experimental Run>` comprising an
50
- :term:`Experiment`; directory name determined by
51
- the batch criteria used.
52
-
53
- batch_output_root: Root directory for all experiment outputs (relative
54
- to current dir or absolute). Each experiment will get
55
- a directory 'exp<n>' in this directory for its
56
- outputs.
57
-
58
- criteria: :class:`~sierra.core.variables.batch_criteria.BatchCriteria`
59
- derived object instance created from cmdline definition.
60
-
61
- controller_name: Name of controller generator to use.
62
-
63
- scenario_basename: Name of scenario generator to use.
64
-
65
- """
66
-
67
- def __init__(self,
68
- criteria: bc.IConcreteBatchCriteria,
69
- controller_name: str,
70
- scenario_basename: str,
71
- cmdopts: types.Cmdopts) -> None:
72
- self.batch_config_template = pathlib.Path(cmdopts['template_input_file'])
73
-
74
- assert self.batch_config_template.is_file(), \
75
- "'{0}' is not a valid file".format(self.batch_config_template)
76
-
77
- self.exp_template_stem = self.batch_config_template.stem
78
- self.batch_config_extension = None
79
-
80
- self.batch_input_root = pathlib.Path(cmdopts['batch_input_root'])
81
- self.batch_output_root = pathlib.Path(cmdopts['batch_output_root'])
82
-
83
- self.controller_name = controller_name
84
- self.scenario_basename = scenario_basename
85
- self.criteria = criteria
86
- self.cmdopts = cmdopts
87
- self.logger = logging.getLogger(__name__)
88
-
89
- def generate_defs(self) -> tp.List[definition.XMLExpDef]:
90
- """Generate and return the batch experiment definition.
91
-
92
- Returns:
93
-
94
- A list of experiment definitions (one for each experiment in the
95
- batch).
96
-
97
- """
98
- scaffold_spec = spec.scaffold_spec_factory(self.criteria)
99
-
100
- # Create and run generators
101
- defs = []
102
- for i in range(0, scaffold_spec.n_exps):
103
- generator = self._create_exp_generator(i)
104
- self.logger.debug(("Generating scenario+controller changes from "
105
- "generator '%s' for exp%s"),
106
- self.cmdopts['joint_generator'],
107
- i)
108
- defs.append(generator.generate())
109
-
110
- return defs
111
-
112
- def _create_exp_generator(self, exp_num: int):
113
- """
114
- Create the joint scenario+controller generator from command line definitions.
115
-
116
- Arguments:
117
-
118
- exp_num: Experiment number in the batch
119
- """
120
-
121
- exp_spec = spec.ExperimentSpec(self.criteria, exp_num, self.cmdopts)
122
- template_fpath = exp_spec.exp_input_root / self.exp_template_stem
123
- config_root = pathlib.Path(self.cmdopts['project_config_root'])
124
- scenario = gf.scenario_generator_create(controller=self.controller_name,
125
- exp_spec=exp_spec,
126
- template_input_file=template_fpath,
127
- cmdopts=self.cmdopts)
128
-
129
- controller = gf.controller_generator_create(controller=self.controller_name,
130
- config_root=config_root,
131
- cmdopts=self.cmdopts,
132
- exp_spec=exp_spec)
133
-
134
- generator = gf.joint_generator_create(scenario=scenario,
135
- controller=controller)
136
- self.cmdopts['joint_generator'] = generator.joint_name
137
- return generator
138
-
139
-
140
- __api__ = [
141
- 'BatchExpDefGenerator',
142
- ]
@@ -1,109 +0,0 @@
1
- # Copyright 2020 John Harwell, All rights reserved.
2
- #
3
- # SPDX-License-Identifier: MIT
4
- #
5
-
6
- # Core packages
7
- import logging
8
- import pathlib
9
-
10
- # 3rd party packages
11
- import numpy as np
12
- import sympy
13
- import matplotlib.pyplot as plt
14
-
15
- # Project packages
16
- from sierra.core import storage, config, utils
17
-
18
-
19
- class Scatterplot2D:
20
- """Generates a 2D scatterplot of rows vs. colums (X vs. Y) from a CSV.
21
-
22
- If the necessary CSV file does not exist, the graph is not generated.
23
-
24
- """
25
-
26
- def __init__(self,
27
- input_fpath: pathlib.Path,
28
- output_fpath: pathlib.Path,
29
- title: str,
30
- xlabel: str,
31
- ylabel: str,
32
- xcol: str,
33
- ycol: str,
34
- large_text: bool = False,
35
- regression: bool = False) -> None:
36
-
37
- self.input_fpath = input_fpath
38
- self.output_fpath = output_fpath
39
- self.title = title
40
- self.xlabel = xlabel
41
- self.ylabel = ylabel
42
- self.xcol = xcol
43
- self.ycol = ycol
44
- self.regression = regression
45
-
46
- if large_text:
47
- self.text_size = config.kGraphTextSizeLarge
48
- else:
49
- self.text_size = config.kGraphTextSizeSmall
50
-
51
- self.logger = logging.getLogger(__name__)
52
-
53
- def generate(self) -> None:
54
- if not utils.path_exists(self.input_fpath):
55
- self.logger.debug("Not generating 2D scatterplot: %s does not exist",
56
- str(self.input_fpath))
57
- return
58
-
59
- # Read .csv and scaffold graph
60
- df = storage.DataFrameReader('storage.csv')(self.input_fpath)
61
- ax = df.plot.scatter(x=self.xcol, y=self.ycol)
62
-
63
- # Plot regression line
64
- if self.regression:
65
- self._plot_regression(df)
66
-
67
- # Plot ticks and labels
68
- ax.tick_params(labelsize=self.text_size['tick_label'])
69
- ax.set_xlabel(self.xlabel, fontsize=self.text_size['xyz_label'])
70
- ax.set_ylabel(self.ylabel, fontsize=self.text_size['xyz_label'])
71
-
72
- # Add title
73
- ax.set_title(self.title, fontsize=self.text_size['title'])
74
-
75
- # Output figure
76
- fig = ax.get_figure()
77
- fig.set_size_inches(config.kGraphBaseSize, config.kGraphBaseSize)
78
- fig.savefig(self.output_fpath,
79
- bbox_inches='tight',
80
- dpi=config.kGraphDPI)
81
- # Prevent memory accumulation (fig.clf() does not close everything)
82
- plt.close(fig)
83
-
84
- def _plot_regression(self, df):
85
- # slope, intercept, r_value, p_value, std_err = stats.linregress(df.loc[:, self.xcol],
86
- # df.loc[:, self.ycol])
87
- # x_new = np.linspace(df[self.xcol].min(), df[self.xcol].max(), 50)
88
- # line = slope * x_new * intercept
89
- # plt.plot(x_new, line, 'r', label='y={:.2f}x+{:.2f}'.format(slope, intercept))
90
-
91
- # Calculate linear regression line
92
- coeffs = np.polyfit(x=df.loc[:, self.xcol],
93
- y=df.loc[:, self.ycol], deg=1)
94
- ffit = np.poly1d(coeffs)
95
- x_new = np.linspace(df[self.xcol].min(), df[self.xcol].max(), 50)
96
- y_new = ffit(x_new)
97
-
98
- # Plot line and add equation to legend
99
- xsym = sympy.symbols('x')
100
- eqn = sum(sympy.S("{:6.2f}".format(v)) * xsym **
101
- i for i, v in enumerate(coeffs[::-1]))
102
- latex = sympy.printing.latex(eqn)
103
- plt.plot(x_new, y_new, label="${}$".format(latex))
104
- plt.legend(fontsize=self.text_size['legend_label'])
105
-
106
-
107
- __api__ = [
108
- 'Scatterplot2D'
109
- ]