math-spec-mapping 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,7 @@ from .ControlAction import ControlAction
6
6
  from .BoundaryAction import BoundaryAction
7
7
  import os
8
8
  from copy import deepcopy
9
+ import shutil
9
10
 
10
11
 
11
12
  class MathSpec:
@@ -603,6 +604,45 @@ class MathSpec:
603
604
  with open(path, "w") as f:
604
605
  f.write(out)
605
606
 
607
+ def metaprogramming_julia_types(self, model_directory, overwrite=False):
608
+ path = model_directory + "/types.jl"
609
+ if not overwrite:
610
+ assert "types.jl" not in os.listdir(
611
+ model_directory
612
+ ), "The types file is already written, either delete it or switch to overwrite mode"
613
+
614
+ shutil.copyfile("src/TypeMappings/types.jl", path)
615
+
616
+ def metaprogramming_julia_spaces(
617
+ self, model_directory, cadCAD_path, overwrite=False
618
+ ):
619
+ path = model_directory + "/spaces.jl"
620
+ if not overwrite:
621
+ assert "spaces.jl" not in os.listdir(
622
+ model_directory
623
+ ), "The spaces file is already written, either delete it or switch to overwrite mode"
624
+
625
+ out = """include("{}")
626
+ include("types.jl")
627
+ using .Spaces: generate_space_type
628
+
629
+ """.format(
630
+ cadCAD_path
631
+ )
632
+
633
+ for space in self.spaces:
634
+ name = self.spaces[space].name
635
+ schema = self.spaces[space].schema
636
+ schema = ["{}={}".format(x, schema[x].original_type_name) for x in schema]
637
+ if len(schema) >= 1:
638
+ schema = ", ".join(schema) + ","
639
+ out += 'generate_space_type(({}), "{}")'.format(schema, name)
640
+ out += "\n"
641
+ # out += "{} = Spaces.{}".format(name, name)
642
+
643
+ with open(path, "w") as f:
644
+ f.write(out)
645
+
606
646
  def build_implementation(self, params):
607
647
  return MathSpecImplementation(self, params)
608
648
 
@@ -45,6 +45,7 @@ class StateVariable:
45
45
  self.symbol = data["symbol"]
46
46
  self.domain = data["domain"]
47
47
  self.updated_by = []
48
+ self.metadata = data["metadata"]
48
49
 
49
50
  # Add check for type of List
50
51
  if hasattr(self.type, "_name"):
@@ -100,5 +100,9 @@ def load_metrics(ms: Dict, json: Dict, stateful_metrics_map) -> None:
100
100
  hold = policy.metrics_used[:]
101
101
  policy.metrics_used = []
102
102
  for x in hold:
103
- assert x in ms["Metrics"], "{} not a valid metric".format(x)
104
- policy.metrics_used.append(ms["Metrics"][x])
103
+ assert (
104
+ x in ms["Metrics"] or x in stateful_metrics_map
105
+ ), "{} not a valid metric or stateful metric".format(x)
106
+ policy.metrics_used.append(
107
+ ms["Metrics"][x] if x in ms["Metrics"] else stateful_metrics_map[x]
108
+ )
@@ -27,6 +27,8 @@ def convert_state(ms, data: Dict) -> State:
27
27
  check_json_keys(var, "State Variable")
28
28
  assert var["type"] in ms["Types"], "Type not in ms"
29
29
  var["type"] = ms["Types"][var["type"]]
30
+ if "metadata" not in var:
31
+ var["metadata"] = {}
30
32
  new_variables.append(StateVariable(var))
31
33
  data["variables"] = new_variables
32
34
 
@@ -111,6 +111,9 @@ def load_julia_type_key(path):
111
111
  elif x.startswith("struct"):
112
112
  name = name[7:]
113
113
  name = name[: name.index("\n")].strip()
114
+ if x.startswith("const"):
115
+ name = name[6:]
116
+ name = name[: name.index("=")].strip()
114
117
  else:
115
118
  assert False
116
119
 
@@ -152,7 +152,10 @@ cssclasses:
152
152
  else:
153
153
  out += symbol2 + name + "\n"
154
154
  for var in ms.state[name].variable_map.keys():
155
- out += symbol3 + var + "\n"
155
+ if linking:
156
+ out += symbol3 + "[[{}-{}\|{}]]".format(name, var, var) + "\n"
157
+ else:
158
+ out += symbol3 + var + "\n"
156
159
 
157
160
  out += symbol1 + "**Stateful Metrics**\n"
158
161
  for name in ms.stateful_metrics.keys():
@@ -145,7 +145,7 @@ def write_boundary_action_markdown_report(ms, path, boundary_action, add_metadat
145
145
  out += "\n"
146
146
  out += "\n"
147
147
 
148
- out += "## Constraints"
148
+ out += "## Constraints\n"
149
149
  for i, x in enumerate(boundary_action.constraints):
150
150
  out += "{}. {}".format(i + 1, x)
151
151
  out += "\n"
@@ -179,6 +179,8 @@ def write_policy_markdown_report(ms, path, policy, add_metadata=True):
179
179
  policy = ms.policies[policy]
180
180
  if "Policies" not in os.listdir(path):
181
181
  os.makedirs(path + "/Policies")
182
+
183
+ out = ""
182
184
  if add_metadata:
183
185
  metadata = policy.metadata
184
186
  if len(metadata) > 0:
@@ -188,7 +190,7 @@ def write_policy_markdown_report(ms, path, policy, add_metadata=True):
188
190
  """.format(
189
191
  "\n".join(["{}: {}".format(x, metadata[x]) for x in metadata])
190
192
  )
191
- out = ""
193
+
192
194
  out += "## Description"
193
195
  out += "\n"
194
196
  out += "\n"
@@ -292,7 +294,9 @@ def write_mechanism_markdown_report(ms, path, mechanism, add_metadata=True):
292
294
  out += "\n\n"
293
295
  out += "## Updates\n\n"
294
296
  for i, x in enumerate(mechanism.updates):
295
- out += "{}. [[{}]].{}".format(i + 1, x[0].name, x[1].name)
297
+ out += "{}. [[{}]].[[{}|{}]]".format(
298
+ i + 1, x[0].name, x[0].state.name + "-" + x[1].name, x[1].name
299
+ )
296
300
  out += "\n"
297
301
 
298
302
  with open("{}/Mechanisms/{}.md".format(path, mechanism.label), "w") as f:
@@ -472,8 +476,14 @@ def write_wiring_markdown_report(ms, path, wiring, add_metadata=True):
472
476
  out += "\n"
473
477
 
474
478
  out += "## All State Updates\n"
479
+
475
480
  for i, x in enumerate(wiring.all_updates):
476
- out += "{}. [[{}]].{}".format(i + 1, x[0].name, x[1].name)
481
+ out += "{}. [[{}]].[[{}|{}]]".format(
482
+ i + 1,
483
+ x[0].name,
484
+ ms.entities[x[0].name].state.name + "-" + x[1].name,
485
+ x[1].name,
486
+ )
477
487
  out += "\n"
478
488
  out += "\n"
479
489
 
@@ -608,6 +618,45 @@ def write_displays_markdown_reports(ms, path, add_metadata=True):
608
618
  )
609
619
 
610
620
 
621
+ def write_state_variables_markdown_reports(ms, path, state, add_metadata=True):
622
+ if "State Variables" not in os.listdir(path):
623
+ os.makedirs(path + "/State Variables")
624
+ state = ms.state[state]
625
+ for variable in state.variables:
626
+ out = ""
627
+ if add_metadata:
628
+ metadata = variable.metadata
629
+ if len(metadata) > 0:
630
+ out += """---
631
+ {}
632
+ ---
633
+ """.format(
634
+ "\n".join(["{}: {}".format(x, metadata[x]) for x in metadata])
635
+ )
636
+ out += "Description: "
637
+ out += variable.description
638
+ out += "\n\n"
639
+ out += "Type: [["
640
+ out += variable.type.name
641
+ out += "]]\n\n"
642
+ out += "Symbol: "
643
+ if variable.symbol:
644
+ out += variable.symbol
645
+ out += "\n\n"
646
+ out += "Domain: "
647
+ if variable.domain:
648
+ out += variable.domain
649
+ out += "\n\n"
650
+
651
+ with open(
652
+ "{}/State Variables/{}.md".format(
653
+ path, "{}-{}".format(state.name, variable.name)
654
+ ),
655
+ "w",
656
+ ) as f:
657
+ f.write(out)
658
+
659
+
611
660
  def write_wiring_display_markdown_report(ms, path, wiring, add_metadata=True):
612
661
  wirings = [ms.wiring[w] for w in wiring["components"]]
613
662
  out = ""
@@ -696,6 +745,7 @@ def write_all_markdown_reports(ms, path, clear_folders=False):
696
745
  states = list(ms.state.keys())
697
746
  for x in states:
698
747
  write_state_markdown_report(ms, path, x)
748
+ write_state_variables_markdown_reports(ms, path, x)
699
749
 
700
750
  # Write types
701
751
  for t in ms.types.values():
@@ -51,6 +51,8 @@ def write_state_variable_table_markdown(target_state, links=False):
51
51
  if tv:
52
52
  if links and i == 2:
53
53
  table += "[[{}]]".format(tv)
54
+ elif links and i == 0:
55
+ table += "[[{}-{}\|{}]]".format(target_state.name, tv, tv)
54
56
  else:
55
57
  table += "{}".format(tv)
56
58
  table += "|"
@@ -360,7 +360,8 @@
360
360
  "type": "string"
361
361
  },
362
362
  "description": "All metrics used in implementation of policies"
363
- }
363
+ },
364
+ "metadata": {"type": "object"}
364
365
  },
365
366
  "required": [
366
367
  "codomain",
@@ -390,7 +391,8 @@
390
391
  "logic": {
391
392
  "type": "string",
392
393
  "description": "Any logic associated with the implementation"
393
- }
394
+ },
395
+ "metadata": {"type": "object"}
394
396
  },
395
397
  "required": [
396
398
  "description",
@@ -561,7 +563,8 @@
561
563
  "domain": {
562
564
  "type": ["string","null"],
563
565
  "description": "The mathematical domain of the parameter (optional)"
564
- }
566
+ },
567
+ "metadata": {"type": "object"}
565
568
  },
566
569
  "required": [
567
570
  "description",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.3.0
3
+ Version: 0.3.1
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
@@ -1,18 +1,18 @@
1
1
  math_spec_mapping/__init__.py,sha256=k5KVhqX1_iIkGjTBHAHezWUeh0b3ilWpJaSIVSbKMcg,907
2
2
  math_spec_mapping/schema.py,sha256=6mrRqzEnTTSXjb19xJ63MBp0KjKH0s7i6TfT4MkAY9k,233
3
- math_spec_mapping/schema.schema.json,sha256=DTrPuYbA-n27jatLt2h76WgMm7pWVgkFwC3zGDnlptQ,29208
3
+ math_spec_mapping/schema.schema.json,sha256=gvKfsWNuxnwdwtLCdQPi4GYno_QfZfRNo86ThNUckF0,29352
4
4
  math_spec_mapping/Classes/ActionTransmissionChannel.py,sha256=zWMo5QsgPh5WGIWXl-xOrZNMXYJXmK6Vejw1dQvi0og,246
5
5
  math_spec_mapping/Classes/Block.py,sha256=hXQO221IP-TqZm_TwFKfURpEEjZm7L1TPZDCYlaOdho,17302
6
6
  math_spec_mapping/Classes/BoundaryAction.py,sha256=AOENCqCEfpjotnHhzUj_F2SOP0SGpkN1tNPr8Mtl6Tc,476
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=FTxArDTLt7PBwXE79VqhP7qIA4Gf6zgXAo_iQWOh_7U,27443
9
+ math_spec_mapping/Classes/MathSpec.py,sha256=KEk7oUs21YznNmsdCUtldpOl7p-rwFmpZcolVNHlaTo,28854
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
13
13
  math_spec_mapping/Classes/Policy.py,sha256=fzV85tB3QScjiYGfhw_dyQt9L1BYYfTyTIQQcxeT8ac,530
14
14
  math_spec_mapping/Classes/Space.py,sha256=QsahxoUfRsDWQLBL683KnGx72MAmRxv7CDE7TMgCG-E,472
15
- math_spec_mapping/Classes/State.py,sha256=0gJHHTNjTrz1fL2K-yPu-dJlaCsU_NMxClw6neDv6gE,1497
15
+ math_spec_mapping/Classes/State.py,sha256=2Yn4wQnbBK-Au40tx5YHR8ZsLA7NHHbWvVPjDzU6Tq0,1538
16
16
  math_spec_mapping/Classes/StateUpdateTransmissionChannel.py,sha256=3hBLvD1lE64PkwqksBXAfFWv7foOZzGQLAFQWy42tOA,257
17
17
  math_spec_mapping/Classes/StatefulMetric.py,sha256=UCis1BJ7fsajHHxFF05ZiyDean2D4s4a95uYYW1Mjq4,749
18
18
  math_spec_mapping/Classes/Type.py,sha256=2KFY8d3cv1PzJJ7SSMHJf1zcfQ3ZbqxotK2KgTaLZdM,289
@@ -30,31 +30,31 @@ math_spec_mapping/Load/general.py,sha256=2q6aGKxXhebiHHTZhtACvM4nWIkTben0o5rXuvf
30
30
  math_spec_mapping/Load/implementations.py,sha256=SGKZ_YXeNpJUTnw5fajQTXji7S2bNQo8sh-7YcIO6pk,395
31
31
  math_spec_mapping/Load/load.py,sha256=CLprDhJpbwm9RAzKM2Ghwr8eqBu0a-wvGDOCMmc01YE,2484
32
32
  math_spec_mapping/Load/mechanism.py,sha256=JBy-QpB4W0Z2OcNiakONjD4_RtEgxlFKtLXfDqfhR-0,2037
33
- math_spec_mapping/Load/metrics.py,sha256=gD68mt0Y5jSgofZUwscV8PFatOMV_LPwYyPrwV9SdtE,3273
33
+ math_spec_mapping/Load/metrics.py,sha256=EyCFEgHpyffBPKaqISdIeTyqUtPtu2xoS0gZjh-6i3U,3434
34
34
  math_spec_mapping/Load/parameters.py,sha256=aid_vqYub9643s82NDtMAXLRdV9BPQkri5MadA0L0eQ,1334
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
38
  math_spec_mapping/Load/stateful_metrics.py,sha256=uGSTc6x6lld5xptgSUMHrO0Vg0QDRIL14C6zTg33S8o,1977
39
- math_spec_mapping/Load/states.py,sha256=cwo29SBAtj1FoQLEb8c0wkSCn038lIgM9RjNiZefUaE,1223
40
- math_spec_mapping/Load/type.py,sha256=Wq2EYTofuq4v8_jGGSr23IXJjwavLMjsqSEyhX9VoAM,4217
39
+ math_spec_mapping/Load/states.py,sha256=gAiCGxqc8_js8Gd0aRRrK4PeUW4jgZsgukR6e-5fcg4,1290
40
+ math_spec_mapping/Load/type.py,sha256=wrzT3bmLn2ghvuy8hZhtQZ479HZNntKoLdIC2TcMrgw,4330
41
41
  math_spec_mapping/Load/wiring.py,sha256=1dR94U5N1W_WI5rL6lYBltH25ZvApB2pIpq9r5Opkug,3083
42
42
  math_spec_mapping/Reports/__init__.py,sha256=W27I6S9Ro1hWeHmnxIokCA06awB__eYey7PvKD4Hc1s,933
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=xf5jk3DHWg4CfZHZuF2JK5iZ515ecjDShJJsahiqb4g,8882
47
- math_spec_mapping/Reports/markdown.py,sha256=eJidreiLmfUznoq_-C4IsFTZ__Bka-PWLKjKYn6bhmw,21113
46
+ math_spec_mapping/Reports/html.py,sha256=tqydmwFWz_1Bg_J_avG4t9LtE-DUGbOKAPNuwg6lgRI,9007
47
+ math_spec_mapping/Reports/markdown.py,sha256=r9tHxuGvmwbUy92GVoChqcs7h8pvrGMwXgogAfla4O0,22479
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
51
51
  math_spec_mapping/Reports/policies.py,sha256=EuBzBsTM6QSS_GHFcAyhGgWvDDZwRuKe7Eos9nX13ho,1814
52
52
  math_spec_mapping/Reports/spaces.py,sha256=-76hR5wQBv4lsG000ypBJ-OprjsNjI-rNRMYdtsYnjQ,579
53
- math_spec_mapping/Reports/state.py,sha256=RSHDjzSiUj4ZjReWbkBW7k2njs3Ovp-q0rCC7GBfD-A,2203
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.0.dist-info/LICENSE,sha256=ObyEzSw8kgCaFbEfpu1zP4TrcAKLA0xhqHMZZfyh7N0,1069
57
- math_spec_mapping-0.3.0.dist-info/METADATA,sha256=Vc8ZOoyIufYp8gQkctaAbFV6cuSPNQnOWZw2SaYJXPI,6012
58
- math_spec_mapping-0.3.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
59
- math_spec_mapping-0.3.0.dist-info/top_level.txt,sha256=AImhn9wgazkdV0a9vfiphtQR8uGe2nq-ZIOp-6yUk9o,18
60
- math_spec_mapping-0.3.0.dist-info/RECORD,,
56
+ math_spec_mapping-0.3.1.dist-info/LICENSE,sha256=ObyEzSw8kgCaFbEfpu1zP4TrcAKLA0xhqHMZZfyh7N0,1069
57
+ math_spec_mapping-0.3.1.dist-info/METADATA,sha256=dhHFXSeznJ8iViRkPXM7IC0TOFEkuvSVX41dMIzpuT0,6012
58
+ math_spec_mapping-0.3.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
59
+ math_spec_mapping-0.3.1.dist-info/top_level.txt,sha256=AImhn9wgazkdV0a9vfiphtQR8uGe2nq-ZIOp-6yUk9o,18
60
+ math_spec_mapping-0.3.1.dist-info/RECORD,,