Skip to content

Fix QIS numerical edge cases and support Hamiltonian copy protocols - #55

Merged
jianjian01 merged 4 commits into
cq-lib:release/2.0from
jianjian01:release/2.0
Oct 8, 2026
Merged

jianjian01 merged 4 commits into
cq-lib:release/2.0from
jianjian01:release/2.0

Conversation

@jianjian01

Copy link
Copy Markdown
Collaborator

What Changed

  • Validate simulator dimensions and reject non-finite state data, with recoverable errors in Rust, Python, and C.
  • Fix noisy simulation to respect original qubit labels and apply identity-gate noise.
  • Stabilize Rényi entropy for small orders and rank-deficient states, validate Hermitian observables and finite coefficients, retain small evolution coefficients, and preserve global phase during ZNE
    folding.
  • Support copy.copy() and copy.deepcopy() for Python Hamiltonians, including independent copies and nested alias preservation.
  • Update English and Chinese API documentation, describe CQLib conventions directly, cite the original SABRE paper, and retain existing dependency and implementation references.

Why

These changes prevent invalid inputs from producing misleading results and correct numerical and simulation edge cases. Regression tests cover the affected behavior, including non-diagonal pure-state
entropy, sparse qubit labels, coefficient validation, and global phase.

How Tested

  • Python QIS suite: 1205 tests passed against a freshly built extension.
  • Related Rust QIS, ZNE, and regression tests: 567 passed.
  • C regression tests: 4 passed.
  • Compiler rewrite tests: 99 passed.
  • Each functional commit was validated independently from its staged source snapshot.
  • Rust formatting, Clippy, Ruff, spelling checks, and repository commit hooks passed.

Validate state dimensions and finite inputs before constructing simulators. Respect original qubit labels and identity-gate noise during noisy simulation.

Stabilize Renyi entropy, validate real observable expectations and variance, retain small evolution coefficients, and preserve global phase during ZNE folding. Include regression tests and matching Rust, Python, and C API documentation.

Validation: 16 core regression tests, 4 C regression tests, and 1200 Python QIS tests passed against the staged source snapshot. Rust formatting and Python formatting checks passed.
Implement copy.copy and copy.deepcopy using the existing owned-value clone. Include type declarations, English and Chinese documentation, and tests for empty operators, independent terms, and alias preservation in nested deepcopy.

Validation: all 58 Hamiltonian Python tests passed against an extension built from the staged source snapshot.
Describe endian ordering, release workflow organization, gate-basis tests, and phase conventions directly in terms of CQLib behavior. Cite the original SABRE paper and retain the existing commutative-cancellation implementation reference.

Validation: all 99 compiler rewrite tests passed. Runtime behavior is unchanged.
Use a square-root machine-epsilon tolerance for rotated pure-state formation entropy, while checking finite results and physical bounds. Null-space eigenvalue roundoff is amplified by square roots and varies between eigensolver backends.

Extract the existing concurrence-to-entropy calculation into a private helper and directly test clamping above one, below zero, and an interior value. Preserve the public API and numerical algorithm.

Validation on macOS: 36 entropy unit tests, 16 core regression tests, and 1205 Python QIS tests passed against a freshly built extension. Formatting, Ruff, and Clippy checks passed. Windows and Linux CI verification remains pending.
@jianjian01
jianjian01 merged commit 3955e6d into cq-lib:release/2.0 Oct 8, 2026
4 checks passed
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.

1 participant