§
    ¹³ÙgZ  ã                  ó¢   — d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ erddlmZ ddlmZ ej        j         G d„ d	e	¦  «        ¦   «         Zd
S )zPhase Oracle object.é    )Úannotations)ÚUnionÚCallableÚOptionalÚTYPE_CHECKING)ÚQuantumCircuit)Ú	optionals©ÚBooleanExpression©ÚClassicalElementc                  óJ   ‡ — e Zd ZdZ	 	 ddˆ fd„Zdd„Zedd„¦   «         Zˆ xZS )ÚPhaseOraclea]  Phase Oracle.

    The Phase Oracle object constructs circuits for any arbitrary
    input logical expressions. A logical expression is composed of logical operators
    `&` (`AND`), `|` (`OR`), `~` (`NOT`), and `^` (`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.

    For convenience, this oracle, in addition to parsing arbitrary logical expressions,
    also supports input strings in the `DIMACS CNF format
    <http://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.
    NÚ
expressionúUnion[str, ClassicalElement]Úsynthesizerú7Optional[Callable[[BooleanExpression], QuantumCircuit]]Ú	var_orderÚlistÚreturnÚNonec                ó¶  •— ddl }|                     ¦   «         5  |                     dt          ¦  «         ddlm} ddlm} t          ||¦  «        s |||¬¦  «        }|| _	        |€d„ }| 
                    |¬¦  «        }t          ¦   «                              |j        d	¬
¦  «         |                      |dd¬¦  «         ddd¦  «         dS # 1 swxY w Y   dS )a®  Creates a PhaseOracle object

        Args:
            expression: A Python-like boolean expression.
            synthesizer: Optional. A function to convert a BooleanExpression into a QuantumCircuit
               If None is provided, Tweedledum's `pkrm_synth` with `phase_esop` will be used.
            var_order(list): A list with the order in which variables will be created.
               (default: by appearance)
        r   NÚignorer
   r   )r   c                ó†   — ddl m} ddlm} | j                             d¬¦  «        } ||dddii¦  «        } ||¦  «        S )Nr   )Ú
pkrm_synth)Útweedledum2qiskit)Ú
output_bitr   Ú
phase_esopT)Útweedledum.synthesisr   Ú&qiskit.circuit.classicalfunction.utilsr   Ú_tweedledum_bool_expressionÚtruth_table)Úboolean_expressionr   r   r"   Útweedledum_circuits        úY/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/phase_oracle.pyr   z)PhaseOracle.__init__.<locals>.synthesizerQ   s~   € Ø?Ð?Ð?Ð?Ð?Ð?ØXÐXÐXÐXÐXÐXà"4Ô"P×"\Ò"\Ø#$ð #]ñ #ô #�Kð *4¨Ø# l°\À4Ð4HÐ%Iñ*ô *Ð&ð -Ð,Ð-?Ñ@Ô@Ð@ó    )r   zPhase Oracle)ÚnameTF)ÚinplaceÚcopy)ÚwarningsÚcatch_warningsÚsimplefilterÚDeprecationWarningÚ3qiskit.circuit.classicalfunction.boolean_expressionr   Ú2qiskit.circuit.classicalfunction.classical_elementr   Ú
isinstancer#   ÚsynthÚsuperÚ__init__Ú
num_qubitsÚcompose)	Úselfr   r   r   r*   r   r   ÚoracleÚ	__class__s	           €r%   r3   zPhaseOracle.__init__3   sX  ø€ ð  	ˆˆˆà×$Ò$Ñ&Ô&ð 	;ð 	;Ø×!Ò! (Õ,>Ñ?Ô?Ð?Ø]Ð]Ð]Ð]Ð]Ð]Ø[Ð[Ð[Ð[Ð[Ð[å˜jÐ*:Ñ;Ô;ð PØ.Ð.¨zÀYÐOÑOÔO�
à&0ˆDÔ#àÐ"ð
Að 
Að 
Að  ×%Ò%°+Ð%Ñ>Ô>ˆFå‰GŒG×Ò˜VÔ.°^ÐÑDÔDÐDà�LŠL˜¨°EˆLÑ:Ô:Ð:ð9	;ð 	;ð 	;ñ 	;ô 	;ð 	;ð 	;ð 	;ð 	;ð 	;ð 	;ð 	;øøøð 	;ð 	;ð 	;ð 	;ð 	;ð 	;s   šB'CÃCÃCÚ	bitstringÚstrÚboolc                óH   — | j                              |ddd…         ¦  «        S )ad  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)r6   r9   s     r%   Úevaluate_bitstringzPhaseOracle.evaluate_bitstringc   s%   € ð Ô&×/Ò/°	¸$¸$¸B¸$´Ñ@Ô@Ð@r&   Úfilenamec                óD   — ddl m}  |j        |¦  «        } | |¦  «        S )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
        <http://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   r
   )r.   r   Úfrom_dimacs_file)Úclsr@   r   Úexprs       r%   rB   zPhaseOracle.from_dimacs_filep   s9   € ðZ 	ZÐYÐYÐYÐYÐYà1Ð Ô1°(Ñ;Ô;ˆØˆs�4‰yŒyÐr&   )NN)r   r   r   r   r   r   r   r   )r9   r:   r   r;   )r@   r:   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   r?   ÚclassmethodrB   Ú__classcell__)r8   s   @r%   r   r      s�   ø€ € € € € ðð ð0 PTØð	.;ð .;ð .;ð .;ð .;ð .;ð .;ð`Að Að Að Að ð/ð /ð /ñ „[ð/ð /ð /ð /ð /r&   r   N)rH   Ú
__future__r   Útypingr   r   r   r   Úqiskit.circuitr   Úqiskit.utilsr	   Ú
_optionalsr.   r   r/   r   ÚHAS_TWEEDLEDUMÚrequire_in_instancer   © r&   r%   ú<module>rS      sç   ðð Ð ð #Ð "Ð "Ð "Ð "Ð "à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;à )Ð )Ð )Ð )Ð )Ð )Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0àð TØUÐUÐUÐUÐUÐUØSÐSÐSÐSÐSÐSð ÔÔ.ðCð Cð Cð Cð C�.ñ Cô Cñ /Ô.ðCð Cð Cr&   