microsoft / azure-quantum-python

The azure-quantum python package submits jobs to the Azure Quantum service.
https://learn.microsoft.com/azure/quantum/
MIT License
126 stars 92 forks source link

Cannot submit list of circuits via AzureQuantumBackend.run #224

Open guenp opened 2 years ago

guenp commented 2 years ago

Currently, to submit multiple circuits, users have to submit each circuit individually, e.g.

jobs = []
for circuit in circuits:
    jobs.append(backend.run(circuit, shots=N))

results = []
for job in jobs:
    results.append(job.result())

Iterative algorithms require being able to submit a batch of circuits at the same time. There are several Qiskit libraries that depend on support for backend.run(circuits: List[QuantumCircuit]), such as qiskit-experiments and qiskit-aqua. See also: https://qiskit.org/documentation/stubs/qiskit.providers.ibmq.managed.IBMQJobManager.html#qiskit.providers.ibmq.managed.IBMQJobManager

This would require being able to submit multiple circuits and get a single job ID back to fetch the results, similar to the IBMQ experience. However, this is currently not something our service supports; Azure Quantum's Backend currently only accepts a single circuit or a list of circuits of length one, see this line: ionq.py#L70.

For instance, Tomography uses the backend.run() method under the hood which returns a single job: base_experiment.py#L345.

guenp commented 2 years ago

It is currently not possible to use e.g. VQEProgram because backend.run(circuit) currently only accepts a single circuit, not a list of circuits: error_screen

anpaz commented 2 years ago

@guenp Adding support for job batching is a great idea, and it's on our road-map, but to be perfectly clear it is not a pre-requisite for qiskit-experiments, QAOA or VQE.

We were recently debugging the submission of StateTomography in qiskit-experiments and found that the problem was not a lack of support for job batching as the qiskit-experiment module takes care of submitting all the necessary jobs and keep track of their state; the problem was that the experiments depend on the circuit metadata to be part of the job's result object. This is fixed in #278; with this StateTomography is working correctly (albeit a couple of submission warnings for unsupported parameters).

With the change in place I've also tested the QAOA and VQE examples in qiskit-tutorials and they also ran successfully.

So, I'm thinking we should close this enhancement since the main scenarios you were trying to cover are working correctly. Thoughts?

guenp commented 2 years ago

Great, glad to hear that the workaround already exists in qiskit! I'll close this issue then.

guenp commented 2 years ago

After some more investigation as per @anpaz's comment above, we figured out that what is missing in the above example is not batch job support, but metadata on the submitted Jobs. This is addressed in this PR #278. However, there is clearly value for submitting multiple circuits as part of a single Job and this is not completely addressed in the above PR, so am reopening this issue for now so we can continue the discussion. I will also rename it to more accurately describe the problem.