Optimising hybrid quantum classical machine learning code

Hi there!

I am currently running the Patch Quantum GAN notebook and was investigating ways to speed up the code execution time. I believe the options are as follows:

  1. GPU: I am using the’ lightning.gpu’ device for GPU utility. However, as I understand, this only benefits when using a large number of qubits for a single circuit. The patch method utilises multiple quantum circuits, each with around ~8 qubits, so I believe I wouldn’t see a speed up there. Would using the ‘lightning.kokkos’ device instead provide the speed up I am looking for?
  2. Multiprocessing on CPU: Given default.qubit and lightning.qubit are CPU devices, is multiprocessing on the CPU/CPUs with multiple cores to increase the execution time available i pennylane.
    3.Overall is there a way when using the ‘Patch Quantum Gan’ (as coded in your demo for example) to improve the execution time by either running all circuits somehow in parallel during execution (and computing gradients in parallel) or some sort of vectorised mapping?
  3. Currently all my code is written using pennylane/pytorch, switching to jax/jit and flax in the long-run would probably be the best bet but for now i am concerned with how to execute the algorithms better from—a hardware perspective.

Hi @Aaron_Thomas.

  1. I don’t think any of the lightning devices will provide speedups over default.qubit if you have 8 qubits. Maybe lightning.qubit can, but I really doubt that lightning.kokkos will help a lot here.
  2. Note that multithreading won’t necessarily make execution faster. This will depend on the overheads related to the specific problem and the number of threads chosen. With default.qubit you can indeed do multiprocessing. Make sure to follow the examples here in the docs. lightning.qubit allows parallel differentiation over observables by setting the OMP_NUM_THREADS environment variable. You can find more info here in the lightning docs.
  3. Switching to Jax could be a good first step. We’re working on a library called Catalyst which is designed for hybrid quantum-classical just-in-time compilation. The goal is to allow you to run programs more efficiently on quantum hardware and simulators. It’s still in Beta but this could be a good time to start exploring it and adapting your code to be able to use it. Note that things might break for a while, but we’re very open to hearing your feedback so that we can keep improving it.

I hope this helps!