Skip to Content
New in v0.1.0 OpenQASM export: run fqkit circuits on real IBM hardware

Gates

A gate is a unitary operation applied to one or more qubits. FQkit provides a Gate base class plus ready-made factories for the common gates.

Single-qubit gates

GateCallParameterizedDescription
HadamardHadamard()noCreates superposition
RXRX(theta)yesRotation about the X axis
RYRY(theta)yesRotation about the Y axis
RZRZ(theta)yesRotation about the Z axis

Multi-qubit gates

GateCallQubitsDescription
CNOTCNOT()2Controlled-NOT (control, target)
CZCZ()2Controlled-Z
SWAPSWAP()2Swaps two qubits
ToffoliToffoli()3Controlled-controlled-NOT

What each gate looks like

Qubit 0 is the top wire. These are the same symbols used in the tutorials and in the notebooks.

q0H
Hadamard
q0RX(π/2)
RX, a rotation about X
q0RY(π/2)
RY, a rotation about Y
q0RZ(π)
RZ, a rotation about Z
q0q1
CNOT. The dot is the control, the plus is the target.
q0q1
CZ. Both qubits get a dot.
q0q1
SWAP
q0q1q2
Toffoli. Two controls, then a target.

Using a gate

Gates are added to a circuit with add_gate(gate, targets). The first target qubit is the gate’s most significant qubit. For CNOT, that is the control.

from fqkit import QuantumCircuit, Hadamard, CNOT, SWAP qc = QuantumCircuit(3) qc.add_gate(Hadamard(), [0]) qc.add_gate(CNOT(), [0, 1]) # control=0, target=1 qc.add_gate(SWAP(), [1, 2])

Parameterized gates

Rotation gates take an angle in radians. Pass a number directly, or a symbolic Parameter to bind later:

from fqkit import RX, Parameter qc.add_gate(RX(1.5708), [0]) # numeric angle theta = Parameter("theta") qc.add_gate(RX(theta), [0]) # symbolic: bind before running

Custom gates

You can build any gate from its unitary matrix:

from fqkit import Gate # A single-qubit identity gate my_gate = Gate("I", 1, matrix=[[1, 0], [0, 1]])
Last updated on