Skip to content

1st Round Speed Up: Changes with big speedup and minimal risk - #519

Open
HKaras wants to merge 35 commits into
JeschkeLab:mainfrom
HKaras:SpeedUp
Open

HKaras wants to merge 35 commits into
JeschkeLab:mainfrom
HKaras:SpeedUp

Conversation

@HKaras

@HKaras HKaras commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Speed up fitting

Summary

This PR removes overhead from fit, following FITTING_SPEEDUPS.md. Every benchmark is now 1.8× to 4.8× faster than main. Most changes leave results bit-identical; the ones that change output are listed below.

Speed-up on the benchmarks

main vs this branch, measured in one session with python benchmarks/compare.py main (mean of 3–5 cold-cache rounds).

benchmark_speedup_light
Benchmark main (s) This PR (s) Speed-up
Global fit, 2× 4pDEER (merge + link) 1.959 0.409 4.8×
4pDEER, complex-valued data 1.465 0.336 4.4×
4pDEER, three pathways 1.535 0.465 3.3×
Bootstrap, 20 samples, 1 core 10.54 3.97 2.7×
4pDEER long trace, parametric 0.661 0.264 2.5×
Bootstrap, 20 samples, 4 cores 4.45 1.94 2.3×
4pDEER long trace 0.647 0.305 2.1×
4pDEER, QP solver 0.472 0.229 2.1×
4pDEER compactness penalty 5.265 2.687 2.0×
4pDEER single pathway 0.513 0.269 1.9×
5pDEER, two pathways 0.722 0.412 1.8×
Profile analysis, 3 parameters × 10 grid points fails on main 5.17 —

The complex-valued and three-pathway benchmarks are new in this PR. Saved runs: 0019_base-main.json, 0020_head.json.

Largest gains

  • Byte-based kernel cache keys (section 1): the dipolar-kernel cache built its keys by converting arrays to strings. About −25% on every fit.
  • Exact Jacobian for the linear parameters in uncertainty propagation (section 3): the model response is linear in P, so its Jacobian is the design matrix; the finite differences over all ~150 P values are no longer needed. −15% on single fits, −49% on the global fit.
  • Linear degrees of freedom computed once (section 4a) instead of with an SVD on every residual call: −16%.
  • Vectorized link/merge (section 7): −24% on the global fit.
  • Model evaluated once per residual and in the complex wrappers (section 2): −33% on complex data.
  • α no longer re-optimized inside finite-difference steps for parameters at or below 0 (section 10): −31% on the three-pathway fit.

Changes that affect output

  • Goodness-of-fit statistics (stats) change (sections 4b and 5): these are bug fixes, so reported values move.
    • The effective number of linear parameters used a wrong formula (≈1.6 instead of ≈10 for 4pDEER). It is now the trace of the hat matrix, as in selregparam.
    • aic, aicc and bic subtracted the parameter penalty instead of adding it.
    • For complex data, rmsd, R2, autocorr and the information criteria were complex numbers; they are now real.
    • Penalties whose weight is selected with aic, aicc or bic can therefore choose a different weight. The default (icc) is unaffected.
    • Fitted parameters and uncertainties do not change.
  • α re-optimization test (section 10): fits with non-linear parameters near or below 0, or below 1 in magnitude, can take a slightly different optimization path. On the benchmarks the parameters moved by at most 0.08 standard errors and P by at most 0.29 of its standard error.
  • Multi-core bootstrap (section 9): the resampled datasets are now drawn in the calling process. With several cores, results now equal the 1-core result and can be reproduced with np.random.seed. Before, they could not be reproduced. 1-core results are unchanged.
  • Small changes:
    • Model confidence intervals (section 3): about 10⁻⁸ relative change, because the linear part of the Jacobian is now exact.
    • Kernel cache (section 1): different inputs can no longer share a cache entry and return the wrong kernel. Previously this could happen for time axes with more than 1000 points or values closer than 8 significant digits.
    • Penalty weights (section 8): penweights now reports the weights the returned fit was run with. Before, this could be the last weight evaluated rather than the optimum.

Other changes

  • New optional jacobian= argument of UQResult.propagate.
  • Removed the memoization dependency.
  • New benchmarks: complex-valued 4pDEER, and 4pDEER with three pathways. The bootstrap benchmarks are now seeded.
  • benchmarks/compare.py: fixed two bugs. The base revision was benchmarked with the working tree's deerlab, because python -m pytest puts the working directory ahead of PYTHONPATH. Also, the --fail threshold was passed in a format that pytest-benchmark rejects.

Details

Each change below lists its benchmark effect (pytest benchmarks, mean of 3–5 cold-cache rounds, same machine; macOS, Python 3.14, NumPy 2.4, SciPy 1.17).

Changes

1. Exact byte-based cache keys for the dipolar kernel

  • Replaced memoization.cached on elementarykernel_twospin and _elementarykernel_twospin_interp with a small LRU cache, _arraycache in dipolarkernel.py. It keeps the size limit of 100 entries and the cache_clear() method.
  • Arrays are keyed on (shape, dtype, tobytes()) instead of str(args).
    • Faster: building the key no longer formats every array as text.
    • Correct: str() rounds to 8 significant digits and abbreviates arrays with more than 1000 elements, so different inputs could share a key and get the wrong kernel back. Verified: two 2000-point time axes that differ in one element had equal str() keys before this change; they now get separate entries.
  • dipolarkernel(..., clearcache=True) now also clears the interpolator cache.
  • Removed the memoization dependency (setup.py, installation docs).
  • Tests: the full suite passes (617 tests).
Benchmark Before (s) After (s) Change
4pDEER single pathway 0.519 0.391 −25%
4pDEER single pathway, QP solver 0.472 0.367 −22%
4pDEER long trace 0.647 0.462 −29%
4pDEER long trace, parametric 0.672 0.339 −50%
5pDEER multiple pathways 0.724 0.680 −6%
Global fit, 2× 4pDEER 1.974 1.433 −27%
4pDEER compactness 5.350 4.071 −24%
Bootstrap, 1 core 11.56 8.14 −30%
Bootstrap, 4 cores 4.44 3.53 −20%

2. Evaluate the model once per residual

  • snlls residual (solvers.py): the residual reuses the design matrix A computed earlier in the same call, instead of evaluating Amodel(p) a second time.
  • Complex-valued wrappers in snlls (solvers.py) and UQResult.propagate (classes.py): the inner model is evaluated once and split into .real/.imag, instead of once for each part.
  • snlls with a complex design matrix: removed a redundant A0 = Amodel(par0) that recomputed the value set on the line before.
  • Results are unchanged. Tests: the full suite passes (617 tests).
  • Complex-valued fit: a 2-parameter complex snlls fit now calls the model 26 times instead of 97, with identical fitted parameters. The new test_4pdeer_complex benchmark (see "Benchmarks added") covers this case.
Benchmark Before (s) After (s) Change
4pDEER single pathway 0.391 0.380 −3%
4pDEER complex-valued data 0.716 0.478 −33%
4pDEER single pathway, QP solver 0.367 0.349 −5%
4pDEER long trace 0.462 0.444 −4%
4pDEER long trace, parametric 0.339 0.279 −18%
5pDEER multiple pathways 0.680 0.641 −6%
Global fit, 2× 4pDEER 1.433 1.272 −11%
4pDEER compactness 4.071 3.852 −5%
Bootstrap, 1 core 8.14 8.24 within noise (±0.5 s)
Bootstrap, 4 cores 3.53 3.45 −2%

3. Exact Jacobian for the linear parameters in uncertainty propagation

  • UQResult.propagate takes a new optional jacobian= argument. If it is given, the finite-difference Jacobian (one model evaluation per parameter) is skipped.
  • Model response (snlls): the response is y = A(θ)·x, so its Jacobian with respect to x is exactly A(θ). Only the non-linear parameters θ use finite differences. Before, there were finite differences over all parameters: 3 + 151 model evaluations for non-parametric 4pDEER.
  • Parameter subsets (uq_subset in snlls, Model._getparamuq): the Jacobian of the selection x[idx] is passed as the selection matrix, instead of being computed by finite differences.
  • FitResult.propagate (e.g. background uncertainty in fit): for moment-based uncertainties, the finite differences only run over the parameters that the propagated model uses. Columns of the other parameters are zero, as before. For the background this replaces about 150 Model.__call__ evaluations by the few for its own parameters.
  • Results: all parameter values, covariance matrices, parameter confidence intervals and background confidence intervals are bit-identical (checked on the 4pDEER, complex 4pDEER and 5pDEER benchmark fits). The model-response confidence intervals change by at most 2×10⁻⁸ relative, because the finite-difference error of the linear columns is gone. Tests: the full suite passes (617 tests).
Benchmark Before (s) After (s) Change
4pDEER single pathway 0.382 0.325 −15%
4pDEER complex-valued data 0.465 0.386 −17%
4pDEER single pathway, QP solver 0.349 0.292 −16%
4pDEER long trace 0.449 0.376 −16%
4pDEER long trace, parametric 0.278 0.278 0% (only 1 linear parameter)
5pDEER multiple pathways 0.646 0.535 −17%
Global fit, 2× 4pDEER 1.285 0.658 −49%
4pDEER compactness 3.905 3.508 −10%
Bootstrap, 1 core 8.01 7.26 −9%
Bootstrap, 4 cores 3.46 3.26 −6%

4a. Compute the linear degrees of freedom once

  • snlls computed Ndof = trace(Ared@pinv(AtA)) inside linear_problem, i.e. one SVD on every residual call. Only the value from the last residual call was used, in the goodness-of-fit statistics. That last call could even be a finite-difference column of the uncertainty Jacobian.
  • It is now computed once, by a new linear_dof(A, alpha) helper, at the solution after the least-squares run. The formula is unchanged in this step.
  • Results: bit-identical, including stats, on the 4pDEER, complex 4pDEER and 5pDEER benchmark fits. Tests: the full suite passes (617 tests).
Benchmark Before (s) After (s) Change
4pDEER single pathway 0.325 0.275 −15%
4pDEER complex-valued data 0.386 0.323 −16%
4pDEER single pathway, QP solver 0.292 0.237 −19%
4pDEER long trace 0.376 0.310 −18%
4pDEER long trace, parametric 0.278 0.269 −3%
5pDEER multiple pathways 0.535 0.450 −16%
Global fit, 2× 4pDEER 0.658 0.552 −16%
4pDEER compactness 3.508 2.941 −16%
Bootstrap, 1 core 7.26 6.08 −16%
Bootstrap, 4 cores 3.26 2.74 −16%

Saved runs: 0007_after_1_3.json (before), 0008_after_1_4a.json (after).

4b. Fix the formula for the linear degrees of freedom

  • Old formula: trace(Ared@pinv(AtA)). Ared is N×n, so the product is N×n and np.trace summed its first n diagonal elements, which mixes time and distance indices. It also used the unweighted, unmasked design matrix.

  • New formula: the effective number of linear parameters is the trace of the hat matrix, H = Aw·(AwᵀAw + α²LᵀL)⁻¹·Awᵀ, with Aw the weighted and masked design matrix. It is computed as trace(solve(AtAreg, AwᵀAw)), with a pinv fallback if AtAreg is singular. This is the same trace of H that selregparam uses for its criteria. Like there, the non-negativity constraints are not taken into account.

  • Effect on stats (fitted parameters and uncertainties unchanged):

    Fit Effective linear parameters (derived from Δaic) chi2red aic bic
    4pDEER ≈1.6 → ≈10.4 1.419 → 1.472 −610.2 → −627.8 −624.3 → −673.0
    5pDEER ≈1 → ≈11.8 1.350 → 1.380 −833.3 → −854.8 −858.6 → −925.5
    4pDEER complex 0.673 → 0.700 −974.4 → −992.9 (real part) −992.0 → −1043.0 (real part)
  • Penalty weights: Penalty.optimize selects the weight with stats['aic'], ['aicc'] or ['bic'] when the user picks one of these criteria, so the chosen weight can change for them. The default for dipolarpenalty is icc, which does not use stats: the compactness benchmark result is identical (same weight, α and P).

  • Tests: the full suite passes (617 tests).

  • Timing: no measurable change. It adds one n×n solve per fit; all benchmarks are within run-to-run noise. A first run showed single-pathway 4pDEER at 0.298 s; two re-runs gave 0.276 and 0.273 s (vs 0.275 s before).

Note: in this step aic/aicc/bic decrease with the larger number of parameters, because of the sign error fixed in section 5.

5. Fix the information criteria and complex-valued statistics in goodness_of_fit (bug fix; changes stats)

Not a speedup but related bugfix

  • Sign of the parameter penalty: the number of parameters was computed as Q = Ndof - N. With Ndof = N - nParam this is −nParam, so aic = loglike + 2Q, aicc and bic subtracted the parameter penalty instead of adding it. Now Q = N - Ndof.

  • Complex-valued data: rmsd, R2, autocorr and the log-likelihood used residuals**2, which is complex for complex residuals, so these statistics came out complex. They now use abs(residuals)**2 (chi2red already used the norm). N remains the number of complex data points.

  • Effect on stats (fitted parameters and uncertainties unchanged):

    Fit aic bic other
    4pDEER −627.8 → −576.5 −673.0 → −531.4
    5pDEER −854.8 → −787.8 −925.5 → −717.1
    4pDEER complex −992.9+769.0j → −371.1 −1043.0+769.0j → −321.0 rmsd 0.0003+0.0092j → 0.0284 (= √2 × noise level 0.02, as expected); R2 1.004+0.011j → 0.892; autocorr 1.115 → 0.139
  • Penalty weights: as in 4b, penalties with selection='aic', 'aicc' or 'bic' can now select a different weight; the default icc is unaffected.

  • Tests: the full suite passes (617 tests). Timing: unchanged, all benchmarks within run-to-run noise.

6. Skip the identity product for non-parametric distributions

  • For a non-parametric distribution, freedist returns np.eye(len(r)) and Vtwospin_nonlinear_fcn (dipolarmodel.py) computed Kdipolar@eye on every model evaluation. When dipolarmodel was built with Pmodel=None, it now returns Kdipolar directly. Kdipolar is a new array on every call (not the cached kernel), so returning it is safe.
  • Results: bit-identical, including stats, on the 4pDEER, complex 4pDEER and 5pDEER benchmark fits. Tests: the full suite passes (617 tests).
  • Gain: the skipped product costs 29 µs (250×150) to 50 µs (475×150) per model evaluation, i.e. a few ms per fit. That is 1–2%, which is at the level of run-to-run noise in the benchmarks:
Benchmark Before (s) After (s) Change
4pDEER single pathway 0.275 0.270 −2%
4pDEER complex-valued data 0.325 0.321 −1%
4pDEER single pathway, QP solver 0.241 0.238 −1%
4pDEER long trace 0.313 0.313 0%
4pDEER long trace, parametric (code path unchanged) 0.267 0.275 +3% (noise)
5pDEER multiple pathways 0.443 0.445 0%
Global fit, 2× 4pDEER 0.552 0.544 −2%
4pDEER compactness 2.895 2.901 0%
Bootstrap, 1 core 6.11 6.08 0%
Bootstrap, 4 cores 2.79 2.69 −3%

7. Vectorize link and merge

  • link (_linked_model_with_constants, model.py): after linking, the design-matrix columns of linked linear parameters were summed with a Python loop over all columns (np.vstack([np.sum(A[:,idx],axis=1) for idx in linear_reduce_idx])), on every model call and at every linking level. The column reduction is now precomputed once at link time by a new _linear_reduction helper:

    • Identity (only non-linear parameters were linked at this level, e.g. conc): no reduction.
    • Permutation: a single column gather.
    • Sums (e.g. P_1 + P_2): start from the first column of each group and add the remaining columns with one vectorized add per position within the groups. This adds the columns in the same order as before. (np.add.reduceat was tried first and was no faster than the loop.)
    • The output is returned in column-major (Fortran) order, as vstack(...).T returned it. With C order, the downstream matrix products take a different BLAS path, and the global fit changed by up to 8×10⁻⁷ relative.
  • merge (_combined_nonlinmodel, model.py): the block-diagonal design matrix is filled into a preallocated dense array instead of scipy.sparse.block_diag(...).toarray(). The scipy.sparse import is no longer needed.

  • Per model call (2-dataset global fit, 725×302 merged matrix):

    Operation Before After
    link, identity level 0.81 ms 0.06 ms
    link, summing level (150 pairs) 0.43 ms 0.10 ms
    merge block diagonal 0.30 ms 0.03 ms
  • Results: bit-identical on the global fit (parameters, covariance, confidence intervals, stats) and on the 4pDEER, complex 4pDEER and 5pDEER fits. The summing path is also bit-identical to the old loop for groups of 3 and 4 columns (checked separately). Tests: the full suite passes (617 tests).

Benchmark Before (s) After (s) Change
Global fit, 2× 4pDEER 0.544 0.416 −24%
all other benchmarks (do not use link/merge) within ±1% (noise)

8. Reuse the fit at the optimal penalty weight

  • Penalty.optimize (model.py) ran the full fit again at the optimal weight after fminbound. fminbound returns the best point it has evaluated, so this fit had already been computed. The fits from the search are now kept, by weight, and the one at the optimum is returned; if the optimum was not evaluated (or the weight is frozen), the fit is run as before.
  • With nested penalties (2 or 3), the repeated fit at the outer optimum also re-ran the inner weight searches, and fit read the reported penweights from the penalty objects' state (_weight_value) afterwards. Without the repeat, that state could belong to another outer weight. fit (fit.py) therefore now stores on each snlls result the penalty weights it was run with, and reports those. Penalty.optimize also sets _weight_value to the optimal weight. Before, it held the last weight evaluated, which is not necessarily the optimum.
  • Not done: switching off model uncertainty for the inner fits. After section 3 it costs ~2% of a fit (0.255 vs 0.260 s for 4pDEER), and the reused fit at the optimum needs it.
  • Number of snlls fits: 11 → 10 with one penalty (compactness), 143 → 120 with two (compactness + smoothness).
  • Results: bit-identical (parameters, covariance, P and its confidence intervals, model and background confidence intervals, penalty weights, α, stats) for one and two penalties. Tests: the full suite passes (617 tests).
Benchmark Before (s) After (s) Change
4pDEER compactness 2.909 2.657 −9%
4pDEER, compactness + smoothness (not in the suite) 45.9 38.5 −16%
all other benchmarks (no penalties) within ±2% (noise)

9. Reproducible bootstrap: draw the samples in the calling process, seed the benchmarks

  • bootstrap_analysis (bootstrap_analysis.py): the resampled datasets were drawn inside each parallel job, i.e. in the worker processes when cores>1. Their random state cannot be seeded from the calling script, so results with several cores were not reproducible and differed from the 1-core result. All samples are now drawn in the calling process before the fits are dispatched.
    • With cores=1 the random numbers are drawn in the same order as before: results are bit-identical to the previous version for the same seed.
    • With any number of cores, np.random.seed(...) now reproduces the result, and it is identical to the 1-core result (checked with 1 and 4 cores, two runs each).
  • Benchmarks (benchmarks/conftest.py): clear_caches, which runs before every round, now also seeds np.random with the dataset seed. The bootstrap benchmarks (and the random draws in UQResult.propagate for bootstrap uncertainties) are therefore the same in every round and every run, and their accuracy checks can no longer fail by chance.
  • Tests: the full suite passes (617 tests). Timing: unchanged (bootstrap 1 core 6.03 → 5.97 s, 4 cores 2.57 → 2.66 s, within noise); the spread between 1-core rounds dropped from 0.12 s to 0.01 s.

10. Fix the test that decides when to re-optimize α

  • snlls re-optimizes the regularization parameter α unless all non-linear parameters changed by less than alphareopt (1e-3) since the previous residual call. The test was all(abs(par_prev-p)/(p+eps) < alphareopt):

    • Parameter at 0 (e.g. a refocusing time at 0): any finite-difference step of least_squares gives a relative change of ~1, so a full α search ran inside that Jacobian column.
    • Negative parameter: the ratio is negative, so that parameter never triggered a re-optimization.
  • New test: np.all(np.abs(p - par_prev) <= alphareopt*np.maximum(np.abs(p),1)), i.e. relative change for |p| ≥ 1 and absolute change below. The floor of 1 is the scale least_squares uses for its own finite-difference steps (max(1,|x|)), so those steps (~1.5×10⁻⁸) can no longer trigger an α search. The alphareopt docstrings in snlls and fit are updated accordingly.

  • Operation counts and results (fit without bootstrap; σ = standard error of the parameter before the change):

    Fit α searches Model evaluations Time Largest parameter change Largest change of P
    4pDEER 9 → 9 47 → 47 — identical identical
    4pDEER long trace 9 → 9 54 → 54 — identical identical
    4pDEER fitted with pathways=[1,3] (refocusing time of pathway 3 at 0) 17 → 9 107 → 66 0.59 → 0.33 s 0.08σ 0.29σ
    5pDEER 11 → 10 72 → 72 0.00σ 0.01σ
    4pDEER complex 9 → 9 55 → 57 0.08σ 0.08σ

    Overlap with the ground truth: 4pDEER [1,3] 0.914 → 0.919, complex 0.934 → 0.933, others unchanged.

  • Tests: the full suite passes (617 tests).

Benchmark Before (s) After (s) Change
4pDEER three pathways (new benchmark, see "Benchmarks added") 0.688 0.477 −31%
5pDEER multiple pathways 0.438 0.419 −4%
4pDEER complex-valued data 0.316 0.340 +8% (2 more model evaluations on the new optimization path)
4pDEER compactness 2.663 2.741 +3%
other benchmarks (results identical) within ±1% (noise)

The benchmarks existing at this point had no parameter at or near 0. The new test_4pdeer_3pathways benchmark (pathway 3 refocuses at 0) covers this case.

11. Fix the profile-analysis benchmark and profile confidence intervals

  • Benchmark (benchmarks/bench_bootstrap.py): test_4pdeer_profile_analysis could never pass.
    • It passed alpha=0.05 to profile_analysis, which forwards unknown keywords to fit and on to snlls: TypeError.
    • Its checks used results.P and results.PUncert, but profile_analysis returns a dict with one UQResult per non-linear parameter.
    • It now profiles all non-linear parameters with 10 grid points each (nprofile) and checks that each 95% profile confidence interval contains the true value of the simulation. The true values are now stored in the data_4pdeer fixture as truth.
    • The benchmark is in the bootstrap group and listed in benchmarks/readme.md.
  • Bug fix in UQResult.ci for profile results (classes.py): ci() failed for every result returned by profile_analysis (TypeError: string indices must be integers). profile_analysis stores a single profile as a dict and the fitted value as a scalar, while ci() iterated over the profiles as a list and indexed the fitted value. Both cases are now handled, as pardist already did. New test test_confidence_intervals in test/test_profile_analysis.py (fails before the fix, passes after).
  • On the benchmark data, the profile intervals contain the true values: mod [0.224, 0.469] (true 0.35), reftime [0.297, 0.305] (0.3), conc [19.6, 34.1] (30).
  • Tests: the full suite passes (618 tests).

12. Warm-start the bootstrap and profile fits

  • Bootstrap (fit.py): the fits of the resampled datasets started from the model's par0, like the original fit. The resampled data are close to the original data, so they now start from the fitted non-linear parameters of the original fit. α is still optimized in every sample, so the bootstrap still includes the variability of α (fixing α would be 3× faster but narrowed the bootstrap spread by 14% on 4pDEER, so it is not done).

  • Profile analysis (profile_analysis.py): the fits along each profile now start from the fitted values of the free non-linear parameters. This is done by setting the model parameters' par0 for the duration of the analysis and restoring them afterwards (also on error), unless the user passes par0. The profiling loop moved into a private helper _profile_parameters for that.

  • Effect (4pDEER, 20 bootstrap samples, seeded; profile with 10 grid points per parameter):

    Analysis α searches least_squares evaluations Time (1 core)
    Bootstrap 172 → 102 273 → 203 6.06 → 4.08 s
    Profile analysis 173 → 136 284 → 272 6.28 → 5.15 s
  • Results: the warm-started fits converge to the same optima within the optimizer's tolerance.

    • Bootstrap: the original fit (sample 0) is identical. In the resampled fits, the non-linear parameters moved by at most 0.32 sample standard deviations, and the typical P element by 0.06. The largest change of a single P element was 1.33 sample standard deviations, in one sample at 5.7 nm, in the tail of the distribution, together with a change of conc (25.2 → 27.1); this is the flat direction between concentration and distribution tail. Confidence intervals: mod [0.338, 0.358] → [0.338, 0.357], reftime unchanged to 10⁻⁴, conc [17.7, 45.0] → [18.5, 44.3]; P and its CI change by at most 0.5% of max(P).
    • Profile analysis: the profile objective changed by at most 1.3×10⁻³ relative and is lower (a better optimum) at 20 of the 30 grid points. CIs: mod unchanged, reftime [0.2972, 0.3052] → [0.2968, 0.3052], conc [19.64, 34.15] → [19.59, 34.07].
  • Tests: the full suite passes (618 tests).

Benchmark Before (s) After (s) Change
Bootstrap, 1 core 6.09 4.12 −32%
Bootstrap, 4 cores 2.67 2.02 −24%
Profile analysis 6.28 5.17 −18%

Benchmarks added

  • test_4pdeer_complex (bench_fitting.py, fixture data_4pdeer_complex): 4pDEER with complex-valued data, as acquired in quadrature. The signal has a receiver phase of π/5 and independent noise on the real and imaginary channels. The model is dipolarmodel multiplied by exp(−i·phase), with the phase fitted as an extra non-linear parameter. Besides the distribution overlap, the benchmark checks that the fitted phase is within 0.05 rad of the true phase. It covers the complex-valued code paths in snlls and UQResult.propagate.
  • test_4pdeer_3pathways (bench_fitting.py, fixture data_4pdeer_3pathways): 4pDEER with three dipolar pathways, simulated and fitted with ex_4pdeer(..., pathways=[1,2,3]) (amplitudes 0.35, 0.05, 0.05; refocusing times τ1, τ1+τ2, 0). Pathway 3 refocuses at t=0, so its refocusing time is a parameter at 0, the case of section 10. Checks the distribution overlap (> 0.9; 0.92 obtained).

HKaras and others added 30 commits December 5, 2022 15:36
* Increase version number and update changelog (JeschkeLab#455)

* Bugfixes 4th sep (JeschkeLab#460)

* Fix normalisation in rice model

Closes JeschkeLab#459

* Remove three spin anaysis

Closes JeschkeLab#427

* Improved installation instructions

* Caution about difference in definition of cost function

Closes JeschkeLab#450

* Bump Version

* Bug for non linearly constrained problems

When a problem is not linearly constrained and not non-negative, the linear solver outputs a result class not the solution.

* Keeping changelog up-to date

* Fixing Sophgrid bug (JeschkeLab#464)

* Fixing Sophgrid bug

* Add unit test for sophgrid

* Update changelog.rst for new release (JeschkeLab#466)
* Fixing Sophgrid bug

* Add unit test for sophgrid

* Minor doc update

* Bump version Number

* Remove unnecessary doc files

* Update changelog
* Seperate Kinterpolator into its own function

Interpolation in Scipy is very slow, currently the same interpolation is being rerun for every calculation of the dipolarkernal. This is now cached to speed it up.

* Only run orientation selection on grid and integral based kernals

This hunk of code is not needed when fresnel integrals are used so does not need to be evaluated

* Update changelog
* Update for 3.12

* Updated workflows and changelog

* Upload to 3.12
* Update for 3.12

* Updated workflows and changelog

* Upload to 3.12

* Numpy 2.0 compatibility updates

* Update Changelog
* Update for 3.12

* Updated workflows and changelog

* Upload to 3.12

* Fix bug in regparam grid search

Regparam would never build the grid correctly. Now using grid or Brent is automatically determined from number of elements in the regparamrange.

* Add extra error messages

* Update changelog

* Updated Example

* Updated test

The test has been updated. The previous convergence criteria was unreliable and only worked based on a coincidence.

* Prepare For Release

* Remove duplicate python version
- ~25% speed-up on fitting
- Fixes issues due to arrays > 1000 elements being cut or small difference being rounded
@HKaras
HKaras requested a review from stestoll December 3, 2026 11:06
@HKaras HKaras added this to the V1.3 milestone Dec 3, 2026
@HKaras HKaras added performance bugfix Patches something that isn't working labels Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Patches something that isn't working performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants