Skip to content

Speed up level populations calculation - #465

Closed
nabobalis wants to merge 1 commit into
wtbarnes:mainfrom
nabobalis:speed_1
Closed

nabobalis wants to merge 1 commit into
wtbarnes:mainfrom
nabobalis:speed_1

Conversation

@nabobalis

Copy link
Copy Markdown
Collaborator

Avoid repeated expensive recomputation in the level populations calculation while keeping the output bit-identical:

  • Cache the Ion instances returned by next_ion()/previous_ion() for internal use so that rate matrices of the recombining ion are only computed once rather than on every density iteration.
  • Cache the density-independent sum of the two-ion rate matrices.
  • Memoize plasmapy atomic_number/atomic_symbol/element_name lookups, which construct an expensive Particle object on every call.
  • Share the proton-electron ratio with the next ion since it only depends on temperature and the abundance/ionization datasets.

Benchmark (21 temperatures x 9 densities): Fe XXIII 73.5->7.2 s, Ca XVIII 74.3->8.1 s, O VI 73.3->9.3 s, Fe XII (single-ion model) 9.9->5.0 s, coupled n-T 14.5->3.0 s.

Avoid repeated expensive recomputation in the level populations
calculation while keeping the output bit-identical:

- Cache the Ion instances returned by next_ion()/previous_ion() for
  internal use so that rate matrices of the recombining ion are only
  computed once rather than on every density iteration.
- Cache the density-independent sum of the two-ion rate matrices.
- Memoize plasmapy atomic_number/atomic_symbol/element_name lookups,
  which construct an expensive Particle object on every call.
- Share the proton-electron ratio with the next ion since it only
  depends on temperature and the abundance/ionization datasets.

Benchmark (21 temperatures x 9 densities): Fe XXIII 73.5->7.2 s,
Ca XVIII 74.3->8.1 s, O VI 73.3->9.3 s, Fe XII (single-ion model)
9.9->5.0 s, coupled n-T 14.5->3.0 s.
@nabobalis nabobalis closed this Aug 10, 2026
@nabobalis
nabobalis deleted the speed_1 branch August 10, 2026 23:59
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.

1 participant