Skip to content

Commit 57072cb

Browse files
authored
Merge pull request #1026 from gempy-project/model_serialize
[ENH] Replace InterpolationOptions constructor with from_args method for serialization
2 parents 61b804b + 4e8a196 commit 57072cb

File tree

7 files changed

+50
-5
lines changed

7 files changed

+50
-5
lines changed

docs/developers_notes/dev_log/2025_05.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,25 @@
55

66
# TODO:
77
-[ ] Saving and loading models
8+
- [ ] Make tests passing for InterpOptions serializable
9+
- [ ] Try to make BaseModel dirctly to StructuralFrame
10+
- [ ] Try to make Serializable directly to Grid
811
-[ ] Better api for nugget effect optimization
912

13+
## Saving models
14+
- From gempy
15+
- StructuralFrame
16+
- OrientationsTable
17+
- SurfacePointsTable
18+
- From Engine
19+
- Input
20+
- EngineGrid
21+
- GeophysicsInput
22+
- InterpolationOptions
23+
- InputDataDescriptor
24+
- InterpolatorInput
25+
- Solutions (Not sure if I want to save them)
26+
- RawArraysSolutions
27+
- Solutions
28+
29+
## What do I have in the engine server logic?

examples/examples/real/mik.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
extent=[extent_from_data[0][0], extent_from_data[1][0], extent_from_data[0][1], extent_from_data[1][1], extent_from_data[0][2], extent_from_data[1][2]],
313313
resolution=(50, 50, 50)
314314
),
315-
interpolation_options=gp.data.InterpolationOptions(
315+
interpolation_options=gp.data.InterpolationOptions.from_args(
316316
range=5,
317317
c_o=10,
318318
mesh_extraction=True,

gempy/modules/json_io/json_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def load_model_from_json(file_path: str):
155155
default_range = 1.7 # Match standard GemPy default
156156

157157
# Create interpolation options with defaults if not provided
158-
interpolation_options = InterpolationOptions(
158+
interpolation_options = InterpolationOptions.from_args(
159159
range=data.get('interpolation_options', {}).get('kernel_options', {}).get('range', default_range),
160160
c_o=data.get('interpolation_options', {}).get('kernel_options', {}).get('c_o', 10),
161161
mesh_extraction=data.get('interpolation_options', {}).get('mesh_extraction', True),

requirements/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# This install also numpy
2-
gempy_engine~=2025.1.1
2+
gempy_engine>=2025.2.0dev0,<2025.3.0

test/test_api/test_model_construction_granular.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_create_structural_frame() -> StructuralFrame:
9494

9595
def test_create_interpolation_options() -> InterpolationOptions:
9696
range_ = 1000.0
97-
interpolation_options: InterpolationOptions = InterpolationOptions(
97+
interpolation_options: InterpolationOptions = InterpolationOptions.from_args(
9898
range=range_,
9999
c_o=(range_ ** 2) / 14 / 3,
100100
)

test/test_modules/test_pile/test_stratigraphic_pile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_structural_elements_from_borehole_set(self, borehole_set: BoreholeSet):
129129
extent=[extent_from_data[0][0], extent_from_data[1][0], extent_from_data[0][1], extent_from_data[1][1], extent_from_data[0][2], extent_from_data[1][2]],
130130
resolution=(50, 50, 50)
131131
),
132-
interpolation_options=gp.data.InterpolationOptions(
132+
interpolation_options=gp.data.InterpolationOptions.from_args(
133133
range=5,
134134
c_o=10,
135135
mesh_extraction=True,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pprint
2+
3+
import gempy as gp
4+
from gempy.core.data.enumerators import ExampleModel
5+
from gempy_engine.core.data import InterpolationOptions
6+
7+
8+
def test_generate_horizontal_stratigraphic_model():
9+
model: gp.data.GeoModel = gp.generate_example_model(ExampleModel.HORIZONTAL_STRAT, compute_model=False)
10+
print(model.structural_frame)
11+
options: InterpolationOptions = model.interpolation_options
12+
pass
13+
14+
def test_interpolation_options():
15+
options = InterpolationOptions.from_args(
16+
range=1.7,
17+
c_o=10.
18+
)
19+
json = options.model_dump(mode="json")
20+
# Pretty print json
21+
pprint.pp(json)
22+
23+
# Deserialize with pydantic
24+
options2 = InterpolationOptions.model_validate(json)
25+
assert options.__str__() == options2.__str__()

0 commit comments

Comments
 (0)