§
    ¹³Ùgü  ã                   óH   — d Z ddlmZ ddlmZ ddlmZ ddlmZ d„ Z	d	d„Z
dS )
z2Helper function for converting a circuit to a gateé    )ÚAnnotatedOperation)ÚGate)ÚQuantumRegister)ÚQiskitErrorc                 ó†   — t          | t          ¦  «        rdS t          | t          ¦  «        rt          | j        ¦  «        S dS )z+Checks whether op can be converted to Gate.TF)Ú
isinstancer   r   Ú_check_is_gateÚbase_op)Úops    úW/granary/edev/quantum/lib/python3.11/site-packages/qiskit/converters/circuit_to_gate.pyr	   r	      sA   € å�"•dÑÔð *ØˆtÝ	�BÕ*Ñ	+Ô	+ð *Ý˜bœjÑ)Ô)Ð)Øˆ5ó    Nc           	      óú  ‡
‡— ddl m} | j        rt          d¦  «        ‚| j        rt          d¦  «        ‚| j        D ]3}t          |j        ¦  «        st          d|j        j        › d�¦  «        ‚Œ4|€d„ | j	        D ¦   «         }n|  
                    |¦  «        }|                     ¦   «         | j	        k    rt          d	| j	        › d
|› �¦  «        ‚t          | j        | j        g |                     ¦   «         ¢|¬¦  «        }d|_        |                      |d¬¦  «        }|�|                     ||¦  «          ||j        |j        ¬¦  «        }	|j        dk    r*t'          |j        d¦  «        Š
|	                     ‰
¦  «         ˆ
fd„t+          | j        ¦  «        D ¦   «         Š|j        D ]I}|	                     |                     t3          ˆfd„|j        D ¦   «         ¦  «        ¬¦  «        ¦  «         ŒJ|	|_        |S )a	  Build a :class:`.Gate` object from a :class:`.QuantumCircuit`.

    The gate is anonymous (not tied to a named quantum register),
    and so can be inserted into another circuit. The gate will
    have the same string name as the circuit.

    Args:
        circuit (QuantumCircuit): the input circuit.
        parameter_map (dict): For parameterized circuits, a mapping from
           parameters in the circuit to parameters to be used in the gate.
           If None, existing circuit parameters will also parameterize the
           Gate.
        equivalence_library (EquivalenceLibrary): Optional equivalence library
           where the converted gate will be registered.
        label (str): Optional gate label.

    Raises:
        QiskitError: if circuit is non-unitary or if
            parameter_map is not compatible with circuit

    Return:
        Gate: a Gate equivalent to the action of the
        input circuit. Upon decomposition, this gate will
        yield the components comprising the original circuit.
    r   )ÚQuantumCircuitz8Circuit with classical bits cannot be converted to gate.zGcircuits with realtime classical variables cannot be converted to gatesz9One or more instructions cannot be converted to a gate. "z" is not a gate instructionNc                 ó   — i | ]}||“ŒS © r   )Ú.0Úps     r   ú
<dictcomp>z#circuit_to_gate.<locals>.<dictcomp>H   s   € Ð;Ð;Ð; 1˜!˜QÐ;Ð;Ð;r   zEparameter_map should map all circuit parameters. Circuit parameters: z, parameter_map: )ÚnameÚ
num_qubitsÚparamsÚlabelF)Úinplace)r   Úglobal_phaseÚqc                 ó(   •— i | ]\  }}|‰|         “ŒS r   r   )r   ÚidxÚbitr   s      €r   r   z#circuit_to_gate.<locals>.<dictcomp>c   s#   ø€ ÐGÐGÐG¡  c��a˜”fÐGÐGÐGr   c              3   ó(   •K  — | ]}‰|         V — Œd S )Nr   )r   ÚyÚ	qubit_maps     €r   ú	<genexpr>z"circuit_to_gate.<locals>.<genexpr>i   s'   øè è € Ð3]Ð3]ÀQ°I¸a´LÐ3]Ð3]Ð3]Ð3]Ð3]Ð3]r   )Úqubits)Úqiskit.circuit.quantumcircuitr   Úclbitsr   Únum_varsÚdatar	   Ú	operationr   Ú
parametersÚ_unroll_param_dictÚkeysr   r   ÚvaluesÚ	conditionÚassign_parametersÚadd_equivalencer   r   Úadd_registerÚ	enumerater#   Ú_appendÚreplaceÚtupleÚ
definition)ÚcircuitÚparameter_mapÚequivalence_libraryr   r   ÚinstructionÚparameter_dictÚgateÚtargetÚqcr   r!   s             @@r   Úcircuit_to_gater>      sw  øø€ ð6 =Ð<Ð<Ð<Ð<Ð<à„~ð VÝÐTÑUÔUÐUØÔð eÝÐcÑdÔdÐdà”|ð ð ˆÝ˜kÔ3Ñ4Ô4ð 	ÝðUØ(Ô2Ô7ðUð Uð Uñô ð ð	ð ÐØ;Ð;¨Ô(:Ð;Ñ;Ô;ˆˆà ×3Ò3°MÑBÔBˆà×ÒÑÔ Ô 2Ò2Ð2ÝðYØ#*Ô#5ðYð YØHVðYð Yñ
ô 
ð 	
õ
 ØŒ\ØÔ%Ø)�×&Ò&Ñ(Ô(Ð)Øð	ñ ô €Dð €D„Nà×&Ò& ~¸uÐ&ÑEÔE€FàÐ&Ø×+Ò+¨D°&Ñ9Ô9Ð9à	ˆ˜TœY°VÔ5HÐ	IÑ	IÔ	I€BØ„˜ÒÐÝ˜DœO¨SÑ1Ô1ˆØ
�Š˜ÑÔÐØGÐGÐGÐG­Y°w´~Ñ-FÔ-FÐGÑGÔG€Ið
 ”{ð `ð `ˆØ
�
Š
�;×&Ò&­eÐ3]Ð3]Ð3]Ð3]È+ÔJ\Ð3]Ñ3]Ô3]Ñ.]Ô.]Ð&Ñ^Ô^Ñ_Ô_Ð_Ð_Ø€D„OØ€Kr   )NNN)Ú__doc__Ú"qiskit.circuit.annotated_operationr   Úqiskit.circuit.gater   Úqiskit.circuit.quantumregisterr   Úqiskit.exceptionsr   r	   r>   r   r   r   ú<module>rD      sˆ   ðð 9Ð 8Ø AÐ AÐ AÐ AÐ AÐ AØ $Ð $Ð $Ð $Ð $Ð $Ø :Ð :Ð :Ð :Ð :Ð :Ø )Ð )Ð )Ð )Ð )Ð )ðð ð ðMð Mð Mð Mð Mð Mr   