Skip to content

Commit

Permalink
Added an explanation on how to create a bit flip oracle from a phase …
Browse files Browse the repository at this point in the history
…flip oracle
  • Loading branch information
gadial committed Feb 13, 2025
1 parent 4510aee commit ad5cdd0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion qiskit/circuit/classicalfunction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def grover_oracle(a: Int1, b: Int1, c: Int1, d: Int1) -> Int1:
removal_timeline="in Qiskit 2.0",
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.",
"qubit before and after the instruction, and conditioning."
"the instruction on the target qubit.",
)
def classical_function(func):
"""
Expand Down
3 changes: 2 additions & 1 deletion qiskit/circuit/classicalfunction/boolean_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class BooleanExpression(ClassicalElement):
removal_timeline="in Qiskit 2.0",
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.",
"qubit before and after the instruction, and conditioning."
"the instruction on the target qubit.",
)
def __init__(self, expression: str, name: str = None, var_order: list = None) -> None:
"""
Expand Down
3 changes: 2 additions & 1 deletion qiskit/circuit/classicalfunction/classicalfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ClassicalFunction(ClassicalElement):
removal_timeline="in Qiskit 2.0",
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.",
"qubit before and after the instruction, and conditioning."
"the instruction on the target qubit.",
)
def __init__(self, source, name=None):
"""Creates a ``ClassicalFunction`` from Python source code in ``source``.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ deprecations_circuits:
For a similar functionality please use the :class:`.PhaseOracle` which
is going to have a `tweedledum` independent implementation, and
the :class:`.BitFlipOracle` which will be added in Qiskit 2.0.
Until :class:`.BitFlipOracle` is added, a phase flip oracle can be converted
to a bit flip oracle by conditioning it on the result qubit, and applying
Hadamard gate before and after the application of the oracle, as in the
following example (where the oracle is on `qr_x` and the result is on `qr_y`):
.. code-block:: python
phase_flip_oracle = PhaseOracle(bool_expr)
controlled_phase_flip_oracle = phase_flip_oracle.control(1)
qc.h(qr_y)
qc.compose(controlled_phase_flip_oracle, qubits=[*qr_y, *qr_x], inplace=True)
qc.h(qr_y)

0 comments on commit ad5cdd0

Please sign in to comment.