RATapi 0.0.0.dev0__cp39-cp39-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.cp39-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/test_inputs.py
ADDED
|
@@ -0,0 +1,908 @@
|
|
|
1
|
+
"""Test the inputs module."""
|
|
2
|
+
|
|
3
|
+
import pathlib
|
|
4
|
+
from itertools import chain
|
|
5
|
+
from unittest import mock
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
import RATapi
|
|
11
|
+
import RATapi.wrappers
|
|
12
|
+
from RATapi.inputs import check_indices, make_cells, make_controls, make_input, make_problem
|
|
13
|
+
from RATapi.rat_core import Cells, Checks, Control, Limits, Priors, ProblemDefinition
|
|
14
|
+
from RATapi.utils.enums import (
|
|
15
|
+
BoundHandling,
|
|
16
|
+
Calculations,
|
|
17
|
+
Display,
|
|
18
|
+
Geometries,
|
|
19
|
+
LayerModels,
|
|
20
|
+
Parallel,
|
|
21
|
+
Procedures,
|
|
22
|
+
TypeOptions,
|
|
23
|
+
)
|
|
24
|
+
from tests.utils import dummy_function
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.fixture
|
|
28
|
+
def standard_layers_project():
|
|
29
|
+
"""Add parameters to the default project for a non polarised calculation."""
|
|
30
|
+
test_project = RATapi.Project(
|
|
31
|
+
data=RATapi.ClassList([RATapi.models.Data(name="Test Data", data=np.array([[1.0, 1.0, 1.0]]))]),
|
|
32
|
+
)
|
|
33
|
+
test_project.parameters.append(name="Test Thickness")
|
|
34
|
+
test_project.parameters.append(name="Test SLD")
|
|
35
|
+
test_project.parameters.append(name="Test Roughness")
|
|
36
|
+
test_project.custom_files.append(
|
|
37
|
+
name="Test Custom File",
|
|
38
|
+
filename="python_test.py",
|
|
39
|
+
function_name="dummy_function",
|
|
40
|
+
language="python",
|
|
41
|
+
)
|
|
42
|
+
test_project.layers.append(
|
|
43
|
+
name="Test Layer",
|
|
44
|
+
thickness="Test Thickness",
|
|
45
|
+
SLD="Test SLD",
|
|
46
|
+
roughness="Test Roughness",
|
|
47
|
+
)
|
|
48
|
+
test_project.contrasts.append(
|
|
49
|
+
name="Test Contrast",
|
|
50
|
+
data="Test Data",
|
|
51
|
+
background="Background 1",
|
|
52
|
+
bulk_in="SLD Air",
|
|
53
|
+
bulk_out="SLD D2O",
|
|
54
|
+
scalefactor="Scalefactor 1",
|
|
55
|
+
resolution="Resolution 1",
|
|
56
|
+
model=["Test Layer"],
|
|
57
|
+
)
|
|
58
|
+
return test_project
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@pytest.fixture
|
|
62
|
+
def domains_project():
|
|
63
|
+
"""Add parameters to the default project for a domains calculation."""
|
|
64
|
+
test_project = RATapi.Project(
|
|
65
|
+
calculation=Calculations.Domains,
|
|
66
|
+
data=RATapi.ClassList([RATapi.models.Data(name="Test Data", data=np.array([[1.0, 1.0, 1.0]]))]),
|
|
67
|
+
)
|
|
68
|
+
test_project.parameters.append(name="Test Thickness")
|
|
69
|
+
test_project.parameters.append(name="Test SLD")
|
|
70
|
+
test_project.parameters.append(name="Test Roughness")
|
|
71
|
+
test_project.custom_files.append(name="Test Custom File", filename="matlab_test.m", language="matlab")
|
|
72
|
+
test_project.layers.append(
|
|
73
|
+
name="Test Layer",
|
|
74
|
+
thickness="Test Thickness",
|
|
75
|
+
SLD="Test SLD",
|
|
76
|
+
roughness="Test Roughness",
|
|
77
|
+
)
|
|
78
|
+
test_project.domain_contrasts.append(name="up", model=["Test Layer"])
|
|
79
|
+
test_project.domain_contrasts.append(name="down", model=["Test Layer"])
|
|
80
|
+
test_project.contrasts.append(
|
|
81
|
+
name="Test Contrast",
|
|
82
|
+
data="Test Data",
|
|
83
|
+
background="Background 1",
|
|
84
|
+
bulk_in="SLD Air",
|
|
85
|
+
bulk_out="SLD D2O",
|
|
86
|
+
scalefactor="Scalefactor 1",
|
|
87
|
+
resolution="Resolution 1",
|
|
88
|
+
domain_ratio="Domain Ratio 1",
|
|
89
|
+
model=["down", "up"],
|
|
90
|
+
)
|
|
91
|
+
return test_project
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@pytest.fixture
|
|
95
|
+
def custom_xy_project():
|
|
96
|
+
"""Add parameters to the default project for a non polarised calculation and use the custom xy model."""
|
|
97
|
+
test_project = RATapi.Project(model=LayerModels.CustomXY)
|
|
98
|
+
test_project.parameters.append(name="Test Thickness")
|
|
99
|
+
test_project.parameters.append(name="Test SLD")
|
|
100
|
+
test_project.parameters.append(name="Test Roughness")
|
|
101
|
+
test_project.custom_files.append(name="Test Custom File", filename="cpp_test.dll", language="cpp")
|
|
102
|
+
test_project.contrasts.append(
|
|
103
|
+
name="Test Contrast",
|
|
104
|
+
data="Simulation",
|
|
105
|
+
background="Background 1",
|
|
106
|
+
bulk_in="SLD Air",
|
|
107
|
+
bulk_out="SLD D2O",
|
|
108
|
+
scalefactor="Scalefactor 1",
|
|
109
|
+
resolution="Resolution 1",
|
|
110
|
+
model=["Test Custom File"],
|
|
111
|
+
)
|
|
112
|
+
return test_project
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@pytest.fixture
|
|
116
|
+
def standard_layers_problem():
|
|
117
|
+
"""The expected problem object from "standard_layers_project"."""
|
|
118
|
+
problem = ProblemDefinition()
|
|
119
|
+
problem.TF = Calculations.NonPolarised
|
|
120
|
+
problem.modelType = LayerModels.StandardLayers
|
|
121
|
+
problem.geometry = Geometries.AirSubstrate
|
|
122
|
+
problem.useImaginary = False
|
|
123
|
+
problem.params = [3.0, 0.0, 0.0, 0.0]
|
|
124
|
+
problem.bulkIn = [0.0]
|
|
125
|
+
problem.bulkOut = [6.35e-06]
|
|
126
|
+
problem.qzshifts = []
|
|
127
|
+
problem.scalefactors = [0.23]
|
|
128
|
+
problem.domainRatio = []
|
|
129
|
+
problem.backgroundParams = [1e-06]
|
|
130
|
+
problem.resolutionParams = [0.03]
|
|
131
|
+
problem.contrastBulkIns = [1]
|
|
132
|
+
problem.contrastBulkOuts = [1]
|
|
133
|
+
problem.contrastQzshifts = []
|
|
134
|
+
problem.contrastScalefactors = [1]
|
|
135
|
+
problem.contrastBackgroundParams = [1]
|
|
136
|
+
problem.contrastBackgroundActions = [1]
|
|
137
|
+
problem.contrastResolutionParams = [1]
|
|
138
|
+
problem.contrastCustomFiles = [float("NaN")]
|
|
139
|
+
problem.contrastDomainRatios = [0]
|
|
140
|
+
problem.resample = [False]
|
|
141
|
+
problem.dataPresent = [1]
|
|
142
|
+
problem.oilChiDataPresent = [0]
|
|
143
|
+
problem.numberOfContrasts = 1
|
|
144
|
+
problem.numberOfLayers = 1
|
|
145
|
+
problem.numberOfDomainContrasts = 0
|
|
146
|
+
problem.fitParams = [3.0]
|
|
147
|
+
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03]
|
|
148
|
+
problem.fitLimits = [[1.0, 5.0]]
|
|
149
|
+
problem.otherLimits = [
|
|
150
|
+
[0.0, 0.0],
|
|
151
|
+
[0.0, 0.0],
|
|
152
|
+
[0.0, 0.0],
|
|
153
|
+
[1e-07, 1e-05],
|
|
154
|
+
[0.02, 0.25],
|
|
155
|
+
[0.0, 0.0],
|
|
156
|
+
[6.2e-06, 6.35e-06],
|
|
157
|
+
[0.01, 0.05],
|
|
158
|
+
]
|
|
159
|
+
|
|
160
|
+
return problem
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@pytest.fixture
|
|
164
|
+
def domains_problem():
|
|
165
|
+
"""The expected problem object from "standard_layers_project"."""
|
|
166
|
+
problem = ProblemDefinition()
|
|
167
|
+
problem.TF = Calculations.Domains
|
|
168
|
+
problem.modelType = LayerModels.StandardLayers
|
|
169
|
+
problem.geometry = Geometries.AirSubstrate
|
|
170
|
+
problem.useImaginary = False
|
|
171
|
+
problem.params = [3.0, 0.0, 0.0, 0.0]
|
|
172
|
+
problem.bulkIn = [0.0]
|
|
173
|
+
problem.bulkOut = [6.35e-06]
|
|
174
|
+
problem.qzshifts = []
|
|
175
|
+
problem.scalefactors = [0.23]
|
|
176
|
+
problem.domainRatio = [0.5]
|
|
177
|
+
problem.backgroundParams = [1e-06]
|
|
178
|
+
problem.resolutionParams = [0.03]
|
|
179
|
+
problem.contrastBulkIns = [1]
|
|
180
|
+
problem.contrastBulkOuts = [1]
|
|
181
|
+
problem.contrastQzshifts = []
|
|
182
|
+
problem.contrastScalefactors = [1]
|
|
183
|
+
problem.contrastBackgroundParams = [1]
|
|
184
|
+
problem.contrastBackgroundActions = [1]
|
|
185
|
+
problem.contrastResolutionParams = [1]
|
|
186
|
+
problem.contrastCustomFiles = [float("NaN")]
|
|
187
|
+
problem.contrastDomainRatios = [1]
|
|
188
|
+
problem.resample = [False]
|
|
189
|
+
problem.dataPresent = [1]
|
|
190
|
+
problem.oilChiDataPresent = [0]
|
|
191
|
+
problem.numberOfContrasts = 1
|
|
192
|
+
problem.numberOfLayers = 1
|
|
193
|
+
problem.numberOfDomainContrasts = 2
|
|
194
|
+
problem.fitParams = [3.0]
|
|
195
|
+
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03, 0.5]
|
|
196
|
+
problem.fitLimits = [[1.0, 5.0]]
|
|
197
|
+
problem.otherLimits = [
|
|
198
|
+
[0.0, 0.0],
|
|
199
|
+
[0.0, 0.0],
|
|
200
|
+
[0.0, 0.0],
|
|
201
|
+
[1e-07, 1e-05],
|
|
202
|
+
[0.02, 0.25],
|
|
203
|
+
[0.0, 0.0],
|
|
204
|
+
[6.2e-06, 6.35e-06],
|
|
205
|
+
[0.01, 0.05],
|
|
206
|
+
[0.4, 0.6],
|
|
207
|
+
]
|
|
208
|
+
|
|
209
|
+
return problem
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
@pytest.fixture
|
|
213
|
+
def custom_xy_problem():
|
|
214
|
+
"""The expected problem object from "custom_xy_project"."""
|
|
215
|
+
problem = ProblemDefinition()
|
|
216
|
+
problem.TF = Calculations.NonPolarised
|
|
217
|
+
problem.modelType = LayerModels.CustomXY
|
|
218
|
+
problem.geometry = Geometries.AirSubstrate
|
|
219
|
+
problem.useImaginary = False
|
|
220
|
+
problem.params = [3.0, 0.0, 0.0, 0.0]
|
|
221
|
+
problem.bulkIn = [0.0]
|
|
222
|
+
problem.bulkOut = [6.35e-06]
|
|
223
|
+
problem.qzshifts = []
|
|
224
|
+
problem.scalefactors = [0.23]
|
|
225
|
+
problem.domainRatio = []
|
|
226
|
+
problem.backgroundParams = [1e-06]
|
|
227
|
+
problem.resolutionParams = [0.03]
|
|
228
|
+
problem.contrastBulkIns = [1]
|
|
229
|
+
problem.contrastBulkOuts = [1]
|
|
230
|
+
problem.contrastQzshifts = []
|
|
231
|
+
problem.contrastScalefactors = [1]
|
|
232
|
+
problem.contrastBackgroundParams = [1]
|
|
233
|
+
problem.contrastBackgroundActions = [1]
|
|
234
|
+
problem.contrastResolutionParams = [1]
|
|
235
|
+
problem.contrastCustomFiles = [1]
|
|
236
|
+
problem.contrastDomainRatios = [0]
|
|
237
|
+
problem.resample = [False]
|
|
238
|
+
problem.dataPresent = [0]
|
|
239
|
+
problem.oilChiDataPresent = [0]
|
|
240
|
+
problem.numberOfContrasts = 1
|
|
241
|
+
problem.numberOfLayers = 0
|
|
242
|
+
problem.numberOfDomainContrasts = 0
|
|
243
|
+
problem.fitParams = [3.0]
|
|
244
|
+
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03]
|
|
245
|
+
problem.fitLimits = [[1.0, 5.0]]
|
|
246
|
+
problem.otherLimits = [
|
|
247
|
+
[0.0, 0.0],
|
|
248
|
+
[0.0, 0.0],
|
|
249
|
+
[0.0, 0.0],
|
|
250
|
+
[1e-07, 1e-05],
|
|
251
|
+
[0.02, 0.25],
|
|
252
|
+
[0.0, 0.0],
|
|
253
|
+
[6.2e-06, 6.35e-06],
|
|
254
|
+
[0.01, 0.05],
|
|
255
|
+
]
|
|
256
|
+
|
|
257
|
+
return problem
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
@pytest.fixture
|
|
261
|
+
def standard_layers_cells():
|
|
262
|
+
"""The expected cells object from "standard_layers_project"."""
|
|
263
|
+
cells = Cells()
|
|
264
|
+
cells.f1 = [[0, 1]]
|
|
265
|
+
cells.f2 = [np.array([[1.0, 1.0, 1.0]])]
|
|
266
|
+
cells.f3 = [[1.0, 1.0]]
|
|
267
|
+
cells.f4 = [[1.0, 1.0]]
|
|
268
|
+
cells.f5 = [[1]]
|
|
269
|
+
cells.f6 = [[2, 3, 4, float("nan"), 2]]
|
|
270
|
+
cells.f7 = ["Substrate Roughness", "Test Thickness", "Test SLD", "Test Roughness"]
|
|
271
|
+
cells.f8 = ["Background Param 1"]
|
|
272
|
+
cells.f9 = ["Scalefactor 1"]
|
|
273
|
+
cells.f10 = []
|
|
274
|
+
cells.f11 = ["SLD Air"]
|
|
275
|
+
cells.f12 = ["SLD D2O"]
|
|
276
|
+
cells.f13 = ["Resolution Param 1"]
|
|
277
|
+
cells.f14 = [dummy_function]
|
|
278
|
+
cells.f15 = [TypeOptions.Constant]
|
|
279
|
+
cells.f16 = [TypeOptions.Constant]
|
|
280
|
+
cells.f17 = [[[]]]
|
|
281
|
+
cells.f18 = []
|
|
282
|
+
cells.f19 = []
|
|
283
|
+
cells.f20 = []
|
|
284
|
+
|
|
285
|
+
return cells
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
@pytest.fixture
|
|
289
|
+
def domains_cells():
|
|
290
|
+
"""The expected cells object from "domains_project"."""
|
|
291
|
+
cells = Cells()
|
|
292
|
+
cells.f1 = [[0, 1]]
|
|
293
|
+
cells.f2 = [np.array([[1.0, 1.0, 1.0]])]
|
|
294
|
+
cells.f3 = [[1.0, 1.0]]
|
|
295
|
+
cells.f4 = [[1.0, 1.0]]
|
|
296
|
+
cells.f5 = [[2, 1]]
|
|
297
|
+
cells.f6 = [[2, 3, 4, float("nan"), 2]]
|
|
298
|
+
cells.f7 = ["Substrate Roughness", "Test Thickness", "Test SLD", "Test Roughness"]
|
|
299
|
+
cells.f8 = ["Background Param 1"]
|
|
300
|
+
cells.f9 = ["Scalefactor 1"]
|
|
301
|
+
cells.f10 = []
|
|
302
|
+
cells.f11 = ["SLD Air"]
|
|
303
|
+
cells.f12 = ["SLD D2O"]
|
|
304
|
+
cells.f13 = ["Resolution Param 1"]
|
|
305
|
+
cells.f14 = [dummy_function]
|
|
306
|
+
cells.f15 = [TypeOptions.Constant]
|
|
307
|
+
cells.f16 = [TypeOptions.Constant]
|
|
308
|
+
cells.f17 = [[[]]]
|
|
309
|
+
cells.f18 = [[0, 1], [0, 1]]
|
|
310
|
+
cells.f19 = [[1], [1]]
|
|
311
|
+
cells.f20 = ["Domain Ratio 1"]
|
|
312
|
+
|
|
313
|
+
return cells
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
@pytest.fixture
|
|
317
|
+
def custom_xy_cells():
|
|
318
|
+
"""The expected cells object from "custom_xy_project"."""
|
|
319
|
+
cells = Cells()
|
|
320
|
+
cells.f1 = [[0, 1]]
|
|
321
|
+
cells.f2 = [np.empty([0, 3])]
|
|
322
|
+
cells.f3 = [[0.0, 0.0]]
|
|
323
|
+
cells.f4 = [[0.005, 0.7]]
|
|
324
|
+
cells.f5 = [[0]]
|
|
325
|
+
cells.f6 = [[0]]
|
|
326
|
+
cells.f7 = ["Substrate Roughness", "Test Thickness", "Test SLD", "Test Roughness"]
|
|
327
|
+
cells.f8 = ["Background Param 1"]
|
|
328
|
+
cells.f9 = ["Scalefactor 1"]
|
|
329
|
+
cells.f10 = []
|
|
330
|
+
cells.f11 = ["SLD Air"]
|
|
331
|
+
cells.f12 = ["SLD D2O"]
|
|
332
|
+
cells.f13 = ["Resolution Param 1"]
|
|
333
|
+
cells.f14 = [dummy_function]
|
|
334
|
+
cells.f15 = [TypeOptions.Constant]
|
|
335
|
+
cells.f16 = [TypeOptions.Constant]
|
|
336
|
+
cells.f17 = [[[]]]
|
|
337
|
+
cells.f18 = []
|
|
338
|
+
cells.f19 = []
|
|
339
|
+
cells.f20 = []
|
|
340
|
+
|
|
341
|
+
return cells
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
@pytest.fixture
|
|
345
|
+
def non_polarised_limits():
|
|
346
|
+
"""The expected limits object from "standard_layers_project" and "custom_xy_project"."""
|
|
347
|
+
limits = Limits()
|
|
348
|
+
limits.param = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
|
|
349
|
+
limits.backgroundParam = [[1e-7, 1e-5]]
|
|
350
|
+
limits.qzshift = []
|
|
351
|
+
limits.scalefactor = [[0.02, 0.25]]
|
|
352
|
+
limits.bulkIn = [[0.0, 0.0]]
|
|
353
|
+
limits.bulkOut = [[6.2e-6, 6.35e-6]]
|
|
354
|
+
limits.resolutionParam = [[0.01, 0.05]]
|
|
355
|
+
limits.domainRatio = []
|
|
356
|
+
|
|
357
|
+
return limits
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
@pytest.fixture
|
|
361
|
+
def domains_limits():
|
|
362
|
+
"""The expected limits object from "domains_project"."""
|
|
363
|
+
limits = Limits()
|
|
364
|
+
limits.param = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
|
|
365
|
+
limits.backgroundParam = [[1e-7, 1e-5]]
|
|
366
|
+
limits.qzshift = []
|
|
367
|
+
limits.scalefactor = [[0.02, 0.25]]
|
|
368
|
+
limits.bulkIn = [[0.0, 0.0]]
|
|
369
|
+
limits.bulkOut = [[6.2e-6, 6.35e-6]]
|
|
370
|
+
limits.resolutionParam = [[0.01, 0.05]]
|
|
371
|
+
limits.domainRatio = [[0.4, 0.6]]
|
|
372
|
+
|
|
373
|
+
return limits
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
@pytest.fixture
|
|
377
|
+
def non_polarised_priors():
|
|
378
|
+
"""The expected priors object from "standard_layers_project" and "custom_xy_project"."""
|
|
379
|
+
priors = Priors()
|
|
380
|
+
priors.param = [
|
|
381
|
+
["Substrate Roughness", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
|
|
382
|
+
["Test Thickness", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
|
|
383
|
+
["Test SLD", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
|
|
384
|
+
["Test Roughness", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
|
|
385
|
+
]
|
|
386
|
+
priors.backgroundParam = [["Background Param 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
387
|
+
priors.qzshift = []
|
|
388
|
+
priors.scalefactor = [["Scalefactor 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
389
|
+
priors.bulkIn = [["SLD Air", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
390
|
+
priors.bulkOut = [["SLD D2O", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
391
|
+
priors.resolutionParam = [["Resolution Param 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
392
|
+
priors.domainRatio = []
|
|
393
|
+
priors.priorNames = [
|
|
394
|
+
"Substrate Roughness",
|
|
395
|
+
"Test Thickness",
|
|
396
|
+
"Test SLD",
|
|
397
|
+
"Test Roughness",
|
|
398
|
+
"Background Param 1",
|
|
399
|
+
"Scalefactor 1",
|
|
400
|
+
"SLD Air",
|
|
401
|
+
"SLD D2O",
|
|
402
|
+
"Resolution Param 1",
|
|
403
|
+
]
|
|
404
|
+
priors.priorValues = [
|
|
405
|
+
[1, 0.0, np.inf],
|
|
406
|
+
[1, 0.0, np.inf],
|
|
407
|
+
[1, 0.0, np.inf],
|
|
408
|
+
[1, 0.0, np.inf],
|
|
409
|
+
[1, 0.0, np.inf],
|
|
410
|
+
[1, 0.0, np.inf],
|
|
411
|
+
[1, 0.0, np.inf],
|
|
412
|
+
[1, 0.0, np.inf],
|
|
413
|
+
[1, 0.0, np.inf],
|
|
414
|
+
]
|
|
415
|
+
|
|
416
|
+
return priors
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
@pytest.fixture
|
|
420
|
+
def domains_priors():
|
|
421
|
+
"""The expected priors object from "domains_project"."""
|
|
422
|
+
priors = Priors()
|
|
423
|
+
priors.param = [
|
|
424
|
+
["Substrate Roughness", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
|
|
425
|
+
["Test Thickness", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
|
|
426
|
+
["Test SLD", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
|
|
427
|
+
["Test Roughness", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
|
|
428
|
+
]
|
|
429
|
+
priors.backgroundParam = [["Background Param 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
430
|
+
priors.qzshift = []
|
|
431
|
+
priors.scalefactor = [["Scalefactor 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
432
|
+
priors.bulkIn = [["SLD Air", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
433
|
+
priors.bulkOut = [["SLD D2O", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
434
|
+
priors.resolutionParam = [["Resolution Param 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
435
|
+
priors.domainRatio = [["Domain Ratio 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
|
|
436
|
+
priors.priorNames = [
|
|
437
|
+
"Substrate Roughness",
|
|
438
|
+
"Test Thickness",
|
|
439
|
+
"Test SLD",
|
|
440
|
+
"Test Roughness",
|
|
441
|
+
"Background Param 1",
|
|
442
|
+
"Scalefactor 1",
|
|
443
|
+
"SLD Air",
|
|
444
|
+
"SLD D2O",
|
|
445
|
+
"Resolution Param 1",
|
|
446
|
+
"Domain Ratio 1",
|
|
447
|
+
]
|
|
448
|
+
priors.priorValues = [
|
|
449
|
+
[1, 0.0, np.inf],
|
|
450
|
+
[1, 0.0, np.inf],
|
|
451
|
+
[1, 0.0, np.inf],
|
|
452
|
+
[1, 0.0, np.inf],
|
|
453
|
+
[1, 0.0, np.inf],
|
|
454
|
+
[1, 0.0, np.inf],
|
|
455
|
+
[1, 0.0, np.inf],
|
|
456
|
+
[1, 0.0, np.inf],
|
|
457
|
+
[1, 0.0, np.inf],
|
|
458
|
+
[1, 0.0, np.inf],
|
|
459
|
+
]
|
|
460
|
+
|
|
461
|
+
return priors
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
@pytest.fixture
|
|
465
|
+
def standard_layers_controls():
|
|
466
|
+
"""The expected controls object for input to the compiled RAT code given the default inputs and
|
|
467
|
+
"standard_layers_project".
|
|
468
|
+
"""
|
|
469
|
+
controls = Control()
|
|
470
|
+
controls.procedure = Procedures.Calculate
|
|
471
|
+
controls.parallel = Parallel.Single
|
|
472
|
+
controls.calcSldDuringFit = False
|
|
473
|
+
controls.resampleParams = [0.9, 50.0]
|
|
474
|
+
controls.display = Display.Iter
|
|
475
|
+
controls.xTolerance = 1.0e-6
|
|
476
|
+
controls.funcTolerance = 1.0e-6
|
|
477
|
+
controls.maxFuncEvals = 10000
|
|
478
|
+
controls.maxIterations = 1000
|
|
479
|
+
controls.updateFreq = 1
|
|
480
|
+
controls.updatePlotFreq = 20
|
|
481
|
+
controls.populationSize = 20
|
|
482
|
+
controls.fWeight = 0.5
|
|
483
|
+
controls.crossoverProbability = 0.8
|
|
484
|
+
controls.strategy = 4
|
|
485
|
+
controls.targetValue = 1.0
|
|
486
|
+
controls.numGenerations = 500
|
|
487
|
+
controls.nLive = 150
|
|
488
|
+
controls.nMCMC = 0.0
|
|
489
|
+
controls.propScale = 0.1
|
|
490
|
+
controls.nsTolerance = 0.1
|
|
491
|
+
controls.nSamples = 20000
|
|
492
|
+
controls.nChains = 10
|
|
493
|
+
controls.jumpProbability = 0.5
|
|
494
|
+
controls.pUnitGamma = 0.2
|
|
495
|
+
controls.boundHandling = BoundHandling.Reflect
|
|
496
|
+
controls.adaptPCR = True
|
|
497
|
+
controls.checks.fitParam = [1, 0, 0, 0]
|
|
498
|
+
controls.checks.fitBackgroundParam = [0]
|
|
499
|
+
controls.checks.fitQzshift = []
|
|
500
|
+
controls.checks.fitScalefactor = [0]
|
|
501
|
+
controls.checks.fitBulkIn = [0]
|
|
502
|
+
controls.checks.fitBulkOut = [0]
|
|
503
|
+
controls.checks.fitResolutionParam = [0]
|
|
504
|
+
controls.checks.fitDomainRatio = []
|
|
505
|
+
|
|
506
|
+
return controls
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
@pytest.fixture
|
|
510
|
+
def custom_xy_controls():
|
|
511
|
+
"""The expected controls object for input to the compiled RAT code given the default inputs and
|
|
512
|
+
"custom_xy_project".
|
|
513
|
+
"""
|
|
514
|
+
controls = Control()
|
|
515
|
+
controls.procedure = Procedures.Calculate
|
|
516
|
+
controls.parallel = Parallel.Single
|
|
517
|
+
controls.calcSldDuringFit = True
|
|
518
|
+
controls.resampleParams = [0.9, 50.0]
|
|
519
|
+
controls.display = Display.Iter
|
|
520
|
+
controls.xTolerance = 1.0e-6
|
|
521
|
+
controls.funcTolerance = 1.0e-6
|
|
522
|
+
controls.maxFuncEvals = 10000
|
|
523
|
+
controls.maxIterations = 1000
|
|
524
|
+
controls.updateFreq = 1
|
|
525
|
+
controls.updatePlotFreq = 20
|
|
526
|
+
controls.populationSize = 20
|
|
527
|
+
controls.fWeight = 0.5
|
|
528
|
+
controls.crossoverProbability = 0.8
|
|
529
|
+
controls.strategy = 4
|
|
530
|
+
controls.targetValue = 1.0
|
|
531
|
+
controls.numGenerations = 500
|
|
532
|
+
controls.nLive = 150
|
|
533
|
+
controls.nMCMC = 0.0
|
|
534
|
+
controls.propScale = 0.1
|
|
535
|
+
controls.nsTolerance = 0.1
|
|
536
|
+
controls.nSamples = 20000
|
|
537
|
+
controls.nChains = 10
|
|
538
|
+
controls.jumpProbability = 0.5
|
|
539
|
+
controls.pUnitGamma = 0.2
|
|
540
|
+
controls.boundHandling = BoundHandling.Reflect
|
|
541
|
+
controls.adaptPCR = True
|
|
542
|
+
controls.checks.fitParam = [1, 0, 0, 0]
|
|
543
|
+
controls.checks.fitBackgroundParam = [0]
|
|
544
|
+
controls.checks.fitQzshift = []
|
|
545
|
+
controls.checks.fitScalefactor = [0]
|
|
546
|
+
controls.checks.fitBulkIn = [0]
|
|
547
|
+
controls.checks.fitBulkOut = [0]
|
|
548
|
+
controls.checks.fitResolutionParam = [0]
|
|
549
|
+
controls.checks.fitDomainRatio = []
|
|
550
|
+
|
|
551
|
+
return controls
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
@pytest.fixture
|
|
555
|
+
def test_checks():
|
|
556
|
+
"""The expected checks object from "standard_layers_project", "domains_project" and "custom_xy_project"."""
|
|
557
|
+
checks = Checks()
|
|
558
|
+
checks.fitParam = [1, 0, 0, 0]
|
|
559
|
+
checks.fitBackgroundParam = [0]
|
|
560
|
+
checks.fitQzshift = []
|
|
561
|
+
checks.fitScalefactor = [0]
|
|
562
|
+
checks.fitBulkIn = [0]
|
|
563
|
+
checks.fitBulkOut = [0]
|
|
564
|
+
checks.fitResolutionParam = [0]
|
|
565
|
+
checks.fitDomainRatio = []
|
|
566
|
+
|
|
567
|
+
return checks
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
@pytest.mark.parametrize(
|
|
571
|
+
["test_project", "test_problem", "test_cells", "test_limits", "test_priors", "test_controls"],
|
|
572
|
+
[
|
|
573
|
+
(
|
|
574
|
+
"standard_layers_project",
|
|
575
|
+
"standard_layers_problem",
|
|
576
|
+
"standard_layers_cells",
|
|
577
|
+
"non_polarised_limits",
|
|
578
|
+
"non_polarised_priors",
|
|
579
|
+
"standard_layers_controls",
|
|
580
|
+
),
|
|
581
|
+
(
|
|
582
|
+
"custom_xy_project",
|
|
583
|
+
"custom_xy_problem",
|
|
584
|
+
"custom_xy_cells",
|
|
585
|
+
"non_polarised_limits",
|
|
586
|
+
"non_polarised_priors",
|
|
587
|
+
"custom_xy_controls",
|
|
588
|
+
),
|
|
589
|
+
(
|
|
590
|
+
"domains_project",
|
|
591
|
+
"domains_problem",
|
|
592
|
+
"domains_cells",
|
|
593
|
+
"domains_limits",
|
|
594
|
+
"domains_priors",
|
|
595
|
+
"standard_layers_controls",
|
|
596
|
+
),
|
|
597
|
+
],
|
|
598
|
+
)
|
|
599
|
+
def test_make_input(test_project, test_problem, test_cells, test_limits, test_priors, test_controls, request) -> None:
|
|
600
|
+
"""When converting the "project" and "controls", we should obtain the five input objects required for the compiled
|
|
601
|
+
RAT code.
|
|
602
|
+
"""
|
|
603
|
+
test_project = request.getfixturevalue(test_project)
|
|
604
|
+
test_problem = request.getfixturevalue(test_problem)
|
|
605
|
+
test_cells = request.getfixturevalue(test_cells)
|
|
606
|
+
test_limits = request.getfixturevalue(test_limits)
|
|
607
|
+
test_priors = request.getfixturevalue(test_priors)
|
|
608
|
+
test_controls = request.getfixturevalue(test_controls)
|
|
609
|
+
|
|
610
|
+
parameter_fields = [
|
|
611
|
+
"param",
|
|
612
|
+
"backgroundParam",
|
|
613
|
+
"scalefactor",
|
|
614
|
+
"qzshift",
|
|
615
|
+
"bulkIn",
|
|
616
|
+
"bulkOut",
|
|
617
|
+
"resolutionParam",
|
|
618
|
+
"domainRatio",
|
|
619
|
+
]
|
|
620
|
+
|
|
621
|
+
mocked_matlab_future = mock.MagicMock()
|
|
622
|
+
mocked_engine = mock.MagicMock()
|
|
623
|
+
mocked_matlab_future.result.return_value = mocked_engine
|
|
624
|
+
|
|
625
|
+
with mock.patch.object(
|
|
626
|
+
RATapi.wrappers.MatlabWrapper,
|
|
627
|
+
"loader",
|
|
628
|
+
mocked_matlab_future,
|
|
629
|
+
), mock.patch.object(RATapi.rat_core, "DylibEngine", mock.MagicMock()), mock.patch.object(
|
|
630
|
+
RATapi.inputs,
|
|
631
|
+
"get_python_handle",
|
|
632
|
+
mock.MagicMock(return_value=dummy_function),
|
|
633
|
+
), mock.patch.object(
|
|
634
|
+
RATapi.wrappers.MatlabWrapper,
|
|
635
|
+
"getHandle",
|
|
636
|
+
mock.MagicMock(return_value=dummy_function),
|
|
637
|
+
), mock.patch.object(RATapi.wrappers.DylibWrapper, "getHandle", mock.MagicMock(return_value=dummy_function)):
|
|
638
|
+
problem, cells, limits, priors, controls = make_input(test_project, RATapi.Controls())
|
|
639
|
+
|
|
640
|
+
check_problem_equal(problem, test_problem)
|
|
641
|
+
check_cells_equal(cells, test_cells)
|
|
642
|
+
|
|
643
|
+
for limit_field in parameter_fields:
|
|
644
|
+
assert (getattr(limits, limit_field) == getattr(test_limits, limit_field)).all()
|
|
645
|
+
|
|
646
|
+
for prior_field in parameter_fields:
|
|
647
|
+
assert getattr(priors, prior_field) == getattr(test_priors, prior_field)
|
|
648
|
+
|
|
649
|
+
assert priors.priorNames == test_priors.priorNames
|
|
650
|
+
assert (priors.priorValues == test_priors.priorValues).all()
|
|
651
|
+
|
|
652
|
+
check_controls_equal(controls, test_controls)
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
@pytest.mark.parametrize(
|
|
656
|
+
["test_project", "test_problem"],
|
|
657
|
+
[
|
|
658
|
+
("standard_layers_project", "standard_layers_problem"),
|
|
659
|
+
("custom_xy_project", "custom_xy_problem"),
|
|
660
|
+
("domains_project", "domains_problem"),
|
|
661
|
+
],
|
|
662
|
+
)
|
|
663
|
+
def test_make_problem(test_project, test_problem, request) -> None:
|
|
664
|
+
"""The problem object should contain the relevant parameters defined in the input project object."""
|
|
665
|
+
test_project = request.getfixturevalue(test_project)
|
|
666
|
+
test_problem = request.getfixturevalue(test_problem)
|
|
667
|
+
|
|
668
|
+
problem = make_problem(test_project)
|
|
669
|
+
check_problem_equal(problem, test_problem)
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
@pytest.mark.parametrize(
|
|
673
|
+
"test_problem",
|
|
674
|
+
[
|
|
675
|
+
"standard_layers_problem",
|
|
676
|
+
"custom_xy_problem",
|
|
677
|
+
"domains_problem",
|
|
678
|
+
],
|
|
679
|
+
)
|
|
680
|
+
def test_check_indices(test_problem, request) -> None:
|
|
681
|
+
"""The check_indices routine should not raise errors for a properly defined ProblemDefinition object."""
|
|
682
|
+
test_problem = request.getfixturevalue(test_problem)
|
|
683
|
+
|
|
684
|
+
check_indices(test_problem)
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
@pytest.mark.parametrize(
|
|
688
|
+
["test_problem", "index_list", "bad_value"],
|
|
689
|
+
[
|
|
690
|
+
("standard_layers_problem", "contrastBulkIns", [0.0]),
|
|
691
|
+
("standard_layers_problem", "contrastBulkIns", [2.0]),
|
|
692
|
+
("standard_layers_problem", "contrastBulkOuts", [0.0]),
|
|
693
|
+
("standard_layers_problem", "contrastBulkOuts", [2.0]),
|
|
694
|
+
("standard_layers_problem", "contrastScalefactors", [0.0]),
|
|
695
|
+
("standard_layers_problem", "contrastScalefactors", [2.0]),
|
|
696
|
+
("standard_layers_problem", "contrastBackgroundParams", [0.0]),
|
|
697
|
+
("standard_layers_problem", "contrastBackgroundParams", [2.0]),
|
|
698
|
+
("standard_layers_problem", "contrastResolutionParams", [0.0]),
|
|
699
|
+
("standard_layers_problem", "contrastResolutionParams", [2.0]),
|
|
700
|
+
("custom_xy_problem", "contrastBulkIns", [0.0]),
|
|
701
|
+
("custom_xy_problem", "contrastBulkIns", [2.0]),
|
|
702
|
+
("custom_xy_problem", "contrastBulkOuts", [0.0]),
|
|
703
|
+
("custom_xy_problem", "contrastBulkOuts", [2.0]),
|
|
704
|
+
("custom_xy_problem", "contrastScalefactors", [0.0]),
|
|
705
|
+
("custom_xy_problem", "contrastScalefactors", [2.0]),
|
|
706
|
+
("custom_xy_problem", "contrastBackgroundParams", [0.0]),
|
|
707
|
+
("custom_xy_problem", "contrastBackgroundParams", [2.0]),
|
|
708
|
+
("custom_xy_problem", "contrastResolutionParams", [0.0]),
|
|
709
|
+
("custom_xy_problem", "contrastResolutionParams", [2.0]),
|
|
710
|
+
("domains_problem", "contrastBulkIns", [0.0]),
|
|
711
|
+
("domains_problem", "contrastBulkIns", [2.0]),
|
|
712
|
+
("domains_problem", "contrastBulkOuts", [0.0]),
|
|
713
|
+
("domains_problem", "contrastBulkOuts", [2.0]),
|
|
714
|
+
("domains_problem", "contrastScalefactors", [0.0]),
|
|
715
|
+
("domains_problem", "contrastScalefactors", [2.0]),
|
|
716
|
+
("domains_problem", "contrastDomainRatios", [0.0]),
|
|
717
|
+
("domains_problem", "contrastDomainRatios", [2.0]),
|
|
718
|
+
("domains_problem", "contrastBackgroundParams", [0.0]),
|
|
719
|
+
("domains_problem", "contrastBackgroundParams", [2.0]),
|
|
720
|
+
("domains_problem", "contrastResolutionParams", [0.0]),
|
|
721
|
+
("domains_problem", "contrastResolutionParams", [2.0]),
|
|
722
|
+
],
|
|
723
|
+
)
|
|
724
|
+
def test_check_indices_error(test_problem, index_list, bad_value, request) -> None:
|
|
725
|
+
"""The check_indices routine should raise an IndexError if a contrast list contains an index that is out of the
|
|
726
|
+
range of the corresponding parameter list in a ProblemDefinition object.
|
|
727
|
+
"""
|
|
728
|
+
param_list = {
|
|
729
|
+
"contrastBulkIns": "bulkIn",
|
|
730
|
+
"contrastBulkOuts": "bulkOut",
|
|
731
|
+
"contrastScalefactors": "scalefactors",
|
|
732
|
+
"contrastDomainRatios": "domainRatio",
|
|
733
|
+
"contrastBackgroundParams": "backgroundParams",
|
|
734
|
+
"contrastResolutionParams": "resolutionParams",
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
test_problem = request.getfixturevalue(test_problem)
|
|
738
|
+
setattr(test_problem, index_list, bad_value)
|
|
739
|
+
|
|
740
|
+
with pytest.raises(
|
|
741
|
+
IndexError,
|
|
742
|
+
match=f'The problem field "{index_list}" contains: {bad_value[0]}, which lie '
|
|
743
|
+
f'outside of the range of "{param_list[index_list]}"',
|
|
744
|
+
):
|
|
745
|
+
check_indices(test_problem)
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
@pytest.mark.parametrize(
|
|
749
|
+
["test_project", "test_cells"],
|
|
750
|
+
[
|
|
751
|
+
("standard_layers_project", "standard_layers_cells"),
|
|
752
|
+
("custom_xy_project", "custom_xy_cells"),
|
|
753
|
+
("domains_project", "domains_cells"),
|
|
754
|
+
],
|
|
755
|
+
)
|
|
756
|
+
def test_make_cells(test_project, test_cells, request) -> None:
|
|
757
|
+
"""The cells object should be populated according to the input project object."""
|
|
758
|
+
test_project = request.getfixturevalue(test_project)
|
|
759
|
+
test_cells = request.getfixturevalue(test_cells)
|
|
760
|
+
|
|
761
|
+
mocked_matlab_future = mock.MagicMock()
|
|
762
|
+
mocked_engine = mock.MagicMock()
|
|
763
|
+
mocked_matlab_future.result.return_value = mocked_engine
|
|
764
|
+
with mock.patch.object(
|
|
765
|
+
RATapi.wrappers.MatlabWrapper,
|
|
766
|
+
"loader",
|
|
767
|
+
mocked_matlab_future,
|
|
768
|
+
), mock.patch.object(RATapi.rat_core, "DylibEngine", mock.MagicMock()), mock.patch.object(
|
|
769
|
+
RATapi.inputs,
|
|
770
|
+
"get_python_handle",
|
|
771
|
+
mock.MagicMock(return_value=dummy_function),
|
|
772
|
+
), mock.patch.object(
|
|
773
|
+
RATapi.wrappers.MatlabWrapper,
|
|
774
|
+
"getHandle",
|
|
775
|
+
mock.MagicMock(return_value=dummy_function),
|
|
776
|
+
), mock.patch.object(RATapi.wrappers.DylibWrapper, "getHandle", mock.MagicMock(return_value=dummy_function)):
|
|
777
|
+
cells = make_cells(test_project)
|
|
778
|
+
|
|
779
|
+
check_cells_equal(cells, test_cells)
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
def test_get_python_handle():
|
|
783
|
+
path = pathlib.Path(__file__).parent.resolve()
|
|
784
|
+
assert RATapi.inputs.get_python_handle("utils.py", "dummy_function", path).__code__ == dummy_function.__code__
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
def test_make_controls(standard_layers_controls, test_checks) -> None:
|
|
788
|
+
"""The controls object should contain the full set of controls parameters, with the appropriate set defined by the
|
|
789
|
+
input controls.
|
|
790
|
+
"""
|
|
791
|
+
controls = make_controls(RATapi.Controls(), test_checks)
|
|
792
|
+
check_controls_equal(controls, standard_layers_controls)
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
def check_problem_equal(actual_problem, expected_problem) -> None:
|
|
796
|
+
"""Compare two instances of the "problem" object for equality."""
|
|
797
|
+
scalar_fields = [
|
|
798
|
+
"TF",
|
|
799
|
+
"modelType",
|
|
800
|
+
"geometry",
|
|
801
|
+
"useImaginary",
|
|
802
|
+
"numberOfContrasts",
|
|
803
|
+
"numberOfLayers",
|
|
804
|
+
"numberOfDomainContrasts",
|
|
805
|
+
]
|
|
806
|
+
|
|
807
|
+
array_fields = [
|
|
808
|
+
"params",
|
|
809
|
+
"backgroundParams",
|
|
810
|
+
"qzshifts",
|
|
811
|
+
"scalefactors",
|
|
812
|
+
"bulkIn",
|
|
813
|
+
"bulkOut",
|
|
814
|
+
"resolutionParams",
|
|
815
|
+
"domainRatio",
|
|
816
|
+
"contrastBackgroundParams",
|
|
817
|
+
"contrastBackgroundActions",
|
|
818
|
+
"contrastQzshifts",
|
|
819
|
+
"contrastScalefactors",
|
|
820
|
+
"contrastBulkIns",
|
|
821
|
+
"contrastBulkOuts",
|
|
822
|
+
"contrastResolutionParams",
|
|
823
|
+
"contrastDomainRatios",
|
|
824
|
+
"resample",
|
|
825
|
+
"dataPresent",
|
|
826
|
+
"oilChiDataPresent",
|
|
827
|
+
"fitParams",
|
|
828
|
+
"otherParams",
|
|
829
|
+
"fitLimits",
|
|
830
|
+
"otherLimits",
|
|
831
|
+
]
|
|
832
|
+
|
|
833
|
+
for scalar_field in scalar_fields:
|
|
834
|
+
assert getattr(actual_problem, scalar_field) == getattr(expected_problem, scalar_field)
|
|
835
|
+
for array_field in array_fields:
|
|
836
|
+
assert (getattr(actual_problem, array_field) == getattr(expected_problem, array_field)).all()
|
|
837
|
+
|
|
838
|
+
# Need to account for "NaN" entries in contrastCustomFiles field
|
|
839
|
+
assert (actual_problem.contrastCustomFiles == expected_problem.contrastCustomFiles).all() or [
|
|
840
|
+
"NaN" if np.isnan(el) else el for el in actual_problem.contrastCustomFiles
|
|
841
|
+
] == ["NaN" if np.isnan(el) else el for el in expected_problem.contrastCustomFiles]
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
def check_cells_equal(actual_cells, expected_cells) -> None:
|
|
845
|
+
"""Compare two instances of the "cells" object for equality."""
|
|
846
|
+
assert actual_cells.f1 == expected_cells.f1
|
|
847
|
+
|
|
848
|
+
# Need to test equality of the numpy arrays separately
|
|
849
|
+
for a, b in zip(actual_cells.f2, expected_cells.f2):
|
|
850
|
+
assert (a == b).all()
|
|
851
|
+
|
|
852
|
+
# f6 may contain "NaN" values, so consider separately
|
|
853
|
+
assert actual_cells.f6 == expected_cells.f6 or [
|
|
854
|
+
"NaN" if np.isnan(el) else el for entry in actual_cells.f6 for el in entry
|
|
855
|
+
] == ["NaN" if np.isnan(el) else el for entry in expected_cells.f6 for el in entry]
|
|
856
|
+
|
|
857
|
+
for index in chain(range(3, 6), range(7, 21)):
|
|
858
|
+
field = f"f{index}"
|
|
859
|
+
assert getattr(actual_cells, field) == getattr(expected_cells, field)
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
def check_controls_equal(actual_controls, expected_controls) -> None:
|
|
863
|
+
"""Compare two instances of the "controls" object used as input for the compiled RAT code for equality."""
|
|
864
|
+
controls_fields = [
|
|
865
|
+
"procedure",
|
|
866
|
+
"parallel",
|
|
867
|
+
"calcSldDuringFit",
|
|
868
|
+
"display",
|
|
869
|
+
"xTolerance",
|
|
870
|
+
"funcTolerance",
|
|
871
|
+
"maxFuncEvals",
|
|
872
|
+
"maxIterations",
|
|
873
|
+
"updateFreq",
|
|
874
|
+
"updatePlotFreq",
|
|
875
|
+
"populationSize",
|
|
876
|
+
"fWeight",
|
|
877
|
+
"crossoverProbability",
|
|
878
|
+
"strategy",
|
|
879
|
+
"targetValue",
|
|
880
|
+
"numGenerations",
|
|
881
|
+
"nLive",
|
|
882
|
+
"nMCMC",
|
|
883
|
+
"propScale",
|
|
884
|
+
"nsTolerance",
|
|
885
|
+
"nSamples",
|
|
886
|
+
"nChains",
|
|
887
|
+
"jumpProbability",
|
|
888
|
+
"pUnitGamma",
|
|
889
|
+
"boundHandling",
|
|
890
|
+
"adaptPCR",
|
|
891
|
+
]
|
|
892
|
+
checks_fields = [
|
|
893
|
+
"fitParam",
|
|
894
|
+
"fitBackgroundParam",
|
|
895
|
+
"fitQzshift",
|
|
896
|
+
"fitScalefactor",
|
|
897
|
+
"fitBulkIn",
|
|
898
|
+
"fitBulkOut",
|
|
899
|
+
"fitResolutionParam",
|
|
900
|
+
"fitDomainRatio",
|
|
901
|
+
]
|
|
902
|
+
|
|
903
|
+
# Check "resampleParams" separately as it is an array
|
|
904
|
+
assert (actual_controls.resampleParams == expected_controls.resampleParams).all()
|
|
905
|
+
for field in controls_fields:
|
|
906
|
+
assert getattr(actual_controls, field) == getattr(expected_controls, field)
|
|
907
|
+
for field in checks_fields:
|
|
908
|
+
assert (getattr(actual_controls.checks, field) == getattr(expected_controls.checks, field)).all()
|