Skip to content

test: cover periodic noise wrap, energy values, driving force, RK runaway, and minimizer failure paths - #1

Merged
pastewka merged 3 commits into
mainfrom
claude/test-coverage-analysis-rvoBc
Jun 9, 2026
Merged

pastewka merged 3 commits into
mainfrom
claude/test-coverage-analysis-rvoBc

Conversation

@pastewka

@pastewka pastewka commented Jun 9, 2026

Copy link
Copy Markdown
Member

Adds 10 tests targeting the largest untested behaviors:

  • FilteredNoise.PeriodicWrapAcrossManyCells: sample() must wrap query
    coordinates (negative and many periods out) back into the fundamental
    cell. Load-bearing for depinning/dynamics, which drive h through many
    periods of Ly; no prior test queried outside [0,Lx)x[0,Ly).
  • QewModel.ObjectiveFlatLineConstantPotential / ObjectiveSinusoidLinearElastic:
    pin the absolute value of objective() (dx weighting, noise-value term,
    driving-force sign) for both models against closed forms. The arclength
    energy value was previously checked nowhere; the gradient-consistency
    test is blind to all three.
  • Dynamics.DrivingForceShiftsEquilibrium: exercises the driving-force term
    in the integrated gradient (all prior dynamics tests used f=0).
  • Dynamics.ZeroDiffusionIgnoresSeed: pins that the thermal kick is gated on
    diff_coeff>0, so the zero-temperature path is deterministic.
  • RossoKrauth.RunawayFlagSetAboveThreshold: pins the runaway verdict the
    depinning executable keys f_c bracketing on (prior tests read only .blocked).
  • RossoKrauth.BlocksArclengthModel: arclength blocking correctness through
    rk_block (prior arclength coverage was determinism only).
  • Fire/Lbfgs.ReportsNonConvergence: the converged=false failure path callers
    branch on.
  • Lbfgs.ConvergesToHarmonicMinimumArclength: L-BFGS on the arclength model
    (all other L-BFGS tests used the linear model).

26 -> 36 tests, all passing.

claude added 3 commits June 8, 2026 12:49
…away, and minimizer failure paths

Adds 10 tests targeting the largest untested behaviors:

- FilteredNoise.PeriodicWrapAcrossManyCells: sample() must wrap query
  coordinates (negative and many periods out) back into the fundamental
  cell. Load-bearing for depinning/dynamics, which drive h through many
  periods of Ly; no prior test queried outside [0,Lx)x[0,Ly).
- QewModel.ObjectiveFlatLineConstantPotential / ObjectiveSinusoidLinearElastic:
  pin the absolute value of objective() (dx weighting, noise-value term,
  driving-force sign) for both models against closed forms. The arclength
  energy value was previously checked nowhere; the gradient-consistency
  test is blind to all three.
- Dynamics.DrivingForceShiftsEquilibrium: exercises the driving-force term
  in the integrated gradient (all prior dynamics tests used f=0).
- Dynamics.ZeroDiffusionIgnoresSeed: pins that the thermal kick is gated on
  diff_coeff>0, so the zero-temperature path is deterministic.
- RossoKrauth.RunawayFlagSetAboveThreshold: pins the runaway verdict the
  depinning executable keys f_c bracketing on (prior tests read only .blocked).
- RossoKrauth.BlocksArclengthModel: arclength blocking correctness through
  rk_block (prior arclength coverage was determinism only).
- Fire/Lbfgs.ReportsNonConvergence: the converged=false failure path callers
  branch on.
- Lbfgs.ConvergesToHarmonicMinimumArclength: L-BFGS on the arclength model
  (all other L-BFGS tests used the linear model).

26 -> 36 tests, all passing.
The three simulation executables were hardcoded main()s with no testable
seams, so their orchestration and HDF5 output were entirely uncovered.
Factor them into reusable, unit-tested units without changing behaviour:

- src/qew_runs.h: static_sweep / dynamic_anneal / depinning_ramp -- the
  pinning-length sweep, annealed-Langevin loop (timestep heuristic + anneal
  schedule), and Rosso-Krauth force ramp with f_c bracketing. Templated on
  the Noise functor (like the kernels), HDF5-free, loop bodies copied
  verbatim from the mains.
- src/qew_io.h: write_static / write_dynamic / write_depinning -- the HDF5
  dataset-key construction (a documented contract with the Python analysis
  scripts). Header-only, guarded by QEW_WITH_HDF5, not pulled into core lib.
- src/qew_format.h: the fmt() key helper, previously duplicated in all three
  mains.
- The mains are now config + call + write (+ the same console output).

tests/test_executables.cpp (7 tests): fmt() specs; static_sweep shape and
pinning_length->line_tension map; dynamic_anneal dt heuristic and
log-spaced snapshots; depinning_ramp f_c bracketing, runaway verdict, and
profile-only-when-blocked; and (HDF5) round-trip of all three writers
asserting the exact documented dataset keys and that runaway forces store
no profile.

Verified qew_static runs end-to-end and writes the documented key layout
(driving_force=.../pinning_length=.../h, length nx). 36 -> 43 tests.
…nches

These defensive branches are never hit by smooth convex problems, so they
were uncovered. To make them observable AND assertable, add two diagnostic
counters to LbfgsResult (n_curvature_skips, n_ls_restarts), consistent with
the existing n_func_evals, then force each path:

- CurvatureSkipForcedByLargeEps: curvature_eps = 1e30 makes the acceptance
  test sy > eps*sqrt(ss*yy) fail for every pair (Cauchy-Schwarz bounds
  sy <= sqrt(ss*yy)), so no (s,y) is stored. Asserts the skip counter fired
  and the solver still degrades gracefully to steepest descent and reaches
  the minimum. Mathematically robust across backends.

- LineSearchGivesUpWithNoHistory: max_ls = 0 -> the first steepest-descent
  step takes no trial and, with empty history, the solver returns
  converged=false at iteration 0 (the give-up branch). Deterministic.

- LineSearchRestartsOnStepFailure: a rough strong-noise landscape where a
  unit L-BFGS step overshoots by ~16x (needs ~5 Armijo backtracks) with
  max_ls clamped to 3 -> after history is built the line search exhausts its
  budget and hits the restart branch (discard history, retry as steepest
  descent). The overshoot is decisive (mls=1,2,3 all fire it; failures stop
  only at mls>=5), so the branch is reached with margin, not on an FP
  knife-edge. A control run at the normal max_ls=30 converges with zero
  restarts, confirming the restart is a safety net, not a routine path.

43 -> 46 tests.
@pastewka
pastewka merged commit 1bbb8e8 into main Jun 9, 2026
4 checks passed
@pastewka
pastewka deleted the claude/test-coverage-analysis-rvoBc branch June 9, 2026 05:52
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.

2 participants