diff --git a/RATapi/inputs.py b/RATapi/inputs.py index 0bc00284..3798cb0f 100644 --- a/RATapi/inputs.py +++ b/RATapi/inputs.py @@ -10,7 +10,7 @@ import RATapi import RATapi.controls import RATapi.wrappers -from RATapi.rat_core import Checks, Control, Limits, NameStore, ProblemDefinition +from RATapi.rat_core import Checks, Control, NameStore, ProblemDefinition from RATapi.utils.enums import Calculations, Languages, LayerModels, TypeOptions parameter_field = { @@ -113,7 +113,7 @@ def __len__(self): return len(self.files) -def make_input(project: RATapi.Project, controls: RATapi.Controls) -> tuple[ProblemDefinition, Limits, Control]: +def make_input(project: RATapi.Project, controls: RATapi.Controls) -> tuple[ProblemDefinition, Control]: """Construct the inputs required for the compiled RAT code using the data defined in the input project and controls. Parameters @@ -127,28 +127,14 @@ def make_input(project: RATapi.Project, controls: RATapi.Controls) -> tuple[Prob ------- problem : RAT.rat_core.ProblemDefinition The problem input used in the compiled RAT code. - limits : RAT.rat_core.Limits - A list of min/max values for each parameter defined in the project. cpp_controls : RAT.rat_core.Control The controls object used in the compiled RAT code. """ - limits = Limits() - - for class_list in RATapi.project.parameter_class_lists: - setattr( - limits, - parameter_field[class_list], - [[element.min, element.max] for element in getattr(project, class_list)], - ) - - if project.model == LayerModels.CustomXY: - controls.calcSldDuringFit = True - problem = make_problem(project) cpp_controls = make_controls(controls) - return problem, limits, cpp_controls + return problem, cpp_controls def make_problem(project: RATapi.Project) -> ProblemDefinition: diff --git a/RATapi/outputs.py b/RATapi/outputs.py index 84b3222d..150ebc2d 100644 --- a/RATapi/outputs.py +++ b/RATapi/outputs.py @@ -141,12 +141,13 @@ class Results: The background for each contrast defined over the simulation range. resolutions : list The resolution for each contrast defined over the simulation range. - layerSlds : list - The array of layer parameter values for each contrast. sldProfiles : list The SLD profiles for each contrast. + layers : list + The array of layer parameter values for each contrast. resampledLayers : list - If resampling is used, the SLD for each contrast after resampling has been performed. + If resampling is used, the array of layer parameter values for each contrast after resampling has been + performed. calculationResults : CalculationResults The chi-squared fit results from the final calculation and fit. contrastParams : ContrastParams @@ -164,8 +165,8 @@ class Results: shiftedData: list backgrounds: list resolutions: list - layerSlds: list sldProfiles: list + layers: list resampledLayers: list calculationResults: CalculationResults contrastParams: ContrastParams @@ -323,8 +324,6 @@ class DreamOutput(RATResult): The runtime of the DREAM algorithm in seconds. iteration : float The number of iterations performed. - modelOutput : float - Unused. Will always be 0. AR : np.ndarray A two-column array where ``DreamOutput.AR[i, 0]`` is an iteration number and ``DreamOutput.AR[i, 1]`` is the average acceptance rate of chain step @@ -344,7 +343,6 @@ class DreamOutput(RATResult): outlierChains: np.ndarray runtime: float iteration: float - modelOutput: float AR: np.ndarray R_stat: np.ndarray CR: np.ndarray @@ -483,7 +481,6 @@ def make_results( outlierChains=bayes_results.dreamOutput.outlierChains, runtime=bayes_results.dreamOutput.runtime, iteration=bayes_results.dreamOutput.iteration, - modelOutput=bayes_results.dreamOutput.modelOutput, AR=bayes_results.dreamOutput.AR, R_stat=bayes_results.dreamOutput.R_stat, CR=bayes_results.dreamOutput.CR, @@ -502,8 +499,8 @@ def make_results( shiftedData=output_results.shiftedData, backgrounds=output_results.backgrounds, resolutions=output_results.resolutions, - layerSlds=output_results.layerSlds, sldProfiles=output_results.sldProfiles, + layers=output_results.layers, resampledLayers=output_results.resampledLayers, calculationResults=calculation_results, contrastParams=contrast_params, @@ -524,8 +521,8 @@ def make_results( shiftedData=output_results.shiftedData, backgrounds=output_results.backgrounds, resolutions=output_results.resolutions, - layerSlds=output_results.layerSlds, sldProfiles=output_results.sldProfiles, + layers=output_results.layers, resampledLayers=output_results.resampledLayers, calculationResults=calculation_results, contrastParams=contrast_params, diff --git a/RATapi/run.py b/RATapi/run.py index 17f47ecc..476daa39 100644 --- a/RATapi/run.py +++ b/RATapi/run.py @@ -109,7 +109,7 @@ def run(project, controls): horizontal_line = "\u2500" * 107 + "\n" display_on = controls.display != Display.Off - problem_definition, limits, cpp_controls = make_input(project, controls) + problem_definition, cpp_controls = make_input(project, controls) if display_on: print("Starting RAT " + horizontal_line) @@ -118,7 +118,6 @@ def run(project, controls): with ProgressBar(display=display_on), TextOutput(display=display_on): problem_definition, output_results, bayes_results = RATapi.rat_core.RATMain( problem_definition, - limits, cpp_controls, ) end = time.time() diff --git a/cpp/RAT b/cpp/RAT index 282d17be..df626113 160000 --- a/cpp/RAT +++ b/cpp/RAT @@ -1 +1 @@ -Subproject commit 282d17beb964af0855c1b2cc412e0b187b1a4140 +Subproject commit df626113d7a930cfa23c1ab47fdf9b1111b52123 diff --git a/cpp/includes/defines.h b/cpp/includes/defines.h index ffecaec3..67b0fda7 100644 --- a/cpp/includes/defines.h +++ b/cpp/includes/defines.h @@ -237,8 +237,6 @@ runtime : float The runtime of the DREAM algorithm in seconds. iteration : float The number of iterations performed. -modelOutput : float - Unused. Will always be 0. AR : np.ndarray[np.float] A two-column array where ``DreamOutput.AR[i, 0]`` is an iteration number and ``DreamOutput.AR[i, 1]`` is the average acceptance rate of chain step @@ -259,7 +257,6 @@ struct DreamOutput py::array_t outlierChains; real_T runtime; real_T iteration; - real_T modelOutput; py::array_t AR; py::array_t R_stat; py::array_t CR; @@ -354,12 +351,12 @@ backgrounds : list The background for each contrast defined over the simulation range. resolutions : list The resolution for each contrast defined over the simulation range. -layerSlds : list - The array of layer parameter values for each contrast. sldProfiles : list The SLD profiles for each contrast. +layers : list + The array of layer parameter values for each contrast. resampledLayers : list - If resampling is used, the SLD for each contrast after resampling has been performed. + If resampling is used, the array of layer parameter values for each contrast after resampling has been performed. calculationResults : RATapi.rat_core.Calculation The chi-squared fit results from the final calculation and fit. contrastParams : RATapi.rat_core.ContrastParams @@ -377,8 +374,8 @@ struct OutputResult { py::list shiftedData; py::list backgrounds; py::list resolutions; - py::list layerSlds; py::list sldProfiles; + py::list layers; py::list resampledLayers; Calculation calculationResults {}; ContrastParams contrastParams {}; @@ -386,37 +383,6 @@ struct OutputResult { py::list fitNames; }; -const std::string docsLimits = R"(The Python binding for the C++ limit struct which contains -Min and max values for each parameter defined in the project. - -Parameters ----------- -params : np.ndarray[np.float] - Limits for params in the problem definition. -backgroundParams : np.ndarray[np.float] - Limits for backgroundParams in the problem definition. -scalefactors : np.ndarray[np.float] - Limits for scalefactors in the problem definition. -bulkIns : np.ndarray[np.float] - Limits for bulkIns in the problem definition. -bulkOuts : np.ndarray[np.float] - Limits for bulkOuts in the problem definition. -resolutionParams : np.ndarray[np.float] - Limits for resolutionParams in the problem definition. -domainRatios : np.ndarray[np.float] - Limits for domainRatios in the problem definition. -)"; - -struct Limits { - py::array_t params; - py::array_t backgroundParams; - py::array_t scalefactors; - py::array_t bulkIns; - py::array_t bulkOuts; - py::array_t resolutionParams; - py::array_t domainRatios; -}; - const std::string docsNameStore = R"(The Python binding for the C++ names struct which contains names of all parameters in the project. diff --git a/cpp/rat.cpp b/cpp/rat.cpp index d8d48d68..a92dc49d 100644 --- a/cpp/rat.cpp +++ b/cpp/rat.cpp @@ -301,21 +301,6 @@ RAT::b_ProblemDefinition createProblemDefinitionStruct(const ProblemDefinition& } -RAT::ProblemLimits createProblemLimitsStruct(const Limits& limits) -{ - RAT::ProblemLimits limits_struct; - limits_struct.params = customCaller("Limits.params", pyArrayToRatArray2d, limits.params); - limits_struct.backgroundParams = customCaller("Limits.backgroundParams", pyArrayToRatArray2d, limits.backgroundParams); - limits_struct.scalefactors = customCaller("Limits.scalefactors", pyArrayToRatArray2d, limits.scalefactors); - limits_struct.bulkIns = customCaller("Limits.bulkIns", pyArrayToRatArray2d, limits.bulkIns); - limits_struct.bulkOuts = customCaller("Limits.bulkOuts", pyArrayToRatArray2d, limits.bulkOuts); - limits_struct.resolutionParams = customCaller("Limits.resolutionParams", pyArrayToRatArray2d, limits.resolutionParams); - limits_struct.domainRatios = customCaller("Limits.domainRatios", pyArrayToRatArray2d, limits.domainRatios); - - return limits_struct; -} - - RAT::Controls createControlsStruct(const Control& control) { RAT::Controls control_struct; @@ -391,26 +376,26 @@ OutputResult OutputResultFromStruct(const RAT::Results result) output_result.resolutions.append(array); } - for (int32_T idx0{0}; idx0 < result.layerSlds.size(0); idx0++) { + for (int32_T idx0{0}; idx0 < result.sldProfiles.size(0); idx0++) { py::list inner_list; - for (int32_T idx1{0}; idx1 < result.layerSlds.size(1); idx1++) { - auto tmp = result.layerSlds[idx0 + result.layerSlds.size(0) * idx1]; + for (int32_T idx1{0}; idx1 < result.sldProfiles.size(1); idx1++) { + auto tmp = result.sldProfiles[idx0 + result.sldProfiles.size(0) * idx1]; auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); inner_list.append(array); } - output_result.layerSlds.append(inner_list); + output_result.sldProfiles.append(inner_list); } - for (int32_T idx0{0}; idx0 < result.sldProfiles.size(0); idx0++) { + for (int32_T idx0{0}; idx0 < result.layers.size(0); idx0++) { py::list inner_list; - for (int32_T idx1{0}; idx1 < result.sldProfiles.size(1); idx1++) { - auto tmp = result.sldProfiles[idx0 + result.sldProfiles.size(0) * idx1]; + for (int32_T idx1{0}; idx1 < result.layers.size(1); idx1++) { + auto tmp = result.layers[idx0 + result.layers.size(0) * idx1]; auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); inner_list.append(array); } - output_result.sldProfiles.append(inner_list); + output_result.layers.append(inner_list); } for (int32_T idx0{0}; idx0 < result.resampledLayers.size(0); idx0++) { @@ -548,7 +533,6 @@ BayesResults bayesResultsFromStruct(const RAT::BayesResults results) bayesResults.dreamOutput.outlierChains = pyArray2dFromBoundedArray>(results.dreamOutput.outlierChains); bayesResults.dreamOutput.runtime = results.dreamOutput.runtime; bayesResults.dreamOutput.iteration = results.dreamOutput.iteration; - bayesResults.dreamOutput.modelOutput = results.dreamOutput.modelOutput; bayesResults.dreamOutput.R_stat = pyArrayFromRatArray2d(results.dreamOutput.R_stat); bayesResults.dreamOutput.CR = pyArrayFromRatArray2d(results.dreamOutput.CR); bayesResults.dreamOutput.AR = pyArray2dFromBoundedArray>(results.dreamOutput.AR); @@ -582,8 +566,6 @@ Parameters ---------- problem_def : Rat.rat_core.ProblemDefinition The project input for the RAT calculation. -limits : RATapi.rat_core.Limits - Min and max values for each parameter defined in the problem definition. control : RATapi.rat_core.Control The controls object for the RAT calculation. @@ -597,16 +579,15 @@ bayes_result : Rat.rat_core.BayesResults The extra results if RAT calculation is Bayesian. )"; -py::tuple RATMain(const ProblemDefinition& problem_def, const Limits& limits, const Control& control) +py::tuple RATMain(const ProblemDefinition& problem_def, const Control& control) { RAT::b_ProblemDefinition problem_def_struct = createProblemDefinitionStruct(problem_def); - RAT::ProblemLimits limits_struct = createProblemLimitsStruct(limits); RAT::Controls control_struct = createControlsStruct(control); // Output RAT::Results results; RAT::BayesResults bayesResults; // Call the entry-point - RAT::RATMain(&problem_def_struct, &limits_struct, &control_struct, &results, &bayesResults); + RAT::RATMain(&problem_def_struct, &control_struct, &results, &bayesResults); // Copy result to output auto out_problem_def = problemDefinitionFromStruct(problem_def_struct); out_problem_def.customFiles = problem_def.customFiles.attr("copy")(); @@ -802,7 +783,6 @@ PYBIND11_MODULE(rat_core, m) { .def_readwrite("outlierChains", &DreamOutput::outlierChains) .def_readwrite("runtime", &DreamOutput::runtime) .def_readwrite("iteration", &DreamOutput::iteration) - .def_readwrite("modelOutput", &DreamOutput::modelOutput) .def_readwrite("AR", &DreamOutput::AR) .def_readwrite("R_stat", &DreamOutput::R_stat) .def_readwrite("CR", &DreamOutput::CR); @@ -836,8 +816,8 @@ PYBIND11_MODULE(rat_core, m) { .def_readwrite("shiftedData", &OutputResult::shiftedData) .def_readwrite("backgrounds", &OutputResult::backgrounds) .def_readwrite("resolutions", &OutputResult::resolutions) - .def_readwrite("layerSlds", &OutputResult::layerSlds) .def_readwrite("sldProfiles", &OutputResult::sldProfiles) + .def_readwrite("layers", &OutputResult::layers) .def_readwrite("resampledLayers", &OutputResult::resampledLayers) .def_readwrite("calculationResults", &OutputResult::calculationResults) .def_readwrite("contrastParams", &OutputResult::contrastParams) @@ -912,39 +892,6 @@ PYBIND11_MODULE(rat_core, m) { return chk; })); - py::class_(m, "Limits", docsLimits.c_str()) - .def(py::init<>()) - .def_readwrite("params", &Limits::params) - .def_readwrite("backgroundParams", &Limits::backgroundParams) - .def_readwrite("scalefactors", &Limits::scalefactors) - .def_readwrite("bulkIns", &Limits::bulkIns) - .def_readwrite("bulkOuts", &Limits::bulkOuts) - .def_readwrite("resolutionParams", &Limits::resolutionParams) - .def_readwrite("domainRatios", &Limits::domainRatios) - .def(py::pickle( - [](const Limits &lim) { // __getstate__ - /* Return a tuple that fully encodes the state of the object */ - return py::make_tuple(lim.params, lim.backgroundParams, lim.scalefactors, lim.bulkIns, lim.bulkOuts, - lim.resolutionParams, lim.domainRatios); - }, - [](py::tuple t) { // __setstate__ - if (t.size() != 7) - throw std::runtime_error("Encountered invalid state unpickling Limits object!"); - - /* Create a new C++ instance */ - Limits lim; - - lim.params = t[0].cast>(); - lim.backgroundParams = t[1].cast>(); - lim.scalefactors = t[2].cast>(); - lim.bulkIns = t[3].cast>(); - lim.bulkOuts = t[4].cast>(); - lim.resolutionParams = t[5].cast>(); - lim.domainRatios = t[6].cast>(); - - return lim; - })); - py::class_(m, "Control", docsControl.c_str()) .def(py::init<>()) .def_readwrite("parallel", &Control::parallel) @@ -1150,7 +1097,7 @@ PYBIND11_MODULE(rat_core, m) { return p; })); - m.def("RATMain", &RATMain, docsRATMain.c_str(), py::arg("problem_def"), py::arg("limits"), py::arg("control")); + m.def("RATMain", &RATMain, docsRATMain.c_str(), py::arg("problem_def"), py::arg("control")); m.def("makeSLDProfileXY", &makeSLDProfileXY, docsMakeSLDProfileXY.c_str(), py::arg("bulk_in"), py::arg("bulk_out"), py::arg("ssub"), py::arg("layers"), py::arg("number_of_repeats") = DEFAULT_NREPEATS); diff --git a/tests/conftest.py b/tests/conftest.py index ce580c15..50fbc11c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -774,36 +774,6 @@ def reflectivity_calculation_output_results(): ] ), ] - results.layerSlds = [ - [ - np.array( - [ - [1.954000e01, 4.001499e-06, 3.000000e00], - [2.266000e01, -6.586988e-08, 3.000000e00], - [8.560000e00, 3.672535e-06, 5.640000e00], - [1.712000e01, 5.980000e-06, 5.640000e00], - [1.070000e01, 3.100365e-06, 6.014000e00], - [1.782000e01, 6.751924e-07, 6.014000e00], - [1.782000e01, 6.751924e-07, 6.014000e00], - [1.070000e01, 3.100365e-06, 6.014000e00], - ], - ), - ], - [ - np.array( - [ - [1.9540000e01, 3.1114020e-06, 3.0000000e00], - [2.2660000e01, -2.6387028e-07, 3.0000000e00], - [8.5600000e00, 1.9590700e-06, 5.6400000e00], - [1.7120000e01, 2.2100000e-06, 5.6400000e00], - [1.0700000e01, 1.7375100e-06, 6.0140000e00], - [1.7820000e01, 1.0164400e-08, 6.0140000e00], - [1.7820000e01, 1.0164400e-08, 6.0140000e00], - [1.0700000e01, 1.7375100e-06, 6.0140000e00], - ], - ), - ], - ] results.sldProfiles = [ [ np.array( @@ -866,6 +836,36 @@ def reflectivity_calculation_output_results(): ), ], ] + results.layers = [ + [ + np.array( + [ + [1.954000e01, 4.001499e-06, 3.000000e00], + [2.266000e01, -6.586988e-08, 3.000000e00], + [8.560000e00, 3.672535e-06, 5.640000e00], + [1.712000e01, 5.980000e-06, 5.640000e00], + [1.070000e01, 3.100365e-06, 6.014000e00], + [1.782000e01, 6.751924e-07, 6.014000e00], + [1.782000e01, 6.751924e-07, 6.014000e00], + [1.070000e01, 3.100365e-06, 6.014000e00], + ], + ), + ], + [ + np.array( + [ + [1.9540000e01, 3.1114020e-06, 3.0000000e00], + [2.2660000e01, -2.6387028e-07, 3.0000000e00], + [8.5600000e00, 1.9590700e-06, 5.6400000e00], + [1.7120000e01, 2.2100000e-06, 5.6400000e00], + [1.0700000e01, 1.7375100e-06, 6.0140000e00], + [1.7820000e01, 1.0164400e-08, 6.0140000e00], + [1.7820000e01, 1.0164400e-08, 6.0140000e00], + [1.0700000e01, 1.7375100e-06, 6.0140000e00], + ], + ), + ], + ] results.resampledLayers = [[np.array([[0.0, 0.0, 0.0]])], [np.array([[0.0, 0.0, 0.0]])]] results.calculationResults = RATapi.rat_core.Calculation() results.calculationResults.chiValues = np.array([202.83057377, 1641.4024969]) @@ -1430,36 +1430,6 @@ def reflectivity_calculation_results(): ] ), ], - layerSlds=[ - [ - np.array( - [ - [1.954000e01, 4.001499e-06, 3.000000e00], - [2.266000e01, -6.586988e-08, 3.000000e00], - [8.560000e00, 3.672535e-06, 5.640000e00], - [1.712000e01, 5.980000e-06, 5.640000e00], - [1.070000e01, 3.100365e-06, 6.014000e00], - [1.782000e01, 6.751924e-07, 6.014000e00], - [1.782000e01, 6.751924e-07, 6.014000e00], - [1.070000e01, 3.100365e-06, 6.014000e00], - ], - ), - ], - [ - np.array( - [ - [1.9540000e01, 3.1114020e-06, 3.0000000e00], - [2.2660000e01, -2.6387028e-07, 3.0000000e00], - [8.5600000e00, 1.9590700e-06, 5.6400000e00], - [1.7120000e01, 2.2100000e-06, 5.6400000e00], - [1.0700000e01, 1.7375100e-06, 6.0140000e00], - [1.7820000e01, 1.0164400e-08, 6.0140000e00], - [1.7820000e01, 1.0164400e-08, 6.0140000e00], - [1.0700000e01, 1.7375100e-06, 6.0140000e00], - ], - ), - ], - ], sldProfiles=[ [ np.array( @@ -1522,6 +1492,36 @@ def reflectivity_calculation_results(): ), ], ], + layers=[ + [ + np.array( + [ + [1.954000e01, 4.001499e-06, 3.000000e00], + [2.266000e01, -6.586988e-08, 3.000000e00], + [8.560000e00, 3.672535e-06, 5.640000e00], + [1.712000e01, 5.980000e-06, 5.640000e00], + [1.070000e01, 3.100365e-06, 6.014000e00], + [1.782000e01, 6.751924e-07, 6.014000e00], + [1.782000e01, 6.751924e-07, 6.014000e00], + [1.070000e01, 3.100365e-06, 6.014000e00], + ], + ), + ], + [ + np.array( + [ + [1.9540000e01, 3.1114020e-06, 3.0000000e00], + [2.2660000e01, -2.6387028e-07, 3.0000000e00], + [8.5600000e00, 1.9590700e-06, 5.6400000e00], + [1.7120000e01, 2.2100000e-06, 5.6400000e00], + [1.0700000e01, 1.7375100e-06, 6.0140000e00], + [1.7820000e01, 1.0164400e-08, 6.0140000e00], + [1.7820000e01, 1.0164400e-08, 6.0140000e00], + [1.0700000e01, 1.7375100e-06, 6.0140000e00], + ], + ), + ], + ], resampledLayers=[[np.array([[0.0, 0.0, 0.0]])], [np.array([[0.0, 0.0, 0.0]])]], calculationResults=RATapi.outputs.CalculationResults( chiValues=np.array([202.83057377, 1641.4024969]), @@ -2091,36 +2091,6 @@ def dream_output_results(): ] ), ] - results.layerSlds = [ - [ - np.array( - [ - [3.15755349e01, 3.35278238e-06, 4.16625659e00], - [3.61791464e01, 7.68327921e-07, 4.16625659e00], - [1.00488530e01, 2.06044530e-06, 2.78042232e01], - [1.08043784e01, 3.29384190e-06, 2.78042232e01], - [2.42251646e01, 2.35556998e-06, 1.55593097e01], - [1.49022278e01, 7.42138004e-07, 1.55593097e01], - [1.49022278e01, 7.42138004e-07, 1.55593097e01], - [2.42251646e01, 2.35556998e-06, 1.55593097e01], - ], - ), - ], - [ - np.array( - [ - [3.15755349e01, 4.11636356e-06, 4.16625659e00], - [3.61791464e01, 1.39268494e-06, 4.16625659e00], - [1.00488530e01, 2.45715680e-06, 2.78042232e01], - [1.08043784e01, 5.26668495e-06, 2.78042232e01], - [2.42251646e01, 3.31348777e-06, 1.55593097e01], - [1.49022278e01, 1.37428245e-06, 1.55593097e01], - [1.49022278e01, 1.37428245e-06, 1.55593097e01], - [2.42251646e01, 3.31348777e-06, 1.55593097e01], - ], - ), - ], - ] results.sldProfiles = [ [ np.array( @@ -2191,6 +2161,36 @@ def dream_output_results(): ), ], ] + results.layers = [ + [ + np.array( + [ + [3.15755349e01, 3.35278238e-06, 4.16625659e00], + [3.61791464e01, 7.68327921e-07, 4.16625659e00], + [1.00488530e01, 2.06044530e-06, 2.78042232e01], + [1.08043784e01, 3.29384190e-06, 2.78042232e01], + [2.42251646e01, 2.35556998e-06, 1.55593097e01], + [1.49022278e01, 7.42138004e-07, 1.55593097e01], + [1.49022278e01, 7.42138004e-07, 1.55593097e01], + [2.42251646e01, 2.35556998e-06, 1.55593097e01], + ], + ), + ], + [ + np.array( + [ + [3.15755349e01, 4.11636356e-06, 4.16625659e00], + [3.61791464e01, 1.39268494e-06, 4.16625659e00], + [1.00488530e01, 2.45715680e-06, 2.78042232e01], + [1.08043784e01, 5.26668495e-06, 2.78042232e01], + [2.42251646e01, 3.31348777e-06, 1.55593097e01], + [1.49022278e01, 1.37428245e-06, 1.55593097e01], + [1.49022278e01, 1.37428245e-06, 1.55593097e01], + [2.42251646e01, 3.31348777e-06, 1.55593097e01], + ], + ), + ], + ] results.resampledLayers = [[np.array([[0.0, 0.0, 0.0]])], [np.array([[0.0, 0.0, 0.0]])]] results.calculationResults = RATapi.rat_core.Calculation() results.calculationResults.chiValues = (np.array([4.6077885, 7.00028098]),) @@ -3984,7 +3984,6 @@ def dream_bayes(): bayes.dreamOutput.outlierChains = np.array([[0.0, 0.0]]) bayes.dreamOutput.runtime = 2.6e-06 bayes.dreamOutput.iteration = 2.0 - bayes.dreamOutput.modelOutput = 0.0 bayes.dreamOutput.AR = np.array([[1.0, np.nan]]) bayes.dreamOutput.R_stat = np.array( [ @@ -4576,36 +4575,6 @@ def dream_results(): ] ), ], - layerSlds=[ - [ - np.array( - [ - [3.15755349e01, 3.35278238e-06, 4.16625659e00], - [3.61791464e01, 7.68327921e-07, 4.16625659e00], - [1.00488530e01, 2.06044530e-06, 2.78042232e01], - [1.08043784e01, 3.29384190e-06, 2.78042232e01], - [2.42251646e01, 2.35556998e-06, 1.55593097e01], - [1.49022278e01, 7.42138004e-07, 1.55593097e01], - [1.49022278e01, 7.42138004e-07, 1.55593097e01], - [2.42251646e01, 2.35556998e-06, 1.55593097e01], - ], - ), - ], - [ - np.array( - [ - [3.15755349e01, 4.11636356e-06, 4.16625659e00], - [3.61791464e01, 1.39268494e-06, 4.16625659e00], - [1.00488530e01, 2.45715680e-06, 2.78042232e01], - [1.08043784e01, 5.26668495e-06, 2.78042232e01], - [2.42251646e01, 3.31348777e-06, 1.55593097e01], - [1.49022278e01, 1.37428245e-06, 1.55593097e01], - [1.49022278e01, 1.37428245e-06, 1.55593097e01], - [2.42251646e01, 3.31348777e-06, 1.55593097e01], - ], - ), - ], - ], sldProfiles=[ [ np.array( @@ -4676,6 +4645,36 @@ def dream_results(): ), ], ], + layers=[ + [ + np.array( + [ + [3.15755349e01, 3.35278238e-06, 4.16625659e00], + [3.61791464e01, 7.68327921e-07, 4.16625659e00], + [1.00488530e01, 2.06044530e-06, 2.78042232e01], + [1.08043784e01, 3.29384190e-06, 2.78042232e01], + [2.42251646e01, 2.35556998e-06, 1.55593097e01], + [1.49022278e01, 7.42138004e-07, 1.55593097e01], + [1.49022278e01, 7.42138004e-07, 1.55593097e01], + [2.42251646e01, 2.35556998e-06, 1.55593097e01], + ], + ), + ], + [ + np.array( + [ + [3.15755349e01, 4.11636356e-06, 4.16625659e00], + [3.61791464e01, 1.39268494e-06, 4.16625659e00], + [1.00488530e01, 2.45715680e-06, 2.78042232e01], + [1.08043784e01, 5.26668495e-06, 2.78042232e01], + [2.42251646e01, 3.31348777e-06, 1.55593097e01], + [1.49022278e01, 1.37428245e-06, 1.55593097e01], + [1.49022278e01, 1.37428245e-06, 1.55593097e01], + [2.42251646e01, 3.31348777e-06, 1.55593097e01], + ], + ), + ], + ], resampledLayers=[[np.array([[0.0, 0.0, 0.0]])], [np.array([[0.0, 0.0, 0.0]])]], calculationResults=RATapi.outputs.CalculationResults( chiValues=np.array([4.6077885, 7.00028098]), @@ -6463,7 +6462,6 @@ def dream_results(): outlierChains=np.array([[0.0, 0.0]]), runtime=2.6e-06, iteration=2.0, - modelOutput=0.0, AR=np.array([[1.0, np.nan]]), R_stat=np.array( [ diff --git a/tests/test_inputs.py b/tests/test_inputs.py index d931ff5f..2874a888 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -9,7 +9,7 @@ import RATapi import RATapi.wrappers from RATapi.inputs import FileHandles, check_indices, make_controls, make_input, make_problem -from RATapi.rat_core import Checks, Control, Limits, NameStore, ProblemDefinition +from RATapi.rat_core import Checks, Control, NameStore, ProblemDefinition from RATapi.utils.enums import ( BackgroundActions, BoundHandling, @@ -351,36 +351,6 @@ def custom_xy_problem(test_names, test_checks): return problem -@pytest.fixture -def normal_limits(): - """The expected limits object from "standard_layers_project" and "custom_xy_project".""" - limits = Limits() - limits.params = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]] - limits.backgroundParams = [[1e-7, 1e-5]] - limits.scalefactors = [[0.02, 0.25]] - limits.bulkIns = [[0.0, 0.0]] - limits.bulkOuts = [[6.2e-6, 6.35e-6]] - limits.resolutionParams = [[0.01, 0.05]] - limits.domainRatios = [] - - return limits - - -@pytest.fixture -def domains_limits(): - """The expected limits object from "domains_project".""" - limits = Limits() - limits.params = [[1.0, 5.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]] - limits.backgroundParams = [[1e-7, 1e-5]] - limits.scalefactors = [[0.02, 0.25]] - limits.bulkIns = [[0.0, 0.0]] - limits.bulkOuts = [[6.2e-6, 6.35e-6]] - limits.resolutionParams = [[0.01, 0.05]] - limits.domainRatios = [[0.4, 0.6]] - - return limits - - @pytest.fixture def standard_layers_controls(): """The expected controls object for input to the compiled RAT code given the default inputs and @@ -427,7 +397,7 @@ def custom_xy_controls(): controls = Control() controls.procedure = Procedures.Calculate controls.parallel = Parallel.Single - controls.calcSldDuringFit = True + controls.calcSldDuringFit = False controls.resampleMinAngle = 0.9 controls.resampleNPoints = 50.0 controls.display = Display.Iter @@ -458,55 +428,38 @@ def custom_xy_controls(): @pytest.mark.parametrize( - ["test_project", "test_problem", "test_limits", "test_controls"], + ["test_project", "test_problem", "test_controls"], [ ( "standard_layers_project", "standard_layers_problem", - "normal_limits", "standard_layers_controls", ), ( "custom_xy_project", "custom_xy_problem", - "normal_limits", "custom_xy_controls", ), ( "domains_project", "domains_problem", - "domains_limits", "standard_layers_controls", ), ], ) -def test_make_input(test_project, test_problem, test_limits, test_controls, request) -> None: - """When converting the "project" and "controls", we should obtain the five input objects required for the compiled +def test_make_input(test_project, test_problem, test_controls, request) -> None: + """When converting the "project" and "controls", we should obtain the two input objects required for the compiled RAT code. """ test_project = request.getfixturevalue(test_project) test_problem = request.getfixturevalue(test_problem) - test_limits = request.getfixturevalue(test_limits) test_controls = request.getfixturevalue(test_controls) - parameter_fields = [ - "params", - "backgroundParams", - "scalefactors", - "bulkIns", - "bulkOuts", - "resolutionParams", - "domainRatios", - ] + problem, controls = make_input(test_project, RATapi.Controls()) - problem, limits, controls = make_input(test_project, RATapi.Controls()) problem = pickle.loads(pickle.dumps(problem)) check_problem_equal(problem, test_problem) - limits = pickle.loads(pickle.dumps(limits)) - for limit_field in parameter_fields: - assert np.all(getattr(limits, limit_field) == getattr(test_limits, limit_field)) - controls = pickle.loads(pickle.dumps(controls)) check_controls_equal(controls, test_controls) diff --git a/tests/test_outputs.py b/tests/test_outputs.py index 7d9a0afd..37a4c631 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -24,8 +24,8 @@ def reflectivity_calculation_str(): "shiftedData = [Data array: [21 x 3], Data array: [21 x 3]],\n" "backgrounds = [Data array: [82 x 3], Data array: [82 x 3]],\n" "resolutions = [Data array: [82 x 2], Data array: [82 x 2]],\n" - "layerSlds = [[Data array: [8 x 3]], [Data array: [8 x 3]]],\n" "sldProfiles = [[Data array: [25 x 2], Data array: [25 x 2]]],\n" + "layers = [[Data array: [8 x 3]], [Data array: [8 x 3]]],\n" "resampledLayers = [[Data array: [1 x 3]], [Data array: [1 x 3]]],\n" "calculationResults = CalculationResults(\n" "\tchiValues = [ 202.83057377 1641.4024969 ],\n" @@ -59,8 +59,8 @@ def dream_str(): "shiftedData = [Data array: [21 x 3], Data array: [21 x 3]],\n" "backgrounds = [Data array: [82 x 3], Data array: [82 x 3]],\n" "resolutions = [Data array: [82 x 2], Data array: [82 x 2]],\n" - "layerSlds = [[Data array: [8 x 3]], [Data array: [8 x 3]]],\n" "sldProfiles = [[Data array: [29 x 2], Data array: [29 x 2]]],\n" + "layers = [[Data array: [8 x 3]], [Data array: [8 x 3]]],\n" "resampledLayers = [[Data array: [1 x 3]], [Data array: [1 x 3]]],\n" "calculationResults = CalculationResults(\n" "\tchiValues = [4.6077885 7.00028098],\n" @@ -119,7 +119,6 @@ def dream_str(): "\toutlierChains = Data array: [1 x 2],\n" "\truntime = 2.6e-06,\n" "\titeration = 2.0,\n" - "\tmodelOutput = 0.0,\n" "\tAR = Data array: [1 x 2],\n" "\tR_stat = Data array: [1 x 19],\n" "\tCR = Data array: [1 x 4],\n" diff --git a/tests/utils.py b/tests/utils.py index a9411aac..40524fd0 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -31,7 +31,7 @@ def check_results_equal(actual_results, expected_results) -> None: "CalculationResults" and "ContrastParams". """ list_fields = ["reflectivity", "simulation", "shiftedData", "backgrounds", "resolutions"] - double_list_fields = ["layerSlds", "sldProfiles", "resampledLayers"] + double_list_fields = ["sldProfiles", "layers", "resampledLayers"] contrast_param_fields = [ "scalefactors", "bulkIn", @@ -109,7 +109,7 @@ def check_bayes_fields_equal(actual_results, expected_results) -> None: "IO", "storeOutput", ], - "dreamOutput": ["runtime", "iteration", "modelOutput"], + "dreamOutput": ["runtime", "iteration"], "nestedSamplerOutput": ["logZ"], }