Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/includes/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ procedure : str
Which procedure RAT should execute. Can be 'calculate', 'simplex', 'de', 'ns', or 'dream'.
calcSldDuringFit : bool
Whether SLD will be calculated during fit (for live plotting etc.)
numSimulationPoints : int
The number of points used for a reflectivity simulation where no data is present.
resampleMinAngle : float
The upper threshold on the angle between three sampled points for resampling, in units of radians over pi.
resampleNPoints : int
Expand Down Expand Up @@ -663,6 +665,7 @@ struct Control {
real_T propScale {};
real_T nsTolerance {};
boolean_T calcSldDuringFit {};
real_T numSimulationPoints {};
real_T resampleMinAngle {};
real_T resampleNPoints {};
real_T updateFreq {};
Expand Down
29 changes: 16 additions & 13 deletions cpp/rat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ RAT::Controls createControlsStruct(const Control& control)
control_struct.propScale = control.propScale;
control_struct.nsTolerance = control.nsTolerance;
control_struct.calcSldDuringFit = control.calcSldDuringFit;
control_struct.numSimulationPoints = control.numSimulationPoints;
control_struct.updateFreq = control.updateFreq;
control_struct.updatePlotFreq = control.updatePlotFreq;
control_struct.nSamples = control.nSamples;
Expand Down Expand Up @@ -910,6 +911,7 @@ PYBIND11_MODULE(rat_core, m) {
.def_readwrite("propScale", &Control::propScale)
.def_readwrite("nsTolerance", &Control::nsTolerance)
.def_readwrite("calcSldDuringFit", &Control::calcSldDuringFit)
.def_readwrite("numSimulationPoints", &Control::numSimulationPoints)
.def_readwrite("resampleMinAngle", &Control::resampleMinAngle)
.def_readwrite("resampleNPoints", &Control::resampleNPoints)
.def_readwrite("updateFreq", &Control::updateFreq)
Expand All @@ -927,12 +929,12 @@ PYBIND11_MODULE(rat_core, m) {
return py::make_tuple(ctrl.parallel, ctrl.procedure, ctrl.display, ctrl.xTolerance, ctrl.funcTolerance,
ctrl.maxFuncEvals, ctrl.maxIterations, ctrl.populationSize, ctrl.fWeight, ctrl.crossoverProbability,
ctrl.targetValue, ctrl.numGenerations, ctrl.strategy, ctrl.nLive, ctrl.nMCMC, ctrl.propScale,
ctrl.nsTolerance, ctrl.calcSldDuringFit, ctrl.resampleMinAngle, ctrl.resampleNPoints,
ctrl.nsTolerance, ctrl.calcSldDuringFit, ctrl.numSimulationPoints, ctrl.resampleMinAngle, ctrl.resampleNPoints,
ctrl.updateFreq, ctrl.updatePlotFreq, ctrl.nSamples, ctrl.nChains, ctrl.jumpProbability, ctrl.pUnitGamma,
ctrl.boundHandling, ctrl.adaptPCR, ctrl.IPCFilePath);
},
[](py::tuple t) { // __setstate__
if (t.size() != 29)
if (t.size() != 30)
throw std::runtime_error("Encountered invalid state unpickling ProblemDefinition object!");

/* Create a new C++ instance */
Expand All @@ -956,17 +958,18 @@ PYBIND11_MODULE(rat_core, m) {
ctrl.propScale = t[15].cast<real_T>();
ctrl.nsTolerance = t[16].cast<real_T>();
ctrl.calcSldDuringFit = t[17].cast<boolean_T>();
ctrl.resampleMinAngle = t[18].cast<real_T>();
ctrl.resampleNPoints = t[19].cast<real_T>();
ctrl.updateFreq = t[20].cast<real_T>();
ctrl.updatePlotFreq = t[21].cast<real_T>();
ctrl.nSamples = t[22].cast<real_T>();
ctrl.nChains = t[23].cast<real_T>();
ctrl.jumpProbability = t[24].cast<real_T>();
ctrl.pUnitGamma = t[25].cast<real_T>();
ctrl.boundHandling = t[26].cast<std::string>();
ctrl.adaptPCR = t[27].cast<boolean_T>();
ctrl.IPCFilePath = t[28].cast<std::string>();
ctrl.numSimulationPoints = t[18].cast<real_T>();
ctrl.resampleMinAngle = t[19].cast<real_T>();
ctrl.resampleNPoints = t[20].cast<real_T>();
ctrl.updateFreq = t[21].cast<real_T>();
ctrl.updatePlotFreq = t[22].cast<real_T>();
ctrl.nSamples = t[23].cast<real_T>();
ctrl.nChains = t[24].cast<real_T>();
ctrl.jumpProbability = t[25].cast<real_T>();
ctrl.pUnitGamma = t[26].cast<real_T>();
ctrl.boundHandling = t[27].cast<std::string>();
ctrl.adaptPCR = t[28].cast<boolean_T>();
ctrl.IPCFilePath = t[29].cast<std::string>();

return ctrl;
}));
Expand Down
13 changes: 12 additions & 1 deletion ratapi/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
from ratapi.utils.custom_errors import custom_pydantic_validation_error
from ratapi.utils.enums import BoundHandling, Display, Parallel, Procedures, Strategies

common_fields = ["procedure", "parallel", "calcSldDuringFit", "resampleMinAngle", "resampleNPoints", "display"]
common_fields = [
"procedure",
"parallel",
"calcSldDuringFit",
"numSimulationPoints",
"resampleMinAngle",
"resampleNPoints",
"display",
]
update_fields = ["updateFreq", "updatePlotFreq"]
fields = {
"calculate": common_fields,
Expand Down Expand Up @@ -53,6 +61,9 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid", use_attribut
calcSldDuringFit: bool = False
"""Whether SLD will be calculated during fit (for live plotting etc.)"""

numSimulationPoints: int = Field(500, ge=2)
"""The number of points used for reflectivity simulations where no data is supplied."""

resampleMinAngle: float = Field(0.9, le=1, gt=0)
"""The upper threshold on the angle between three sampled points for resampling, in units of radians over pi."""

Expand Down
1 change: 1 addition & 0 deletions ratapi/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ def make_controls(input_controls: ratapi.Controls) -> Control:
controls.procedure = input_controls.procedure
controls.parallel = input_controls.parallel
controls.calcSldDuringFit = input_controls.calcSldDuringFit
controls.numSimulationPoints = input_controls.numSimulationPoints
controls.resampleMinAngle = input_controls.resampleMinAngle
controls.resampleNPoints = input_controls.resampleNPoints
controls.display = input_controls.display
Expand Down
127 changes: 71 additions & 56 deletions tests/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ def setup_class(self):
@pytest.fixture
def table_str(self):
table_str = (
"+------------------+-----------+\n"
"| Property | Value |\n"
"+------------------+-----------+\n"
"| procedure | calculate |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
"+------------------+-----------+"
"+---------------------+-----------+\n"
"| Property | Value |\n"
"+---------------------+-----------+\n"
"| procedure | calculate |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
"+---------------------+-----------+"
)

return table_str
Expand All @@ -74,6 +75,7 @@ def table_str(self):
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
("display", Display.Iter),
Expand All @@ -89,6 +91,7 @@ def test_calculate_property_values(self, control_property: str, value: Any) -> N
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
("display", Display.Notify),
Expand Down Expand Up @@ -212,22 +215,23 @@ def setup_class(self):
@pytest.fixture
def table_str(self):
table_str = (
"+------------------+---------+\n"
"| Property | Value |\n"
"+------------------+---------+\n"
"| procedure | simplex |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
"| xTolerance | 1e-06 |\n"
"| funcTolerance | 1e-06 |\n"
"| maxFuncEvals | 10000 |\n"
"| maxIterations | 1000 |\n"
"| updateFreq | 1 |\n"
"| updatePlotFreq | 20 |\n"
"+------------------+---------+"
"+---------------------+---------+\n"
"| Property | Value |\n"
"+---------------------+---------+\n"
"| procedure | simplex |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
"| xTolerance | 1e-06 |\n"
"| funcTolerance | 1e-06 |\n"
"| maxFuncEvals | 10000 |\n"
"| maxIterations | 1000 |\n"
"| updateFreq | 1 |\n"
"| updatePlotFreq | 20 |\n"
"+---------------------+---------+"
)

return table_str
Expand All @@ -237,6 +241,7 @@ def table_str(self):
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
("display", Display.Iter),
Expand All @@ -258,6 +263,7 @@ def test_simplex_property_values(self, control_property: str, value: Any) -> Non
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
("display", Display.Notify),
Expand Down Expand Up @@ -375,6 +381,7 @@ def table_str(self):
"| procedure | de |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
Expand All @@ -396,6 +403,7 @@ def table_str(self):
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
("display", Display.Iter),
Expand All @@ -417,6 +425,7 @@ def test_de_property_values(self, control_property: str, value: Any) -> None:
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
("display", Display.Notify),
Expand Down Expand Up @@ -542,20 +551,21 @@ def setup_class(self):
@pytest.fixture
def table_str(self):
table_str = (
"+------------------+--------+\n"
"| Property | Value |\n"
"+------------------+--------+\n"
"| procedure | ns |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
"| nLive | 150 |\n"
"| nMCMC | 0 |\n"
"| propScale | 0.1 |\n"
"| nsTolerance | 0.1 |\n"
"+------------------+--------+"
"+---------------------+--------+\n"
"| Property | Value |\n"
"+---------------------+--------+\n"
"| procedure | ns |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
"| nLive | 150 |\n"
"| nMCMC | 0 |\n"
"| propScale | 0.1 |\n"
"| nsTolerance | 0.1 |\n"
"+---------------------+--------+"
)

return table_str
Expand All @@ -565,6 +575,7 @@ def table_str(self):
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
("display", Display.Iter),
Expand All @@ -584,6 +595,7 @@ def test_ns_property_values(self, control_property: str, value: Any) -> None:
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
("display", Display.Notify),
Expand Down Expand Up @@ -708,22 +720,23 @@ def setup_class(self):
@pytest.fixture
def table_str(self):
table_str = (
"+------------------+---------+\n"
"| Property | Value |\n"
"+------------------+---------+\n"
"| procedure | dream |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
"| nSamples | 20000 |\n"
"| nChains | 10 |\n"
"| jumpProbability | 0.5 |\n"
"| pUnitGamma | 0.2 |\n"
"| boundHandling | reflect |\n"
"| adaptPCR | True |\n"
"+------------------+---------+"
"+---------------------+---------+\n"
"| Property | Value |\n"
"+---------------------+---------+\n"
"| procedure | dream |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
"| display | iter |\n"
"| nSamples | 20000 |\n"
"| nChains | 10 |\n"
"| jumpProbability | 0.5 |\n"
"| pUnitGamma | 0.2 |\n"
"| boundHandling | reflect |\n"
"| adaptPCR | True |\n"
"+---------------------+---------+"
)

return table_str
Expand All @@ -733,6 +746,7 @@ def table_str(self):
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
("display", Display.Iter),
Expand All @@ -754,6 +768,7 @@ def test_dream_property_values(self, control_property: str, value: Any) -> None:
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
("display", Display.Notify),
Expand Down
5 changes: 4 additions & 1 deletion tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ def standard_layers_controls():
controls.procedure = Procedures.Calculate
controls.parallel = Parallel.Single
controls.calcSldDuringFit = False
controls.numSimulationPoints = 500
controls.resampleMinAngle = 0.9
controls.resampleNPoints = 50.0
controls.resampleNPoints = 50
controls.display = Display.Iter
controls.xTolerance = 1.0e-6
controls.funcTolerance = 1.0e-6
Expand Down Expand Up @@ -398,6 +399,7 @@ def custom_xy_controls():
controls.procedure = Procedures.Calculate
controls.parallel = Parallel.Single
controls.calcSldDuringFit = False
controls.numSimulationPoints = 500
controls.resampleMinAngle = 0.9
controls.resampleNPoints = 50.0
controls.display = Display.Iter
Expand Down Expand Up @@ -756,6 +758,7 @@ def check_controls_equal(actual_controls, expected_controls) -> None:
"procedure",
"parallel",
"calcSldDuringFit",
"numSimulationPoints",
"resampleMinAngle",
"resampleNPoints",
"display",
Expand Down