Skip to content

Remove Opflow and QI #17

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

Merged
merged 27 commits into from
Jul 26, 2023
Merged

Remove Opflow and QI #17

merged 27 commits into from
Jul 26, 2023

Conversation

ElePT
Copy link
Collaborator

@ElePT ElePT commented Jul 25, 2023

Summary

This PR fixes #15. I think that this is a helpful removal in terms of code maintenance and "self-containedness" of the qiskit-algorithms repo, however, I am not 100% sure about how strict we should be with Qiskit's deprecation policy, which states that the code should stay for 2 releases after deprecation. I am not too worried because the old code is still in terra, but I wonder if it is best to keep this PR on hold until the terra code is removed.

Also fixes #11.

Details and comments

There are a couple of unit tests that fail, I wanted to put the PR out there first, and then ask for help to fix these specific algorithms, as I am not a particular expert in them (I suspect that I butchered them a bit). Namely:

  • test.time_evolvers.test_trotter_qrte -> deprecation warning handling only
  • test.test_phase_estimator -> deprecation warning handling only
  • test.test_amplitude_estimators
  • test.optimizers.test_spsa
  • test.optimizers.test_optimizers (qnspsa test)
  • test.optimizers.test_gradient_descent
  • test.minimum_eigensolvers.test_adapt_vqe -> deprecation warning handling only
  • flaky deprecation warnings

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

It's a solid idea not to bring over-deprecated code into this new repo because it continues to exist in Terra. That indeed makes this repo easier to work with.

You only will want to consider improving the deprecation messages here and in Terra to clarify that for opflow, you should keep using Terra rather than qiskit_algorithms. As in, runtime warnings and our documentation.

But, it is an awkward user experience that they're going to get one deprecation message saying "use qiskit_algorithms!" and another that says "opflow is deprecated, and don't use qiskit_algorithms". So, it depends on how important it is to avoid that confusing UX.

@ElePT
Copy link
Collaborator Author

ElePT commented Jul 25, 2023

But, it is an awkward user experience that they're going to get one deprecation message saying "use qiskit_algorithms!" and another that says "opflow is deprecated, and don't use qiskit_algorithms". So, it depends on how important it is to avoid that confusing UX.

Thanks @Eric-Arellano!!! I think that if we improve the terra deprecation message to specify that if you absolutely want to keep using the old code you should not migrate to the new repo, and the releasenote in #19, it is hopefully clear enough for users. I think it is the best way to go about it.

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Jul 25, 2023

If people want to stick with the deprecated code, or use it as they see an example out there these will all be Terra and they can stay with that as long as the code exists. To move here, they need to get off the deprecated code. Ideally they should do this as soon as its convenient for them as the code will be removed and no longer supported later this year. I see no reason to duplicate deprecated code here, indeed every reason not too. It was just expedient to copy the whole algos over, then prune things out. Some logic has already been removed right, the QI based (minimum)eigensolvers where it was all or nothing in terms of the code. What remains is just the algorithms like Grover which supported both and an internal switch one way or another so removal is a little bit more delicate surgery. Having some logic here supporting opflow/QI and some already gone will be rather confusing. This should be a clean start for primitive based algos - but is one that also alleviates moving over to it as its the same primitive based algos as in Terra just a slightly different import. But you have to have migrated to using that in Terra or migrate directly here with the caveat that its the same deal but with the extra import change too.

In regards of Eric's comment You only will want to consider improving the deprecation messages here we should be starting out with clean slate, no deprecated warnings from the get go. I don't think by the time the code is cleaned up and opflow/QI usage removed that any will exist - none should exist right.

@Eric-Arellano
Copy link
Contributor

In regards of Eric's comment You only will want to consider improving the deprecation messages here we should be starting out with clean slate, no deprecated warnings from the get go. I don't think by the time the code is cleaned up and opflow/QI usage removed that any will exist - none should exist right.

To clarify, I mean the holistic experience of deprecation messages, including considering tweaking messages in Terra itself.

@woodsp-ibm
Copy link
Member

including considering tweaking messages in Terra itself.

Yes, the entire "messaging" which includes what we say in release notes. maybe augmenting the existing algorithm migration guide with info around this additional move etc I only picked on that bit since it seemed to be talking about deprecation warnings/messages here, and I think we will have none being emitted from the code. Now we have text in a release note trying to explain things - I just updated it in #13 to fix it for CI and at the same time I tried to improve the content/format, and issue #7 was created with an intent to add some stuff to the readme here that could also inform what happening with the algorithms. So addressing it from a holistic view I agree.

@coveralls
Copy link

coveralls commented Jul 26, 2023

Pull Request Test Coverage Report for Build 5671689784

  • 215 of 260 (82.69%) changed or added relevant lines in 22 files are covered.
  • 64 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.8%) to 89.796%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_algorithms/amplitude_amplifiers/grover.py 3 4 75.0%
qiskit_algorithms/eigensolvers/numpy_eigensolver.py 11 13 84.62%
qiskit_algorithms/phase_estimators/ipe.py 6 9 66.67%
qiskit_algorithms/amplitude_estimators/ae.py 14 18 77.78%
qiskit_algorithms/amplitude_estimators/mlae.py 21 25 84.0%
qiskit_algorithms/phase_estimators/hamiltonian_phase_estimation.py 24 28 85.71%
qiskit_algorithms/time_evolvers/classical_methods/evolve.py 3 8 37.5%
qiskit_algorithms/amplitude_estimators/fae.py 42 49 85.71%
qiskit_algorithms/amplitude_estimators/iae.py 57 64 89.06%
qiskit_algorithms/phase_estimators/phase_estimation.py 18 26 69.23%
Files with Coverage Reduction New Missed Lines %
qiskit_algorithms/phase_estimators/hamiltonian_phase_estimation_result.py 1 92.59%
qiskit_algorithms/phase_estimators/phase_estimation.py 1 84.48%
qiskit_algorithms/time_evolvers/classical_methods/evolve.py 1 87.84%
qiskit_algorithms/time_evolvers/trotterization/trotter_qrte.py 2 94.87%
qiskit_algorithms/optimizers/spsa.py 4 91.89%
qiskit_algorithms/phase_estimators/phase_estimation_scale.py 4 80.0%
qiskit_algorithms/amplitude_estimators/iae.py 9 85.38%
qiskit_algorithms/amplitude_estimators/mlae.py 13 87.5%
qiskit_algorithms/amplitude_estimators/ae.py 14 88.6%
qiskit_algorithms/phase_estimators/phase_estimation_result.py 15 67.35%
Totals Coverage Status
Change from base Build 5671615478: -0.8%
Covered Lines: 6380
Relevant Lines: 7105

💛 - Coveralls

@ElePT ElePT marked this pull request as ready for review July 26, 2023 15:07
@ElePT ElePT requested a review from Cryoris as a code owner July 26, 2023 15:07
@ElePT ElePT force-pushed the remove-opflow-qi branch from b5842be to 3e6c6be Compare July 26, 2023 15:47
@@ -311,7 +310,8 @@ def estimate(self, estimation_problem: EstimationProblem) -> "AmplitudeEstimatio
"The state_preparation property of the estimation problem must be set."
)
if self._sampler is None:
raise ValueError("A sampler must be provided.")
warnings.warn("No sampler provided, defaulting to Sampler from qiskit.primitives")
Copy link
Member

@woodsp-ibm woodsp-ibm Jul 26, 2023

Choose a reason for hiding this comment

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

I would have more likely done this in the sampler setter - let it take None and if None set to the reference one. Document in the constructor/setter that None will use the reference sampler - set it in the contructor via the setter. And then no need for any warning. This is what ML does for QNNs taking a Sampler etc. This will work though and if you want to go with this for now...

woodsp-ibm
woodsp-ibm previously approved these changes Jul 26, 2023
@mergify mergify bot merged commit 50e168c into qiskit-community:main Jul 26, 2023
@ElePT ElePT added this to the 0.1.0 milestone Jul 27, 2023
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.

Remove deprecated algorithm use of opflow/QI Change AlgorithmsTestCase base class
4 participants