Skip to content
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

Reduce runtime of unit tests #628

Closed
peanutfun opened this issue Jan 23, 2023 · 1 comment
Closed

Reduce runtime of unit tests #628

peanutfun opened this issue Jan 23, 2023 · 1 comment

Comments

@peanutfun
Copy link
Member

peanutfun commented Jan 23, 2023

Executing all CLIMADA unit tests takes between 4 to 5 minutes. I was wondering if we could reduce that a bit. The advantage would be that testing CLIMADA against multiple versions of Python would be more feasible, which in turn would make upgrading to new Python versions easier (see #596).

I executed the unit tests with duration reports and these are the tests that take the most time:

Unit Test Durations
============================================================================ slowest durations =============================================================================
16.14s call     climada/util/test/test_lines_polys_handler.py::TestGeomImpactCalcs::test_calc_geom_impact_polys
8.35s call     climada/hazard/test/test_storm_europe.py::TestReader::test_from_footprints
7.74s call     climada/engine/test/test_impact_data.py::TestEmdatProcessing::test_emdat_damage_yearlysum
6.42s call     climada/engine/test/test_impact_data.py::TestGDPScaling::test_scale_impact2refyear
5.38s call     climada/hazard/centroids/test/test_centr.py::TestCentroidsReader::test_base_grid
4.87s call     climada/entity/exposures/test/test_base.py::TestFuncs::test_assign_large_hazard_subset_pass
4.78s call     climada/hazard/test/test_base.py::TestCentroids::test_reproject_raster_pass
4.77s call     climada/util/test/test_plot.py::TestPlots::test_geo_scatter_categorical
4.64s call     climada/hazard/test/test_tc_tracks.py::TestIbtracs::test_ibtracs_with_basin
4.56s call     climada/engine/test/test_impact_data.py::TestEmdatToImpact::test_emdat_to_impact_scale
4.49s call     climada/engine/unsequa/test/test_unsequa.py::TestCalcCostBenefit::test_calc_uncertainty_pass
4.27s call     climada/hazard/test/test_base.py::TestHDF5::test_write_read_pass
4.12s call     climada/engine/unsequa/test/test_unsequa.py::TestOutput::test_plot_unc_cb
3.96s call     climada/util/test/test_coordinates.py::TestGetGeodata::test_on_land_pass
3.85s call     climada/hazard/test/test_base.py::TestCentroids::test_raster_to_vector_pass
3.28s call     climada/hazard/test/test_storm_europe.py::TestReader::test_generate_prob_storms
3.16s call     climada/engine/test/test_forecast.py::TestPlot::test_Forecast_plot
3.10s call     climada/entity/exposures/test/test_litpop.py::TestLitPop::test_get_total_value_per_country_gdp
2.86s call     climada/engine/test/test_impact_data.py::TestEmdatProcessing::test_emdat_impact_event_2018
2.83s call     climada/hazard/test/test_tc_tracks.py::TestFuncs::test_track_land_params
2.79s call     climada/hazard/test/test_tc_tracks_synth.py::TestSynth::test_cutoff_tracks
2.78s call     climada/engine/test/test_impact_data.py::TestEmdatProcessing::test_emdat_impact_event_2020
2.74s call     climada/engine/test/test_forecast.py::TestCalc::test_Forecast_init_raise
2.73s call     climada/hazard/test/test_tc_tracks.py::TestIbtracs::test_ibtracs_range
2.71s call     climada/hazard/test/test_storm_europe.py::TestReader::test_centroids_from_nc
2.67s call     climada/util/test/test_coordinates.py::TestRasterIO::test_transform_raster_pass
2.52s call     climada/util/test/test_lines_polys_handler.py::TestGdfGeomToPnt::test_gdf_poly_to_pnts
2.21s call     climada/engine/unsequa/test/test_unsequa.py::TestCalcCostBenefit::test_calc_sensitivity_pass
2.19s call     climada/entity/measures/test/test_base.py::TestApply::test_cutoff_hazard_region_pass
2.16s call     climada/engine/unsequa/test/test_unsequa.py::TestOutput::test_plot_unc_imp
2.08s call     climada/hazard/test/test_storm_europe.py::TestReader::test_set_ssi
1.99s call     climada/util/test/test_coordinates.py::TestGetGeodata::test_get_admin1_geometries_pass
1.98s call     climada/util/test/test_coordinates.py::TestGetGeodata::test_get_admin1_info_pass
1.98s call     climada/hazard/test/test_storm_europe.py::TestReader::test_read_with_ref
1.94s call     climada/util/test/test_finance.py::TestWBWealthAccount::test_tow_IND_1985_pass
1.93s call     climada/hazard/test/test_tc_tracks.py::TestIO::test_hdf5_io
1.91s call     climada/util/test/test_coordinates.py::TestGetGeodata::test_dist_to_coast
1.91s call     climada/hazard/test/test_storm_europe.py::TestReader::test_icon_read
1.91s call     climada/util/test/test_coordinates.py::TestRasterIO::test_crs_raster_pass
1.90s call     climada/entity/exposures/test/test_litpop.py::TestLitPop::test_get_total_value_per_country_pc
1.79s call     climada/hazard/test/test_tc_tracks.py::TestIbtracs::test_ibtracs_scale_wind
1.76s call     climada/util/test/test_plot.py::TestPlots::test_geo_im_from_array
1.73s call     climada/hazard/test/test_tc_tracks.py::TestIbtracs::test_ibtracs_interpolate_missing
1.68s call     climada/hazard/test/test_tc_tracks_synth.py::TestSynth::test_random_walk_single_point
1.61s call     climada/util/test/test_coordinates.py::TestRasterIO::test_crs_and_geometry_raster_pass
1.60s call     climada/entity/measures/test/test_base.py::TestApply::test_cutoff_hazard_pass
1.56s call     climada/hazard/centroids/test/test_vec_ras.py::TestRaster::test_dist_coast_pass
1.55s call     climada/hazard/test/test_tc_tracks.py::TestFuncs::test_subset
1.51s call     climada/entity/exposures/test/test_litpop.py::TestLitPop::test_grp_read_pass
1.48s call     climada/hazard/test/test_tc_tracks_synth.py::TestSynth::test_angle_funs_pass
1.43s call     climada/util/test/test_coordinates.py::TestGetGeodata::test_country_code_pass
1.42s call     climada/engine/test/test_impact.py::TestIO::test_excel_io
1.42s call     climada/hazard/test/test_tc_tracks_synth.py::TestSynth::test_random_walk_decay_pass
1.41s call     climada/engine/unsequa/test/test_unsequa.py::TestCalcCostBenefit::test_calc_uncertainty_pool_pass
1.34s call     climada/util/test/test_coordinates.py::TestGetGeodata::test_get_admin1_geometries_fail
1.27s call     climada/hazard/test/test_tc_tracks.py::TestIbtracs::test_ibtracs_with_provider
1.27s call     climada/hazard/centroids/test/test_vec_ras.py::TestVector::test_on_land
1.26s call     climada/hazard/test/test_tc_tracks.py::TestFuncs::test_tracks_in_exp_pass
1.24s call     climada/util/test/test_plot.py::TestPlots::test_geo_bin_from_array
1.22s call     climada/util/test/test_files.py::TestDownloadUrl::test_wrong_url_fail
1.14s call     climada/entity/exposures/test/test_base.py::TestAddSea::test_add_sea_pass
1.13s call     climada/engine/test/test_impact_calc.py::TestImpactCalc::test_calc_impact_RF_pass
1.10s call     climada/engine/test/test_cost_benefit.py::TestSteps::test_apply_transf_future_pass
1.08s call     climada/util/test/test_finance.py::TestWBWealthAccount::test_pca_CUB_2015_pass
1.08s call     climada/hazard/test/test_tc_tracks.py::TestFuncs::test_dist_since_lf_pass
1.05s call     climada/entity/exposures/test/test_litpop.py::TestLitPop::test_get_total_value_per_country_nfw
1.05s call     climada/util/test/test_finance.py::TestWBData::test_gdp_sxm_2010_pass
1.05s call     climada/util/test/test_coordinates.py::TestGetGeodata::test_get_country_geometries_country_norway_pass
1.01s call     climada/util/test/test_finance.py::TestWBData::test_wb_esp_1950_pass

(1860 durations < 1s hidden.  Use -vv to show these durations.)

How to replicate this on your machine:

conda activate climada_env
conda install pytest pytest-subtests
cd climada_python
pytest --durations=0 --durations-min=1 climada/engine/ climada/entity/ climada/hazard/ climada/util/

Looking at these numbers, I think it might be feasible to reduce the overall runtime of the unit tests by about 1 min. Options for reducing the run time include:

  • Moving tests to the integration tests
  • Reducing the amount of data to be loaded (e.g., self-made exemplary data instead of "real-world data")
  • "Simplifying" tests (quotation marks because it is also unclear to me how each test could be simplified)
@peanutfun
Copy link
Member Author

#709 reduced the runtime of all unit tests by about 1 min

@peanutfun peanutfun closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant