Skip to content

Add expectation and trace to tableau python bindings#176

Open
david-pl wants to merge 1 commit into
mainfrom
feat/generalized-tableau-trace-expect
Open

Add expectation and trace to tableau python bindings#176
david-pl wants to merge 1 commit 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 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)
}
Comment on lines +214 to +216
Args:
word: A Pauli string such as ``"ZZ"`` or ``"X0Y1"`` (underscores
are ignored).
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://QuEraComputing.github.io/ppvm/pr-preview/pr-176/

Built to branch gh-pages at 2026-07-09 10:00 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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