Skip to content

Commit f40ee3f

Browse files
committed
[WIP] Investigating time explosion when multiple recomputations
1 parent e56a388 commit f40ee3f

File tree

1 file changed

+117
-4
lines changed

1 file changed

+117
-4
lines changed

test/test_modules/test_compute_times_for_grids.py

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,54 @@
55

66
PLOT = True
77

8+
def test_compute_time_dense_dense():
89

9-
def test_compute_time_topo_dense_grid():
1010
geo_model: gp.data.GeoModel = _setup_model()
1111

12-
# Compute a solution for the model
13-
geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY
12+
geo_model.grid.active_grids = gp.data.Grid.GridTypes.DENSE
1413
start_time = time.perf_counter()
1514
gp.compute_model(geo_model)
1615
print(f"Computing model on grids: {geo_model.grid.active_grids}")
1716
end_time = time.perf_counter()
18-
computation_time_topo = end_time - start_time
17+
computation_time_dense_I = end_time - start_time
18+
19+
20+
start_time = time.perf_counter()
21+
gp.compute_model(geo_model)
22+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
23+
end_time = time.perf_counter()
24+
computation_time_dense_II = end_time - start_time
25+
26+
27+
start_time = time.perf_counter()
28+
gp.compute_model(geo_model)
29+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
30+
end_time = time.perf_counter()
31+
computation_time_dense_III = end_time - start_time
32+
33+
print(f"Computation only model dense grid 125*50*50: {computation_time_dense_I:.2f} seconds")
34+
print(f"Computation only model dense grid 125*50*50: {computation_time_dense_II:.2f} seconds")
35+
print(f"Computation only model dense grid 125*50*50: {computation_time_dense_III:.2f} seconds")
1936

2037

38+
def test_compute_time_topo_dense_grid():
39+
geo_model: gp.data.GeoModel = _setup_model()
40+
2141
geo_model.grid.active_grids = gp.data.Grid.GridTypes.DENSE
2242
start_time = time.perf_counter()
2343
gp.compute_model(geo_model)
2444
print(f"Computing model on grids: {geo_model.grid.active_grids}")
2545
end_time = time.perf_counter()
2646
computation_time_dense = end_time - start_time
47+
48+
# Compute a solution for the model
49+
geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY
50+
start_time = time.perf_counter()
51+
gp.compute_model(geo_model)
52+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
53+
end_time = time.perf_counter()
54+
computation_time_topo = end_time - start_time
55+
2756

2857
# Recompute model as a new grid was added
2958
geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY | gp.data.Grid.GridTypes.DENSE
@@ -37,6 +66,11 @@ def test_compute_time_topo_dense_grid():
3766
print(f"Computation only model dense grid 125*50*50: {computation_time_dense:.2f} seconds")
3867
print(f"Computation time with topography 125*50: {computation_time_topo:.2f} seconds")
3968
print(f"Computation time with topography and dense grid 125*50*50: {computation_time_topo_dense:.2f} seconds")
69+
"""
70+
Computation only model dense grid 125*50*50: 79.56 seconds
71+
Computation time with topography 125*50: 5.34 seconds
72+
Computation time with topography and dense grid 125*50*50: 59.24 seconds
73+
"""
4074

4175

4276
def test_compute_time_custom_dense_grid():
@@ -57,6 +91,85 @@ def test_compute_time_custom_dense_grid():
5791
print(f"Computation compute_at with 1000 custom points: {computation_time_at:.2f} seconds")
5892

5993

94+
def test_compute_at_computation_time():
95+
96+
# Define the path to data
97+
data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'
98+
path_to_data = data_path + "/data/input_data/jan_models/"
99+
100+
# Create a GeoModel instance
101+
geo_model = gp.create_geomodel(
102+
project_name='EGU_example',
103+
extent=[0, 2500, 0, 1000, 0, 1000],
104+
resolution=[125, 50, 50],
105+
importer_helper=gp.data.ImporterHelper(
106+
path_to_orientations=path_to_data + "model7_orientations.csv",
107+
path_to_surface_points=path_to_data + "model7_surface_points.csv"
108+
)
109+
)
110+
111+
# Map geological series to surfaces
112+
gp.map_stack_to_surfaces(
113+
gempy_model=geo_model,
114+
mapping_object={
115+
"Fault_Series": ('fault'),
116+
"Strat_Series1": ('rock3'),
117+
"Strat_Series2": ('rock2', 'rock1'),
118+
}
119+
)
120+
121+
# Define youngest structural group as fault
122+
gp.set_is_fault(geo_model, ["Fault_Series"])
123+
124+
# Compute a solution for the model
125+
start_time = time.perf_counter()
126+
gp.compute_model(geo_model)
127+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
128+
end_time = time.perf_counter()
129+
computation_time_model = end_time - start_time
130+
131+
return
132+
133+
# Setting a randomly generated topography
134+
gp.set_topography_from_random(
135+
grid=geo_model.grid,
136+
fractal_dimension=2,
137+
d_z=np.array([700, 950]),
138+
topography_resolution=np.array([125, 50])
139+
)
140+
141+
# Recompute model as a new grid was added
142+
start_time = time.perf_counter()
143+
gp.compute_model(geo_model)
144+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
145+
end_time = time.perf_counter()
146+
computation_time_topo = end_time - start_time
147+
148+
# numpy array with random coordinates within the extent of the model
149+
custom_coordinates = np.random.uniform(
150+
low=geo_model.grid.extent[:3],
151+
high=geo_model.grid.extent[3:],
152+
size=(1000, 3)
153+
)
154+
155+
start_time = time.perf_counter()
156+
gp.compute_model_at(geo_model, custom_coordinates)
157+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
158+
end_time = time.perf_counter()
159+
computation_time_at = end_time - start_time
160+
161+
print(f"Computation only model dense grid 125*50*50: {computation_time_model:.2f} seconds")
162+
print(f"Computation time with topography 125*50: {computation_time_topo:.2f} seconds")
163+
print(f"Computation compute_at with 1000 custom points: {computation_time_at:.2f} seconds")
164+
165+
"""
166+
Computation only model dense grid 125*50*50: 19.96 seconds
167+
Computation time with topography 125*50: 60.75 seconds
168+
Computation compute_at with 1000 custom points: 7.88 seconds
169+
"""
170+
171+
172+
60173
def _setup_model():
61174
# Define the path to data
62175
data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'

0 commit comments

Comments
 (0)