A quantum Circuit contains a sequences of circuit elements. These can be any quantum Operation, including other circuits.
Returns the Hermitian conjugate of this circuit. If all the subsidiary gates are unitary, returns the circuit inverse.
Convert this quantum operation to a channel (if possible).
ValueError – If this operation cannot be converted to a Channel
Convert this quantum operation to a gate (if possible).
ValueError – If this operation cannot be converted to a Gate
Decompose this operation into smaller or more standard subunits. If cannot be decomposed, returns self.
Returns: An iteration of operations.
Iterate over all elementary elements of Circuit, recursively flattening composite elements such as sub-Circuit’s, DAGCircuit’s, and Moment’s
Return a a named parameters of this Operation.
KeyError – If unrecognized parameter name
Return all of the parameters of this Operation
Resolve the parameters of all of the elements of this circuit
Apply the action of this circuit upon a state.
If no initial state provided an initial zero state will be created.
Return the number of operations in this circuit
A Directed Acyclic Graph representation of a Circuit.
The circuit is converted to a networkx directed acyclic multi-graph, stored in the graph attribute.
There are 3 node types, ‘in’ nodes representing qubits at the start of a circuit; operation nodes; and ‘out’ nodes for qubits at the end of a circuit. Edges are directed from ‘in’ to ‘out’ via the Operation nodes. Each edge is keyed to a qubit.
A DAGCircuit is considered a mutable object. But it should not be mutated if it is part of another Circuit or other immutable composite Operation.
DAGCircuit is iterable, yielding all of the operation nodes in topological sort order.
Note: Provisional API
Return the Hermitian conjugate of this quantum operation.
For unitary Gates (and Circuits composed of the same) the Hermitian conjugate returns the inverse Gate (or Circuit)
ValueError – If this operation does not support Hermitian conjugate
Convert this quantum operation to a channel (if possible).
ValueError – If this operation cannot be converted to a Channel
Convert this quantum operation to a gate (if possible).
ValueError – If this operation cannot be converted to a Gate
Return the number of independent components that this DAGCircuit can be split into.
Split DAGCircuit into independent components
Return the circuit depth.
local – If True include local one-qubit gates in depth calculation. Else return the multi-qubit gate depth.
Split DAGCircuit into Moments, where the operations within each moment operate on different qubits (and therefore commute).
Returns: A Circuit of Moments
Return a copy of this Operation with new qubits
Return the total number of qubits
Return the total number of qubits
Relabel qubits and return copy of this Operation
Return the number of operations.
Returns a circuit for a target gate controlled by a collection of control qubits. [Barenco1995]
Uses a number of gates quadratic in the number of control qubits.
A. Barenco, C. Bennett, R. Cleve (1995) Elementary Gates for Quantum Computation`<https://arxiv.org/abs/quant-ph/9503016>`_ Sec 7.2
A circuit of ZPow, XPow, ZPow gates on the same qubit
A Euler decomposition of a 1-qubit gate.
The ‘euler’ argument can be used to specify any of the 6 Euler decompositions: ‘XYX’, ‘XZX’, ‘YXY’, ‘YZY’, ‘ZXZ’, ‘ZYZ’ (Default)
Returns a circuit for quantum phase estimation.
The gate has an eigenvector with eigenvalue e^(i 2 pi phase). To run the circuit, the eigenvector should be set on the gate qubits, and the output qubits should be in the zero state. After evolution and measurement, the output qubits will be (approximately) a binary fraction representation of the phase.
The output registers can be converted with the aid of the quantumflow.utils.bitlist_to_int() method.
>>> import numpy as np
>>> import quantumflow as qf
>>> N = 8
>>> phase = 1/4
>>> gate = qf.Rz(-4*np.pi*phase, N)
>>> circ = qf.phase_estimation_circuit(gate, range(N))
>>> res = circ.run().measure()[0:N]
>>> est_phase = int(''.join([str(d) for d in res]), 2) / 2**N # To float
>>> print(phase, est_phase)
0.25 0.25
Returns a quantum circuit for ripple-carry addition. [Cuccaro2004]
Requires two carry qubit (input and output). The result is returned in addend1.
A new quantum ripple-carry addition circuit, Steven A. Cuccaro, Thomas G. Draper, Samuel A. Kutin, David Petrie Moulton arXiv:quant-ph/0410184 (2004)
Returns a circuit that prepares a multi-qubit Bell state from the zero state.
Create a multilayer parameterized circuit given a graph of connected qubits.
We alternate between applying a sublayer of arbitrary 1-qubit gates to all qubits, and a sublayer of ZZ gates between all connected qubits.
In practice the pattern is ZPow, XPow, ZPow, (ZZ, XPow, ZPow )*, where ZPow are 1-qubit Z rotations, and XPow and 1-qubits X rotations. Since a Z rotation commutes across a ZZ, we only need one Z sublayer per layer.
Our fundamental 2-qubit interaction is the Ising like ZZ gate. We could apply a more general gate, such as the universal Canonical gate. But ZZ gates commute with each other, whereas other choice of gate would not, which would necessitate specifying the order of all 2-qubit gates within the layer.
Return a set of initial parameters for graph_circuit()
Draw a text diagram of a quantum circuit.
circ – A quantum Circuit
qubits – Optional qubit list to specify qubit order
use_unicode – If false, return ascii
qubit_labels – If false, do not display qubit names
A string representation of the circuit.
Create an image of a quantum circuit.
A convenience function that calls circuit_to_latex() and latex_to_image().
circ – A quantum Circuit
qubits – Optional qubit list to specify qubit order
Returns – A PIL Image (Use img.show() to display)
NotImplementedError – For unsupported gates.
OSError – If an external dependency is not installed.
Create an image of a quantum circuit in LaTeX.
circ – A quantum Circuit
qubits – Optional qubit list to specify qubit order
document – If false, just the qcircuit latex is returned. Else the circuit image is wrapped in a standalone LaTeX document ready for typesetting.
package – The LaTeX package used for rendering. Either ‘qcircuit’ or ‘quantikz’ (default)
A LaTeX string representation of the circuit.
NotImplementedError – For unsupported gates.
Convert a single page LaTeX document into an image.
To display the returned image, img.show()
Required external dependencies: pdflatex (with qcircuit package), and poppler (for pdftocairo).
string. (A LaTeX document as a) –
A PIL Image
OSError – If an external dependency is not installed.