qiskit-community / qiskit-optimization

Quantum Optimization
https://qiskit-community.github.io/qiskit-optimization/
Apache License 2.0
216 stars 132 forks source link

Replace opflow operators with quantum_info `SparsePauliOp` #433

Closed t-imamichi closed 10 months ago

t-imamichi commented 1 year ago

What is the expected enhancement?

As primitive-based algorithm is rolled out and opflow might be deprecated in the future, we might need to update Qiskit-optimization to replace opflow operators with SparsePauliOp of quantum_info. For example, to_ising returns PauliSumOp and from_ising receives PauliSumOp.

woodsp-ibm commented 1 year ago

I imagine we can transition over already to some degree if we choose. For from_ising we could probably support conversion for both the opflow OperatorBase and the quantum_info BaseOperator with the former type being deprecated, so things can be transitioned over. For to_ising maybe add an additional parameter that presently defaults to producing an OperatorBase (PauliSumOp), so any users code still works, but set it via when optimization uses it internally so it goes over to producing an OperatorBase - SparsePauliOp. Maybe this new parameter will be removed when only OperatorBase is emitted. I guess as far as the optimization stack is concerned its use of to_ising is all internal and can just be switched based on the algorithm, whether it be older QI based ones, so users existing code continues to work or the new primitive based ones that can take a BaseOperator directly - at least it looks that way for the minimum eigen optimizer. Of course the new primitive based algos still work with PaulisSumOp so switching at present is not strictly needed. But for the public API of to/from_ising it would probably be better to additionally do it a new way while supporting the old. Please note that with the new primitive Terra NumPy(Minimum)Eigensolver there is presently a bug Qiskit/qiskit-terra#9101

t-imamichi commented 1 year ago

Thank you for the feedback. Yes, we have to update the code without breaking user codes. I intend to work on it when opflow is deprecated and the new primitive-based algorithms get stable.

t-imamichi commented 10 months ago

done by #542