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

Replace qiskit.algorithms with qiskit_algorithms #537

Merged
merged 15 commits into from
Sep 5, 2023

Conversation

t-imamichi
Copy link
Collaborator

@t-imamichi t-imamichi commented Aug 21, 2023

Summary

Replace qiskit.algorithms with qiskit_algorithms except QAOAClient and VQEClient because they are deprecated.

This PR requires qiskit-algorithms>=0.2.0 to switch to qiskit_algorithms.utils.algorithm_globals.

Details and comments

@woodsp-ibm
Copy link
Member

  • We should add qiskit_algorithms to the requirements file.

  • Once 0.2.0 of qiskit_algorithms in released we can also switch here from qiskit.utils import algorithm_globals over to the equivalent class in qiskit_algorithms i.e. from qiskit_algorithms.utils import algorithm_globals and make that the min version in the requirements file. Similar to noted here /Switch to qiskit_algorithms qiskit-finance#291 qiskst_algorithms works with either but that file in utils in Qiskit, along with another that's only used by algorithms. I expect to be deprecated and removed when the algorithms are removed from Qiskit so its better to switch now.

@coveralls
Copy link

coveralls commented Aug 22, 2023

Pull Request Test Coverage Report for Build 5949370263

  • 17 of 17 (100.0%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 92.427%

Totals Coverage Status
Change from base Build 5947076830: 0.01%
Covered Lines: 4455
Relevant Lines: 4820

💛 - Coveralls

@t-imamichi
Copy link
Collaborator Author

Yes, I added qiskit-algorithms in requirements.txt.

OK. I will switch to from qiskit_algorithms.utils import algorithm_globals. When is qiskit-algorithms 0.2.0 planned? Is it soon?

@woodsp-ibm
Copy link
Member

When is qiskit-algorithms 0.2.0 planned? Is it soon?

Should be very soon now.

@t-imamichi
Copy link
Collaborator Author

It's ready to review because qiskit-algorithms 0.2.0 was released on Aug 24.

@woodsp-ibm
Copy link
Member

@t-imamichi My take is that I think the logic ought to be able to take a qiskit.algorithms instance or a qiskit_algorithms one. The instance checks there I think will prevent the former. That may end up being a tradeoff in what sort of upfront checks can be made and how much we want to switch to just using qiskit_algorithms and no longer refer to qiskit.algorithms at this point. Did you see the post in the thread in the internal algorithms related discussion channel - where you mentioned this PR it was a response to that - it includes some thoughts about this and more.

@t-imamichi
Copy link
Collaborator Author

@woodsp-ibm Thanks. I tried to remove all imports of qiskit.algorithms 63474dc. It would work fine with qiskit.algorithms implicitly. But, it requires #542 to pass the unit tests because some legacy tests uses qiskit.algorithms that need to be removed first.

README.md Outdated Show resolved Hide resolved
# Conflicts:
#	docs/tutorials/02_converters_for_quadratic_programs.ipynb
#	qiskit_optimization/algorithms/grover_optimizer.py
#	qiskit_optimization/algorithms/minimum_eigen_optimizer.py
#	qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py
#	requirements.txt
#	test/algorithms/test_grover_optimizer.py
#	test/algorithms/test_min_eigen_optimizer.py
Comment on lines +221 to +226
if not hasattr(eigen_result, "eigenstate"):
raise QiskitOptimizationError(
"MinimumEigenOptimizer does not support this minimum eigensolver "
f"{type(self._min_eigen_solver)}. "
"You can use qiskit_algorithms.SamplingMinimumEigensolver instead."
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of early type check of SamplingMinimumEigensolver or NumPyMinimumEigensolver, I added a result check when solve is invoked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will certainly result in a more friendly error message that is easier to understand. This is of course detected though after its run compute_minimum_eigenvalue which may take a lot of time/resources that ends up being wasted. An IDE via the typehinting should flag VQE (which I think we we most concerned about in 0.5 since in the past you could use this) as not being valid to be used for this algorithm. I think its ok - we can see how it goes - one suggestion I had made was to get the class name string from the solver instance and compare that up front to see if it was one of the primitive based VQE's we know about ie - that being just a string check does not require anything to be imported. But we could always add this later if users are still tripping up on VQE - since 0.5 has been out a while hopefully users are familiar enough now. And its quite clear now in the docs what is supported...

image

`Grover Adaptive Search <https://arxiv.org/abs/quant-ph/9607014>`_
(:class:`~algorithms.GroverOptimizer`), leveraging
fundamental :mod:`~qiskit.algorithms.minimum_eigensolver` provided by Qiskit Terra.
fundamental :mod:`~qiskit_algorithms.minimum_eigensolvers` provided by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With qiskit_algorithms this will not form a link as it will not resolve to any documentation since the minimum_eigensolvers module is not documented as it was before (before it was not a link either since it lacked the s at the end). I think its ok.

The Qiskit Algorithms link on the next line I think would be better to the published docs though so you go from docs to docs ie. use https://qiskit.org/ecosystem/algorithms/

And for the module above if you preferred it to be a link then it could be changed to make it a link to where the Minimum Eigensolvers are documented ie this https://qiskit.org/ecosystem/algorithms/apidocs/qiskit_algorithms.html#minimum-eigensolvers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I updated it to mention minimum eigensolvers with https://qiskit.org/ecosystem/algorithms/apidocs/qiskit_algorithms.html#minimum-eigensolvers instead of ~qiskit_algorithms.minimum_eigensolvers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, you did not push the change yet then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I forgot to push it. 10d057b

prelude: >
Qiskit Optimization 0.6 switches from ``qiskit.algorithms`` of Qiskit Terra
to `Qiskit Algorithms <https://github.com/qiskit-community/qiskit-algorithms>`_.
Qiskit Optimization 0.6 drops supports of the former algorithms based on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although support for the qiskit.algorithms primitive based ones is dropped, for the moment since they are compatible with what was migrated to qiskit_algorithms they should still work so any users code should still work as they transition/upgrade it - right.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether I have to mention qiskit.algorithms is not officially supported by qiskit-optimization but it works actually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent was really to have it work so users had a easier transition. Code that they had working based on primitives should still work with this new version. Then they can simply switch the code to qiskit_algorithms and it should work just like before.

@@ -40,6 +41,7 @@
class TestGroverOptimizer(QiskitOptimizationTestCase):
"""GroverOptimizer tests."""

@unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, since the reference Sampler is probably fast enough, we could probably change tests like these so we do not require Aer any longer and this test no longer is an optional one - though CI of course will install Aer. I would leave things as they are now. Its more just a comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that I removed this line accidentally in #542. I intended to revert the removal in this PR. It requires aer sampler because terra sampler takes much more time than aer sampler (#451 for details).

@mergify mergify bot merged commit 80e7ef7 into qiskit-community:main Sep 5, 2023
15 checks passed
@t-imamichi t-imamichi deleted the qiskit_alg branch September 5, 2023 01:51
@svdbtno
Copy link

svdbtno commented Sep 12, 2023

@t-imamichi When can we expect this to be released?

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

Successfully merging this pull request may close these issues.

4 participants