|
| 1 | +import time |
1 | 2 | import copy |
2 | 3 | from typing import List, Optional |
3 | 4 |
|
|
15 | 16 | from ...core.data.input_data_descriptor import InputDataDescriptor |
16 | 17 | from ...core.data.interpolation_input import InterpolationInput |
17 | 18 | from ...core.utils import gempy_profiler_decorator |
18 | | - |
19 | | - |
| 19 | +from ...modules.weights_cache.weights_cache_interface import WeightCache |
20 | 20 |
|
21 | 21 |
|
22 | 22 | @gempy_profiler_decorator |
23 | 23 | def compute_model(interpolation_input: InterpolationInput, options: InterpolationOptions, |
24 | 24 | data_descriptor: InputDataDescriptor, *, geophysics_input: Optional[GeophysicsInput] = None) -> Solutions: |
25 | 25 |
|
26 | | - # ! If we inline this it seems the deepcopy does not work |
27 | | - if BackendTensor.engine_backend is not AvailableBackends.PYTORCH and NOT_MAKE_INPUT_DEEP_COPY is False: |
28 | | - interpolation_input = copy.deepcopy(interpolation_input) |
| 26 | + try: |
| 27 | + WeightCache.initialize_cache_dir() |
| 28 | + options.temp_interpolation_values.start_computation_ts = int(time.time()) |
29 | 29 |
|
30 | | - # Check input is valid |
31 | | - _check_input_validity(interpolation_input, options, data_descriptor) |
32 | | - |
33 | | - output: list[OctreeLevel] = interpolate_n_octree_levels( |
34 | | - interpolation_input=interpolation_input, |
35 | | - options=options, |
36 | | - data_descriptor=data_descriptor |
37 | | - ) |
38 | | - # region Geophysics |
39 | | - # --------------------- |
40 | | - # TODO: [x] Gravity |
41 | | - # TODO: [ ] Magnetics |
42 | | - |
43 | | - if geophysics_input is not None: |
44 | | - first_level_last_field: InterpOutput = output[0].outputs_centers[-1] |
45 | | - gravity = compute_gravity( |
46 | | - geophysics_input=geophysics_input, |
47 | | - root_ouput=first_level_last_field |
48 | | - ) |
49 | | - else: |
50 | | - gravity = None |
51 | | - |
52 | | - # 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) |
53 | 36 |
|
54 | | - meshes: Optional[list[DualContouringMesh]] = None |
55 | | - if options.mesh_extraction: |
56 | | - if interpolation_input.grid.octree_grid is None: |
57 | | - raise ValueError("Octree grid must be defined to extract the mesh") |
58 | | - |
59 | | - meshes: list[DualContouringMesh] = dual_contouring_multi_scalar( |
60 | | - data_descriptor=data_descriptor, |
| 37 | + output: list[OctreeLevel] = interpolate_n_octree_levels( |
61 | 38 | interpolation_input=interpolation_input, |
62 | 39 | options=options, |
63 | | - octree_list=output[:options.number_octree_levels_surface] |
| 40 | + data_descriptor=data_descriptor |
64 | 41 | ) |
| 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 |
65 | 57 |
|
66 | | - solutions = Solutions( |
67 | | - octrees_output=output, |
68 | | - dc_meshes=meshes, |
69 | | - fw_gravity=gravity, |
70 | | - block_solution_type=options.block_solutions_type |
71 | | - ) |
| 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 | + ) |
72 | 76 |
|
73 | | - if options.debug: |
74 | | - 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 |
75 | 83 |
|
76 | 84 | return solutions |
77 | 85 |
|
|
0 commit comments