Skip to content

Move matrix-free HVP carriers out of Piccolo (→ Piccolissimo #214)#254

Merged
jeonghun-jj-lee merged 6 commits into
mainfrom
feat/ket-fidelity-knot-hvp-carrier
Jul 6, 2026
Merged

Move matrix-free HVP carriers out of Piccolo (→ Piccolissimo #214)#254
jeonghun-jj-lee merged 6 commits into
mainfrom
feat/ket-fidelity-knot-hvp-carrier

Conversation

@Rchari1

@Rchari1 Rchari1 commented Jul 4, 2026

Copy link
Copy Markdown
Member

Move matrix-free HVP carrier construction out of public Piccolo → Piccolissimo

Public Piccolo should carry only objective/loss definitions, not the solver-specific matrix-free per-knot HVP construction. That construction (and its consumer) belongs in Piccolissimo's altissimo_backend.jl. This PR removes all matrix-free carrier code from Piccolo; the construction moves to harmoniqs/Piccolissimo.jl#214 (FidelityCarriers module), which this pairs with.

Removed from src/control/objectives.jl

  • _ket_infidelity_knot_hvp (added earlier in this PR's history) — ket-infidelity rank-2 factor.
  • _coherent_ket_lowrank_factor and _unitary_lowrank_factor (pre-existing on main) — coherent-ket and unitary rank-2 factors.
  • Every knot_hvp = … attachment on KetInfidelityObjective, CoherentKetInfidelityObjective, UnitaryInfidelityObjective.
  • The weights kwarg on CoherentKetInfidelityObjective (weighted variant now lives in Piccolissimo).
  • The 4 knot_hvp matrix-free testitems.

Result

Piccolo objectives are carrier-freeknot_hvp(obj, traj) === nothing — carrying only the loss physics, exactly as before the carrier work. Correctness is unchanged: outside the Altissimo backend a carrier-free objective takes the dense/ForwardDiff HVP.

No speed regression for default solver runs. When a carrier-free ket / coherent-ket / full-op unitary objective goes through the Altissimo backend (harmoniqs/Piccolissimo.jl#214), the backend now auto-attaches the analytic rank-2 carrier: it rebuilds and self-validates the factor from the trajectory goals — bit-identical to the old declared carrier — so ALL THREE objective types that declared carriers on main (ket, coherent-ket, full-op unitary) keep the pre-refactor wall time at any problem size and skip the expensive nested-ForwardDiff rank probe. EmbeddedOperator unitaries stay on the fallback — exact parity with main, which also never gave them a carrier. Verified end-to-end: i=2 default run (carrier-free objective + auto-attach) reproduces the pre-refactor solve bit-identically — fid 0.99930377 to all printed digits, outer trajectory identical, wall 887.6 s vs banked 909.5 s. Campaign runs needing the weighted-coherent objective build it explicitly from Piccolissimo's FidelityCarriers constructors. The backend consumption seam (knot_hvp(obj, template)) is untouched.

Verified (rqpnn validate_carrier_refactor.jl): Piccolo coherent objective carrier-free; Piccolissimo constructors attach ConstantLowRankHVP; ket + weighted-coherent F-form and Hessian identities vs ForwardDiff at 4.4e-16 / 1.1e-16.

🤖 Generated with Claude Code

Rchari1 and others added 2 commits July 4, 2026 16:19
…ective

The per-ket infidelity ℓ = |1 − |⟨g|ψ⟩|²| has a constant rank-2 Hessian
Aᵀ·(−2·sign(1−F)·I)·A with A = [gᵣᵀ gᵢᵀ; −gᵢᵀ gᵣᵀ] (F = ‖A·ψ̃‖² = |⟨g|ψ⟩|²
in block-iso layout). Declaring it via the DTO KnotHVP carrier seam
(:neg2_sign link rule, consumed by Piccolissimo #188/#190) bypasses the
nested-ForwardDiff per-knot rank probe and the per-iterate FD
refactorization — O(m²) per state term, measured 91 min at i=5 scale
(d=12376, K=64) vs ~2 min at i=4.

Gate (rqpnn validate_ket_knot_hvp.jl): F-form and Hessian identities at
1.1e-16 vs ForwardDiff on both sides of the F=1 sign flip; carrier present
on all per-ket terms via SplinePulseProblem(coherent=false); end-to-end
GPU solve healthy.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ket anchor terms

The unweighted coherent overlap abandons expensive minority kets (measured
at i=4 Stage-2: hard kets 0.9997→0.0018 while 30 easy kets aligned — the
same collapse behind the historical i=3 0.765 ceiling). Kets with weight
above the minimum now get dedicated per-ket infidelity anchors scaled by
the excess weight; phase-free terms the majority gradient cannot cancel.
Uniform weights ⇒ behavior unchanged. Both term types carry the CLRH
carrier (fast analytic path).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Rchari1 and others added 3 commits July 5, 2026 06:15
F = |Σ wᵢ⟨gᵢ|ψᵢ⟩ / Σw|². The unweighted sum abandons an expensive minority
(i=4 Stage-2 measured: hard kets 0.9997→0.002 at N=14 and →0.03 at N=20 while
easy kets aligned; the mechanism behind the historical i=3 0.765 ceiling) and
external per-ket anchors wedge when already satisfied. Weights reshape the
optimum itself; the CLRH factor scales per-ket blocks by wᵢ/Σw so the carrier
(Hessian + analytic gradient) carries through exactly. Uniform weights
reproduce the original objective bit-for-bit. _ensemble_ket_objective now
passes the ensemble weights through (replaces the anchor-term approach).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ccolissimo

Strips all matrix-free per-knot HVP carriers from the public package: the ket
carrier added in this PR plus the pre-existing coherent-ket and unitary
low-rank factors (_coherent_ket_lowrank_factor, _unitary_lowrank_factor), every
knot_hvp= attachment, the weighted-coherent kwarg, and the 4 carrier testitems.
Piccolo objectives are now carrier-free (knot_hvp === nothing) — only the
objective/loss physics remain. The construction lives in Piccolissimo's
FidelityCarriers module next to its consumer in altissimo_backend.jl
(harmoniqs/Piccolissimo.jl#214); solver runs build carrier-bearing objectives
from there. Public users get the dense/FD fallback, unchanged correctness.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Rchari1 Rchari1 changed the title Declare ConstantLowRankHVP carrier on KetInfidelityObjective (kills the FD rank probe) Move matrix-free HVP carriers out of Piccolo (→ Piccolissimo #214) Jul 6, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jeonghun-jj-lee

Copy link
Copy Markdown
Contributor

lgtm!

@jeonghun-jj-lee jeonghun-jj-lee merged commit c34c337 into main Jul 6, 2026
8 checks passed
@jeonghun-jj-lee jeonghun-jj-lee deleted the feat/ket-fidelity-knot-hvp-carrier branch July 6, 2026 21:25
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