Main Content

quantum.backend.QuantumTaskAWS class

Package: quantum.backend

Task sent to AWS for execution on quantum device

Since R2023a

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

Description

A QuantumTaskAWS object represents a task sent for execution on a quantum device that is available through Amazon® Web Services (AWS®). To work with remote devices and data using AWS, you must first set up access following the steps in Run Quantum Circuit on Hardware Using AWS.

The quantum.backend.QuantumTaskAWS class is a handle class.

Creation

Use the run function to run a quantum circuit remotely on a quantum device available through AWS and return the task as a QuantumTaskAWS object.

Additionally, you can create a QuantumTaskAWS object from an existing remote task on AWS using the task ARN (Amazon Resource Name) with the following syntax.

Description

example

task = quantum.backend.QuantumTaskAWS(taskARN) returns a QuantumTaskAWS handle object that is attached to an existing remote task on AWS with the specified task ARN. You can retrieve the task ARN of an existing task by accessing its TaskARN property value or by using the AWS web interface. This syntax sets the TaskARN property to taskARN.

A remote task expires after some time. Use fetchOutput on the QuantumTaskAWS object and save the returned QuantumMeasurement object to store the result.

Note

Saving and loading QuantumTaskAWS objects in MATLAB® are not supported. To check on a task from a previous MATLAB session, save the TaskARN property value of the QuantumTaskAWS object from the previous session and construct a new QuantumTaskAWS object in the new MATLAB session.

Properties

expand all

Status of the task, returned as "queued", "running", "finished", or "failed".

Attributes:

GetAccess
public
SetAccess
private

ARN identifier of the task, returned as a string scalar.

This property value can be saved and used in a future MATLAB session to construct a new QuantumTaskAWS object and query the task status.

Attributes:

GetAccess
public
SetAccess
private

Methods

expand all

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 by running the circuit on the device.

dev = quantum.backend.QuantumDeviceAWS("Aspen-M-3");
task = run(c,dev)
task = 

  QuantumTaskAWS with properties:

    TaskARN: "arn:aws:braket:us-west-1:123456789012:quantum-task/12a34b5c-6a78-9a01-2ab3-4c56def7g890"
     Status: "queued"

Wait for the task to finish and retrieve the result.

wait(task)
m = fetchOutput(task)
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.

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

  4×3 table

    Counts    Probabilities    States
    ______    _____________    ______

      47          0.47          "00" 
       2          0.02          "10" 
       5          0.05          "01" 
      46          0.46          "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");
task = run(c,dev,NumShots=2000)
task = 

  QuantumTaskAWS with properties:

    TaskARN: "arn:aws:braket:us-west-1:123456789012:quantum-task/12a34b5c-6a78-9a01-2ab3-4c56def7g890"
     Status: "queued"

Save the ARN string value in the task.TaskARN property.

ARNstr = task.TaskARN;
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 previously saved ARN of that task to create the QuantumTaskAWS object again.

load ARNstr.mat
task = quantum.backend.QuantumTaskAWS(ARNstr)
task = 

  QuantumTaskAWS with properties:

    TaskARN: "arn:aws:braket:us-west-1:123456789012:quantum-task/12a34b5c-6a78-9a01-2ab3-4c56def7g890"
     Status: "running"

Wait for the task to finish and retrieve the result.

wait(task)
m = fetchOutput(task)
m = 

  QuantumMeasurement with properties:

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

Version History

Introduced in R2023a