Skip to content

Add snapshot-based balanced POD for continuous-time LTI systems - #219

Open
TommyDanMa wants to merge 1 commit into
SciML:mainfrom
TommyDanMa:feat/bpod-pr
Open

TommyDanMa wants to merge 1 commit into
SciML:mainfrom
TommyDanMa:feat/bpod-pr

Conversation

@TommyDanMa

@TommyDanMa TommyDanMa commented Nov 14, 2026 •

Copy link
Copy Markdown

Summary

Adds snapshot-based Balanced Proper Orthogonal Decomposition (BPOD) for continuous-time linear time-invariant systems, using Rowley's (2005) direct primal/adjoint snapshot formulation.

Related to #11.

The new public function is:

bpod(A, B, C, X, Y, D = nothing; n = nothing, atol = 0, rtol = 1e-3)

It accepts already-weighted primal and adjoint snapshot factors, computes the SVD of Y' * X, and constructs the balanced Petrov-Galerkin projectors and reduced system.

The result reuses the existing BalancedTruncation type, containing reduced A, B, C, D, retained approximate Hankel singular values, and the left/right projectors.

The implementation:

  • Follows the order-selection and numerical-rank conventions of baltrunc.
  • Supports Float32, Float64, compatible mixed precision, and common sparse/banded matrix representations.
  • Validates dimensions, finite inputs, and numerical rank.
  • Includes a documented end-to-end example generating quadrature-weighted impulse snapshots.

Numerical validation

Tests cover:

  • Agreement with classical balanced truncation using exact Gramian factors.
  • Independent Cholesky-based balancing identities and full-order transfer-function equivalence.
  • Convergence using forward and adjoint impulse snapshots.
  • Coarse quadrature as a negative control: biorthogonality alone does not establish accurate balancing.
  • Reduced frequency-response comparisons.
  • Rank-deficient factors, unequal snapshot counts, repeated singular values, input validation, precision, and structured matrix storage.
  • Cases where poor finite-horizon snapshots produce unstable reduced models.

Validation status

The full Core suite and documentation build remain blocked by the unrelated MethodOfLines 1.6 incompatibility documented in #216. PR #218 proposes a fix. The same DEIM failure was reproduced on the upstream baseline without these BPOD changes.

The complete documentation build, including final rendering and link checks, has therefore not been verified.

Scope and limitations

This PR implements the snapshot-based reduction core. The caller supplies weighted factors X and Y; snapshot generation, ODE integration, analytic tail correction, and ModelingToolkit integration are outside the scope.

The dense interaction SVD may become expensive when snapshot counts are large. Finite-horizon and quadrature errors affect the reduced model, and stability is not guaranteed for approximate factors.

I would particularly welcome maintainer feedback on whether this low-level snapshot-factor API is the appropriate initial scope for #11, and whether automatic snapshot generation should be considered as a follow-up PR.

@TommyDanMa
TommyDanMa marked this pull request as ready for review November 14, 2026 19:17
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #219

Reviewed head: 52f33cb
Raw SHA-256: 0c43ed6a1dc54f3e1daf70ea6a208e0d20cabf09045055cec4c6c194785b4ab5
Source SHA-256: c179653cbca767ef866ad17d2c11abfba7a111a4a4c2370432ef813d2763f047
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1ffc4-6950-7d61-9310-75819be5afb6
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium-low (ML7)
  • Verdict: CHANGES
  • Reviewed head: 52f33cb

Review report

VERDICT: CHANGES
Round: 1
Head: 52f33cb
Slot: 1
CI: CI unreadable; review only; merge gates unchanged
Session: 01a1ffc4-6950-7d61-9310-75819be5afb6
Reviewer: codex-cli 0.170.0; model: gpt-6.2-sol

Risk

medium-low (ML7: additive bpod API with a docstring, rendered documentation entry, and numerical tests)

Blocking findings

  • Blocking priorities: P1, P2, P2
  • [P1] src/bpod.jl:194 Mixed precision rejects valid single-output row matrices. With Float64 A, X, and Y, both C = Float32[1, 0]' and transpose(Float32[1, 0]) threw MethodError for _coerce_operator(::Vector{Float32}, ::Type{Float64}). The Float64 row produced the expected reduced output coefficient 1.0. The wrapper branch recurses into a vector, while the helper accepts only matrices. Convert the wrapper with a storage-preserving array conversion and add regression tests for both row forms.
  • [P2] src/bpod.jl:186 Projection can silently return an infinite pole from finite inputs with a representable exact result. For a one-state system with A = -1e300, X = 1e100, Y = 1e-100, B = sqrt(-2A) * X, and C = sqrt(-2A) * Y, the exact one-state projection has pole -1e300 and DC gain about 2. The probe returned pole -Inf and gain 0.0 because A * Tr overflowed. Use a scale-aware projection or reject non-finite reduced coefficients explicitly, and cover this case.
  • [P2] src/bpod.jl:226 The finiteness check inspects padding in SymTridiagonal. SymTridiagonal(Float32[-1, -2], Float32[0.25, NaN]) materialized as a finite matrix, but bpod rejected it with A contains non-finite entries. The final off-diagonal storage element is outside the matrix. Validate the logical diagonals, for example with diag(A) and diag(A, 1), and test this storage layout.

Non-blocking findings

  • test/bpod.jl:111 The H₂ helper masks the sign of the computed energy. A scratch mutation that negated the trace produced the same 0.2886751345948129 for a scalar difference with analytic energy 1/12. Check the signed trace and allow a clamp to zero only within a justified roundoff bound.
  • src/bpod.jl:174 A valid integer type can escape the documented error path. n = big(typemax(Int)) + 1 raised InexactError in the order helper. Compare n against the available rank before narrowing it to Int.
  • src/bpod.jl:35 and docs/src/tutorials/balanced_pod.md:21 claim the SVD dominates the cost. From the matrix dimensions, forming Y' * X costs O(nx * nX * nY) and can dominate when the state count is much larger than both snapshot counts. State the two costs and qualify the claim.

What I ran

  • Julia 1.12.4 with the review depot preserved. GROUP=Core julia --project -e 'using Pkg; Pkg.test()' passed bpod 190/190 and balanced truncation 15/15, then stopped at test/deim.jl:50 with DimensionMismatch: solution states must match the system unknowns. Core passed on current origin/main, including DEIM 77/77. With the PR test dependencies at the actual merge base, the same DEIM call failed with 12 snapshot rows and 2 symbolic unknowns. Current origin/main counts scalar unknowns for this check.
  • GROUP=QA julia --project -e 'using Pkg; Pkg.test()' passed JET 5/5 and package QA 21/21.
  • julia --project=docs docs/make.jl passed on current origin/main. Both PR-head runs stopped before rendering after the existing DEIM tutorial hit the same DimensionMismatch at docs/src/tutorials/deim_FitzHugh-Nagumo.md:137. All five balanced POD tutorial blocks ran in isolation.
  • Package probes (julia --project ../operators.jl and julia --project ../probes.jl) reproduced the blocking cases. The independent closed-form impulse-spectrum and transfer-map probe passed 13/13 checks on unequal grids. Its error against the exact finite-horizon spectrum decreased from 0.07260 to 0.001223 over three step halvings.
  • git diff --check, Runic in check mode on changed Julia files, and typos on changed files passed. uv run --locked python --version printed Python 3.13.13 and warned that --locked had no effect outside a Python project. This Julia checkout has no uv.lock.

What I did not verify

  • The remaining PR-head Core tests after the DEIM error and the rendered PR documentation. I stopped a duplicate Core run after more than 27 minutes in dbdsqr through the existing TSVD path, as observed in two debugger snapshots. That run produced no second Core result.
  • Other Julia versions and 32-bit execution.

AUTHOR_GRADE: {"task":"feature","score":3,"difficulty":3,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"The balanced POD and analytic convergence tests pass, but supported operator inputs fail and a finite scalar projection can silently return an infinite pole."}

Head link: 52f33cb


🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a1ffc4-6950-7d61-9310-75819be5afb6 (no session URL)

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants