math-spec-mapping 0.3.3__tar.gz → 0.3.4__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. {math_spec_mapping-0.3.3/src/math_spec_mapping.egg-info → math_spec_mapping-0.3.4}/PKG-INFO +1 -1
  2. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/pyproject.toml +1 -1
  3. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/BoundaryAction.py +2 -0
  4. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/MathSpec.py +83 -11
  5. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/boundary_actions.py +11 -0
  6. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/displays.py +4 -2
  7. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/states.py +3 -1
  8. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/markdown.py +2 -2
  9. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/schema.schema.json +34 -2
  10. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4/src/math_spec_mapping.egg-info}/PKG-INFO +1 -1
  11. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/LICENSE +0 -0
  12. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/README.md +0 -0
  13. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/setup.cfg +0 -0
  14. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/ActionTransmissionChannel.py +0 -0
  15. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/Block.py +0 -0
  16. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/ControlAction.py +0 -0
  17. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/Entity.py +0 -0
  18. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/Mechanism.py +0 -0
  19. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/Metric.py +0 -0
  20. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/Parameter.py +0 -0
  21. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/Policy.py +0 -0
  22. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/Space.py +0 -0
  23. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/State.py +0 -0
  24. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/StateUpdateTransmissionChannel.py +0 -0
  25. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/StatefulMetric.py +0 -0
  26. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/Type.py +0 -0
  27. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Classes/__init__.py +0 -0
  28. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Convenience/__init__.py +0 -0
  29. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Convenience/documentation.py +0 -0
  30. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Convenience/starter.py +0 -0
  31. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/__init__.py +0 -0
  32. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/action_transmission_channel.py +0 -0
  33. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/control_actions.py +0 -0
  34. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/entities.py +0 -0
  35. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/general.py +0 -0
  36. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/implementations.py +0 -0
  37. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/load.py +0 -0
  38. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/mechanism.py +0 -0
  39. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/metrics.py +0 -0
  40. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/parameters.py +0 -0
  41. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/policy.py +0 -0
  42. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/spaces.py +0 -0
  43. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/state_update_transmission_channels.py +0 -0
  44. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/stateful_metrics.py +0 -0
  45. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/type.py +0 -0
  46. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Load/wiring.py +0 -0
  47. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/__init__.py +0 -0
  48. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/boundary_actions.py +0 -0
  49. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/control_actions.py +0 -0
  50. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/general.py +0 -0
  51. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/html.py +0 -0
  52. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/mechanisms.py +0 -0
  53. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/node_map.py +0 -0
  54. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/parameters.py +0 -0
  55. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/policies.py +0 -0
  56. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/spaces.py +0 -0
  57. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/state.py +0 -0
  58. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/tables.py +0 -0
  59. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/Reports/wiring.py +0 -0
  60. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/__init__.py +0 -0
  61. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping/schema.py +0 -0
  62. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping.egg-info/SOURCES.txt +0 -0
  63. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping.egg-info/dependency_links.txt +0 -0
  64. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping.egg-info/requires.txt +0 -0
  65. {math_spec_mapping-0.3.3 → math_spec_mapping-0.3.4}/src/math_spec_mapping.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: A library for easy mapping of mathematical specifications.
5
5
  Author-email: Sean McOwen <Sean@Block.Science>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
  [project]
5
5
  name = "math-spec-mapping"
6
- version = "0.3.3"
6
+ version = "0.3.4"
7
7
  authors = [
8
8
  { name="Sean McOwen", email="Sean@Block.Science" },
9
9
  ]
@@ -8,6 +8,7 @@ class BoundaryAction(Block):
8
8
  super().__init__(data)
9
9
  self.boundary_action_options = data["boundary_action_options"]
10
10
  self.block_type = "Boundary Action"
11
+ self.model_name = self.name.replace(" ", "_").lower()
11
12
 
12
13
 
13
14
  class BoundaryActionOption:
@@ -15,3 +16,4 @@ class BoundaryActionOption:
15
16
  self.name = data["name"]
16
17
  self.description = data["description"]
17
18
  self.logic = data["logic"]
19
+ self.implementations = data["implementations"]
@@ -364,7 +364,7 @@ class MathSpec:
364
364
  ]
365
365
  opts.extend(
366
366
  [
367
- (x, x.boundary_actions)
367
+ (x, x.boundary_action_options)
368
368
  for x in self.boundary_actions.values()
369
369
  if len(x.boundary_action_options) > 1
370
370
  ]
@@ -604,6 +604,34 @@ class MathSpec:
604
604
  with open(path, "w") as f:
605
605
  f.write(out)
606
606
 
607
+ def metaprogramming_boundary_actions(
608
+ self, model_directory, overwrite=False, default_values=None
609
+ ):
610
+ path = model_directory + "/boundary_actions.py"
611
+ if not overwrite:
612
+ assert "boundary_actions.py" not in os.listdir(
613
+ model_directory
614
+ ), "The boundary actions file is already written, either delete it or switch to overwrite mode"
615
+ out = ""
616
+
617
+ unique_spaces = set().union(
618
+ *[x.all_spaces_used for x in self.boundary_actions.values()]
619
+ )
620
+ unique_spaces = [x.name_variable for x in unique_spaces]
621
+
622
+ out += "from .spaces import {}".format(", ".join(unique_spaces))
623
+ out += "\n\n"
624
+ for x in self.boundary_actions.values():
625
+ out += "def "
626
+ out += x.model_name
627
+ out += "(state, params) -> ({}):".format(
628
+ ", ".join([y.name_variable for y in x.codomain])
629
+ )
630
+ out += "\n\n"
631
+
632
+ with open(path, "w") as f:
633
+ f.write(out)
634
+
607
635
  def metaprogramming_julia_types(self, model_directory, overwrite=False):
608
636
  path = model_directory + "/types.jl"
609
637
  if not overwrite:
@@ -652,7 +680,7 @@ class MathSpecImplementation:
652
680
  self.ms = deepcopy(ms)
653
681
  self.params = params
654
682
  self.control_actions = self.load_control_actions()
655
- self.boundary_actions = {}
683
+ self.boundary_actions = self.load_boundary_actions()
656
684
  self.policies = self.load_policies()
657
685
  self.mechanisms = self.load_mechanisms()
658
686
  self.load_wiring()
@@ -670,24 +698,64 @@ class MathSpecImplementation:
670
698
  else:
671
699
  assert (
672
700
  "FP {}".format(ca.name) in self.params
673
- ), "No functional parameterization for {}".format(ca.name)
701
+ ), "No functional parameterization for {}. To fix this error, add {} to the parameters passed to ms.build_implementation. Option can be: {}".format(
702
+ ca.name, "FP " + ca.name, [x.name for x in opts]
703
+ )
674
704
  opt = self.ms.functional_parameters["FP {}".format(ca.name)][
675
705
  self.params["FP {}".format(ca.name)]
676
706
  ]
677
707
 
678
- assert (
679
- "python" in opt.implementations
680
- ), "No python implementation for {} / {}".format(ca.name, opt.name)
681
-
682
- control_actions[ca.name] = opt.implementations["python"]
708
+ if "python" not in opt.implementations:
709
+ print(
710
+ "No python implementation for {} / {}. To fix this, go to Implementations/Python/ControlActions and add {}".format(
711
+ ca.name, opt.name, opt.name
712
+ )
713
+ )
714
+ else:
715
+ control_actions[ca.name] = opt.implementations["python"]
683
716
  return control_actions
684
717
 
718
+ def load_boundary_actions(self):
719
+ boundary_actions = {}
720
+ for ba in self.ms.boundary_actions:
721
+ ba = self.ms.boundary_actions[ba]
722
+ opts = ba.boundary_action_options
723
+ if len(opts) == 0:
724
+ print("{} has no boundary action options".format(ba.name))
725
+ else:
726
+ if len(opts) == 1:
727
+ opt = opts[0]
728
+ else:
729
+ assert (
730
+ "FP {}".format(ba.name) in self.params
731
+ ), "No functional parameterization for {}. To fix this error, add {} to the parameters passed to ms.build_implementation. Option can be: {}".format(
732
+ ba.name, ba.name, [x.name for x in opts]
733
+ )
734
+
735
+ opt = self.ms.functional_parameters["FP {}".format(ba.name)][
736
+ self.params["FP {}".format(ba.name)]
737
+ ]
738
+
739
+ if "python" not in opt.implementations:
740
+ print(
741
+ "No python implementation for {} / {}. To fix this, go to Implementations/Python/BoundaryActions and add {}".format(
742
+ ba.name, opt.name, opt.name
743
+ )
744
+ )
745
+ else:
746
+ boundary_actions[ba.name] = opt.implementations["python"]
747
+ return boundary_actions
748
+
685
749
  def load_mechanisms(self):
686
750
  mechanisms = {}
687
751
  for m in self.ms.mechanisms:
688
752
  m = self.ms.mechanisms[m]
689
753
  if "python" not in m.implementations:
690
- print("No python implementation for {}".format(m.name))
754
+ print(
755
+ "No python implementation for {}. To fix this, go to Implementations/Python/Mechanisms and add {}".format(
756
+ m.name, m.name
757
+ )
758
+ )
691
759
  else:
692
760
  mechanisms[m.name] = m.implementations["python"]
693
761
  return mechanisms
@@ -737,14 +805,18 @@ class MathSpecImplementation:
737
805
  else:
738
806
  assert (
739
807
  "FP {}".format(p.name) in self.params
740
- ), "No functional parameterization for {}".format(p.name)
808
+ ), "No functional parameterization for {}. To fix this error, add {} to the parameters passed to ms.build_implementation. Option can be: {}".format(
809
+ p.name, p.name, [x.name for x in opts]
810
+ )
741
811
  opt = self.ms.functional_parameters["FP {}".format(p.name)][
742
812
  self.params["FP {}".format(p.name)]
743
813
  ]
744
814
 
745
815
  if "python" not in opt.implementations:
746
816
  print(
747
- "No python implementation for {} / {}".format(p.name, opt.name)
817
+ "No python implementation for {} / {}. To fix this, go to Implementations/Python/Policies and add {}".format(
818
+ p.name, opt.name, opt.name
819
+ )
748
820
  )
749
821
  else:
750
822
  policies[p.name] = opt.implementations["python"]
@@ -34,6 +34,17 @@ def convert_boundary_action(data: Dict, ms: Dict) -> BoundaryAction:
34
34
  new_bao = []
35
35
  for ba in data["boundary_action_options"]:
36
36
  check_json_keys(ba, "Boundary Action Option")
37
+
38
+ ba["implementations"] = {}
39
+ if "python" in ms["Implementations"]:
40
+ if "boundary_action_options" in ms["Implementations"]["python"]:
41
+ if (
42
+ ba["name"]
43
+ in ms["Implementations"]["python"]["boundary_action_options"]
44
+ ):
45
+ ba["implementations"]["python"] = ms["Implementations"]["python"][
46
+ "boundary_action_options"
47
+ ][ba["name"]]
37
48
  new_bao.append(BoundaryActionOption(ba))
38
49
  data["boundary_action_options"] = new_bao
39
50
 
@@ -7,7 +7,9 @@ def load_wiring(ms, json):
7
7
  ms["Displays"]["Wiring"] = []
8
8
  for display in json["Displays"]["wiring"]:
9
9
  for component in display["components"]:
10
- assert component in ms["Blocks"], "{} is not a valid block".format(
11
- component
10
+ assert (
11
+ component in ms["Blocks"]
12
+ ), "{} referenced in {} is not a valid block".format(
13
+ component, display["name"]
12
14
  )
13
15
  ms["Displays"]["Wiring"].append(display)
@@ -25,7 +25,9 @@ def convert_state(ms, data: Dict) -> State:
25
25
  new_variables = []
26
26
  for var in data["variables"]:
27
27
  check_json_keys(var, "State Variable")
28
- assert var["type"] in ms["Types"], "Type {} not in ms".format(var["name"])
28
+ assert var["type"] in ms["Types"], "Type {} referenced by {} not in ms".format(
29
+ var["type"], var["name"]
30
+ )
29
31
  var["type"] = ms["Types"][var["type"]]
30
32
  if "metadata" not in var:
31
33
  var["metadata"] = {}
@@ -577,7 +577,7 @@ def write_metrics_markdown_report(ms, path, metric, add_metadata=True):
577
577
  out += "\n\n"
578
578
 
579
579
  out += "## Parameters Used\n"
580
- for i, x in enumerate(sorted(metric.parameters_used, key=lambda x: x.name)):
580
+ for i, x in enumerate(sorted(metric.parameters_used, key=lambda x: x)):
581
581
  out += "{}. [[{}]]".format(i + 1, x)
582
582
  var = ms.parameters.parameter_map[x]
583
583
  if var.symbol:
@@ -711,7 +711,7 @@ def write_wiring_display_markdown_report(ms, path, wiring, add_metadata=True):
711
711
  parameters = set().union(*parameters)
712
712
  parameters = sorted(parameters, key=lambda x: x)
713
713
  out += "## Unique Parameters Used\n"
714
- for i, x in enumerate(sorted(parameters, key=lambda x: x.name)):
714
+ for i, x in enumerate(sorted(parameters, key=lambda x: x)):
715
715
  out += "{}. [[{}]]".format(i + 1, x)
716
716
  out += "\n"
717
717
  out += "\n"
@@ -130,7 +130,7 @@
130
130
  },
131
131
  "control_action_options": {
132
132
  "type": "array",
133
- "items": {},
133
+ "items": {"$ref": "./schema.schema.json/#/definitions/ControlActionOption"},
134
134
  "description": "Possible implementations of the control action"
135
135
  },
136
136
  "codomain": {
@@ -157,6 +157,38 @@
157
157
  "title": "ControlAction",
158
158
  "description": "The definition of actions that the system might call, such as an action to refill the stock of an item when reserves run too low or something that could get triggered from a sensor. The key differentiator from boundary actions is that there is no entity calling it and it is not done with randomness."
159
159
  },
160
+ "BoundaryActionOption": {"type": "object",
161
+ "additionalProperties": false,
162
+ "properties": {"name": {"type": "string",
163
+ "description": "The name of the boundary action option"},
164
+ "description": {"type": "string",
165
+ "description": "A description of what this implementation does"},
166
+ "logic": {"type": "string",
167
+ "description": "The logic related to the implementation"},
168
+ "metadata": {"type": "object"}},
169
+ "title": "BoundaryActionOption",
170
+ "required": [
171
+ "name",
172
+ "description",
173
+ "logic"
174
+ ],
175
+ "description": "Specific implementations of a control action which are in the same form of the underlying control action definition."},
176
+ "ControlActionOption": {"type": "object",
177
+ "additionalProperties": false,
178
+ "properties": {"name": {"type": "string",
179
+ "description": "The name of the control action option"},
180
+ "description": {"type": "string",
181
+ "description": "A description of what this implementation does"},
182
+ "logic": {"type": "string",
183
+ "description": "The logic related to the implementation"},
184
+ "metadata": {"type": "object"}},
185
+ "title": "ControlActionOption",
186
+ "required": [
187
+ "name",
188
+ "description",
189
+ "logic"
190
+ ],
191
+ "description": "Specific implementations of a control action which are in the same form of the underlying control action definition."},
160
192
  "Entity": {
161
193
  "type": "object",
162
194
  "additionalProperties": false,
@@ -469,7 +501,7 @@
469
501
  },
470
502
  "boundary_action_options": {
471
503
  "type": "array",
472
- "items": {},
504
+ "items": {"$ref": "./schema.schema.json/#/definitions/BoundaryActionOption"},
473
505
  "description": "The options for implementation of the boundary action"
474
506
  },
475
507
  "called_by": {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: A library for easy mapping of mathematical specifications.
5
5
  Author-email: Sean McOwen <Sean@Block.Science>
6
6
  Classifier: Programming Language :: Python :: 3