# run

Run circuit on quantum device

Since R2023a

Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.

## Description

example

task = run(c,dev) runs the quantum circuit c remotely on a quantum device dev.

The input dev must be a QuantumDeviceAWS or QuantumDeviceIBM object that connects to a quantum device available through AWS® or IBM®, respectively. The output task is a QuantumTaskAWS or QuantumTaskIBM object, which can be used to monitor the task and retrieve its result. By default, the run function runs the circuit with 100 shots.

example

task = run(c,dev,Name=Value) specifies options using one or more name-value arguments. For example, you can specify NumShots=n to run the circuit with n shots remotely on the quantum device.

Note

Running a circuit on a remote quantum device results in charges to your account with the remote service.

## Examples

collapse all

Create a quantum circuit that consists of a Hadamard gate and a controlled X gate to entangle two qubits.

gates = [hGate(1); cxGate(1,2)];
c = quantumCircuit(gates);

Connect to a remote quantum device through AWS. Create a task that runs the circuit on the device with 100 shots.

dev = quantum.backend.QuantumDeviceAWS("Lucy");

Status: "queued"

Wait for the task to finish. Retrieve the result of running the circuit on the device.

m =

QuantumMeasurement with properties:

MeasuredStates: [4×1 string]
Counts: [4×1 double]
Probabilities: [4×1 double]
NumQubits: 2

Show the measurement result of running the circuit. Due to the noise in the physical quantum device, the $|01〉$ and $|10〉$ states can appear as measurements.

table(m.Counts,m.Probabilities,m.MeasuredStates, ...
VariableNames=["Counts","Probabilities","States"])
ans =

4×3 table

Counts    Probabilities    States
______    _____________    ______

46          0.46          "00"
9          0.09          "10"
3          0.03          "01"
42          0.42          "11"

Create a quantum circuit that applies the quantum Fourier transform to five qubits.

gates = qftGate(1:5);
c = quantumCircuit(gates);

Connect to a remote quantum device through AWS. Create a task that runs the circuit on the device with 2000 shots.

dev = quantum.backend.QuantumDeviceAWS("Aspen-M-3");

Status: "queued"

save ARNstr.mat ARNstr

You can close the current MATLAB® session. To retrieve the previously queued task in a new MATLAB session, you can use the ARN of that task to create the QuantumTaskAWS object again.

Status: "running"

Wait for the task to finish and retrieve the result.

m =

QuantumMeasurement with properties:

MeasuredStates: [32×1 string]
Counts: [32×1 double]
Probabilities: [32×1 double]
NumQubits: 5

Create a quantum circuit that consists of a Hadamard gate and a controlled X gate to entangle two qubits.

gates = [hGate(1); cxGate(1,2)];
c = quantumCircuit(gates);

Connect to a remote quantum device through IBM. Create a task that runs the circuit 500 times on the device without error mitigation.

dev = quantum.backend.QuantumDeviceIBM("ibmq_qasm_simulator");

SessionID: <missing>
AccountName: "<my account name>"
Status: "queued"

Wait for the task to finish. Retrieve the result of running the circuit on the device.

m =

QuantumMeasurement with properties:

MeasuredStates: [4×1 string]
Counts: [4×1 double]
Probabilities: [4×1 double]
NumQubits: 2

Show the measurement result of running the circuit. Due to the noise in the physical quantum device, the $|01〉$ and $|10〉$ states can appear as measurements.

table(m.Probabilities,m.MeasuredStates, ...
VariableNames=["Probabilities","States"])
ans =

4×2 table

Probabilities    States
_____________    ______
0.536         "00"
0.018         "10"
0.024         "01"
0.422         "11"

Next, create a task that runs the circuit on the same device, but with quantum error mitigation. The error mitigation applies a collection of tools and methods to the measurement results that attempts to reduce the effects of measurement errors.

Wait for the task to finish. Retrieve the result of running the circuit on the device.

m =

QuantumMeasurement with properties:

MeasuredStates: [4×1 string]
Counts: [4×1 double]
Probabilities: [4×1 double]
NumQubits: 2

Show the measurement result of running the circuit with error mitigation. Here, the estimated probabilities of the $|01〉$ and $|10〉$ states are closer to 0.

table(m.Probabilities,m.MeasuredStates, ...
VariableNames=["Probabilities","States"])
ans =

4×2 table

Probabilities    States
_____________    ______
0.59254       "00"
0.001586       "10"
-0.0094173       "01"
0.4153       "11"

Create a quantum circuit that applies the quantum Fourier transform to five qubits.

gates = qftGate(1:5);
c = quantumCircuit(gates);

Connect to a remote quantum device through IBM. Create a task that runs the circuit on the device with 500 shots.

dev = quantum.backend.QuantumDeviceIBM("ibmq_qasm_simulator");

SessionID: <missing>
AccountName: "<my account name>"
Status: "queued"

You can close the current MATLAB session. To retrieve the previously queued task in a new MATLAB session, you can use the identifier of that task to create the QuantumTaskIBM object again.

SessionID: <missing>
AccountName: "<my account name>"
Status: "running"

Wait for the task to finish and retrieve the result.

m =

QuantumMeasurement with properties:

MeasuredStates: [32×1 string]
Counts: [32×1 double]
Probabilities: [32×1 double]
NumQubits: 5

## Input Arguments

collapse all

Quantum circuit, specified as a quantumCircuit object.

Quantum device, specified as a QuantumDeviceAWS or QuantumDeviceIBM object. Use the quantum.backend.QuantumDeviceAWS or quantum.backend.QuantumDeviceIBM constructor to create this object, which connects to a remote quantum device through AWS or IBM, respectively.

### Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: task = run(c,dev,NumShots=500) runs the quantum circuit c with 500 shots remotely on the quantum device dev.

AWS Devices

collapse all

Number of times to run the circuit, specified as a positive integer scalar. By default, NumShots is 100.

IBM Devices

collapse all

Number of times to run the circuit, specified as a positive integer scalar. By default, NumShots is 100.

Level of optimization to perform on the circuit, specified as a 3, 2, 1, or 0. An optimization level of 0 provides no optimization, and an optimization level of 3 provides the most optimization. By default, OptimizationLevel is 3.

Higher levels generate more optimized circuits. However, because the optimization rewrites a given input circuit to match the topology of a specific quantum device for execution (also known as transpilation), better optimization comes at the expense of longer transpilation times.

Option to apply error mitigation, specified as a numeric or logical 1 (true) or 0 (false). The error mitigation applies a collection of tools and methods to the measurement results that attempts to reduce the effects of measurement errors.

## Output Arguments

collapse all

Task that runs the circuit on a quantum device, returned as QuantumTaskAWS or a QuantumTaskIBM object. You can check the status of the task by querying the Status property of this object, where the status can be "queued", "running", "finished", or "failed". Once the task is finished, you can retrieve the measurement result from this object by using the fetchOutput function.

## Version History

Introduced in R2023a

expand all