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
@@ -0,0 +1,135 @@
1
+ # Copyright 2021 John Harwell, All rights reserved.
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """
5
+ Builtin batch criteria which can be used with any :term:`Engine`/:term:`Project`.
6
+
7
+ Batch criteria in this file are the ONLY ones which come with SIERRA which can
8
+ be used as-is. Other stuff in ``sierra.core.variables`` are base classes which
9
+ require specialization to use as batch criteria, or are just experimental
10
+ variables.
11
+ """
12
+ # Core packages
13
+ import typing as tp
14
+ import re
15
+ import pathlib
16
+ import numpy as np
17
+
18
+ # 3rd party packages
19
+ import implements
20
+
21
+ # Project packages
22
+ from sierra.core import types
23
+ from sierra.core.experiment import definition
24
+ from sierra.core.variables import batch_criteria as bc
25
+ from sierra.core.graphs import bcbridge
26
+
27
+
28
+ @implements.implements(bcbridge.IGraphable)
29
+ class MonteCarlo(bc.UnivarBatchCriteria):
30
+ """
31
+ Criteria which does nothing put provide a set of experiments via cardinality.
32
+
33
+ See :ref:`usage/bc/montecarlo` for documentation.
34
+
35
+ """
36
+
37
+ def __init__(
38
+ self,
39
+ cli_arg: str,
40
+ main_config: types.YAMLDict,
41
+ batch_input_root: pathlib.Path,
42
+ cardinality: int,
43
+ ) -> None:
44
+ bc.UnivarBatchCriteria.__init__(self, cli_arg, main_config, batch_input_root)
45
+ self.attr_changes = [] # type: tp.List[definition.AttrChangeSet]
46
+ self.cardinality = cardinality # type: int
47
+
48
+ def gen_attr_changelist(self) -> tp.List[definition.AttrChangeSet]:
49
+ if not self.attr_changes:
50
+ self.attr_changes = [
51
+ definition.AttrChangeSet(definition.NullMod())
52
+ for i in range(0, self.cardinality)
53
+ ]
54
+
55
+ return self.attr_changes
56
+
57
+ def n_agents(self, exp_num: int) -> int:
58
+ return self.size_list[exp_num]
59
+
60
+ def graph_info(
61
+ self,
62
+ cmdopts: types.Cmdopts,
63
+ batch_output_root: tp.Optional[pathlib.Path] = None,
64
+ exp_names: tp.Optional[tp.List[str]] = None,
65
+ ) -> bcbridge.GraphInfo:
66
+ info = bcbridge.GraphInfo(
67
+ cmdopts,
68
+ batch_output_root,
69
+ exp_names if exp_names else self.gen_exp_names(),
70
+ )
71
+
72
+ info.xticks = list(range(0, len(info.exp_names)))
73
+ info.xticklabels = info.exp_names
74
+ info.xlabel = "Experiment"
75
+ return info
76
+
77
+
78
+ def _mc_parse(arg: str) -> int:
79
+ sections = arg.split(".")
80
+
81
+ # This is the one builtin batch criteria which exists for now
82
+ assert (
83
+ sections[1] == "MonteCarlo"
84
+ ), f" Only 'MonteCarlo' builtin defined; have {sections[1]}"
85
+
86
+ # remove batch criteria variable name, leaving only the spec
87
+ sections = sections[1:]
88
+ assert (
89
+ len(sections) == 2
90
+ ), f"Spec must have 2 sections separated by '.'; have {len(sections)} from '{arg}'"
91
+
92
+ res = re.search("C[0-9]+", sections[1])
93
+ assert res is not None, "Bad cardinality in criteria section '{sections[1]}'"
94
+ return int(res.group(0)[1:])
95
+
96
+
97
+ def linspace_parse(arg: str, scale_factor: tp.Optional[float] = 1.0) -> tp.List[float]:
98
+ """
99
+ Generate an array from a linspace spec of the form ``<min>.<max>.C<cardinality>``.
100
+
101
+ Args:
102
+ arg: The CLI string.
103
+
104
+ scale_factor: A linear factor applied to the min/max to shift the
105
+ range. This can be used to, e.g., generate ranges like
106
+ 0.4-0.8 from specs like ``4.8.C8`` instead of having to do
107
+ contortions around parsing decimal values out of CLI
108
+ strings directly.
109
+ """
110
+ regex = r"(\d+)\.(\d+)\s*\.C\s*(\d+)\s*"
111
+ res = re.match(regex, arg)
112
+ assert len(res.groups()) == 3, f"Spec must match {regex}, have {arg}"
113
+
114
+ # groups(0) is always the full matched string; subsequent groups are the
115
+ # captured groups from the () expressions.
116
+ _min = float(res.group(1)) * scale_factor
117
+ _max = float(res.group(2)) * scale_factor
118
+ cardinality = int(res.group(3))
119
+ return list(x for x in np.linspace(_min, _max, cardinality))
120
+
121
+
122
+ def factory(
123
+ cli_arg: str,
124
+ main_config: types.YAMLDict,
125
+ cmdopts: types.Cmdopts,
126
+ batch_input_root: pathlib.Path,
127
+ **kwargs,
128
+ ) -> MonteCarlo:
129
+ """Create a :class:`MonteCarlo` derived class from the cmdline definition."""
130
+ cardinality = _mc_parse(cli_arg)
131
+
132
+ return MonteCarlo(cli_arg, main_config, batch_input_root, cardinality)
133
+
134
+
135
+ __all__ = ["MonteCarlo", "linspace_parse"]
@@ -15,55 +15,35 @@ import re
15
15
  from sierra.core import types
16
16
 
17
17
 
18
- class Parser():
18
+ def parse(arg: str, dflts: types.SimpleDict) -> types.CLIArgSpec:
19
19
  """Enforces the cmdline definition of ``--exp-setup``.
20
20
 
21
- See :ref:`ln-sierra-vars-expsetup` for documentation.
21
+ See :ref:`usage/vars/expsetup` for documentation.
22
22
 
23
23
  """
24
+ ret = dflts
24
25
 
25
- def __init__(self, dflts: types.SimpleDict):
26
- self.dflts = dflts
26
+ regex = r"T(\d+)(?:\.K(\d+))?"
27
27
 
28
- def __call__(self, arg: str) -> types.CLIArgSpec:
29
- ret = self.dflts
28
+ sections = arg.split(".")
29
+ # remove variable name, leaving only the spec
30
+ sections = sections[1:]
30
31
 
31
- sections = arg.split('.')
32
- # remove variable name, leaving only the spec
33
- sections = sections[1:]
32
+ # Get pretty name for logging
33
+ ret["pretty_name"] = ".".join(sections)
34
+ res = re.match(regex, ret["pretty_name"])
34
35
 
35
- assert len(sections) >= 1 and len(sections) <= 3,\
36
- ("Spec must have between 1 and 3 sections separated by '.'; "
37
- f"have {len(sections)} from '{arg}'")
36
+ assert (
37
+ len(res.groups()) >= 1 and len(res.groups()) <= 3
38
+ ), f"Spec must match {regex}, have {arg}"
38
39
 
39
- # Get pretty name for logging
40
- ret['pretty_name'] = '.'.join(sections)
40
+ ret["n_secs_per_run"] = int(res.group(1))
41
41
 
42
- # Parse duration, which must be present
43
- res = re.search(r"T\d+", sections[0])
44
- assert res is not None, \
45
- f"Bad duration spec in section '{sections[0]}'"
46
- ret['n_secs_per_run'] = int(res.group(0)[1:])
42
+ # Parse # ticks per second for controllers, which can be absent
43
+ if res.group(2) is not None:
44
+ ret["n_ticks_per_sec"] = int(res.group(2))
47
45
 
48
- # Parse # ticks per second for controllers, which can be absent
49
- if len(sections) >= 2:
50
- res = re.search(r"K\d+", sections[1])
51
- assert res is not None, \
52
- f"Bad ticks per second spec in section '{sections[1]}'"
53
- ret['n_ticks_per_sec'] = int(res.group(0)[1:])
46
+ return ret
54
47
 
55
- # Parse # datapoints to capture, which can be absent
56
- if len(sections) == 3:
57
- res = re.search(r"N\d+", sections[2])
58
- assert res is not None, \
59
- f"Bad # datapoints spec in section '{sections[2]}'"
60
- ret['n_datapoints'] = int(res.group(0)[1:])
61
48
 
62
- return ret
63
-
64
-
65
- __api__ = [
66
- 'Parser'
67
-
68
-
69
- ]
49
+ __all__ = ["parse"]
@@ -8,6 +8,7 @@ Reusable classes related to the homogeneous populations of agents.
8
8
  import typing as tp
9
9
  import re
10
10
  import math
11
+ import pathlib
11
12
 
12
13
  # 3rd party packages
13
14
 
@@ -16,7 +17,7 @@ from sierra.core import types
16
17
  from sierra.core.variables import batch_criteria as bc
17
18
 
18
19
 
19
- class BasePopulationSize(bc.UnivarBatchCriteria):
20
+ class PopulationSize(bc.UnivarBatchCriteria):
20
21
  """
21
22
  Base class for changing the # agents/robots to reduce code duplication.
22
23
  """
@@ -24,101 +25,96 @@ class BasePopulationSize(bc.UnivarBatchCriteria):
24
25
  def __init__(self, *args, **kwargs) -> None:
25
26
  bc.UnivarBatchCriteria.__init__(self, *args, *kwargs)
26
27
 
27
- def graph_xticks(self,
28
- cmdopts: types.Cmdopts,
29
- exp_names: tp.Optional[tp.List[str]] = None) -> tp.List[float]:
30
-
31
- if exp_names is None:
32
- exp_names = self.gen_exp_names(cmdopts)
28
+ def graph_xticks(
29
+ self,
30
+ cmdopts: types.Cmdopts,
31
+ batch_output_root: pathlib.Path,
32
+ exp_names: tp.List[str],
33
+ ) -> tp.List[float]:
33
34
 
34
35
  ret = list(map(float, self.populations(cmdopts, exp_names)))
35
36
 
36
- if cmdopts['plot_log_xscale']:
37
+ if cmdopts["plot_log_xscale"]:
37
38
  return [int(math.log2(x)) for x in ret]
38
- elif cmdopts['plot_enumerated_xscale']:
39
+ elif cmdopts["plot_enumerated_xscale"]:
39
40
  return list(range(0, len(ret)))
40
41
  else:
41
42
  return ret
42
43
 
43
- def graph_xticklabels(self,
44
- cmdopts: types.Cmdopts,
45
- exp_names: tp.Optional[tp.List[str]] = None) -> tp.List[str]:
44
+ def graph_xticklabels(
45
+ self,
46
+ cmdopts: types.Cmdopts,
47
+ batch_output_root: pathlib.Path,
48
+ exp_names: tp.List[str],
49
+ ) -> tp.List[str]:
46
50
 
47
51
  if exp_names is None:
48
- exp_names = self.gen_exp_names(cmdopts)
52
+ exp_names = self.gen_exp_names()
49
53
 
50
54
  ret = map(float, self.populations(cmdopts, exp_names))
51
55
 
52
56
  return list(map(lambda x: str(int(round(x, 4))), ret))
53
57
 
54
58
  def graph_xlabel(self, cmdopts: types.Cmdopts) -> str:
55
- if cmdopts['plot_log_xscale']:
59
+ if cmdopts["plot_log_xscale"]:
56
60
  return r"$\log$(System Size)"
57
61
 
58
62
  return "System Size"
59
63
 
60
64
 
61
- class Parser():
62
- """A base parser for use in changing the # robots/agents.
63
-
64
- """
65
-
66
- def __call__(self, arg: str) -> types.CLIArgSpec:
67
- ret = {
68
- 'max_size': int(),
69
- 'model': str(),
70
- 'cardinality': None
71
- } # type: tp.Dict[str, tp.Union[str, tp.Optional[int]]]
72
-
73
- sections = arg.split('.')
74
-
75
- # remove batch criteria variable name, leaving only the spec
76
- sections = sections[1:]
77
- assert len(sections) >= 1 and len(sections) <= 2,\
78
- ("Spec must have 1 or 2 sections separated by '.'; "
79
- f"have {len(sections)} from '{arg}'")
80
-
81
- # Parse increment type
82
- res = re.search("Log|Linear", sections[0])
83
- assert res is not None, \
84
- f"Bad size increment spec in criteria section '{sections[0]}'"
85
- ret['model'] = res.group(0)
86
-
87
- # Parse max size
88
- res = re.search("[0-9]+", sections[0])
89
- assert res is not None, \
90
- "Bad population max in criteria section '{sections[0]}'"
91
- max_size = int(res.group(0))
92
- ret['max_size'] = max_size
93
-
94
- # Parse cardinality for linear models
95
- if ret['model'] == 'Linear':
96
- if len(sections) == 2:
97
- res = re.search("C[0-9]+", sections[1])
98
- assert res is not None, \
99
- "Bad cardinality in criteria section '{sections[1]}'"
100
- ret['cardinality'] = int(res.group(0)[1:])
101
- else:
102
- ret['cardinality'] = int(ret['max_size'] / 10.0) # type: ignore
103
- elif ret['model'] == 'Log':
104
- ret['cardinality'] = len(range(0, int(math.log2(max_size)) + 1))
105
-
106
- return ret
107
-
108
- def to_sizes(self, attr: types.CLIArgSpec) -> tp.List[int]:
109
- """
110
- Generate the system sizes for each experiment in a batch.
111
- """
112
- if attr["model"] == 'Linear':
113
- increment = int(attr['max_size'] / attr['cardinality'])
114
- return [increment * x for x in range(1, attr['cardinality'] + 1)]
115
- elif attr["model"] == 'Log':
116
- return [int(2 ** x) for x in range(0, attr['cardinality'])]
65
+ def parse(arg: str) -> tp.List[int]:
66
+ """Generate the system sizes for each experiment in a batch."""
67
+ spec = {
68
+ "max_size": int(),
69
+ "model": str(),
70
+ "cardinality": None,
71
+ } # type: tp.Dict[str, tp.Union[str, tp.Optional[int]]]
72
+
73
+ sections = arg.split(".")
74
+
75
+ # remove batch criteria variable name, leaving only the spec
76
+ sections = sections[1:]
77
+ assert len(sections) >= 1 and len(sections) <= 2, (
78
+ "Spec must have 1 or 2 sections separated by '.'; "
79
+ f"have {len(sections)} from '{arg}'"
80
+ )
81
+
82
+ # Parse increment type
83
+ res = re.search("Log|Linear", sections[0])
84
+ assert (
85
+ res is not None
86
+ ), f"Bad size increment spec in criteria section '{sections[0]}'"
87
+ spec["model"] = res.group(0)
88
+
89
+ # Parse max size
90
+ res = re.search("[0-9]+", sections[0])
91
+ assert res is not None, "Bad population max in criteria section '{sections[0]}'"
92
+ max_size = int(res.group(0))
93
+ spec["max_size"] = max_size
94
+
95
+ # Parse cardinality for linear models
96
+ if spec["model"] == "Linear":
97
+ if len(sections) == 2:
98
+ res = re.search("C[0-9]+", sections[1])
99
+ assert (
100
+ res is not None
101
+ ), "Bad cardinality in criteria section '{sections[1]}'"
102
+ spec["cardinality"] = int(res.group(0)[1:])
117
103
  else:
118
- raise AssertionError
119
-
120
-
121
- __api__ = [
122
- 'BasePopulationSize',
123
- 'Parser',
104
+ spec["cardinality"] = int(spec["max_size"] / 10.0) # type: ignore
105
+ elif spec["model"] == "Log":
106
+ spec["cardinality"] = len(range(0, int(math.log2(max_size)) + 1))
107
+
108
+ if spec["model"] == "Linear":
109
+ increment = int(spec["max_size"] / spec["cardinality"])
110
+ return [increment * x for x in range(1, spec["cardinality"] + 1)]
111
+ elif spec["model"] == "Log":
112
+ return [int(2**x) for x in range(0, spec["cardinality"])]
113
+ else:
114
+ raise AssertionError
115
+
116
+
117
+ __all__ = [
118
+ "PopulationSize",
119
+ "parse",
124
120
  ]
@@ -9,12 +9,13 @@ import typing as tp
9
9
  import pathlib
10
10
 
11
11
  # 3rd party packages
12
+ import numpy as np
12
13
 
13
14
  # Project packages
14
15
  from sierra.core.variables.batch_criteria import UnivarBatchCriteria
15
16
  from sierra.core.utils import ArenaExtent
16
17
  from sierra.core import types
17
- from sierra.core.experiment import xml
18
+ from sierra.core.experiment import definition # noqa: F401
18
19
 
19
20
 
20
21
  class VariableDensity(UnivarBatchCriteria):
@@ -23,90 +24,65 @@ class VariableDensity(UnivarBatchCriteria):
23
24
  # THINGS is varied as arena size is held constant. This class is a base
24
25
  class which should NEVER be used on its own.
25
26
 
26
- Attributes:
27
-
28
- densities: List of densities to use.
29
-
30
- dist_type: The type of block distribution to use.
31
-
32
- changes: List of sets of changes to apply to generate the specified
33
- arena sizes.
34
-
35
27
  """
36
28
 
37
- def __init__(self,
38
- cli_arg: str,
39
- main_config: types.YAMLDict,
40
- batch_input_root: pathlib.Path,
41
- densities: tp.List[float],
42
- extent: ArenaExtent) -> None:
43
- UnivarBatchCriteria.__init__(
44
- self, cli_arg, main_config, batch_input_root)
29
+ def __init__(
30
+ self,
31
+ cli_arg: str,
32
+ main_config: types.YAMLDict,
33
+ batch_input_root: pathlib.Path,
34
+ densities: tp.List[float],
35
+ extent: ArenaExtent,
36
+ ) -> None:
37
+ UnivarBatchCriteria.__init__(self, cli_arg, main_config, batch_input_root)
45
38
  self.densities = densities
46
39
  self.extent = extent
47
- self.attr_changes = [] # type: tp.List[xml.AttrChangeSet]
48
-
49
-
50
- class Parser():
51
- """Enforces specification of a :class:`VariableDensity` derived batch criteria.
52
-
53
- """
54
-
55
- def __call__(self, arg: str) -> types.CLIArgSpec:
56
- """
57
- Parse the cmdline argument.
58
-
59
- Returns:
40
+ self.attr_changes = [] # type: tp.List[definition.AttrChangeSet]
60
41
 
61
- dict:
62
- density_min: Floating point value of target minimum density.
63
- density_max: Floating point value of target maximum density.
64
- cardinality: # densities in [min,max] that should be created.
65
42
 
66
- """
67
- ret = {}
68
- sections = arg.split('.')
43
+ def parse(arg: str) -> tp.List[float]:
44
+ """Enforces specification of a :class:`VariableDensity` derived batch criteria."""
45
+ spec = {} # type: tp.Dict[str, tp.Union[float, int]]
46
+ sections = arg.split(".")
69
47
 
70
- # remove batch criteria variable name, leaving only the spec
71
- sections = sections[1:]
72
- assert len(sections) == 3,\
73
- ("Spec must have 3 sections separated by '.'; "
74
- f"have {len(sections)} from '{arg}'")
48
+ # remove batch criteria variable name, leaving only the spec
49
+ sections = sections[1:]
50
+ assert len(sections) == 3, (
51
+ "Spec must have 3 sections separated by '.'; "
52
+ f"have {len(sections)} from '{arg}'"
53
+ )
75
54
 
76
- # Parse density min
77
- ret['density_min'] = self._parse_density(sections[0], 'minimum')
55
+ # Parse density min
56
+ spec["min"] = _parse_density(sections[0], "minimum")
78
57
 
79
- # Parse density pmax
80
- ret['density_max'] = self._parse_density(sections[1], 'maximum')
58
+ # Parse density pmax
59
+ spec["max"] = _parse_density(sections[1], "maximum")
81
60
 
82
- # Parse cardinality
83
- res = re.search('C[0-9]+', sections[2])
84
- assert res is not None, \
85
- "Bad cardinality specification in '{sections[2]}'"
61
+ # Parse cardinality
62
+ res = re.search("C[0-9]+", sections[2])
63
+ assert res is not None, "Bad cardinality specification in '{sections[2]}'"
86
64
 
87
- ret['cardinality'] = int(res.group(0)[1:])
65
+ spec["cardinality"] = int(res.group(0)[1:])
88
66
 
89
- return ret
67
+ return list(
68
+ x for x in np.linspace(spec["min"], spec["max"], num=spec["cardinality"])
69
+ )
90
70
 
91
- @staticmethod
92
- def _parse_density(chunk: str, which: str) -> float:
93
- res = re.search('[0-9]+', chunk)
94
- assert res is not None, \
95
- f"Bad {which} density characteristic specification in '{chunk}'"
96
71
 
97
- characteristic = float(res.group(0))
72
+ def _parse_density(chunk: str, which: str) -> float:
73
+ res = re.search("[0-9]+", chunk)
74
+ assert (
75
+ res is not None
76
+ ), f"Bad {which} density characteristic specification in '{chunk}'"
98
77
 
99
- res = re.search('p[0-9]+', chunk)
100
- assert res is not None, \
101
- f"Bad {which} density mantissa specification in '{chunk}'"
78
+ characteristic = float(res.group(0))
102
79
 
103
- mantissa = float("0." + res.group(0)[1:])
80
+ res = re.search("p[0-9]+", chunk)
81
+ assert res is not None, f"Bad {which} density mantissa specification in '{chunk}'"
104
82
 
105
- return characteristic + mantissa
83
+ mantissa = float("0." + res.group(0)[1:])
106
84
 
85
+ return characteristic + mantissa
107
86
 
108
- __api__ = [
109
- 'VariableDensity',
110
- 'Parser'
111
87
 
112
- ]
88
+ __all__ = ["VariableDensity", "parse"]
sierra/core/vector.py CHANGED
@@ -122,4 +122,4 @@ class Vector3D:
122
122
  return m
123
123
 
124
124
 
125
- __api__ = ['Vector3D']
125
+ __all__ = ['Vector3D']