math-spec-mapping 0.3.9.1__py3-none-any.whl → 0.3.11__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- math_spec_mapping/Classes/MathSpec.py +59 -2
- math_spec_mapping/Classes/Metric.py +1 -0
- math_spec_mapping/Load/metrics.py +11 -1
- math_spec_mapping/Load/spaces.py +4 -2
- {math_spec_mapping-0.3.9.1.dist-info → math_spec_mapping-0.3.11.dist-info}/METADATA +1 -1
- {math_spec_mapping-0.3.9.1.dist-info → math_spec_mapping-0.3.11.dist-info}/RECORD +9 -9
- {math_spec_mapping-0.3.9.1.dist-info → math_spec_mapping-0.3.11.dist-info}/WHEEL +1 -1
- {math_spec_mapping-0.3.9.1.dist-info → math_spec_mapping-0.3.11.dist-info}/LICENSE +0 -0
- {math_spec_mapping-0.3.9.1.dist-info → math_spec_mapping-0.3.11.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):
|
@@ -775,8 +786,10 @@ class MathSpecImplementation:
|
|
775
786
|
self.policies = self.load_policies()
|
776
787
|
self.mechanisms = self.load_mechanisms()
|
777
788
|
self.stateful_metrics = self.load_stateful_metrics()
|
789
|
+
self.metrics = self.load_metrics()
|
778
790
|
self.load_wiring()
|
779
791
|
self.load_components()
|
792
|
+
self.load_source_files()
|
780
793
|
|
781
794
|
def load_control_actions(self):
|
782
795
|
control_actions = {}
|
@@ -951,6 +964,22 @@ class MathSpecImplementation:
|
|
951
964
|
|
952
965
|
return stateful_metrics
|
953
966
|
|
967
|
+
def load_metrics(self):
|
968
|
+
metrics = {}
|
969
|
+
|
970
|
+
for m in self.ms.metrics:
|
971
|
+
m = self.ms.metrics[m]
|
972
|
+
if "python" not in m.implementations:
|
973
|
+
print(
|
974
|
+
"No python implementation for {}. To fix this, go to Implementations/Python/Metrics and add {}".format(
|
975
|
+
m.name, m.name
|
976
|
+
)
|
977
|
+
)
|
978
|
+
else:
|
979
|
+
metrics[m.name] = m.implementations["python"]
|
980
|
+
|
981
|
+
return metrics
|
982
|
+
|
954
983
|
def load_wiring(
|
955
984
|
self,
|
956
985
|
):
|
@@ -1026,15 +1055,30 @@ class MathSpecImplementation:
|
|
1026
1055
|
state = deepcopy(state)
|
1027
1056
|
params = deepcopy(params)
|
1028
1057
|
state["Stateful Metrics"] = self.stateful_metrics
|
1058
|
+
state["Metrics"] = self.metrics
|
1029
1059
|
if state_preperation_functions:
|
1030
1060
|
for f in state_preperation_functions:
|
1031
|
-
|
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"
|
1032
1069
|
assert (
|
1033
1070
|
state is not None
|
1034
1071
|
), "A state must be returned from the state preperation functions"
|
1035
1072
|
if parameter_preperation_functions:
|
1036
1073
|
for f in parameter_preperation_functions:
|
1037
|
-
|
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"
|
1038
1082
|
assert (
|
1039
1083
|
params is not None
|
1040
1084
|
), "A parameter set must be returned from the parameter preperation functions"
|
@@ -1052,3 +1096,16 @@ class MathSpecImplementation:
|
|
1052
1096
|
for block in blocks:
|
1053
1097
|
self.components[block](state, params, [])
|
1054
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")
|
@@ -50,6 +50,14 @@ def convert_metric(ms, data: Dict, stateful_metrics_map) -> Metric:
|
|
50
50
|
for x in data["metrics_used"]
|
51
51
|
)
|
52
52
|
|
53
|
+
data["implementations"] = {}
|
54
|
+
if "python" in ms["Implementations"]:
|
55
|
+
if "metrics" in ms["Implementations"]["python"]:
|
56
|
+
if data["name"] in ms["Implementations"]["python"]["metrics"]:
|
57
|
+
data["implementations"]["python"] = ms["Implementations"]["python"][
|
58
|
+
"metrics"
|
59
|
+
][data["name"]]
|
60
|
+
|
53
61
|
# Build the metric object
|
54
62
|
return Metric(data)
|
55
63
|
|
@@ -91,7 +99,9 @@ def load_metrics(ms: Dict, json: Dict, stateful_metrics_map) -> None:
|
|
91
99
|
for z in y["metrics_used"]:
|
92
100
|
assert (
|
93
101
|
z in ms["Metrics"] or z in names or z in stateful_metrics_map
|
94
|
-
), "{} is not defined in the spec".format(
|
102
|
+
), "{} is not defined in the spec, but it is referenced in {}".format(
|
103
|
+
z, y["name"]
|
104
|
+
)
|
95
105
|
assert len(metrics) == 0, "There are circular references"
|
96
106
|
|
97
107
|
# Load the metrics into the policies
|
math_spec_mapping/Load/spaces.py
CHANGED
@@ -13,8 +13,10 @@ def convert_space(ms, data: Dict) -> Space:
|
|
13
13
|
data = data.copy()
|
14
14
|
|
15
15
|
for x in data["schema"]:
|
16
|
-
assert
|
17
|
-
data["schema"][x]
|
16
|
+
assert (
|
17
|
+
data["schema"][x] in ms["Types"]
|
18
|
+
), "Type {} not in ms for space {} at attribute {}".format(
|
19
|
+
data["schema"][x], data["name"], x
|
18
20
|
)
|
19
21
|
data["schema"][x] = ms["Types"][data["schema"][x]]
|
20
22
|
|
@@ -6,9 +6,9 @@ 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
|
-
math_spec_mapping/Classes/Metric.py,sha256=
|
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=fzV85tB3QScjiYGfhw_dyQt9L1BYYfTyTIQQcxeT8ac,530
|
14
14
|
math_spec_mapping/Classes/Space.py,sha256=QsahxoUfRsDWQLBL683KnGx72MAmRxv7CDE7TMgCG-E,472
|
@@ -30,10 +30,10 @@ math_spec_mapping/Load/general.py,sha256=2q6aGKxXhebiHHTZhtACvM4nWIkTben0o5rXuvf
|
|
30
30
|
math_spec_mapping/Load/implementations.py,sha256=SGKZ_YXeNpJUTnw5fajQTXji7S2bNQo8sh-7YcIO6pk,395
|
31
31
|
math_spec_mapping/Load/load.py,sha256=CLprDhJpbwm9RAzKM2Ghwr8eqBu0a-wvGDOCMmc01YE,2484
|
32
32
|
math_spec_mapping/Load/mechanism.py,sha256=JBy-QpB4W0Z2OcNiakONjD4_RtEgxlFKtLXfDqfhR-0,2037
|
33
|
-
math_spec_mapping/Load/metrics.py,sha256=
|
33
|
+
math_spec_mapping/Load/metrics.py,sha256=0XL-E7PUZg5PX_ZensoDpT2Z2xq893JncBEYbPzxeGo,3866
|
34
34
|
math_spec_mapping/Load/parameters.py,sha256=W4utm7to3s2fo4z3XgLH0TM1agaIad1qfM2I-lLMua4,1393
|
35
35
|
math_spec_mapping/Load/policy.py,sha256=HvlhGHGJTweVs7DOI2HSL_2_diECr8ukDUmzoFLQELo,2444
|
36
|
-
math_spec_mapping/Load/spaces.py,sha256=
|
36
|
+
math_spec_mapping/Load/spaces.py,sha256=5nJto38BVMED5KuMXOqavYj8gcSTKiNSTdMOOp5ThTA,1186
|
37
37
|
math_spec_mapping/Load/state_update_transmission_channels.py,sha256=FJWp5n4HdtHAfof5BUQ6BnRakljatL2h8dWCapaVSc0,2238
|
38
38
|
math_spec_mapping/Load/stateful_metrics.py,sha256=3Lq1ZGMaDd5OcGeqR2p5c_znkYw7ETTNPFjUVdZAHKk,2384
|
39
39
|
math_spec_mapping/Load/states.py,sha256=3YurI7eTNkN6nrXRFVrc58wH0VfM22XOuWE07HVpR7Y,1365
|
@@ -53,8 +53,8 @@ math_spec_mapping/Reports/spaces.py,sha256=-76hR5wQBv4lsG000ypBJ-OprjsNjI-rNRMYd
|
|
53
53
|
math_spec_mapping/Reports/state.py,sha256=EPiHz3cDCEPHnVjuFruVKaGJ2SclUfGUFvvOukiHPNg,3110
|
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.11.dist-info/LICENSE,sha256=ObyEzSw8kgCaFbEfpu1zP4TrcAKLA0xhqHMZZfyh7N0,1069
|
57
|
+
math_spec_mapping-0.3.11.dist-info/METADATA,sha256=5mt9yY0Os1Ve_d-ilf7LL-lmiZ_K3vyo39JjKtKDdbM,6501
|
58
|
+
math_spec_mapping-0.3.11.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
|
59
|
+
math_spec_mapping-0.3.11.dist-info/top_level.txt,sha256=AImhn9wgazkdV0a9vfiphtQR8uGe2nq-ZIOp-6yUk9o,18
|
60
|
+
math_spec_mapping-0.3.11.dist-info/RECORD,,
|
File without changes
|
File without changes
|