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

Remove validation methods from primitive base classes #11052

Merged
merged 5 commits into from
Nov 1, 2023

Conversation

chriseclectic
Copy link
Member

Summary

This deprecates the argument validation methods from primitive base classes and moves them to separate helper functions. These methods unnecessarily bloat the base classes, and are odd to have when the BasePrimitive doesn't even define a run method to validate. There is no reason primitive implementations need to use the same validation as these base classes either. A follow up will be to remove the validation from the base run methods and have subclasses implement their own validation.

Details and comments

This deprecates the argument validation methods from primitive base classes and moves them to separate helper functions. These methods unnecessarily bloat the base classes, and are odd to have when the BasePrimitive doesn't even define a run method to validate. There is no reason primitive implementations need to use the same validation as these base classes either. A follow up will be to remove the validation from the base `run` methods and have subclasses implement their own validation.
@chriseclectic chriseclectic requested review from ikkoham, t-imamichi and a team as code owners October 19, 2023 17:46
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @ajavadia
  • @ikkoham
  • @levbishop
  • @t-imamichi

@chriseclectic chriseclectic added the Changelog: Deprecation Include in "Deprecated" section of changelog label Oct 19, 2023
@woodsp-ibm woodsp-ibm added the mod: primitives Related to the Primitives module label Oct 19, 2023
t-imamichi
t-imamichi previously approved these changes Oct 23, 2023
Copy link
Member

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ikkoham ikkoham left a comment

Choose a reason for hiding this comment

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

looks good, but I have a minor question about lifetime of new functions.

from qiskit.opflow import PauliSumOp


def validate_estimator_args(
Copy link
Contributor

Choose a reason for hiding this comment

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

If validate_estimator_args and validate_sampler_args are to be deprecated in the near future, it may not be necessary to make it public in the first place.

Copy link
Member

Choose a reason for hiding this comment

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

I agree to make the validation functions private.

@coveralls
Copy link

coveralls commented Nov 1, 2023

Pull Request Test Coverage Report for Build 6716399147

  • 99 of 109 (90.83%) changed or added relevant lines in 4 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.001%) to 86.914%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/primitives/base/base_sampler.py 4 6 66.67%
qiskit/primitives/base/validation.py 86 88 97.73%
qiskit/primitives/base/base_estimator.py 4 7 57.14%
qiskit/primitives/base/base_primitive.py 5 8 62.5%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 1 90.91%
Totals Coverage Status
Change from base Build 6715131520: -0.001%
Covered Lines: 74030
Relevant Lines: 85176

💛 - Coveralls

ikkoham
ikkoham previously approved these changes Nov 1, 2023
@ikkoham ikkoham added this pull request to the merge queue Nov 1, 2023
Merged via the queue into Qiskit:main with commit 05d958b Nov 1, 2023
@jakelishman
Copy link
Member

@Mergifyio backport stable/0.46

Copy link
Contributor

mergify bot commented Jan 9, 2024

backport stable/0.46

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jan 9, 2024
* Remove validation methods from primitive base classes

This deprecates the argument validation methods from primitive base classes and moves them to separate helper functions. These methods unnecessarily bloat the base classes, and are odd to have when the BasePrimitive doesn't even define a run method to validate. There is no reason primitive implementations need to use the same validation as these base classes either. A follow up will be to remove the validation from the base `run` methods and have subclasses implement their own validation.

* Apply suggestions from code review

* Update qiskit/primitives/base/base_estimator.py

---------

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
(cherry picked from commit 05d958b)

# Conflicts:
#	qiskit/primitives/base/base_sampler.py
jakelishman pushed a commit that referenced this pull request Feb 1, 2024
* Remove validation methods from primitive base classes

This deprecates the argument validation methods from primitive base classes and moves them to separate helper functions. These methods unnecessarily bloat the base classes, and are odd to have when the BasePrimitive doesn't even define a run method to validate. There is no reason primitive implementations need to use the same validation as these base classes either. A follow up will be to remove the validation from the base `run` methods and have subclasses implement their own validation.

* Apply suggestions from code review

* Update qiskit/primitives/base/base_estimator.py

---------

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
(cherry picked from commit 05d958b)
github-merge-queue bot pushed a commit that referenced this pull request Feb 1, 2024
… (#11532)

* Remove validation methods from primitive base classes (#11052)

* Remove validation methods from primitive base classes

This deprecates the argument validation methods from primitive base classes and moves them to separate helper functions. These methods unnecessarily bloat the base classes, and are odd to have when the BasePrimitive doesn't even define a run method to validate. There is no reason primitive implementations need to use the same validation as these base classes either. A follow up will be to remove the validation from the base `run` methods and have subclasses implement their own validation.

* Apply suggestions from code review

* Update qiskit/primitives/base/base_estimator.py

---------

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
(cherry picked from commit 05d958b)

* Update qiskit/primitives/base/base_estimator.py

* Add missing import

---------

Co-authored-by: Christopher J. Wood <cjwood@us.ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Deprecation Include in "Deprecated" section of changelog mod: primitives Related to the Primitives module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants