Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions cpp/includes/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,6 @@ parallel : str
How the calculation should be parallelised (This uses the Parallel Computing Toolbox). Can be 'single', 'contrasts' or 'points'.
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
Expand Down Expand Up @@ -644,6 +642,8 @@ boundHandling : str
[DREAM] How steps past the space boundaries should be handled. Can be 'off', 'reflect', 'bound', or 'fold'.
adaptPCR : bool
[DREAM] Whether the crossover probability for differential evolution should be adapted during the run.
calcSLD : bool
Whether SLD will be calculated (for live plotting etc.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove calcSLD from Controls, I think you can safely revert all changes in this file.

)";

struct Control {
Expand All @@ -664,7 +664,6 @@ struct Control {
real_T nMCMC {};
real_T propScale {};
real_T nsTolerance {};
boolean_T calcSldDuringFit {};
real_T numSimulationPoints {};
real_T resampleMinAngle {};
real_T resampleNPoints {};
Expand All @@ -676,6 +675,7 @@ struct Control {
real_T pUnitGamma {};
std::string boundHandling {};
boolean_T adaptPCR;
boolean_T calcSLD {};
std::string IPCFilePath {};
};

Expand Down
34 changes: 17 additions & 17 deletions cpp/rat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ RAT::Controls createControlsStruct(const Control& control)
control_struct.nMCMC = control.nMCMC;
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;
Expand All @@ -333,6 +332,7 @@ RAT::Controls createControlsStruct(const Control& control)
control_struct.resampleNPoints = control.resampleNPoints;
stringToRatBoundedArray(control.boundHandling, control_struct.boundHandling.data, control_struct.boundHandling.size);
control_struct.adaptPCR = control.adaptPCR;
control_struct.calcSLD = false;
stringToRatBoundedArray(control.IPCFilePath, control_struct.IPCFilePath.data, control_struct.IPCFilePath.size);

return control_struct;
Expand Down Expand Up @@ -910,7 +910,6 @@ PYBIND11_MODULE(rat_core, m) {
.def_readwrite("nMCMC", &Control::nMCMC)
.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)
Expand All @@ -922,16 +921,17 @@ PYBIND11_MODULE(rat_core, m) {
.def_readwrite("pUnitGamma", &Control::pUnitGamma)
.def_readwrite("boundHandling", &Control::boundHandling)
.def_readwrite("adaptPCR", &Control::adaptPCR)
.def_readwrite("calcSLD", &Control::calcSLD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove calcSLD from Controls, I think you can safely revert all changes in this file except for line 335

i.e. control_struct.calcSLD = false;

.def_readwrite("IPCFilePath", &Control::IPCFilePath)
.def(py::pickle(
[](const Control &ctrl) { // __getstate__
/* Return a tuple that fully encodes the state of the object */
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.numSimulationPoints, ctrl.resampleMinAngle, ctrl.resampleNPoints,
ctrl.updateFreq, ctrl.updatePlotFreq, ctrl.nSamples, ctrl.nChains, ctrl.jumpProbability, ctrl.pUnitGamma,
ctrl.boundHandling, ctrl.adaptPCR, ctrl.IPCFilePath);
ctrl.nsTolerance, ctrl.numSimulationPoints, ctrl.resampleMinAngle, ctrl.resampleNPoints,
ctrl.updateFreq, ctrl.updatePlotFreq, ctrl.nSamples, ctrl.nChains, ctrl.jumpProbability,
ctrl.pUnitGamma, ctrl.boundHandling, ctrl.adaptPCR, ctrl.calcSLD, ctrl.IPCFilePath);
},
[](py::tuple t) { // __setstate__
if (t.size() != 30)
Expand All @@ -957,18 +957,18 @@ PYBIND11_MODULE(rat_core, m) {
ctrl.nMCMC = t[14].cast<real_T>();
ctrl.propScale = t[15].cast<real_T>();
ctrl.nsTolerance = t[16].cast<real_T>();
ctrl.calcSldDuringFit = t[17].cast<boolean_T>();
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.numSimulationPoints = t[17].cast<real_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.calcSLD = t[28].cast<boolean_T>();
ctrl.IPCFilePath = t[29].cast<std::string>();

return ctrl;
Expand Down
4 changes: 0 additions & 4 deletions ratapi/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
common_fields = [
"procedure",
"parallel",
"calcSldDuringFit",
"numSimulationPoints",
"resampleMinAngle",
"resampleNPoints",
Expand Down Expand Up @@ -58,9 +57,6 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid", use_attribut
parallel: Parallel = Parallel.Single
"""How the calculation should be parallelised. Can be 'single', 'contrasts' or 'points'."""

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."""

Expand Down
2 changes: 1 addition & 1 deletion ratapi/examples/bayes_benchmark/bayes_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def bayes_benchmark_3d(grid_size: int) -> (RAT.outputs.BayesResults, Calculation
scale_param = problem.scalefactors[0]
scalefactor = np.linspace(scale_param.min, scale_param.max, grid_size)

controls = RAT.Controls(procedure="calculate", calcSldDuringFit=True, display="off")
controls = RAT.Controls(procedure="calculate", display="off")

def calculate_posterior(roughness_index: int, background_index: int, scalefactor_index: int) -> float:
"""Calculate the posterior for an item in the roughness, background, and scalefactor vectors.
Expand Down
1 change: 0 additions & 1 deletion ratapi/examples/languages/run_custom_file_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

project = setup_problem.make_example_problem()
controls = RAT.Controls()
controls.calcSldDuringFit = True

# Python
start = time.time()
Expand Down
3 changes: 0 additions & 3 deletions ratapi/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ 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
Expand Down Expand Up @@ -583,8 +582,6 @@ def make_controls(input_controls: ratapi.Controls) -> Control:
controls.pUnitGamma = input_controls.pUnitGamma
controls.boundHandling = input_controls.boundHandling
controls.adaptPCR = input_controls.adaptPCR
# IPC
controls.IPCFilePath = ""

controls.IPCFilePath = input_controls._IPCFilePath

Expand Down
8 changes: 4 additions & 4 deletions ratapi/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ class Strategies(RATEnum):
"""The base vector is random."""

LocalToBest = "local to best"
"""The base vector is a combination of one randomly-selected local solution
"""The base vector is a combination of one randomly-selected local solution
and the best solution of the previous iteration."""

BestWithJitter = "best jitter"
"""The base vector is the best solution of the previous iteration, with a small random perturbation applied."""

RandomWithPerVectorDither = "vector dither"
"""The base vector is random, with a random scaling factor applied to each mutant.
"""The base vector is random, with a random scaling factor applied to each mutant.
This scaling factor is different for each mutant."""

RandomWithPerGenerationDither = "generation dither"
"""The base vector is random, with a random scaling factor applied to each mutant.
"""The base vector is random, with a random scaling factor applied to each mutant.
This scaling factor is the same for every mutant, and randomised every generation."""

RandomEitherOrAlgorithm = "either or"
"""The base vector is randomly chosen from either a pure random mutation,
"""The base vector is randomly chosen from either a pure random mutation,
or a pure recombination of parent parameter values."""

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class BuildExt(build_ext):
"""A custom build extension for adding compiler-specific options."""

c_opts = {
"msvc": ["/EHsc"],
"unix": ["-fopenmp", "-std=c++11"],
"msvc": ["/O2", "/EHsc"],
"unix": ["-O2", "-fopenmp", "-std=c++11"],
}
l_opts = {
"msvc": [],
Expand All @@ -71,7 +71,7 @@ class BuildExt(build_ext):

if sys.platform == "darwin":
darwin_opts = ["-stdlib=libc++", "-mmacosx-version-min=10.9"]
c_opts["unix"] = [*darwin_opts, "-fopenmp"]
c_opts["unix"] = [*darwin_opts, "-fopenmp", "-O2"]
l_opts["unix"] = [*darwin_opts, "-lomp"]

def build_extensions(self):
Expand Down
23 changes: 0 additions & 23 deletions tests/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def table_str(self):
"+---------------------+-----------+\n"
"| procedure | calculate |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
Expand All @@ -74,7 +73,6 @@ def table_str(self):
"control_property, value",
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
Expand All @@ -90,7 +88,6 @@ def test_calculate_property_values(self, control_property: str, value: Any) -> N
"control_property, value",
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
Expand Down Expand Up @@ -186,14 +183,6 @@ def test_calculate_parallel_validation(self, value: Any) -> None:
with pytest.raises(pydantic.ValidationError, match="Input should be 'single', 'points' or 'contrasts'"):
self.calculate.parallel = value

@pytest.mark.parametrize("value", [5.0, 12])
def test_calculate_calcSldDuringFit_validation(self, value: Union[int, float]) -> None:
"""Tests the calcSldDuringFit setter validation in Calculate class."""
with pytest.raises(
pydantic.ValidationError, match="Input should be a valid boolean, unable to interpret input"
):
self.calculate.calcSldDuringFit = value

@pytest.mark.parametrize("value", ["test", "iterate", True, 1, 3.0])
def test_calculate_display_validation(self, value: Any) -> None:
"""Tests the display setter validation in Calculate class."""
Expand All @@ -220,7 +209,6 @@ def table_str(self):
"+---------------------+---------+\n"
"| procedure | simplex |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
Expand All @@ -240,7 +228,6 @@ def table_str(self):
"control_property, value",
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
Expand All @@ -262,7 +249,6 @@ def test_simplex_property_values(self, control_property: str, value: Any) -> Non
"control_property, value",
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
Expand Down Expand Up @@ -380,7 +366,6 @@ def table_str(self):
"+----------------------+---------------+\n"
"| procedure | de |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
Expand All @@ -402,7 +387,6 @@ def table_str(self):
"control_property, value",
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
Expand All @@ -424,7 +408,6 @@ def test_de_property_values(self, control_property: str, value: Any) -> None:
"control_property, value",
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
Expand Down Expand Up @@ -556,7 +539,6 @@ def table_str(self):
"+---------------------+--------+\n"
"| procedure | ns |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
Expand All @@ -574,7 +556,6 @@ def table_str(self):
"control_property, value",
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
Expand All @@ -594,7 +575,6 @@ def test_ns_property_values(self, control_property: str, value: Any) -> None:
"control_property, value",
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
Expand Down Expand Up @@ -725,7 +705,6 @@ def table_str(self):
"+---------------------+---------+\n"
"| procedure | dream |\n"
"| parallel | single |\n"
"| calcSldDuringFit | False |\n"
"| numSimulationPoints | 500 |\n"
"| resampleMinAngle | 0.9 |\n"
"| resampleNPoints | 50 |\n"
Expand All @@ -745,7 +724,6 @@ def table_str(self):
"control_property, value",
[
("parallel", Parallel.Single),
("calcSldDuringFit", False),
("numSimulationPoints", 500),
("resampleMinAngle", 0.9),
("resampleNPoints", 50),
Expand All @@ -767,7 +745,6 @@ def test_dream_property_values(self, control_property: str, value: Any) -> None:
"control_property, value",
[
("parallel", Parallel.Points),
("calcSldDuringFit", True),
("numSimulationPoints", 10),
("resampleMinAngle", 0.2),
("resampleNPoints", 1),
Expand Down
3 changes: 0 additions & 3 deletions tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ def standard_layers_controls():
controls = Control()
controls.procedure = Procedures.Calculate
controls.parallel = Parallel.Single
controls.calcSldDuringFit = False
controls.numSimulationPoints = 500
controls.resampleMinAngle = 0.9
controls.resampleNPoints = 50
Expand Down Expand Up @@ -398,7 +397,6 @@ def custom_xy_controls():
controls = Control()
controls.procedure = Procedures.Calculate
controls.parallel = Parallel.Single
controls.calcSldDuringFit = False
controls.numSimulationPoints = 500
controls.resampleMinAngle = 0.9
controls.resampleNPoints = 50.0
Expand Down Expand Up @@ -757,7 +755,6 @@ def check_controls_equal(actual_controls, expected_controls) -> None:
controls_fields = [
"procedure",
"parallel",
"calcSldDuringFit",
"numSimulationPoints",
"resampleMinAngle",
"resampleNPoints",
Expand Down
Loading