Skip to content

Commit

Permalink
Update deprecation message and ignore deprecation warning in the non-…
Browse files Browse the repository at this point in the history
…deprecated PhaseOracle
  • Loading branch information
gadial committed Feb 12, 2025
1 parent c81ee1a commit 4510aee
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
4 changes: 3 additions & 1 deletion qiskit/circuit/classicalfunction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ def grover_oracle(a: Int1, b: Int1, c: Int1, d: Int1) -> Int1:
@deprecate_func(
since="1.4",
removal_timeline="in Qiskit 2.0",
additional_msg="Use `PhaseOracle` or `BitFlipOracle` instead",
additional_msg="Use `PhaseOracle` instead, which can be turned into a "
"bit-flip oracle by applying Hadamard gates on the target "
"qubit before and after the instruction.",
)
def classical_function(func):
"""
Expand Down
4 changes: 3 additions & 1 deletion qiskit/circuit/classicalfunction/boolean_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class BooleanExpression(ClassicalElement):
@deprecate_func(
since="1.4",
removal_timeline="in Qiskit 2.0",
additional_msg="Use `PhaseOracle` or `BitFlipOracle` instead",
additional_msg="Use `PhaseOracle` instead, which can be turned into a "
"bit-flip oracle by applying Hadamard gates on the target "
"qubit before and after the instruction.",
)
def __init__(self, expression: str, name: str = None, var_order: list = None) -> None:
"""
Expand Down
4 changes: 3 additions & 1 deletion qiskit/circuit/classicalfunction/classicalfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class ClassicalFunction(ClassicalElement):
@deprecate_func(
since="1.4",
removal_timeline="in Qiskit 2.0",
additional_msg="Use `PhaseOracle` or `BitFlipOracle` instead",
additional_msg="Use `PhaseOracle` instead, which can be turned into a "
"bit-flip oracle by applying Hadamard gates on the target "
"qubit before and after the instruction.",
)
def __init__(self, source, name=None):
"""Creates a ``ClassicalFunction`` from Python source code in ``source``.
Expand Down
5 changes: 5 additions & 0 deletions qiskit/circuit/library/phase_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def __init__(
var_order(list): A list with the order in which variables will be created.
(default: by appearance)
"""
# ignore deprecation warning for BooleanExpression; implementation is changing in 2.0
import warnings

warnings.simplefilter("ignore", DeprecationWarning)

from qiskit.circuit.classicalfunction.boolean_expression import BooleanExpression
from qiskit.circuit.classicalfunction.classical_element import ClassicalElement

Expand Down
18 changes: 3 additions & 15 deletions test/python/circuit/library/test_phase_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ class TestPhaseOracle(QiskitTestCase):
@unpack
def test_evaluate_bitstring(self, expression, input_bitstring, expected):
"""PhaseOracle(...).evaluate_bitstring"""
with self.assertWarnsRegex(
DeprecationWarning,
expected_regex="BooleanExpression`` is deprecated as of qiskit 1.4",
):
oracle = PhaseOracle(expression)
oracle = PhaseOracle(expression)
result = oracle.evaluate_bitstring(input_bitstring)
self.assertEqual(result, expected)

Expand All @@ -54,11 +50,7 @@ def test_evaluate_bitstring(self, expression, input_bitstring, expected):
@unpack
def test_statevector(self, expression, good_states):
"""Circuit generation"""
with self.assertWarnsRegex(
DeprecationWarning,
expected_regex="BooleanExpression`` is deprecated as of qiskit 1.4",
):
oracle = PhaseOracle(expression)
oracle = PhaseOracle(expression)
num_qubits = oracle.num_qubits
circuit = QuantumCircuit(num_qubits)
circuit.h(range(num_qubits))
Expand All @@ -84,11 +76,7 @@ def test_statevector(self, expression, good_states):
@unpack
def test_variable_order(self, expression, var_order, good_states):
"""Circuit generation"""
with self.assertWarnsRegex(
DeprecationWarning,
expected_regex="BooleanExpression`` is deprecated as of qiskit 1.4",
):
oracle = PhaseOracle(expression, var_order=var_order)
oracle = PhaseOracle(expression, var_order=var_order)
num_qubits = oracle.num_qubits
circuit = QuantumCircuit(num_qubits)
circuit.h(range(num_qubits))
Expand Down

0 comments on commit 4510aee

Please sign in to comment.