Skip to content

Commit 73a948a

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

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

RATapi/controls.py

Lines changed: 30 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,
@@ -38,41 +39,70 @@
3839

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."""
42+
model_config = ConfigDict(use_attribute_docstrings=True)
4143

4244
# All Procedures
4345
procedure: Procedures = Procedures.Calculate
46+
"""Which procedure RAT should execute. Can be 'calculate', 'simplex', 'de', 'ns', or 'dream'."""
4447
parallel: Parallel = Parallel.Single
48+
"""How the calculation should be parallelised. Can be 'single', 'contrasts' or 'points'."""
4549
calcSldDuringFit: bool = False
50+
"""Whether SLD will be calculated during fit (for live plotting etc.)"""
4651
resampleMinAngle: float = Field(0.9, le=1, gt=0)
52+
"""The upper threshold on the angle between three sampled points for resampling, in radians over pi."""
4753
resampleNPoints: int = Field(50, gt=0)
54+
"""The number of initial points to use for resampling."""
4855
display: Display = Display.Iter
56+
"""How much RAT should print to the terminal. Can be 'off', 'iter', 'notify', or 'final'."""
4957
# Simplex
5058
xTolerance: float = Field(1.0e-6, gt=0.0)
59+
"""The termination tolerance for step size."""
5160
funcTolerance: float = Field(1.0e-6, gt=0.0)
61+
"""The termination tolerance for change in chi-squared."""
5262
maxFuncEvals: int = Field(10000, gt=0)
63+
"""The maximum number of function evaluations before the algorithm terminates."""
5364
maxIterations: int = Field(1000, gt=0)
65+
"""The maximum number of iterations before the algorithm terminates."""
5466
# Simplex and DE
5567
updateFreq: int = 1
68+
"""How often to print out progress to the terminal, in iterations."""
5669
updatePlotFreq: int = 20
70+
"""How often the live plot should be updated if using."""
5771
# DE
5872
populationSize: int = Field(20, ge=1)
73+
"""The number of candidate solutions that exist at any time."""
5974
fWeight: float = 0.5
75+
"""The step size for how different mutations are to their parents."""
6076
crossoverProbability: float = Field(0.8, gt=0.0, lt=1.0)
77+
"""The probability of exchange of parameters between individuals at any iteration."""
6178
strategy: Strategies = Strategies.RandomWithPerVectorDither
79+
"""The algorithm used to generate new candidates."""
6280
targetValue: float = Field(1.0, ge=1.0)
81+
"""The value of chi-squared at which the algorithm will terminate."""
6382
numGenerations: int = Field(500, ge=1)
83+
"""The maximum number of iterations before the algorithm terminates."""
6484
# NS
6585
nLive: int = Field(150, ge=1)
86+
"""The number of points to sample."""
6687
nMCMC: int = Field(0, ge=0)
88+
"""If non-zero, an MCMC process with ``nMCMC`` chains will be used instead of MultiNest."""
6789
propScale: float = Field(0.1, gt=0.0, lt=1.0)
90+
"""A scaling factor for the ellipsoid generated by MultiNest."""
6891
nsTolerance: float = Field(0.1, ge=0.0)
92+
"""The tolerance threshold for when the algorithm should terminate."""
6993
# Dream
7094
nSamples: int = Field(20000, ge=0)
95+
"""The number of samples in the initial population for each chain."""
7196
nChains: int = Field(10, gt=0)
97+
"""The number of Markov chains to use in the algorithm."""
7298
jumpProbability: float = Field(0.5, gt=0.0, lt=1.0)
99+
"""The probability range for the size of jumps in sampling. Larger values mean more variable jumps."""
73100
pUnitGamma: float = Field(0.2, gt=0.0, lt=1.0)
101+
"""The probability that the scaling-down factor of jumps will be ignored and a larger jump will be taken."""
74102
boundHandling: BoundHandling = BoundHandling.Reflect
103+
"""How steps across the boundary of the space should be handled. Can be 'off', 'reflect', 'bound', or 'fold'."""
75104
adaptPCR: bool = True
105+
"""Whether the crossover probability for differential evolution should be adapted by the algorithm as it runs."""
76106
# Private field for IPC file
77107
_IPCFilePath: str = ""
78108

RATapi/project.py

Lines changed: 21 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,
@@ -129,14 +130,21 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
129130
This class combines the data defined in each of the pydantic models included in "models.py" into the full set of
130131
inputs required for a reflectivity calculation.
131132
"""
133+
model_config = ConfigDict(use_attribute_docstrings=True)
132134

133135
name: str = ""
136+
"""The name of the project."""
134137
calculation: Calculations = Calculations.Normal
138+
"""What calculation type should be used. Can be 'normal' or 'domains'."""
135139
model: LayerModels = LayerModels.StandardLayers
140+
"""What layer model should be used. Can be 'standard layers', 'custom layers', or 'custom xy'."""
136141
geometry: Geometries = Geometries.AirSubstrate
142+
"""What geometry should be used. Can be 'air/substrate' or 'substrate/liquid'"""
137143
absorption: bool = False
144+
"""Whether imaginary (absorption) SLD should be accounted for."""
138145

139146
parameters: ClassList[RATapi.models.Parameter] = ClassList()
147+
"""The list of parameters used in the layers of a model."""
140148

141149
bulk_in: ClassList[RATapi.models.Parameter] = ClassList(
142150
RATapi.models.Parameter(
@@ -150,6 +158,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
150158
sigma=np.inf,
151159
),
152160
)
161+
"""The parameters for SLD of the entry interfaces of a model."""
153162

154163
bulk_out: ClassList[RATapi.models.Parameter] = ClassList(
155164
RATapi.models.Parameter(
@@ -163,6 +172,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
163172
sigma=np.inf,
164173
),
165174
)
175+
"""The parameters for SLD of the exit interfaces of a model."""
166176

167177
scalefactors: ClassList[RATapi.models.Parameter] = ClassList(
168178
RATapi.models.Parameter(
@@ -176,6 +186,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
176186
sigma=np.inf,
177187
),
178188
)
189+
"""The parameters for scale factors to handle systematic error in model data."""
179190

180191
domain_ratios: ClassList[RATapi.models.Parameter] = ClassList(
181192
RATapi.models.Parameter(
@@ -189,6 +200,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
189200
sigma=np.inf,
190201
),
191202
)
203+
"""The parameters for weighting between domains of a domains model."""
192204

193205
background_parameters: ClassList[RATapi.models.Parameter] = ClassList(
194206
RATapi.models.Parameter(
@@ -202,10 +214,12 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
202214
sigma=np.inf,
203215
),
204216
)
217+
"""The parameters for models of backgrounds."""
205218

206219
backgrounds: ClassList[RATapi.models.Background] = ClassList(
207220
RATapi.models.Background(name="Background 1", type=TypeOptions.Constant, source="Background Param 1"),
208221
)
222+
"""The models for background noise in the project."""
209223

210224
resolution_parameters: ClassList[RATapi.models.Parameter] = ClassList(
211225
RATapi.models.Parameter(
@@ -219,13 +233,17 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
219233
sigma=np.inf,
220234
),
221235
)
236+
"""The parameters for models of resolutions."""
222237

223238
resolutions: ClassList[RATapi.models.Resolution] = ClassList(
224239
RATapi.models.Resolution(name="Resolution 1", type=TypeOptions.Constant, source="Resolution Param 1"),
225240
)
241+
"""The models for instrument resolution in the project."""
226242

227243
custom_files: ClassList[RATapi.models.CustomFile] = ClassList()
244+
"""Handles for custom files used by the project."""
228245
data: ClassList[RATapi.models.Data] = ClassList()
246+
"""Arrays of experimental data corresponding to a model."""
229247
layers: Union[
230248
Annotated[ClassList[RATapi.models.Layer], Tag("no_abs")],
231249
Annotated[ClassList[RATapi.models.AbsorptionLayer], Tag("abs")],
@@ -238,7 +256,9 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
238256
custom_error_context={"discriminator": "absorption_or_no"},
239257
),
240258
)
259+
"""The layers of a standard layer model."""
241260
domain_contrasts: ClassList[RATapi.models.DomainContrast] = ClassList()
261+
"""The groups of layers required by each domain in a domains model."""
242262
contrasts: Union[
243263
Annotated[ClassList[RATapi.models.Contrast], Tag("no_ratio")],
244264
Annotated[ClassList[RATapi.models.ContrastWithRatio], Tag("ratio")],
@@ -251,6 +271,7 @@ class Project(BaseModel, validate_assignment=True, extra="forbid"):
251271
custom_error_context={"discriminator": "ratio_or_no_ratio"},
252272
),
253273
)
274+
"""All groups of components used to define each model in the project."""
254275

255276
_all_names: dict
256277
_contrast_model_field: str

0 commit comments

Comments
 (0)