Repository navigation
Conversation
…umber _set_rescaled_free_params read pipeline.params (a new ParamSet collected from all stages on every access) once or twice per free parameter, so its cost grew with the cube of the number of params. Collect each pipeline's params once per call, and skip params this method set to the same value last time (as long as their value object is unchanged). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
jpyanez
marked this pull request as ready for review
November 26, 2026 06:25
JanWeldert
reviewed
Nov 26, 2026
JanWeldert
left a comment
Collaborator
There was a problem hiding this comment.
Apart from the one inline comment, this looks good to me.
| # ~0.4 ms (unit conversions). | ||
| cached = self._rescaled_cache.get((ipipe, name)) | ||
| if (cached is not None and cached[0] == rvalue | ||
| and cached[1] is param._value): # pylint: disable=protected-access |
Collaborator
There was a problem hiding this comment.
For some reason cached[1] is param._value always fails for me even of the two are identical. Maybe switch to cached[1] == param._value? That worked for me and at the end you only want to check if the value is the same, not necessarily if the object is the same, right?
This branch has not been deployed
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.
Summary
DistributionMaker._set_rescaled_free_paramscost grows as N³ in the number of free parameters N. With 142 freeparameters it took 0.44 s per minimizer call, ~85 % of the call on our cluster's worker nodes. This PR makes it
~linear: 0.44 s → 6 ms. The fit result does not change (see "Why this is exact").
iminuitoptionstrategyinmethod_kwargs(default unchanged, Minuit's 1). With many free parameters,strategy 0 saves the full HESSE that MIGRAD runs at the end with strategy 1.
test_set_rescaled_free_params.Context
We fit the IceCube/DeepCore 2023 public data release (PRD 108, 012014) with the daemonflux v2 flux model: 129 free
flux parameters + 13 oscillation/detector parameters = 142 free parameters. One octant took 6.1 h for ~30k
minimizer calls. Profiling showed that most of each call went into setting the parameter values, not into the
pipelines.
The problem
For every free parameter, the method evaluates
pipeline.paramsup to three times(
pipeline.params.free.names,pipeline.params[name],pipeline.params.names).Pipeline.paramsis a propertythat builds a new
ParamSetfrom all stages. Eachextend→updatecall looks upself.names, which is atuple built over all params. That is O(N²) per
pipeline.paramsaccess, so O(N³) per call. For N = 142 this is~1.2e8 generator steps per minimizer call (cProfile:
param.py:1492(<genexpr>)called 116 M times in 31 calls).The change
pipeline.paramsis collected once per pipeline per call, and its free and all names are put in sets.The loop is then O(N).
object is still the one stored then. Minimizers move one parameter at a time in their numerical gradients,
so most params are unchanged between calls. Setting a value costs ~0.2–0.4 ms (pint unit conversions and
range checks), so this saves most of the remaining time when N is large.
_fit_iminuitreadsmethod_kwargs['strategy']and setsMinuit.strategy. Nothing changes if the key isabsent.
Why this is exact
Pipeline.paramsreturns a newParamSetthat holds the sameParamobjects as thestages (
ParamSet.updateappends the objects, no copies). So setting_rescaled_valueon the param of the setcollected once is the same as setting it on a freshly collected set. The code path and the arithmetic are
unchanged. The
AttributeErrorfor a param that is fixed in one pipeline and free in another is unchanged.requested rescaled value and the same value object (
is). Any other change of the value replaces that object:param.value = ...,reset_free(),update_params(),_rescaled_value = ...from elsewhere, or a newDistributionMaker. After such a change the param is set again. The cache is per (pipeline, param name), soparams shared by pipelines are handled independently.
207.077318459636 with master and with this branch;
test_DistributionMaker,test_analysisandtest_constrained_minimizationpass;test_set_rescaled_free_params: values reach every pipeline after a one-param step, afterreset_free(), and after a param was set directly in one pipeline.Timings
Login node (AMD EPYC 7452), 1 thread:
_set_rescaled_free_paramsmasteraeff_scalestep)aeff_scalestep)Worker node (Intel Xeon E5-2623 v4), 142 free params, full minimizer call: 0.74 → 0.17 s on average over a
gradient. That figure also includes a small change in our local flux stage, not part of this PR; for an
aeff_scalestep alone it is 0.62 → 0.08 s.Whole fit, one theta23 octant, 142 free params, same worker type: 6.1 h with master (30194 calls, strategy 1).
With this PR and
strategy: 0(plus the small local flux-stage change above): 55.9 min (19245 calls), same minimum (χ² 200.2151 vs 200.2149, EDM 1.5e-5 against agoal of 2e-5). Expected with this PR and strategy 1 (not run): ~1.4 h (30k calls × 0.17 s).
On the minimizer strategy: on a toy 142-parameter correlated quadratic with the same settings (limits,
tol1e-2), strategy 1 used 18580 calls, ~10800 of them for the final HESSE. Strategy 0 used 7711 calls and reached the
same minimum (EDM 1e-5), without an accurate covariance. HESSE can be run separately at the best fit when the
covariance is needed.
Notes
daemon_fluxstagethat are not in master yet. They are on a branch we will propose separately.
🤖 Generated with Claude Code