RATapi 0.0.0.dev0__cp310-cp310-win_amd64.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.
- RATapi/__init__.py +8 -0
- RATapi/classlist.py +387 -0
- RATapi/controls.py +143 -0
- RATapi/eventManager.dll +0 -0
- RATapi/events.py +70 -0
- RATapi/examples/__init__.py +0 -0
- RATapi/examples/absorption/__init__.py +0 -0
- RATapi/examples/absorption/absorption.py +148 -0
- RATapi/examples/absorption/volume_thiol_bilayer.py +138 -0
- RATapi/examples/data/D2O_spin_down.dat +100 -0
- RATapi/examples/data/D2O_spin_up.dat +101 -0
- RATapi/examples/data/DSPC_D2O.dat +82 -0
- RATapi/examples/data/DSPC_SMW.dat +82 -0
- RATapi/examples/data/H2O_spin_down.dat +102 -0
- RATapi/examples/data/H2O_spin_up.dat +102 -0
- RATapi/examples/data/__init__.py +0 -0
- RATapi/examples/data/c_PLP0016596.dat +146 -0
- RATapi/examples/data/c_PLP0016601.dat +97 -0
- RATapi/examples/data/c_PLP0016607.dat +104 -0
- RATapi/examples/domains/__init__.py +0 -0
- RATapi/examples/domains/alloy_domains.py +26 -0
- RATapi/examples/domains/domains_XY_model.py +70 -0
- RATapi/examples/domains/domains_custom_XY.py +69 -0
- RATapi/examples/domains/domains_custom_layers.py +46 -0
- RATapi/examples/domains/domains_standard_layers.py +75 -0
- RATapi/examples/languages/__init__.py +0 -0
- RATapi/examples/languages/custom_bilayer.py +66 -0
- RATapi/examples/languages/run_custom_file_languages.py +41 -0
- RATapi/examples/languages/setup_problem.py +130 -0
- RATapi/examples/non_polarised/DSPC_custom_XY.py +140 -0
- RATapi/examples/non_polarised/DSPC_custom_layers.py +121 -0
- RATapi/examples/non_polarised/DSPC_standard_layers.py +358 -0
- RATapi/examples/non_polarised/__init__.py +0 -0
- RATapi/examples/non_polarised/custom_XY_DSPC.py +137 -0
- RATapi/examples/non_polarised/custom_bilayer_DSPC.py +85 -0
- RATapi/inputs.py +471 -0
- RATapi/models.py +288 -0
- RATapi/outputs.py +218 -0
- RATapi/project.py +659 -0
- RATapi/rat_core.cp310-win_amd64.pyd +0 -0
- RATapi/run.py +35 -0
- RATapi/utils/__init__.py +0 -0
- RATapi/utils/custom_errors.py +42 -0
- RATapi/utils/enums.py +101 -0
- RATapi/utils/plotting.py +211 -0
- RATapi/wrappers.py +115 -0
- RATapi-0.0.0.dev0.dist-info/METADATA +57 -0
- RATapi-0.0.0.dev0.dist-info/RECORD +64 -0
- RATapi-0.0.0.dev0.dist-info/WHEEL +5 -0
- RATapi-0.0.0.dev0.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/conftest.py +4728 -0
- tests/test_classlist.py +882 -0
- tests/test_controls.py +863 -0
- tests/test_custom_errors.py +49 -0
- tests/test_events.py +61 -0
- tests/test_inputs.py +908 -0
- tests/test_models.py +308 -0
- tests/test_outputs.py +31 -0
- tests/test_plotting.py +167 -0
- tests/test_project.py +1387 -0
- tests/test_run.py +570 -0
- tests/test_wrappers.py +57 -0
- tests/utils.py +171 -0
tests/utils.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
import RATapi.outputs
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class InputAttributes:
|
|
7
|
+
"""Set input arguments as class attributes."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, **kwargs) -> None:
|
|
10
|
+
for key, value in kwargs.items():
|
|
11
|
+
setattr(self, key, value)
|
|
12
|
+
|
|
13
|
+
def __eq__(self, other: object):
|
|
14
|
+
if isinstance(other, InputAttributes):
|
|
15
|
+
return self.__dict__ == other.__dict__
|
|
16
|
+
return False
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SubInputAttributes(InputAttributes):
|
|
20
|
+
"""Trivial subclass of InputAttributes."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def dummy_function() -> None:
|
|
24
|
+
"""Trivial function for function handle tests."""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def check_results_equal(actual_results, expected_results) -> None:
|
|
28
|
+
"""Compare two instances of "Results" or "BayesResults" objects for equality.
|
|
29
|
+
|
|
30
|
+
We focus here on the fields common to both results objects, and also check the equality of the subclasses
|
|
31
|
+
"CalculationResults" and "ContrastParams".
|
|
32
|
+
"""
|
|
33
|
+
list_fields = ["reflectivity", "simulation", "shiftedData"]
|
|
34
|
+
double_list_fields = ["layerSlds", "sldProfiles", "resampledLayers"]
|
|
35
|
+
contrast_param_fields = [
|
|
36
|
+
"backgroundParams",
|
|
37
|
+
"scalefactors",
|
|
38
|
+
"bulkIn",
|
|
39
|
+
"bulkOut",
|
|
40
|
+
"resolutionParams",
|
|
41
|
+
"subRoughs",
|
|
42
|
+
"resample",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
assert (
|
|
46
|
+
isinstance(actual_results, RATapi.outputs.Results) and isinstance(expected_results, RATapi.outputs.Results)
|
|
47
|
+
) or (
|
|
48
|
+
isinstance(actual_results, RATapi.outputs.BayesResults)
|
|
49
|
+
and isinstance(expected_results, RATapi.outputs.BayesResults)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# The first set of fields are either 1D or 2D python lists containing numpy arrays.
|
|
53
|
+
# Hence, we need to compare them element-wise.
|
|
54
|
+
for list_field in list_fields:
|
|
55
|
+
for a, b in zip(getattr(actual_results, list_field), getattr(expected_results, list_field)):
|
|
56
|
+
assert (a == b).all()
|
|
57
|
+
|
|
58
|
+
for list_field in double_list_fields:
|
|
59
|
+
actual_list = getattr(actual_results, list_field)
|
|
60
|
+
expected_list = getattr(expected_results, list_field)
|
|
61
|
+
assert len(actual_list) == len(expected_list)
|
|
62
|
+
for i in range(len(actual_list)):
|
|
63
|
+
for a, b in zip(actual_list[i], expected_list[i]):
|
|
64
|
+
assert (a == b).all()
|
|
65
|
+
|
|
66
|
+
# Compare the final fields
|
|
67
|
+
assert (actual_results.fitParams == expected_results.fitParams).all()
|
|
68
|
+
assert actual_results.fitNames == expected_results.fitNames
|
|
69
|
+
|
|
70
|
+
# Compare the two subclasses defined within the class
|
|
71
|
+
assert actual_results.calculationResults.sumChi == expected_results.calculationResults.sumChi
|
|
72
|
+
assert (actual_results.calculationResults.chiValues == expected_results.calculationResults.chiValues).all()
|
|
73
|
+
|
|
74
|
+
for field in contrast_param_fields:
|
|
75
|
+
assert (getattr(actual_results.contrastParams, field) == getattr(expected_results.contrastParams, field)).all()
|
|
76
|
+
|
|
77
|
+
if isinstance(actual_results, RATapi.outputs.BayesResults) and isinstance(
|
|
78
|
+
expected_results, RATapi.outputs.BayesResults
|
|
79
|
+
):
|
|
80
|
+
check_bayes_fields_equal(actual_results, expected_results)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def check_bayes_fields_equal(actual_results, expected_results) -> None:
|
|
84
|
+
"""Compare two instances of the "BayesResults" object for equality.
|
|
85
|
+
|
|
86
|
+
We focus here on the fields and subclasses specific to the Bayesian optimisation.
|
|
87
|
+
"""
|
|
88
|
+
# The BayesResults object consists of a number of subclasses, each containing fields of differing formats.
|
|
89
|
+
subclasses = ["predictionIntervals", "confidenceIntervals", "dreamParams", "dreamOutput", "nestedSamplerOutput"]
|
|
90
|
+
|
|
91
|
+
param_fields = {
|
|
92
|
+
"predictionIntervals": [],
|
|
93
|
+
"confidenceIntervals": [],
|
|
94
|
+
"dreamParams": [
|
|
95
|
+
"nParams",
|
|
96
|
+
"nChains",
|
|
97
|
+
"nGenerations",
|
|
98
|
+
"parallel",
|
|
99
|
+
"CPU",
|
|
100
|
+
"jumpProbability",
|
|
101
|
+
"pUnitGamma",
|
|
102
|
+
"nCR",
|
|
103
|
+
"delta",
|
|
104
|
+
"steps",
|
|
105
|
+
"zeta",
|
|
106
|
+
"outlier",
|
|
107
|
+
"adaptPCR",
|
|
108
|
+
"thinning",
|
|
109
|
+
"epsilon",
|
|
110
|
+
"ABC",
|
|
111
|
+
"IO",
|
|
112
|
+
"storeOutput",
|
|
113
|
+
],
|
|
114
|
+
"dreamOutput": ["runtime", "iteration", "modelOutput"],
|
|
115
|
+
"nestedSamplerOutput": ["logZ"],
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
list_fields = {
|
|
119
|
+
"predictionIntervals": ["reflectivity", "reflectivityXData"],
|
|
120
|
+
"confidenceIntervals": [],
|
|
121
|
+
"dreamParams": [],
|
|
122
|
+
"dreamOutput": [],
|
|
123
|
+
"nestedSamplerOutput": [],
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
double_list_fields = {
|
|
127
|
+
"predictionIntervals": ["sld", "sldXData"],
|
|
128
|
+
"confidenceIntervals": [],
|
|
129
|
+
"dreamParams": [],
|
|
130
|
+
"dreamOutput": [],
|
|
131
|
+
"nestedSamplerOutput": [],
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
array_fields = {
|
|
135
|
+
"predictionIntervals": ["sampleChi"],
|
|
136
|
+
"confidenceIntervals": ["percentile65", "percentile95", "mean"],
|
|
137
|
+
"dreamParams": ["R"],
|
|
138
|
+
"dreamOutput": ["allChains", "outlierChains", "AR", "R_stat", "CR"],
|
|
139
|
+
"nestedSamplerOutput": ["nestSamples", "postSamples"],
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
for subclass in subclasses:
|
|
143
|
+
actual_subclass = getattr(actual_results, subclass)
|
|
144
|
+
expected_subclass = getattr(expected_results, subclass)
|
|
145
|
+
|
|
146
|
+
for field in param_fields[subclass]:
|
|
147
|
+
assert getattr(actual_subclass, field) == getattr(expected_subclass, field)
|
|
148
|
+
|
|
149
|
+
for field in list_fields[subclass]:
|
|
150
|
+
for a, b in zip(getattr(actual_subclass, field), getattr(expected_subclass, field)):
|
|
151
|
+
assert (a == b).all()
|
|
152
|
+
|
|
153
|
+
for field in double_list_fields[subclass]:
|
|
154
|
+
actual_list = getattr(actual_subclass, field)
|
|
155
|
+
expected_list = getattr(expected_subclass, field)
|
|
156
|
+
assert len(actual_list) == len(expected_list)
|
|
157
|
+
for i in range(len(actual_list)):
|
|
158
|
+
for a, b in zip(actual_list[i], expected_list[i]):
|
|
159
|
+
assert (a == b).all()
|
|
160
|
+
|
|
161
|
+
# Need to account for the arrays that are initialised as "NaN" in the compiled code
|
|
162
|
+
for array in array_fields[subclass]:
|
|
163
|
+
actual_array = getattr(actual_subclass, array)
|
|
164
|
+
expected_array = getattr(expected_subclass, array)
|
|
165
|
+
for i in range(len(actual_array)):
|
|
166
|
+
assert (actual_array == expected_array).all() or (
|
|
167
|
+
["NaN" if np.isnan(el) else el for el in actual_array[i]]
|
|
168
|
+
== ["NaN" if np.isnan(el) else el for el in expected_array[i]]
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
assert (actual_results.chain == expected_results.chain).all()
|