Does Pennylane support a general Qiskit runtime program?

Does Pennylane support a general Qiskit runtime program?
I have a general variational quantum algorithm (VQA) written in Pennylane. It needs multiple (100~200) iterations and each iteration involves both classical optimizer and quantum circuits (e.g., getting qml.expval). My VQA is not a VQE and it does not even have a Hamiltonian. My question is, if I need to run this VQA on IBM quantum hardware, does pennylane support a custom runtime program such that I can run the VQA in Qiskit runtime program? If yes, any examples? If not, what are your suggestions to make it work? For example: translate the pennylane code into qiskit code and then run in Qiskit runtime environment? Any other solutions?

Another question is: for the vqe_runner() given in this link [Qiskit Runtime Programs — PennyLane-Qiskit 0.28.0-dev documentation], can the optimizer use pennylane’s ADAM or not? If yes, how to write the code to do it?

Thanks!

Hi @Jim ,

Yes, you can use the IBMQCircuitRunnerDevice and the IBMQSamplerDevice to create your own Qiskit Runtime program. In the link you shared you can see an example of how to use them.

Regarding your second question, in our blog post on How to create your own optimizer you will find a section on using built-in optimizers in PennyLane. Here you will find an example of using the Adam optimizer. I’m not sure whether or not this will work with qiskit runtime but you can give it a try.

Please let me know if you manage to get this working!

1 Like

Hello @CatalinaAlbornoz ,
Thanks for your reply! I appreciate it. The link you provided for the second question was very helpful.

Regarding the 1st question, I feel like the RunnerDevice and SamplerDevice correspond to two default programs in IBM Runtime programs. For example, IBM Runtime has these programs: hello-world, qaoa, torch-train, torch-infer, qasm3-runner, sampler, estimator, sample-expval, vqe, circuit-runner, sample-program, quantum-kernel-alignment.

In IBM Runtime, you will need to upload a program using provider.runtime.upload_program(…) to have a customized program, which, for example, can upload a user-written python file. See this link [https://qiskit.org/documentation/apidoc/ibmq_runtime.html#listing-runtime-programs] for more details.

I tried to find the corresponding upload function in Pennylane in the two device links you provided to upload my own program but couldn’t find it. Are there any more detailed documents/examples if Pennylane supports customized program upload? Thanks!

Hi Jim, Thank you for your interest in PennyLane Qiskit. Indeed you can upload a specific runtime program with PennyLane, Qiskit Runtime Programs — PennyLane-Qiskit 0.28.0-dev documentation . We only provide a custom VQE runner, so you would have to build your own VQA runner. But you can use the same logic as the VQE runner vqe_runner — PennyLane-Qiskit 0.28.0-dev documentation and adapt it on your side. If you want to share it with other people feel free to open a PR on the qiskit plugin :slight_smile:

1 Like

Hello @Romain_Moyard ,
Thank you for the information. I just clicked the ‘source’ of vqe_runner and I think I have a sense of what it is. When I get a chance, I will give it a try.

That’s awesome @Jim !