Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }

Implementations§

Source§

impl Graph

Source

pub fn neighbor_at(&self, v: V, n: usize) -> V

Explicitly index neighbors of a vertex. Used for iteration.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl GraphLike for Graph

Source§

fn new() -> Graph

Initialise a new empty graph
Source§

fn vindex(&self) -> V

Next fresh vertex index
Source§

fn num_vertices(&self) -> usize

Number of vertices
Source§

fn num_edges(&self) -> usize

Number of edges
Source§

fn vertices(&self) -> impl Iterator<Item = V>

Get iterator over all vertices
Source§

fn edges(&self) -> impl Iterator<Item = (V, V, EType)>

Get iterator over all edges Read more
Source§

fn inputs(&self) -> &Vec<V>

List of boundary vertices which serve as inputs
Source§

fn inputs_mut(&mut self) -> &mut Vec<V>

Mutable list of boundary vertices which serve as inputs
Source§

fn set_inputs(&mut self, inputs: Vec<V>)

Set inputs for the graph
Source§

fn outputs(&self) -> &Vec<V>

List of boundary vertices which serve as outputs
Source§

fn set_outputs(&mut self, outputs: Vec<V>)

Set outputs for the graph
Source§

fn outputs_mut(&mut self) -> &mut Vec<V>

Mutable list of boundary vertices which serve as outputs
Source§

fn add_vertex(&mut self, ty: VType) -> V

Add a vertex with the given type
Source§

fn add_vertex_with_data(&mut self, d: VData) -> V

Add a vertex with the given VData struct
Source§

fn add_named_vertex_with_data(&mut self, v: V, d: VData) -> Result<(), &str>

Add a vertex with the given name and VData struct Read more
Source§

fn remove_vertex(&mut self, v: V)

Remove a vertex from a graph Read more
Source§

fn add_edge_with_type(&mut self, s: V, t: V, ety: EType)

Add an edge with the given type Read more
Source§

fn remove_edge(&mut self, s: V, t: V)

Remove an edge from a graph Read more
Source§

fn vertex_data(&self, v: V) -> &VData

Get the data associated to the given vertex
Source§

fn vertex_data_opt(&self, v: V) -> Option<&VData>

Get the data associated to the given vertex, or None if it doesn’t exist
Source§

fn vertex_data_mut(&mut self, v: V) -> &mut VData

Get a mutable ref to the data associated to the given vertex
Source§

fn set_edge_type(&mut self, s: V, t: V, ety: EType)

Sets type of an edge
Source§

fn edge_type_opt(&self, s: V, t: V) -> Option<EType>

Returns type of an edge or None if the edge (or one of the vertices) doesn’t exist
Source§

fn set_coord(&mut self, v: V, coord: impl Into<Coord>)

Sets the coordinate of a vertex Read more
Source§

fn coord(&self, v: V) -> Coord

Returns the coordinate of a vertex Read more
Source§

fn set_qubit(&mut self, v: V, qubit: f64)

Sets the qubit index of the given vertex Read more
Source§

fn qubit(&self, v: V) -> f64

Returns the qubit index of the given vertex
Source§

fn set_row(&mut self, v: V, row: f64)

Sets the row of the given vertex
Source§

fn row(&self, v: V) -> f64

Returns the row of the given vertex
Source§

fn neighbors(&self, v: V) -> impl Iterator<Item = usize>

Returns an iterator over neighbors of a vertex
Source§

fn incident_edges(&self, v: V) -> impl Iterator<Item = (usize, EType)>

Returns an iterator over pairs (v, t) for v the “other end” of an edge, and t its type.
Source§

fn degree(&self, v: V) -> usize

Returns degree of a vertex
Source§

fn scalar(&self) -> &FScalar

Returns the scalar associated with a ZX diagram
Source§

fn scalar_mut(&mut self) -> &mut FScalar

Returns a mutable ref to the scalar associated with a ZX diagram
Source§

fn find_edge<F>(&self, f: F) -> Option<(V, V, EType)>
where F: Fn(V, V, EType) -> bool,

Returns the first edge satisfying the given function, or None
Source§

fn find_vertex<F>(&self, f: F) -> Option<V>
where F: Fn(V) -> bool,

Returns the first vertex satisfying the given function, or None
Source§

fn contains_vertex(&self, v: V) -> bool

Source§

fn scalar_factors(&self) -> impl Iterator<Item = (&Expr, &FScalar)>

Returns an iterator over all of the parametrised scalar factors Read more
Source§

fn get_scalar_factor(&self, e: &Expr) -> Option<FScalar>

Get the scalar factor associated with a given boolean expression
Source§

fn mul_scalar_factor(&mut self, e: Expr, s: FScalar)

Insert (i.e. multiply) a new scalar factor s^e into the overall scalar
Source§

fn pack(&mut self, force: bool)

This method can be called periodically to reduce wasted space in the graph representation Read more
Source§

fn phase_and_vars(&self, v: V) -> (Phase, Parity)

Returns the phase and any boolean variables at a vertex
Source§

fn set_phase(&mut self, v: V, phase: impl Into<Phase>)

Set the phase of a vertex
Source§

fn phase(&self, v: V) -> Phase

Returns the phase of vertex v
Source§

fn add_to_phase(&mut self, v: V, phase: impl Into<Phase>)

Adds a value to the phase of a vertex
Source§

fn set_vertex_type(&mut self, v: V, ty: VType)

Sets the type of a vertex
Source§

fn vertex_type(&self, v: V) -> VType

Returns the type of a vertex
Source§

fn vertex_type_opt(&self, v: V) -> Option<VType>

Returns type of a vertex or None if the vertex doesn’t exist
Source§

fn set_vars(&mut self, v: V, vars: Parity)

Sets the boolean variables that affect the phase of this vertex Read more
Source§

fn vars(&self, v: V) -> Parity

Returns the boolean variables that affect the phase of this vertex
Source§

fn add_to_vars(&mut self, v: V, vars: &Parity)

Adds the given variables to the parity expression of the vertex
Source§

fn add_edge(&mut self, s: V, t: V)

Add an edge to the graph
Source§

fn edge_type(&self, s: V, t: V) -> EType

Returns the type of a given edge and panics if the edge doesn’t exist
Source§

fn connected(&self, v0: V, v1: V) -> bool

Returns true if the given vertices are connected Read more
Source§

fn toggle_edge_type(&mut self, v0: V, v1: V)

Turns H-edges into normal edges and vice-versa
Source§

fn vertex_vec(&self) -> Vec<V>

Returns a vector of the vertices in the graph Read more
Source§

fn edge_vec(&self) -> Vec<(V, V, EType)>

Returns a vector of the edges in the graph Read more
Source§

fn neighbor_vec(&self, v: V) -> Vec<V>

Returns a vector of the neighbours of a given vertex Read more
Source§

fn incident_edge_vec(&self, v: V) -> Vec<(V, EType)>

Returns a vector of the incident edges of a given vertex Read more
Source§

fn x_to_z(&mut self)

Convert all X spiders to Z with the colour-change rule
Source§

fn add_vertex_with_phase(&mut self, ty: VType, phase: impl Into<Phase>) -> V

Add a vertex to the graph with the given type and phase
Source§

fn add_edge_smart(&mut self, s: V, t: V, ety: EType)

Add an edge and simplify if necessary to remove parallel edges Read more
Source§

fn plug_vertex(&mut self, v: V, b: BasisElem)

Replace a boundary vertex with the given basis element Read more
Source§

fn plug_output(&mut self, i: usize, b: BasisElem)

Plug the given basis vertex into the i-th output.
Source§

fn plug_input(&mut self, i: usize, b: BasisElem)

Plug the given basis vertex into the i-th input.
Source§

fn plug_inputs(&mut self, plug: &[BasisElem])

Plug the given list of normalised basis elements in as inputs, starting from the left Read more
Source§

fn plug_outputs(&mut self, plug: &[BasisElem])

Plug the given list of normalised basis elements in as outputs, starting from the left Read more
Source§

fn append_graph(&mut self, other: &impl GraphLike) -> FxHashMap<V, V>

Appends the given graph to the current one, with fresh names. Read more
Source§

fn plug(&mut self, other: &impl GraphLike)

Plug the given graph into the outputs and multiply scalars Read more
Source§

fn is_identity(&self) -> bool

Checks if the given graph only consists of wires from the inputs to outputs (in order)
Source§

fn tcount(&self) -> usize

Return number of Z or X spiders with non-Clifford phase
Source§

fn to_dot(&self) -> String

Return a graphviz-friendly string representation of the graph
Source§

fn adjoint(&mut self)

Exchange inputs and outputs and reverse all phases
Source§

fn to_adjoint(&self) -> Self

Same as GraphLike::adjoint(), but return as a copy
Source§

fn component_vertices(&self) -> Vec<FxHashSet<V>>

Returns vertices in the components of g
Source§

fn subgraph_from_vertices(&self, verts: Vec<V>) -> Self

Returns the full subgraph containing the given vertices
Source§

fn depth(&self) -> f64

Returns max row of any vertex
Source§

fn copy(&self, adjoint: bool) -> Self

Create a copy of the graph. If adjoint is set, the adjoint of the graph will be returned (inputs and outputs flipped, phases reversed). The copy will have consecutive vertex indices, even if the original graph did not.
Source§

fn make_bipartite(&mut self)

Performs inplace bipartite transformation of ZX graph by inserting opposite colored spiders between same-colored neighbors
Source§

fn adjacency_matrix(&self, nodelist: Option<&[V]>) -> Mat2

Returns the adjacency matrix of the graph, optionally in the order of nodelist (similar to nx’s adjacency_matrix)
Source§

impl PartialEq for Graph

Source§

fn eq(&self, other: &Graph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Graph

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<G> ToCircuit for G
where G: GraphLike + Clone,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<G> ToTensor for G
where G: GraphLike + Clone,

Source§

fn to_tensor<A>(&self) -> ArrayBase<OwnedRepr<A>, Dim<IxDynImpl>>
where A: TensorElem,

Source§

fn to_tensorf(&self) -> TensorF

Shorthand for to_tensor::<FScalar>()
Source§

fn to_tensor64(&self) -> Tensor64

Shorthand for to_tensor::<Complex<f64>>()
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V