Skip to content

perf: stop simplifying the slow-flow equations twice before averaging - #522

Merged
oameye merged 1 commit into
fix/commensurate-krylov-harmonicsfrom
perf/krylov-averaging
Jul 28, 2026
Merged

perf: stop simplifying the slow-flow equations twice before averaging#522
oameye merged 1 commit into
fix/commensurate-krylov-harmonicsfrom
perf/krylov-averaging

Conversation

@oameye

@oameye oameye commented Jul 28, 2026

Copy link
Copy Markdown
Member

Depends on QuantumEngineeredSystems/QuestBase.jl#82 (block-diagonal solve and the declare_variable change).

get_krylov_equations ran Symbolics.expand.(Symbolics.simplify.(...)) twice over the slow-flow equations, on the grounds that once was not enough to fully simplify them. What the second pass actually bought was the cancellation of the denominator rearrange! leaves behind, and Symbolics.simplify is a poor way to get it: its cost explodes with the number of harmonics.

average works term by term, so a flat sum of products is all it needs. A single expand gives that. The denominator is cancelled once at the end with simplify_fractions, after averaging has removed the fast time and the expressions are small.

take_trig_integral multiplied its numerator by ω and divided the denominator by the same ω, then called simplify to undo it. Termwise integration leaves the denominator alone, so it goes back as it came.

Together with the QuestBase changes, get_krylov_equations over the test systems goes from 1412 MiB to 925 MiB, and get_harmonic_equations from 351 MiB to 164 MiB.

The precompile workload is re-enabled (it was commented out because declare_variable's @eval made it impossible) with the two get_krylov_equations calls added.

`get_krylov_equations` ran `Symbolics.expand.(Symbolics.simplify.(...))` twice
over the slow-flow equations, on the grounds that once was not enough to fully
simplify them. What the second pass actually bought was the cancellation of the
denominator `rearrange!` leaves behind, and `Symbolics.simplify` is a poor way to
get it: its cost explodes with the number of harmonics.

`average` works term by term, so a flat sum of products is all it needs. A single
`expand` gives that. The denominator is cancelled once at the end with
`simplify_fractions`, after averaging has removed the fast time and the
expressions are small.

`take_trig_integral` multiplied its numerator by ω and divided the denominator by
the same ω, then called `simplify` to undo it. Termwise integration leaves the
denominator alone, so it goes back as it came.

With the QuestBase-side changes this takes `get_krylov_equations` over the test
systems from 1412 MiB to 925 MiB.

`declare_variable` no longer evaluates into a closed module, so the precompile
workload can run again; the two `get_krylov_equations` calls are added to it.
@oameye
oameye merged commit 6d1c341 into fix/commensurate-krylov-harmonics Jul 28, 2026
2 checks passed
@oameye
oameye deleted the perf/krylov-averaging branch July 28, 2026 12:37
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