Skip to content

Fix variance SpaceMismatch for mixed-scalartype MPOHamiltonians (#524) - #529

Merged
lkdvos merged 1 commit into
mainfrom
issue-524
Sep 25, 2026
Merged

lkdvos merged 1 commit into
mainfrom
issue-524

Conversation

@lkdvos

@lkdvos lkdvos commented Sep 25, 2026

Copy link
Copy Markdown
Member

Summary

  • +/- for MPOHamiltonians required identical Jordan-tensor types on both sides, so combining a real-scalartype Hamiltonian with a complex-scalartype one (as variance does internally) fell through to a generic array + that can't reconcile differing Jordan-block virtual spaces, causing SpaceMismatch. Fixed by adding promote_rules for JordanMPOTensor/FiniteMPOHamiltonian/InfiniteMPOHamiltonian, and promoting storage type in the vector-shift + as well.
  • variance(::FiniteMPS, ...) now centers H on its expectation value before squaring (matching the InfiniteMPS branch), avoiding catastrophic cancellation from computing ⟨H²⟩ - ⟨H⟩² directly.

Closes #524.

🤖 Generated with Claude Code

…524)

`+`/`-` for `MPOHamiltonian`s required identical Jordan-tensor types on both
sides, so combining a real-scalartype Hamiltonian with a complex-scalartype
one (as `variance` does internally) silently fell through to a generic
array `+` that can't reconcile differing Jordan-block virtual spaces. Add
`promote_rule`s so mismatched Hamiltonians promote before combining, and fix
the vector-shift `+` to promote storage type against the shift's eltype too.

Also centers `variance(::FiniteMPS, ...)` on the energy before squaring,
matching the `InfiniteMPS` branch, to avoid catastrophic cancellation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@lkdvos
lkdvos merged commit 90ecc5f into main Sep 25, 2026
4 of 70 checks passed
@lkdvos
lkdvos deleted the issue-524 branch September 25, 2026 22:21
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.

variance() throws SpaceMismatch for real-scalartype long-range InfiniteMPOHamiltonian

1 participant