Skip to content

Commit 43773e7

Browse files
committed
[TEST] Breaking down tests
1 parent 341a9ae commit 43773e7

File tree

1 file changed

+55
-37
lines changed

1 file changed

+55
-37
lines changed

test/test_modules/test_compute_at_computation_time.py renamed to test/test_modules/test_compute_times_for_grids.py

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,61 @@
66
PLOT = True
77

88

9-
def test_compute_at_computation_time():
9+
def test_compute_time_topo_dense_grid():
10+
geo_model: gp.data.GeoModel = _setup_model()
1011

12+
# Compute a solution for the model
13+
geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY
14+
start_time = time.perf_counter()
15+
gp.compute_model(geo_model)
16+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
17+
end_time = time.perf_counter()
18+
computation_time_topo = end_time - start_time
19+
20+
21+
geo_model.grid.active_grids = gp.data.Grid.GridTypes.DENSE
22+
start_time = time.perf_counter()
23+
gp.compute_model(geo_model)
24+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
25+
end_time = time.perf_counter()
26+
computation_time_dense = end_time - start_time
27+
28+
# Recompute model as a new grid was added
29+
geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY | gp.data.Grid.GridTypes.DENSE
30+
start_time = time.perf_counter()
31+
gp.compute_model(geo_model)
32+
print(f"Computing model on grids: {geo_model.grid.active_grids}")
33+
end_time = time.perf_counter()
34+
computation_time_topo_dense = end_time - start_time
35+
36+
37+
print(f"Computation only model dense grid 125*50*50: {computation_time_dense:.2f} seconds")
38+
print(f"Computation time with topography 125*50: {computation_time_topo:.2f} seconds")
39+
print(f"Computation time with topography and dense grid 125*50*50: {computation_time_topo_dense:.2f} seconds")
40+
41+
42+
def test_compute_time_custom_dense_grid():
43+
geo_model: gp.data.GeoModel = _setup_model()
44+
45+
# numpy array with random coordinates within the extent of the model
46+
custom_coordinates = np.random.uniform(
47+
low=geo_model.grid.extent[:3],
48+
high=geo_model.grid.extent[3:],
49+
size=(1000, 3)
50+
)
51+
52+
start_time = time.perf_counter()
53+
gp.compute_model_at(geo_model, custom_coordinates)
54+
end_time = time.perf_counter()
55+
computation_time_at = end_time - start_time
56+
57+
print(f"Computation compute_at with 1000 custom points: {computation_time_at:.2f} seconds")
58+
59+
60+
def _setup_model():
1161
# Define the path to data
1262
data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'
1363
path_to_data = data_path + "/data/input_data/jan_models/"
14-
1564
# Create a GeoModel instance
1665
geo_model = gp.create_geomodel(
1766
project_name='EGU_example',
@@ -22,53 +71,22 @@ def test_compute_at_computation_time():
2271
path_to_surface_points=path_to_data + "model7_surface_points.csv"
2372
)
2473
)
25-
2674
# Map geological series to surfaces
2775
gp.map_stack_to_surfaces(
2876
gempy_model=geo_model,
2977
mapping_object={
30-
"Fault_Series": ('fault'),
31-
"Strat_Series1": ('rock3'),
32-
"Strat_Series2": ('rock2', 'rock1'),
78+
"Fault_Series" : ('fault'),
79+
"Strat_Series1": ('rock3'),
80+
"Strat_Series2": ('rock2', 'rock1'),
3381
}
3482
)
35-
3683
# Define youngest structural group as fault
3784
gp.set_is_fault(geo_model, ["Fault_Series"])
38-
39-
# Compute a solution for the model
40-
start_time = time.perf_counter()
41-
gp.compute_model(geo_model)
42-
end_time = time.perf_counter()
43-
computation_time_model = end_time - start_time
44-
4585
# Setting a randomly generated topography
4686
gp.set_topography_from_random(
4787
grid=geo_model.grid,
4888
fractal_dimension=2,
4989
d_z=np.array([700, 950]),
5090
topography_resolution=np.array([125, 50])
5191
)
52-
53-
# Recompute model as a new grid was added
54-
start_time = time.perf_counter()
55-
gp.compute_model(geo_model)
56-
end_time = time.perf_counter()
57-
computation_time_topo = end_time - start_time
58-
59-
# numpy array with random coordinates within the extent of the model
60-
custom_coordinates = np.random.uniform(
61-
low=geo_model.grid.extent[:3],
62-
high=geo_model.grid.extent[3:],
63-
size=(1000, 3)
64-
)
65-
66-
start_time = time.perf_counter()
67-
gp.compute_model_at(geo_model, custom_coordinates)
68-
end_time = time.perf_counter()
69-
computation_time_at = end_time - start_time
70-
71-
print(f"Computation only model dense grid 125*50*50: {computation_time_model:.2f} seconds")
72-
print(f"Computation time with topography 125*50: {computation_time_topo:.2f} seconds")
73-
print(f"Computation compute_at with 1000 custom points: {computation_time_at:.2f} seconds")
74-
92+
return geo_model

0 commit comments

Comments
 (0)