Skip to content

Add expectation and trace to tableau python bindings#176

Merged
david-pl merged 3 commits into
mainfrom
feat/generalized-tableau-trace-expect
Jul 15, 2026
Merged

Add expectation and trace to tableau python bindings#176
david-pl merged 3 commits into
mainfrom
feat/generalized-tableau-trace-expect

Conversation

@david-pl

@david-pl david-pl commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This wasn't added as part of #172, but should be exposed in python too.

Copilot AI review requested due to automatic review settings July 9, 2026 09:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Exposes the Rust GeneralizedTableau Pauli expectation (⟨ψ|P|ψ⟩) and summed-pattern trace (Σ⟨ψ|P|ψ⟩) APIs through the Python bindings, and adds Python tests to validate basic correctness on small states (|0⟩, |+⟩, Bell, and a single-qubit ry rotation).

Changes:

  • Added GeneralizedTableau.expectation(word: str) -> float and GeneralizedTableau.trace(pattern: str) -> float to the Python wrapper.
  • Extended the native PyO3 interface to call inner.expectation(...) / inner.trace(...).
  • Added pytest coverage for expectation/trace on representative states and patterns.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ppvm-python/test/generalized_tableau/test_expectation.py Adds Python tests for expectation and trace on
ppvm-python/src/ppvm/generalized_tableau.py Adds Python-level convenience methods + docstrings for expectation and trace.
ppvm-python/src/ppvm/_core.pyi Updates native-module type stubs to include expectation and trace.
crates/ppvm-python-native/src/interface_tableau.rs Adds PyO3 methods to expose expectation/trace from the Rust tableau.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/ppvm-python-native/src/interface_tableau.rs
Comment thread crates/ppvm-python-native/src/interface_tableau.rs
Comment thread ppvm-python/src/ppvm/generalized_tableau.py Outdated
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-15 07:49 UTC

The GeneralizedTableau.expectation docstring advertised "X0Y1" (which
panics on the digit) and claimed underscores are ignored (they are
dropped from bit placement but still inflate nqubits). Document the
actual accepted syntax: a dense I/X/Y/Z string whose length equals the
qubit count.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 10, 2026 07:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread crates/ppvm-python-native/src/interface_tableau.rs
Comment thread ppvm-python/test/generalized_tableau/test_expectation.py
@david-pl
david-pl enabled auto-merge (squash) July 15, 2026 07:42
Copilot AI review requested due to automatic review settings July 15, 2026 07:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +87 to +91
/// `⟨ψ|word|ψ⟩` for the multi-qubit Pauli string `word`.
pub fn expectation(&self, word: String) -> f64 {
let w: PauliWord<<$type as Config>::Storage> = word.into();
self.inner.expectation(&w)
}
Comment on lines +93 to +97
/// `Σ_{P matches pattern} ⟨ψ|P|ψ⟩`.
pub fn trace(&self, pattern: String) -> f64 {
let pat: PauliPattern = pattern.into();
self.inner.trace(&pat)
}
@david-pl
david-pl merged commit cb642e4 into main Jul 15, 2026
14 checks passed
@david-pl
david-pl deleted the feat/generalized-tableau-trace-expect branch July 15, 2026 07:49
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.

3 participants