math-spec-mapping 0.3.4__py3-none-any.whl → 0.3.6__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.
@@ -37,6 +37,7 @@ class Block:
37
37
  )
38
38
  ]
39
39
  )
40
+ self.domain_blocks2 = self.domain_blocks[:]
40
41
  self.codomain_blocks = tuple(
41
42
  [
42
43
  self
@@ -191,6 +192,9 @@ class ParallelBlock(Block):
191
192
  self.domain_blocks = tuple(
192
193
  [i for x in self.components for i in x.domain_blocks]
193
194
  )
195
+ self.domain_blocks2 = tuple(
196
+ [x for x in self.components for i in x.domain_blocks2]
197
+ )
194
198
  self.codomain_blocks = tuple(
195
199
  [i for x in self.components for i in x.codomain_blocks]
196
200
  )
@@ -320,6 +324,7 @@ class StackBlock(Block):
320
324
  )
321
325
 
322
326
  self.domain_blocks = self.components[0].domain_blocks
327
+ self.domain_blocks2 = self.components[0].domain_blocks2
323
328
  self.codomain_blocks = self.components[-1].codomain_blocks
324
329
  self.domain_blocks_empty = self.components[0].domain_blocks_empty
325
330
  self.codomain_blocks_empty = self.components[-1].codomain_blocks_empty
@@ -45,6 +45,7 @@ class MathSpec:
45
45
  self._check_dictionary_names()
46
46
  self._build_functional_parameters()
47
47
  self._build_parameter_types()
48
+ self._crawl_spaces()
48
49
 
49
50
  def _check_dictionary_names(self):
50
51
  for key in self.boundary_actions:
@@ -371,7 +372,7 @@ class MathSpec:
371
372
  )
372
373
  opts.extend(
373
374
  [
374
- (x, x.control_actions)
375
+ (x, x.control_action_options)
375
376
  for x in self.control_actions.values()
376
377
  if len(x.control_action_options) > 1
377
378
  ]
@@ -406,6 +407,18 @@ class MathSpec:
406
407
  self.behavioral_parameters_types = behavioral_parameters_types
407
408
  self.functional_parameters_types = functional_parameters_types
408
409
 
410
+ def _crawl_spaces(self):
411
+ self._used_spaces = []
412
+ self._used_spaces.extend([x.codomain for x in self.control_actions.values()])
413
+ self._used_spaces.extend([x.codomain for x in self.boundary_actions.values()])
414
+ self._used_spaces.extend([x.domain for x in self.policies.values()])
415
+ self._used_spaces.extend([x.codomain for x in self.policies.values()])
416
+ self._used_spaces.extend([x.domain for x in self.mechanisms.values()])
417
+
418
+ self._used_spaces = list(set().union(*self._used_spaces))
419
+ us_names = [y.name for y in self._used_spaces]
420
+ self._unused_spaces = [self.spaces[x] for x in self.spaces if x not in us_names]
421
+
409
422
  def metaprogramming_python_types(self, model_directory, overwrite=False):
410
423
  path = model_directory + "/types.py"
411
424
  if not overwrite:
@@ -683,6 +696,7 @@ class MathSpecImplementation:
683
696
  self.boundary_actions = self.load_boundary_actions()
684
697
  self.policies = self.load_policies()
685
698
  self.mechanisms = self.load_mechanisms()
699
+ self.stateful_metrics = self.load_stateful_metrics()
686
700
  self.load_wiring()
687
701
 
688
702
  def load_control_actions(self):
@@ -729,7 +743,7 @@ class MathSpecImplementation:
729
743
  assert (
730
744
  "FP {}".format(ba.name) in self.params
731
745
  ), "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]
746
+ ba.name, "FP " + ba.name, [x.name for x in opts]
733
747
  )
734
748
 
735
749
  opt = self.ms.functional_parameters["FP {}".format(ba.name)][
@@ -761,6 +775,7 @@ class MathSpecImplementation:
761
775
  return mechanisms
762
776
 
763
777
  def load_single_wiring(self, wiring):
778
+ hold = wiring
764
779
  components = [x.name for x in wiring.components]
765
780
  if wiring.block_type == "Stack Block":
766
781
 
@@ -772,16 +787,25 @@ class MathSpecImplementation:
772
787
  elif wiring.block_type == "Parallel Block":
773
788
 
774
789
  spaces_mapping = {}
775
- for x in wiring.components:
776
- spaces_mapping[x.name] = []
777
790
 
778
- for i, x in enumerate([x.name for x in wiring.domain_blocks]):
791
+ for y in [x.name for x in wiring.domain_blocks2]:
792
+ spaces_mapping[y] = []
793
+
794
+ for i, x in enumerate([x.name for x in wiring.domain_blocks2]):
779
795
  spaces_mapping[x].append(i)
780
796
 
781
797
  def wiring(state, params, spaces):
782
798
  codomain = []
783
799
  for component in components:
784
- spaces_i = [spaces[i] for i in spaces_mapping[component]]
800
+ if component in spaces_mapping:
801
+ spaces_i = [spaces[i] for i in spaces_mapping[component]]
802
+ else:
803
+ assert component in [
804
+ x.name for x in hold.domain_blocks_empty
805
+ ], "{} not in domain_blocks_empty of wiring {}".format(
806
+ component, hold
807
+ )
808
+ spaces_i = []
785
809
  spaces_i = self.blocks[component](state, params, spaces_i)
786
810
  if spaces_i:
787
811
  codomain.extend(spaces_i)
@@ -806,7 +830,7 @@ class MathSpecImplementation:
806
830
  assert (
807
831
  "FP {}".format(p.name) in self.params
808
832
  ), "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]
833
+ p.name, "FP " + p.name, [x.name for x in opts]
810
834
  )
811
835
  opt = self.ms.functional_parameters["FP {}".format(p.name)][
812
836
  self.params["FP {}".format(p.name)]
@@ -822,6 +846,22 @@ class MathSpecImplementation:
822
846
  policies[p.name] = opt.implementations["python"]
823
847
  return policies
824
848
 
849
+ def load_stateful_metrics(self):
850
+ stateful_metrics = {}
851
+
852
+ for sm in self.ms.stateful_metrics_map:
853
+ sm = self.ms.stateful_metrics_map[sm]
854
+ if "python" not in sm.implementations:
855
+ print(
856
+ "No python implementation for {}. To fix this, go to Implementations/Python/StatefulMetrics and add {}".format(
857
+ sm.name, sm.name
858
+ )
859
+ )
860
+ else:
861
+ stateful_metrics[sm.name] = sm.implementations["python"]
862
+
863
+ return stateful_metrics
864
+
825
865
  def load_wiring(
826
866
  self,
827
867
  ):
@@ -857,3 +897,38 @@ class MathSpecImplementation:
857
897
  if len(wiring) > 0:
858
898
  wiring = [x.name for x in wiring]
859
899
  print("The following wirings were not loading: {}".format(wiring))
900
+
901
+ def validate_state_and_params(self, state, parameters):
902
+
903
+ k1 = state.keys()
904
+ k2 = [x.name for x in self.ms.state["Global State"].variables]
905
+
906
+ not_in_state = [x for x in k2 if x not in k1]
907
+ shouldnt_be_in_state = [x for x in k1 if x not in k2]
908
+ assert (
909
+ len(not_in_state) == 0
910
+ ), "The following state variables are missing: {}".format(not_in_state)
911
+ assert (
912
+ len(shouldnt_be_in_state) == 0
913
+ ), "The following state variables are extra: {}".format(shouldnt_be_in_state)
914
+
915
+ k1 = parameters.keys()
916
+ k2 = self.ms.parameters.all_parameters + list(
917
+ self.ms.functional_parameters.keys()
918
+ )
919
+
920
+ not_in_params = [x for x in k2 if x not in k1]
921
+ shouldnt_be_in_params = [x for x in k1 if x not in k2]
922
+ assert (
923
+ len(not_in_params) == 0
924
+ ), "The following parameters are missing: {}".format(not_in_params)
925
+ assert (
926
+ len(shouldnt_be_in_params) == 0
927
+ ), "The following parameters are extra: {}".format(shouldnt_be_in_params)
928
+
929
+ def prepare_state_and_params(self, state, params):
930
+ self.validate_state_and_params(state, params)
931
+ state = deepcopy(state)
932
+ params = deepcopy(params)
933
+ state["Stateful Metrics"] = self.stateful_metrics
934
+ return state, params
@@ -16,6 +16,7 @@ class StatefulMetric:
16
16
  else:
17
17
  self.label = self.name
18
18
  self.metadata = data["metadata"]
19
+ self.implementations = data["implementations"]
19
20
 
20
21
 
21
22
  class StatefulMetricSet:
@@ -39,6 +39,15 @@ def convert_stateful_metric(ms, data: Dict) -> StatefulMetricSet:
39
39
  ), "Variable '{}' not in variable map for stateful metrics variables used".format(
40
40
  x[1]
41
41
  )
42
+
43
+ var["implementations"] = {}
44
+
45
+ if "python" in ms["Implementations"]:
46
+ if "stateful_metrics" in ms["Implementations"]["python"]:
47
+ if var["name"] in ms["Implementations"]["python"]["stateful_metrics"]:
48
+ var["implementations"]["python"] = ms["Implementations"]["python"][
49
+ "stateful_metrics"
50
+ ][var["name"]]
42
51
  new_variables.append(StatefulMetric(var))
43
52
  data["metrics"] = new_variables
44
53
 
@@ -164,7 +164,10 @@ cssclasses:
164
164
  else:
165
165
  out += symbol2 + name + "\n"
166
166
  for var in ms.stateful_metrics[name].metrics:
167
- out += symbol3 + "[[{}]]".format(var.name) + "\n"
167
+ if linking:
168
+ out += symbol3 + "[[{}]]".format(var.name) + "\n"
169
+ else:
170
+ out += symbol3 + "{}".format(var.name) + "\n"
168
171
 
169
172
  out += symbol1 + "**Types**\n"
170
173
  for name in ms.types.keys():
@@ -186,7 +189,10 @@ cssclasses:
186
189
  else:
187
190
  out += symbol2 + name + "\n"
188
191
  for param in [x.name for x in ms.parameters.data[name].parameters]:
189
- out += symbol3 + "[[{}]]".format(param) + "\n"
192
+ if linking:
193
+ out += symbol3 + "[[{}]]".format(param) + "\n"
194
+ else:
195
+ out += symbol3 + "{}".format(param) + "\n"
190
196
 
191
197
  out += symbol1 + "**Boundary Actions**\n"
192
198
  for name in ms.boundary_actions.keys():
@@ -538,7 +538,7 @@ def write_stateful_metrics_markdown_report(ms, path, metric, add_metadata=True):
538
538
  out += "Domain: {}\n\n".format(metric.domain)
539
539
 
540
540
  out += "## Parameters Used\n"
541
- for i, x in enumerate(sorted(metric.parameters_used, key=lambda x: x.name)):
541
+ for i, x in enumerate(sorted(metric.parameters_used, key=lambda x: x)):
542
542
  out += "{}. [[{}]]".format(i + 1, x)
543
543
  out += "\n"
544
544
  out += "\n"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.3.4
3
+ Version: 0.3.6
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
@@ -2,11 +2,11 @@ math_spec_mapping/__init__.py,sha256=CzT9KycdX5nuiUzDFmLXVeAIr8v8UKGbXsEQF8vjl1c
2
2
  math_spec_mapping/schema.py,sha256=6mrRqzEnTTSXjb19xJ63MBp0KjKH0s7i6TfT4MkAY9k,233
3
3
  math_spec_mapping/schema.schema.json,sha256=hJP2TcV5WPFPmx4u_A5U1xtnpkE1LeYaTeYOXadTot0,30916
4
4
  math_spec_mapping/Classes/ActionTransmissionChannel.py,sha256=zWMo5QsgPh5WGIWXl-xOrZNMXYJXmK6Vejw1dQvi0og,246
5
- math_spec_mapping/Classes/Block.py,sha256=OsWM1ZAi6ZvavDhMFJi_H7w8ZF9LqJIKR3ZLTXnts9w,17437
5
+ math_spec_mapping/Classes/Block.py,sha256=cGtIhNgRfoDZ0O3SxeXcNzNlHcdXIB89sT2uaZct8LY,17667
6
6
  math_spec_mapping/Classes/BoundaryAction.py,sha256=KuZqtvZwSHWDP7gFQXGnG-r3EuYJU_oU9wMCuqvRkzk,593
7
7
  math_spec_mapping/Classes/ControlAction.py,sha256=ysqpgANwdizVdwqtgZmnxXMpCqrzmVEF_6YT0M3l4Ho,526
8
8
  math_spec_mapping/Classes/Entity.py,sha256=fA0-b128_OHHxfCg4pzqyQV083EYev1HlVpy86S5igg,1226
9
- math_spec_mapping/Classes/MathSpec.py,sha256=AcfqbhYWhqpm3ybK3LmBClQ0mEMmIX9k2S1Snha-aDQ,32143
9
+ math_spec_mapping/Classes/MathSpec.py,sha256=qH0F43SjytPDmxM1Hy3-8z9HzfRqNca-5X-6Vc5Sv8M,35294
10
10
  math_spec_mapping/Classes/Mechanism.py,sha256=2sLm3wYBIeTQaMBcsJ9btqIWsbS895Ra8NY6Y9_G_Dg,379
11
11
  math_spec_mapping/Classes/Metric.py,sha256=AhPgYppOP6q49xvR8S9STxQsXUKJlTWx7wI1LfZEtww,581
12
12
  math_spec_mapping/Classes/Parameter.py,sha256=ZuJ_w0sChvRElJ4sOnXZ2EV4Ell2xXFulKLjVOpgz2E,1237
@@ -14,7 +14,7 @@ math_spec_mapping/Classes/Policy.py,sha256=fzV85tB3QScjiYGfhw_dyQt9L1BYYfTyTIQQc
14
14
  math_spec_mapping/Classes/Space.py,sha256=QsahxoUfRsDWQLBL683KnGx72MAmRxv7CDE7TMgCG-E,472
15
15
  math_spec_mapping/Classes/State.py,sha256=U40DoF2qlx_k9gvqQiP1S3C9ZLk3cW_-jmJn71TiCxg,1599
16
16
  math_spec_mapping/Classes/StateUpdateTransmissionChannel.py,sha256=3hBLvD1lE64PkwqksBXAfFWv7foOZzGQLAFQWy42tOA,257
17
- math_spec_mapping/Classes/StatefulMetric.py,sha256=UCis1BJ7fsajHHxFF05ZiyDean2D4s4a95uYYW1Mjq4,749
17
+ math_spec_mapping/Classes/StatefulMetric.py,sha256=plMFMAFEk1y2t4DR5lA2SRC9UrYArsx_W33l3mZSdgE,804
18
18
  math_spec_mapping/Classes/Type.py,sha256=2KFY8d3cv1PzJJ7SSMHJf1zcfQ3ZbqxotK2KgTaLZdM,289
19
19
  math_spec_mapping/Classes/__init__.py,sha256=0zxgOqns_9JybD74HKMVh6aw8ij8WVbfQ4Q_1uWzof0,761
20
20
  math_spec_mapping/Convenience/__init__.py,sha256=z2W-E5Wg1CNEkDI5UqH3qIVBqp-3A1e63f3u9fA-N7w,112
@@ -35,7 +35,7 @@ math_spec_mapping/Load/parameters.py,sha256=W4utm7to3s2fo4z3XgLH0TM1agaIad1qfM2I
35
35
  math_spec_mapping/Load/policy.py,sha256=HvlhGHGJTweVs7DOI2HSL_2_diECr8ukDUmzoFLQELo,2444
36
36
  math_spec_mapping/Load/spaces.py,sha256=7zgGA57Te7T4hfuCCDElffiidWgn1lKm5E14e1yjt8M,1116
37
37
  math_spec_mapping/Load/state_update_transmission_channels.py,sha256=FJWp5n4HdtHAfof5BUQ6BnRakljatL2h8dWCapaVSc0,2238
38
- math_spec_mapping/Load/stateful_metrics.py,sha256=uGSTc6x6lld5xptgSUMHrO0Vg0QDRIL14C6zTg33S8o,1977
38
+ math_spec_mapping/Load/stateful_metrics.py,sha256=pX2w3MvX2akFAOo6XWybkRE_X-v5BqchV2jTx0EekF0,2356
39
39
  math_spec_mapping/Load/states.py,sha256=3YurI7eTNkN6nrXRFVrc58wH0VfM22XOuWE07HVpR7Y,1365
40
40
  math_spec_mapping/Load/type.py,sha256=z6cBdBNjWed7cRyA0Bj7Jd5PmtemVVh07n3mWFj_5U4,4356
41
41
  math_spec_mapping/Load/wiring.py,sha256=1dR94U5N1W_WI5rL6lYBltH25ZvApB2pIpq9r5Opkug,3083
@@ -43,8 +43,8 @@ math_spec_mapping/Reports/__init__.py,sha256=W27I6S9Ro1hWeHmnxIokCA06awB__eYey7P
43
43
  math_spec_mapping/Reports/boundary_actions.py,sha256=45BPp4QjWdD-3E9ZWwqgj_nI2-YdcI2ZZ19_Qv_K7Qk,1410
44
44
  math_spec_mapping/Reports/control_actions.py,sha256=NksekZKIPFSIkubttFstKFthc5AU9B9PWRLSl9j1wWs,1216
45
45
  math_spec_mapping/Reports/general.py,sha256=WOOn6Wlb8M4fsdN49FlKLwOka6vJPQ9aCUy88TL2ki0,1610
46
- math_spec_mapping/Reports/html.py,sha256=tqydmwFWz_1Bg_J_avG4t9LtE-DUGbOKAPNuwg6lgRI,9007
47
- math_spec_mapping/Reports/markdown.py,sha256=t6C2D6pk3Y9K9vOR0IC6rLe18tBm3JFgJ3rC9tnvt_Q,22871
46
+ math_spec_mapping/Reports/html.py,sha256=uUXxMgGoL2yQelSg7CmJjIsU84SbZarqPg2d9x7Z13k,9220
47
+ math_spec_mapping/Reports/markdown.py,sha256=SdhgOMpMBnGKWDG0cimk-LI_UqjQDPy87IxTb-PrBQ0,22866
48
48
  math_spec_mapping/Reports/mechanisms.py,sha256=d2Rxt3JBYvqAOAYUynl0buYVoXEHrO8EGq7GK6hK8NA,1322
49
49
  math_spec_mapping/Reports/node_map.py,sha256=FdSMDQG16NX6n9sZcH-T5xwsvgjrV9OqBHc9J_VlNK0,3129
50
50
  math_spec_mapping/Reports/parameters.py,sha256=yizNG4lNGrgrlzYYcHMGfXKDFlPw4PMDYshDqZ3YARs,535
@@ -53,8 +53,8 @@ math_spec_mapping/Reports/spaces.py,sha256=-76hR5wQBv4lsG000ypBJ-OprjsNjI-rNRMYd
53
53
  math_spec_mapping/Reports/state.py,sha256=RkqfSonar74KVC8PpA9GgI2xaHX6BrkNdAuWMZlYQfI,2321
54
54
  math_spec_mapping/Reports/tables.py,sha256=O0CNuqh3LMECq5uLjBOoxMUk5hUvkUK660FNnwWUxDY,1505
55
55
  math_spec_mapping/Reports/wiring.py,sha256=u9SvKWy6T-WJUEgFI6-zgZanoOaTTs_2YwmEceDLsV8,1618
56
- math_spec_mapping-0.3.4.dist-info/LICENSE,sha256=ObyEzSw8kgCaFbEfpu1zP4TrcAKLA0xhqHMZZfyh7N0,1069
57
- math_spec_mapping-0.3.4.dist-info/METADATA,sha256=YxnBIW_L8GLJvqyioONJHgj3DyILY0idwpjj-G-McnE,6012
58
- math_spec_mapping-0.3.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
59
- math_spec_mapping-0.3.4.dist-info/top_level.txt,sha256=AImhn9wgazkdV0a9vfiphtQR8uGe2nq-ZIOp-6yUk9o,18
60
- math_spec_mapping-0.3.4.dist-info/RECORD,,
56
+ math_spec_mapping-0.3.6.dist-info/LICENSE,sha256=ObyEzSw8kgCaFbEfpu1zP4TrcAKLA0xhqHMZZfyh7N0,1069
57
+ math_spec_mapping-0.3.6.dist-info/METADATA,sha256=j1RD4vS3rk4E76cXbVAPsdYAKBjT2o6wpCNIQvKG1Ag,6012
58
+ math_spec_mapping-0.3.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
59
+ math_spec_mapping-0.3.6.dist-info/top_level.txt,sha256=AImhn9wgazkdV0a9vfiphtQR8uGe2nq-ZIOp-6yUk9o,18
60
+ math_spec_mapping-0.3.6.dist-info/RECORD,,