Batching Inputs to Quantum Circuit


#1

Is there a way to batch inputs to a circuit? I’m trying to use Pennylane to train a circuit to do image classification on MNIST, and as it is right now for each batch I pass each input individually, gather their gradients together, and then do an optimizer step. According to back of the envelope calculations, to get through the 60000 / 128 batches it will take around 16 hours. I can post code if need be.

Thanks so much!


#2

Hi kushkhosla,

At the moment, there is no direct way to batch inputs. Obviously batching of outputs can be done by asking for more shots, but no such trick works for inputs. What you are doing now is the recommended method.

If the device backends supported batching natively (either hardware or software), we could potentially add functionality to PennyLane to leverage this. Alternatively, we could implement batching internally in PennyLane itself as a convenience to the user.

The second one is more likely to be implemented sooner (since it is under our control), but might also necessity larger compute power in order to run faster (e.g., parallel computing).

I know this doesn’t help with your current problem, but it gives you an idea of what we’re thinking.