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

Moving up some parameter checks in the class hierarchy #3668

Merged
merged 36 commits into from
Apr 9, 2020

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Jan 2, 2020

Fixes #3282

@nonhermitian notices that parameters are too broadly checked. I moved some of the checks up the class hierarchy. This allows to be more prices in the kind of check and normalization for each class. Also, it can be improved further with a better class hierarchy for Instructions. But that's story for another time.

All the tests are passing. If reviewers find a uncovered case, let's add the test!

@1ucian0 1ucian0 marked this pull request as ready for review January 2, 2020 20:44
@1ucian0 1ucian0 removed their assignment Jan 10, 2020
@1ucian0 1ucian0 added this to the 0.12 milestone Jan 29, 2020
Copy link
Member

@kdk kdk 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, one question is whether or not the base Instruction class should default permissive or default restrictive. Default permissive is less likely to break existing users as it matches previous behavior, but maybe its the case that substantially more gates would have to specify that they e.g. don't accept complex parameters. Alternately, subclasses could be annotated with the types they support. Thoughts?

qiskit/circuit/instruction.py Outdated Show resolved Hide resolved
@kdk kdk modified the milestones: 0.12, 0.13 Feb 6, 2020
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

I'm a bit confused here. Like we're moving the type checking for each parameter in params() to a normalize_parameters method so subclasses can override it and define their own behavior, that makes sense to me. But, none of the subclasses look like they do anything different because we call the parent's method if it's not one of the expected types for the subclass.

qiskit/circuit/instruction.py Outdated Show resolved Hide resolved
qiskit/circuit/gate.py Outdated Show resolved Hide resolved
@1ucian0 1ucian0 changed the title Moving up some parameter checks in the class hierarchy [WIP ]Moving up some parameter checks in the class hierarchy Apr 2, 2020
@1ucian0 1ucian0 changed the title [WIP ]Moving up some parameter checks in the class hierarchy [WIP] Moving up some parameter checks in the class hierarchy Apr 2, 2020
@1ucian0
Copy link
Member Author

1ucian0 commented Apr 7, 2020

57854df adds validate_parameter to barrier.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Based on a discussion offline we decided that for the base Instruction class they should accept anything and it's on the users to not manually set a parameter type that can't be handled by the whatever the output mechanism of the circuit is. With that open question settled this PR LGTM.

@mergify mergify bot merged commit 5afe87c into Qiskit:master Apr 9, 2020
@1ucian0 1ucian0 deleted the 3282 branch April 9, 2020 00:55
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Apr 9, 2020
…t#3668)"

This change has some unforseen backwards compatibility implications and
is causing downstream projects like qiskit-aer to fail CI now. Given the
pending release and this not being critical, this commit reverts this
commit and we can revisit it after the 0.13.0 release.

This reverts commit 5afe87c.
mtreinish added a commit that referenced this pull request Apr 9, 2020
…" (#4117)

This change has some unforseen backwards compatibility implications and
is causing downstream projects like qiskit-aer to fail CI now. Given the
pending release and this not being critical, this commit reverts this
commit and we can revisit it after the 0.13.0 release.

This reverts commit 5afe87c.
ajavadia pushed a commit to ajavadia/qiskit that referenced this pull request Apr 11, 2020
…t#3668)" (Qiskit#4117)

This change has some unforseen backwards compatibility implications and
is causing downstream projects like qiskit-aer to fail CI now. Given the
pending release and this not being critical, this commit reverts this
commit and we can revisit it after the 0.13.0 release.

This reverts commit 5afe87c.

add new fake backends
kdk added a commit that referenced this pull request Apr 17, 2020
…4129)

* Revert "Moving up some parameter checks in the class hierarchy (#3668)" (#4117)

This change has some unforseen backwards compatibility implications and
is causing downstream projects like qiskit-aer to fail CI now. Given the
pending release and this not being critical, this commit reverts this
commit and we can revisit it after the 0.13.0 release.

This reverts commit 5afe87c.

add new fake backends

* fix dt and dtm conversion by qiskit to SI

* fix imports

* lint

* Update qiskit/test/mock/backends/armonk/fake_armonk.py

Co-Authored-By: Kevin Krsulich <[email protected]>

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Kevin Krsulich <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* abstract method

* moving some checks up the Class hierarchy

* lint

* lint!

* normalize_parameter

* merge

* instruction

* no need to override in gate

* clean qiskit/extensions/quantum_initializer/diag.py diff

* new approach

* mising import

* validate_parameter

* skip multiplexer

* docstring

* lint

* deprecation warning

* custom gates are gates

* add np.number for gate parameters

* lint

* barrier validate_parameter

* syntax error

* message

* test barrier

* no warning

* unused import

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
…t#3668)" (Qiskit#4117)

This change has some unforseen backwards compatibility implications and
is causing downstream projects like qiskit-aer to fail CI now. Given the
pending release and this not being critical, this commit reverts this
commit and we can revisit it after the 0.13.0 release.

This reverts commit 5afe87c.
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
…iskit#4129)

* Revert "Moving up some parameter checks in the class hierarchy (Qiskit#3668)" (Qiskit#4117)

This change has some unforseen backwards compatibility implications and
is causing downstream projects like qiskit-aer to fail CI now. Given the
pending release and this not being critical, this commit reverts this
commit and we can revisit it after the 0.13.0 release.

This reverts commit 5afe87c.

add new fake backends

* fix dt and dtm conversion by qiskit to SI

* fix imports

* lint

* Update qiskit/test/mock/backends/armonk/fake_armonk.py

Co-Authored-By: Kevin Krsulich <[email protected]>

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Kevin Krsulich <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
ElePT pushed a commit to ElePT/qiskit-ibm-provider that referenced this pull request Oct 9, 2023
…iskit/qiskit#4129)

* Revert "Moving up some parameter checks in the class hierarchy (Qiskit/qiskit#3668)" (Qiskit/qiskit#4117)

This change has some unforseen backwards compatibility implications and
is causing downstream projects like qiskit-aer to fail CI now. Given the
pending release and this not being critical, this commit reverts this
commit and we can revisit it after the 0.13.0 release.

This reverts commit 5afe87ce1e5279ca716fdf5a3c478f2e27a6519f.

add new fake backends

* fix dt and dtm conversion by qiskit to SI

* fix imports

* lint

* Update qiskit/test/mock/backends/armonk/fake_armonk.py

Co-Authored-By: Kevin Krsulich <[email protected]>

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Kevin Krsulich <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gates do not check if complex inputs passed in
4 participants