Non-blocking workflow for the single qudit simulator

In the previous examples we only ran our devices in a blocking mode. Basically the juypter notebook was blocked until the result was there. However, this is not always necessary the workflow that you would like. Sometimes you would like to start the job and see a few hours later what is its status. Here, we show how this works out in pennylane-ls.

import pennylane as qml
import numpy as np
import sys
from pennylane_ls import *
from heroku_credentials import username, password
testDevice = qml.device(
    "synqs.sqs", shots=50, username=username, password=password, blocking=False
)
testDevice.operations
{'load', 'rLx', 'rLz', 'rLz2'}

Submit a circuit

Let us start out with the submission of the circuit without blocking the full notebook.

@qml.qnode(testDevice)
def quantum_circuit(alpha=0):
    load(50, wires=0)
    rLx(alpha, wires=0)
    rLx(alpha, wires=0)
    rLz(alpha, wires=0)
    return qml.expval(SingleQuditOps.Z(0))
res = quantum_circuit(3)
res
tensor('Job_not_done', dtype='<U12', requires_grad=True)
print(quantum_circuit.draw())
 0: ──load(50)──rLx(3)──rLx(3)──rLz(3)──┤ ⟨Z⟩ 

Access job_id

After your ran the job you receive a job_ib. You should save them somewhere for later access. If you submit multiple jobs corresponding to one simulation for e.g you wanted to scan a parameter, consider making a dictionary that maps the value of the scan parameter to its job id. You can save this dictionary on your disk (maybe as a JSON) and later access it. Or you can use a different method you prefer!

testDevice.job_id
'20211102_160251-singlequdit-synqs_test-bcfae'

Run measurement functions later on!

Since our job_id class variable) is still saved in memory, we can directly call measurement functions.

testDevice.expval("Z", wires=0, par=0)
'Job_not_done'
testDevice.var("Z", wires=0, par=0)
'Job_not_done'

Run measurement functions much later on!

Lets say our job_id (class variable) is not saved in memory anymore. But we have saved the job_id of the job whose results we want. The we can simply set the value of the job_id class variable and then call measurement functions.

If you submit multiple jobs corresponding to one simulation for e.g you wanted to scan a parameter, consider making a dictionary that maps the value of the scan parameter to its job id. You can save this dictionary on your disk (maybe as a JSON) and later access it. Or you can use a different method you prefer!

Try running only the following cells (directly after import statements) without running the quantum circuit function.

testDevice.reset()
testDevice.job_id = '20211102_160251-singlequdit-synqs_test-bcfae'
testDevice.expval("Z", wires=0, par=0)
0.74
testDevice.var("Z", wires=0, par=0)
0.8724