math-spec-mapping 0.3.10__py3-none-any.whl → 0.3.12__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 +41 -2
- math_spec_mapping/Reports/parameters.py +13 -2
- math_spec_mapping/Reports/state.py +23 -5
- {math_spec_mapping-0.3.10.dist-info → math_spec_mapping-0.3.12.dist-info}/METADATA +1 -1
- {math_spec_mapping-0.3.10.dist-info → math_spec_mapping-0.3.12.dist-info}/RECORD +8 -8
- {math_spec_mapping-0.3.10.dist-info → math_spec_mapping-0.3.12.dist-info}/WHEEL +1 -1
- {math_spec_mapping-0.3.10.dist-info → math_spec_mapping-0.3.12.dist-info}/LICENSE +0 -0
- {math_spec_mapping-0.3.10.dist-info → math_spec_mapping-0.3.12.dist-info}/top_level.txt +0 -0
@@ -8,6 +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
|
11
12
|
|
12
13
|
|
13
14
|
class MathSpec:
|
@@ -47,6 +48,7 @@ class MathSpec:
|
|
47
48
|
self._build_functional_parameters()
|
48
49
|
self._build_parameter_types()
|
49
50
|
self._crawl_spaces()
|
51
|
+
self._set_source_code()
|
50
52
|
|
51
53
|
def _check_dictionary_names(self):
|
52
54
|
for key in self.boundary_actions:
|
@@ -765,6 +767,15 @@ using .Spaces: generate_space_type
|
|
765
767
|
def build_implementation(self, params):
|
766
768
|
return MathSpecImplementation(self, params)
|
767
769
|
|
770
|
+
def _set_source_code(self):
|
771
|
+
if "python" not in self.implementations:
|
772
|
+
self.source_code = None
|
773
|
+
return
|
774
|
+
self.source_code = deepcopy(self.implementations["python"])
|
775
|
+
for x in self.source_code:
|
776
|
+
for y in self.source_code[x]:
|
777
|
+
self.source_code[x][y] = getsource(self.source_code[x][y])
|
778
|
+
|
768
779
|
|
769
780
|
class MathSpecImplementation:
|
770
781
|
def __init__(self, ms: MathSpec, params):
|
@@ -778,6 +789,7 @@ class MathSpecImplementation:
|
|
778
789
|
self.metrics = self.load_metrics()
|
779
790
|
self.load_wiring()
|
780
791
|
self.load_components()
|
792
|
+
self.load_source_files()
|
781
793
|
|
782
794
|
def load_control_actions(self):
|
783
795
|
control_actions = {}
|
@@ -1046,13 +1058,27 @@ class MathSpecImplementation:
|
|
1046
1058
|
state["Metrics"] = self.metrics
|
1047
1059
|
if state_preperation_functions:
|
1048
1060
|
for f in state_preperation_functions:
|
1049
|
-
|
1061
|
+
if len(signature(f).parameters) == 1:
|
1062
|
+
state = f(state)
|
1063
|
+
elif len(signature(f).parameters) == 2:
|
1064
|
+
state = f(state, params)
|
1065
|
+
else:
|
1066
|
+
assert (
|
1067
|
+
False
|
1068
|
+
), "Incorrect number of parameters for the state preperation function"
|
1050
1069
|
assert (
|
1051
1070
|
state is not None
|
1052
1071
|
), "A state must be returned from the state preperation functions"
|
1053
1072
|
if parameter_preperation_functions:
|
1054
1073
|
for f in parameter_preperation_functions:
|
1055
|
-
|
1074
|
+
if len(signature(f).parameters) == 1:
|
1075
|
+
params = f(params)
|
1076
|
+
elif len(signature(f).parameters) == 2:
|
1077
|
+
params = f(params, state)
|
1078
|
+
else:
|
1079
|
+
assert (
|
1080
|
+
False
|
1081
|
+
), "Incorrect number of parameters for the state preperation function"
|
1056
1082
|
assert (
|
1057
1083
|
params is not None
|
1058
1084
|
), "A parameter set must be returned from the parameter preperation functions"
|
@@ -1070,3 +1096,16 @@ class MathSpecImplementation:
|
|
1070
1096
|
for block in blocks:
|
1071
1097
|
self.components[block](state, params, [])
|
1072
1098
|
return state
|
1099
|
+
|
1100
|
+
def load_source_files(self):
|
1101
|
+
self.source_files = {}
|
1102
|
+
for key in self.components:
|
1103
|
+
self.source_files[key] = getsource(self.components[key])
|
1104
|
+
|
1105
|
+
def print_source_code_files(self, keys=None):
|
1106
|
+
if not keys:
|
1107
|
+
keys = list(self.source_files.keys())
|
1108
|
+
for key in keys:
|
1109
|
+
print("-" * 20 + key + "-" * 20)
|
1110
|
+
print(self.source_files[key])
|
1111
|
+
print("\n\n\n")
|
@@ -15,7 +15,9 @@ def write_out_params(ms: MathSpec, params: List[str]) -> str:
|
|
15
15
|
return out
|
16
16
|
|
17
17
|
|
18
|
-
def write_parameter_table_markdown(
|
18
|
+
def write_parameter_table_markdown(
|
19
|
+
ms, initial_values=None, links=False, compress_arrays=False
|
20
|
+
):
|
19
21
|
if initial_values:
|
20
22
|
table = """| Name | Description | Parameter Class | Symbol | Domain | Initial Value |
|
21
23
|
| --- | --- | --- | --- | --- | --- |
|
@@ -43,7 +45,16 @@ def write_parameter_table_markdown(ms, initial_values=None, links=False):
|
|
43
45
|
table += "{}".format(tv)
|
44
46
|
table += "|"
|
45
47
|
if initial_values:
|
46
|
-
|
48
|
+
if compress_arrays:
|
49
|
+
iv = initial_values[var.name]
|
50
|
+
if type(iv) == list:
|
51
|
+
if len(iv) > 4:
|
52
|
+
iv = "[{}, {}, ... , {}, {}]".format(
|
53
|
+
iv[0], iv[1], iv[-2], iv[-1]
|
54
|
+
)
|
55
|
+
table += " {} |".format(iv)
|
56
|
+
else:
|
57
|
+
table += " {} |".format(initial_values[var.name])
|
47
58
|
|
48
59
|
table += "\n"
|
49
60
|
|
@@ -33,7 +33,9 @@ def write_state_variable_table(target_state, links=False):
|
|
33
33
|
return table
|
34
34
|
|
35
35
|
|
36
|
-
def write_state_variable_table_markdown(
|
36
|
+
def write_state_variable_table_markdown(
|
37
|
+
target_state, initial_values=None, links=False, compress_arrays=False
|
38
|
+
):
|
37
39
|
if initial_values:
|
38
40
|
table = """| Name | Description | Type | Symbol | Domain | Initial Value |
|
39
41
|
| --- | --- | --- | --- | --- | --- |
|
@@ -62,18 +64,32 @@ def write_state_variable_table_markdown(target_state, initial_values=None, links
|
|
62
64
|
table += "{}".format(tv)
|
63
65
|
table += "|"
|
64
66
|
if initial_values:
|
65
|
-
|
67
|
+
if compress_arrays:
|
68
|
+
iv = initial_values[var.name]
|
69
|
+
if type(iv) == list:
|
70
|
+
if len(iv) > 4:
|
71
|
+
iv = "[{}, {}, ... , {}, {}]".format(
|
72
|
+
iv[0], iv[1], iv[-2], iv[-1]
|
73
|
+
)
|
74
|
+
table += " {} |".format(iv)
|
75
|
+
else:
|
76
|
+
table += " {} |".format(initial_values[var.name])
|
66
77
|
|
67
78
|
table += "\n"
|
68
79
|
|
69
80
|
return table
|
70
81
|
|
71
82
|
|
72
|
-
def write_initial_state_variables_tables(
|
83
|
+
def write_initial_state_variables_tables(
|
84
|
+
ms, initial_values, links=False, compress_arrays=False
|
85
|
+
):
|
73
86
|
out = "### Global State"
|
74
87
|
out += "\n\n"
|
75
88
|
out += write_state_variable_table_markdown(
|
76
|
-
ms.state["Global State"],
|
89
|
+
ms.state["Global State"],
|
90
|
+
initial_values=initial_values,
|
91
|
+
links=links,
|
92
|
+
compress_arrays=compress_arrays,
|
77
93
|
)
|
78
94
|
out += "\n"
|
79
95
|
for x in ms.state:
|
@@ -82,7 +98,9 @@ def write_initial_state_variables_tables(ms, initial_values, links=False):
|
|
82
98
|
|
83
99
|
out += "### {}".format(x)
|
84
100
|
out += "\n\n"
|
85
|
-
out += write_state_variable_table_markdown(
|
101
|
+
out += write_state_variable_table_markdown(
|
102
|
+
ms.state[x], links=links, compress_arrays=compress_arrays
|
103
|
+
)
|
86
104
|
out += "\n"
|
87
105
|
|
88
106
|
return out
|
@@ -6,7 +6,7 @@ math_spec_mapping/Classes/Block.py,sha256=cGtIhNgRfoDZ0O3SxeXcNzNlHcdXIB89sT2uaZ
|
|
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=MnQQQMAk8VojjTzao56MBN3rvO_fexQrkh5SAGmWpP8,42033
|
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
|
@@ -47,14 +47,14 @@ math_spec_mapping/Reports/html.py,sha256=zRo67S81pIRK_sttuFy8Y06qllen_K0lNS1qeHQ
|
|
47
47
|
math_spec_mapping/Reports/markdown.py,sha256=SdhgOMpMBnGKWDG0cimk-LI_UqjQDPy87IxTb-PrBQ0,22866
|
48
48
|
math_spec_mapping/Reports/mechanisms.py,sha256=d2Rxt3JBYvqAOAYUynl0buYVoXEHrO8EGq7GK6hK8NA,1322
|
49
49
|
math_spec_mapping/Reports/node_map.py,sha256=FdSMDQG16NX6n9sZcH-T5xwsvgjrV9OqBHc9J_VlNK0,3129
|
50
|
-
math_spec_mapping/Reports/parameters.py,sha256
|
50
|
+
math_spec_mapping/Reports/parameters.py,sha256=-ucL71lolqU0xvV7yb0sXl4pFMRl5tXNWdoBfUjLOaQ,1944
|
51
51
|
math_spec_mapping/Reports/policies.py,sha256=EuBzBsTM6QSS_GHFcAyhGgWvDDZwRuKe7Eos9nX13ho,1814
|
52
52
|
math_spec_mapping/Reports/spaces.py,sha256=-76hR5wQBv4lsG000ypBJ-OprjsNjI-rNRMYdtsYnjQ,579
|
53
|
-
math_spec_mapping/Reports/state.py,sha256=
|
53
|
+
math_spec_mapping/Reports/state.py,sha256=QYeCvX5cHeZBrbvMeDsTqJcUDTuDFJSLvPbasjLspk8,3643
|
54
54
|
math_spec_mapping/Reports/tables.py,sha256=O0CNuqh3LMECq5uLjBOoxMUk5hUvkUK660FNnwWUxDY,1505
|
55
55
|
math_spec_mapping/Reports/wiring.py,sha256=u9SvKWy6T-WJUEgFI6-zgZanoOaTTs_2YwmEceDLsV8,1618
|
56
|
-
math_spec_mapping-0.3.
|
57
|
-
math_spec_mapping-0.3.
|
58
|
-
math_spec_mapping-0.3.
|
59
|
-
math_spec_mapping-0.3.
|
60
|
-
math_spec_mapping-0.3.
|
56
|
+
math_spec_mapping-0.3.12.dist-info/LICENSE,sha256=ObyEzSw8kgCaFbEfpu1zP4TrcAKLA0xhqHMZZfyh7N0,1069
|
57
|
+
math_spec_mapping-0.3.12.dist-info/METADATA,sha256=0vIDBOENySVkVAwdDuRbtZ84uOKAEwWLj9qwaR6-Mh8,6501
|
58
|
+
math_spec_mapping-0.3.12.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
59
|
+
math_spec_mapping-0.3.12.dist-info/top_level.txt,sha256=AImhn9wgazkdV0a9vfiphtQR8uGe2nq-ZIOp-6yUk9o,18
|
60
|
+
math_spec_mapping-0.3.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|