Skip to content

Conversation

@StFroese
Copy link
Collaborator

@StFroese StFroese commented Nov 14, 2025

This speeds up calls to cross_section by a factor of 3 😮

There is some slow down of the cross section calculation described in #244 .

This reduces the number of internal calls of cross_section due to _temporary_kinematics context manager.

Before PR:

In [2]: from chromo.kinematics import FixedTarget
   ...: from chromo.models import Sibyll23e

In [3]: kin_init = FixedTarget(100, 2212, 'O16')
   ...: kin = FixedTarget(80, 2212, 'O16')
   ...:
   ...:
   ...: sib = Sibyll23e(kin_init)

In [4]: def cs(mod, kin):
   ...:     return mod.cross_section(kin).prod
   ...:
In [5]: %timeit cs(sib, kin)
992 μs ± 252 ns per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

With this PR:

In [8]: %timeit cs(sib, kin)
328 μs ± 791 ns per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

@StFroese
Copy link
Collaborator Author

needs a rebase after #243

@StFroese
Copy link
Collaborator Author

tests passed locally ✅ should pass here too, let's see

@afedynitch I think if we merge this after #243 I should do a patch release v0.10.1 because factor 3 speed up should be made available to users soon

@StFroese StFroese requested a review from afedynitch November 20, 2025 06:26
@afedynitch
Copy link
Member

Oh, and don't forget to update the PR description with the correct timings

@StFroese StFroese merged commit 86be631 into main Nov 20, 2025
5 checks passed
@StFroese StFroese deleted the fix_cache_kin branch November 20, 2025 07:22
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.

3 participants