Quantum Computing Cheat Sheet
Quantum Computing Cheat Sheet
MATLAB Support Package for Quantum Computing lets you build, simulate,
and run quantum algorithms.
Overview and download >>
Build >>
Single Qubit Gate
Apply a single qubit gate to a quantum circuit. The quantity in parentheses () is the qubit index on which the gate
is applied.
Quantum Circuit Object Plot Matrix
Syntax >> qc = quantumCircuit (xGate(1)) >> plot (qc) >> getMatrix(qc)
NumQubits:1
Output Gates:[1×1 quantum.gate.SimpleGate]
Single Qubit Gate Description The rotation gates are single qubit gates that take two
arguments. The first is the qubit index on which the
xGate(1) xGate = π rotation around X-axis to qubit 1 gate is applied, and second is the rotation angle or
yGate(1) yGate = π rotation around Y-axis to qubit 1 phase (θ) in radian.
zGate(1) zGate = π rotation around Z-axis to qubit 1 Parameterized Description
sGate(1) sGate = π/2 positive rotation around Z-axis Single Qubit Gate
rxGate(1,pi/2) rxGate = X-axis rotation gate
tGate(1) tGate = π/2 positive rotation around Z-axis
ryGate(1,pi/2) ryGate = Y-axis rotation gate
tiGate(1) tiGate = π/2 negative rotation around Z-axis
rzGate(1,pi/2) rzGate = Z-axis rotation gate
hGate(1) hGate = Hadamard gate
r1Gate(1,pi/2)
r1Gate = Z-axis rotation gate
idGate(1) idGate = Identity gate (does nothing) with global phase
cxGate(1,2)
cxGate or cnotGate = π rotation around crxGate(1,2,pi/2)
crxGate = Controlled X-axis
X-axis to qubit 2 if qubit 1 is in |1> state rotation gate
cyGate(1,2)
cyGate = π rotation around Y-axis to qubit cryGate(1,2,pi/2)
cryGate = Controlled y-axis
2 if qubit 1 is in |1> state rotation gate
czGate(1,2)
czGate = π rotation around Z-axis to qubit crzGate(1,2,pi/2)
crzGate = Controlled z-axis
2 if qubit 1 is in |1> state rotation gate
chGate(1,2) cr1Gate(1,2,pi/2)
cr1Gate = Controlled z-axis
czGate = Controlled Hadamard gate
rotation gate with global phase
mathworks.com
Special Gates
Gate Description
Constructs a composite gate from an In the gates below, the first and second arguments
compositeGate inner quantum circuit and returns a are the qubit indices, and the third is phase (θ),
(qc, [1,2]) CompositeGate object. The qc is the except for the swapGate which has two
inner quantum circuit in the example. arguments. Swapping the two target qubits
Controlled controlled X gate (CCNOT for all the gates below does not change the
ccxGate(1,2,3) gate operation.
or Toffoli gate)
Multi-controlled X gate
The first argument is three control qubits
Gate Description
(1,2,3), the second argument is one target
qubit (4), and the third argument is one ancil- rxxGate(1,2,pi/2) Ising XX coupling gate
mcxGate(1:3,4,5)
la qubits (5). This gate operates on a single
ryyGate(1,2,pi/2) Ising YY coupling gate
target qubit based on the states of the control
qubits, with a number of ancilla qubits that rzzGate(1,2,pi/2) Ising ZZ coupling gate
determines the number of simple gates
swapGate(1,2)
Swaps the values of
qftGate(1:3) Quantum Fourier transform (QFT) gate the qubits.
Simulate >>
Quantum Circuit Operations
Operation Example Output
>> gates = [hGate(1); cxGate(1,2)];
>> bell = quantumCircuit(gates,
plot = Draw a quantum circuit name=“bell”); % circuit
>> plot(bell) %plot
inv = Inverse of a quantum circuit >> bell _ inverted = inv(bell);
or gate >> plot(bell _ inverted)
mathworks.com
© 2023 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See mathworks.com/trademarks for a list of additional trademarks.
Other product or brand names may be trademarks or registered trademarks of their respective holders.
Simulated Quantum Circuit Operations
Operation Example Output
Initialize the quantum state of the cir- QuantumState with properties:
cuit where the qubit 1 (top qubit in BasisStates: [4×1 string]
S = simulate(bell,”10”)
circuit plot) is set to |1> and second Amplitudes: [4×1 double]
is to |0> NumQubits: 2
Show the output basis states and S.BasisStates BasisStates: “00” ”01” ”10” ”11”
their amplitudes S.Amplitudes Amplitudes: 0.7071 0 0 -0.7071
Visualizations >>
Matrix representation of |0> >> plot(qftGate(1:3)) >> histogram(states)
is [1;0] >> plotBlochSphere([1;0])
mathworks.com
© 2023 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See mathworks.com/trademarks for a list of additional trademarks.
Other product or brand names may be trademarks or registered trademarks of their respective holders.