math-spec-mapping 0.2.3__tar.gz → 0.2.5__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/PKG-INFO +1 -1
  2. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/pyproject.toml +1 -1
  3. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/Block.py +102 -10
  4. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/Policy.py +1 -0
  5. math_spec_mapping-0.2.5/src/Convenience/__init__.py +1 -0
  6. math_spec_mapping-0.2.5/src/Convenience/documentation.py +49 -0
  7. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/load.py +8 -0
  8. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/metrics.py +9 -0
  9. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/stateful_metrics.py +4 -0
  10. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/type.py +40 -0
  11. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/html.py +18 -6
  12. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/markdown.py +77 -5
  13. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/__init__.py +1 -0
  14. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/math_spec_mapping.egg-info/PKG-INFO +1 -1
  15. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/math_spec_mapping.egg-info/SOURCES.txt +1 -0
  16. math_spec_mapping-0.2.3/src/Convenience/__init__.py +0 -0
  17. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/LICENSE +0 -0
  18. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/README.md +0 -0
  19. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/setup.cfg +0 -0
  20. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/ActionTransmissionChannel.py +0 -0
  21. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/BoundaryAction.py +0 -0
  22. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/ControlAction.py +0 -0
  23. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/Entity.py +0 -0
  24. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/MathSpec.py +0 -0
  25. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/Mechanism.py +0 -0
  26. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/Metric.py +0 -0
  27. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/Parameter.py +0 -0
  28. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/Space.py +0 -0
  29. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/State.py +0 -0
  30. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/StateUpdateTransmissionChannel.py +0 -0
  31. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/StatefulMetric.py +0 -0
  32. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/Type.py +0 -0
  33. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Classes/__init__.py +0 -0
  34. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Convenience/starter.py +0 -0
  35. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/__init__.py +0 -0
  36. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/action_transmission_channel.py +0 -0
  37. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/boundary_actions.py +0 -0
  38. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/control_actions.py +0 -0
  39. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/displays.py +0 -0
  40. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/entities.py +0 -0
  41. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/general.py +0 -0
  42. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/mechanism.py +0 -0
  43. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/parameters.py +0 -0
  44. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/policy.py +0 -0
  45. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/spaces.py +0 -0
  46. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/state_update_transmission_channels.py +0 -0
  47. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/states.py +0 -0
  48. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Load/wiring.py +0 -0
  49. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/__init__.py +0 -0
  50. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/boundary_actions.py +0 -0
  51. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/control_actions.py +0 -0
  52. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/general.py +0 -0
  53. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/mechanisms.py +0 -0
  54. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/node_map.py +0 -0
  55. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/parameters.py +0 -0
  56. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/policies.py +0 -0
  57. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/spaces.py +0 -0
  58. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/state.py +0 -0
  59. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/tables.py +0 -0
  60. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/Reports/wiring.py +0 -0
  61. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/math_spec_mapping.egg-info/dependency_links.txt +0 -0
  62. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/math_spec_mapping.egg-info/requires.txt +0 -0
  63. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/math_spec_mapping.egg-info/top_level.txt +0 -0
  64. {math_spec_mapping-0.2.3 → math_spec_mapping-0.2.5}/src/schema.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math_spec_mapping
3
- Version: 0.2.3
3
+ Version: 0.2.5
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.2.3"
6
+ version = "0.2.5"
7
7
  authors = [
8
8
  { name="Sean McOwen", email="Sean@Block.Science" },
9
9
  ]
@@ -21,6 +21,7 @@ class Block:
21
21
  self.called_by = []
22
22
  self.calls = []
23
23
  self.block_type = "Block"
24
+ self.all_updates = []
24
25
  # Will be overwritten in composite blocks to represent individual components
25
26
  self.domain_blocks = tuple(
26
27
  [
@@ -61,14 +62,95 @@ class Block:
61
62
  for _ in range(len([x for x in self.codomain if x == TerminatingSpace]))
62
63
  )
63
64
 
65
+ self.find_all_spaces_used(data)
66
+
64
67
  def render_mermaid(self, i):
65
68
  i += 1
66
- return "X{}[{}]".format(i, self.name), i
69
+ out = 'X{}["{}"]'.format(i, self.name)
70
+ if self.block_type == "Mechanism":
71
+ for u in self.updates:
72
+ out += "\n"
73
+ out += "X{} --> {}".format(
74
+ i,
75
+ (u[0].name + "-" + u[1].name).replace(" ", "-"),
76
+ )
77
+ return out, i
78
+
79
+ def render_ending_entities(self):
80
+ if self.block_type == "Mechanism":
81
+ updates = self.updates
82
+ elif self.block_type in ["Parallel Block", "Stack Block", "Split Block"]:
83
+ updates = self.all_updates
84
+ else:
85
+ return "\n", {}
86
+
87
+ out = "\n"
88
+ out += 'subgraph SVS["State Variables"]\n'
89
+
90
+ # Render the entities
91
+ entity_mapping = {}
92
+ entities = set([x[0] for x in updates])
93
+ for i, x in enumerate(entities):
94
+ entity_mapping[x.name] = "EE{}".format(i)
95
+ out += '{}[("{}")]'.format(entity_mapping[x.name], x.name)
96
+ out += "\n"
97
+
98
+ entity_variable_mapping = {}
99
+ # Render the state variables
100
+ for i, x in enumerate(updates):
101
+ entity_variable_mapping[(x[0].name + "-" + x[1].name).replace(" ", "-")] = (
102
+ "EES{}".format(i)
103
+ )
104
+ out += '{}(["{}"])'.format("EES{}".format(i), x[1].name)
105
+ out += "\n"
106
+
107
+ out += "{} --- {}".format("EES{}".format(i), entity_mapping[x[0].name])
108
+ out += "\n"
109
+ out += "end\n"
110
+ out += "\n"
111
+ return out, entity_variable_mapping
67
112
 
68
113
  def render_mermaid_root(self):
69
114
  out = """```mermaid\ngraph TB\n"""
115
+ add, entity_variable_mapping = self.render_ending_entities()
116
+ out += add
70
117
  out += self.render_mermaid(0)[0]
118
+
119
+ for key in entity_variable_mapping:
120
+ out = out.replace(key, entity_variable_mapping[key])
71
121
  out += "\n```"
122
+
123
+ return out
124
+
125
+ def find_all_spaces_used(self, data):
126
+ self.all_spaces_used = []
127
+ self.all_spaces_used.extend(self.domain)
128
+ self.all_spaces_used.extend(self.codomain)
129
+ if "components" in data:
130
+ for x in data["components"]:
131
+ self.all_spaces_used.extend(x.all_spaces_used)
132
+ self.all_spaces_used = list(set(self.all_spaces_used))
133
+
134
+ def find_all_updates(self, data):
135
+ self.all_updates = []
136
+ if "components" in data:
137
+ for x in data["components"]:
138
+ if x.block_type == "Mechanism":
139
+ self.all_updates.extend(x.updates)
140
+ else:
141
+ self.all_updates.extend(x.all_updates)
142
+ self.all_updates = list(set(self.all_updates))
143
+
144
+ def components_full(self):
145
+ q = [self]
146
+ out = []
147
+ while len(q) > 0:
148
+ cur = q.pop()
149
+ if hasattr(cur, "components"):
150
+ q.extend(cur.components)
151
+ else:
152
+ out.append(cur)
153
+ out = list(set(out))
72
154
  return out
73
155
 
74
156
 
@@ -123,8 +205,9 @@ class ParallelBlock(Block):
123
205
 
124
206
  self.called_by = []
125
207
  self.calls = []
126
- self.block_type = "Paralell Block"
208
+ self.block_type = "Parallel Block"
127
209
  self.metadata = data["metadata"]
210
+ self.find_all_spaces_used(data)
128
211
 
129
212
  def render_mermaid(self, i):
130
213
  multi = None
@@ -139,6 +222,7 @@ class ParallelBlock(Block):
139
222
  # Render components
140
223
  domain_map = {}
141
224
  codomain_map = {}
225
+
142
226
  for component in self.components:
143
227
  domain = component.domain
144
228
  codomain = component.codomain
@@ -182,22 +266,27 @@ class ParallelBlock(Block):
182
266
  for ix1 in nodes:
183
267
  d = domain_map[ix1]
184
268
  if len(d) > 0:
269
+ d_length = len(d)
185
270
  d = "\n".join(d)
186
271
  d = '"{}"'.format(d)
187
- out += "X{} --{}--> X{}".format(domain_i, d, ix1)
272
+ out += "X{} --{}{}-> X{}".format(domain_i, d, "-" * d_length, ix1)
188
273
  else:
189
274
  out += "X{} --> X{}".format(domain_i, ix1)
190
275
  out += "\n"
191
276
 
277
+ codomain_connections = 0
192
278
  for ix1 in nodes:
193
279
  d = codomain_map[ix1]
194
280
  if len(d) > 0:
195
281
  d = "\n".join(d)
196
282
  d = '"{}"'.format(d)
197
283
  out += "X{} --{}--> X{}".format(ix1, d, codomain_i)
198
- else:
199
- out += "X{} --> X{}".format(ix1, codomain_i)
200
- out += "\n"
284
+ codomain_connections += 1
285
+ out += "\n"
286
+ # else:
287
+ # out += "X{} --> X{}".format(ix1, codomain_i)
288
+ if codomain_connections == 0:
289
+ out = out.replace("X{}[Codomain]".format(codomain_i), "")
201
290
 
202
291
  # Subgraph it
203
292
  if self.mermaid_show_name:
@@ -205,7 +294,7 @@ class ParallelBlock(Block):
205
294
  else:
206
295
  name = " "
207
296
  i += 1
208
- out = "subgraph X{}[{}]\ndirection TB\n".format(i, name) + out
297
+ out = 'subgraph X{}["{}"]\ndirection TB\n'.format(i, name) + out
209
298
 
210
299
  out += "end"
211
300
 
@@ -241,6 +330,7 @@ class StackBlock(Block):
241
330
 
242
331
  self.block_type = "Stack Block"
243
332
  self.metadata = data["metadata"]
333
+ self.find_all_spaces_used(data)
244
334
 
245
335
  def _check_domain_mapping(self):
246
336
  x = self.components[:-1]
@@ -340,12 +430,13 @@ class StackBlock(Block):
340
430
  d = domain_map[ix4]
341
431
  optional = global_optional
342
432
  if len(d) > 0:
433
+ d_length = len(d)
343
434
  d = "\n".join(d)
344
435
  d = '"{}"'.format(d)
345
436
  if optional:
346
- out += "X{}-.{}.->X{}".format(ix3, d, ix4)
437
+ out += "X{}-.{}.{}->X{}".format(ix3, d, "." * d_length, ix4)
347
438
  else:
348
- out += "X{}--{}-->X{}".format(ix3, d, ix4)
439
+ out += "X{}--{}-{}->X{}".format(ix3, d, "-" * d_length, ix4)
349
440
  else:
350
441
  if optional:
351
442
  out += "X{}-.->X{}".format(ix3, ix4)
@@ -359,7 +450,7 @@ class StackBlock(Block):
359
450
  else:
360
451
  name = " "
361
452
  i += 1
362
- out = "subgraph X{}[{}]\ndirection TB\n".format(i, name) + out
453
+ out = 'subgraph X{}["{}"]\ndirection TB\n'.format(i, name) + out
363
454
  out += "end"
364
455
 
365
456
  return out, i
@@ -419,6 +510,7 @@ class SplitBlock(Block):
419
510
 
420
511
  self.block_type = "Split Block"
421
512
  self.metadata = data["metadata"]
513
+ self.find_all_spaces_used(data)
422
514
 
423
515
  def render_mermaid(self, i):
424
516
  multi = None
@@ -14,3 +14,4 @@ class Policy(Block):
14
14
  super().__init__(data)
15
15
  self.policy_options: List[PolicyOption] = data["policy_options"]
16
16
  self.block_type = "Policy"
17
+ self.metrics_used = data["metrics_used"]
@@ -0,0 +1 @@
1
+ from .documentation import write_top_level_json_description
@@ -0,0 +1,49 @@
1
+ from src import schema
2
+
3
+
4
+ def write_json_description(schema, key, name):
5
+ out = "- **{}**: ".format(name)
6
+
7
+ out += schema["definitions"][key]["description"]
8
+ out += "\n"
9
+ return out
10
+
11
+
12
+ def write_top_level_json_description(indent_level):
13
+
14
+ out = "#{} MSML Components".format("#" * indent_level)
15
+ out += "\n\n"
16
+ out += "MSML extends GDS with multiple types of blocks and other enhancements. Below are the definitions of top level components."
17
+ out += "\n\n"
18
+
19
+ out += "##{} Types & Spaces".format("#" * indent_level)
20
+ out += "\n\n"
21
+
22
+ out += write_json_description(schema, "Type", "Type")
23
+ out += write_json_description(schema, "Space", "Space")
24
+
25
+ out += "\n"
26
+
27
+ out += "##{} Entities, States, Parameters & Metrics".format("#" * indent_level)
28
+ out += "\n\n"
29
+
30
+ out += write_json_description(schema, "Entity", "Entity")
31
+ out += write_json_description(schema, "State", "State")
32
+ out += write_json_description(schema, "StatefulMetric", "Stateful Metric")
33
+ out += write_json_description(schema, "Parameter", "Parameter")
34
+ out += write_json_description(schema, "Metric", "Metric")
35
+
36
+ out += "\n"
37
+
38
+ out += "##{} Blocks & Wiring".format("#" * indent_level)
39
+ out += "\n\n"
40
+
41
+ out += write_json_description(schema, "BoundaryAction", "Boundary Action")
42
+ out += write_json_description(schema, "ControlAction", "Control Action")
43
+ out += write_json_description(schema, "Policy", "Policy")
44
+ out += write_json_description(schema, "Mechanism", "Mechanism")
45
+ out += write_json_description(schema, "Wiring", "Wiring")
46
+
47
+ out += "\n"
48
+
49
+ return out
@@ -58,6 +58,14 @@ def load_from_json(json: Dict) -> MathSpec:
58
58
  action_transmission_channels = load_wiring(ms, json)
59
59
  load_action_transmission_channels(ms, action_transmission_channels)
60
60
  load_state_update_transmission_channels(ms, state_update_transmission_channels)
61
+
62
+ temp = {}
63
+ for w in json["Wiring"]:
64
+ temp[w["name"]] = w
65
+ for w in ms["Wiring"]:
66
+ w = temp[w]
67
+ ms["Wiring"][w["name"]].find_all_updates(w)
68
+
61
69
  load_metrics(ms, json, stateful_metrics_map)
62
70
  if "Displays" in json:
63
71
  load_displays(ms, json)
@@ -93,3 +93,12 @@ def load_metrics(ms: Dict, json: Dict, stateful_metrics_map) -> None:
93
93
  z in ms["Metrics"] or z in names or z in stateful_metrics_map
94
94
  ), "{} is not defined in the spec".format(z)
95
95
  assert len(metrics) == 0, "There are circular references"
96
+
97
+ # Load the metrics into the policies
98
+ for key in ms["Policies"]:
99
+ policy = ms["Policies"][key]
100
+ hold = policy.metrics_used[:]
101
+ policy.metrics_used = []
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])
@@ -55,5 +55,9 @@ def load_stateful_metrics(ms: Dict, json: Dict) -> None:
55
55
  """
56
56
 
57
57
  ms["Stateful Metrics"] = {}
58
+ check = []
58
59
  for sm in json["Stateful Metrics"]:
59
60
  ms["Stateful Metrics"][sm["name"]] = convert_stateful_metric(ms, sm)
61
+ for x in ms["Stateful Metrics"][sm["name"]].metrics:
62
+ assert x.name not in check, "{} stateful metric name is repeated"
63
+ check.append(x)
@@ -1,6 +1,7 @@
1
1
  from .general import check_json_keys
2
2
  from ..Classes import Type
3
3
  import os
4
+ from typing import _UnionGenericAlias
4
5
 
5
6
 
6
7
  def convert_type(data, ms):
@@ -32,8 +33,14 @@ def convert_type(data, ms):
32
33
  val = val.__name__
33
34
  out[key] = val
34
35
  data["type_name"]["python"] = str(out)
36
+ elif type(data["type"]["python"]) == _UnionGenericAlias:
37
+ data["type_name"]["python"] = data["type"]["python"].__repr__()
35
38
  else:
36
39
  data["type_name"]["python"] = data["type"]["python"].__name__
40
+ if "typescript" in ms["Type Keys"]:
41
+ if type_name in ms["Type Keys"]["typescript"]:
42
+ data["type"]["typescript"] = ms["Type Keys"]["typescript"][type_name]
43
+ data["type_name"]["typescript"] = ms["Type Keys"]["typescript"][type_name]
37
44
 
38
45
  # Build the type object
39
46
  return Type(data)
@@ -52,10 +59,43 @@ def load_python_type_key():
52
59
  return mapping
53
60
 
54
61
 
62
+ def load_typescript_type_key(path):
63
+ with open(path, "r") as file:
64
+ type_definitions = file.read()
65
+ type_definitions = type_definitions.split("\n")
66
+ type_definitions = [x for x in type_definitions if len(x) > 0]
67
+ hold = type_definitions[:]
68
+ type_definitions = []
69
+ type_definitions.append(hold.pop(0))
70
+ while len(hold) > 0:
71
+ curr = hold.pop(0)
72
+ if "type" in curr or "interface" in curr:
73
+ type_definitions.append(curr)
74
+ else:
75
+ type_definitions[-1] += "\n" + curr
76
+
77
+ hold = type_definitions[:]
78
+ type_definitions = {}
79
+ for x in hold:
80
+ name = x
81
+ if x.startswith("type"):
82
+ name = name[5:]
83
+ elif x.startswith("interface"):
84
+ name = name[10:]
85
+ else:
86
+ assert False
87
+ name = name[: name.index("=")].strip()
88
+ type_definitions[name] = x
89
+ return type_definitions
90
+
91
+
55
92
  def load_type_keys(ms) -> dict:
56
93
  type_keys = {}
57
94
  python_path = "src/TypeMappings/types.py"
95
+ typescript_path = "src/TypeMappings/types.ts"
58
96
  if os.path.exists(python_path):
59
97
  type_keys["python"] = load_python_type_key()
98
+ if os.path.exists(typescript_path):
99
+ type_keys["typescript"] = load_typescript_type_key(typescript_path)
60
100
 
61
101
  ms["Type Keys"] = type_keys
@@ -111,7 +111,9 @@ def write_entity_reports(ms: MathSpec, directory: str, entities: List[str]) -> N
111
111
  f.write(out)
112
112
 
113
113
 
114
- def write_spec_tree(ms: MathSpec, path=None, linking=False, add_tabbing=False) -> str:
114
+ def write_spec_tree(
115
+ ms: MathSpec, path=None, linking=False, add_tabbing=False, readme=False
116
+ ) -> str:
115
117
  """Write the tree of the specification structure
116
118
 
117
119
  Args:
@@ -145,11 +147,18 @@ def write_spec_tree(ms: MathSpec, path=None, linking=False, add_tabbing=False) -
145
147
  out += symbol1 + "**Stateful Metrics**\n"
146
148
  for name in ms.stateful_metrics.keys():
147
149
  if linking:
148
- out += symbol2 + "[[{}]]".format(name) + "\n"
150
+ out += symbol2 + "{}".format(name) + "\n"
149
151
  else:
150
152
  out += symbol2 + name + "\n"
151
153
  for var in ms.stateful_metrics[name].metrics:
152
- out += symbol3 + var.name + "\n"
154
+ out += symbol3 + "[[{}]]".format(var.name) + "\n"
155
+
156
+ out += symbol1 + "**Types**\n"
157
+ for name in ms.types.keys():
158
+ if linking:
159
+ out += symbol2 + "[[{}]]".format(name) + "\n"
160
+ else:
161
+ out += symbol2 + name + "\n"
153
162
 
154
163
  out += symbol1 + "**Spaces**\n"
155
164
  for name in ms.spaces.keys():
@@ -160,11 +169,11 @@ def write_spec_tree(ms: MathSpec, path=None, linking=False, add_tabbing=False) -
160
169
  out += symbol1 + "**Parameters**\n"
161
170
  for name in ms.parameters.data.keys():
162
171
  if linking:
163
- out += symbol2 + "[[{}]]".format(name) + "\n"
172
+ out += symbol2 + "{}".format(name) + "\n"
164
173
  else:
165
174
  out += symbol2 + name + "\n"
166
175
  for param in [x.name for x in ms.parameters.data[name].parameters]:
167
- out += symbol3 + param + "\n"
176
+ out += symbol3 + "[[{}]]".format(param) + "\n"
168
177
 
169
178
  out += symbol1 + "**Boundary Actions**\n"
170
179
  for name in ms.boundary_actions.keys():
@@ -198,6 +207,9 @@ def write_spec_tree(ms: MathSpec, path=None, linking=False, add_tabbing=False) -
198
207
  out = out.split("\n")
199
208
  out = ["\t" + x for x in out]
200
209
  out = "\n".join(out)
210
+ if readme:
211
+ out = "\n\n```\n{}\n```".format(out)
212
+ out = out.replace("**", "")
201
213
 
202
214
  if path:
203
215
  with open("{}/Spec Tree.md".format(path), "w") as f:
@@ -211,6 +223,6 @@ def write_overview(ms: MathSpec, name: str, file_path: str, summary: str = None)
211
223
  out += "<h2>Summary</h2>"
212
224
  out += "<p>{}</p>".format(summary)
213
225
  out += "<h2>Specification Tree</h2>"
214
- out += write_spec_tree(ms)
226
+ out += write_spec_tree(ms, readme=True)
215
227
  with open(file_path, "w") as f:
216
228
  f.write(out)
@@ -95,6 +95,10 @@ def write_types_markdown_report(ms, path, t, add_metadata=True):
95
95
  out += "### Python Type\n"
96
96
  out += t.type_name["python"]
97
97
  out += "\n"
98
+ if "typescript" in t.type:
99
+ out += "### Typescript Type\n"
100
+ out += t.type_name["typescript"]
101
+ out += "\n"
98
102
  out += "\n"
99
103
  out += "## Notes"
100
104
  out += "\n\n"
@@ -131,6 +135,12 @@ def write_boundary_action_markdown_report(ms, path, boundary_action, add_metadat
131
135
  out += "\n"
132
136
  out += "\n"
133
137
 
138
+ out += "## Followed By\n"
139
+ for i, x in enumerate([x[0] for x in boundary_action.calls]):
140
+ out += "{}. [[{}]]".format(i + 1, x.label)
141
+ out += "\n"
142
+ out += "\n"
143
+
134
144
  out += "## Constraints"
135
145
  for i, x in enumerate(boundary_action.constraints):
136
146
  out += "{}. {}".format(i + 1, x)
@@ -208,6 +218,16 @@ def write_policy_markdown_report(ms, path, policy, add_metadata=True):
208
218
  out += "{}. {}".format(i + 1, x)
209
219
  out += "\n"
210
220
 
221
+ out += "## Parameters Used\n"
222
+ for i, x in enumerate(policy.parameters_used):
223
+ out += "{}. [[{}]]".format(i + 1, x)
224
+ out += "\n"
225
+
226
+ out += "## Metrics Used\n"
227
+ for i, x in enumerate(policy.metrics_used):
228
+ out += "{}. [[{}]]".format(i + 1, x.name)
229
+ out += "\n"
230
+
211
231
  if policy.policy_options:
212
232
  out += "## Policy Options\n"
213
233
  for i, x in enumerate(policy.policy_options):
@@ -296,7 +316,9 @@ def write_space_markdown_report(ms, path, space, add_metadata=True):
296
316
  out += "\n"
297
317
  out += "\n"
298
318
  d = space.schema
299
- d = ",\n".join(["{}: {}".format(a, b.name) for a, b in zip(d.keys(), d.values())])
319
+ d = ",\n".join(
320
+ ["{}: [[{}]]".format(a, b.name) for a, b in zip(d.keys(), d.values())]
321
+ )
300
322
  d = "{" + d + "}"
301
323
  out += d
302
324
  out += "\n"
@@ -326,6 +348,12 @@ def write_control_action_markdown_report(ms, path, control_action, add_metadata=
326
348
  out += control_action.description
327
349
  out += "\n"
328
350
 
351
+ out += "## Followed By\n"
352
+ for i, x in enumerate([x[0] for x in control_action.calls]):
353
+ out += "{}. [[{}]]".format(i + 1, x.label)
354
+ out += "\n"
355
+ out += "\n"
356
+
329
357
  out += "## Constraints"
330
358
  for i, x in enumerate(control_action.constraints):
331
359
  out += "{}. {}".format(i + 1, x)
@@ -390,7 +418,14 @@ def write_wiring_markdown_report(ms, path, wiring, add_metadata=True):
390
418
 
391
419
  out += "\n"
392
420
 
393
- out += "## Constraints"
421
+ out += "## All Blocks\n"
422
+ for i, x in enumerate(wiring.components_full()):
423
+ out += "{}. [[{}]]".format(i + 1, x.name)
424
+ out += "\n"
425
+
426
+ out += "\n"
427
+
428
+ out += "## Constraints\n"
394
429
  for i, x in enumerate(wiring.constraints):
395
430
  out += "{}. {}".format(i + 1, x)
396
431
  out += "\n"
@@ -408,6 +443,12 @@ def write_wiring_markdown_report(ms, path, wiring, add_metadata=True):
408
443
  out += "\n"
409
444
  out += "\n"
410
445
 
446
+ out += "## All Spaces Used\n"
447
+ for i, x in enumerate(wiring.all_spaces_used):
448
+ out += "{}. [[{}]]".format(i + 1, x.name)
449
+ out += "\n"
450
+ out += "\n"
451
+
411
452
  out += "## Parameters Used\n"
412
453
  for i, x in enumerate(wiring.parameters_used):
413
454
  out += "{}. [[{}]]".format(i + 1, x)
@@ -426,6 +467,12 @@ def write_wiring_markdown_report(ms, path, wiring, add_metadata=True):
426
467
  out += "\n"
427
468
  out += "\n"
428
469
 
470
+ out += "## All State Updates\n"
471
+ for i, x in enumerate(wiring.all_updates):
472
+ out += "{}. [[{}]].{}".format(i + 1, x[0].name, x[1].name)
473
+ out += "\n"
474
+ out += "\n"
475
+
429
476
  with open("{}/Wiring/{}.md".format(path, wiring.name), "w") as f:
430
477
  f.write(out)
431
478
 
@@ -482,7 +529,7 @@ def write_stateful_metrics_markdown_report(ms, path, metric, add_metadata=True):
482
529
 
483
530
  out += "## Variables Used\n"
484
531
  for i, x in enumerate(metric.variables_used):
485
- out += "{}. {}.{}".format(i + 1, x[0], x[1])
532
+ out += "{}. [[{}]].{}".format(i + 1, x[0], x[1])
486
533
  out += "\n"
487
534
  out += "\n"
488
535
 
@@ -516,12 +563,18 @@ def write_metrics_markdown_report(ms, path, metric, add_metadata=True):
516
563
  out += "## Parameters Used\n"
517
564
  for i, x in enumerate(metric.parameters_used):
518
565
  out += "{}. [[{}]]".format(i + 1, x)
566
+ var = ms.parameters.parameter_map[x]
567
+ if var.symbol:
568
+ out += " , symbol: {}".format(var.symbol)
519
569
  out += "\n"
520
570
  out += "\n"
521
571
 
522
572
  out += "## Variables Used\n"
523
573
  for i, x in enumerate(metric.variables_used):
524
574
  out += "{}. {}.{}".format(i + 1, x[0], x[1])
575
+ var = ms.state[x[0]].variable_map[x[1]]
576
+ if var.symbol:
577
+ out += " , symbol: {}".format(var.symbol)
525
578
  out += "\n"
526
579
  out += "\n"
527
580
 
@@ -575,7 +628,7 @@ def write_wiring_display_markdown_report(ms, path, wiring, add_metadata=True):
575
628
  out += "\n"
576
629
 
577
630
  out += "## Unique Components Used\n"
578
- components = [set(x.components) for x in wirings]
631
+ components = [set(x.components_full()) for x in wirings]
579
632
  components = set().union(*components)
580
633
  for i, x in enumerate(components):
581
634
  out += "{}. [[{}]]".format(i + 1, x.name)
@@ -610,7 +663,26 @@ def write_wiring_display_markdown_report(ms, path, wiring, add_metadata=True):
610
663
  f.write(out)
611
664
 
612
665
 
613
- def write_all_markdown_reports(ms, path):
666
+ def write_all_markdown_reports(ms, path, clear_folders=False):
667
+ if clear_folders:
668
+ for x in [
669
+ "Metrics",
670
+ "Mechanisms",
671
+ "Types",
672
+ "Control Actions",
673
+ "Spaces",
674
+ ".obsidian",
675
+ "Boundary Actions",
676
+ "Policies",
677
+ "Wiring",
678
+ "States",
679
+ "Parameters",
680
+ "Entities",
681
+ "Stateful Metrics",
682
+ ]:
683
+ if os.path.exists("{}/{}".format(path, x)):
684
+ for y in os.listdir("{}/{}".format(path, x)):
685
+ os.remove("{}/{}/{}".format(path, x, y))
614
686
 
615
687
  # Write entities
616
688
  entities = list(ms.entities.keys())
@@ -26,3 +26,4 @@ from .Reports import (
26
26
  write_all_markdown_reports,
27
27
  )
28
28
  from .schema import schema
29
+ from .Convenience import write_top_level_json_description
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math_spec_mapping
3
- Version: 0.2.3
3
+ Version: 0.2.5
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
@@ -20,6 +20,7 @@ src/Classes/StatefulMetric.py
20
20
  src/Classes/Type.py
21
21
  src/Classes/__init__.py
22
22
  src/Convenience/__init__.py
23
+ src/Convenience/documentation.py
23
24
  src/Convenience/starter.py
24
25
  src/Load/__init__.py
25
26
  src/Load/action_transmission_channel.py
File without changes