
    z	i)                    h    S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	   " S S\5      r
 " S S	\5      rg
)zPhase Oracle object.    )annotations)QuantumCircuitGate)BooleanExpression)deprecate_funcc                  t   ^  \ rS rSrSr\" SSSS9 S     SU 4S jjj5       rSS jr\SS	 j5       r	S
r
U =r$ )PhaseOracle   a  Phase Oracle.

The Phase Oracle object constructs circuits for any arbitrary
input logical expressions. A logical expression is composed of logical operators
`&` (logical `AND`), `|` (logical  `OR`),
`~` (logical  `NOT`), and `^` (logical  `XOR`).
as well as symbols for literals (variables).
For example, `'a & b'`, and `(v0 | ~v1) & (~v2 & v3)`
are both valid string representation of boolean logical expressions.

A phase oracle for a boolean function `f(x)` performs the following
quantum operation:

.. math::

        |x\rangle \mapsto (-1)^{f(x)}|x\rangle

For convenience, this oracle, in addition to parsing arbitrary logical expressions,
also supports input strings in the `DIMACS CNF format
<https://web.archive.org/web/20190325181937/https://www.satcompetition.org/2009/format-benchmarks2009.html>`__,
which is the standard format for specifying SATisfiability (SAT) problem instances in
`Conjunctive Normal Form (CNF) <https://en.wikipedia.org/wiki/Conjunctive_normal_form>`__,
which is a conjunction of one or more clauses, where a clause is a disjunction of one
or more literals. See :meth:`qiskit.circuit.library.phase_oracle.PhaseOracle.from_dimacs_file`.

From 16 variables on, possible performance issues should be expected when using the
default synthesizer.
z2.2z=Use the class qiskit.circuit.library.PhaseOracleGate instead.zin Qiskit 3.0)sinceadditional_msgremoval_timelinec                   > [        U[        5      (       a	  [        XS9nXl        U R                  R	                  SS9n[
        TU ]  UR                  SS9  U R                  USSS9  g	)
z
Args:
    expression: A Python-like boolean expression string or a `BooleanExpression` object.
    var_order: A list with the order in which variables will be created.
       (default: by appearance)
	var_orderphasecircuit_typePhase Oracle)nameTF)inplacecopyN)	
isinstancestrr   boolean_expressionsynthsuper__init__
num_qubitscompose)self
expressionr   oracle	__class__s       ]/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/phase_oracle.pyr   PhaseOracle.__init__5   se    " j#&&*:KJ",((..G.D**@VT6    c                D    U R                   R                  USSS2   5      $ )a,  Evaluate the oracle on a bitstring.
This evaluation is done classically without any quantum circuit.

Args:
    bitstring: The bitstring for which to evaluate. The input bitstring is expected to be
        in little-endian order.

Returns:
    True if the bitstring is a good state, False otherwise.
N)r   simulate)r    	bitstrings     r$   evaluate_bitstringPhaseOracle.evaluate_bitstringO   s#     &&//	$B$@@r&   c                >    [         R                  " U5      nU " U5      $ )a  Create a PhaseOracle from the string in the DIMACS format.

It is possible to build a PhaseOracle from a file in `DIMACS CNF format
<https://web.archive.org/web/20190325181937/https://www.satcompetition.org/2009/format-benchmarks2009.html>`__,
which is the standard format for specifying SATisfiability (SAT) problem instances in
`Conjunctive Normal Form (CNF) <https://en.wikipedia.org/wiki/Conjunctive_normal_form>`__,
which is a conjunction of one or more clauses, where a clause is a disjunction of one
or more literals.

The following is an example of a CNF expressed in the DIMACS format:

.. code:: text

  c DIMACS CNF file with 3 satisfying assignments: 1 -2 3, -1 -2 -3, 1 2 -3.
  p cnf 3 5
  -1 -2 -3 0
  1 -2 3 0
  1 2 -3 0
  1 -2 -3 0
  -1 2 3 0

The first line, following the `c` character, is a comment. The second line specifies that
the CNF is over three boolean variables --- let us call them  :math:`x_1, x_2, x_3`, and
contains five clauses.  The five clauses, listed afterwards, are implicitly joined by the
logical `AND` operator, :math:`\land`, while the variables in each clause, represented by
their indices, are implicitly disjoined by the logical `OR` operator, :math:`lor`. The
:math:`-` symbol preceding a boolean variable index corresponds to the logical `NOT`
operator, :math:`lnot`. Character `0` (zero) marks the end of each clause.  Essentially,
the code above corresponds to the following CNF:

:math:`(\lnot x_1 \lor \lnot x_2 \lor \lnot x_3)
\land (x_1 \lor \lnot x_2 \lor x_3)
\land (x_1 \lor x_2 \lor \lnot x_3)
\land (x_1 \lor \lnot x_2 \lor \lnot x_3)
\land (\lnot x_1 \lor x_2 \lor x_3)`.


Args:
    filename: A file in DIMACS format.

Returns:
    PhaseOracle: A quantum circuit with a phase oracle.
r   from_dimacs_fileclsfilenameexprs      r$   r/   PhaseOracle.from_dimacs_file\       Z !11(;4yr&   )r   )N)r!   str | BooleanExpressionr   list[str] | NonereturnNone)r*   r   r8   bool)r2   r   )__name__
__module____qualname____firstlineno____doc__r   r   r+   classmethodr/   __static_attributes____classcell__r#   s   @r$   r	   r	      se    : V( '+7+7 $7 
	7
7*A - -r&   r	   c                  `   ^  \ rS rSrSr  S       SU 4S jjjrS r\S	S j5       rSr	U =r
$ )
PhaseOracleGate   a  Implements a phase oracle.

The Phase Oracle Gate object constructs circuits for any arbitrary
input logical expressions. A logical expression is composed of logical operators
`&` (logical `AND`), `|` (logical  `OR`),
`~` (logical  `NOT`), and `^` (logical  `XOR`).
as well as symbols for literals (variables).
For example, `'a & b'`, and `(v0 | ~v1) & (~v2 & v3)`
are both valid string representation of boolean logical expressions.

A phase oracle for a boolean function `f(x)` performs the following
quantum operation:

.. math::

        |x\rangle \mapsto (-1)^{f(x)}|x\rangle

For convenience, this oracle, in addition to parsing arbitrary logical expressions,
also supports input strings in the `DIMACS CNF format
<https://web.archive.org/web/20190325181937/https://www.satcompetition.org/2009/format-benchmarks2009.html>`__,
which is the standard format for specifying SATisfiability (SAT) problem instances in
`Conjunctive Normal Form (CNF) <https://en.wikipedia.org/wiki/Conjunctive_normal_form>`__,
which is a conjunction of one or more clauses, where a clause is a disjunction of one
or more literals. See :meth:`qiskit.circuit.library.phase_oracle.PhaseOracleGate.from_dimacs_file`.

From 16 variables on, possible performance issues should be expected when using the
default synthesizer.
c                   > Uc1  [        U[        5      (       a  [        U5      S:  a  USS S-   OUnOSn[        U[        5      (       a	  [        XS9nXl        [
        TU ]  SU R                  R                  / US9  g)a  
Args:
    expression: A Python-like boolean expression string or a `BooleanExpression` object.
    var_order: A list with the order in which variables will be created.
       (default: by appearance)
    label: A label for the gate to display in visualizations. Per default, the label is
        set to display the textual represntation of the boolean expression (truncated if needed)
N   z...zBoolean Expressionr   r   )r   r   paramslabel)r   r   lenr   r   r   r   num_bits)r    r!   r   rJ   r#   s       r$   r   PhaseOracleGate.__init__   s     =*c**58_r5ICR50z,j#&&*:KJ",..77	 	 	
r&   c                @    U R                   R                  SS9U l        g)z'Defined by the synthesized phase oracler   r   N)r   r   
definition)r    s    r$   _definePhaseOracleGate._define   s    1177W7Mr&   c                >    [         R                  " U5      nU " U5      $ )a  Create a PhaseOracle from the string in the DIMACS format.

It is possible to build a PhaseOracle from a file in `DIMACS CNF format
<https://web.archive.org/web/20190325181937/https://www.satcompetition.org/2009/format-benchmarks2009.html>`__,
which is the standard format for specifying SATisfiability (SAT) problem instances in
`Conjunctive Normal Form (CNF) <https://en.wikipedia.org/wiki/Conjunctive_normal_form>`__,
which is a conjunction of one or more clauses, where a clause is a disjunction of one
or more literals.

The following is an example of a CNF expressed in the DIMACS format:

.. code:: text

  c DIMACS CNF file with 3 satisfying assignments: 1 -2 3, -1 -2 -3, 1 2 -3.
  p cnf 3 5
  -1 -2 -3 0
  1 -2 3 0
  1 2 -3 0
  1 -2 -3 0
  -1 2 3 0

The first line, following the `c` character, is a comment. The second line specifies that
the CNF is over three boolean variables --- let us call them  :math:`x_1, x_2, x_3`, and
contains five clauses.  The five clauses, listed afterwards, are implicitly joined by the
logical `AND` operator, :math:`\land`, while the variables in each clause, represented by
their indices, are implicitly disjoined by the logical `OR` operator, :math:`\lor`. The
:math:`-` symbol preceding a boolean variable index corresponds to the logical `NOT`
operator, :math:`\lnot`. Character `0` (zero) marks the end of each clause.  Essentially,
the code above corresponds to the following CNF:

:math:`(\lnot x_1 \lor \lnot x_2 \lor \lnot x_3)
\land (x_1 \lor \lnot x_2 \lor x_3)
\land (x_1 \lor x_2 \lor \lnot x_3)
\land (x_1 \lor \lnot x_2 \lor \lnot x_3)
\land (\lnot x_1 \lor x_2 \lor x_3)`.


Args:
    filename: A file in DIMACS format.

Returns:
    PhaseOracleGate: A quantum circuit with a phase oracle.
r.   r0   s      r$   r/    PhaseOracleGate.from_dimacs_file   r5   r&   )r   rO   )NN)r!   r6   r   r7   rJ   z
str | Noner8   r9   )r2   r   r8   rE   )r;   r<   r=   r>   r?   r   rP   r@   r/   rA   rB   rC   s   @r$   rE   rE      s[    @ '+ 	
+
 $
 	

 

 
>N - -r&   rE   N)r?   
__future__r   qiskit.circuitr   r   +qiskit.synthesis.boolean.boolean_expressionr   qiskit.utils.deprecationr   r	   rE    r&   r$   <module>rY      s3     " / I 3s. slod or&   