Add expectation and trace to tableau python bindings#176
Open
david-pl wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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) -> floatandGeneralizedTableau.trace(pattern: str) -> floatto 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). |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This wasn't added as part of #172, but should be exposed in python too.