Getting Started Guide for Quantum Computing with MATLAB
MATLAB Support Package for Quantum Computing lets you build, simulate, and run quantum algorithms.
| 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)) |
|
>> getMatrix(qc) |
| Output |
|
|
|
| Single Qubit Gate | Description |
|---|---|
|
xGate = π rotation around x-axis to qubit 1 |
|
yGate = π rotation around y-axis to qubit 1 |
|
zGate = π rotation around z-axis to qubit 1 |
|
sGate = π/2 positive rotation around z-axis |
|
tGate = π/4 positive rotation around z-axis |
|
tiGate = π/4 negative rotation around z-axis |
|
hGate = Hadamard gate |
|
idGate = Identity gate (does nothing) |
The rotation gates are single qubit gates that take two arguments. The first is the qubit index on which the gate is applied, and second is the rotation angle or phase (θ) in radian
Parameterized Single Qubit Gate |
Description |
|
rxGate = x-axis rotation gate |
|
ryGate = y-axis rotation gate |
|
rzGate = z-axis rotation gate |
|
r1Gate = z-axis rotation gate with global phase |
Gates with One Control Qubit
Apply a gate with one control qubit to a quantum circuit. These gates have two arguments in parentheses (); the first is the control qubit and the second is the target qubit. If the control qubit is in the |0> state, then the gate does nothing. If the control qubit is in the |1> state, then the specified gate acts on the target qubit. >> cxGate(control,target)
Qubit index 1: control qubit
Qubit index 2: target qubit
The controlled rotation gates are two qubit gates that take three arguments. The first is the control qubit, the second is the target qubit, and third is the rotation angle or phase (θ) in radian.
Two Qubit Gate |
Description |
|
cxGate or cnotGate = π rotation around x-axis to qubit 2 if qubit 1 is in |1> state |
|
cyGate = π rotation around y-axis to qubit 2 if qubit 1 is in |1> state |
|
czGate = π rotation around z-axis to qubit 2 if qubit 1 is in |1> state |
|
chGate = Controlled Hadamard gate |
Parameterized Two Qubit Gate |
Description |
|
crxGate = Controlled X-axis rotation gate |
|
cryGate = Controlled y-axis rotation gate |
|
crzGate = Controlled z-axis rotation gate |
|
cr1Gate = Controlled z-axis rotation gate with global phase |
Special Gates
Gate |
Description |
compositeGate (qc, [1,2]) |
Constructs a composite gate from an inner quantum circuit and returns a CompositeGate object. The qc is the inner quantum circuit in the example. |
|
Controlled controlled X gate (CCNOT or Toffoli gate) |
mcxGate(1:3,4,5) |
Multi-controlled X gate The first argument is three control qubits (1,2,3), the second argument is one target qubit (4), and the third argument is one ancil- la qubits (5). This gate operates on a single target qubit based on the states of the control qubits, with a number of ancilla qubits that determines the number of simple gates |
|
Quantum Fourier transform (QFT) gate |
In the gates below, the first and second arguments are the qubit indices, and the third is phase (θ), except for the swapGate which has two arguments. Swapping the two target qubits for all the gates below does not change the gate operation.
Gate |
Description |
|
Ising XX coupling gate |
|
Ising YY coupling gate |
|
Ising ZZ coupling gate |
|
Swaps the values of the qubits. |
| Quantum Circuit Operations | ||
Operation |
Example |
Output |
|
|
|
|
|
|
getMatrix = Matrix representation of a quantum circuit or gate |
>> ggetMatrix(bell) |
|
generateQASM = Generate QASM code |
>> ggenerateQASM(bell) |
|
simulate(circuit, inputState), Simulate circuit and specify the ini- tial quantum state of the circuit and return a QuantumState object |
>> simulate(bell) |
|
unpack = Unpack composite gates inside a quantum circuit |
|
|
Simulated Quantum Circuit Operations |
||
Operation |
Example |
Output |
Initialize the quantum state of the cir- cuit where the qubit 1 (top qubit in circuit plot) is set to |1> and second is to |0> |
S = simulate(bell,”10”) |
|
Show the output basis states and their amplitudes |
|
|
Show the final state of the circuit such as the basis in which to represent each qubit |
|
|
Show the possible states and the probability of measuring each state |
|
states = "00" P= |
| Randomly sample the quantum state of the circuit with any number of shots |
|
|
Function |
Description |
|
Connect to an Amazon Braket device, specifying the device name, region, and S3 bucket path to store results |
|
Connect to an IBM quantum device, specifying the device name and the account credentials |
|
Get additional information about the device |
|
Create a task to run the circuit on the device |
|
Check the status of a task |
|
Retrieve the result of the circuit run |
|
>> plot(qftGate(1:3))
|
|
| >> GitHub with Examples | ||