Main Content

wait

Wait for quantum task to reach status

Since R2023a

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

Description

wait(task) waits for the quantum task to reach a "finished" or "failed" status. This function checks the Status property of the quantum task.

example

wait(task,status) waits for the quantum task to reach the specified status. The status input must be "finished" (default) or "running". If the status of the task reaches "failed" while waiting, then wait automatically stops waiting.

tf = wait(task,status,timeout) specifies the timeout period (in seconds) to wait for the quantum task to reach the specified status. If the task does not reach the specified status within the timeout period (it times out), then tf is returned as false. Otherwise, tf is returned as true.

example

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 Amazon® Web Services (AWS®). Create a task that runs 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-4c56def7a890"
     Status: "queued"

Wait for the task to finish running.

wait(task)
task
task = 

  QuantumTaskAWS with properties:

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

Retrieve the measurement result of running the circuit.

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.

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 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 the IBM® Qiskit® Runtime Services. Create a task that runs the circuit on the device.

dev = quantum.backend.QuantumDeviceIBM("ibmq_qasm_simulator");
task = run(c,dev)
task = 

  QuantumTaskIBM with properties:

         TaskID: "123abcd4efa5bcdef890"
      SessionID: <missing>
    AccountName: "some_account_name"
         Status: "queued"

Wait for the task to finish running.

wait(task)
task
task = 

  QuantumTaskIBM with properties:

         TaskID: "123abcd4efa5bcdef890"
      SessionID: <missing>
    AccountName: "some_account_name"
         Status: "finished"

Retrieve the measurement result of running the circuit.

m = fetchOutput(task)
m = 

  QuantumMeasurement with properties:

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

Show the measurement result.

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

  3×2 table

    Probabilities    States
    _____________    ______
        0.59552       "00" 
      0.0034886       "01" 
          0.401       "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 1000 shots.

dev = quantum.backend.QuantumDeviceAWS("Lucy");
task = run(c,dev,NumShots=1000)
task = 

  QuantumTaskAWS with properties:

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

Wait for the task to reach the "running" status within the next 100 seconds. The wait function returns logical 0 (false), which means it times out and the task does not reach the "running" status within the 100-second timeout period.

tf = wait(task,"running",100)
tf =

  logical

   0

Check the current task status.

s = task.Status
s = 

    "queued"

Wait for the task to reach the "running" status within the next 300 seconds. The wait function returns logical 1 (true), which means it does not time out and the task reaches the "running" status before the 300-second timeout period.

tf = wait(task,"running",300)
tf =

  logical

   1

Check the current task status.

s = task.Status
s = 

    "finished"

Input Arguments

collapse all

Quantum task to wait for, specified as a QuantumTaskAWS or a QuantumTaskIBM object.

Status for the task to reach, specified as "finished" or "running".

Timeout period in seconds, specified as Inf or a positive integer scalar.

Version History

Introduced in R2023a