pub struct DetectorParity<M = u32> { /* private fields */ }Expand description
A mod-2 sum of DetectorTerms and a constant sign bit — the parity a
detector or observable checks.
Terms are held in a canonical form: sorted, with pairs that cancel removed, so equal parities compare and hash equally regardless of construction order.
Implementations§
Source§impl<M> DetectorParity<M>
impl<M> DetectorParity<M>
Sourcepub fn from_measurements(
measurements: impl IntoIterator<Item = M>,
) -> DetectorParity<M>
pub fn from_measurements( measurements: impl IntoIterator<Item = M>, ) -> DetectorParity<M>
Builds a parity from measurement ids, canonicalizing the result.
Sourcepub fn from_terms(
terms: impl IntoIterator<Item = DetectorTerm<M>>,
) -> DetectorParity<M>
pub fn from_terms( terms: impl IntoIterator<Item = DetectorTerm<M>>, ) -> DetectorParity<M>
Builds a parity from arbitrary terms, canonicalizing the result.
Sourcepub fn from_term_buf(terms: SmallVec<[DetectorTerm<M>; 2]>) -> DetectorParity<M>
pub fn from_term_buf(terms: SmallVec<[DetectorTerm<M>; 2]>) -> DetectorParity<M>
Like Self::from_terms, but takes the term buffer by value so
callers that already hold one (e.g. a completed flow’s measurements)
avoid rebuilding it element by element.
Sourcepub fn with_sign(self, sign: bool) -> DetectorParity<M>
pub fn with_sign(self, sign: bool) -> DetectorParity<M>
Sets the constant XOR term. true represents a negative stabilizer
sign, so a noiseless detector with odd raw measurement parity evaluates
to zero.
Sourcepub fn terms(&self) -> &[DetectorTerm<M>]
pub fn terms(&self) -> &[DetectorTerm<M>]
The canonicalized terms.
Sourcepub fn measurements(&self) -> impl Iterator<Item = M>
pub fn measurements(&self) -> impl Iterator<Item = M>
Measurement terms only, dropping loop-carried detector state.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true for the zero parity: no terms and no constant sign.
Sourcepub fn xor_assign(&mut self, other: &DetectorParity<M>)
pub fn xor_assign(&mut self, other: &DetectorParity<M>)
XORs other’s terms into self (mod-2 addition) and recanonicalizes.
Sourcepub fn map_measurements(self, f: impl FnMut(M) -> M) -> DetectorParity<M>
pub fn map_measurements(self, f: impl FnMut(M) -> M) -> DetectorParity<M>
Maps measurement terms in the existing buffer and recanonicalizes it.
Sourcepub fn try_map_measurements<N, E>(
&self,
f: impl FnMut(M) -> Result<N, E>,
) -> Result<DetectorParity<N>, E>
pub fn try_map_measurements<N, E>( &self, f: impl FnMut(M) -> Result<N, E>, ) -> Result<DetectorParity<N>, E>
Maps each measurement term through f, leaving loop-state terms intact,
and canonicalizes the result. Loop-state terms pass through unchanged.
§Errors
Returns the first error f produces.
Trait Implementations§
Source§impl<M> Clone for DetectorParity<M>where
M: Clone,
impl<M> Clone for DetectorParity<M>where
M: Clone,
Source§fn clone(&self) -> DetectorParity<M>
fn clone(&self) -> DetectorParity<M>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<M> Debug for DetectorParity<M>where
M: Debug,
impl<M> Debug for DetectorParity<M>where
M: Debug,
Source§impl<M> Default for DetectorParity<M>
impl<M> Default for DetectorParity<M>
Source§fn default() -> DetectorParity<M>
fn default() -> DetectorParity<M>
Source§impl<'de, M> Deserialize<'de> for DetectorParity<M>where
M: Deserialize<'de>,
impl<'de, M> Deserialize<'de> for DetectorParity<M>where
M: Deserialize<'de>,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<DetectorParity<M>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<DetectorParity<M>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<M> Display for DetectorParity<M>where
M: Display,
impl<M> Display for DetectorParity<M>where
M: Display,
impl<M> Eq for DetectorParity<M>where
M: Eq,
Source§impl<M> Hash for DetectorParity<M>where
M: Hash,
impl<M> Hash for DetectorParity<M>where
M: Hash,
Source§impl<M> PartialEq for DetectorParity<M>where
M: PartialEq,
impl<M> PartialEq for DetectorParity<M>where
M: PartialEq,
Source§impl<M> Serialize for DetectorParity<M>where
M: Serialize,
impl<M> Serialize for DetectorParity<M>where
M: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<M> StructuralPartialEq for DetectorParity<M>where
M: PartialEq,
Auto Trait Implementations§
impl<M> Freeze for DetectorParity<M>where
M: Freeze,
impl<M> RefUnwindSafe for DetectorParity<M>where
M: RefUnwindSafe,
impl<M> Send for DetectorParity<M>where
M: Send,
impl<M> Sync for DetectorParity<M>where
M: Sync,
impl<M> Unpin for DetectorParity<M>where
M: Unpin,
impl<M> UnsafeUnpin for DetectorParity<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for DetectorParity<M>where
M: UnwindSafe + RefUnwindSafe,
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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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.