math-spec-mapping 0.3.19__py3-none-any.whl → 0.3.20__py3-none-any.whl
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.
- math_spec_mapping/Classes/MathSpec.py +66 -4
- math_spec_mapping/Classes/Space.py +17 -2
- math_spec_mapping/Classes/Type.py +3 -0
- math_spec_mapping/Load/spaces.py +3 -0
- math_spec_mapping/Load/spec_tree.py +28 -7
- math_spec_mapping/Load/stateful_metrics.py +2 -2
- math_spec_mapping/Reports/markdown.py +11 -2
- math_spec_mapping/schema.schema.json +3 -0
- {math_spec_mapping-0.3.19.dist-info → math_spec_mapping-0.3.20.dist-info}/METADATA +1 -1
- {math_spec_mapping-0.3.19.dist-info → math_spec_mapping-0.3.20.dist-info}/RECORD +13 -13
- {math_spec_mapping-0.3.19.dist-info → math_spec_mapping-0.3.20.dist-info}/LICENSE +0 -0
- {math_spec_mapping-0.3.19.dist-info → math_spec_mapping-0.3.20.dist-info}/WHEEL +0 -0
- {math_spec_mapping-0.3.19.dist-info → math_spec_mapping-0.3.20.dist-info}/top_level.txt +0 -0
@@ -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(
|
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, [])
|
@@ -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.description = data["description"]
|
9
10
|
self.name_variable = self.name.replace(" ", "").replace("-", "_")
|
10
11
|
self.domain_blocks = []
|
11
12
|
self.codomain_blocks = []
|
@@ -14,5 +15,19 @@ class Space:
|
|
14
15
|
return self.name
|
15
16
|
|
16
17
|
|
17
|
-
TerminatingSpace = Space(
|
18
|
-
|
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
|
+
)
|
math_spec_mapping/Load/spaces.py
CHANGED
@@ -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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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"
|
@@ -1,21 +1,21 @@
|
|
1
1
|
math_spec_mapping/__init__.py,sha256=7fGuxoSDYl61z0PZ_PzS6x5P8l174gOzobI9u0aoLVw,1260
|
2
2
|
math_spec_mapping/schema.py,sha256=6mrRqzEnTTSXjb19xJ63MBp0KjKH0s7i6TfT4MkAY9k,233
|
3
|
-
math_spec_mapping/schema.schema.json,sha256=
|
3
|
+
math_spec_mapping/schema.schema.json,sha256=NyzUy899YR_5Y956ID5HQtgnRBrNTAN6QjrqCyBasRA,31005
|
4
4
|
math_spec_mapping/Classes/ActionTransmissionChannel.py,sha256=zWMo5QsgPh5WGIWXl-xOrZNMXYJXmK6Vejw1dQvi0og,246
|
5
5
|
math_spec_mapping/Classes/Block.py,sha256=KHdGILGW7G29nXXsrjeRkKsilqEqYl31ZV1u9gm4xio,20147
|
6
6
|
math_spec_mapping/Classes/BoundaryAction.py,sha256=_rFvEZ4LNxmlM59js4SuQ9n5CgVmITw4YWKs0-q0r-4,560
|
7
7
|
math_spec_mapping/Classes/ControlAction.py,sha256=4AzMSA8fbnUf-fGlvMJXHJFbz32G1h1QVWf2yzrXrLA,493
|
8
8
|
math_spec_mapping/Classes/Entity.py,sha256=fA0-b128_OHHxfCg4pzqyQV083EYev1HlVpy86S5igg,1226
|
9
|
-
math_spec_mapping/Classes/MathSpec.py,sha256=
|
9
|
+
math_spec_mapping/Classes/MathSpec.py,sha256=nQTesARmLrYagoW2T3G6gbidTsFM-NFC9yl3Li01ey8,55970
|
10
10
|
math_spec_mapping/Classes/Mechanism.py,sha256=2sLm3wYBIeTQaMBcsJ9btqIWsbS895Ra8NY6Y9_G_Dg,379
|
11
11
|
math_spec_mapping/Classes/Metric.py,sha256=iQhH4g8Z60QlM22nPX9ytGmidOsZSiSs0KjqwmsScwU,636
|
12
12
|
math_spec_mapping/Classes/Parameter.py,sha256=ZuJ_w0sChvRElJ4sOnXZ2EV4Ell2xXFulKLjVOpgz2E,1237
|
13
13
|
math_spec_mapping/Classes/Policy.py,sha256=Nso8QJMBDeyN66VkZ29nnZ1WjaMnReMn7SxKt_bRngU,481
|
14
|
-
math_spec_mapping/Classes/Space.py,sha256=
|
14
|
+
math_spec_mapping/Classes/Space.py,sha256=tdxah3TtixvT0wCqljC_pXFRvO92TY6lomGu2WS8Jtw,806
|
15
15
|
math_spec_mapping/Classes/State.py,sha256=U40DoF2qlx_k9gvqQiP1S3C9ZLk3cW_-jmJn71TiCxg,1599
|
16
16
|
math_spec_mapping/Classes/StateUpdateTransmissionChannel.py,sha256=3hBLvD1lE64PkwqksBXAfFWv7foOZzGQLAFQWy42tOA,257
|
17
17
|
math_spec_mapping/Classes/StatefulMetric.py,sha256=plMFMAFEk1y2t4DR5lA2SRC9UrYArsx_W33l3mZSdgE,804
|
18
|
-
math_spec_mapping/Classes/Type.py,sha256=
|
18
|
+
math_spec_mapping/Classes/Type.py,sha256=cA5-5nOfjX6aHzTHM8M6mP5lsS7foumckRu7WDX610M,339
|
19
19
|
math_spec_mapping/Classes/__init__.py,sha256=0zxgOqns_9JybD74HKMVh6aw8ij8WVbfQ4Q_1uWzof0,761
|
20
20
|
math_spec_mapping/Convenience/__init__.py,sha256=BEZr1rXohKAknOa3wjNVx3EvSVxDcfftJsvtSw5mvmQ,264
|
21
21
|
math_spec_mapping/Convenience/documentation.py,sha256=1ziWVJznbCUxeAAt03nAdEYtMlXNo5TeedHfgs0vSBU,1625
|
@@ -34,10 +34,10 @@ math_spec_mapping/Load/mechanism.py,sha256=6tgISsxc-SXCYS5yxuIqnl0nX__t1k0uj9z0O
|
|
34
34
|
math_spec_mapping/Load/metrics.py,sha256=CcVM0_aN-aPnH5_AyEKzFCJGPbgMb0brw5nECsdNVeU,3936
|
35
35
|
math_spec_mapping/Load/parameters.py,sha256=W4utm7to3s2fo4z3XgLH0TM1agaIad1qfM2I-lLMua4,1393
|
36
36
|
math_spec_mapping/Load/policy.py,sha256=61F7sobAwaXrT1g_pXqBmQS0O-jekdQ1nB9C658LJyg,2770
|
37
|
-
math_spec_mapping/Load/spaces.py,sha256=
|
38
|
-
math_spec_mapping/Load/spec_tree.py,sha256=
|
37
|
+
math_spec_mapping/Load/spaces.py,sha256=PcAQ8QnsCZQarPaymUhESqbRMXH-uVRumXTh-E256A4,1256
|
38
|
+
math_spec_mapping/Load/spec_tree.py,sha256=cRSvb3vHPJIJ7pS6KKH3yJLJXPQXMMPt-ciX9NccQhM,3264
|
39
39
|
math_spec_mapping/Load/state_update_transmission_channels.py,sha256=FJWp5n4HdtHAfof5BUQ6BnRakljatL2h8dWCapaVSc0,2238
|
40
|
-
math_spec_mapping/Load/stateful_metrics.py,sha256=
|
40
|
+
math_spec_mapping/Load/stateful_metrics.py,sha256=eNXIsNmezVN75L3zMXUl8_JORShm_ovJuM7vkiODs7s,2599
|
41
41
|
math_spec_mapping/Load/states.py,sha256=3YurI7eTNkN6nrXRFVrc58wH0VfM22XOuWE07HVpR7Y,1365
|
42
42
|
math_spec_mapping/Load/type.py,sha256=FbViE3wV1o1JTx7mUYyUpAvgIxDKDQYc6Iw50FrZ4nY,4808
|
43
43
|
math_spec_mapping/Load/wiring.py,sha256=l1FhHNFRMKorn1oiRhsuMDsExcXnUmTjqQt5ElE-Bbk,3258
|
@@ -46,7 +46,7 @@ math_spec_mapping/Reports/boundary_actions.py,sha256=45BPp4QjWdD-3E9ZWwqgj_nI2-Y
|
|
46
46
|
math_spec_mapping/Reports/control_actions.py,sha256=NksekZKIPFSIkubttFstKFthc5AU9B9PWRLSl9j1wWs,1216
|
47
47
|
math_spec_mapping/Reports/general.py,sha256=WOOn6Wlb8M4fsdN49FlKLwOka6vJPQ9aCUy88TL2ki0,1610
|
48
48
|
math_spec_mapping/Reports/html.py,sha256=MCVp_D1LuRoZrHtwzFOJGQviztGeahqsWf3Zue1Yz64,10134
|
49
|
-
math_spec_mapping/Reports/markdown.py,sha256=
|
49
|
+
math_spec_mapping/Reports/markdown.py,sha256=q4dCzH6dDE0TLJ3XS7olUpDfPk8323IEPbT9ki7GEgE,30595
|
50
50
|
math_spec_mapping/Reports/mechanisms.py,sha256=d2Rxt3JBYvqAOAYUynl0buYVoXEHrO8EGq7GK6hK8NA,1322
|
51
51
|
math_spec_mapping/Reports/node_map.py,sha256=FdSMDQG16NX6n9sZcH-T5xwsvgjrV9OqBHc9J_VlNK0,3129
|
52
52
|
math_spec_mapping/Reports/parameters.py,sha256=-ucL71lolqU0xvV7yb0sXl4pFMRl5tXNWdoBfUjLOaQ,1944
|
@@ -55,8 +55,8 @@ math_spec_mapping/Reports/spaces.py,sha256=-76hR5wQBv4lsG000ypBJ-OprjsNjI-rNRMYd
|
|
55
55
|
math_spec_mapping/Reports/state.py,sha256=QYeCvX5cHeZBrbvMeDsTqJcUDTuDFJSLvPbasjLspk8,3643
|
56
56
|
math_spec_mapping/Reports/tables.py,sha256=O0CNuqh3LMECq5uLjBOoxMUk5hUvkUK660FNnwWUxDY,1505
|
57
57
|
math_spec_mapping/Reports/wiring.py,sha256=u9SvKWy6T-WJUEgFI6-zgZanoOaTTs_2YwmEceDLsV8,1618
|
58
|
-
math_spec_mapping-0.3.
|
59
|
-
math_spec_mapping-0.3.
|
60
|
-
math_spec_mapping-0.3.
|
61
|
-
math_spec_mapping-0.3.
|
62
|
-
math_spec_mapping-0.3.
|
58
|
+
math_spec_mapping-0.3.20.dist-info/LICENSE,sha256=ObyEzSw8kgCaFbEfpu1zP4TrcAKLA0xhqHMZZfyh7N0,1069
|
59
|
+
math_spec_mapping-0.3.20.dist-info/METADATA,sha256=NXnBv92-ZzX5ESZFyq6bzbKWGa5Jq1y0cPddW7o4ndc,6498
|
60
|
+
math_spec_mapping-0.3.20.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
61
|
+
math_spec_mapping-0.3.20.dist-info/top_level.txt,sha256=AImhn9wgazkdV0a9vfiphtQR8uGe2nq-ZIOp-6yUk9o,18
|
62
|
+
math_spec_mapping-0.3.20.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|