-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Deprecate qiskit.circuit.classicalfunction
#13786
Deprecate qiskit.circuit.classicalfunction
#13786
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 13235330308Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on, I'm happy to see this cleaned up for 2.0! 🙂
It seems there is still one call to classical function in the visualization tests, which is not caught and causes the CI to fail.
releasenotes/notes/deprecate-classical-function-3bf44ef26d984366.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments, otherwise LGTM 👍🏻
releasenotes/notes/deprecate-classical-function-3bf44ef26d984366.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/deprecate-classical-function-3bf44ef26d984366.yaml
Outdated
Show resolved
Hide resolved
ClassicalFunction
qiskit.circuit.classicalfunction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just making sure: in this PR we raise deprecation warnings, and the new API will be introduced in qiskit 2.0 ?
Should there be another PR for removing ClassicalFunction for qiskit 2.0, since it's not part of #13769?
releasenotes/notes/deprecate-classical-function-3bf44ef26d984366.yaml
Outdated
Show resolved
Hide resolved
I also found tweedledum here: qiskit/qiskit/utils/optionals.py Line 186 in 9ae0a80
should it be removed / deprecated? See also this test file: |
Yes, we'll add the new API in 2.0. I think we can use #13769 to remove |
It should definitely be removed, but I don't think we need deprecation warning here. |
This one should be against |
…66.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
…66.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deprecation is a bit finnicky. Our deprecation rules are that
- an alternative implementation must be available for 1 minor release, where no
DeprecationWarning
is issued (PendingDeprecationWarning
is fine) - then, the
DeprecationWarning
must be issued for 1 minor release - finally, we can remove the feature
Here we cannot point users to the BitFlipOracle
, which doesn't exist yet, and we cannot issue a deprecation warning inside PhaseOracle
, which doesn't have a deprecation-free alternative. In a perfect world we would have introduced a tweedledum-free version of PhaseOracle
and the BitFlipOracle
in 1.3 already, deprecate the classicalfunction
in 1.4 and remove in 2.0.
To move forward while still being true to the deprecation policy, I'd suggest we'd
- just point to
PhaseOracle
as alternative path for everything (this has existed for long enough) - don't issue any warnings when using
PhaseOracle
- tell users how they could get a boolean expression/bitflip oracle from a
PhaseOracle
@deprecate_func( | ||
since="1.4", | ||
removal_timeline="in Qiskit 2.0", | ||
additional_msg="Use `PhaseOracle` or `BitFlipOracle` instead", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BitFlipOracle
doesn't exist in Qiskit 1.4, we need to remove mentioning it from the deprecation messages. Since the PhaseOracle
is not a direct replacement of the classical functions but requires extra steps, it might be good to tell the users how to get there
additional_msg="Use `PhaseOracle` or `BitFlipOracle` instead", | |
additional_msg=( | |
"Use the PhaseOracle instead, which can be turned into a " | |
"bit-flip oracle by applying Hadamard gates on the target " | |
"qubit before and after the instruction." | |
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 4510aee
is going to have a `tweedledum` independent implementation, and | ||
the :class:`.BitFlipOracle` which will be added in Qiskit 2.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also add a code snippet as example if we want to be extra nice to the users 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second that, and maybe the release notes would be a perfect place to include an example on how to convert the phase oracle to the bit-flip oracle.
DeprecationWarning, | ||
expected_regex="BooleanExpression`` is deprecated as of qiskit 1.4", | ||
): | ||
oracle = PhaseOracle(expression) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PhaseOracle
is not getting deprecated, it should not emit a deprecation warning. Instead we can filter the warning in the PhaseOracle
code in 1.4 until we get the tweedledum-free version in 2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 4510aee
…deprecated PhaseOracle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. do you have any last comments @Cryoris ?
import warnings | ||
|
||
warnings.simplefilter("ignore", DeprecationWarning) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will enable a global filter, we should use
with warnings.catch_warnings(action="ignore", category=DeprecationWarning):
# code here...
🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b4878c6
|
||
.. code-block:: python | ||
|
||
phase_flip_oracle = PhaseOracle(bool_expr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's nice! What do you think of making this a fully executable snippet with some example boolean expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b4878c6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the work!
* Deprecate `ClassicalFunction` * Changes according to PR review * Update releasenotes/notes/deprecate-classical-function-3bf44ef26d984366.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com> * Update qiskit/circuit/classicalfunction/__init__.py Co-authored-by: Julien Gacon <gaconju@gmail.com> * Update releasenotes/notes/deprecate-classical-function-3bf44ef26d984366.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com> * Test fix * Deprecate `BooleanExpression` as well * Linting * Test fix due to deprecation * Update the release note * Test message fix * Update deprecation message and ignore deprecation warning in the non-deprecated PhaseOracle * Added an explanation on how to create a bit flip oracle from a phase flip oracle * Fixes according to PR review * Typo --------- Co-authored-by: Julien Gacon <gaconju@gmail.com>
Third try to really be sure it's not a flake.. |
I just inspected the backwards compatibility tests and found the source of the problems we are seeing: |
Summary
This PR deprecates the
ClassicalFunction
class and relatedclassical_function
method, to be removed in 2.0.Partially addresses #13755
Details and comments
ClassicalFunction
is a useful class, but it relies on thetweedledum
library which is dropped from qiskit in 2.0. Most of the functionality enabled byClassicalFunction
is also supplied byBooleanExpression
that is made independent fromtweedledum
in #13769 and it's not clear if there is demand for the extra functionality at this stage.