math-spec-mapping 0.2.6.7__tar.gz → 0.2.7__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.2.6.7/src/math_spec_mapping.egg-info → math-spec-mapping-0.2.7}/PKG-INFO +1 -1
  2. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/pyproject.toml +1 -1
  3. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/ControlAction.py +1 -0
  4. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/MathSpec.py +98 -0
  5. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/Mechanism.py +1 -0
  6. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/Policy.py +1 -0
  7. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/Space.py +1 -0
  8. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/State.py +1 -0
  9. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/Type.py +1 -0
  10. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/control_actions.py +10 -0
  11. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/mechanism.py +8 -0
  12. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/policy.py +11 -2
  13. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/type.py +1 -0
  14. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/html.py +33 -1
  15. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7/src/math_spec_mapping.egg-info}/PKG-INFO +1 -1
  16. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/LICENSE +0 -0
  17. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/README.md +0 -0
  18. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/setup.cfg +0 -0
  19. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/ActionTransmissionChannel.py +0 -0
  20. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/Block.py +0 -0
  21. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/BoundaryAction.py +0 -0
  22. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/Entity.py +0 -0
  23. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/Metric.py +0 -0
  24. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/Parameter.py +0 -0
  25. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/StateUpdateTransmissionChannel.py +0 -0
  26. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/StatefulMetric.py +0 -0
  27. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Classes/__init__.py +0 -0
  28. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Convenience/__init__.py +0 -0
  29. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Convenience/documentation.py +0 -0
  30. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Convenience/starter.py +0 -0
  31. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/__init__.py +0 -0
  32. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/action_transmission_channel.py +0 -0
  33. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/boundary_actions.py +0 -0
  34. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/displays.py +0 -0
  35. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/entities.py +0 -0
  36. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/general.py +0 -0
  37. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/implementations.py +0 -0
  38. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/load.py +0 -0
  39. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/metrics.py +0 -0
  40. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/parameters.py +0 -0
  41. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/spaces.py +0 -0
  42. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/state_update_transmission_channels.py +0 -0
  43. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/stateful_metrics.py +0 -0
  44. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/states.py +0 -0
  45. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Load/wiring.py +0 -0
  46. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/__init__.py +0 -0
  47. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/boundary_actions.py +0 -0
  48. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/control_actions.py +0 -0
  49. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/general.py +0 -0
  50. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/markdown.py +0 -0
  51. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/mechanisms.py +0 -0
  52. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/node_map.py +0 -0
  53. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/parameters.py +0 -0
  54. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/policies.py +0 -0
  55. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/spaces.py +0 -0
  56. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/state.py +0 -0
  57. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/tables.py +0 -0
  58. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/Reports/wiring.py +0 -0
  59. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/__init__.py +0 -0
  60. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/schema.py +0 -0
  61. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping/schema.schema.json +0 -0
  62. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping.egg-info/SOURCES.txt +0 -0
  63. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping.egg-info/dependency_links.txt +0 -0
  64. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/src/math_spec_mapping.egg-info/requires.txt +0 -0
  65. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.7}/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.2.6.7
3
+ Version: 0.2.7
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.6.7"
6
+ version = "0.2.7"
7
7
  authors = [
8
8
  { name="Sean McOwen", email="Sean@Block.Science" },
9
9
  ]
@@ -15,3 +15,4 @@ class ControlActionOption:
15
15
  self.name = data["name"]
16
16
  self.description = data["description"]
17
17
  self.logic = data["logic"]
18
+ self.implementations = data["implementations"]
@@ -4,6 +4,7 @@ from .Policy import Policy
4
4
  from .Mechanism import Mechanism
5
5
  from .ControlAction import ControlAction
6
6
  from .BoundaryAction import BoundaryAction
7
+ import os
7
8
 
8
9
 
9
10
  class MathSpec:
@@ -12,6 +13,7 @@ class MathSpec:
12
13
  self._ms_dict = ms_dict
13
14
  self._json = json
14
15
  self.type_keys = ms_dict["Type Keys"]
16
+ self.implementations = ms_dict["Implementations"]
15
17
  self.action_transmission_channels = ms_dict["Action Transmission Channels"]
16
18
  self.boundary_actions = ms_dict["Boundary Actions"]
17
19
  self.control_actions = ms_dict["Control Actions"]
@@ -349,3 +351,99 @@ class MathSpec:
349
351
  for metrics in self.stateful_metrics.values():
350
352
  sm.extend([x.name for x in metrics.metrics])
351
353
  return sm
354
+
355
+ def metaprogramming_python_types(self, model_directory, overwrite=False):
356
+ path = model_directory + "/types.py"
357
+ if not overwrite:
358
+ assert "types.py" not in os.listdir(
359
+ model_directory
360
+ ), "The types file is already written, either delete it or switch to overwrite mode"
361
+ out = "import typing\n\n"
362
+ for t in self.types:
363
+ t = self.types[t]
364
+ assert "python" in t.type, "No python type associated with {}".format(
365
+ t.name
366
+ )
367
+ x = t.type["python"]
368
+ type_desc = x.__name__ if hasattr(x, "__name__") else str(x)
369
+ out += "{} = {}".format(t.original_type_name, type_desc)
370
+ out += "\n"
371
+ with open(path, "w") as f:
372
+ f.write(out)
373
+
374
+ def metaprogramming_python_spaces(self, model_directory, overwrite=False):
375
+ path = model_directory + "/spaces.py"
376
+ if not overwrite:
377
+ assert "spaces.py" not in os.listdir(
378
+ model_directory
379
+ ), "The spaces file is already written, either delete it or switch to overwrite mode"
380
+ unique_spaces = set().union(
381
+ *[set(x.schema.values()) for x in self.spaces.values()]
382
+ )
383
+ unique_types = [x.original_type_name for x in unique_spaces]
384
+ out = ""
385
+ out += "from .types import {}".format(", ".join(unique_types))
386
+ out += "\n"
387
+ out += "from typing import TypedDict"
388
+ out += "\n"
389
+ out += "\n"
390
+
391
+ for space in self.spaces:
392
+ out += self.spaces[space].name_variable
393
+ out += " = "
394
+ d = self.spaces[space].schema
395
+ d = [(x, d[x].original_type_name) for x in d]
396
+ d = ["'{}': {}".format(x[0], x[1]) for x in d]
397
+ d = ", ".join(d)
398
+ d = "{" + d + "}"
399
+ out += "TypedDict('{}', {})".format(self.spaces[space].name, d)
400
+ out += "\n"
401
+
402
+ with open(path, "w") as f:
403
+ f.write(out)
404
+
405
+ def metaprogramming_python_states(
406
+ self, model_directory, overwrite=False, default_values=None
407
+ ):
408
+ path = model_directory + "/states.py"
409
+ if not overwrite:
410
+ assert "states.py" not in os.listdir(
411
+ model_directory
412
+ ), "The states file is already written, either delete it or switch to overwrite mode"
413
+ out = ""
414
+ unique_types = [x.variables for x in self.state.values()]
415
+ unique_types = [set(y.type.original_type_name for y in x) for x in unique_types]
416
+ unique_types = set().union(*unique_types)
417
+ out = ""
418
+ out += "from .types import {}".format(", ".join(unique_types))
419
+ out += "\n"
420
+ out += "from typing import TypedDict"
421
+ out += "\n"
422
+ out += "\n"
423
+
424
+ for state in self.state:
425
+ out += self.state[state].name_variable
426
+ out += " = "
427
+ d = self.state[state].variables
428
+ d = [(x.name, x.type.original_type_name) for x in d]
429
+ d = ["'{}': {}".format(x[0], x[1]) for x in d]
430
+ d = ", ".join(d)
431
+ d = "{" + d + "}"
432
+ out += "TypedDict('{}', {})".format(self.state[state].name, d)
433
+ out += "\n"
434
+ out += "\n"
435
+ out += "state: GlobalState = "
436
+ out += "{"
437
+ for x in self.state["Global State"].variables:
438
+ out += '"{}"'.format(x.name)
439
+ out += ": "
440
+ val = "None"
441
+ if default_values:
442
+ if x.name in default_values:
443
+ val = str(default_values[x.name])
444
+ out += val
445
+ out += ",\n"
446
+ out += "}"
447
+
448
+ with open(path, "w") as f:
449
+ f.write(out)
@@ -10,3 +10,4 @@ class Mechanism(Block):
10
10
  self.logic = data["logic"]
11
11
  self.updates = []
12
12
  self.block_type = "Mechanism"
13
+ self.implementations = data["implementations"]
@@ -7,6 +7,7 @@ class PolicyOption:
7
7
  self.name = data["name"]
8
8
  self.description = data["description"]
9
9
  self.logic = data["logic"]
10
+ self.implementations = data["implementations"]
10
11
 
11
12
 
12
13
  class Policy(Block):
@@ -6,6 +6,7 @@ class Space:
6
6
  self.name = data["name"]
7
7
  self.schema = data["schema"]
8
8
  self.metadata = data["metadata"]
9
+ self.name_variable = self.name.replace(" ", "").replace("-", "_")
9
10
 
10
11
  def __repr__(self):
11
12
  return self.name
@@ -15,6 +15,7 @@ class State:
15
15
  self._write_variable_map()
16
16
  self.updated_by = []
17
17
  self.metadata = data["metadata"]
18
+ self.name_variable = self.name.replace(" ", "").replace("-", "_")
18
19
 
19
20
  def _write_variable_map(self) -> None:
20
21
  """
@@ -6,3 +6,4 @@ class Type:
6
6
  self.type_name = data["type_name"]
7
7
  self.notes = data["notes"]
8
8
  self.metadata = data["metadata"]
9
+ self.original_type_name = data["original_type_name"]
@@ -35,6 +35,16 @@ def convert_control_action(data: Dict, ms: Dict) -> ControlAction:
35
35
  new_cao = []
36
36
  for ca in data["control_action_options"]:
37
37
  check_json_keys(ca, "Control Action Option")
38
+ ca["implementations"] = {}
39
+ if "python" in ms["Implementations"]:
40
+ if "control_action_options" in ms["Implementations"]["python"]:
41
+ if (
42
+ ca["name"]
43
+ in ms["Implementations"]["python"]["control_action_options"]
44
+ ):
45
+ ca["implementations"]["python"] = ms["Implementations"]["python"][
46
+ "control_action_options"
47
+ ][ca["name"]]
38
48
  new_cao.append(ControlActionOption(ca))
39
49
  data["control_action_options"] = new_cao
40
50
 
@@ -42,6 +42,14 @@ def convert_mechanism(data: Dict, ms: Dict) -> Mechanism:
42
42
  )
43
43
 
44
44
  data["domain"] = tuple(ms["Spaces"][x] for x in data["domain"])
45
+ data["implementations"] = {}
46
+
47
+ if "python" in ms["Implementations"]:
48
+ if "mechanisms" in ms["Implementations"]["python"]:
49
+ if data["name"] in ms["Implementations"]["python"]["mechanisms"]:
50
+ data["implementations"]["python"] = ms["Implementations"]["python"][
51
+ "mechanisms"
52
+ ][data["name"]]
45
53
 
46
54
  # Build the action transmission channel object
47
55
  return Mechanism(data), new_channels
@@ -5,7 +5,7 @@ from ..Classes import Policy, PolicyOption
5
5
  from .general import check_json_keys
6
6
 
7
7
 
8
- def convert_policy_options(data: Dict) -> PolicyOption:
8
+ def convert_policy_options(data: Dict, ms) -> PolicyOption:
9
9
  """Function to convert policy options
10
10
 
11
11
  Args:
@@ -21,6 +21,15 @@ def convert_policy_options(data: Dict) -> PolicyOption:
21
21
  # Copy
22
22
  data = data.copy()
23
23
 
24
+ data["implementations"] = {}
25
+
26
+ if "python" in ms["Implementations"]:
27
+ if "policies" in ms["Implementations"]["python"]:
28
+ if data["name"] in ms["Implementations"]["python"]["policies"]:
29
+ data["implementations"]["python"] = ms["Implementations"]["python"][
30
+ "policies"
31
+ ][data["name"]]
32
+
24
33
  # Build the policy object
25
34
  return PolicyOption(data)
26
35
 
@@ -62,7 +71,7 @@ def convert_policy(data: Dict, ms: Dict) -> Policy:
62
71
  # Convert policy options
63
72
  policy_options = []
64
73
  for po in data["policy_options"]:
65
- policy_options.append(convert_policy_options(po))
74
+ policy_options.append(convert_policy_options(po, ms))
66
75
  data["policy_options"] = policy_options
67
76
 
68
77
  data["codomain"] = tuple(ms["Spaces"][x] for x in data["codomain"])
@@ -18,6 +18,7 @@ def convert_type(data, ms):
18
18
  type_name = data["type"]
19
19
  data["type"] = {}
20
20
  data["type_name"] = {}
21
+ data["original_type_name"] = type_name
21
22
 
22
23
  if "python" in ms["Type Keys"]:
23
24
 
@@ -9,6 +9,7 @@ from .node_map import create_action_chains_graph
9
9
  from .parameters import write_out_params
10
10
  from .state import write_local_state_variable_tables, write_global_state_variable_table
11
11
  from typing import List
12
+ import os
12
13
 
13
14
 
14
15
  def write_basic_report_full(ms: MathSpec, directory: str, name: str) -> None:
@@ -128,6 +129,15 @@ def write_spec_tree(
128
129
  symbol3 = "│ │ ├──"
129
130
 
130
131
  out = ""
132
+
133
+ if linking:
134
+ out += """---
135
+ cssclasses:
136
+ - spec
137
+ ---
138
+
139
+ """
140
+
131
141
  out += symbol1 + "**Entities**\n"
132
142
  for name in ms.entities.keys():
133
143
  if linking:
@@ -214,7 +224,29 @@ def write_spec_tree(
214
224
  if path:
215
225
  with open("{}/Spec Tree.md".format(path), "w") as f:
216
226
  f.write(out)
217
- return out
227
+ try:
228
+ if ".obsidian" not in os.listdir(path):
229
+ path = path + "/" + ".obsidian"
230
+ os.mkdir(path)
231
+ else:
232
+ path = path + "/" + ".obsidian"
233
+ if "snippets" not in os.listdir(path):
234
+ path = path + "/" + "snippets"
235
+ os.mkdir(path)
236
+ else:
237
+ path = path + "/" + "snippets"
238
+
239
+ snippet = """.spec {
240
+ font-family: 'Consolas', Courier, monospace ;
241
+ line-height: 1;
242
+ }"""
243
+ with open("{}/spec.css".format(path), "w") as f:
244
+ f.write(snippet)
245
+
246
+ except:
247
+ print("Couldn't find .obsidian/snippets to put snippet in")
248
+ else:
249
+ return out
218
250
 
219
251
 
220
252
  def write_overview(ms: MathSpec, name: str, file_path: str, summary: str = None):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.2.6.7
3
+ Version: 0.2.7
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