math-spec-mapping 0.4.0__tar.gz → 0.4.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. {math_spec_mapping-0.4.0/src/math_spec_mapping.egg-info → math_spec_mapping-0.4.1.2}/PKG-INFO +5 -2
  2. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/pyproject.toml +5 -2
  3. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/MathSpec.py +200 -1
  4. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/type.py +3 -1
  5. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2/src/math_spec_mapping.egg-info}/PKG-INFO +5 -2
  6. math_spec_mapping-0.4.1.2/src/math_spec_mapping.egg-info/requires.txt +6 -0
  7. math_spec_mapping-0.4.0/src/math_spec_mapping.egg-info/requires.txt +0 -3
  8. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/LICENSE +0 -0
  9. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/README.md +0 -0
  10. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/setup.cfg +0 -0
  11. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/ActionTransmissionChannel.py +0 -0
  12. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/Block.py +0 -0
  13. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/BoundaryAction.py +0 -0
  14. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/ControlAction.py +0 -0
  15. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/Entity.py +0 -0
  16. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/Mechanism.py +0 -0
  17. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/Metric.py +0 -0
  18. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/Parameter.py +0 -0
  19. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/Policy.py +0 -0
  20. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/Space.py +0 -0
  21. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/State.py +0 -0
  22. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/StateUpdateTransmissionChannel.py +0 -0
  23. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/StatefulMetric.py +0 -0
  24. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/Type.py +0 -0
  25. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Classes/__init__.py +0 -0
  26. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Convenience/__init__.py +0 -0
  27. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Convenience/documentation.py +0 -0
  28. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Convenience/github.py +0 -0
  29. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Convenience/starter.py +0 -0
  30. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/__init__.py +0 -0
  31. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/action_transmission_channel.py +0 -0
  32. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/boundary_actions.py +0 -0
  33. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/control_actions.py +0 -0
  34. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/displays.py +0 -0
  35. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/entities.py +0 -0
  36. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/general.py +0 -0
  37. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/implementations.py +0 -0
  38. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/load.py +0 -0
  39. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/mechanism.py +0 -0
  40. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/metrics.py +0 -0
  41. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/parameters.py +0 -0
  42. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/policy.py +0 -0
  43. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/spaces.py +0 -0
  44. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/spec_tree.py +0 -0
  45. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/state_update_transmission_channels.py +0 -0
  46. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/stateful_metrics.py +0 -0
  47. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/states.py +0 -0
  48. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Load/wiring.py +0 -0
  49. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/__init__.py +0 -0
  50. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/boundary_actions.py +0 -0
  51. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/control_actions.py +0 -0
  52. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/general.py +0 -0
  53. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/html.py +0 -0
  54. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/markdown.py +0 -0
  55. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/mechanisms.py +0 -0
  56. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/node_map.py +0 -0
  57. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/parameters.py +0 -0
  58. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/policies.py +0 -0
  59. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/spaces.py +0 -0
  60. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/state.py +0 -0
  61. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/tables.py +0 -0
  62. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/Reports/wiring.py +0 -0
  63. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/__init__.py +0 -0
  64. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/schema.py +0 -0
  65. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping/schema.schema.json +0 -0
  66. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping.egg-info/SOURCES.txt +0 -0
  67. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping.egg-info/dependency_links.txt +0 -0
  68. {math_spec_mapping-0.4.0 → math_spec_mapping-0.4.1.2}/src/math_spec_mapping.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: math-spec-mapping
3
- Version: 0.4.0
3
+ Version: 0.4.1.2
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
@@ -12,6 +12,9 @@ License-File: LICENSE
12
12
  Requires-Dist: graphviz>=0.20.1
13
13
  Requires-Dist: ipython>=7.7.0
14
14
  Requires-Dist: pandas>=1.4
15
+ Requires-Dist: jsonschema>=4.21.1
16
+ Requires-Dist: PyGithub==2.5.0
17
+ Requires-Dist: python-dotenv>=1.0.0
15
18
 
16
19
  # Mathematical Specification Mapping Library (MSML)
17
20
 
@@ -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.4.0"
6
+ version = "0.4.1.2"
7
7
  authors = [
8
8
  { name="Sean McOwen", email="Sean@Block.Science" },
9
9
  ]
@@ -11,7 +11,10 @@ description = "A library for easy mapping of mathematical specifications."
11
11
  dependencies = [
12
12
  "graphviz>=0.20.1",
13
13
  "ipython>=7.7.0",
14
- "pandas>=1.4"
14
+ "pandas>=1.4",
15
+ "jsonschema>=4.21.1",
16
+ "PyGithub==2.5.0",
17
+ "python-dotenv>=1.0.0"
15
18
  ]
16
19
  readme = "README.md"
17
20
  requires-python = ">=3.7"
@@ -1,4 +1,4 @@
1
- from typing import Dict, List
1
+ from typing import Dict, List, Literal
2
2
  from .Entity import Entity
3
3
  from .Policy import Policy
4
4
  from .Mechanism import Mechanism
@@ -10,6 +10,16 @@ import shutil
10
10
  import pandas as pd
11
11
  from inspect import signature, getsource, getfile, getsourcelines
12
12
  from IPython.display import display, Markdown
13
+ from copy import copy, deepcopy
14
+
15
+
16
+ class ValidKeyDict(dict):
17
+ def __getitem__(self, key):
18
+ # Add an assertion to check if the key exists
19
+ assert key in self, "Key not valid, valid options are: {}".format(
20
+ ", ".join(self.keys())
21
+ )
22
+ return super().__getitem__(key)
13
23
 
14
24
 
15
25
  class MathSpec:
@@ -54,6 +64,21 @@ class MathSpec:
54
64
  self._crawl_spaces()
55
65
  self._set_source_code()
56
66
 
67
+ self.boundary_actions = ValidKeyDict(self.boundary_actions)
68
+ self.control_actions = ValidKeyDict(self.control_actions)
69
+ self.entities = ValidKeyDict(self.entities)
70
+ self.mechanisms = ValidKeyDict(self.mechanisms)
71
+ self.parameters.parameter_map = ValidKeyDict(self.parameters.parameter_map)
72
+ self.policies = ValidKeyDict(self.policies)
73
+ self.spaces = ValidKeyDict(self.spaces)
74
+ self.state = ValidKeyDict(self.state)
75
+ self.stateful_metrics_map = ValidKeyDict(self.stateful_metrics_map)
76
+ self.wiring = ValidKeyDict(self.wiring)
77
+ self.metrics = ValidKeyDict(self.metrics)
78
+ self.displays = ValidKeyDict(self.displays)
79
+ self.blocks = ValidKeyDict(self.blocks)
80
+ self.components = ValidKeyDict(self.components)
81
+
57
82
  def _check_dictionary_names(self):
58
83
  for key in self.boundary_actions:
59
84
  assert key == self.boundary_actions[key].name
@@ -986,6 +1011,50 @@ using .Spaces: generate_space_type
986
1011
  self, params, domain_codomain_checking=domain_codomain_checking
987
1012
  )
988
1013
 
1014
+ def _build_state_space(self):
1015
+ state = self.state["Global State"]
1016
+ state_map = {}
1017
+ for variable in state.variables:
1018
+ if "python" in variable.type.type:
1019
+ state_map[variable.name] = variable.type.type["python"]
1020
+ else:
1021
+ state_map[variable.name] = None
1022
+
1023
+ return state_map
1024
+
1025
+ def _build_parameter_space(self):
1026
+ parameter_space = {}
1027
+ for parameter in self.parameters.all_parameters:
1028
+ parameter = self.parameters.parameter_map[parameter]
1029
+ if "python" in parameter.variable_type.type:
1030
+ parameter_space[parameter.name] = parameter.variable_type.type["python"]
1031
+ else:
1032
+ parameter_space[parameter.name] = None
1033
+ for name in self.functional_parameters.keys():
1034
+ fp = self.functional_parameters[name]
1035
+ fp = tuple(fp.keys())
1036
+ parameter_space[name] = Literal[fp]
1037
+ return parameter_space
1038
+
1039
+ def build_cadCAD(
1040
+ self,
1041
+ blocks,
1042
+ state_preperation_functions=[],
1043
+ parameter_preperation_functions=[],
1044
+ ):
1045
+ out = {}
1046
+ out["StateSpace"] = self._build_state_space()
1047
+ out["ParameterSpace"] = self._build_parameter_space()
1048
+ out["Model"] = cadCADModel(
1049
+ self,
1050
+ out["StateSpace"],
1051
+ out["ParameterSpace"],
1052
+ blocks,
1053
+ state_preperation_functions=state_preperation_functions,
1054
+ parameter_preperation_functions=parameter_preperation_functions,
1055
+ )
1056
+ return out
1057
+
989
1058
  def _set_source_code(self):
990
1059
  if "python" not in self.implementations:
991
1060
  self.source_code = None
@@ -1001,6 +1070,126 @@ using .Spaces: generate_space_type
1001
1070
  self.source_code[x][y] = getsource(self.source_code[x][y])
1002
1071
 
1003
1072
 
1073
+ class cadCADModel:
1074
+ def __init__(
1075
+ self,
1076
+ ms,
1077
+ state_space,
1078
+ parameter_space,
1079
+ blocks,
1080
+ state_preperation_functions=[],
1081
+ parameter_preperation_functions=[],
1082
+ ):
1083
+ self.ms = ms
1084
+ self.state_space = state_space
1085
+ self.parameter_space = parameter_space
1086
+ self.blocks = blocks
1087
+ self.state_preperation_functions = state_preperation_functions
1088
+ self.parameter_preperation_functions = parameter_preperation_functions
1089
+
1090
+ def create_experiment(
1091
+ self, state, params, record_trajectory=False, use_deepcopy=True
1092
+ ):
1093
+ return Experiment(
1094
+ self,
1095
+ state,
1096
+ params,
1097
+ self.ms,
1098
+ record_trajectory=record_trajectory,
1099
+ use_deepcopy=use_deepcopy,
1100
+ )
1101
+
1102
+ def create_batch_experiments(
1103
+ self, state, params, record_trajectory=False, use_deepcopy=True
1104
+ ):
1105
+ return BatchExperiments(
1106
+ self,
1107
+ state,
1108
+ params,
1109
+ self.ms,
1110
+ record_trajectory=record_trajectory,
1111
+ use_deepcopy=use_deepcopy,
1112
+ )
1113
+
1114
+ def __repr__(self):
1115
+ return f"Model({self.parameter_space}, {self.state_space}, {self.blocks})"
1116
+
1117
+
1118
+ class Experiment:
1119
+ def __init__(self, model, state, params, ms, record_trajectory, use_deepcopy=True):
1120
+ self.model = model
1121
+ self.state = deepcopy(state)
1122
+ self.params = deepcopy(params)
1123
+ self._use_deepcopy = use_deepcopy
1124
+ self.msi = ms.build_implementation(self.params)
1125
+ self.state, self.params = self.msi.prepare_state_and_params(
1126
+ self.state,
1127
+ self.params,
1128
+ state_preperation_functions=self.model.state_preperation_functions,
1129
+ parameter_preperation_functions=self.model.parameter_preperation_functions,
1130
+ )
1131
+
1132
+ if record_trajectory:
1133
+ if self._use_deepcopy:
1134
+ self.trajectories = [deepcopy(self.state)]
1135
+ else:
1136
+ self.trajectories = [copy(self.state)]
1137
+ self.trajectories[-1].pop("Stateful Metrics")
1138
+ self.trajectories[-1].pop("Metrics")
1139
+ else:
1140
+ self.trajectories = None
1141
+ self._record_trajectory = record_trajectory
1142
+ self._iteration_count = 0
1143
+
1144
+ def step(self):
1145
+ self.msi.execute_blocks(self.state, self.params, self.model.blocks)
1146
+ self._iteration_count += 1
1147
+ if self._record_trajectory:
1148
+ if self._use_deepcopy:
1149
+ self.trajectories.append(deepcopy(self.state))
1150
+ else:
1151
+ self.trajectories.append(copy(self.state))
1152
+ self.trajectories[-1].pop("Stateful Metrics")
1153
+ self.trajectories[-1].pop("Metrics")
1154
+
1155
+ def run(self, t):
1156
+ for _ in range(t):
1157
+ self.step()
1158
+
1159
+
1160
+ class BatchExperiments:
1161
+ def __init__(self, model, state, params, ms, record_trajectory, use_deepcopy=True):
1162
+ assert type(state) == list, "Input for state must be a list of states"
1163
+ assert type(params) == list, "Input for params must be a list of states"
1164
+ assert len(state) == len(
1165
+ params
1166
+ ), "Length of state and parameters has to be the same"
1167
+
1168
+ self.experiments = [
1169
+ Experiment(
1170
+ model,
1171
+ s,
1172
+ p,
1173
+ ms,
1174
+ record_trajectory=record_trajectory,
1175
+ use_deepcopy=use_deepcopy,
1176
+ )
1177
+ for s, p in zip(state, params)
1178
+ ]
1179
+
1180
+ def step(self):
1181
+ for experiment in self.experiments:
1182
+ experiment.step()
1183
+
1184
+ def run(self, t):
1185
+ for experiment in self.experiments:
1186
+ experiment.run(t)
1187
+
1188
+ @property
1189
+ def trajectories(self):
1190
+ return [experiment.trajectories for experiment in self.experiments]
1191
+
1192
+
1004
1193
  class MathSpecImplementation:
1005
1194
  def __init__(self, ms: MathSpec, params, domain_codomain_checking):
1006
1195
  self.ms = deepcopy(ms)
@@ -1016,6 +1205,16 @@ class MathSpecImplementation:
1016
1205
  self.load_components()
1017
1206
  self.load_source_files()
1018
1207
 
1208
+ self.boundary_actions = ValidKeyDict(self.boundary_actions)
1209
+ self.control_actions = ValidKeyDict(self.control_actions)
1210
+ self.mechanisms = ValidKeyDict(self.mechanisms)
1211
+ self.policies = ValidKeyDict(self.policies)
1212
+ self.stateful_metrics = ValidKeyDict(self.stateful_metrics)
1213
+ self.wiring = ValidKeyDict(self.wiring)
1214
+ self.metrics = ValidKeyDict(self.metrics)
1215
+ self.blocks = ValidKeyDict(self.blocks)
1216
+ self.components = ValidKeyDict(self.components)
1217
+
1019
1218
  def load_control_actions(self):
1020
1219
  control_actions = {}
1021
1220
  for ca in self.ms.control_actions:
@@ -1,7 +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
+ from typing import _UnionGenericAlias, List, _GenericAlias
5
5
 
6
6
 
7
7
  def convert_type(data, ms):
@@ -36,6 +36,8 @@ def convert_type(data, ms):
36
36
  data["type_name"]["python"] = str(out)
37
37
  elif type(data["type"]["python"]) == _UnionGenericAlias:
38
38
  data["type_name"]["python"] = data["type"]["python"].__repr__()
39
+ elif type(data["type"]["python"]) == _GenericAlias:
40
+ data["type_name"]["python"] = data["type"]["python"].__repr__()
39
41
  else:
40
42
  data["type_name"]["python"] = data["type"]["python"].__name__
41
43
  if "typescript" in ms["Type Keys"]:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: math-spec-mapping
3
- Version: 0.4.0
3
+ Version: 0.4.1.2
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
@@ -12,6 +12,9 @@ License-File: LICENSE
12
12
  Requires-Dist: graphviz>=0.20.1
13
13
  Requires-Dist: ipython>=7.7.0
14
14
  Requires-Dist: pandas>=1.4
15
+ Requires-Dist: jsonschema>=4.21.1
16
+ Requires-Dist: PyGithub==2.5.0
17
+ Requires-Dist: python-dotenv>=1.0.0
15
18
 
16
19
  # Mathematical Specification Mapping Library (MSML)
17
20
 
@@ -0,0 +1,6 @@
1
+ graphviz>=0.20.1
2
+ ipython>=7.7.0
3
+ pandas>=1.4
4
+ jsonschema>=4.21.1
5
+ PyGithub==2.5.0
6
+ python-dotenv>=1.0.0
@@ -1,3 +0,0 @@
1
- graphviz>=0.20.1
2
- ipython>=7.7.0
3
- pandas>=1.4