perf: stop simplifying the slow-flow equations twice before averaging - #522
Merged
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on QuantumEngineeredSystems/QuestBase.jl#82 (block-diagonal solve and the
declare_variablechange).get_krylov_equationsranSymbolics.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 denominatorrearrange!leaves behind, andSymbolics.simplifyis a poor way to get it: its cost explodes with the number of harmonics.averageworks term by term, so a flat sum of products is all it needs. A singleexpandgives that. The denominator is cancelled once at the end withsimplify_fractions, after averaging has removed the fast time and the expressions are small.take_trig_integralmultiplied its numerator by ω and divided the denominator by the same ω, then calledsimplifyto undo it. Termwise integration leaves the denominator alone, so it goes back as it came.Together with the QuestBase changes,
get_krylov_equationsover the test systems goes from 1412 MiB to 925 MiB, andget_harmonic_equationsfrom 351 MiB to 164 MiB.The precompile workload is re-enabled (it was commented out because
declare_variable's@evalmade it impossible) with the twoget_krylov_equationscalls added.