-
Notifications
You must be signed in to change notification settings - Fork 19
Add performance tests #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
trexfeathers
merged 13 commits into
SciTools:unstructured_scheme
from
stephenworsley:sperf
Oct 4, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b6aed33
time regridding prepare
stephenworsley 1ba4f14
add scalability benchmarks
stephenworsley 0bfe7e3
fix tests
stephenworsley cb71205
fix tests
stephenworsley df81e86
fix tests
stephenworsley 3d942b2
add long benchmark function to nox
stephenworsley 9db4778
fix tests
stephenworsley 4bea5e3
test fixes
stephenworsley 752cfce
fix tests
stephenworsley ae9400e
tidy up code
stephenworsley 7076a89
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ec53eba
address review comments
stephenworsley 488a1a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| """Slower benchmarks for :mod:`esmf_regrid.esmf_regridder`.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| import dask.array as da | ||
| import iris | ||
| from iris.cube import Cube | ||
|
|
||
| from benchmarks import disable_repeat_between_setup | ||
| from esmf_regrid.experimental.unstructured_scheme import ( | ||
| GridToMeshESMFRegridder, | ||
| MeshToGridESMFRegridder, | ||
| ) | ||
| from esmf_regrid.schemes import ESMFAreaWeightedRegridder | ||
| from esmf_regrid.tests.unit.schemes.test__cube_to_GridInfo import _grid_cube | ||
|
|
||
|
|
||
| class PrepareScalabilityGridToGrid: | ||
| params = [50, 100, 200, 400, 600, 800] | ||
| param_names = ["grid width"] | ||
| height = 100 | ||
| regridder = ESMFAreaWeightedRegridder | ||
|
|
||
| def src_cube(self, n): | ||
| lon_bounds = (-180, 180) | ||
| lat_bounds = (-90, 90) | ||
| src = _grid_cube(n, n, lon_bounds, lat_bounds) | ||
| return src | ||
|
|
||
| def tgt_cube(self, n): | ||
| lon_bounds = (-180, 180) | ||
| lat_bounds = (-90, 90) | ||
| grid = _grid_cube(n + 1, n + 1, lon_bounds, lat_bounds) | ||
| return grid | ||
|
|
||
| def setup(self, n): | ||
| self.src = self.src_cube(n) | ||
| self.tgt = self.tgt_cube(n) | ||
|
|
||
| def time_prepare(self, n): | ||
| _ = self.regridder(self.src, self.tgt) | ||
|
|
||
|
|
||
| class PrepareScalabilityMeshToGrid(PrepareScalabilityGridToGrid): | ||
| regridder = MeshToGridESMFRegridder | ||
|
|
||
| def src_cube(self, n): | ||
| from esmf_regrid.tests.unit.experimental.unstructured_scheme.test__mesh_to_MeshInfo import ( | ||
| _gridlike_mesh, | ||
| ) | ||
|
|
||
| src = Cube(np.ones([n * n])) | ||
| mesh = _gridlike_mesh(n, n) | ||
| mesh_coord_x, mesh_coord_y = mesh.to_MeshCoords("face") | ||
| src.add_aux_coord(mesh_coord_x, 0) | ||
| src.add_aux_coord(mesh_coord_y, 0) | ||
| return src | ||
|
|
||
|
|
||
| class PrepareScalabilityGridToMesh(PrepareScalabilityGridToGrid): | ||
| regridder = GridToMeshESMFRegridder | ||
|
|
||
| def tgt_cube(self, n): | ||
| from esmf_regrid.tests.unit.experimental.unstructured_scheme.test__mesh_to_MeshInfo import ( | ||
| _gridlike_mesh, | ||
| ) | ||
|
|
||
| tgt = Cube(np.ones([(n + 1) * (n + 1)])) | ||
| mesh = _gridlike_mesh(n + 1, n + 1) | ||
| mesh_coord_x, mesh_coord_y = mesh.to_MeshCoords("face") | ||
| tgt.add_aux_coord(mesh_coord_x, 0) | ||
| tgt.add_aux_coord(mesh_coord_y, 0) | ||
| return tgt | ||
|
|
||
|
|
||
| @disable_repeat_between_setup | ||
| class PerformScalabilityGridToGrid: | ||
| params = [100, 200, 400, 600, 800, 1000] | ||
| param_names = ["height"] | ||
| grid_size = 400 | ||
| target_grid_size = 41 | ||
| chunk_size = [grid_size, grid_size, 10] | ||
| regridder = ESMFAreaWeightedRegridder | ||
| file_name = "chunked_cube.nc" | ||
|
|
||
| def src_cube(self, height): | ||
| data = da.ones([self.grid_size, self.grid_size, height], chunks=self.chunk_size) | ||
| src = Cube(data) | ||
| return src | ||
|
|
||
| def add_src_metadata(self, cube): | ||
| lon_bounds = (-180, 180) | ||
| lat_bounds = (-90, 90) | ||
| grid = _grid_cube(self.grid_size, self.grid_size, lon_bounds, lat_bounds) | ||
| cube.add_dim_coord(grid.coord("latitude"), 0) | ||
| cube.add_dim_coord(grid.coord("longitude"), 1) | ||
| return cube | ||
|
|
||
| def tgt_cube(self): | ||
| lon_bounds = (-180, 180) | ||
| lat_bounds = (-90, 90) | ||
| grid = _grid_cube( | ||
| self.target_grid_size, self.target_grid_size, lon_bounds, lat_bounds | ||
| ) | ||
| return grid | ||
|
|
||
| def setup_cache(self): | ||
| SYNTH_DATA_DIR = Path().cwd() / "tmp_data" | ||
| SYNTH_DATA_DIR.mkdir(exist_ok=True) | ||
| file = str(SYNTH_DATA_DIR.joinpath(self.file_name)) | ||
|
|
||
| src = self.src_cube(max(self.params)) | ||
| # While iris is not able to save meshes, we add these after loading. | ||
| # TODO: change this back after iris allows mesh saving. | ||
| iris.save(src, file, chunksizes=self.chunk_size) | ||
| loaded_src = iris.load_cube(file) | ||
| loaded_src = self.add_src_metadata(loaded_src) | ||
| tgt = self.tgt_cube() | ||
| rg = self.regridder(loaded_src, tgt) | ||
| return rg, file | ||
|
|
||
| def setup(self, cache, height): | ||
| regridder, file = cache | ||
| src = iris.load_cube(file)[..., :height] | ||
| self.src = self.add_src_metadata(src) | ||
| # Realise data. | ||
| self.src.data | ||
| cube = iris.load_cube(file)[..., :height] | ||
| cube = self.add_src_metadata(cube) | ||
| self.result = regridder(cube) | ||
|
|
||
| def time_perform(self, cache, height): | ||
| assert not self.src.has_lazy_data() | ||
| rg, _ = cache | ||
| _ = rg(self.src) | ||
|
|
||
| def time_lazy_perform(self, cache, height): | ||
| assert self.result.has_lazy_data() | ||
| _ = self.result.data | ||
|
trexfeathers marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class PerformScalabilityMeshToGrid(PerformScalabilityGridToGrid): | ||
| regridder = MeshToGridESMFRegridder | ||
| chunk_size = [PerformScalabilityGridToGrid.grid_size ^ 2, 10] | ||
| file_name = "chunked_cube_1d.nc" | ||
|
|
||
| def setup_cache(self): | ||
| return super().setup_cache() | ||
|
|
||
| def src_cube(self, height): | ||
| data = da.ones( | ||
| [self.grid_size * self.grid_size, height], chunks=self.chunk_size | ||
| ) | ||
| src = Cube(data) | ||
| return src | ||
|
|
||
| def add_src_metadata(self, cube): | ||
| from esmf_regrid.tests.unit.experimental.unstructured_scheme.test__mesh_to_MeshInfo import ( | ||
| _gridlike_mesh, | ||
| ) | ||
|
|
||
| mesh = _gridlike_mesh(self.grid_size, self.grid_size) | ||
| mesh_coord_x, mesh_coord_y = mesh.to_MeshCoords("face") | ||
| cube.add_aux_coord(mesh_coord_x, 0) | ||
| cube.add_aux_coord(mesh_coord_y, 0) | ||
| return cube | ||
|
|
||
|
|
||
| class PerformScalabilityGridToMesh(PerformScalabilityGridToGrid): | ||
| regridder = GridToMeshESMFRegridder | ||
|
|
||
| def setup_cache(self): | ||
| return super().setup_cache() | ||
|
|
||
| def tgt_cube(self): | ||
| from esmf_regrid.tests.unit.experimental.unstructured_scheme.test__mesh_to_MeshInfo import ( | ||
| _gridlike_mesh, | ||
| ) | ||
|
|
||
| tgt = Cube(np.ones([self.target_grid_size * self.target_grid_size])) | ||
| mesh = _gridlike_mesh(self.target_grid_size, self.target_grid_size) | ||
| mesh_coord_x, mesh_coord_y = mesh.to_MeshCoords("face") | ||
| tgt.add_aux_coord(mesh_coord_x, 0) | ||
| tgt.add_aux_coord(mesh_coord_y, 0) | ||
| return tgt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.