Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use Qiskit features such as AmplitudeEstimation #200

Closed
jplewa opened this issue Dec 16, 2021 · 3 comments · Fixed by #201
Closed

Unable to use Qiskit features such as AmplitudeEstimation #200

jplewa opened this issue Dec 16, 2021 · 3 comments · Fixed by #201

Comments

@jplewa
Copy link
Contributor

jplewa commented Dec 16, 2021

I've been trying to play around with this example from Qiskit's docs. To submit the circuit to IonQ via Azure, I'm using these instructions.
When I get to the line ae_result = ae.estimate(problem), I end up getting the following error:

FAILURE: Can not get job id, Resubmit the qobj to get job id. Error: 'list' object has no attribute 'clbits' 

This is printed out in a loop until my computer runs out of RAM. If I run the code on IBM's online Quantum Lab, the code terminates with the error:

FAILURE: Can not get job id, Resubmit the qobj to get job id. Error: 'list' object has no attribute 'clbits' 
FAILURE: Can not get job id, Resubmit the qobj to get job id. Error: 'list' object has no attribute 'clbits' 
[...]
FAILURE: Can not get job id, Resubmit the qobj to get job id. Error: 'list' object has no attribute 'clbits' 
Traceback (most recent call last):
  File "/tmp/ipykernel_240/1492105537.py", line 1, in <module>
    ae_result = ae.estimate(problem)
  File "/opt/conda/lib/python3.8/site-packages/qiskit/algorithms/amplitude_estimators/ae.py", line 314, in estimate
    counts = self._quantum_instance.execute(circuit).get_counts()
  File "/opt/conda/lib/python3.8/site-packages/qiskit/utils/quantum_instance.py", line 774, in execute
    run_circuits(
  File "/opt/conda/lib/python3.8/site-packages/qiskit/utils/run_circuits.py", line 507, in run_circuits
    job, job_id = _safe_submit_circuits(
  File "/opt/conda/lib/python3.8/site-packages/qiskit/utils/run_circuits.py", line 694, in _safe_submit_circuits
    raise QiskitError("Max retry limit reached. Failed to submit the qobj correctly")
QiskitError: 'Max retry limit reached. Failed to submit the qobj correctly'

Is this the intended behavior? I'm able to run the circuit if I construct it manually via ae.construct_circuit(problem, measurement=True) and submit that to IonQ, but this way I can't use any of the nice post-processing provided by the wrapper.

Apologies if this isn't the right way to ask, but I have no idea if this is a Qiskit, Azure, or IonQ issue.

@guenp
Copy link
Contributor

guenp commented Dec 16, 2021

Thanks @jplewa for submitting this issue! It looks like we currently don't support the Qiskit QuantumInstance. I'm looking into this now.

Meanwhile, as a workaround you could try to manually generate the circuit, transpile it and add measurement operators.

Please give this code snippet a try and let me know if it works (picking up after defining the problem and quantum_instance objects in the sample notebook):

ae_circuit = ae.construct_circuit(problem)
ae_circuit = transpile(ae_circuit, backend)
ae_circuit.add_register(0,ae_circuit.num_qubits)
for n in range(num_qubits):
    ae_circuit.measure(n,n)

job = execute(ae_ciarcuit, backend=backend)
job_monitor(job)
result = job.result()
count = result.get_counts(ae_circuit)

@jplewa
Copy link
Contributor Author

jplewa commented Dec 16, 2021

It looks like we currently don't support the Qiskit QuantumInstance. I'm looking into this now.

I think the errors are caused by this line in qiskit-ionq:
https://github.com/Qiskit-Partners/qiskit-ionq/blob/552760543d34ea7ba62b011e42e04d35da8c0c36/qiskit_ionq/helpers.py#L134
The method expects a circuit, but I'm pretty sure in my case it gets a list of circuits. Qiskit Terra accepts either a circuit or a list and then passes it to azure-quantum, which in turn passes it to qiskit-ionq (which doesn't know how to handle that). This whole thing seems related to this issue from April.

Meanwhile, as a workaround you could try to manually generate the circuit, transpile it and add measurement operators.

I know :) But I would have to implement my own Maximum Likelihood Estimator to be able to obtain equivalent results (the AmplitudeEstimation class has this implemented). I'm also facing the same issues with IterativeAmplitudeEstimation, MaximumLikelihoodAmplitudeEstimation, and FasterAmplitudeEstimation - implementing all of those algorithms from scratch doesn't sound like something I particularly want to do ;)

EDIT: The troublesome method from qiskit-ionq gets called here:
https://github.com/microsoft/qdk-python/blob/b309b0bfeda778a8cc5049af7ae5728448e84ffc/azure-quantum/azure/quantum/qiskit/backends/ionq.py#L61
Azure-quantum doesn't seem to be ready for lists of circuits either, since in the following line you refer to circuit.num_qubits. This will also fail if circuit is a list :)

@jplewa
Copy link
Contributor Author

jplewa commented Dec 17, 2021

FYI, my circuit becomes a one-element list of circuits after the method qiskit.utils.quantum_instance.QuantumInstance.transpile is called.

Quoting the docs:

        Returns:
            List['QuantumCircuit']: The transpiled circuits, it is always a list even though
                the length is one.

I checked out how this is done in AerBackend and I can see that they have separate implemetations of AerJob and AerJobSet depending on whether they're dealing with a single circuit or a list. The distinction happens here. IonQBackend from azure-quantum doesn't seem to be making this distinction.

I also figured out that qiskit-ionq (which doesn't support multi-circuit experiments either) added a PR that at least makes it possible to run one-element circuit lists (see qiskit-community/qiskit-ionq#71). They also have more explicit error messages. I'll submit a PR to do the same here. This way at least some of Qiskit's features will be available (although MaximumLikelihoodAmplitudeEstimation will remain unavailable, since it submits multiple circuits at the same time by design). EDIT: The four amplitude estimation methods available in Qiskit should start working once this is merged. I thought MLAE wouldn't work, but it does due to the changes introducted in Terra in Qiskit/qiskit#6391 (a circuit list with miltiple elements will get split up into one-element batches depending on the backend).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants