Skip to content

Commit c093e2d

Browse files
committed
[TEST] Adding asserts to tests
1 parent 25e78fc commit c093e2d

File tree

1 file changed

+11
-100
lines changed

1 file changed

+11
-100
lines changed

test/test_modules/test_compute_times_for_grids.py

Lines changed: 11 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
import time
55

66
PLOT = True
7-
# DENSE_RESOLUTION = [125, 50, 50]
8-
DENSE_RESOLUTION = [20,20,20]
7+
DENSE_RESOLUTION = [20, 20, 20]
98

109

1110
def test_compute_time_dense_dense():
12-
1311
geo_model: gp.data.GeoModel = _setup_model()
12+
geo_model.interpolation_options.evaluation_options.mesh_extraction = True
1413

1514
geo_model.grid.active_grids = gp.data.Grid.GridTypes.DENSE
1615
start_time = time.perf_counter()
@@ -19,23 +18,17 @@ def test_compute_time_dense_dense():
1918
end_time = time.perf_counter()
2019
computation_time_dense_I = end_time - start_time
2120

22-
2321
start_time = time.perf_counter()
2422
gp.compute_model(geo_model)
2523
print(f"Computing model on grids: {geo_model.grid.active_grids}")
2624
end_time = time.perf_counter()
2725
computation_time_dense_II = end_time - start_time
2826

29-
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_dense_III = end_time - start_time
35-
3627
print(f"Computation only model dense grid 125*50*50: {computation_time_dense_I:.2f} seconds")
3728
print(f"Computation only model dense grid 125*50*50: {computation_time_dense_II:.2f} seconds")
38-
print(f"Computation only model dense grid 125*50*50: {computation_time_dense_III:.2f} seconds")
29+
30+
# Assert that it is not too different
31+
assert abs(computation_time_dense_I - computation_time_dense_II) < 0.2
3932

4033

4134
def test_compute_time_topo_dense_grid():
@@ -47,7 +40,7 @@ def test_compute_time_topo_dense_grid():
4740
print(f"Computing model on grids: {geo_model.grid.active_grids}")
4841
end_time = time.perf_counter()
4942
computation_time_dense = end_time - start_time
50-
43+
5144
# Compute a solution for the model
5245
geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY
5346
start_time = time.perf_counter()
@@ -56,7 +49,6 @@ def test_compute_time_topo_dense_grid():
5649
end_time = time.perf_counter()
5750
computation_time_topo = end_time - start_time
5851

59-
6052
# Recompute model as a new grid was added
6153
geo_model.grid.active_grids = gp.data.Grid.GridTypes.TOPOGRAPHY | gp.data.Grid.GridTypes.DENSE
6254
start_time = time.perf_counter()
@@ -65,16 +57,14 @@ def test_compute_time_topo_dense_grid():
6557
end_time = time.perf_counter()
6658
computation_time_topo_dense = end_time - start_time
6759

68-
6960
print(f"Computation only model dense grid 125*50*50: {computation_time_dense:.2f} seconds")
7061
print(f"Computation time with topography 125*50: {computation_time_topo:.2f} seconds")
7162
print(f"Computation time with topography and dense grid 125*50*50: {computation_time_topo_dense:.2f} seconds")
72-
"""
73-
Computation only model dense grid 125*50*50: 79.56 seconds
74-
Computation time with topography 125*50: 5.34 seconds
75-
Computation time with topography and dense grid 125*50*50: 59.24 seconds
76-
"""
77-
63+
64+
# Assert that dense takes longer than topo and that the sum of both is close
65+
assert computation_time_dense > computation_time_topo
66+
assert computation_time_topo_dense > computation_time_dense
67+
7868

7969
def test_compute_time_custom_dense_grid():
8070
geo_model: gp.data.GeoModel = _setup_model()
@@ -94,85 +84,6 @@ def test_compute_time_custom_dense_grid():
9484
print(f"Computation compute_at with 1000 custom points: {computation_time_at:.2f} seconds")
9585

9686

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

0 commit comments

Comments
 (0)