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

QAOA algorithms not working with IBM's latest update #81

Closed
BrunoRosendo opened this issue Apr 18, 2024 · 4 comments · Fixed by #89
Closed

QAOA algorithms not working with IBM's latest update #81

BrunoRosendo opened this issue Apr 18, 2024 · 4 comments · Fixed by #89
Labels
bug Something isn't working cplex P0

Comments

@BrunoRosendo
Copy link
Owner

BrunoRosendo commented Apr 18, 2024

This issue came up in #44, and it's related to an update made recently by IBM (March 2024): https://docs.quantum.ibm.com/run/primitives-examples

beginning 1 March 2024, Qiskit Runtime will require that circuits and observables are transformed to use only instructions supported by the system (referred to as instruction set architecture (ISA) circuits and observables) before being submitted to the primitives

The issue was created 1 month ago without much track qiskit-community/qiskit-algorithms#164 . I have commented on it and I saw more people complain about the same issue on slack. This happens not only on qiskit-algorithms but also other libraries, such as qiskit-machine-learning and qiskit-optimization.

The problem does not happen when using BackendSampler instead of SamplerV1 of qiskit-ibm-runtime. SamplerV2 is not yet supported by the library. The problem with using BackendSampler is the lack of sessions, making it unfeasible to run the algorithms (check #44 for details).

Based on the announcement and the thread below, I tried transpiling the ansatz and adding a padding to the operator (observable) as to match the number of qubits in the backend. However, I can't find a way to add the padding. Even if I did, I think there would be more problems. I made a fork with that approach, used in feature/qaoa-fork

https://quantumcomputing.stackexchange.com/questions/29332/how-to-avoid-delays-must-be-a-multiple-of-16-samples-error-with-estimator-sa

For now, I'm going to wait for a potential fix on qiskit's part. If that doesn't happen, I will try once again to fix their library

@BrunoRosendo BrunoRosendo added bug Something isn't working P0 cplex labels Apr 18, 2024
@BrunoRosendo
Copy link
Owner Author

I found quite useful information on slack. One way to possibly fix this:

To the original poster. As QAOA does not allow you to pass an ansatz, which should be a transpiled circuit now, one thing you could use instead is SamplingVQE with the QAOAAnsatz from the Qiskit circuit library (which is what QAOA does as its just a simple sub-class of SamplingVQE). You would need to have the operator - to set number of qubits for the circuit - lets gets to that. To get the operator you would have to create the problem and convert it to_ising yourself so you have the operator you can use directly with the algorithm. Ie you would not be using MinimumEigenOptimizer which does this for you. With the operator you can get its num_qubits and set the QAOAAnsatz up and then transpile it. That gets the circuit part. The next bit would be to make sure the operator (observable) matches the transpiled circuit using apply_layout. If you look at the second link in my post above you will find that in the first Estimator example. Once you have the result of the algorithm you can interpret it in the context of the original problem. You can look at the code in MinimumEigenOptimizer for an example. I knew this ISA requirement for real devices - I was not aware of it being done for simulators though. The other choice would be to install Qiskit Aer and run this locally via an Aer Primitive on your machine as the ISA requirement is for IBM Runtime.

Thanks Steve, that's really useful. Just for others' reference, I found an alternative way which involves converting the QuadraticProgram to an Ising, applying the layout, and converting it back into a QuadraticProgram, which means the MinimumEigenOptimizer can still be used

@BrunoRosendo
Copy link
Owner Author

This slack thread has additional doubts that might arise https://qiskit.slack.com/archives/C7SS31917/p1713377308386869

@BrunoRosendo
Copy link
Owner Author

Something like this is likely necessary hamiltonian_isa = hamiltonian.apply_layout(layout=ansatz_isa.layout)

@BrunoRosendo
Copy link
Owner Author

The problem is solved on my fork https://github.com/BrunoRosendo/qiskit-algorithms, although this only works for minimum eigen value case. The reason for this is the fix only works for SparsePauliOp, while SamplingVQE supports all kinds of BaseOperator

I tested in IBM runtime with and without warm start. The Queue is currently very long so I'll wait a bit to complete #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cplex P0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant