Namespace zx

namespace zx

Typedefs

using Vertex = std::size_t
using Col = std::int32_t
using Qubit = std::int32_t
using fp = double
using PiExpression = sym::Expression<double, PiRational>
using gf2Mat = std::vector<std::vector<bool>>
using gf2Vec = std::vector<bool>

Enums

enum class EdgeType : uint8_t

Enum for the different types of edges in the ZX-calculus.

Simple edges are the standard edges in the ZX-calculus, while Hadamard edges are a shorthand used to represent edges with Hadamard gates on them.

Values:

enumerator Simple
enumerator Hadamard
enum class VertexType : uint8_t

Enum for the different types of vertices in the ZX-calculus.

Boundary vertices represent inputs and outputs. Otherwise, vertices are either Z-vertices or X-vertices.

Values:

enumerator Boundary
enumerator Z
enumerator X

Functions

inline PiRational operator-(const PiRational &rhs)
inline PiRational operator+(PiRational lhs, const PiRational &rhs)
inline PiRational operator+(PiRational lhs, const int64_t rhs)
inline PiRational operator+(const int64_t lhs, PiRational rhs)
inline PiRational operator-(PiRational lhs, const PiRational &rhs)
inline PiRational operator-(PiRational lhs, const int64_t rhs)
inline PiRational operator-(const int64_t lhs, PiRational rhs)
inline PiRational operator*(PiRational lhs, const PiRational &rhs)
inline PiRational operator*(PiRational lhs, const int64_t rhs)
inline PiRational operator*(const int64_t lhs, PiRational rhs)
inline PiRational operator/(PiRational lhs, const PiRational &rhs)
inline PiRational operator/(PiRational lhs, const int64_t rhs)
inline PiRational operator/(const int64_t lhs, PiRational rhs)
inline bool operator<(const PiRational &lhs, const PiRational &rhs)
inline bool operator<(const PiRational &lhs, const int64_t rhs)
inline bool operator<(const int64_t lhs, const PiRational &rhs)
inline bool operator<=(const PiRational &lhs, const PiRational &rhs)
inline bool operator<=(const PiRational &lhs, const int64_t rhs)
inline bool operator<=(const int64_t lhs, const PiRational &rhs)
inline bool operator>(const PiRational &lhs, const PiRational &rhs)
inline bool operator>(const PiRational &lhs, const int64_t rhs)
inline bool operator>(const int64_t lhs, const PiRational &rhs)
inline bool operator>=(const PiRational &lhs, const PiRational &rhs)
inline bool operator>=(const PiRational &lhs, const int64_t rhs)
inline bool operator>=(const int64_t lhs, const PiRational &rhs)
inline bool operator==(const PiRational &lhs, const PiRational &rhs)
inline bool operator==(const PiRational &lhs, const int64_t rhs)
inline bool operator==(const int64_t lhs, const PiRational &rhs)
inline bool operator!=(const PiRational &lhs, const PiRational &rhs)
inline bool operator!=(const PiRational &lhs, const int64_t rhs)
inline bool operator!=(const int64_t lhs, const PiRational &rhs)
inline std::ostream &operator<<(std::ostream &os, const zx::PiRational &rhs)
bool checkIdSimp(const ZXDiagram &diag, Vertex v)

Check whether the spider has exactly two incident edges and a phase of 0.

Parameters:
  • diag – The diagram.

  • v – The vertex to check.

Returns:

True if the spider has exactly two incident edges and a phase of 0.

void removeId(ZXDiagram &diag, Vertex v)

Remove spider from the diagram. checkIdSimp() should yield true.

The spider is removed by connecting its incident edges.

bool checkSpiderFusion(const ZXDiagram &diag, Vertex v0, Vertex v1)

Check whether two spiders can be fused.

See https://arxiv.org/abs/2012.13966, page 27, rule (f).

Parameters:
  • diag – The diagram.

  • v0 – The first spider.

  • v1 – The second spider.

Returns:

True if the spiders can be fused.

void fuseSpiders(ZXDiagram &diag, Vertex v0, Vertex v1)

Fuse two spiders. checkSpiderFusion() should yield true.

The spiders are fused by connecting their incident edges.

bool checkLocalComp(const ZXDiagram &diag, Vertex v)

Check if the local complementation rule can be applied to the given spider.

See https://arxiv.org/abs/2012.13966, equation (102).

Parameters:
  • diag – The diagram.

  • v – The spider.

Returns:

True if the local complementation rule can be applied.

void localComp(ZXDiagram &diag, Vertex v)

Apply the local complementation rule to the given spider. checkLocalComp() should yield true.

See https://arxiv.org/abs/2012.13966, equation (102).

bool checkPivotPauli(const ZXDiagram &diag, Vertex v0, Vertex v1)

Check if the pivot rule can be applied to the given interior spiders.

See https://arxiv.org/abs/2012.13966, equation (103).

Parameters:
  • diag – The diagram.

  • v0 – The first spider.

  • v1 – The second spider.

Returns:

True if the pivot rule can be applied.

void pivotPauli(ZXDiagram &diag, Vertex v0, Vertex v1)

Apply the pivot rule to the given interior spiders. checkPivotPauli() should yield true.

See https://arxiv.org/abs/2012.13966, equation (103).

bool checkPivot(const ZXDiagram &diag, Vertex v0, Vertex v1)

Check if the pivot rule can be applied. Spiders can be connected to boundaries.

Parameters:
  • diag – The diagram.

  • v0 – The first spider.

  • v1 – The second spider.

Returns:

True if the pivot rule can be applied.

void pivot(ZXDiagram &diag, Vertex v0, Vertex v1)

Apply the pivot rule. Spiders can be connected to boundaries. checkPivot() should yield true.

bool checkPivotGadget(const ZXDiagram &diag, Vertex v0, Vertex v1)

Check if the gadget pivot rule can be applied. Spiders can be connected to boundaries.

See https://arxiv.org/abs/1903.10477, page 13 rule (P2) and (P3) for details.

Parameters:
  • diag – The diagram.

  • v0 – The first spider.

  • v1 – The second spider.

Returns:

True if the gadget pivot rule can be applied.

void pivotGadget(ZXDiagram &diag, Vertex v0, Vertex v1)

Apply the gadget pivot rule. Spiders can be connected to boundaries. checkPivotGadget() should yield true.

See https://arxiv.org/abs/1903.10477, page 13 rule (P2) and (P3) for details.

bool checkAndFuseGadget(ZXDiagram &diag, Vertex v)

Check if a gadget can be fused with its connected spider and fuse if true.

Unlike other rules, this function performs the check and modification in one step. This is for performance reasons, since the overhead for the check is significant and otherwise intermediate results would have to be computed twice. See https://arxiv.org/abs/1903.10477, page 13, rule (ID).

Parameters:
  • diag – The diagram.

  • v – The spider.

Returns:

True if the gadget can be fused with its connected spider.

template<class VertexCheckFun, class VertexRuleFun>
std::size_t simplifyVertices(ZXDiagram &diag, VertexCheckFun check, VertexRuleFun rule)

Simplify the diagram by applying the given rule to all vertices that match the given check.

Template Parameters:
  • VertexCheckFun – Type of the check function

  • VertexRuleFun – Type of the rule function

Parameters:
  • diag – The diagram to simplify

  • check – The check function that determines if a vertex should be simplified

  • rule – The rule function that is applied to the vertex

Returns:

The number of simplifications that were applied

template<class EdgeCheckFun, class EdgeRuleFun>
std::size_t simplifyEdges(ZXDiagram &diag, EdgeCheckFun check, EdgeRuleFun rule)

Simplify the diagram by applying the given rule to all edges that match the given check.

Template Parameters:
  • EdgeCheckFun – Type of the check function

  • EdgeRuleFun – Type of the rule function

Parameters:
  • diag – The diagram to simplify

  • check – The check function that determines if an edge should be simplified

  • rule – The rule function that is applied to the edge

Returns:

The number of simplifications that were applied

std::size_t gadgetSimp(ZXDiagram &diag)
std::size_t idSimp(ZXDiagram &diag)

Apply the identity rule to the Diagram until exhaustion.

A spider with exactly two incident edges and a phase of 0 is removed. See https://arxiv.org/abs/2012.13966 page 27, rule (id).

Parameters:

diag – The diagram to simplify

Returns:

The number of simplifications that were applied

std::size_t spiderSimp(ZXDiagram &diag)

Apply the spider rule to the Diagram until exhaustion.

Spiders of the same type connected by a regular edge can be turned into one by adding both phases and fusing all incident edges. See https://arxiv.org/abs/2012.13966 page 27, rule (f).

Parameters:

diag – The diagram to simplify

Returns:

The number of simplifications that were applied

std::size_t localCompSimp(ZXDiagram &diag)

Apply the local complementation rule to the Diagram until exhaustion.

See https://arxiv.org/abs/2012.13966 equation (102).

Parameters:

diag – The diagram to simplify

Returns:

The number of simplifications that were applied

std::size_t pivotSimp(ZXDiagram &diag)

Simplify the diagram by applying the pivot rule.

See https://arxiv.org/abs/2012.13966, equation 103 for details. Similar to the Pauli pivot rule but can be applied to vertices connectedto the boundary.

Parameters:

diag – The diagram to simplify.

Returns:

The number of simplifications applied.

std::size_t pivotPauliSimp(ZXDiagram &diag)

Simplify the diagram by applying the pivot rule in the case that the pivot spiders have phases of Pi. See https://arxiv.org/abs/2012.13966, equation 103 for details.

Parameters:

diag – The diagram to simplify.

Returns:

The number of simplifications applied.

std::size_t interiorCliffordSimp(ZXDiagram &diag)

Simplify all internal vertices and edges of the diagram using Clifford simplifications.

This function applies the id, spider, local complementation, and Pauli pivot rules.

Parameters:

diag – The diagram to simplify.

Returns:

The number of simplifications applied.

std::size_t cliffordSimp(ZXDiagram &diag)
std::size_t pivotgadgetSimp(ZXDiagram &diag)

Simplify the diagram by applying the pivot rule to non-Pauli spider.

By extracting the phases into extra “gadgets”, the pivot rule can be applies to non-Pauli spiders. See https://arxiv.org/abs/1903.10477, page 13 rule (P2) and (P3) for details.

Parameters:

diag – The diagram to simplify.

Returns:

The number of simplifications applied.

std::size_t fullReduce(ZXDiagram &diag)

Simplify the diagram by applying Clifford simplifications and the gadget pivot rule.

In addition to the Clifford simplification, this function also applies the pivot gadget rule.

Parameters:

diag – The diagram to simplify.

Returns:

The number of simplifications applied.

std::size_t fullReduceApproximate(ZXDiagram &diag, fp tolerance)

Apply full reduction to the diagram. Rounds phases to nearest multiple of Pi/2 during simplification.

Parameters:
  • diag – The diagram to simplify.

  • tolerance – The tolerance for rounding phases to multiples of Pi/2.

Returns:

The number of simplifications applied

bool isPauli(const PiExpression &expr)

Check whether a PiExpression is a constant multiple of pi.

Parameters:

expr – PiExpression to check

Returns:

true if the expression is a constant multiple of pi, false otherwise

bool isClifford(const PiExpression &expr)

Check whether a PiExpression is a constant multiple of pi/2.

Parameters:

expr – PiExpression to check

Returns:

true if the expression is a constant multiple of pi/2, false otherwise

bool isProperClifford(const PiExpression &expr)

Check whether a PiExpression is a constant multiple of pi/2 but not a multiple of pi.

Parameters:

expr – PiExpression to check

Returns:

true if the expression is a constant multiple of pi/2 but not a multiple of pi, false otherwise

void roundToClifford(PiExpression &expr, fp tolerance)

Round phase to the nearest multiple of pi/2. The phase has to be non-symbolic.

Parameters:
  • expr – PiExpression to round

  • tolerance – Tolerance for rounding

inline std::ostream &operator<<(std::ostream &os, const EdgeType &type)
inline std::ostream &operator<<(std::ostream &os, const VertexType &type)

Variables

constexpr fp MAX_DENOM = 1e9
constexpr fp PARAMETER_TOLERANCE = 1e-13
constexpr fp TOLERANCE = 1e-13
static constexpr auto PI = static_cast<fp>(3.141592653589793238462643383279502884197169399375105820974L)
struct Edge
#include <Utils.hpp>

Struct to represent a (half-)edge in a ZX-diagram.

class Edges
#include <Utils.hpp>

Class to represent a collection of edges in a ZX-diagram.

The ZXDiagram class stores edges in a vector of vectors of Edge objects. The Edges class provides an iterator to iterate over all edges in the diagram. This avoids the need to iterate over all vertices and check if the vertex has an edge to another vertex.

class EdgeIterator
#include <Utils.hpp>

Class wrapping an iterator to iterate over all edges in a ZX-diagram.

class FunctionalityConstruction
#include <FunctionalityConstruction.hpp>

Static class to construct ZX-diagrams from a QuantumComputation.

Public Static Functions

static ZXDiagram buildFunctionality(const qc::QuantumComputation *qc)

Builds a ZX-diagram from a QuantumComputation.

Parameters:

qc – Pointer to QuantumComputation to build the ZX-diagram from

Returns:

ZXDiagram

static bool transformableToZX(const qc::QuantumComputation *qc)

Check whether a given QuantumComputation can be transformed to a ZXDiagram.

Not all instructions supported by the QuantumComputation are supported by the ZXDiagram (e.g. arbitrarily-controlled multi-qubit gates).

Parameters:

qc – Pointer to QuantumComputation to check

Returns:

true if the QuantumComputation can be transformed to a ZXDiagram, false otherwise

static bool transformableToZX(const qc::Operation *op)

Check whether a given Operation can be transformed to a ZXDiagram.

Not all Operations have a corresponding representation in the ZX-calculus.

Parameters:

op – Pointer to Operation to check

Returns:

true if the Operation can be transformed to a ZXDiagram, false otherwise

class PiRational

Public Functions

PiRational() = default

Default constructor initializes the rational to 0/1.

inline explicit PiRational(int64_t num, int64_t denom)

Construct a PiRational from numerator and denominator.

The input fraction is already assumed to be in multiples of Pi. For example, the fraction 1/2 corresponds to Pi/2.

Parameters:
  • num – Numerator of the fraction.

  • denom – Denominator of the fraction.

inline explicit PiRational(int64_t num)

Construct a PiRational from numerator. Denominator is assumed to be 1.

The input numerator is already assumed to be in multiples of Pi. For example a numerator of 1 corresponds to a fraction Pi/1.

Parameters:

num – Numerator of the fraction.

explicit PiRational(double val)

Construct a PiRational from a double.

The input double is approximated as a fraction of Pi within a tolerance of 1e-13.

Parameters:

val – Double value to be approximated.

inline bool isInteger() const

Check if the fraction is an integer, i.e., the denominator is 1.

Returns:

True if the fraction is an integer, false otherwise.

inline bool isZero() const

Check if the fraction is zero, i,e, the numerator is 0.

Returns:

True if the fraction is zero, false otherwise.

inline BigInt getDenom() const

Get the denominator of the fraction.

Returns:

Denominator of the fraction.

inline BigInt getNum() const

Get the numerator of the fraction.

Returns:

Numerator of the fraction.

double toDouble() const

Convert the fraction to a double.

The result is not taken mod Pi. Converting 1/1 will return an approximation of Pi.

Returns:

Double value of the fraction.

inline double toDoubleDivPi() const

Convert the fraction to a double mod Pi.

The result is taken mod Pi. Converting 1/1 will return 1.0.

Returns:

Double value of the fraction.

inline bool isClose(const double x, const double tolerance) const

Check if the fraction is close to a double value within a tolerance.

The comparison is not done mod Pi. So if the fraction is 1/1 isClose(1.0, 1e-13) will return true.

Parameters:
  • x – Double value to compare to.

  • tolerance – Tolerance for the comparison.

Returns:

True if the fraction is close to the double value, false otherwise.

inline bool isCloseDivPi(const double x, const double tolerance) const

Check if the fraction is close to a double value within a tolerance mod Pi.

The comparison is done mod Pi. So if the fraction is 1/1 isCloseDivPi(1.0, 1e-13) will return false, but isCloseDivPi(3.14159, 1e-14) will return true.

Parameters:
  • x – Double value to compare to.

  • tolerance – Tolerance for the comparison.

Returns:

True if the fraction is close to the double value divided by Pi, false otherwise.

inline explicit operator double() const

Get the double value of the fraction.

The result is not taken mod Pi. Converting 1/1 will return 1.0.

Returns:

Double value of the fraction.

struct VertexData
#include <Utils.hpp>

Struct storing all data corresponding to a vertex in a ZX-diagram.

class Vertices
#include <Utils.hpp>

Class to represent a collection of vertices in a ZX-diagram.

The ZXDiagram class stores vertices in a vector of optional VertexData objects to allow for fast deletion without changing the indices of the other vertices. The Vertices class provides an iterator to iterate over all vertices in the diagram. This avoids the need to iterate over all indices and check if the vertex at that index is valid.

class VertexIterator
class ZXDiagram
#include <ZXDiagram.hpp>

Class representing a ZX-diagram.

Labelled undirected graph. Every node is either of type VertexType::Z, VertexType::X or VertexType::Boundary. The boundary vertices are the inputs and outputs of the diagram. The graph is stored as an adjacency list. The vertices are stored in a vector of optional VertexData. The optional is empty if the vertex has been deleted. The scalars of the diagram are SymbolicPiExpressions, meaning that all computations can be done symbolically.

Public Functions

explicit ZXDiagram(std::size_t nqubits)

Create an nqubit identity diagram.

Parameters:

nqubits – number of qubits

void addEdge(Vertex from, Vertex to, EdgeType type = EdgeType::Simple)

Add an edge to the diagram.

Parameters:
  • from – first vertex of the edge

  • to – second vertex of the edge

  • type – type of the edge (Simple or Hadamard)

inline void addHadamardEdge(const Vertex from, const Vertex to)

Add a Hadamard edge to the diagram.

Parameters:
  • from – first vertex of the edge

  • to – second vertex of the edge

void addEdgeParallelAware(Vertex from, Vertex to, EdgeType eType = EdgeType::Simple)

Add edge to diagram, simplifying the diagram if this results in parallel edges.

In the ZX-calculus, parallel edges and self-loops can usually be simplified. Two parallel Simple edges between two opposite-colored vertices cancel out for example. This function adds an edge to the diagram and then simplifies the diagram if necessary.

Parameters:
  • from – first vertex of the edge

  • to – second vertex of the edge

  • eType – type of the edge (Simple or Hadamard)

void removeEdge(Vertex from, Vertex to)

Remove Edge from the diagram.

Parameters:
  • from – first vertex of the edge

  • to – second vertex of the edge

Vertex addVertex(const VertexData &data)

Add a vertex to the diagram.

Parameters:

data – data of the vertex

Returns:

the vertex that was added

Vertex addVertex(Qubit qubit, Col col = 0, const PiExpression &phase = PiExpression(), VertexType type = VertexType::Z)

Add a vertex to the diagram.

Parameters:
  • qubit – qubit index of the vertex

  • col – column index of the vertex

  • phase – phase of the vertex

  • type – type of the vertex

Returns:

the vertex that was added

void addQubit()

Add a bare qubit to the diagram.

void addQubits(zx::Qubit n)

Add multiple bare qubits to the diagram.

Parameters:

n – number of qubits to add

void removeVertex(Vertex toRemove)

Remove a vertex from the diagram. Also removes all edges incident to the vertex.

Parameters:

toRemove – vertex to remove

inline std::size_t getNdeleted() const

Get number of deleted vertices.

Deleted vertices are not removed from the vertices vector, but are left as optional in the array.

Returns:

number of deleted vertices

inline std::size_t getNVertices() const

Get number of vertices.

Returns:

number of vertices

inline std::size_t getNEdges() const

Get number of edges.

Returns:

number of edges

inline std::size_t getNQubits() const

Get number of qubits.

Returns:

number of qubits

bool connected(Vertex from, Vertex to) const

Check whether there is a path between two vertices.

Parameters:
  • from – first vertex

  • to – second vertex

Returns:

true if there is a path between the two vertices, false otherwise

std::optional<Edge> getEdge(Vertex from, Vertex to) const

Get the edge between two vertices.

Parameters:
  • from – first vertex

  • to – second vertex

Returns:

the edge between the two vertices, if it exists

inline const std::vector<Edge> &incidentEdges(const Vertex v) const

Get all edges incident to a vertex.

Parameters:

v – vertex

Returns:

vector of edges incident to the vertex

inline const Edge &incidentEdge(const Vertex v, const std::size_t n)

Get the n-th incident edge of a vertex. Bounds are not checked for performance reasons!

Parameters:
  • v – vertex

  • n – index of the incident edge

Returns:

the n-th incident edge of the vertex

inline std::size_t degree(const Vertex v) const

Get the degree of a vertex.

Parameters:

v – vertex

Returns:

degree of the vertex

inline const PiExpression &phase(const Vertex v) const

Get the phase of a vertex.

Parameters:

v – vertex

Returns:

phase of the vertex

inline Qubit qubit(const Vertex v) const

Get the qubit of a vertex.

Parameters:

v – vertex

Returns:

qubit of the vertex

inline VertexType type(const Vertex v) const

Get the type of a vertex.

Parameters:

v – vertex

Returns:

type of the vertex

inline std::optional<VertexData> getVData(const Vertex v) const

Get vertex data if vertex has not been deleted.

Parameters:

v – vertex

Returns:

vertex data if vertex has not been deleted

std::vector<std::pair<Vertex, const VertexData&>> getVertices() const

Get all vertices of the diagram.

Returns:

vector of vertices

std::vector<std::pair<Vertex, Vertex>> getEdges() const

Get all edges of the diagram.

Returns:

vector of edges

inline const std::vector<Vertex> &getInputs() const

Get all input vertices of the diagram.

Returns:

vector of input vertices

inline Vertex getInput(const std::size_t i) const

Get i-th input vertex of the diagram. Bounds are not checked!

Parameters:

i – index of the input vertex

Returns:

i-th input vertex

inline const std::vector<Vertex> &getOutputs() const

Get all output vertices of the diagram.

Returns:

vector of output vertices

inline Vertex getOutput(const std::size_t i) const

Get i-th output vertex of the diagram. Bounds are not checked!

Parameters:

i – index of the output vertex

Returns:

i-th output vertex

inline bool isDeleted(const Vertex v) const

Check whether vertex has been deleted.

Parameters:

v – vertex

Returns:

true if vertex has been deleted, false otherwise

inline bool isBoundaryVertex(const Vertex v) const

Check whether vertex is a boundary vertex.

Parameters:

v – vertex

Returns:

true if vertex is a boundary vertex, false otherwise

bool isInput(Vertex v) const

Check whether vertex is an input vertex.

Parameters:

v – vertex

Returns:

true if vertex is an input vertex, false otherwise

bool isOutput(Vertex v) const

Check whether vertex is an output vertex.

Parameters:

v – vertex

Returns:

true if vertex is an output vertex, false otherwise

inline void addPhase(const Vertex v, const PiExpression &phase)

Add phase to a vertex. The phase is added to the existing phase.

Parameters:
  • v – vertex

  • phase – phase to add

inline void setPhase(const Vertex v, const PiExpression &phase)

Set phase of a vertex. Previous value is overwritten.

Parameters:
  • v – vertex

  • phase – phase to set

inline void setType(const Vertex v, const VertexType type)

Set type of a vertex.

Parameters:
  • v – vertex

  • type – type to set

void toGraphlike()

Transform the diagram to a graph-like diagram. Modifies the diagram in place.

A graph-like diagram is a diagram where all vertices are of type Z and all edges are hadamard edges. Every ZX-diagram can be rewritten into this form by adding Hadamard edges and changing the type of the vertices.

bool isIdentity() const

check whether the diagram is the identity diagram.

The identity diagram is a diagram where every input is connected to one output without any additional vertices or hadamard edges in between.

Returns:

true if the diagram is the identity diagram, false otherwise

ZXDiagram adjoint() const

Get the adjoint of the diagram.

The adjoint of a ZX-diagram is the diagram with inputs and outputs swapped and all phases negated.

Returns:

the adjoint of the diagram

ZXDiagram &invert()

Invert the diagram in place.

Diagram is replaced by its adjoint.

Returns:

reference to the inverted diagram

ZXDiagram &concat(const ZXDiagram &rhs)

Concatenate two diagrams. Modifies the first diagram in place.

The second diagram is added to the first diagram. The inputs of the second diagram are connected to the outputs of the first diagram. The number of qubits of the two diagrams must be the same.

Parameters:

rhs – second diagram

Returns:

reference to the concatenated diagram

inline ZXDiagram &operator+=(const ZXDiagram &rhs)

Same as concat(const ZXDiagram&)

Parameters:

rhs – second diagram

Returns:

reference to the concatenated diagram

void makeAncilla(Qubit qubit)

Convert a qubit to an ancilla initialized and post-selected on |0>.

Parameters:

qubit – qubit to convert

void makeAncilla(Qubit in, Qubit out)

Convert a qubit to an ancilla initialized and post-selected on |0>.

Parameters:
  • in – qubit initialized in |0>

  • out – qubit post-selected in |0>

void approximateCliffords(fp tolerance)

Round phases in the diagram to multiples of pi/2. Modifies the diagram in place.

Parameters:

tolerance – tolerance for rounding

void removeDisconnectedSpiders()

Remove disconnected spiders from the diagram. Modifies the diagram in place.

void addGlobalPhase(const PiExpression &phase)

Add a global phase to the diagram. Adds the phase to the current global phase.

Parameters:

phase – phase to add

inline PiExpression getGlobalPhase() const

Get the global phase of the diagram.

Returns:

global phase of the diagram

inline bool globalPhaseIsZero() const

Check whether the global phase of the diagram is zero.

Returns:

true if the global phase is zero, false otherwise

gf2Mat getAdjMat() const

Get the adjacency matrix of the diagram.

Returns:

adjacency matrix of the diagram

std::vector<Vertex> getConnectedSet(const std::vector<Vertex> &s, const std::vector<Vertex> &exclude = {}) const

Get the connected set of a set of vertices.

The connected set of a set of vertices is the set of all vertices that are connected to the input set.

Parameters:
  • s – set of vertices

  • exclude – set of vertices to exclude from the connected set

Returns:

connected set of the input set

Public Static Functions

static bool isIn(const Vertex &v, const std::vector<Vertex> &vertices)

Check whether a vertex is in a vector of vertices.

Parameters:
  • v – vertex

  • vertices – vector of vertices

Returns:

true if the vertex is in the vector, false otherwise

class ZXException : public std::invalid_argument