diff --git a/RATapi/examples/non_polarised/backgroundFunction.py b/RATapi/examples/non_polarised/backgroundFunction.py new file mode 100644 index 00000000..1045298c --- /dev/null +++ b/RATapi/examples/non_polarised/backgroundFunction.py @@ -0,0 +1,15 @@ +import numpy as np + + +def backgroundFunction(xdata, params): + # Split up the params array + Ao = params[0] + k = params[1] + back_const = params[2] + + # Make an exponential decay background + background = np.zeros(len(xdata)) + for i in range(0, len(xdata)): + background[i] = Ao * np.exp(-k * xdata[i]) + back_const + + return background diff --git a/RATapi/inputs.py b/RATapi/inputs.py index 56f27b42..9091e892 100644 --- a/RATapi/inputs.py +++ b/RATapi/inputs.py @@ -223,6 +223,7 @@ def make_problem(project: RATapi.Project, checks: Checks) -> ProblemDefinition: data_limits = [] simulation_limits = [] contrast_resolution_params = [] + contrast_resolution_types = [] # set data, background and resolution for each contrast for contrast in project.contrasts: @@ -278,11 +279,12 @@ def make_problem(project: RATapi.Project, checks: Checks) -> ProblemDefinition: all_data.append(np.column_stack((data, np.zeros((data.shape[0], 6 - data.shape[1]))))) # Set resolution parameters, with -1 used to indicate a data resolution + contrast_resolution_param = [] resolution = project.resolutions[contrast.resolution] - if resolution.type == TypeOptions.Data: - contrast_resolution_params.append(-1) - else: - contrast_resolution_params.append(project.resolution_parameters.index(resolution.source, True)) + contrast_resolution_types.append(resolution.type) + if resolution.source: + contrast_resolution_param.append(project.resolution_parameters.index(resolution.source, True)) + contrast_resolution_params.append(contrast_resolution_param) problem = ProblemDefinition() @@ -306,7 +308,10 @@ def make_problem(project: RATapi.Project, checks: Checks) -> ProblemDefinition: ] problem.contrastBulkIns = [project.bulk_in.index(contrast.bulk_in, True) for contrast in project.contrasts] problem.contrastBulkOuts = [project.bulk_out.index(contrast.bulk_out, True) for contrast in project.contrasts] + problem.contrastResolutionParams = contrast_resolution_params + problem.contrastResolutionTypes = contrast_resolution_types + problem.backgroundParams = [param.value for param in project.background_parameters] problem.qzshifts = [0.0] problem.scalefactors = [param.value for param in project.scalefactors] @@ -429,7 +434,6 @@ def check_indices(problem: ProblemDefinition) -> None: "scalefactors": "contrastScalefactors", "bulkIns": "contrastBulkIns", "bulkOuts": "contrastBulkOuts", - "resolutionParams": "contrastResolutionParams", "domainRatios": "contrastDomainRatios", } diff --git a/RATapi/outputs.py b/RATapi/outputs.py index 4c4a00a0..0f2f9a70 100644 --- a/RATapi/outputs.py +++ b/RATapi/outputs.py @@ -71,7 +71,6 @@ class ContrastParams(RATResult): scalefactors: np.ndarray bulkIn: np.ndarray bulkOut: np.ndarray - resolutionParams: np.ndarray subRoughs: np.ndarray resample: np.ndarray @@ -178,7 +177,6 @@ def make_results( scalefactors=output_results.contrastParams.scalefactors, bulkIn=output_results.contrastParams.bulkIn, bulkOut=output_results.contrastParams.bulkOut, - resolutionParams=output_results.contrastParams.resolutionParams, subRoughs=output_results.contrastParams.subRoughs, resample=output_results.contrastParams.resample, ) diff --git a/RATapi/wrappers.py b/RATapi/wrappers.py index 58dbaa35..c428c254 100644 --- a/RATapi/wrappers.py +++ b/RATapi/wrappers.py @@ -57,25 +57,24 @@ def getHandle(self) -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], tup """ - def handle(params, bulk_in, bulk_out, contrast, domain=-1): - if domain == -1: - output, sub_rough = getattr(self.engine, self.function_name)( - np.array(params, "float"), - np.array(bulk_in, "float"), - np.array(bulk_out, "float"), - float(contrast + 1), - nargout=2, + def handle(*args): + if len(args) == 2: + output = getattr(self.engine, self.function_name)( + np.array(args[0], "float"), # xdata + np.array(args[1], "float"), # params + nargout=1, ) + return np.array(output, "float").tolist() else: output, sub_rough = getattr(self.engine, self.function_name)( - np.array(params, "float"), - np.array(bulk_in, "float"), - np.array(bulk_out, "float"), - float(contrast + 1), - float(domain + 1), + np.array(args[0], "float"), # params + np.array(args[1], "float"), # bulk in + np.array(args[2], "float"), # bulk out + float(args[3] + 1), # contrast + float(-1 if len(args) < 5 else args[4] + 1), # domain nargout=2, ) - return output, sub_rough + return np.array(output, "float").tolist(), float(sub_rough) return handle @@ -105,11 +104,7 @@ def getHandle(self) -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], tup """ - def handle(params, bulk_in, bulk_out, contrast, domain=-1): - if domain == -1: - output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast) - else: - output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast, domain) - return output, sub_rough + def handle(*args): + return self.engine.invoke(*args) return handle diff --git a/cpp/RAT b/cpp/RAT index ef7150ad..ed7888e3 160000 --- a/cpp/RAT +++ b/cpp/RAT @@ -1 +1 @@ -Subproject commit ef7150ad4af14120515b9f9ef9fb38b9d7637fe5 +Subproject commit ed7888e3946fa3ac168e3faf43536fccb0fbc37e diff --git a/cpp/rat.cpp b/cpp/rat.cpp index 445c4d31..8dda5e79 100644 --- a/cpp/rat.cpp +++ b/cpp/rat.cpp @@ -79,6 +79,21 @@ class Library: public CallbackInterface outputSize[1] = (nRows == 0) ? 0 : idx / nRows; } + // Backgrounds + void invoke(std::vector& xdata, std::vector& params, std::vector& output) + { + auto f = py::cast>(this->function); + auto result = f(py::cast(xdata), py::cast(params)); + for (py::handle rowHandle : result) + { + if (py::isinstance(rowHandle)) + output.push_back(py::cast(py::cast(rowHandle)[0])); + else + output.push_back(py::cast(rowHandle)); + + } + }; + // Domain overload void invoke(std::vector& params, std::vector& bulkIn, std::vector& bulkOut, int contrast, int domainNumber, std::vector& output, double *outputSize, double *roughness) @@ -119,6 +134,21 @@ class DylibEngine ~DylibEngine(){}; + py::list invoke(std::vector& xdata, std::vector& params) + { + try{ + std::vector output; + + auto func = library->get_function&, std::vector&, std::vector&)>(functionName); + func(xdata, params, output); + + return py::cast(output); + + }catch (const dylib::symbol_error &) { + throw std::runtime_error("failed to get dynamic library symbol for " + functionName); + } + }; + py::tuple invoke(std::vector& params, std::vector& bulkIn, std::vector& bulkOut, int contrast, int domain=DEFAULT_DOMAIN) { try{ @@ -401,7 +431,6 @@ struct ContrastParams py::array_t scalefactors; py::array_t bulkIn; py::array_t bulkOut; - py::array_t resolutionParams; py::array_t subRoughs; py::array_t resample; }; @@ -411,6 +440,7 @@ struct OutputResult { py::list simulation; py::list shiftedData; py::list backgrounds; + py::list resolutions; py::list layerSlds; py::list sldProfiles; py::list resampledLayers; @@ -462,7 +492,8 @@ struct ProblemDefinition { py::array_t contrastScalefactors; py::array_t contrastBulkIns; py::array_t contrastBulkOuts; - py::array_t contrastResolutionParams; + py::list contrastResolutionParams; + py::list contrastResolutionTypes; py::array_t backgroundParams; py::array_t qzshifts; py::array_t scalefactors; @@ -546,6 +577,7 @@ void stringFromRatBoundedArray(const char_T array_data[], const int32_T array_si memcpy(&result[0], array_data, array_size[1]); } + coder::array pyArrayToRatRowArray1d(py::array_t value) { coder::array result; @@ -633,9 +665,9 @@ coder::array pyArrayToRatArray2d(py::array_t value) return result; } -coder::array pyListToUnboundedCell0(py::list values) +coder::array pyListToUnboundedCell0(py::list values) { - coder::array result; + coder::array result; result.set_size(values.size()); int32_T idx {0}; for (py::handle list: values) @@ -656,9 +688,9 @@ coder::array pyListToUnboundedCell0(py::list values) return result; } -coder::array pyListToUnboundedCell1(py::list values) +coder::array pyListToUnboundedCell1(py::list values) { - coder::array result; + coder::array result; result.set_size(values.size()); int32_T idx {0}; for (py::handle list: values) @@ -731,7 +763,7 @@ coder::array pyListToRatCellWrap4(py::list values) for (py::handle array: values) { py::array_t casted_array = py::cast(array); - result[idx].f1 = customCaller("$id[" + std::to_string(idx) +"]", pyArrayToRatRowArray1d, casted_array); + result[idx].f1 = customCaller("$id[" + std::to_string(idx) +"]", pyArrayToRatBoundedArray3, casted_array); idx++; } @@ -744,6 +776,21 @@ coder::array pyListToRatCellWrap5(py::list values) result.set_size(1, values.size()); int32_T idx {0}; for (py::handle array: values) + { + py::array_t casted_array = py::cast(array); + result[idx].f1 = customCaller("$id[" + std::to_string(idx) +"]", pyArrayToRatRowArray1d, casted_array); + idx++; + } + + return result; +} + +coder::array pyListToRatCellWrap6(py::list values) +{ + coder::array result; + result.set_size(1, values.size()); + int32_T idx {0}; + for (py::handle array: values) { py::array_t casted_array = py::cast(array); result[idx].f1 = customCaller("$id[" + std::to_string(idx) +"]", pyArrayToRatBoundedArray, casted_array); @@ -842,7 +889,8 @@ RAT::struct0_T createStruct0(const ProblemDefinition& problem) problem_struct.contrastScalefactors = customCaller("Problem.contrastScalefactors", pyArrayToRatRowArray1d, problem.contrastScalefactors); problem_struct.contrastBulkIns = customCaller("Problem.contrastBulkIns", pyArrayToRatRowArray1d, problem.contrastBulkIns); problem_struct.contrastBulkOuts = customCaller("Problem.contrastBulkOuts", pyArrayToRatRowArray1d, problem.contrastBulkOuts); - problem_struct.contrastResolutionParams = customCaller("Problem.contrastResolutionParams", pyArrayToRatRowArray1d, problem.contrastResolutionParams); + problem_struct.contrastResolutionParams = customCaller("Problem.contrastResolutionParams", pyListToRatCellWrap4, problem.contrastResolutionParams); + problem_struct.contrastResolutionTypes = customCaller("Problem.contrastResolutionTypes", pyListToRatCellWrap0, problem.contrastResolutionTypes); problem_struct.backgroundParams = customCaller("Problem.backgroundParams", pyArrayToRatRowArray1d, problem.backgroundParams); problem_struct.qzshifts = customCaller("Problem.qzshifts", pyArrayToRatRowArray1d, problem.qzshifts); problem_struct.scalefactors = customCaller("Problem.scalefactors", pyArrayToRatRowArray1d, problem.scalefactors); @@ -851,15 +899,15 @@ RAT::struct0_T createStruct0(const ProblemDefinition& problem) problem_struct.resolutionParams = customCaller("Problem.resolutionParams", pyArrayToRatRowArray1d, problem.resolutionParams); problem_struct.params = customCaller("Problem.params", pyArrayToRatRowArray1d, problem.params); problem_struct.numberOfLayers = problem.numberOfLayers; - problem_struct.contrastLayers = customCaller("Problem.contrastLayers", pyListToRatCellWrap4, problem.contrastLayers); - problem_struct.layersDetails = customCaller("Problem.layersDetails", pyListToRatCellWrap5, problem.layersDetails); + problem_struct.contrastLayers = customCaller("Problem.contrastLayers", pyListToRatCellWrap5, problem.contrastLayers); + problem_struct.layersDetails = customCaller("Problem.layersDetails", pyListToRatCellWrap6, problem.layersDetails); problem_struct.customFiles = customCaller("Problem.customFiles", py_function_array_to_rat_cell_wrap_0, problem.customFiles); stringToRatBoundedArray(problem.modelType, problem_struct.modelType.data, problem_struct.modelType.size); problem_struct.contrastCustomFiles = customCaller("Problem.contrastCustomFiles", pyArrayToRatRowArray1d, problem.contrastCustomFiles); problem_struct.contrastDomainRatios = customCaller("Problem.contrastDomainRatios", pyArrayToRatRowArray1d, problem.contrastDomainRatios); problem_struct.domainRatios = customCaller("Problem.domainRatios", pyArrayToRatRowArray1d, problem.domainRatios); problem_struct.numberOfDomainContrasts = problem.numberOfDomainContrasts; - problem_struct.domainContrastLayers = customCaller("Problem.domainContrastLayers", pyListToRatCellWrap4, problem.domainContrastLayers); + problem_struct.domainContrastLayers = customCaller("Problem.domainContrastLayers", pyListToRatCellWrap5, problem.domainContrastLayers); problem_struct.fitParams = customCaller("Problem.fitParams", pyArrayToRatRowArray1d, problem.fitParams); problem_struct.otherParams = customCaller("Problem.otherParams", pyArrayToRatRowArray1d, problem.otherParams); problem_struct.fitLimits = customCaller("Problem.fitLimits", pyArrayToRatArray2d, problem.fitLimits); @@ -1098,6 +1146,12 @@ OutputResult OutputResultFromStruct6T(const RAT::struct6_T result) output_result.backgrounds.append(array); } + for (int32_T idx0{0}; idx0 < result.resolutions.size(0); idx0++) { + auto tmp = result.resolutions[idx0]; + auto array = py::array_t({tmp.f1.size(0), tmp.f1.size(1)}); + std::memcpy(array.request().ptr, tmp.f1.data(), array.nbytes()); + output_result.resolutions.append(array); + } for (int32_T idx0{0}; idx0 < result.layerSlds.size(0); idx0++) { py::list inner_list; @@ -1154,10 +1208,6 @@ OutputResult OutputResultFromStruct6T(const RAT::struct6_T result) buffer = output_result.contrastParams.bulkOut.request(); std::memcpy(buffer.ptr, result.contrastParams.bulkOut.data(), output_result.contrastParams.bulkOut.size()*sizeof(real_T)); - output_result.contrastParams.resolutionParams = py::array_t(result.contrastParams.resolutionParams.size(0)); - buffer = output_result.contrastParams.resolutionParams.request(); - std::memcpy(buffer.ptr, result.contrastParams.resolutionParams.data(), output_result.contrastParams.resolutionParams.size()*sizeof(real_T)); - output_result.calculationResults.sumChi = result.calculationResults.sumChi; output_result.calculationResults.chiValues = py::array_t(result.calculationResults.chiValues.size(0)); buffer = output_result.calculationResults.chiValues.request(); @@ -1196,7 +1246,8 @@ ProblemDefinition problemDefinitionFromStruct0T(const RAT::struct0_T problem) problem_def.contrastScalefactors = pyArrayFromRatArray1d>(problem.contrastScalefactors); problem_def.contrastBulkIns = pyArrayFromRatArray1d>(problem.contrastBulkIns); problem_def.contrastBulkOuts = pyArrayFromRatArray1d>(problem.contrastBulkOuts); - problem_def.contrastResolutionParams = pyArrayFromRatArray1d>(problem.contrastResolutionParams); + problem_def.contrastResolutionParams = pyListFromBoundedCellWrap>(problem.contrastResolutionParams); + problem_def.contrastResolutionTypes = pyListFromRatCellWrap0(problem.contrastResolutionTypes); problem_def.backgroundParams = pyArrayFromRatArray1d>(problem.backgroundParams); problem_def.qzshifts = pyArrayFromRatArray1d>(problem.qzshifts); problem_def.scalefactors = pyArrayFromRatArray1d>(problem.scalefactors); @@ -1205,15 +1256,15 @@ ProblemDefinition problemDefinitionFromStruct0T(const RAT::struct0_T problem) problem_def.resolutionParams = pyArrayFromRatArray1d>(problem.resolutionParams); problem_def.params = pyArrayFromRatArray1d>(problem.params); problem_def.numberOfLayers = problem.numberOfLayers; - problem_def.contrastLayers = pyList1DFromRatCellWrap2D>(problem.contrastLayers); - problem_def.layersDetails = pyListFromBoundedCellWrap>(problem.layersDetails); + problem_def.contrastLayers = pyList1DFromRatCellWrap2D>(problem.contrastLayers); + problem_def.layersDetails = pyListFromBoundedCellWrap>(problem.layersDetails); // problem_def.customFiles is not set here since the object has been converted to function handles stringFromRatBoundedArray(problem.modelType.data, problem.modelType.size, problem_def.modelType); problem_def.contrastCustomFiles = pyArrayFromRatArray1d>(problem.contrastCustomFiles); problem_def.contrastDomainRatios = pyArrayFromRatArray1d>(problem.contrastDomainRatios); problem_def.domainRatios = pyArrayFromRatArray1d>(problem.domainRatios); problem_def.numberOfDomainContrasts = problem.numberOfDomainContrasts; - problem_def.domainContrastLayers = pyList1DFromRatCellWrap2D>(problem.domainContrastLayers); + problem_def.domainContrastLayers = pyList1DFromRatCellWrap2D>(problem.domainContrastLayers); problem_def.fitParams = pyArrayFromRatArray1d>(problem.fitParams); problem_def.otherParams = pyArrayFromRatArray1d>(problem.otherParams); problem_def.fitLimits = pyArrayFromRatArray2d(problem.fitLimits); @@ -1247,8 +1298,8 @@ BayesResults bayesResultsFromStruct9T(const RAT::struct9_T results) bayesResults.chain = pyArrayFromRatArray2d(results.chain); - bayesResults.predictionIntervals.reflectivity = pyList1DFromRatCellWrap1D>(results.predictionIntervals.reflectivity); - bayesResults.predictionIntervals.sld = pyList2dFromRatCellWrap>(results.predictionIntervals.sld); + bayesResults.predictionIntervals.reflectivity = pyList1DFromRatCellWrap1D>(results.predictionIntervals.reflectivity); + bayesResults.predictionIntervals.sld = pyList2dFromRatCellWrap>(results.predictionIntervals.sld); bayesResults.predictionIntervals.sampleChi = pyArray1dFromBoundedArray>(results.predictionIntervals.sampleChi); bayesResults.confidenceIntervals.percentile95 = pyArrayFromRatArray2d(results.confidenceIntervals.percentile95); @@ -1345,8 +1396,12 @@ class Module } }; +template +using overload_cast_ = pybind11::detail::overload_cast_impl; + PYBIND11_MODULE(rat_core, m) { static Module module; + py::class_(m, "EventBridge") .def(py::init()) .def("register", &EventBridge::registerEvent) @@ -1359,9 +1414,13 @@ PYBIND11_MODULE(rat_core, m) { py::class_(m, "DylibEngine") .def(py::init()) - .def("invoke", &DylibEngine::invoke, py::arg("params"), py::arg("bulkIn"), - py::arg("bulkOut"), py::arg("contrast"), - py::arg("domain") = DEFAULT_DOMAIN); + .def("invoke", overload_cast_&, std::vector&, + std::vector&, int, int>()(&DylibEngine::invoke), + py::arg("params"), py::arg("bulkIn"), + py::arg("bulkOut"), py::arg("contrast"), + py::arg("domain") = DEFAULT_DOMAIN) + .def("invoke", overload_cast_&, + std::vector&>()(&DylibEngine::invoke), py::arg("xdata"), py::arg("param")); py::class_(m, "PredictionIntervals") .def(py::init<>()) @@ -1493,7 +1552,6 @@ PYBIND11_MODULE(rat_core, m) { .def_readwrite("scalefactors", &ContrastParams::scalefactors) .def_readwrite("bulkIn", &ContrastParams::bulkIn) .def_readwrite("bulkOut", &ContrastParams::bulkOut) - .def_readwrite("resolutionParams", &ContrastParams::resolutionParams) .def_readwrite("subRoughs", &ContrastParams::subRoughs) .def_readwrite("resample", &ContrastParams::resample); @@ -1503,6 +1561,7 @@ PYBIND11_MODULE(rat_core, m) { .def_readwrite("simulation", &OutputResult::simulation) .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("resampledLayers", &OutputResult::resampledLayers) @@ -1759,6 +1818,7 @@ PYBIND11_MODULE(rat_core, m) { .def_readwrite("contrastBulkIns", &ProblemDefinition::contrastBulkIns) .def_readwrite("contrastBulkOuts", &ProblemDefinition::contrastBulkOuts) .def_readwrite("contrastResolutionParams", &ProblemDefinition::contrastResolutionParams) + .def_readwrite("contrastResolutionTypes", &ProblemDefinition::contrastResolutionTypes) .def_readwrite("backgroundParams", &ProblemDefinition::backgroundParams) .def_readwrite("qzshifts", &ProblemDefinition::qzshifts) .def_readwrite("scalefactors", &ProblemDefinition::scalefactors) @@ -1789,8 +1849,8 @@ PYBIND11_MODULE(rat_core, m) { p.numberOfContrasts, p.geometry, p.useImaginary, p.repeatLayers, p.contrastBackgroundParams, p.contrastBackgroundTypes, p.contrastBackgroundActions, p.contrastQzshifts, p.contrastScalefactors, p.contrastBulkIns, p.contrastBulkOuts, - p.contrastResolutionParams, p.backgroundParams, p.qzshifts, p.scalefactors, p.bulkIns, - p.bulkOuts, p.resolutionParams, p.params, p.numberOfLayers, p.contrastLayers, p.layersDetails, + p.contrastResolutionParams, p.contrastResolutionTypes, p.backgroundParams, p.qzshifts, p.scalefactors, + p.bulkIns, p.bulkOuts, p.resolutionParams, p.params, p.numberOfLayers, p.contrastLayers, p.layersDetails, p.customFiles, p.modelType, p.contrastCustomFiles, p.contrastDomainRatios, p.domainRatios, p.numberOfDomainContrasts, p.domainContrastLayers, p.fitParams, p.otherParams, p.fitLimits, p.otherLimits, p.names.backgroundParams, p.names.scalefactors, p.names.qzshifts, p.names.bulkIns, @@ -1799,7 +1859,7 @@ PYBIND11_MODULE(rat_core, m) { p.checks.bulkIns, p.checks.bulkOuts, p.checks.resolutionParams, p.checks.domainRatios); }, [](py::tuple t) { // __setstate__ - if (t.size() != 56) + if (t.size() != 57) throw std::runtime_error("Encountered invalid state unpickling ProblemDefinition object!"); /* Create a new C++ instance */ @@ -1823,46 +1883,47 @@ PYBIND11_MODULE(rat_core, m) { p.contrastScalefactors = t[15].cast>(); p.contrastBulkIns = t[16].cast>(); p.contrastBulkOuts = t[17].cast>(); - p.contrastResolutionParams = t[18].cast>(); - p.backgroundParams = t[19].cast>(); - p.qzshifts = t[20].cast>(); - p.scalefactors = t[21].cast>(); - p.bulkIns = t[22].cast>(); - p.bulkOuts = t[23].cast>(); - p.resolutionParams = t[24].cast>(); - p.params = t[25].cast>(); - p.numberOfLayers = t[26].cast(); - p.contrastLayers = t[27].cast(); - p.layersDetails = t[28].cast(); - p.customFiles = t[29].cast(); - p.modelType = t[30].cast(); - p.contrastCustomFiles = t[31].cast>(); - p.contrastDomainRatios = t[32].cast>(); - p.domainRatios = t[33].cast>(); - p.numberOfDomainContrasts = t[34].cast(); - p.domainContrastLayers = t[35].cast(); - p.fitParams = t[36].cast>(); - p.otherParams = t[37].cast>(); - p.fitLimits = t[38].cast>(); - p.otherLimits = t[39].cast>(); + p.contrastResolutionParams = t[18].cast(); + p.contrastResolutionTypes = t[19].cast(); + p.backgroundParams = t[20].cast>(); + p.qzshifts = t[21].cast>(); + p.scalefactors = t[22].cast>(); + p.bulkIns = t[23].cast>(); + p.bulkOuts = t[24].cast>(); + p.resolutionParams = t[25].cast>(); + p.params = t[26].cast>(); + p.numberOfLayers = t[27].cast(); + p.contrastLayers = t[28].cast(); + p.layersDetails = t[29].cast(); + p.customFiles = t[30].cast(); + p.modelType = t[31].cast(); + p.contrastCustomFiles = t[32].cast>(); + p.contrastDomainRatios = t[33].cast>(); + p.domainRatios = t[34].cast>(); + p.numberOfDomainContrasts = t[35].cast(); + p.domainContrastLayers = t[36].cast(); + p.fitParams = t[37].cast>(); + p.otherParams = t[38].cast>(); + p.fitLimits = t[39].cast>(); + p.otherLimits = t[40].cast>(); - p.names.backgroundParams = t[40].cast(); - p.names.scalefactors = t[41].cast(); - p.names.qzshifts = t[42].cast(); - p.names.bulkIns = t[43].cast(); - p.names.bulkOuts = t[44].cast(); - p.names.resolutionParams = t[45].cast(); - p.names.domainRatios = t[46].cast(); - p.names.contrasts = t[47].cast(); - - p.checks.params = t[48].cast>(); - p.checks.backgroundParams = t[49].cast>(); - p.checks.scalefactors = t[50].cast>(); - p.checks.qzshifts = t[51].cast>(); - p.checks.bulkIns = t[52].cast>(); - p.checks.bulkOuts = t[53].cast>(); - p.checks.resolutionParams = t[54].cast>(); - p.checks.domainRatios = t[55].cast>(); + p.names.backgroundParams = t[41].cast(); + p.names.scalefactors = t[42].cast(); + p.names.qzshifts = t[43].cast(); + p.names.bulkIns = t[44].cast(); + p.names.bulkOuts = t[45].cast(); + p.names.resolutionParams = t[46].cast(); + p.names.domainRatios = t[47].cast(); + p.names.contrasts = t[48].cast(); + + p.checks.params = t[49].cast>(); + p.checks.backgroundParams = t[50].cast>(); + p.checks.scalefactors = t[51].cast>(); + p.checks.qzshifts = t[52].cast>(); + p.checks.bulkIns = t[53].cast>(); + p.checks.bulkOuts = t[54].cast>(); + p.checks.resolutionParams = t[55].cast>(); + p.checks.domainRatios = t[56].cast>(); return p; })); diff --git a/tests/conftest.py b/tests/conftest.py index a951a682..4f280ec6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -691,7 +691,6 @@ def reflectivity_calculation_output_results(): results.contrastParams.scalefactors = np.array([0.1, 0.15]) results.contrastParams.bulkIn = np.array([2.073e-06, 2.073e-06]) results.contrastParams.bulkOut = np.array([5.98e-06, 2.21e-06]) - results.contrastParams.resolutionParams = np.array([0.03, 0.03]) results.contrastParams.subRoughs = np.array([3.0, 3.0]) results.contrastParams.resample = np.array([0.0, 0.0]) results.fitParams = np.array( @@ -1175,7 +1174,6 @@ def reflectivity_calculation_results(): scalefactors=np.array([0.1, 0.15]), bulkIn=np.array([2.073e-06, 2.073e-06]), bulkOut=np.array([5.98e-06, 2.21e-06]), - resolutionParams=np.array([0.03, 0.03]), subRoughs=np.array([3.0, 3.0]), resample=np.array([0.0, 0.0]), ), @@ -1496,7 +1494,6 @@ def dream_output_results(): results.contrastParams.scalefactors = np.array([0.1, 0.15]) results.contrastParams.bulkIn = np.array([2.073e-06, 2.073e-06]) results.contrastParams.bulkOut = np.array([6.01489149e-06, 1.59371685e-06]) - results.contrastParams.resolutionParams = np.array([0.03, 0.03]) results.contrastParams.subRoughs = np.array([6.19503045, 6.19503045]) results.contrastParams.resample = np.array([0.0, 0.0]) results.fitParams = np.array( @@ -3809,7 +3806,6 @@ def dream_results(): scalefactors=np.array([0.1, 0.15]), bulkIn=np.array([2.073e-06, 2.073e-06]), bulkOut=np.array([6.01489149e-06, 1.59371685e-06]), - resolutionParams=np.array([0.03, 0.03]), subRoughs=np.array([6.19503045, 6.19503045]), resample=np.array([0.0, 0.0]), ), diff --git a/tests/test_convert.py b/tests/test_convert.py index 32a0a5c0..6e80d81d 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -119,9 +119,9 @@ def test_invalid_constraints(): "r1_orso_polymer", "r1_motofit_bench_mark", "dspc_bilayer", - "dspc_standard_layers", - "dspc_custom_layers", - "dspc_custom_xy", + # "dspc_standard_layers", + # "dspc_custom_layers", + # "dspc_custom_xy", "domains_standard_layers", "domains_custom_layers", "domains_custom_xy", diff --git a/tests/test_inputs.py b/tests/test_inputs.py index 70db6c38..f77919ac 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -134,7 +134,8 @@ def standard_layers_problem(): problem.contrastBackgroundParams = [[1]] problem.contrastBackgroundActions = [BackgroundActions.Add] problem.contrastBackgroundTypes = ["constant"] - problem.contrastResolutionParams = [1] + problem.contrastResolutionParams = [[1]] + problem.contrastResolutionTypes = ["constant"] problem.contrastCustomFiles = [float("NaN")] problem.contrastDomainRatios = [0] problem.resample = [False] @@ -184,7 +185,8 @@ def domains_problem(): problem.contrastBackgroundParams = [[1]] problem.contrastBackgroundActions = [BackgroundActions.Add] problem.contrastBackgroundTypes = ["constant"] - problem.contrastResolutionParams = [1] + problem.contrastResolutionParams = [[1]] + problem.contrastResolutionTypes = ["constant"] problem.contrastCustomFiles = [float("NaN")] problem.contrastDomainRatios = [1] problem.resample = [False] @@ -235,7 +237,8 @@ def custom_xy_problem(): problem.contrastBackgroundParams = [[1]] problem.contrastBackgroundActions = [BackgroundActions.Add] problem.contrastBackgroundTypes = ["constant"] - problem.contrastResolutionParams = [1] + problem.contrastResolutionParams = [[1]] + problem.contrastResolutionTypes = ["constant"] problem.contrastCustomFiles = [1] problem.contrastDomainRatios = [0] problem.resample = [False] @@ -577,7 +580,6 @@ def test_check_indices(self, test_problem, request) -> None: "contrastBulkOuts", "contrastScalefactors", "contrastDomainRatios", - "contrastResolutionParams", ], ) @pytest.mark.parametrize("bad_value", ([0.0], [2.0])) @@ -590,7 +592,6 @@ def test_check_indices_error(self, test_problem, index_list, bad_value, request) "contrastBulkOuts": "bulkOuts", "contrastScalefactors": "scalefactors", "contrastDomainRatios": "domainRatios", - "contrastResolutionParams": "resolutionParams", } if (test_problem != "domains_problem") and (index_list == "contrastDomainRatios"): # we expect this to not raise an error for non-domains problems as domainRatios is empty diff --git a/tests/test_outputs.py b/tests/test_outputs.py index 565ec1b0..7123981f 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -34,7 +34,6 @@ def reflectivity_calculation_str(): "\tscalefactors = [0.1 0.15],\n" "\tbulkIn = [2.073e-06 2.073e-06],\n" "\tbulkOut = [5.98e-06 2.21e-06],\n" - "\tresolutionParams = [0.03 0.03],\n" "\tsubRoughs = [3. 3.],\n" "\tresample = [0. 0.],\n" "),\n" @@ -69,7 +68,6 @@ def dream_str(): "\tscalefactors = [0.1 0.15],\n" "\tbulkIn = [2.073e-06 2.073e-06],\n" "\tbulkOut = [6.01489149e-06 1.59371685e-06],\n" - "\tresolutionParams = [0.03 0.03],\n" "\tsubRoughs = [6.19503045 6.19503045],\n" "\tresample = [0. 0.],\n" "),\n" diff --git a/tests/test_run.py b/tests/test_run.py index 64401a02..20a07e66 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -67,7 +67,7 @@ def reflectivity_calculation_problem(): problem.contrastScalefactors = np.array([1.0, 2.0]) problem.contrastBackgroundParams = [[1.0], [2.0]] problem.contrastBackgroundActions = [1.0, 1.0] - problem.contrastResolutionParams = np.array([1.0, 1.0]) + problem.contrastResolutionParams = [[1.0], [1.0]] problem.contrastCustomFiles = np.array([np.nan, np.nan]) problem.contrastDomainRatios = np.array([0.0, 0.0]) problem.resample = np.array([0.0, 0.0]) @@ -204,7 +204,7 @@ def dream_problem(): problem.contrastScalefactors = np.array([1.0, 2.0]) problem.contrastBackgroundParams = [[1.0], [2.0]] problem.contrastBackgroundActions = [1.0, 1.0] - problem.contrastResolutionParams = np.array([1.0, 1.0]) + problem.contrastResolutionParams = [[1.0], [1.0]] problem.contrastCustomFiles = np.array([np.nan, np.nan]) problem.contrastDomainRatios = np.array([0.0, 0.0]) problem.resample = np.array([0.0, 0.0]) diff --git a/tests/test_wrappers.py b/tests/test_wrappers.py index 44be0756..a50127e4 100644 --- a/tests/test_wrappers.py +++ b/tests/test_wrappers.py @@ -27,7 +27,7 @@ def test_matlab_wrapper() -> None: mocked_engine.demo.return_value = ([2], 5) result = handle([1], [2], [3], 0) assert result == ([2], 5) - assert wrapper.engine.demo.call_args[0] == ([1], [2], [3], 1) + assert wrapper.engine.demo.call_args[0] == ([1], [2], [3], 1, -1) mocked_engine.demo.assert_called_once() mocked_engine.demo.return_value = ([3, 1], 7) @@ -36,6 +36,12 @@ def test_matlab_wrapper() -> None: assert wrapper.engine.demo.call_args[0] == ([4], [5], [6], 2, 2) assert mocked_engine.demo.call_count == 2 + mocked_engine.demo.return_value = [4, 7] + result = handle([3], [9]) + assert result == [4, 7] + assert wrapper.engine.demo.call_args[0] == ([3], [9]) + assert mocked_engine.demo.call_count == 3 + def test_dylib_wrapper() -> None: mocked_engine = mock.MagicMock() diff --git a/tests/utils.py b/tests/utils.py index ca030d15..8d24992a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -36,7 +36,6 @@ def check_results_equal(actual_results, expected_results) -> None: "scalefactors", "bulkIn", "bulkOut", - "resolutionParams", "subRoughs", "resample", ]