circ0 = qf.Circuit()
circ0 += qf.Z(0) # Z gate on qubit 0
circ0 += qf.CNOT(0, 1) # Controlled not gate: control is qubit 0, target is qubit 1
qf.circuit_to_image(circ0) # Convert circuit to LaTex, then to PNG image
#!/usr/bin/env python
#
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.
"""A collection of useful circuit identities"""
from itertools import zip_longest
import numpy as np
from quantumflow import (
I, H, X, Y, Z, CNOT, CZ, SWAP, ISWAP, CANONICAL, XX, YY, ZZ, S,
CCNOT, RZ, Circuit, ccnot_circuit, gates_close, RX, CPHASE, TZ,
CPHASE00, CPHASE10, CPHASE01)
def identities():
""" Return a list of circuit identities, each consisting of a name, and
two equivalent Circuits."""
circuit_identities = []
# Pick random parameter
theta = np.pi * np.random.uniform()
# Single qubit gate identities
name = "Hadamard is own inverse"
circ0 = Circuit([H(0), H(0)])
circ1 = Circuit([I(0)])
circuit_identities.append([name, circ0, circ1])
name = "Hadamards convert X to Z"
circ0 = Circuit([H(0), X(0), H(0)])
circ1 = Circuit([Z(0)])
circuit_identities.append([name, circ0, circ1])
name = "Hadamards convert Z to X"
circ0 = Circuit([H(0), Z(0), H(0)])
circ1 = Circuit([X(0)])
circuit_identities.append([name, circ0, circ1])
name = "S sandwich converts X to Y"
circ0 = Circuit([S(0).H, X(0), S(0)])
circ1 = Circuit([Y(0)])
circuit_identities.append([name, circ0, circ1])
name = "S sandwich converts Y to X"
circ0 = Circuit([S(0), Y(0), S(0).H])
circ1 = Circuit([X(0)])
circuit_identities.append([name, circ0, circ1])
name = "Hadamards convert RZ to RX"
circ0 = Circuit([H(0), RZ(theta, 0), H(0)])
Notice: This is research code that will not necessarily be maintained to
support further releases of Forest and other Rigetti Software. We welcome
bug reports and PRs but make no guarantee about fixes or responses.
QuantumFlow: A Quantum Algorithms Development Toolkit
Installation for development
It is easiest to install QuantumFlow's requirements using conda.
You can also install with pip. However some of the requirements are tricky to install (notably tensorflow & cvxpy), and (probably) not everything in QuantumFlow will work correctly.