Skip to content

Commit a1615b5

Browse files
committed
[BUG] Improve computation timestamp handling and fix uninitialized WeightCache issues
1 parent 2ac86a4 commit a1615b5

File tree

4 files changed

+61
-48
lines changed

4 files changed

+61
-48
lines changed

gempy_engine/API/interp_single/_interp_scalar_field.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ def interpolate_scalar_field(solver_input: SolverInput, options: InterpolationOp
2929
key=weights_key,
3030
look_in_disk= not options.cache_mode == InterpolationOptions.CacheMode.IN_MEMORY_CACHE
3131
)
32+
ts = options.temp_interpolation_values.start_computation_ts
33+
if ts == -1:
34+
raise ValueError("ts not set")
35+
3236
weights_hash = generate_cache_key(
3337
name="",
3438
parameters={
35-
"ts": options.temp_interpolation_values.start_computation_ts
39+
"ts": ts
3640
}
3741
)
3842
case InterpolationOptions.CacheMode.CLEAR_CACHE:

gempy_engine/API/model/model_api.py

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,58 +23,63 @@
2323
def compute_model(interpolation_input: InterpolationInput, options: InterpolationOptions,
2424
data_descriptor: InputDataDescriptor, *, geophysics_input: Optional[GeophysicsInput] = None) -> Solutions:
2525

26-
WeightCache.initialize_cache_dir()
27-
options.temp_interpolation_values.start_computation_ts = int(time.time())
28-
29-
# ! If we inline this it seems the deepcopy does not work
30-
if BackendTensor.engine_backend is not AvailableBackends.PYTORCH and NOT_MAKE_INPUT_DEEP_COPY is False:
31-
interpolation_input = copy.deepcopy(interpolation_input)
26+
try:
27+
WeightCache.initialize_cache_dir()
28+
options.temp_interpolation_values.start_computation_ts = int(time.time())
3229

33-
# Check input is valid
34-
_check_input_validity(interpolation_input, options, data_descriptor)
35-
36-
output: list[OctreeLevel] = interpolate_n_octree_levels(
37-
interpolation_input=interpolation_input,
38-
options=options,
39-
data_descriptor=data_descriptor
40-
)
41-
# region Geophysics
42-
# ---------------------
43-
# TODO: [x] Gravity
44-
# TODO: [ ] Magnetics
45-
46-
if geophysics_input is not None:
47-
first_level_last_field: InterpOutput = output[0].outputs_centers[-1]
48-
gravity = compute_gravity(
49-
geophysics_input=geophysics_input,
50-
root_ouput=first_level_last_field
51-
)
52-
else:
53-
gravity = None
54-
55-
# endregion
30+
# ! If we inline this it seems the deepcopy does not work
31+
if BackendTensor.engine_backend is not AvailableBackends.PYTORCH and NOT_MAKE_INPUT_DEEP_COPY is False:
32+
interpolation_input = copy.deepcopy(interpolation_input)
33+
34+
# Check input is valid
35+
_check_input_validity(interpolation_input, options, data_descriptor)
5636

57-
meshes: Optional[list[DualContouringMesh]] = None
58-
if options.mesh_extraction:
59-
if interpolation_input.grid.octree_grid is None:
60-
raise ValueError("Octree grid must be defined to extract the mesh")
61-
62-
meshes: list[DualContouringMesh] = dual_contouring_multi_scalar(
63-
data_descriptor=data_descriptor,
37+
output: list[OctreeLevel] = interpolate_n_octree_levels(
6438
interpolation_input=interpolation_input,
6539
options=options,
66-
octree_list=output[:options.number_octree_levels_surface]
40+
data_descriptor=data_descriptor
6741
)
42+
# region Geophysics
43+
# ---------------------
44+
# TODO: [x] Gravity
45+
# TODO: [ ] Magnetics
46+
47+
if geophysics_input is not None:
48+
first_level_last_field: InterpOutput = output[0].outputs_centers[-1]
49+
gravity = compute_gravity(
50+
geophysics_input=geophysics_input,
51+
root_ouput=first_level_last_field
52+
)
53+
else:
54+
gravity = None
55+
56+
# endregion
6857

69-
solutions = Solutions(
70-
octrees_output=output,
71-
dc_meshes=meshes,
72-
fw_gravity=gravity,
73-
block_solution_type=options.block_solutions_type
74-
)
58+
meshes: Optional[list[DualContouringMesh]] = None
59+
if options.mesh_extraction:
60+
if interpolation_input.grid.octree_grid is None:
61+
raise ValueError("Octree grid must be defined to extract the mesh")
62+
63+
meshes: list[DualContouringMesh] = dual_contouring_multi_scalar(
64+
data_descriptor=data_descriptor,
65+
interpolation_input=interpolation_input,
66+
options=options,
67+
octree_list=output[:options.number_octree_levels_surface]
68+
)
69+
70+
solutions = Solutions(
71+
octrees_output=output,
72+
dc_meshes=meshes,
73+
fw_gravity=gravity,
74+
block_solution_type=options.block_solutions_type
75+
)
7576

76-
if options.debug:
77-
solutions.debug_input_data["stack_interpolation_input"] = interpolation_input
77+
if options.debug:
78+
solutions.debug_input_data["stack_interpolation_input"] = interpolation_input
79+
except Exception as e:
80+
raise e
81+
finally:
82+
options.temp_interpolation_values.start_computation_ts = -1
7883

7984
return solutions
8085

tests/fixtures/complex_geometries.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
@pytest.fixture(scope="session")
2323
def one_fault_model():
24-
from gempy_engine.modules.weights_cache.weights_cache_interface import WeightCache
25-
WeightCache.initialize_cache_dir()
2624
centers = np.array([500, 500, -550])
2725
rescaling_factor = 240
2826

tests/test_common/test_api/test_faults/test_one_fault.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def test_one_fault_model_thickness(one_fault_model, n_oct_levels=2):
107107

108108

109109
def test_one_fault_model_finite_fault(one_fault_model, n_oct_levels=4):
110+
from gempy_engine.modules.weights_cache.weights_cache_interface import WeightCache
111+
WeightCache.initialize_cache_dir()
112+
110113
interpolation_input: InterpolationInput
111114
structure: InputDataDescriptor
112115
options: InterpolationOptions
@@ -171,6 +174,9 @@ def test_one_fault_model_finite_fault(one_fault_model, n_oct_levels=4):
171174

172175

173176
def test_implicit_ellipsoid_projection_on_fault(one_fault_model):
177+
from gempy_engine.modules.weights_cache.weights_cache_interface import WeightCache
178+
WeightCache.initialize_cache_dir()
179+
174180
interpolation_input: InterpolationInput
175181
structure: InputDataDescriptor
176182
options: InterpolationOptions

0 commit comments

Comments
 (0)