Skip to content

ppvm-pauli-word-2 Patch - #246

Open
JonhasA wants to merge 7 commits into
mainfrom
trait-2/ppvm-pauli-word
Open

JonhasA wants to merge 7 commits into
mainfrom
trait-2/ppvm-pauli-word

Conversation

@JonhasA

@JonhasA JonhasA commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

This patch introduces the ppvm-pauli-word-2 crate from #204. On top of the crate shown in that PR, this patch also includes the following:

  • Separate parsing and formatting, phase representation, hashing, and gate operations into into modules
  • Reject construction beyond backing-storage capacity, including identity-only strings.
  • Reject mixed-width multiplication and column insertion/replacement.
  • Enforce logical qubit bounds in column toggles, Clifford gates, and symplectic mutations.
  • Reject identical qubits in two-qubit Clifford gates before mutation.
  • Removed Clone for PauliStorage

…er for functionality on parsing pauli words and str formatting. cleaned up current set of files including more descriptive names, removing unnecessary allocations, and correcting stale comments
@JonhasA
JonhasA requested review from Roger-luo and david-pl October 8, 2026 20:47
@github-actions

github-actions Bot commented Oct 8, 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-246/

Built to branch gh-pages at 2026-10-08 21:15 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@david-pl david-pl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@JonhasA this looks very clean, thank you. Just some minor things regarding assert! vs debug_assert! and I'm not sure if we want a way to disable hashing.

{
#[inline(always)]
fn x_bit(&self, i: usize) -> bool {
debug_assert!(i < self.nqubits, "index {i} out of bounds");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One inconsistency I notice here is that we have assert! in some places and debug_assert! in others. Not sure which one we want.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IMO, we should probably keep it at as a debug_assert. This way, there's no runtime impact at release mode. If the assertion were to fail, the program would have failed anyways. The rust compiler is pretty great at giving error messages, so I think we can get away with just having debug_asserts

debug_assert!(i < self.nqubits, "index {i} out of bounds");
if self.xbits[i] != v {
self.xbits.set(i, v);
self.refresh_hash();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There won't be a use-case with the upcoming refactor, but I still want to point this out: if we ever want to do operations on PauliWord in a hot-path, but don't need it to be indexable, hashing can be a significant overhead. I noticed this when implementing the current version of the generalized tableau, which didn't need its rows to be hashable. So I hacked around it by implementing a new word type which just has a no-op for hashing.

I don't see a place we need it right now, but this is something to be aware of. Do we want to have a convenience function to turn this off? I understand that the current implementation should guarantee that PauliWord can be used as a key in a hash map. That would break that guarantee.

{
#[inline]
fn x(&mut self, q: usize) {
assert!(q < self.nqubits, "qubit {q} out of bounds");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the performance impact of having assert! here? Without it, this function gets eliminated entirely, so it has to be at least a little bit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

assertion expressions are kept in both release and debug builds for a crate. Whereas debug assertions are no-opt in release mode, so there's no runtime impact in release mode. With assertion however, because this is kept in, latency does worsen. I'll have to profile this.

This branch has not been deployed

No deployments
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