Running Pennylane circuit in IBMQ backend with Qiskit Runtime Session

Hi, I have a hybrid quantum-classical machine learning program which I am running on IBMQ backends using the qiskit-pennylane plugin. For each classical data-point, I need to run the quantum circuit with classical post processing of the expectation values. When running on IBMQ backends, the execution of each circuit corresponding to each data-point is submitted as a separate job. I was wondering if it is possible to use Qiskit Runtime Session with Pennylane circuit so that the whole program is submitted to IBMQ backend as a single job, and I do not have to wait in queue.

I am initializing “dev” in the following way-

dev = qml.device("qiskit.ibmq.circuit_runner", wires=n_qubits, backend="ibmq_quito", ibmqx_token=token)

Before running the loop on data points, I add-

with Session(service = service, backend = "ibmq_quito"):

but this does not work as the jobs are still being submitted as separate jobs. Is there a way to submit it as a single job?

1 Like

Im having similar issue trying to fit a variational classifier for 10 epochs in ibmq_quito is taking days, dont know what to do

1 Like

Hey @sdas!

Great question. This sounds a little strange to me… I’m going to confirm a couple things with some of our development team and I will get back to you as soon as I can :slight_smile:

Thanks @isaacdevlugt . Looking forward to your reply. If this function does not already exist, it will be very useful to add.

Hey @sdas!

There’s a batch_execute method that each of the pennylane-qiskit devices have (e.g. IBMQDevice — PennyLane-Qiskit 0.32.0-dev documentation). Does that do the trick for you?

Hi @isaacdevlugt this function does not seem to be useful. I have only one circuit which needs to run once for each data point. For example, a variational quantum circuit is trained for a model, and now I predict each data-point from the test set. I want that for the whole test dataset, the IBMQ device will be reserved for me (which you can achieve using Qiskit Runtime session), and I do not have to wait in queue for every data point.
I cannot use Qiskit runtime service because my network is a mixture of classical and quantum layers, where the quantum layer is defined as a pytorch nn.Module.

@sdas I think what’s best at this point is to see a minimal code example (as small as possible :pray: :sweat_smile:). Look forward to hearing back!

Also have the same problem. Is there a way to run qiskit primitives such as Sampler or Estimator with Pennylane? This would likely work in a session.

Hey @joaofbravo! Welcome to the forum :slight_smile:.

It might be best to make a new forum post for this :sweat_smile:, but the answer to your question is yes to Sampler (see here) and I don’t think so for estimator.

1 Like

I was wondering what the status of Qiskit runtime session support is within Pennylane. Are there any updates? I can’t seem to find any news

Hey @Matteo_Argenton! Welcome to the forum :slight_smile:

Check this documentation out: Qiskit Runtime Programs — PennyLane-Qiskit 0.35.0-dev documentation

Also, be on the lookout for v0.35 of PennyLane coming out next week! We have some exciting features for importing Qiskit code into PennyLane :eyes: