pub struct ZXDiagram {
pub spiders: FxHashMap<usize, Spider>,
pub adjacency: FxHashMap<usize, Vec<(usize, EdgeType)>>,
pub inputs: Vec<usize>,
pub outputs: Vec<usize>,
/* private fields */
}
Expand description
ZX-diagram representation
Fields§
§spiders: FxHashMap<usize, Spider>
Spiders (nodes) in the diagram
adjacency: FxHashMap<usize, Vec<(usize, EdgeType)>>
Adjacency list representation of edges
inputs: Vec<usize>
Input boundary spiders (ordered by qubit)
outputs: Vec<usize>
Output boundary spiders (ordered by qubit)
Implementations§
Source§impl ZXDiagram
impl ZXDiagram
Sourcepub fn add_spider(&mut self, spider_type: SpiderType, phase: f64) -> usize
pub fn add_spider(&mut self, spider_type: SpiderType, phase: f64) -> usize
Add a spider to the diagram
Sourcepub fn add_boundary(&mut self, qubit: QubitId, is_input: bool) -> usize
pub fn add_boundary(&mut self, qubit: QubitId, is_input: bool) -> usize
Add a boundary spider
Sourcepub fn add_edge(&mut self, source: usize, target: usize, edge_type: EdgeType)
pub fn add_edge(&mut self, source: usize, target: usize, edge_type: EdgeType)
Add an edge between two spiders
Sourcepub fn remove_edge(&mut self, source: usize, target: usize)
pub fn remove_edge(&mut self, source: usize, target: usize)
Remove an edge between two spiders
Sourcepub fn neighbors(&self, spider_id: usize) -> Vec<(usize, EdgeType)>
pub fn neighbors(&self, spider_id: usize) -> Vec<(usize, EdgeType)>
Get the neighbors of a spider
Sourcepub fn remove_spider(&mut self, spider_id: usize)
pub fn remove_spider(&mut self, spider_id: usize)
Remove a spider and its edges
Sourcepub fn degree(&self, spider_id: usize) -> usize
pub fn degree(&self, spider_id: usize) -> usize
Get the degree (number of connections) of a spider
Sourcepub fn spider_fusion(
&mut self,
spider1: usize,
spider2: usize,
) -> QuantRS2Result<()>
pub fn spider_fusion( &mut self, spider1: usize, spider2: usize, ) -> QuantRS2Result<()>
Apply spider fusion rule: two adjacent spiders of the same color merge
Sourcepub fn remove_identities(&mut self) -> usize
pub fn remove_identities(&mut self) -> usize
Apply identity removal: remove spiders with phase 0 and degree 2
Sourcepub fn color_change(&mut self, spider_id: usize) -> QuantRS2Result<()>
pub fn color_change(&mut self, spider_id: usize) -> QuantRS2Result<()>
Apply color change rule: X and Z spiders connected by Hadamard become the same color
Sourcepub fn pi_copy(&mut self, spider_id: usize) -> QuantRS2Result<Vec<usize>>
pub fn pi_copy(&mut self, spider_id: usize) -> QuantRS2Result<Vec<usize>>
Apply pi-copy rule: Pauli spider can be copied through
Sourcepub fn bialgebra(
&mut self,
z_spider: usize,
x_spider: usize,
) -> QuantRS2Result<()>
pub fn bialgebra( &mut self, z_spider: usize, x_spider: usize, ) -> QuantRS2Result<()>
Apply bialgebra rule
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ZXDiagram
impl RefUnwindSafe for ZXDiagram
impl Send for ZXDiagram
impl Sync for ZXDiagram
impl Unpin for ZXDiagram
impl UnwindSafe for ZXDiagram
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.