Skip to content

feat: add sim/pauli package for arbitrary Pauli expectation values#2

Merged
splch merged 4 commits intomainfrom
feat/pauli-expectation-values
Mar 12, 2026
Merged

feat: add sim/pauli package for arbitrary Pauli expectation values#2
splch merged 4 commits intomainfrom
feat/pauli-expectation-values

Conversation

@splch
Copy link
Copy Markdown
Owner

@splch splch commented Mar 11, 2026

Add Pauli algebra types (PauliString, PauliSum) with symplectic encoding and efficient expectation value computation for both statevector and density matrix simulators. Enables Hamiltonian energy evaluation and variational workflows beyond the existing Z-only ExpectationValue.

  • Statevector: O(2^n) single-pass via bitmask phase trick, parallel at 17+ qubits
  • Density matrix: O(2^n) reading one element per row of rho
  • Shot-based: Z-basis parity estimation from measurement counts
  • Wrapper methods on both Sim types: ExpectPauliString, ExpectPauliSum
  • Z-only ExpectationValue added to density matrix for statevector parity

Add Pauli algebra types (PauliString, PauliSum) with symplectic encoding
and efficient expectation value computation for both statevector and
density matrix simulators. Enables Hamiltonian energy evaluation and
variational workflows beyond the existing Z-only ExpectationValue.

- Statevector: O(2^n) single-pass via bitmask phase trick, parallel at 17+ qubits
- Density matrix: O(2^n) reading one element per row of rho
- Shot-based: Z-basis parity estimation from measurement counts
- Wrapper methods on both Sim types: ExpectPauliString, ExpectPauliSum
- Z-only ExpectationValue added to density matrix for statevector parity
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4be9916bd2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sim/statevector/sim.go
Comment thread sim/densitymatrix/sim.go
splch added 3 commits March 11, 2026 17:13
Every package now has a dedicated doc.go with [Symbol] cross-references,
bulleted lists, and code examples following godoc best practices. Also
fixes pre-commit hook to handle separate Go modules (braket, otelbridge,
prombridge).
Groups changed packages by their nearest go.mod and runs a single
go vet invocation per module instead of one per directory.
…dge case tests

Fix 5 bugs found during full codebase audit:

- (critical) densitymatrix gate2ColsParallel used conjugate-transpose
  instead of element-wise conjugate, producing wrong results for
  non-symmetric 2Q gates at >=9 qubits
- (medium) ExpectPauliString/ExpectPauliSum lacked qubit count
  validation, causing index-out-of-range panics on mismatch
- (low) MergeRotations had no default case for unexpected rotation axis
- (low) Parser implicit measurement silently referenced nonexistent
  classical bits when numClbits < numQubits

Also fix pre-commit hook to avoid bash 4+ associative arrays (declare -A)
which fail on macOS default bash 3.2 and zsh.

Add ~60 new tests across 17 packages including first-ever coverage for
circuit/ir, regression tests for the parallel kernel fix, and edge case
tests for zero-shot runs, empty circuits, boundary conditions, and
error paths.
@splch splch merged commit ac55066 into main Mar 12, 2026
6 checks passed
@splch splch deleted the feat/pauli-expectation-values branch March 12, 2026 00:48
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