Skip to content

Commit 874da6a

Browse files
committed
[WIP] Getting the first example of InterpolationOptions serializable
1 parent e33d627 commit 874da6a

File tree

3 files changed

+61
-37
lines changed

3 files changed

+61
-37
lines changed

gempy_engine/core/data/options/evaluation_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MeshExtractionMaskingOptions(enum.Enum):
1414
class EvaluationOptions:
1515
_number_octree_levels: int = 1
1616
_number_octree_levels_surface: int = 4
17-
octree_curvature_threshold: float = -1 #: Threshold to do octree refinement due to curvature to deal with angular geometries. This curvature assumes that 1 is the maximum curvature of any voxel
17+
octree_curvature_threshold: float = -1. #: Threshold to do octree refinement due to curvature to deal with angular geometries. This curvature assumes that 1 is the maximum curvature of any voxel
1818
octree_error_threshold: float = 1. #: Number of standard deviations to consider a voxel as candidate to refine
1919
octree_min_level: int = 2
2020

gempy_engine/core/data/options/interpolation_options.py

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import enum
22
import warnings
3-
from dataclasses import dataclass, asdict, field
3+
4+
from pydantic import BaseModel, ConfigDict, Field, model_validator, PrivateAttr
45

56
import gempy_engine.config
67
from .evaluation_options import MeshExtractionMaskingOptions, EvaluationOptions
@@ -10,40 +11,46 @@
1011
from ..raw_arrays_solution import RawArraysSolution
1112

1213

13-
@dataclass
14-
class InterpolationOptions:
15-
__slots__ = ['kernel_options', 'evaluation_options', 'temp_interpolation_values', 'debug',
16-
'cache_mode', 'cache_model_name', 'block_solutions_type', 'sigmoid_slope']
17-
14+
class InterpolationOptions(BaseModel):
1815
class CacheMode(enum.Enum):
1916
""" Cache mode for the interpolation"""
2017
NO_CACHE: int = enum.auto() #: No cache at all even during the interpolation computation. This is quite expensive for no good reason.
2118
CACHE = enum.auto()
2219
IN_MEMORY_CACHE = enum.auto()
2320
CLEAR_CACHE = enum.auto()
2421

22+
model_config = ConfigDict(
23+
arbitrary_types_allowed=False,
24+
use_enum_values=False,
25+
json_encoders={
26+
CacheMode: lambda e: e.value
27+
}
28+
)
29+
2530
# @off
26-
kernel_options: KernelOptions # * This is the compression of the fields above and the way to go in the future
27-
evaluation_options: EvaluationOptions
28-
temp_interpolation_values: TempInterpolationValues
31+
kernel_options: KernelOptions = Field(init=True) # * This is the compression of the fields above and the way to go in the future
32+
evaluation_options: EvaluationOptions = Field(init=True)
2933

3034
debug: bool
3135
cache_mode: CacheMode
3236
cache_model_name: str # : Model name for the cache
33-
3437
block_solutions_type: RawArraysSolution.BlockSolutionType
35-
3638
sigmoid_slope: int
37-
3839
debug_water_tight: bool = False
3940

40-
def __init__(
41-
self,
41+
# region Volatile
42+
_temp_interpolation_values: TempInterpolationValues = PrivateAttr(default_factory=TempInterpolationValues)
43+
44+
# endregion
45+
46+
@classmethod
47+
def from_args(
48+
cls,
4249
range: int | float,
4350
c_o: float,
4451
uni_degree: int = 1,
45-
i_res: float = 4,
46-
gi_res: float = 2, # ! This should be DEP
52+
i_res: float = 4.,
53+
gi_res: float = 2., # ! This should be DEP
4754
number_dimensions: int = 3, # ? This probably too
4855
number_octree_levels: int = 1,
4956
kernel_function: AvailableKernelFunctions = AvailableKernelFunctions.cubic,
@@ -52,7 +59,7 @@ def __init__(
5259
compute_condition_number: bool = False,
5360
):
5461

55-
self.kernel_options = KernelOptions(
62+
kernel_options = KernelOptions(
5663
range=range,
5764
c_o=c_o,
5865
uni_degree=uni_degree,
@@ -63,7 +70,7 @@ def __init__(
6370
compute_condition_number=compute_condition_number
6471
)
6572

66-
self.evaluation_options = EvaluationOptions(
73+
evaluation_options = EvaluationOptions(
6774
_number_octree_levels=number_octree_levels,
6875
_number_octree_levels_surface=4,
6976
mesh_extraction=mesh_extraction,
@@ -73,12 +80,24 @@ def __init__(
7380

7481
)
7582

76-
self.temp_interpolation_values = TempInterpolationValues()
77-
self.debug = gempy_engine.config.DEBUG_MODE
78-
self.cache_mode = InterpolationOptions.CacheMode.IN_MEMORY_CACHE
79-
self.cache_model_name = ""
80-
self.block_solutions_type = RawArraysSolution.BlockSolutionType.OCTREE
81-
self.sigmoid_slope = 5_000_000
83+
temp_interpolation_values = TempInterpolationValues()
84+
debug = gempy_engine.config.DEBUG_MODE
85+
cache_mode = InterpolationOptions.CacheMode.IN_MEMORY_CACHE
86+
cache_model_name = ""
87+
block_solutions_type = RawArraysSolution.BlockSolutionType.OCTREE
88+
sigmoid_slope = 5_000_000
89+
90+
return InterpolationOptions(
91+
kernel_options=kernel_options,
92+
evaluation_options=evaluation_options,
93+
# temp_interpolation_values=temp_interpolation_values,
94+
debug=debug,
95+
cache_mode=cache_mode,
96+
cache_model_name=cache_model_name,
97+
block_solutions_type=block_solutions_type,
98+
sigmoid_slope=sigmoid_slope,
99+
debug_water_tight=False,
100+
)
82101

83102
# @on
84103

@@ -107,17 +126,17 @@ def probabilistic_options(cls):
107126
# TODO: This should have the sigmoid slope different
108127
raise NotImplementedError("Probabilistic interpolation is not yet implemented.")
109128

110-
def __repr__(self):
111-
return f"InterpolationOptions({', '.join(f'{k}={v}' for k, v in asdict(self).items())})"
129+
# def __repr__(self):
130+
# return f"InterpolationOptions({', '.join(f'{k}={v}' for k, v in asdict(self).items())})"
112131

113-
def _repr_html_(self):
114-
html = f"""
115-
<table>
116-
<tr><td colspan='2' style='text-align:center'><b>InterpolationOptions</b></td></tr>
117-
{''.join(f'<tr><td>{k}</td><td>{v._repr_html_() if isinstance(v, KernelOptions) else v}</td></tr>' for k, v in asdict(self).items())}
118-
</table>
119-
"""
120-
return html
132+
# def _repr_html_(self):
133+
# html = f"""
134+
# <table>
135+
# <tr><td colspan='2' style='text-align:center'><b>InterpolationOptions</b></td></tr>
136+
# {''.join(f'<tr><td>{k}</td><td>{v._repr_html_() if isinstance(v, KernelOptions) else v}</td></tr>' for k, v in asdict(self).items())}
137+
# </table>
138+
# """
139+
# return html
121140

122141
def update_options(self, **kwargs):
123142
"""
@@ -147,6 +166,10 @@ def update_options(self, **kwargs):
147166
else:
148167
warnings.warn(f"{key} is not a recognized attribute and will be ignored.")
149168

169+
@property
170+
def temp_interpolation_values(self):
171+
return self._temp_interpolation_values
172+
150173
@property
151174
def number_octree_levels(self):
152175
return self.evaluation_options.number_octree_levels

gempy_engine/core/data/options/kernel_options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import warnings
22

33
from dataclasses import dataclass, asdict
4+
from typing import Optional
45

56
from gempy_engine.core.data.kernel_classes.kernel_functions import AvailableKernelFunctions
67
from gempy_engine.core.data.kernel_classes.solvers import Solvers
78

89

910
@dataclass(frozen=False)
1011
class KernelOptions:
11-
range: int # TODO: have constructor from RegularGrid
12+
range: int | float # TODO: have constructor from RegularGrid
1213
c_o: float # TODO: This should be a property
1314
uni_degree: int = 1
1415
i_res: float = 4.
@@ -20,7 +21,7 @@ class KernelOptions:
2021

2122
compute_condition_number: bool = False
2223
optimizing_condition_number: bool = False
23-
condition_number: float = None
24+
condition_number: Optional[float] = None
2425

2526
@property
2627
def n_uni_eq(self):

0 commit comments

Comments
 (0)