qcpy is an open source python library and collaborative project for flexible simulations and visualizations of quantum circuits. This library contains a set of tools to teach computer scientists about the emerging discipline of quantum computing and improve overall understanding.
You can download the package using pip:
pip install qcpydev
Object representation of a qubit.
initial (chr)
default: z
- Character input for starting direction in the x, y, or z axis.
None
from qcpy import qubit
qx = qubit(initial_state = 'x')
qy = qubit(initial_state = 'y')
qz = qubit(initial_state = 'z')
print("x:\n", qx)
print("y:\n", qy)
print("z:\n", qz)
# x:
# [[0.70710677+0.j]
# [0.70710677+0.j]]
# y:
# [[0.70710677+0.j]
# [0.+0.70710677j]]
# z:
# [[1.+0.j]
# [0.+0.j]]
Gate that does not modify the quantum state.
None
identity=[1+0j, 0+0j],
[0+0j, 1+0j]
from qcpy import gates as qg
print(qg.identity())
# [[1.+0.j 0.+0.j]
# [0.+0.j 1.+0.j]]
Quantum equivalent of the NOT gate in classical computing with respect to the standard basis |0>, |1>.
None
PauliX = [0+0j, 1+0j],
[1+0j, 0+0j]
from qcpy import gates as qg
print(qg.paulix())
# [[1.+0.j 0.+0.j]
# [0.+0.j 1.+0.j]]
Rotation around y-axis of the bloch sphere by π radiains, mapping |0> to i|1> and |1> to -i|0>.
None
PauliY = [0+0j, 0-1j],
[0+1j, 0+0j]
from qcpy import gates as qg
print(qg.pauliy())
# [[0+0j, 0-1j]
# [0+1j, 0+0j]]
Rotation around z-axis of the bloch sphere by π radiains, mapping |1> to -|1>; known as the phase-flip.
None
PauliZ = [1+0j, 0+0j],
[0+0j, -1+0j]
from qcpy import gates as qg
print(qg.pauliz())
# [[1+0j, 0+0j],
# [0+0j, -1+0j]]
Maps the basis states |0> to |+> and |1> to |->, creating a superposition state if given a computation basis state.
None
Hadamard = [1, 1]
[1, -1] * (1/sqrt(2))
from qcpy import gates as qg
print(qg.hadamard())
# [[ 0.70710677+0.j 0.70710677+0.j]
# [ 0.70710677+0.j -0.70710677+0.j]]
Controlled gate acts on two or more qubits, performing the NOT operation of the target qubit only if the control qubits are |1>, can act as a quantum regiester and is used to entangle and disentangle Bell states.
little_endian (bool)
- if the gate is an inverse, with the target being above the control.
# regular
CNot = [1+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 1+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 0+0j, 1+0j],
[0+0j, 0+0j, 1+0j, 0+0j]
# little_endian = True
CNot = [1+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 0+0j, 1+0j],
[0+0j, 0+0j, 1+0j, 0+0j],
[0+0j, 1+0j, 0+0j, 0+0j]
from qcpy import gates as qg
print(qg.cnot())
# [[1.+0.j 0.+0.j 0.+0.j 0.+0.j]
# [0.+0.j 1.+0.j 0.+0.j 0.+0.j]
# [0.+0.j 0.+0.j 0.+0.j 1.+0.j]
# [0.+0.j 0.+0.j 1.+0.j 0.+0.j]]
# [[1.+0.j 0.+0.j 0.+0.j 0.+0.j]
# [0.+0.j 0.+0.j 0.+0.j 1.+0.j]
# [0.+0.j 0.+0.j 1.+0.j 0.+0.j]
# [0.+0.j 1.+0.j 0.+0.j 0.+0.j]]
Swaps two qubits, with respect to the basis |00>, |01>, |10>, and |11>.
None
Swap = [1+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 1+0j, 0+0j],
[0+0j, 1+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 0+0j, 1+0j]
from qcpy import gates as qg
print(qg.swap())
# [1+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 1+0j, 0+0j],
# [0+0j, 1+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 1+0j]
Universal reversible logic gate, known as the “controlled-controlled-NOT” gate; if the two control bits are set to 1, it will invert the target.
None
Toffoli = [1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j],
[0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j]
from qcpy import gates as qg
print(qg.toffoli())
# [1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j],
# [0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j]
Applies a rotation of theta around the z-axis.
theta (float)
default: numpy.pi/2
- angle of rotation around z-axis.
Phase = [1+0j, 0+0j],
[0+0j, numpy.exp(0+1j * theta)]
from qcpy import gates as qg
print(qg.phase())
# [1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j, 0+0j],
# [0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j],
# [0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 0+0j, 1+0j, 0+0j]
Equivalent to a pi/2 rotation around the z-axis.
None
S.matrix = [1+0j, 0+0j],
[0+0j, 0+1j]
from qcpy import gates as qg
print(qg.s())
# [1+0j, 0+0j],
# [0+0j, 0+1j]
Inverse of S gate; a -pi/2 rotation around the z-axis.
None
Sdg.matrix = [1+0j, 0+0j],
[0+0j, 0-1j]
from qcpy import gates as qg
print(qg.sdg())
# [1+0j, 0+0j],
# [0+0j, 0-1j]
Square of S gate; where T = S^2.
None
T.matrix = [1+0j, 0+0j],
[0+0j, numpy.exp((0+1j * numpy.pi) / 4)]
from qcpy import gates as qg
print(qg.t())
# [[1.+0.j 0.+0.j]
# [0.+0.j 0.70710677+0.70710677j]]
Inverse of T gate.
None
Tdg = [1+0j, 0+0j],
[0+0j, numpy.exp((0-1j * numpy.pi) / 4)]
from qcpy import gates as qg
print(qg.tdg())
# [[1.+0.j 0.+0.j]
# [0.+0.j 0.70710677-0.70710677j]]
Rotation of qubit around the z-axis.
theta (float)
default: numpy.pi/2
- angle of rotation around z-axis.
from qcpy import gates as qg
print(qg.rz())
# [numpy.exp((0-1j * (theta / 2))), 0+0j],
# [0+0j, numpy.exp(0+1j * (theta / 2))]
Rotation of qubit around the x-axis.
theta (float)
default: numpy.pi/2
- angle of rotation around x-axis.
Rx = [numpy.cos(theta / 2), 0-1j * numpy.sin(theta / 2)],
[0-1j * numpy.sin(theta / 2), numpy.cos(theta / 2)]
from qcpy import gates as qg
print(qg.rx())
# [[0.70710677+0.j 0.-0.70710677j]
# [0.-0.70710677j 0.70710677+0.j]]
Rotation of qubit around the y-axis.
theta (float)
default: numpy.pi/2
- angle of rotation around y-axis.
Ry = [numpy.cos(theta / 2), -1 * numpy.sin(theta / 2)],
[numpy.sin(theta / 2), numpy.cos(theta / 2)]
from qcpy import gates as qg
print(qg.ry())
# [[ 0.70710677+0.j -0.70710677+0.j]
# [ 0.70710677+0.j 0.70710677+0.j]]
Rotation around the x-axis by 90 degrees in the counter-clockwise direction. Also known as the “square-root X gate” due to the fact that applying the SX gate twice results in an X gate.
None
Sx = [1+1j, 1-1j],
[1-1j, 1+1j] * (1 / 2)
from qcpy import gates as qg
print(qg.sx())
# [[0.5+0.5j 0.5-0.5j]
# [0.5-0.5j 0.5+0.5j]]
Inverse of the Sx gate.
None
Sxdg = [1-1j, 1+1j],
[1+1j, 1-1j] * (1 / 2)
from qcpy import gates as qg
print(qg.sxdg())
# [[0.5-0.5j 0.5+0.5j]
# [0.5+0.5j 0.5-0.5j]]
Rotation of qubit with respect to theta, phi, and lambda, in Euler angles.
theta (float)
default: numpy.pi/2
- angle of rotation around Euler angle theta.
phi (float)
default: numpy.pi/2
- angle of rotation around Euler angle phi.
lmbda (float)
default: numpy.pi/2
- angle of rotation around Eulear angle lambda.
U.matrix = [numpy.cos(theta / 2), -1 * numpy.exp(0+1j * lmbda) * numpy.sin(theta / 2)],
[numpy.exp(0+1j * phi) * numpy.sin(theta / 2), numpy.exp(0+1j * (lmbda + phi)) * numpy.cos(theta / 2)]]
from qcpy import gates as qg
print(qg.u())
# [[0.7071+0.j -0.-0.7071j]
# [0.+0.7071j -0.7071+0.j]]
Rotation about XX, maximally entangling at theta = pi/2.
theta (float)
default: numpy.pi/2
- angle of rotation around XX.
Rxx.matrix = [numpy.cos(theta / 2), 0+0j, 0+0j, 0-1j * numpy.sin(theta / 2)],
[0+0j, numpy.cos(theta / 2), 0-1j * numpy.sin(theta / 2), 0+0j],
[0+0j, 0-1j * numpy.sin(theta / 2), numpy.cos(theta / 2), 0+0j],
[0-1j * numpy.sin(theta / 2), 0+0j, 0+0j, numpy.cos(theta / 2)]
from qcpy import gates as qg
print(qg.rxx())
# [[0.70710677+0.j 0+0.j 0+0.j 0-0.70710677j]
# [0+0.j 0.70710677+0.j 0-0.70710677j 0+0.j]
# [0+0.j 0-0.70710677j 0.70710677+0.j 0+0.j]
# [0-0.70710677j 0+0.j 0.+0.j 0.70710677+0.j]]
Rotation about ZZ, maximally entangling at theta = pi/2.
theta (float)
default: numpy.pi/2
- angle of rotation around ZZ.
Rzz.matrix = [numpy.exp(0-1j * (theta / 2)), 0+0j, 0+0j, 0+0j],
[0+0j, numpy.exp(0+1j * (theta / 2)), 0+0j, 0+0j],
[0+0j, 0+0j, numpy.exp(0+1j * (theta / 2)), 0+0j],
[0+0j, 0+0j, 0+0j, numpy.exp(0-1j * (theta / 2))]
from qcpy import gates as qg
print(qg.rzz())
# [[0.70710677-0.70710677j 0+0.j 0+0.jn 0+0.j]
# [0+0.j 0.70710677+0.70710677j 0+0.j 0+0.j]
# [0+0.j 0+0.j 0.70710677+0.70710677j 0+0.j]
# [0+0.j 0+0.j 0+0.j 0.70710677-0.70710677j]]
Controlled phase shift rotation in theta radians; generalization of Cz gate.
theta (float)
default: numpy.pi/2
- angle of rotation in theta radians.
Cr = [1+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 1+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 1+0j, 0+0j],
[0+0j, 0+0j, 0+0j, exp(theta * 0+1j)]
from qcpy import gates as qg
print(qg.cr())
# [[1+0.j 0+0.j 0+0.j 0+0.j]
# [0+0.j 1+0.j 0+0.j 0+0.j]
# [0+0.j 0+0.j 1+0.j 0+0.j]
# [0+0.j 0+0.j 0+0.j 0.5403023+0.84147096j]]
Controlled phase shift rotation in theta radians.
theta (float)
default: numpy.pi/2
- angle of rotation in theta radians.
Cz = [1+0j, 0+0j, 0+0j, 0+0j],
[0+0j, 1+0j, 0+0j, 0+0j],
[0+0j, 0+0j, 1+0j, 0+0j],
[0+0j, 0+0j, 0+0j, -1+0j]
from qcpy import gates as qg
print(qg.cz())
# [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j]
# [ 0.+0.j 1.+0.j 0.+0.j 0.+0.j]
# [ 0.+0.j 0.+0.j 1.+0.j 0.+0.j]
# [ 0.+0.j 0.+0.j 0.+0.j -1.+0.j]]
Quantum circuit that represents the state of a quantum system and performs operations on select qubits.
qubits (int)
- number of qubits in the circuit.
little_endian (bool)
default: False
- order of qubits and tensor products.
prep (char)
options: [z
, y
, x
] - initial direction of the qubits' phase angle.
gpu (bool)
default: False
- initialize GPU usage for the quantum circuit.
sparse (bool)
default: False
- use sparse matrix for the quantum circuit.
Returns state of the quantum circuit.
None
state (numpy.ndarray)
- array of quantum circuit's state.
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.cnot(0, 1)
print(qc.state)
# [[0.707+0.j]
# [0. +0.j]
# [0. +0.j]
# [0.707+0.j]]
Returns the number of qubits in the quantum circuit.
None
qubits (int)
- number of qubits.
from qcpy import quantumcircuit
qc = quantumcircuit(2)
print(qc.size)
A 3-qubit quantum gate that takes in two control qubits and one target qubit.
control_one (int)
- first control qubit.
control_two (int)
- second control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.ccx(0,1,2)
print(qc.state)
# [[0.5+0.j]
# [0. +0.j]
# [0.5+0.j]
# [0. +0.j]
# [0.5+0.j]
# [0. +0.j]
# [0. +0.j]
# [0.5+0.j]]
A 3-qubit quantum gate that takes in two control qubits and one target qubit.
control_1 (int)
- first control qubit.
control_2 (int)
- second control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.rccx(0,1,2)
print(qc.state)
# [[ 0.5-0.j ]
# [ 0. +0.j ]
# [ 0.5-0.j ]
# [ 0. +0.j ]
# [ 0.5-0.j ]
# [ 0. +0.j ]
# [-0. +0.j ]
# [ 0. +0.5j]]
A 4-qubit quantum gate that takes in 4 unique qubits.
qubit_1 (int)
- first input qubit.
qubit_2 (int)
- second input qubit.
qubit_3 (int)
- third input qubit.
qubit_4 (int)
- fourth input qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(4)
qc.h(0)
qc.h(1)
qc.h(2)
qc.rc3x(0,1,2,3)
print(qc.state)
# [[ 0.354-0.j ]
# [ 0. +0.j ]
# [ 0.354-0.j ]
# [ 0. +0.j ]
# [ 0.354-0.j ]
# [ 0. +0.j ]
# [ 0.354-0.j ]
# [ 0. +0.j ]
# [ 0.354-0.j ]
# [ 0. +0.j ]
# [ 0.354-0.j ]
# [ 0. +0.j ]
# [ 0. +0.354j]
# [-0. +0.j ]
# [ 0. -0.j ]
# [-0.354+0.j ]]
A 2-qubit quantum gate that takes in a control qubit and one target qubit.
control (int)
- control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.cx(0,1)
print(qc.state)
# [[0.707+0.j]
# [0. +0.j]
# [0. +0.j]
# [0.707+0.j]]
A controlled Hadamard gate to use in the quantum circuit.
control (int)
- control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.ch(0,1)
print(qc.state)
A controlled PauliY gate to use in the quantum circuit.
control (int)
- control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.cy(0,1)
print(qc.state)
A 2-qubit quantum gate that takes in a control qubit and one target qubit.
control (int)
- control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.cz(0,1)
print(qc.state)
# [[0.707+0.j]
# [0. +0.j]
# [0.707+0.j]
# [0. +0.j]]
A controlled RX gate to use in the quantum circuit.
control (int)
- control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.cry(0,1)
print(qc.state)
A controlled RY gate to use in the quantum circuit.
control (int)
- control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.cry(0,1)
print(qc.state)
A controlled RZ gate to use in the quantum circuit.
control (int)
- control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.crz(0,1)
print(qc.state)
A controlled R1 gate to use in the quantum circuit.
control (int)
- control qubit.
target (int)
- target qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.cr1(0,1)
print(qc.state)
Use the QFt algorithm in the quantum circuit.
qubit_one (int)
- first qubit.
qubit_two (int)
- second qubit.
qubit_three (int)
- third qubit.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.qft(0,1)
print(qc.state)
A 2-qubit quantum gate that takes in 2 qubits to swap there properties.
qubit_1 (int)
- first qubit to swap.
qubit_2 (int)
- second qubit to swap.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.swap(0,1)
print(qc.state)
# [[0.707+0.j]
# [0.707+0.j]
# [0. +0.j]
# [0. +0.j]]
A 2-qubit quantum gate that takes in two qubits and a representation of theta to initialize in the quantum state.
qubit_1 (int)
- first qubit input.
qubit_2 (int)
- second qubit input.
theta (float)
default: numpy.pi/2
- angle of rotation around z-axis.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.rxx(0,1)
print(qc.state)
# [[0.5+0.j ]
# [0. -0.5j]
# [0.5+0.j ]
# [0. -0.5j]]
A 2-qubit quantum gate that takes in two qubits and a representation of theta to initialize in the quantum state.
qubit_1 (int)
- first qubit input.
qubit_2 (int)
- second qubit input.
theta (float)
default: numpy.pi/2
- angle of rotation around z-axis.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.rxx(0,1)
print(qc.state)
# [[0.5+0.j ]
# [0. -0.5j]
# [0.5+0.j ]
# [0. -0.5j]]
Inset a custom controlled gate into the quantum circuit.
control (int)
- control qubit for given matrix.
target (int)
- target qubit for given matrix.
gate (np.array)
- (2,2) matrix to be applied to the quantum circuit.
None
from qcpy import quantumcircuit, paulix
qc = quantumcircuit(2)
qc.h(0)
qc.multicustom(0,1, paulix())
print(qc.state)
# [[0.707+0.j]
# [0. +0.j]
# [0. +0.j]
# [0.707+0.j]]
Used to confirm value that a qubit is representing and does nothing to manipulate the value of such qubit.
qubit (int)
- the qubit to have the identity gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.i(0)
print(qc.state)
# [[1.+0.j]
# [0.+0.j]
# [0.+0.j]
# [0.+0.j]]
Used to invert the value of what a qubit is representing.
qubit (int)
- the qubit to have the Pauli-X gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.x(0)
print(qc.state)
# [[0.+0.j]
# [0.+0.j]
# [1.+0.j]
# [0.+0.j]]
Used to put a given qubit into superposition.
qubit (int)
- the qubit to have the Hadamard gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
print(qc.state)
# [[0.707+0.j]
# [0. +0.j]
# [0.707+0.j]
# [0. +0.j]]
Changes the state of a qubit by pi around the y-axis of a Bloch Sphere.
qubit (int)
- the qubit to have the Pauli-Y gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.y(0)
print(qc.state)
# [[0.+0.j]
# [0.+0.j]
# [0.+1.j]
# [0.+0.j]]
Changes the state of a qubit by pi around the z-axis of a Bloch Sphere.
qubit (int)
- the qubit to have the Pauli-Z gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.z(0)
print(qc.state)
# [[ 0.707+0.j]
# [ 0. +0.j]
# [-0.707+0.j]
# [ 0. +0.j]]
Commits to a rotation around the z-axis based off of the inputted theta value.
qubit (int)
- the qubit to have the Phase gate be applied to the quantum wire.
theta (float)
default: numpy.pi/2
- angle of rotation around z-axis.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.p(0)
print(qc.state)
# [[0.707+0.j ]
# [0. +0.j ]
# [0. +0.707j]
# [0. +0.j ]]
Is a Phase gate where the inputted theta value is given as a constant of theta = pi / 2.
qubit (int)
- the qubit to have the Pauli-Z gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.s(0)
print(qc.state)
# [[0.707+0.j ]
# [0. +0.j ]
# [0. +0.707j]
# [0. +0.j ]]
Is a Phase gate and inverse of the S gate where the inputted theta value is given as a constant of theta = -pi / 2.
qubit (int)
- the qubit to have the Sdg gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.sdg(0)
print(qc.state)
# [[0.707+0.j ]
# [0. +0.j ]
# [0. -0.707j]
# [0. +0.j ]]
T gate is a special use case gate that in implemented from the P Gate.
qubit (int)
- the qubit to have the T gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.t(0)
print(qc.state)
# [[0.707+0.j ]
# [0. +0.j ]
# [0.5 +0.5j]
# [0. +0.j ]]
Tdg gate is a special use case gate that in implemented from the P Gate and is the inverse of the T gate.
qubit (int)
- the qubit to have the Tdg gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.tdg(0)
print(qc.state)
# [[0.707+0.j ]
# [0. +0.j ]
# [0.5 -0.5j]
# [0. +0.j ]]
RZ gate commits a rotation around the z-axis for a qubit.
qubit (int)
- the qubit to have the Rz gate be applied to the quantum wire.
theta (float)
default: numpy.pi/2
- angle of rotation around z-axis.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.h(0)
qc.rz(0)
print(qc.state)
# [[0.5-0.5j]
# [0. +0.j ]
# [0.5+0.5j]
# [0. +0.j ]]
RY gate commits a rotation around the y-axis for a qubit.
qubit (int)
- the qubit to have the Ry gate be applied to the quantum wire.
theta (float)
default: numpy.pi/2
- angle of rotation around y-axis.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.ry(0)
print(qc.state)
# [[0.707+0.j]
# [0. +0.j]
# [0.707+0.j]
# [0. +0.j]]
RX gate commits a rotation around the x-axis for a qubit.
qubit (int)
- the qubit to have the Ry gate be applied to the quantum wire.
theta (float)
default: numpy.pi/2
- angle of rotation around x-axis.
None
from qcpy import quantumCircuit
qc = quantumcircuit(2)
qc.rx(0)
print(qc.state)
# [[0.707+0.j ]
# [0. +0.j ]
# [0. -0.707j]
# [0. +0.j ]]
SX gate is the square root of the Inverse gate (X, PauliX Gate).
qubit (int)
- the qubit to have the Sx gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.sx(0)
print(qc.state)
# [[0.5+0.5j]
# [0. +0.j ]
# [0.5-0.5j]
# [0. +0.j ]]
SXDG gate is the negative square root of the Inverse gate (X, PauliX Gate) and inverse of the SX gate.
qubit (int)
- the qubit to have the SXdg gate be applied to the quantum wire.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.sxdg(0)
print(qc.state)
# [[0.5-0.5j]
# [0. +0.j ]
# [0.5+0.5j]
# [0. +0.j ]]
U gate is given three inputs (theta, phi, and lambda) that allow the inputs to manipulate the base matrix to allow for the position of the enacted qubit around the bloch sphere representation.
qubit (int)
- the qubit to have the U gate be applied to the quantum wire.
theta (float)
default: numpy.pi/2
- angle representation to rotate the qubit's representation.
phi (float)
default: numpy.pi/2
- angle representation to rotate the qubit's representation.
lmbda (float)
default: numpy.pi/2
- angle representation to rotate the qubit's representation.
None
from qcpy import quantumcircuit
qc = quantumcircuit(2)
qc.u(0)
print(qc.state)
# [[0.5-0.5j]
# [0. +0.j ]
# [0.5+0.5j]
# [0. +0.j ]]
Will take in a custom single qubit quantum gate and implement it on a qubit.
qubit (int)
- the qubit to have the U gate be applied to the quantum wire.
custom_matrix (np.array)
- matrix to be applied to the quantum circuit.
None
from qcpy import quantumcircuit, gates as qg
qc = quantumcircuit(2)
qc.custom(0, qg.cx())
print(qc.state)
# [[0.+0.j]
# [0.+0.j]
# [1.+0.j]
# [0.+0.j]]
Will take in a custom single qubit quantum gate and implement it on a qubit.
custom_matrix (List)
- Array of (2,2) matrix to apply to the quantum circuit.
None
from qcpy import quantumcircuit, gates as qg
qc = quantumcircuit(2)
arr = [qg.hadamard()] * 2
qc.gatearray(arr)
print(qc.state)
# [[0.5+0.j]
# [0.5+0.j]
# [0.5+0.j]
# [0.5+0.j]]
A collection of tools to visualize the quantum circuit
Returns a Q-Sphere that plots a global visualization of the quantum states in a 3D global view
quantumstate (quantumcircuit)
- quantum circuit to represent.
path (str)
- name of the image to be saved.
save (bool)
- save the image.
show (bool)
- present in matplotlib.
light (bool)
- toggle light and dark mode.
None
from qcpy import quantumcircuit, visualize
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.h(2)
visualize.qsphere(qc)
Returns a Bloch Sphere that plots the quantum state of a single qubit in a 3D global view
quantumstate (quantumcircuit)
- quantum circuit to represent.
path (str)
- name of the image to be saved.
save (bool)
- save the image.
show (bool)
- present in matplotlib.
light (bool)
- toggle light and dark mode.
None
from qcpy import quantumcircuit, visualize
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.h(2)
visualize.bloch(qc)
Returns a graph that plots all the amplitudes of the qubits being measured
quantumstate (quantumcircuit)
- quantum circuit to represent.
path (str)
- name of the image to be saved.
save (bool)
- save the image.
show (bool)
- present in matplotlib.
light (bool)
- toggle light and dark mode.
None
from qcpy import quantumcircuit, visualize
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.h(2)
visualize.statevector(qc)
Returns a graph that plots all the probabilities of the qubits being measured
quantumstate (quantumcircuit)
- quantum circuit to represent.
path (str)
- name of the image to be saved.
save (bool)
- save the image.
show (bool)
- present in matplotlib.
light (bool)
- toggle light and dark mode.
None
from qcpy import quantumcircuit, visualize
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.h(2)
visualize.probability(qc)
A collection of tools to represent a quantum state
Returns an array of the probability of the quantum circuit
quantumstate (quantumcircuit)
- quantum circuit to represent.
show_bit (int, str)
- Output a single value from the calculation, enter either a binary string or integer.
round (int)
- Round the the nth decimal point.
show_percent (bool)
- Output the probability in percentages instead of floats.
NDArray
from qcpy import quantumcircuit, probability
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.h(2)
probability(qc)
Returns an array of the amplitude of the quantum circuit
quantumstate (quantumcircuit)
- quantum circuit to represent.
show_bit (int, str)
- Output a single value from the calculation, enter either a binary string or integer.
round (int)
- Round the the nth decimal point.
radians (bool)
- Output the calculation in radians.
NDArray
from qcpy import quantumcircuit, amplitude
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.h(2)
amplitude(qc)
Returns a graph that plots all the probabilities of the qubits being measured
quantumstate (quantumcircuit)
- quantum circuit to represent.
show_bit (int, str)
- Output a single value from the calculation, enter either a binary string or integer.
round (int)
- Round the the nth decimal point.
radians (bool)
- Output the calculation in radians.
NDArray
from qcpy import quantumcircuit, phaseangle
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.h(2)
phaseangle(qc)
Returns a binary string that could be outputted from the quantum circuit.
quantumstate (quantumcircuit)
- quantum circuit to represent.
str
from qcpy import quantumcircuit, measure
qc = quantumcircuit(3)
qc.h(0)
qc.h(1)
qc.h(2)
measure(qc)