Skip to content

Commit 8a786d8

Browse files
committed
Removes controls option "calcSLDDuringFit"
1 parent 50289e3 commit 8a786d8

File tree

11 files changed

+30
-63
lines changed

11 files changed

+30
-63
lines changed

cpp/includes/defines.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,6 @@ parallel : str
588588
How the calculation should be parallelised (This uses the Parallel Computing Toolbox). Can be 'single', 'contrasts' or 'points'.
589589
procedure : str
590590
Which procedure RAT should execute. Can be 'calculate', 'simplex', 'de', 'ns', or 'dream'.
591-
calcSldDuringFit : bool
592-
Whether SLD will be calculated during fit (for live plotting etc.)
593591
numSimulationPoints : int
594592
The number of points used for a reflectivity simulation where no data is present.
595593
resampleMinAngle : float
@@ -644,6 +642,8 @@ boundHandling : str
644642
[DREAM] How steps past the space boundaries should be handled. Can be 'off', 'reflect', 'bound', or 'fold'.
645643
adaptPCR : bool
646644
[DREAM] Whether the crossover probability for differential evolution should be adapted during the run.
645+
calcSLD : bool
646+
Whether SLD will be calculated (for live plotting etc.)
647647
)";
648648

649649
struct Control {
@@ -664,7 +664,6 @@ struct Control {
664664
real_T nMCMC {};
665665
real_T propScale {};
666666
real_T nsTolerance {};
667-
boolean_T calcSldDuringFit {};
668667
real_T numSimulationPoints {};
669668
real_T resampleMinAngle {};
670669
real_T resampleNPoints {};
@@ -676,6 +675,7 @@ struct Control {
676675
real_T pUnitGamma {};
677676
std::string boundHandling {};
678677
boolean_T adaptPCR;
678+
boolean_T calcSLD {};
679679
std::string IPCFilePath {};
680680
};
681681

cpp/rat.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ RAT::Controls createControlsStruct(const Control& control)
317317
control_struct.nMCMC = control.nMCMC;
318318
control_struct.propScale = control.propScale;
319319
control_struct.nsTolerance = control.nsTolerance;
320-
control_struct.calcSldDuringFit = control.calcSldDuringFit;
321320
control_struct.numSimulationPoints = control.numSimulationPoints;
322321
control_struct.updateFreq = control.updateFreq;
323322
control_struct.updatePlotFreq = control.updatePlotFreq;
@@ -333,6 +332,7 @@ RAT::Controls createControlsStruct(const Control& control)
333332
control_struct.resampleNPoints = control.resampleNPoints;
334333
stringToRatBoundedArray(control.boundHandling, control_struct.boundHandling.data, control_struct.boundHandling.size);
335334
control_struct.adaptPCR = control.adaptPCR;
335+
control_struct.calcSLD = control.calcSLD;
336336
stringToRatBoundedArray(control.IPCFilePath, control_struct.IPCFilePath.data, control_struct.IPCFilePath.size);
337337

338338
return control_struct;
@@ -910,7 +910,6 @@ PYBIND11_MODULE(rat_core, m) {
910910
.def_readwrite("nMCMC", &Control::nMCMC)
911911
.def_readwrite("propScale", &Control::propScale)
912912
.def_readwrite("nsTolerance", &Control::nsTolerance)
913-
.def_readwrite("calcSldDuringFit", &Control::calcSldDuringFit)
914913
.def_readwrite("numSimulationPoints", &Control::numSimulationPoints)
915914
.def_readwrite("resampleMinAngle", &Control::resampleMinAngle)
916915
.def_readwrite("resampleNPoints", &Control::resampleNPoints)
@@ -922,16 +921,17 @@ PYBIND11_MODULE(rat_core, m) {
922921
.def_readwrite("pUnitGamma", &Control::pUnitGamma)
923922
.def_readwrite("boundHandling", &Control::boundHandling)
924923
.def_readwrite("adaptPCR", &Control::adaptPCR)
924+
.def_readwrite("calcSLD", &Control::calcSLD)
925925
.def_readwrite("IPCFilePath", &Control::IPCFilePath)
926926
.def(py::pickle(
927927
[](const Control &ctrl) { // __getstate__
928928
/* Return a tuple that fully encodes the state of the object */
929929
return py::make_tuple(ctrl.parallel, ctrl.procedure, ctrl.display, ctrl.xTolerance, ctrl.funcTolerance,
930930
ctrl.maxFuncEvals, ctrl.maxIterations, ctrl.populationSize, ctrl.fWeight, ctrl.crossoverProbability,
931931
ctrl.targetValue, ctrl.numGenerations, ctrl.strategy, ctrl.nLive, ctrl.nMCMC, ctrl.propScale,
932-
ctrl.nsTolerance, ctrl.calcSldDuringFit, ctrl.numSimulationPoints, ctrl.resampleMinAngle, ctrl.resampleNPoints,
933-
ctrl.updateFreq, ctrl.updatePlotFreq, ctrl.nSamples, ctrl.nChains, ctrl.jumpProbability, ctrl.pUnitGamma,
934-
ctrl.boundHandling, ctrl.adaptPCR, ctrl.IPCFilePath);
932+
ctrl.nsTolerance, ctrl.numSimulationPoints, ctrl.resampleMinAngle, ctrl.resampleNPoints,
933+
ctrl.updateFreq, ctrl.updatePlotFreq, ctrl.nSamples, ctrl.nChains, ctrl.jumpProbability,
934+
ctrl.pUnitGamma, ctrl.boundHandling, ctrl.adaptPCR, ctrl.calcSLD, ctrl.IPCFilePath);
935935
},
936936
[](py::tuple t) { // __setstate__
937937
if (t.size() != 30)
@@ -957,18 +957,18 @@ PYBIND11_MODULE(rat_core, m) {
957957
ctrl.nMCMC = t[14].cast<real_T>();
958958
ctrl.propScale = t[15].cast<real_T>();
959959
ctrl.nsTolerance = t[16].cast<real_T>();
960-
ctrl.calcSldDuringFit = t[17].cast<boolean_T>();
961-
ctrl.numSimulationPoints = t[18].cast<real_T>();
962-
ctrl.resampleMinAngle = t[19].cast<real_T>();
963-
ctrl.resampleNPoints = t[20].cast<real_T>();
964-
ctrl.updateFreq = t[21].cast<real_T>();
965-
ctrl.updatePlotFreq = t[22].cast<real_T>();
966-
ctrl.nSamples = t[23].cast<real_T>();
967-
ctrl.nChains = t[24].cast<real_T>();
968-
ctrl.jumpProbability = t[25].cast<real_T>();
969-
ctrl.pUnitGamma = t[26].cast<real_T>();
970-
ctrl.boundHandling = t[27].cast<std::string>();
971-
ctrl.adaptPCR = t[28].cast<boolean_T>();
960+
ctrl.numSimulationPoints = t[17].cast<real_T>();
961+
ctrl.resampleMinAngle = t[18].cast<real_T>();
962+
ctrl.resampleNPoints = t[19].cast<real_T>();
963+
ctrl.updateFreq = t[20].cast<real_T>();
964+
ctrl.updatePlotFreq = t[21].cast<real_T>();
965+
ctrl.nSamples = t[22].cast<real_T>();
966+
ctrl.nChains = t[23].cast<real_T>();
967+
ctrl.jumpProbability = t[24].cast<real_T>();
968+
ctrl.pUnitGamma = t[25].cast<real_T>();
969+
ctrl.boundHandling = t[26].cast<std::string>();
970+
ctrl.adaptPCR = t[27].cast<boolean_T>();
971+
ctrl.calcSLD = t[28].cast<boolean_T>();
972972
ctrl.IPCFilePath = t[29].cast<std::string>();
973973

974974
return ctrl;

ratapi/controls.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
common_fields = [
2424
"procedure",
2525
"parallel",
26-
"calcSldDuringFit",
2726
"numSimulationPoints",
2827
"resampleMinAngle",
2928
"resampleNPoints",
@@ -58,9 +57,6 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid", use_attribut
5857
parallel: Parallel = Parallel.Single
5958
"""How the calculation should be parallelised. Can be 'single', 'contrasts' or 'points'."""
6059

61-
calcSldDuringFit: bool = False
62-
"""Whether SLD will be calculated during fit (for live plotting etc.)"""
63-
6460
numSimulationPoints: int = Field(500, ge=2)
6561
"""The number of points used for reflectivity simulations where no data is supplied."""
6662

ratapi/examples/bayes_benchmark/bayes_benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def bayes_benchmark_3d(grid_size: int) -> (RAT.outputs.BayesResults, Calculation
250250
scale_param = problem.scalefactors[0]
251251
scalefactor = np.linspace(scale_param.min, scale_param.max, grid_size)
252252

253-
controls = RAT.Controls(procedure="calculate", calcSldDuringFit=True, display="off")
253+
controls = RAT.Controls(procedure="calculate", display="off")
254254

255255
def calculate_posterior(roughness_index: int, background_index: int, scalefactor_index: int) -> float:
256256
"""Calculate the posterior for an item in the roughness, background, and scalefactor vectors.

ratapi/examples/languages/run_custom_file_languages.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
project = setup_problem.make_example_problem()
1313
controls = RAT.Controls()
14-
controls.calcSldDuringFit = True
1514

1615
# Python
1716
start = time.time()

ratapi/inputs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ def make_controls(input_controls: ratapi.Controls) -> Control:
552552

553553
controls.procedure = input_controls.procedure
554554
controls.parallel = input_controls.parallel
555-
controls.calcSldDuringFit = input_controls.calcSldDuringFit
556555
controls.numSimulationPoints = input_controls.numSimulationPoints
557556
controls.resampleMinAngle = input_controls.resampleMinAngle
558557
controls.resampleNPoints = input_controls.resampleNPoints
@@ -583,9 +582,8 @@ def make_controls(input_controls: ratapi.Controls) -> Control:
583582
controls.pUnitGamma = input_controls.pUnitGamma
584583
controls.boundHandling = input_controls.boundHandling
585584
controls.adaptPCR = input_controls.adaptPCR
586-
# IPC
587-
controls.IPCFilePath = ""
588585

586+
controls.calcSLD = False
589587
controls.IPCFilePath = input_controls._IPCFilePath
590588

591589
return controls

ratapi/utils/enums.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ class Strategies(RATEnum):
7373
"""The base vector is random."""
7474

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

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

8282
RandomWithPerVectorDither = "vector dither"
83-
"""The base vector is random, with a random scaling factor applied to each mutant.
83+
"""The base vector is random, with a random scaling factor applied to each mutant.
8484
This scaling factor is different for each mutant."""
8585

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

9090
RandomEitherOrAlgorithm = "either or"
91-
"""The base vector is randomly chosen from either a pure random mutation,
91+
"""The base vector is randomly chosen from either a pure random mutation,
9292
or a pure recombination of parent parameter values."""
9393

9494
@classmethod

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class BuildExt(build_ext):
6161
"""A custom build extension for adding compiler-specific options."""
6262

6363
c_opts = {
64-
"msvc": ["/EHsc"],
65-
"unix": ["-fopenmp", "-std=c++11"],
64+
"msvc": ["/O2", "/EHsc"],
65+
"unix": ["-O2", "-fopenmp", "-std=c++11"],
6666
}
6767
l_opts = {
6868
"msvc": [],
@@ -71,7 +71,7 @@ class BuildExt(build_ext):
7171

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

7777
def build_extensions(self):

tests/test_controls.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def table_str(self):
6060
"+---------------------+-----------+\n"
6161
"| procedure | calculate |\n"
6262
"| parallel | single |\n"
63-
"| calcSldDuringFit | False |\n"
6463
"| numSimulationPoints | 500 |\n"
6564
"| resampleMinAngle | 0.9 |\n"
6665
"| resampleNPoints | 50 |\n"
@@ -74,7 +73,6 @@ def table_str(self):
7473
"control_property, value",
7574
[
7675
("parallel", Parallel.Single),
77-
("calcSldDuringFit", False),
7876
("numSimulationPoints", 500),
7977
("resampleMinAngle", 0.9),
8078
("resampleNPoints", 50),
@@ -90,7 +88,6 @@ def test_calculate_property_values(self, control_property: str, value: Any) -> N
9088
"control_property, value",
9189
[
9290
("parallel", Parallel.Points),
93-
("calcSldDuringFit", True),
9491
("numSimulationPoints", 10),
9592
("resampleMinAngle", 0.2),
9693
("resampleNPoints", 1),
@@ -186,14 +183,6 @@ def test_calculate_parallel_validation(self, value: Any) -> None:
186183
with pytest.raises(pydantic.ValidationError, match="Input should be 'single', 'points' or 'contrasts'"):
187184
self.calculate.parallel = value
188185

189-
@pytest.mark.parametrize("value", [5.0, 12])
190-
def test_calculate_calcSldDuringFit_validation(self, value: Union[int, float]) -> None:
191-
"""Tests the calcSldDuringFit setter validation in Calculate class."""
192-
with pytest.raises(
193-
pydantic.ValidationError, match="Input should be a valid boolean, unable to interpret input"
194-
):
195-
self.calculate.calcSldDuringFit = value
196-
197186
@pytest.mark.parametrize("value", ["test", "iterate", True, 1, 3.0])
198187
def test_calculate_display_validation(self, value: Any) -> None:
199188
"""Tests the display setter validation in Calculate class."""
@@ -220,7 +209,6 @@ def table_str(self):
220209
"+---------------------+---------+\n"
221210
"| procedure | simplex |\n"
222211
"| parallel | single |\n"
223-
"| calcSldDuringFit | False |\n"
224212
"| numSimulationPoints | 500 |\n"
225213
"| resampleMinAngle | 0.9 |\n"
226214
"| resampleNPoints | 50 |\n"
@@ -240,7 +228,6 @@ def table_str(self):
240228
"control_property, value",
241229
[
242230
("parallel", Parallel.Single),
243-
("calcSldDuringFit", False),
244231
("numSimulationPoints", 500),
245232
("resampleMinAngle", 0.9),
246233
("resampleNPoints", 50),
@@ -262,7 +249,6 @@ def test_simplex_property_values(self, control_property: str, value: Any) -> Non
262249
"control_property, value",
263250
[
264251
("parallel", Parallel.Points),
265-
("calcSldDuringFit", True),
266252
("numSimulationPoints", 10),
267253
("resampleMinAngle", 0.2),
268254
("resampleNPoints", 1),
@@ -380,7 +366,6 @@ def table_str(self):
380366
"+----------------------+---------------+\n"
381367
"| procedure | de |\n"
382368
"| parallel | single |\n"
383-
"| calcSldDuringFit | False |\n"
384369
"| numSimulationPoints | 500 |\n"
385370
"| resampleMinAngle | 0.9 |\n"
386371
"| resampleNPoints | 50 |\n"
@@ -402,7 +387,6 @@ def table_str(self):
402387
"control_property, value",
403388
[
404389
("parallel", Parallel.Single),
405-
("calcSldDuringFit", False),
406390
("numSimulationPoints", 500),
407391
("resampleMinAngle", 0.9),
408392
("resampleNPoints", 50),
@@ -424,7 +408,6 @@ def test_de_property_values(self, control_property: str, value: Any) -> None:
424408
"control_property, value",
425409
[
426410
("parallel", Parallel.Points),
427-
("calcSldDuringFit", True),
428411
("numSimulationPoints", 10),
429412
("resampleMinAngle", 0.2),
430413
("resampleNPoints", 1),
@@ -556,7 +539,6 @@ def table_str(self):
556539
"+---------------------+--------+\n"
557540
"| procedure | ns |\n"
558541
"| parallel | single |\n"
559-
"| calcSldDuringFit | False |\n"
560542
"| numSimulationPoints | 500 |\n"
561543
"| resampleMinAngle | 0.9 |\n"
562544
"| resampleNPoints | 50 |\n"
@@ -574,7 +556,6 @@ def table_str(self):
574556
"control_property, value",
575557
[
576558
("parallel", Parallel.Single),
577-
("calcSldDuringFit", False),
578559
("numSimulationPoints", 500),
579560
("resampleMinAngle", 0.9),
580561
("resampleNPoints", 50),
@@ -594,7 +575,6 @@ def test_ns_property_values(self, control_property: str, value: Any) -> None:
594575
"control_property, value",
595576
[
596577
("parallel", Parallel.Points),
597-
("calcSldDuringFit", True),
598578
("numSimulationPoints", 10),
599579
("resampleMinAngle", 0.2),
600580
("resampleNPoints", 1),
@@ -725,7 +705,6 @@ def table_str(self):
725705
"+---------------------+---------+\n"
726706
"| procedure | dream |\n"
727707
"| parallel | single |\n"
728-
"| calcSldDuringFit | False |\n"
729708
"| numSimulationPoints | 500 |\n"
730709
"| resampleMinAngle | 0.9 |\n"
731710
"| resampleNPoints | 50 |\n"
@@ -745,7 +724,6 @@ def table_str(self):
745724
"control_property, value",
746725
[
747726
("parallel", Parallel.Single),
748-
("calcSldDuringFit", False),
749727
("numSimulationPoints", 500),
750728
("resampleMinAngle", 0.9),
751729
("resampleNPoints", 50),
@@ -767,7 +745,6 @@ def test_dream_property_values(self, control_property: str, value: Any) -> None:
767745
"control_property, value",
768746
[
769747
("parallel", Parallel.Points),
770-
("calcSldDuringFit", True),
771748
("numSimulationPoints", 10),
772749
("resampleMinAngle", 0.2),
773750
("resampleNPoints", 1),

0 commit comments

Comments
 (0)