Skip to content

Commit cfd8677

Browse files
committed
Add deprecation and ignores for old parameters
1 parent f5cc15f commit cfd8677

2 files changed

Lines changed: 63 additions & 14 deletions

File tree

simpeg_drivers/options.py

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@
3030
from geoh5py.objects import DrapeModel, Grid2D, Octree, Points
3131
from geoh5py.shared.utils import fetch_active_workspace
3232
from geoh5py.ui_json import InputFile
33-
from pydantic import BaseModel, ConfigDict, field_validator, model_validator
33+
from geoh5py.ui_json.annotations import Deprecated
34+
from pydantic import (
35+
AliasChoices,
36+
BaseModel,
37+
ConfigDict,
38+
Field,
39+
field_validator,
40+
model_validator,
41+
)
3442

3543
import simpeg_drivers
3644

@@ -124,7 +132,7 @@ class CoreOptions(BaseData):
124132
starting_model: float | FloatData
125133
active_cells: ActiveCellsOptions
126134
tile_spatial: int = 1
127-
n_cpu: int | None = None
135+
128136
solver_type: SolverType = SolverType.Pardiso
129137
save_sensitivities: bool = False
130138
max_chunk_size: int = 128
@@ -135,6 +143,37 @@ class CoreOptions(BaseData):
135143
n_threads: int | None = None
136144
max_ram: float | None = None
137145
performance_report: bool = False
146+
gradient_type: str = "total" # To properly deprecate in the future
147+
n_cpu: int | None = None # To properly deprecate in the future
148+
149+
# List of deprecated parameters
150+
chunk_by_rows: bool = Field(
151+
True, deprecated="Option 'chunk_by_rows' has been deprecated.", exclude=True
152+
)
153+
parallelized: bool = Field(
154+
True, deprecated="Option 'parallelized' has been deprecated.", exclude=True
155+
)
156+
ga_group: str = Field(
157+
"", deprecated="Option 'ga_group' has been deprecated.", exclude=True
158+
)
159+
z_from_topo: bool = Field(
160+
True, deprecated="Option 'z_from_topo' has been deprecated.", exclude=True
161+
)
162+
receivers_radar_drape: FloatData | None = Field(
163+
None,
164+
deprecated="Option 'receivers_radar_drape' has been deprecated.",
165+
exclude=True,
166+
)
167+
receivers_offset_z: FloatData | None = Field(
168+
None,
169+
deprecated="Option 'receivers_offset_z' has been deprecated.",
170+
exclude=True,
171+
)
172+
gps_receivers_offset: FloatData | None = Field(
173+
None,
174+
deprecated="Option 'gps_receivers_offset' has been deprecated.",
175+
exclude=True,
176+
)
138177

139178
@field_validator("mesh", mode="before")
140179
@classmethod
@@ -289,7 +328,6 @@ class BaseInversionOptions(CoreOptions):
289328
:param x_norm: X norm.
290329
:param y_norm: Y norm.
291330
:param z_norm: Z norm.
292-
:param gradient_type: Gradient type.
293331
:param max_irls_iterations: Maximum IRLS iterations.
294332
:param starting_chi_factor: Starting chi factor.
295333
@@ -315,14 +353,9 @@ class BaseInversionOptions(CoreOptions):
315353
:param solver_type: Direct solver provider. Either Mumps or Pardiso.
316354
:param tile_spatial: Tile the data spatially.
317355
:param store_sensitivities: Store sensitivities.
318-
:param max_chunk_size: Maximum chunk size.
319-
:param chunk_by_rows: Chunk by rows.
320-
321356
:param out_group: Output group.
322-
323357
:param generate_sweep: Generate sweep.
324-
325-
:param coolEpsFact: Cool eps fact.
358+
:param epsilon_cooling_factor: Cool eps fact.
326359
:param beta_search: Beta search.
327360
"""
328361

@@ -352,17 +385,25 @@ class BaseInversionOptions(CoreOptions):
352385
x_norm: float | FloatData = 2.0
353386
y_norm: float | FloatData | None = 2.0
354387
z_norm: float | FloatData = 2.0
355-
gradient_type: str = "total"
388+
356389
max_irls_iterations: int = 25
357390
starting_chi_factor: float = 1.0
358391

359392
chi_factor: float = 1.0
360393
auto_scale_misfits: bool = True
361394
initial_beta_ratio: float | None = 100.0
362395
initial_beta: float | None = None
363-
cooling_factor: float = 2.0
364396

365-
cooling_rate: int = 1
397+
cooling_factor: float = Field(
398+
2.0, validation_alias=AliasChoices("cooling_factor", "coolingFactor")
399+
)
400+
cooling_rate: int = Field(
401+
1, validation_alias=AliasChoices("cooling_rate", "coolingRate")
402+
)
403+
epsilon_cooling_factor: float = Field(
404+
1.2, validation_alias=AliasChoices("epsilon_cooling_factor", "coolEpsFact")
405+
)
406+
366407
max_global_iterations: int = 50
367408
max_line_search_iterations: int = 20
368409
max_cg_iterations: int = 30
@@ -376,8 +417,10 @@ class BaseInversionOptions(CoreOptions):
376417
store_sensitivities: str = "ram"
377418

378419
beta_tol: float = 0.5
379-
percentile: float = 95.0
380-
epsilon_cooling_factor: float = 1.2
420+
421+
percentile: float = Field(
422+
95, validation_alias=AliasChoices("percentile", "prctile")
423+
)
381424

382425
@property
383426
def gradient_dip(self) -> np.ndarray | None:

tests/uijson_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ def test_legacy_uijson(tmp_path: Path):
316316
ifile.data["data_object"] = survey
317317
ifile.data["topography_object"] = topo
318318

319+
# Test deprecated name
320+
ifile.data["coolingFactor"] = 4.0
321+
319322
if "2d" in inversion_type or "pseudo 3d" in inversion_type:
320323
line_id = geoh5.get_entity("line_ids")[0]
321324
ifile.data["line_object"] = line_id
@@ -352,6 +355,9 @@ def test_legacy_uijson(tmp_path: Path):
352355

353356
driver = InversionDriver.from_input_file(ifile)
354357

358+
if hasattr(driver.params, "cooling_factor"):
359+
assert driver.params.cooling_factor == 4.0
360+
355361
if isinstance(driver, LineSweepDriver):
356362
continue
357363

0 commit comments

Comments
 (0)