pub struct PauliString { /* private fields */ }Expand description
A dense unsigned Pauli operator over len qubits, stored as XZ bit vectors.
Phaseless, with each site read as the Hermitian single-qubit Pauli it
names — a site carrying both bits is Y = iXZ, not the bare product XZ.
A product of Hermitian factors on distinct sites is Hermitian, so every
PauliString is a valid measurement observable or rotation axis by
construction; there is no phase to make it otherwise.
Operations between different widths treat missing trailing sites as
identities; XOR keeps the wider width.
Parse strings of I, _, X, Y, and Z with str::parse;
Display renders identity as _.
Implementations§
Source§impl PauliString
impl PauliString
Sourcepub fn new(num_qubits: usize) -> Self
pub fn new(num_qubits: usize) -> Self
Creates the identity Pauli string over num_qubits qubits.
Sourcepub fn from_terms(
num_qubits: usize,
terms: impl IntoIterator<Item = (usize, Pauli)>,
) -> Self
pub fn from_terms( num_qubits: usize, terms: impl IntoIterator<Item = (usize, Pauli)>, ) -> Self
Collects (index, pauli) terms into a string over num_qubits qubits.
Terms are assignments, not factors: a repeated index keeps the last Pauli given for it rather than multiplying the two.
§Panics
Panics if any index is >= num_qubits.
§Examples
use bloq_utils::{Pauli, PauliString};
let stabilizer = PauliString::from_terms(3, [(0, Pauli::Z), (2, Pauli::Z)]);
assert_eq!(stabilizer.to_string(), "Z_Z");Sourcepub fn commutes_with(&self, other: &Self) -> bool
pub fn commutes_with(&self, other: &Self) -> bool
Returns true if self and other commute as operators.
Two Pauli strings anticommute exactly when they anticommute on an odd
number of sites, which the symplectic form ⟨x, other.z⟩ + ⟨z, other.x⟩
counts mod 2.
The two strings need not name the same number of qubits. Where one runs
out the other is being compared against implicit identities, which
commute with everything — so the fold below stops at the shorter operand
rather than requiring equal widths. Going through the words directly is
also what avoids BitVec::dot, whose length assertion holds in release
builds and would turn a width mismatch into a panic.
§Examples
use bloq_utils::PauliString;
let xx = PauliString::try_from("XX")?;
let zz = PauliString::try_from("ZZ")?;
let zi = PauliString::try_from("Z_")?;
assert!(xx.commutes_with(&zz)); // two anticommuting sites
assert!(!xx.commutes_with(&zi)); // one
// Widths may differ; the shorter string ends in implicit identities.
let x_wide = PauliString::try_from("X___")?;
assert!(!x_wide.commutes_with(&PauliString::try_from("Z")?));
assert!(x_wide.commutes_with(&PauliString::try_from("_Z")?));Sourcepub fn product_phase(&self, other: &Self) -> u8
pub fn product_phase(&self, other: &Self) -> u8
Returns the power of i contributed by multiplying these strings.
Missing sites are identities.
Sourcepub fn x_words(&self) -> &[u64]
pub fn x_words(&self) -> &[u64]
The X components as u64 words, least-significant qubit first.
Word-level access for bit algebra over whole strings — the simulator’s
frame decomposition walks these directly rather than one site at a time.
Bits at or beyond len are always clear.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Returns whether every site is identity, stopping at the first nonzero word.
Sourcepub fn iter_support(&self) -> impl Iterator<Item = (usize, Pauli)> + '_
pub fn iter_support(&self) -> impl Iterator<Item = (usize, Pauli)> + '_
Iterates the non-identity sites in ascending index order.
§Panics
Panics if the packed X/Z representation contains an impossible support bit.
Trait Implementations§
Source§impl BitXor for &PauliString
impl BitXor for &PauliString
Source§impl BitXorAssign<&PauliString> for PauliString
impl BitXorAssign<&PauliString> for PauliString
Source§fn bitxor_assign(&mut self, other: &Self)
fn bitxor_assign(&mut self, other: &Self)
^= operation. Read moreSource§impl Clone for PauliString
impl Clone for PauliString
Source§fn clone(&self) -> PauliString
fn clone(&self) -> PauliString
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PauliString
impl Debug for PauliString
Source§impl Display for PauliString
impl Display for PauliString
impl Eq for PauliString
Source§impl FromStr for PauliString
impl FromStr for PauliString
Source§impl PartialEq for PauliString
impl PartialEq for PauliString
impl StructuralPartialEq for PauliString
Auto Trait Implementations§
impl Freeze for PauliString
impl RefUnwindSafe for PauliString
impl Send for PauliString
impl Sync for PauliString
impl Unpin for PauliString
impl UnsafeUnpin for PauliString
impl UnwindSafe for PauliString
Blanket Implementations§
§impl<T, BorrowedSelf> BitwiseMutViaBorrow<BorrowedSelf> for T
impl<T, BorrowedSelf> BitwiseMutViaBorrow<BorrowedSelf> for T
fn assign_index(&mut self, index: usize, to: bool)
fn negate_index(&mut self, index: usize)
fn clear_bits(&mut self)
fn assign_random(
&mut self,
bit_count: usize,
random_number_generator: &mut impl RngExt,
)where
BorrowedSelf: BitLength,
§impl<Bits, Other, BorrowedSelf, BorrowedOther> BitwisePairMutViaBorrow<Other, BorrowedSelf, BorrowedOther> for Bits
impl<Bits, Other, BorrowedSelf, BorrowedOther> BitwisePairMutViaBorrow<Other, BorrowedSelf, BorrowedOther> for Bits
fn assign(&mut self, other: &Other)
fn bitxor_assign(&mut self, other: &Other)
fn bitand_assign(&mut self, other: &Other)
fn bitor_assign(&mut self, other: &Other)
§impl<T, Other, BorrowedSelf, BorrowedOther> BitwisePairViaBorrow<Other, BorrowedSelf, BorrowedOther> for T
impl<T, Other, BorrowedSelf, BorrowedOther> BitwisePairViaBorrow<Other, BorrowedSelf, BorrowedOther> for T
§impl<T, BorrowedSelf> BitwiseViaBorrow<BorrowedSelf> for T
impl<T, BorrowedSelf> BitwiseViaBorrow<BorrowedSelf> for T
fn index(&self, index: usize) -> bool
fn weight(&self) -> usize
fn parity(&self) -> bool
fn is_zero(&self) -> bool
fn is_unit(&self, index: usize) -> bool
fn support<'a>(&'a self) -> impl SortedIteratorwhere
BorrowedSelf: 'a,
fn max_support(&self) -> Option<usize>
fn min_support(&self) -> Option<usize>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.