math-spec-mapping 0.3.19__tar.gz → 0.3.21__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. {math_spec_mapping-0.3.19/src/math_spec_mapping.egg-info → math_spec_mapping-0.3.21}/PKG-INFO +11 -31
  2. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/README.md +10 -30
  3. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/pyproject.toml +1 -1
  4. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/Block.py +3 -3
  5. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/MathSpec.py +66 -4
  6. math_spec_mapping-0.3.21/src/math_spec_mapping/Classes/Space.py +33 -0
  7. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/Type.py +3 -0
  8. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/spaces.py +3 -0
  9. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/spec_tree.py +28 -7
  10. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/stateful_metrics.py +2 -2
  11. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/markdown.py +11 -2
  12. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/schema.schema.json +3 -0
  13. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21/src/math_spec_mapping.egg-info}/PKG-INFO +11 -31
  14. math_spec_mapping-0.3.19/src/math_spec_mapping/Classes/Space.py +0 -18
  15. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/LICENSE +0 -0
  16. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/setup.cfg +0 -0
  17. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/ActionTransmissionChannel.py +0 -0
  18. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/BoundaryAction.py +0 -0
  19. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/ControlAction.py +0 -0
  20. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/Entity.py +0 -0
  21. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/Mechanism.py +0 -0
  22. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/Metric.py +0 -0
  23. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/Parameter.py +0 -0
  24. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/Policy.py +0 -0
  25. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/State.py +0 -0
  26. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/StateUpdateTransmissionChannel.py +0 -0
  27. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/StatefulMetric.py +0 -0
  28. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Classes/__init__.py +0 -0
  29. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Convenience/__init__.py +0 -0
  30. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Convenience/documentation.py +0 -0
  31. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Convenience/github.py +0 -0
  32. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Convenience/starter.py +0 -0
  33. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/__init__.py +0 -0
  34. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/action_transmission_channel.py +0 -0
  35. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/boundary_actions.py +0 -0
  36. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/control_actions.py +0 -0
  37. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/displays.py +0 -0
  38. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/entities.py +0 -0
  39. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/general.py +0 -0
  40. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/implementations.py +0 -0
  41. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/load.py +0 -0
  42. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/mechanism.py +0 -0
  43. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/metrics.py +0 -0
  44. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/parameters.py +0 -0
  45. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/policy.py +0 -0
  46. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/state_update_transmission_channels.py +0 -0
  47. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/states.py +0 -0
  48. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/type.py +0 -0
  49. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Load/wiring.py +0 -0
  50. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/__init__.py +0 -0
  51. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/boundary_actions.py +0 -0
  52. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/control_actions.py +0 -0
  53. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/general.py +0 -0
  54. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/html.py +0 -0
  55. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/mechanisms.py +0 -0
  56. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/node_map.py +0 -0
  57. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/parameters.py +0 -0
  58. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/policies.py +0 -0
  59. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/spaces.py +0 -0
  60. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/state.py +0 -0
  61. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/tables.py +0 -0
  62. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/Reports/wiring.py +0 -0
  63. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/__init__.py +0 -0
  64. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping/schema.py +0 -0
  65. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping.egg-info/SOURCES.txt +0 -0
  66. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping.egg-info/dependency_links.txt +0 -0
  67. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/src/math_spec_mapping.egg-info/requires.txt +0 -0
  68. {math_spec_mapping-0.3.19 → math_spec_mapping-0.3.21}/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.19
3
+ Version: 0.3.21
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
@@ -13,7 +13,9 @@ Requires-Dist: graphviz>=0.20.1
13
13
  Requires-Dist: ipython>=7.7.0
14
14
  Requires-Dist: pandas>=1.4
15
15
 
16
- # MSML
16
+ # Mathematical Specification Mapping Library (MSML)
17
+
18
+ For documentation and getting started with MSML, please refer to the site for MSML [here](https://blockscience.github.io/MSML/).
17
19
 
18
20
  ## What is the Mathematical Specification Mapping Library (MSML)?
19
21
 
@@ -21,7 +23,7 @@ MSML is a library for standardizing the creation of mathematical specifications
21
23
 
22
24
  It uses block diagram wirings and spaces to represent the actions in complex systems in line with current BlockScience research on Generalized Dynamical Systems. It also adds some enhancements to the primitive blocks to represent richer sets of behaviors.
23
25
 
24
- One good example is the [wiring report](https://github.com/SeanMcOwen/Root-Finding-Simulation/blob/main/MSML/reports/Simulation%20Block.md) for the Root Finding Simulation canonical example.
26
+ One good example is the [wiring report](https://github.com/BlockScience/Predator-Prey-MSML/blob/main/reports/obsidian/Wiring/Hunt%20Prey%20Wiring.md) for hunt prey wiring in the predator prey example (although it is best viewed in Obsidian where all the linking will work).
25
27
 
26
28
  ## Installing the library
27
29
 
@@ -31,6 +33,12 @@ To install the library, simply pip install by running "pip install math_spec_map
31
33
 
32
34
  Writing mathematical specifications can be a difficult process, especially when variable names are changed or new mechanisms are introduced. MSML seeks to streamline the process with automations as well as enhance the abilities of static math specs to deliver deeper insights. Because it is automated, one can write specifications at different levels of details or for different purposes.
33
35
 
36
+ ### Stakeholder Communications
37
+
38
+ - In organizations, senior people / non-developers don't always have as intimate a view of the underlying code as the primary developers in a system because of time constraints and not working as directly with the code as the primary developers
39
+ - Often this means that there is a reliance on asking the primary developers for clarifications and relying on "front-end" kinds of stuff such as visualizations or outputs of the model as opposed to combing through the underlying code
40
+ - MSML seeks to help bridge this gap by allowing for the Obsidian markdown vault that can showcase every component and its dependencies for easier consumption.... this reduces the barriers to entry on understanding the back-end/underlying model
41
+ - Also through things such as code linking, MSML allows for those with code fluency to jump into underlying code if they need to without even opening up the actual project repository
34
42
 
35
43
  ## What are some of the solutions offered?
36
44
 
@@ -79,34 +87,6 @@ Thanks to some of the more advanced features, MSML can be used as an aid for deb
79
87
 
80
88
  The ability to fork the repository of an MSML spec as well as the ability to use it for A/B testing with the policy options makes it well suited for iterating on model evolution.
81
89
 
82
- ## Technical Details
83
-
84
- The documentation on the technical details of using the MSML can be found [here](https://github.com/BlockScience/MSML/tree/main/docs)
85
-
86
- ## Canonical Examples
87
-
88
- [Dummy/Starter Repository](https://github.com/BlockScience/MSML/tree/main/examples/StarterRepo)
89
- [Root Finding Simulation](https://github.com/SeanMcOwen/Root-Finding-Simulation)
90
-
91
- ### Comparison of Canonical Example Features
92
-
93
- | Feature | Dummy | Root Finding |
94
- | --- | --- | --- |
95
- | Action Transmission Channels | X | X |
96
- | Stack Block | X | X |
97
- | Parallel Block | | X |
98
- | Split Block | | |
99
- | Boundary Actions | X | |
100
- | Control Actions | X | X |
101
- | Entities | X | |
102
- | Mechanisms | X | X |
103
- | Parameters | X | X |
104
- | Policies | X | X |
105
- | Spaces | X | X |
106
- | State | X | X |
107
- | Stateful Metrics | | |
108
- | State Update Transmission Channels | X | X |
109
- | Reports | X | X |
110
90
 
111
91
  ## Other Related Repositories
112
92
 
@@ -1,4 +1,6 @@
1
- # MSML
1
+ # Mathematical Specification Mapping Library (MSML)
2
+
3
+ For documentation and getting started with MSML, please refer to the site for MSML [here](https://blockscience.github.io/MSML/).
2
4
 
3
5
  ## What is the Mathematical Specification Mapping Library (MSML)?
4
6
 
@@ -6,7 +8,7 @@ MSML is a library for standardizing the creation of mathematical specifications
6
8
 
7
9
  It uses block diagram wirings and spaces to represent the actions in complex systems in line with current BlockScience research on Generalized Dynamical Systems. It also adds some enhancements to the primitive blocks to represent richer sets of behaviors.
8
10
 
9
- One good example is the [wiring report](https://github.com/SeanMcOwen/Root-Finding-Simulation/blob/main/MSML/reports/Simulation%20Block.md) for the Root Finding Simulation canonical example.
11
+ One good example is the [wiring report](https://github.com/BlockScience/Predator-Prey-MSML/blob/main/reports/obsidian/Wiring/Hunt%20Prey%20Wiring.md) for hunt prey wiring in the predator prey example (although it is best viewed in Obsidian where all the linking will work).
10
12
 
11
13
  ## Installing the library
12
14
 
@@ -16,6 +18,12 @@ To install the library, simply pip install by running "pip install math_spec_map
16
18
 
17
19
  Writing mathematical specifications can be a difficult process, especially when variable names are changed or new mechanisms are introduced. MSML seeks to streamline the process with automations as well as enhance the abilities of static math specs to deliver deeper insights. Because it is automated, one can write specifications at different levels of details or for different purposes.
18
20
 
21
+ ### Stakeholder Communications
22
+
23
+ - In organizations, senior people / non-developers don't always have as intimate a view of the underlying code as the primary developers in a system because of time constraints and not working as directly with the code as the primary developers
24
+ - Often this means that there is a reliance on asking the primary developers for clarifications and relying on "front-end" kinds of stuff such as visualizations or outputs of the model as opposed to combing through the underlying code
25
+ - MSML seeks to help bridge this gap by allowing for the Obsidian markdown vault that can showcase every component and its dependencies for easier consumption.... this reduces the barriers to entry on understanding the back-end/underlying model
26
+ - Also through things such as code linking, MSML allows for those with code fluency to jump into underlying code if they need to without even opening up the actual project repository
19
27
 
20
28
  ## What are some of the solutions offered?
21
29
 
@@ -64,34 +72,6 @@ Thanks to some of the more advanced features, MSML can be used as an aid for deb
64
72
 
65
73
  The ability to fork the repository of an MSML spec as well as the ability to use it for A/B testing with the policy options makes it well suited for iterating on model evolution.
66
74
 
67
- ## Technical Details
68
-
69
- The documentation on the technical details of using the MSML can be found [here](https://github.com/BlockScience/MSML/tree/main/docs)
70
-
71
- ## Canonical Examples
72
-
73
- [Dummy/Starter Repository](https://github.com/BlockScience/MSML/tree/main/examples/StarterRepo)
74
- [Root Finding Simulation](https://github.com/SeanMcOwen/Root-Finding-Simulation)
75
-
76
- ### Comparison of Canonical Example Features
77
-
78
- | Feature | Dummy | Root Finding |
79
- | --- | --- | --- |
80
- | Action Transmission Channels | X | X |
81
- | Stack Block | X | X |
82
- | Parallel Block | | X |
83
- | Split Block | | |
84
- | Boundary Actions | X | |
85
- | Control Actions | X | X |
86
- | Entities | X | |
87
- | Mechanisms | X | X |
88
- | Parameters | X | X |
89
- | Policies | X | X |
90
- | Spaces | X | X |
91
- | State | X | X |
92
- | Stateful Metrics | | |
93
- | State Update Transmission Channels | X | X |
94
- | Reports | X | X |
95
75
 
96
76
  ## Other Related Repositories
97
77
 
@@ -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.19"
6
+ version = "0.3.21"
7
7
  authors = [
8
8
  { name="Sean McOwen", email="Sean@Block.Science" },
9
9
  ]
@@ -75,7 +75,7 @@ class Block:
75
75
  if self.block_type == "Mechanism":
76
76
  for u in sorted(self.updates, key=lambda x: x[0].name + "-" + x[1].name):
77
77
  out += "\n"
78
- out += "X{} --> {}".format(
78
+ out += 'X{} --"State Update"--> {}'.format(
79
79
  i,
80
80
  (u[0].name + "-" + u[1].name).replace(" ", "-"),
81
81
  )
@@ -248,7 +248,7 @@ class ParallelBlock(Block):
248
248
  self.all_updates, key=lambda x: x[0].name + "-" + x[1].name
249
249
  ):
250
250
  out += "\n"
251
- out += "X{} --> {}".format(
251
+ out += 'X{} --"State Update"--> {}'.format(
252
252
  i,
253
253
  (u[0].name + "-" + u[1].name).replace(" ", "-"),
254
254
  )
@@ -445,7 +445,7 @@ class StackBlock(Block):
445
445
  self.all_updates, key=lambda x: x[0].name + "-" + x[1].name
446
446
  ):
447
447
  out += "\n"
448
- out += "X{} --> {}".format(
448
+ out += 'X{} --"State Update"--> {}'.format(
449
449
  i,
450
450
  (u[0].name + "-" + u[1].name).replace(" ", "-"),
451
451
  )
@@ -8,7 +8,7 @@ import os
8
8
  from copy import deepcopy
9
9
  import shutil
10
10
  import pandas as pd
11
- from inspect import signature, getsource, getfile
11
+ from inspect import signature, getsource, getfile, getsourcelines
12
12
  from IPython.display import display, Markdown
13
13
 
14
14
 
@@ -971,23 +971,31 @@ using .Spaces: generate_space_type
971
971
  with open(path, "w") as f:
972
972
  f.write(out)
973
973
 
974
- def build_implementation(self, params):
975
- return MathSpecImplementation(self, params)
974
+ def build_implementation(self, params, domain_codomain_checking=False):
975
+ return MathSpecImplementation(
976
+ self, params, domain_codomain_checking=domain_codomain_checking
977
+ )
976
978
 
977
979
  def _set_source_code(self):
978
980
  if "python" not in self.implementations:
979
981
  self.source_code = None
980
982
  return
981
983
  self.source_code = deepcopy(self.implementations["python"])
984
+ self.source_code_lines = {}
982
985
  for x in self.source_code:
986
+ self.source_code_lines[x] = {}
983
987
  for y in self.source_code[x]:
988
+ self.source_code_lines[x][y] = "#L{}".format(
989
+ getsourcelines(self.source_code[x][y])[1]
990
+ )
984
991
  self.source_code[x][y] = getsource(self.source_code[x][y])
985
992
 
986
993
 
987
994
  class MathSpecImplementation:
988
- def __init__(self, ms: MathSpec, params):
995
+ def __init__(self, ms: MathSpec, params, domain_codomain_checking):
989
996
  self.ms = deepcopy(ms)
990
997
  self.params = params
998
+ self.domain_codomain_checking = domain_codomain_checking
991
999
  self.control_actions = self.load_control_actions()
992
1000
  self.boundary_actions = self.load_boundary_actions()
993
1001
  self.policies = self.load_policies()
@@ -1323,6 +1331,60 @@ class MathSpecImplementation:
1323
1331
  self.components.update(self.mechanisms)
1324
1332
  self.components.update(self.wiring)
1325
1333
 
1334
+ self.components_enhanced = {}
1335
+
1336
+ def create_wrapper(component, domain_codomain_checking):
1337
+ def wrapper(
1338
+ state,
1339
+ params,
1340
+ spaces,
1341
+ domain_codomain_checking=self.domain_codomain_checking,
1342
+ ):
1343
+ domain = spaces
1344
+
1345
+ # Domain Checking
1346
+ if domain_codomain_checking:
1347
+ prototype_spaces = self.ms.blocks[component].domain
1348
+ prototype_spaces = [
1349
+ x.schema for x in prototype_spaces if x.name != "Empty Space"
1350
+ ]
1351
+ assert len(prototype_spaces) == len(
1352
+ domain
1353
+ ), "Length of domain incorrect for {}".format(component)
1354
+ for space1, space2 in zip(domain, prototype_spaces):
1355
+ assert set(space1.keys()) == set(
1356
+ space2.keys()
1357
+ ), "Keys for domain schema of {} is not matched by {} in {} component".format(
1358
+ set(space2.keys()), set(space1.keys()), component
1359
+ )
1360
+
1361
+ codomain = self.components[component](state, params, spaces)
1362
+
1363
+ # Codomain Checking
1364
+ if domain_codomain_checking and codomain:
1365
+ prototype_spaces = self.ms.blocks[component].codomain
1366
+ prototype_spaces = [
1367
+ x.schema for x in prototype_spaces if x.name != "Empty Space"
1368
+ ]
1369
+ assert len(prototype_spaces) == len(
1370
+ codomain
1371
+ ), "Length of codomain incorrect for {}".format(component)
1372
+ for space1, space2 in zip(codomain, prototype_spaces):
1373
+ assert set(space1.keys()) == set(
1374
+ space2.keys()
1375
+ ), "Keys for codomain schema of {} is not matched by {} in {} component".format(
1376
+ set(space2.keys()), set(space1.keys()), component
1377
+ )
1378
+ return codomain
1379
+
1380
+ return wrapper
1381
+
1382
+ for component in self.components:
1383
+
1384
+ self.components_enhanced[component] = create_wrapper(
1385
+ component, self.domain_codomain_checking
1386
+ )
1387
+
1326
1388
  def execute_blocks(self, state, params, blocks):
1327
1389
  for block in blocks:
1328
1390
  self.components[block](state, params, [])
@@ -0,0 +1,33 @@
1
+ from typing import Dict
2
+
3
+
4
+ class Space:
5
+ def __init__(self, data: Dict):
6
+ self.name = data["name"]
7
+ self.schema = data["schema"]
8
+ self.metadata = data["metadata"]
9
+ self.description = data["description"]
10
+ self.name_variable = self.name.replace(" ", "").replace("-", "_")
11
+ self.domain_blocks = []
12
+ self.codomain_blocks = []
13
+
14
+ def __repr__(self):
15
+ return self.name
16
+
17
+
18
+ TerminatingSpace = Space(
19
+ {
20
+ "name": "Terminating Space",
21
+ "schema": {},
22
+ "metadata": {},
23
+ "description": "Built-in space for denoting termination of block",
24
+ }
25
+ )
26
+ EmptySpace = Space(
27
+ {
28
+ "name": "Empty Space",
29
+ "schema": {},
30
+ "metadata": {},
31
+ "description": "Built-in space for denoting returning no data",
32
+ }
33
+ )
@@ -7,3 +7,6 @@ class Type:
7
7
  self.notes = data["notes"]
8
8
  self.metadata = data["metadata"]
9
9
  self.original_type_name = data["original_type_name"]
10
+
11
+ def __repr__(self):
12
+ return self.name
@@ -20,6 +20,9 @@ def convert_space(ms, data: Dict) -> Space:
20
20
  )
21
21
  data["schema"][x] = ms["Types"][data["schema"][x]]
22
22
 
23
+ if "description" not in data:
24
+ data["description"] = None
25
+
23
26
  # Build the space object
24
27
  return Space(data)
25
28
 
@@ -2,6 +2,18 @@ import ast
2
2
  import os
3
3
 
4
4
 
5
+ def index_to_line_and_column(lines, index):
6
+ cumulative_length = 0
7
+ for line_number, line in enumerate(lines):
8
+ line_length = len(line) + 1 # +1 for the newline character
9
+ if cumulative_length + line_length > index:
10
+ column = index - cumulative_length
11
+ return line_number, column
12
+ cumulative_length += line_length
13
+
14
+ raise ValueError("Index out of range")
15
+
16
+
5
17
  def load_spec_tree(path, ms):
6
18
  tree = {}
7
19
  for folder in [
@@ -61,11 +73,20 @@ def load_spec_tree(path, ms):
61
73
  assert False, "Not implemented for imports that are not import from"
62
74
  elif isinstance(node, ast.ImportFrom):
63
75
  if node.module:
64
- for name in node.names:
65
- file_path = "{}/{}/{}.py".format(path, folder, node.module)
66
- with open(file_path, "r") as file2:
67
- contents = file2.read()
68
- for key in keys:
69
- if key in contents:
70
- tree[folder][key] = os.path.abspath(file_path)
76
+ file_path = "{}/{}/{}.py".format(path, folder, node.module)
77
+
78
+ with open(file_path, "r") as file2:
79
+ contents = file2.read()
80
+ split = contents.split("\n")
81
+ for key in keys:
82
+ if key in contents:
83
+ line_number = (
84
+ index_to_line_and_column(
85
+ split, contents.index(key)
86
+ )[0]
87
+ + 1
88
+ )
89
+ tree[folder][key] = os.path.abspath(
90
+ file_path
91
+ ) + "#L{}".format(line_number)
71
92
  return tree
@@ -41,8 +41,8 @@ def convert_stateful_metric(ms, data: Dict) -> StatefulMetricSet:
41
41
  )
42
42
 
43
43
  assert (
44
- var["type"] in ms["Types"]
45
- ), "{} type referenced by {} is not present in math spec".format(
44
+ var["type"] in ms["Types"] or var["type"] in ms["Spaces"]
45
+ ), "{} type/space referenced by {} is not present in math spec".format(
46
46
  var["type"], var["name"]
47
47
  )
48
48
 
@@ -1,6 +1,6 @@
1
1
  import os
2
2
  from .state import write_state_section
3
- from inspect import signature, getsource, getfile
3
+ from inspect import signature, getsource, getfile, getsourcelines
4
4
 
5
5
 
6
6
  def get_source_code(
@@ -16,7 +16,7 @@ def get_source_code(
16
16
  {}```""".format(
17
17
  getsource(code)
18
18
  )
19
- file_path = getfile(code)
19
+ file_path = getfile(code) + "#L{}".format(getsourcelines(code)[1])
20
20
  return source_code, file_path
21
21
 
22
22
 
@@ -437,6 +437,13 @@ def write_space_markdown_report(ms, path, space, add_metadata=True):
437
437
  "\n".join(["{}: {}".format(x, metadata[x]) for x in metadata])
438
438
  )
439
439
 
440
+ if space.description:
441
+ out += "## Description"
442
+ out += "\n"
443
+ out += space.description
444
+ out += "\n"
445
+ out += "\n"
446
+
440
447
  out += "## Schema"
441
448
  out += "\n"
442
449
  out += "\n"
@@ -858,6 +865,8 @@ def write_state_variables_markdown_reports(ms, path, state, add_metadata=True):
858
865
  out += "Description: "
859
866
  out += variable.description
860
867
  out += "\n\n"
868
+ out += "Underlying state: [[{}]]".format(state.name)
869
+ out += "\n\n"
861
870
  out += "Type: [["
862
871
  out += variable.type.name
863
872
  out += "]]\n\n"
@@ -441,6 +441,9 @@
441
441
  "name": {
442
442
  "type": "string"
443
443
  },
444
+ "description": {
445
+ "type": "string"
446
+ },
444
447
  "schema": {
445
448
  "$ref": "./schema.schema.json/#/definitions/Schema"
446
449
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.3.19
3
+ Version: 0.3.21
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
@@ -13,7 +13,9 @@ Requires-Dist: graphviz>=0.20.1
13
13
  Requires-Dist: ipython>=7.7.0
14
14
  Requires-Dist: pandas>=1.4
15
15
 
16
- # MSML
16
+ # Mathematical Specification Mapping Library (MSML)
17
+
18
+ For documentation and getting started with MSML, please refer to the site for MSML [here](https://blockscience.github.io/MSML/).
17
19
 
18
20
  ## What is the Mathematical Specification Mapping Library (MSML)?
19
21
 
@@ -21,7 +23,7 @@ MSML is a library for standardizing the creation of mathematical specifications
21
23
 
22
24
  It uses block diagram wirings and spaces to represent the actions in complex systems in line with current BlockScience research on Generalized Dynamical Systems. It also adds some enhancements to the primitive blocks to represent richer sets of behaviors.
23
25
 
24
- One good example is the [wiring report](https://github.com/SeanMcOwen/Root-Finding-Simulation/blob/main/MSML/reports/Simulation%20Block.md) for the Root Finding Simulation canonical example.
26
+ One good example is the [wiring report](https://github.com/BlockScience/Predator-Prey-MSML/blob/main/reports/obsidian/Wiring/Hunt%20Prey%20Wiring.md) for hunt prey wiring in the predator prey example (although it is best viewed in Obsidian where all the linking will work).
25
27
 
26
28
  ## Installing the library
27
29
 
@@ -31,6 +33,12 @@ To install the library, simply pip install by running "pip install math_spec_map
31
33
 
32
34
  Writing mathematical specifications can be a difficult process, especially when variable names are changed or new mechanisms are introduced. MSML seeks to streamline the process with automations as well as enhance the abilities of static math specs to deliver deeper insights. Because it is automated, one can write specifications at different levels of details or for different purposes.
33
35
 
36
+ ### Stakeholder Communications
37
+
38
+ - In organizations, senior people / non-developers don't always have as intimate a view of the underlying code as the primary developers in a system because of time constraints and not working as directly with the code as the primary developers
39
+ - Often this means that there is a reliance on asking the primary developers for clarifications and relying on "front-end" kinds of stuff such as visualizations or outputs of the model as opposed to combing through the underlying code
40
+ - MSML seeks to help bridge this gap by allowing for the Obsidian markdown vault that can showcase every component and its dependencies for easier consumption.... this reduces the barriers to entry on understanding the back-end/underlying model
41
+ - Also through things such as code linking, MSML allows for those with code fluency to jump into underlying code if they need to without even opening up the actual project repository
34
42
 
35
43
  ## What are some of the solutions offered?
36
44
 
@@ -79,34 +87,6 @@ Thanks to some of the more advanced features, MSML can be used as an aid for deb
79
87
 
80
88
  The ability to fork the repository of an MSML spec as well as the ability to use it for A/B testing with the policy options makes it well suited for iterating on model evolution.
81
89
 
82
- ## Technical Details
83
-
84
- The documentation on the technical details of using the MSML can be found [here](https://github.com/BlockScience/MSML/tree/main/docs)
85
-
86
- ## Canonical Examples
87
-
88
- [Dummy/Starter Repository](https://github.com/BlockScience/MSML/tree/main/examples/StarterRepo)
89
- [Root Finding Simulation](https://github.com/SeanMcOwen/Root-Finding-Simulation)
90
-
91
- ### Comparison of Canonical Example Features
92
-
93
- | Feature | Dummy | Root Finding |
94
- | --- | --- | --- |
95
- | Action Transmission Channels | X | X |
96
- | Stack Block | X | X |
97
- | Parallel Block | | X |
98
- | Split Block | | |
99
- | Boundary Actions | X | |
100
- | Control Actions | X | X |
101
- | Entities | X | |
102
- | Mechanisms | X | X |
103
- | Parameters | X | X |
104
- | Policies | X | X |
105
- | Spaces | X | X |
106
- | State | X | X |
107
- | Stateful Metrics | | |
108
- | State Update Transmission Channels | X | X |
109
- | Reports | X | X |
110
90
 
111
91
  ## Other Related Repositories
112
92
 
@@ -1,18 +0,0 @@
1
- from typing import Dict
2
-
3
-
4
- class Space:
5
- def __init__(self, data: Dict):
6
- self.name = data["name"]
7
- self.schema = data["schema"]
8
- self.metadata = data["metadata"]
9
- self.name_variable = self.name.replace(" ", "").replace("-", "_")
10
- self.domain_blocks = []
11
- self.codomain_blocks = []
12
-
13
- def __repr__(self):
14
- return self.name
15
-
16
-
17
- TerminatingSpace = Space({"name": "Terminating Space", "schema": {}, "metadata": {}})
18
- EmptySpace = Space({"name": "Empty Space", "schema": {}, "metadata": {}})