Skip to content

Commit c9b0c5d

Browse files
committed
added docstrings to controls and project fields
1 parent 78626fe commit c9b0c5d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

RATapi/controls.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import prettytable
77
from pydantic import (
88
BaseModel,
9+
ConfigDict,
910
Field,
1011
ValidationError,
1112
ValidatorFunctionWrapHandler,
@@ -39,40 +40,70 @@
3940
class Controls(BaseModel, validate_assignment=True, extra="forbid"):
4041
"""The full set of controls parameters for all five procedures that are required for the compiled RAT code."""
4142

43+
model_config = ConfigDict(use_attribute_docstrings=True)
44+
4245
# All Procedures
4346
procedure: Procedures = Procedures.Calculate
47+
"""Which procedure RAT should execute. Can be 'calculate', 'simplex', 'de', 'ns', or 'dream'."""
4448
parallel: Parallel = Parallel.Single
49+
"""How the calculation should be parallelised. Can be 'single', 'contrasts' or 'points'."""
4550
calcSldDuringFit: bool = False
51+
"""Whether SLD will be calculated during fit (for live plotting etc.)"""
4652
resampleMinAngle: float = Field(0.9, le=1, gt=0)
53+
"""The upper threshold on the angle between three sampled points for resampling, in radians over pi."""
4754
resampleNPoints: int = Field(50, gt=0)
55+
"""The number of initial points to use for resampling."""
4856
display: Display = Display.Iter
57+
"""How much RAT should print to the terminal. Can be 'off', 'iter', 'notify', or 'final'."""
4958
# Simplex
5059
xTolerance: float = Field(1.0e-6, gt=0.0)
60+
"""[SIMPLEX] The termination tolerance for step size."""
5161
funcTolerance: float = Field(1.0e-6, gt=0.0)
62+
"""[SIMPLEX] The termination tolerance for change in chi-squared."""
5263
maxFuncEvals: int = Field(10000, gt=0)
64+
"""[SIMPLEX] The maximum number of function evaluations before the algorithm terminates."""
5365
maxIterations: int = Field(1000, gt=0)
66+
"""[SIMPLEX] The maximum number of iterations before the algorithm terminates."""
5467
# Simplex and DE
5568
updateFreq: int = 1
69+
"""[SIMPLEX, DE] How often to print out progress to the terminal, in iterations."""
5670
updatePlotFreq: int = 20
71+
"""[SIMPLEX, DE] How often the live plot should be updated if using."""
5772
# DE
5873
populationSize: int = Field(20, ge=1)
74+
"""[DE] The number of candidate solutions that exist at any time."""
5975
fWeight: float = 0.5
76+
"""[DE] The step size for how different mutations are to their parents."""
6077
crossoverProbability: float = Field(0.8, gt=0.0, lt=1.0)
78+
"""[DE] The probability of exchange of parameters between individuals at any iteration."""
6179
strategy: Strategies = Strategies.RandomWithPerVectorDither
80+
"""[DE] The algorithm used to generate new candidates."""
6281
targetValue: float = Field(1.0, ge=1.0)
82+
"""[DE] The value of chi-squared at which the algorithm will terminate."""
6383
numGenerations: int = Field(500, ge=1)
84+
"""[DE] The maximum number of iterations before the algorithm terminates."""
6485
# NS
6586
nLive: int = Field(150, ge=1)
87+
"""[NS] The number of points to sample."""
6688
nMCMC: int = Field(0, ge=0)
89+
"""[NS] If non-zero, an MCMC process with ``nMCMC`` chains will be used instead of MultiNest."""
6790
propScale: float = Field(0.1, gt=0.0, lt=1.0)
91+
"""[NS] A scaling factor for the ellipsoid generated by MultiNest."""
6892
nsTolerance: float = Field(0.1, ge=0.0)
93+
"""[NS] The tolerance threshold for when the algorithm should terminate."""
6994
# Dream
7095
nSamples: int = Field(20000, ge=0)
96+
"""[DREAM] The number of samples in the initial population for each chain."""
7197
nChains: int = Field(10, gt=0)
98+
"""[DREAM] The number of Markov chains to use in the algorithm."""
7299
jumpProbability: float = Field(0.5, gt=0.0, lt=1.0)
100+
"""[DREAM] The probability range for the size of jumps in sampling. Larger values mean more variable jumps."""
73101
pUnitGamma: float = Field(0.2, gt=0.0, lt=1.0)
102+
"""[DREAM] The probability that the scaling-down factor of jumps will be ignored and a larger jump will be taken."""
74103
boundHandling: BoundHandling = BoundHandling.Reflect
104+
"""[DREAM] How steps past the space boundaries should be handled. Can be 'off', 'reflect', 'bound', or 'fold'."""
75105
adaptPCR: bool = True
106+
"""[DREAM] Whether the crossover probability for differential evolution should be adapted during the run."""
76107
# Private field for IPC file
77108
_IPCFilePath: str = ""
78109

RATapi/project.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import numpy as np
1212
from pydantic import (
1313
BaseModel,
14+
ConfigDict,
1415
Discriminator,
1516
Field,
1617
Tag,
@@ -130,13 +131,21 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
130131
inputs required for a reflectivity calculation.
131132
"""
132133

134+
model_config = ConfigDict(use_attribute_docstrings=True)
135+
133136
name: str = ""
137+
"""The name of the project."""
134138
calculation: Calculations = Calculations.Normal
139+
"""What calculation type should be used. Can be 'normal' or 'domains'."""
135140
model: LayerModels = LayerModels.StandardLayers
141+
"""What layer model should be used. Can be 'standard layers', 'custom layers', or 'custom xy'."""
136142
geometry: Geometries = Geometries.AirSubstrate
143+
"""What geometry should be used. Can be 'air/substrate' or 'substrate/liquid'"""
137144
absorption: bool = False
145+
"""Whether imaginary (absorption) SLD should be accounted for."""
138146

139147
parameters: ClassList[RATapi.models.Parameter] = ClassList()
148+
"""The list of parameters used in the layers of a model."""
140149

141150
bulk_in: ClassList[RATapi.models.Parameter] = ClassList(
142151
RATapi.models.Parameter(
@@ -150,6 +159,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
150159
sigma=np.inf,
151160
),
152161
)
162+
"""The parameters for SLD of the entry interfaces of a model."""
153163

154164
bulk_out: ClassList[RATapi.models.Parameter] = ClassList(
155165
RATapi.models.Parameter(
@@ -163,6 +173,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
163173
sigma=np.inf,
164174
),
165175
)
176+
"""The parameters for SLD of the exit interfaces of a model."""
166177

167178
scalefactors: ClassList[RATapi.models.Parameter] = ClassList(
168179
RATapi.models.Parameter(
@@ -176,6 +187,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
176187
sigma=np.inf,
177188
),
178189
)
190+
"""The parameters for scale factors to handle systematic error in model data."""
179191

180192
domain_ratios: ClassList[RATapi.models.Parameter] = ClassList(
181193
RATapi.models.Parameter(
@@ -189,6 +201,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
189201
sigma=np.inf,
190202
),
191203
)
204+
"""The parameters for weighting between domains of a domains model."""
192205

193206
background_parameters: ClassList[RATapi.models.Parameter] = ClassList(
194207
RATapi.models.Parameter(
@@ -202,10 +215,12 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
202215
sigma=np.inf,
203216
),
204217
)
218+
"""The parameters for models of backgrounds."""
205219

206220
backgrounds: ClassList[RATapi.models.Background] = ClassList(
207221
RATapi.models.Background(name="Background 1", type=TypeOptions.Constant, source="Background Param 1"),
208222
)
223+
"""The models for background noise in the project."""
209224

210225
resolution_parameters: ClassList[RATapi.models.Parameter] = ClassList(
211226
RATapi.models.Parameter(
@@ -219,13 +234,17 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
219234
sigma=np.inf,
220235
),
221236
)
237+
"""The parameters for models of resolutions."""
222238

223239
resolutions: ClassList[RATapi.models.Resolution] = ClassList(
224240
RATapi.models.Resolution(name="Resolution 1", type=TypeOptions.Constant, source="Resolution Param 1"),
225241
)
242+
"""The models for instrument resolution in the project."""
226243

227244
custom_files: ClassList[RATapi.models.CustomFile] = ClassList()
245+
"""Handles for custom files used by the project."""
228246
data: ClassList[RATapi.models.Data] = ClassList()
247+
"""Arrays of experimental data corresponding to a model."""
229248
layers: Union[
230249
Annotated[ClassList[RATapi.models.Layer], Tag("no_abs")],
231250
Annotated[ClassList[RATapi.models.AbsorptionLayer], Tag("abs")],
@@ -238,7 +257,9 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
238257
custom_error_context={"discriminator": "absorption_or_no"},
239258
),
240259
)
260+
"""The layers of a standard layer model."""
241261
domain_contrasts: ClassList[RATapi.models.DomainContrast] = ClassList()
262+
"""The groups of layers required by each domain in a domains model."""
242263
contrasts: Union[
243264
Annotated[ClassList[RATapi.models.Contrast], Tag("no_ratio")],
244265
Annotated[ClassList[RATapi.models.ContrastWithRatio], Tag("ratio")],
@@ -251,6 +272,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
251272
custom_error_context={"discriminator": "ratio_or_no_ratio"},
252273
),
253274
)
275+
"""All groups of components used to define each model in the project."""
254276

255277
_all_names: dict
256278
_contrast_model_field: str

0 commit comments

Comments
 (0)