Skip to content

Commit e968375

Browse files
committed
Adds additional problem_definition fields to test data
1 parent 8698f4a commit e968375

File tree

4 files changed

+83
-12
lines changed

4 files changed

+83
-12
lines changed

tests/test_convert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ def test_invalid_constraints():
119119
"r1_orso_polymer",
120120
"r1_motofit_bench_mark",
121121
"dspc_bilayer",
122-
# "dspc_standard_layers",
123-
# "dspc_custom_layers",
124-
# "dspc_custom_xy",
122+
"dspc_standard_layers",
123+
"dspc_custom_layers",
124+
"dspc_custom_xy",
125125
"domains_standard_layers",
126126
"domains_custom_layers",
127127
"domains_custom_xy",

tests/test_examples.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ def test_rat_examples(example_name):
3131
"example_name",
3232
[
3333
"DSPC_function_background",
34-
# FIXME: https://github.com/RascalSoftware/python-RAT/issues/102
35-
# "convert_rascal",
34+
"convert_rascal",
3635
],
3736
)
3837
@pytest.mark.skipif(importlib.util.find_spec("matlab") is None, reason="Matlab not installed")

tests/test_inputs.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,17 @@ def standard_layers_problem():
140140
problem.contrastDomainRatios = [0]
141141
problem.resample = [False]
142142
problem.dataPresent = [1]
143+
problem.data = [np.array([[1.0, 1.0, 1.0, 0.0, 0.0, 0.0]])]
144+
problem.dataLimits = [[1.0, 1.0]]
145+
problem.simulationLimits = [[1.0, 1.0]]
143146
problem.oilChiDataPresent = [0]
144147
problem.numberOfContrasts = 1
145148
problem.numberOfLayers = 1
149+
problem.repeatLayers = [[0, 1]]
150+
problem.layersDetails = [[2, 3, 4, float("NaN"), 2]]
151+
problem.contrastLayers = [[1]]
146152
problem.numberOfDomainContrasts = 0
153+
problem.domainContrastLayers = []
147154
problem.fitParams = [3.0]
148155
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03]
149156
problem.fitLimits = [[1.0, 5.0]]
@@ -164,7 +171,7 @@ def standard_layers_problem():
164171

165172
@pytest.fixture
166173
def domains_problem():
167-
"""The expected problem object from "standard_layers_project"."""
174+
"""The expected problem object from "domains_project"."""
168175
problem = ProblemDefinition()
169176
problem.TF = Calculations.Domains
170177
problem.modelType = LayerModels.StandardLayers
@@ -191,10 +198,17 @@ def domains_problem():
191198
problem.contrastDomainRatios = [1]
192199
problem.resample = [False]
193200
problem.dataPresent = [1]
201+
problem.data = [np.array([[1.0, 1.0, 1.0, 0.0, 0.0, 0.0]])]
202+
problem.dataLimits = [[1.0, 1.0]]
203+
problem.simulationLimits = [[1.0, 1.0]]
194204
problem.oilChiDataPresent = [0]
195205
problem.numberOfContrasts = 1
196206
problem.numberOfLayers = 1
207+
problem.repeatLayers = [[0, 1]]
208+
problem.layersDetails = [[2, 3, 4, float("NaN"), 2]]
209+
problem.contrastLayers = [[2, 1]]
197210
problem.numberOfDomainContrasts = 2
211+
problem.domainContrastLayers = [[1], [1]]
198212
problem.fitParams = [3.0]
199213
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03, 0.5]
200214
problem.fitLimits = [[1.0, 5.0]]
@@ -243,10 +257,17 @@ def custom_xy_problem():
243257
problem.contrastDomainRatios = [0]
244258
problem.resample = [False]
245259
problem.dataPresent = [0]
260+
problem.data = [np.empty([0, 6])]
261+
problem.dataLimits = [[0.0, 0.0]]
262+
problem.simulationLimits = [[0.005, 0.7]]
246263
problem.oilChiDataPresent = [0]
264+
problem.repeatLayers = [[0, 1]]
265+
problem.layersDetails = []
266+
problem.contrastLayers = [[]]
247267
problem.numberOfContrasts = 1
248268
problem.numberOfLayers = 0
249269
problem.numberOfDomainContrasts = 0
270+
problem.domainContrastLayers = []
250271
problem.fitParams = [3.0]
251272
problem.otherParams = [0.0, 0.0, 0.0, 1e-06, 0.23, 0.0, 6.35e-06, 0.03]
252273
problem.fitLimits = [[1.0, 5.0]]
@@ -273,8 +294,8 @@ def normal_limits():
273294
limits = Limits()
274295
limits.params = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
275296
limits.backgroundParams = [[1e-7, 1e-5]]
276-
limits.qzshifts = []
277297
limits.scalefactors = [[0.02, 0.25]]
298+
limits.qzshifts = []
278299
limits.bulkIns = [[0.0, 0.0]]
279300
limits.bulkOuts = [[6.2e-6, 6.35e-6]]
280301
limits.resolutionParams = [[0.01, 0.05]]
@@ -289,8 +310,8 @@ def domains_limits():
289310
limits = Limits()
290311
limits.params = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]
291312
limits.backgroundParams = [[1e-7, 1e-5]]
292-
limits.qzshifts = []
293313
limits.scalefactors = [[0.02, 0.25]]
314+
limits.qzshifts = []
294315
limits.bulkIns = [[0.0, 0.0]]
295316
limits.bulkOuts = [[6.2e-6, 6.35e-6]]
296317
limits.resolutionParams = [[0.01, 0.05]]
@@ -310,8 +331,8 @@ def normal_priors():
310331
["Test Roughness", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
311332
]
312333
priors.backgroundParams = [["Background Param 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
313-
priors.qzshifts = []
314334
priors.scalefactors = [["Scalefactor 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
335+
priors.qzshifts = []
315336
priors.bulkIns = [["SLD Air", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
316337
priors.bulkOuts = [["SLD D2O", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
317338
priors.resolutionParams = [["Resolution Param 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
@@ -353,8 +374,8 @@ def domains_priors():
353374
["Test Roughness", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf],
354375
]
355376
priors.backgroundParams = [["Background Param 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
356-
priors.qzshifts = []
357377
priors.scalefactors = [["Scalefactor 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
378+
priors.qzshifts = []
358379
priors.bulkIns = [["SLD Air", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
359380
priors.bulkOuts = [["SLD D2O", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
360381
priors.resolutionParams = [["Resolution Param 1", RATapi.utils.enums.Priors.Uniform, 0.0, np.inf]]
@@ -469,8 +490,8 @@ def test_checks():
469490
checks = Checks()
470491
checks.params = [1, 0, 0, 0]
471492
checks.backgroundParams = [0]
472-
checks.qzshifts = []
473493
checks.scalefactors = [0]
494+
checks.qzshifts = []
474495
checks.bulkIns = [0]
475496
checks.bulkOuts = [0]
476497
checks.resolutionParams = [0]
@@ -725,7 +746,12 @@ def check_problem_equal(actual_problem, expected_problem) -> None:
725746
"contrastDomainRatios",
726747
"resample",
727748
"dataPresent",
749+
"dataLimits",
750+
"simulationLimits",
728751
"oilChiDataPresent",
752+
"repeatLayers",
753+
"contrastLayers",
754+
"domainContrastLayers",
729755
"fitParams",
730756
"otherParams",
731757
"fitLimits",
@@ -737,7 +763,17 @@ def check_problem_equal(actual_problem, expected_problem) -> None:
737763
for array_field in array_fields:
738764
assert np.all(getattr(actual_problem, array_field) == getattr(expected_problem, array_field))
739765

740-
# Need to account for "NaN" entries in contrastCustomFiles field
766+
# Data field is a numpy array
767+
assert [
768+
actual_data == expected_data for (actual_data, expected_data) in zip(actual_problem.data, expected_problem.data)
769+
]
770+
771+
# Need to account for "NaN" entries in layersDetails and contrastCustomFiles field
772+
for actual_layer, expected_layer in zip(actual_problem.layersDetails, expected_problem.layersDetails):
773+
assert (actual_layer == expected_layer) or ["NaN" if np.isnan(el) else el for el in actual_layer] == [
774+
"NaN" if np.isnan(el) else el for el in expected_layer
775+
]
776+
741777
assert (actual_problem.contrastCustomFiles == expected_problem.contrastCustomFiles).all() or [
742778
"NaN" if np.isnan(el) else el for el in actual_problem.contrastCustomFiles
743779
] == ["NaN" if np.isnan(el) else el for el in expected_problem.contrastCustomFiles]

tests/test_run.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,34 @@ def reflectivity_calculation_problem():
6666
problem.contrastQzshifts = np.array([0.0, 0.0])
6767
problem.contrastScalefactors = np.array([1.0, 2.0])
6868
problem.contrastBackgroundParams = [[1.0], [2.0]]
69+
problem.contrastBackgroundTypes = ["constant", "constant"]
6970
problem.contrastBackgroundActions = [1.0, 1.0]
7071
problem.contrastResolutionParams = [[1.0], [1.0]]
72+
problem.contrastResolutionTypes = ["constant", "constant"]
7173
problem.contrastCustomFiles = np.array([np.nan, np.nan])
7274
problem.contrastDomainRatios = np.array([0.0, 0.0])
7375
problem.resample = np.array([0.0, 0.0])
7476
problem.dataPresent = np.array([1.0, 1.0])
77+
problem.dataLimits = [[0.011403, 0.59342], [0.011403, 0.59342]]
78+
problem.simulationLimits = [[0.011403, 0.59342], [0.011403, 0.59342]]
7579
problem.oilChiDataPresent = np.array([0.0, 0.0])
7680
problem.numberOfContrasts = 2.0
7781
problem.numberOfLayers = 6.0
82+
problem.repeatLayers = [[0.0, 1.0], [0.0, 1.0]]
83+
problem.layersDetails = [
84+
np.array([2.0]),
85+
np.array([4.0]),
86+
np.array([10.0]),
87+
np.array([8.0]),
88+
np.array([13.0]),
89+
np.array([16.0]),
90+
]
91+
problem.contrastLayers = [
92+
np.array([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 6.0, 5.0]]),
93+
np.array([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 6.0, 5.0]]),
94+
]
7895
problem.numberOfDomainContrasts = 0.0
96+
problem.domainContrastLayers = []
7997
problem.fitParams = np.array(
8098
[
8199
3.000e00,
@@ -203,16 +221,34 @@ def dream_problem():
203221
problem.contrastQzshifts = np.array([0.0, 0.0])
204222
problem.contrastScalefactors = np.array([1.0, 2.0])
205223
problem.contrastBackgroundParams = [[1.0], [2.0]]
224+
problem.contrastBackgroundTypes = ["constant", "constant"]
206225
problem.contrastBackgroundActions = [1.0, 1.0]
207226
problem.contrastResolutionParams = [[1.0], [1.0]]
227+
problem.contrastResolutionTypes = ["constant", "constant"]
208228
problem.contrastCustomFiles = np.array([np.nan, np.nan])
209229
problem.contrastDomainRatios = np.array([0.0, 0.0])
210230
problem.resample = np.array([0.0, 0.0])
211231
problem.dataPresent = np.array([1.0, 1.0])
232+
problem.dataLimits = [[0.011403, 0.59342], [0.011403, 0.59342]]
233+
problem.simulationLimits = [[0.011403, 0.59342], [0.011403, 0.59342]]
212234
problem.oilChiDataPresent = np.array([0.0, 0.0])
213235
problem.numberOfContrasts = 2.0
214236
problem.numberOfLayers = 6.0
237+
problem.repeatLayers = [[0.0, 1.0], [0.0, 1.0]]
238+
problem.layersDetails = [
239+
np.array([2.0]),
240+
np.array([4.0]),
241+
np.array([10.0]),
242+
np.array([8.0]),
243+
np.array([13.0]),
244+
np.array([16.0]),
245+
]
246+
problem.contrastLayers = [
247+
np.array([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 6.0, 5.0]]),
248+
np.array([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 6.0, 5.0]]),
249+
]
215250
problem.numberOfDomainContrasts = 0.0
251+
problem.domainContrastLayers = []
216252
problem.fitParams = np.array(
217253
[
218254
6.19503045e00,

0 commit comments

Comments
 (0)