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

Make tests faster #589

Merged
merged 9 commits into from
Jan 4, 2025
Merged

Make tests faster #589

merged 9 commits into from
Jan 4, 2025

Conversation

ckolbPTB
Copy link
Collaborator

@ckolbPTB ckolbPTB commented Dec 18, 2024

Closes #564

I went through some of the tests and reduced matrix sizes to speed up the tests.

On my MacBook Pro I got similar timing results than @fzimmermann89 reported here: #564 and I got a total run time for most of the tests (not all tests run on my laptop) of 4.5 mins. With these changes this was reduced to 2 mins.

In the github action it seems to reduce the time from ~2min to ~1min.

@koflera Could you please have a look at the tests for the optimizers:

def test_optimizers_rosenbrock(optimizer, enforce_bounds_on_x1, optimizer_kwargs):

This currently takes quite some time. Maybe we can speed it up by starting closer to the solution? You can time it yourself by e.g. running pytest tests/algorithms/test_optimizers.py --durations=10

Copy link
Contributor

github-actions bot commented Dec 18, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/mrpro/algorithms/csm
   inati.py24196%44
   walsh.py16194%34
src/mrpro/algorithms/dcf
   dcf_voronoi.py53492%15, 48–49, 76
src/mrpro/algorithms/optimizers
   adam.py20195%69
src/mrpro/algorithms/reconstruction
   DirectReconstruction.py281643%51–71, 85
   IterativeSENSEReconstruction.py13192%76
   Reconstruction.py502256%42, 54–56, 80–87, 104–113
   RegularizedIterativeSENSEReconstruction.py411759%96–100, 114–139
src/mrpro/data
   AcqInfo.py128398%26, 169, 207
   CsmData.py29390%15, 82–84
   DcfData.py45882%18, 66, 78–83
   IData.py67987%119, 125, 129, 159–167
   IHeader.py75791%75, 109, 127–131
   KHeader.py1531789%25, 119–123, 150, 199, 210, 217–218, 221, 228, 260–271
   KNoise.py311552%39–52, 56–61
   KTrajectory.py811285%108–113, 116–118, 203–207
   MoveDataMixin.py1401887%15, 113, 129, 143–145, 207, 323–325, 338, 417, 437–438, 440, 455–456, 458
   QData.py39782%42, 65–73
   Rotation.py6743595%100, 198, 335, 433, 477, 495, 581, 583, 592, 626, 628, 691, 768, 773, 776, 791, 808, 813, 889, 1077, 1082, 1085, 1109, 1113, 1240, 1242, 1250–1251, 1315, 1397, 1690, 1846, 1881, 1885, 1996
   SpatialDimension.py2322191%34, 104, 141, 148, 154, 274–276, 289–291, 325, 343, 356, 369, 382, 395, 404–405, 420, 429
   acq_filters.py12192%47
src/mrpro/data/_kdata
   KData.py1341887%109–110, 125, 132, 142, 150, 204–205, 243, 248–249, 268–279
   KDataRemoveOsMixin.py29293%44, 46
   KDataSelectMixin.py19289%48, 63
   KDataSplitMixin.py48394%53, 84, 93
src/mrpro/data/traj_calculators
   KTrajectoryCalculator.py25292%23, 45
   KTrajectoryIsmrmrd.py13285%41, 50
   KTrajectoryPulseq.py23196%55
src/mrpro/operators
   CartesianSamplingOp.py89397%118, 157, 280
   ConstraintsOp.py60297%46, 48
   EndomorphOperator.py65297%228, 234
   FiniteDifferenceOp.py27293%40, 105
   FourierOp.py158398%263, 381, 386
   Functional.py71593%20–22, 117, 119
   GridSamplingOp.py136993%72–73, 82–83, 90–91, 94, 96, 98
   LinearOperator.py1681094%55, 91, 190, 220, 261, 270, 278, 287, 295, 320
   LinearOperatorMatrix.py1581690%82, 119, 152, 161, 166, 175–178, 191–194, 203, 215, 304, 331, 359
   MultiIdentityOp.py13285%43, 48
   Operator.py78297%25, 74
   ProximableFunctionalSeparableSum.py39392%50, 103, 110
   SliceProjectionOp.py173895%44, 61, 63, 69, 206, 227, 260, 300
   WaveletOp.py120596%152, 170, 205, 210, 233
   ZeroPadOp.py16194%30
src/mrpro/utils
   filters.py62297%44, 49
   reshape.py60198%191
   slice_profiles.py46687%20, 36, 113–116, 149
   sliding_window.py34197%34
   split_idx.py10280%43, 47
   summarize_tensorvalues.py11918%20–29
   typing.py181139%8–23
   zero_pad_or_crop.py31681%26, 30, 54, 57, 60, 63
TOTAL493336093% 

Tests Skipped Failures Errors Time
2262 0 💤 0 ❌ 0 🔥 1m 10s ⏱️

Copy link
Contributor

github-actions bot commented Dec 18, 2024

📚 Documentation

📁 Download as zip
🔍 View online

@fzimmermann89
Copy link
Member

I think most low-hanging fruits have been picked now:

4.00s call     tests/operators/test_fourier_op.py::test_fourier_op_gram[radial_phase_encoding_2_coils_non_cartesian_sampling]
3.55s call     tests/operators/test_fourier_op.py::test_fourier_op_gram[3d_nonuniform_3_coils_2_other]
3.04s setup    tests/data/test_kdata.py::test_KData_kspace
1.60s call     tests/algorithms/test_optimizers.py::test_optimizers_rosenbrock[adam-optimizer_kwargs0-True]
1.56s call     tests/data/test_csm_data.py::test_CsmData_smoothing_width[random_kheader0-random_full_ismrmrd_header0-random_acquisition0-from_idata_walsh]
1.55s call     tests/operators/test_fourier_op.py::test_fourier_op_gram[2d_nonuniform_cine_mri_3_cardiac_phases_2_coils]
1.43s call     tests/operators/test_fourier_op.py::test_fourier_op_fwd_adj_property[stack_of_stars_3_other_2_coil_with_oversampling]
1.32s call     tests/operators/test_fourier_op.py::test_fourier_op_fwd_adj_property[3d_nonuniform_3_coils_2_other]
1.28s call     tests/operators/test_fourier_op.py::test_fourier_op_gram[stack_of_stars_3_other_2_coil_with_oversampling]
1.23s call     tests/operators/functionals/test_functional_arithmetic.py::test_functional_scaling_prox_optimality[L1Norm-mean-dim=None-no_target-scalar_weight-float32-shape=[1,2,3]]
1.19s call     tests/algorithms/csm/test_inati.py::test_inati[random_kheader0-random_full_ismrmrd_header0-random_acquisition0]
1.17s call     tests/data/test_kdata.py::test_KData_compress_coils_diff_batch_joint_dims[consistently_shaped_kdata0-random_kheader_shape0-random_acquisition0-random_full_ismrmrd_header0-batching_along_dim-2_and_dim-1]
1.17s call     tests/algorithms/test_optimizers.py::test_optimizers_rosenbrock[adam-optimizer_kwargs0-False]
1.15s call     tests/data/test_rotation.py::test_weighted_mean_dims[shape2-True-dim2-expected_shape2]
1.11s call     tests/data/test_rotation.py::test_align_vectors_near_inf
1.09s call     tests/operators/functionals/test_functional_arithmetic.py::test_functional_scaling_prox_optimality[L1NormViewAsReal-mean-dim=None-random_target-complex_weight-complex64-shape=[1,2,3]]
1.00s call     tests/operators/functionals/test_functionals.py::test_functional_prox_optimality[L1NormViewAsReal-sum-dim=None-random_target-complex_weight-float32-shape=[1,2,3]]

@fzimmermann89 fzimmermann89 self-requested a review January 4, 2025 01:32
@ckolbPTB ckolbPTB merged commit bc2e05a into main Jan 4, 2025
21 checks passed
@ckolbPTB ckolbPTB deleted the speed_up_tests branch January 4, 2025 14:51
@fzimmermann89 fzimmermann89 mentioned this pull request Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some tests have large runtimes
2 participants