§
    ¹³ÙgÒ&  ã                  óp   — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ  G d„ de	e¦  «        Zd	S )
zBlueprint circuit object.é    )Úannotations)ÚABCÚabstractmethod)ÚCircuitData)ÚQuantumCircuitÚQuantumRegisterÚClassicalRegister)ÚParameterViewc                  ó¸  ‡ — e Zd ZdZddœd-ˆ fd„Zed.d/d„¦   «         Zed0d„¦   «         Zd0d„Ze	d„ ¦   «         Z
e
j        d„ ¦   «         Z
e	ˆ fd„¦   «         Zd1ˆ fd„	Zˆ fd„Ze	d2ˆ fd„¦   «         Ze	d3ˆ fd„¦   «         Zd4ddœˆ fd„Z	 	 	 	 	 d5d	dddœˆ fd„Zd6d7ˆ fd„Zd „ Zd!„ Zˆ fd"„Zd4ˆ fd#„	Zd4ˆ fd$„	Zˆ fd%„Zˆ fd&„Zˆ fd'„Zd6ˆ fd(„	Zd8d)d*œˆ fd+„Zd8ˆ fd,„	Zˆ xZS )9ÚBlueprintCircuita  Blueprint circuit object.

    In many applications it is necessary to pass around the structure a circuit will have without
    explicitly knowing e.g. its number of qubits, or other missing information. This can be solved
    by having a circuit that knows how to construct itself, once all information is available.

    This class provides an interface for such circuits. Before internal data of the circuit is
    accessed, the ``_build`` method is called. There the configuration of the circuit is checked.
    N©Únamer   ú
str | NoneÚreturnÚNonec               óŽ   •— d| _          t          ¦   «         j        |d|iŽ g | _        g | _        i | _        d| _        d| _         dS )zCreate a new blueprint circuit.Fr   TN)Ú_is_initializedÚsuperÚ__init__Ú_qregsÚ_cregsÚ_qubit_indicesÚ	_is_built)Úselfr   ÚregsÚ	__class__s      €ú]/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/blueprintcircuit.pyr   zBlueprintCircuit.__init__"   sR   ø€ à$ˆÔØ�‰ŒÔ˜$Ð* TÐ*Ð*Ð*Ø-/ˆŒØ/1ˆŒØ ˆÔØˆŒØ#ˆÔÐÐó    TÚraise_on_failureÚboolc                ó   — t           ‚)a¢  Check if the current configuration allows the circuit to be built.

        Args:
            raise_on_failure: If True, raise if the configuration is invalid. If False, return
                False if the configuration is invalid.

        Returns:
            True, if the configuration is valid. Otherwise, depending on the value of
            ``raise_on_failure`` an error is raised or False is returned.
        )ÚNotImplementedError)r   r   s     r   Ú_check_configurationz%BlueprintCircuit._check_configuration,   s
   € õ "Ð!r   c                óN   — | j         rdS |                      ¦   «          d| _         dS )zBuild the circuit.NT)r   r#   ©r   s    r   Ú_buildzBlueprintCircuit._build:   s2   € ð Œ>ð 	ØˆFð 	×!Ò!Ñ#Ô#Ð#ØˆŒˆˆr   c                ót   — t          | j        j        | j        j        ¦  «        | _        d| _        d| _        dS )z%Invalidate the current circuit build.r   FN)r   Ú_dataÚqubitsÚclbitsÚglobal_phaser   r%   s    r   Ú_invalidatezBlueprintCircuit._invalidateD   s0   € å  ¤Ô!2°D´JÔ4EÑFÔFˆŒ
ØˆÔØˆŒˆˆr   c                ó   — | j         S )z<A list of the quantum registers associated with the circuit.)r   r%   s    r   ÚqregszBlueprintCircuit.qregsJ   s   € ð Œ{Ðr   c                ó°   — | j         sdS g | _        g | _        i | _        t	          | j        j        ¬¦  «        | _        d| _        d| _         | j	        |Ž  dS )z6Set the quantum registers associated with the circuit.N)r*   r   F)
r   r   Ú	_ancillasr   r   r(   r*   r+   r   Úadd_register)r   r.   s     r   r.   zBlueprintCircuit.qregsO   sh   € ð Ô#ð 	ð ˆFØˆŒØˆŒØ ˆÔÝ ¨¬
Ô(9Ð:Ñ:Ô:ˆŒ
ØˆÔØˆŒàˆÔ˜5Ð!Ð!Ð!Ð!r   c                ó`   •— | j         s|                      ¦   «          t          ¦   «         j        S )zËThe circuit data (instructions and context).

        Returns:
            QuantumCircuitData: a list-like object containing the :class:`.CircuitInstruction`\ s
            for each instruction.
        )r   r&   r   Údata©r   r   s    €r   r3   zBlueprintCircuit.data_   s(   ø€ ð Œ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒwŒ|Ðr   é   c                ó~   •— | j         s|                      ¦   «          t          ¦   «                              ||¦  «        S ©N)r   r&   r   Ú	decompose)r   Úgates_to_decomposeÚrepsr   s      €r   r8   zBlueprintCircuit.decomposek   s5   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw× Ò Ð!3°TÑ:Ô:Ð:r   c                ól   •— | j         s|                      ¦   «           t          ¦   «         j        |i |¤ŽS r7   )r   r&   r   Údraw©r   ÚargsÚkwargsr   s      €r   r<   zBlueprintCircuit.drawp   ó5   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMØ�u‰wŒwŒ|˜TÐ, VÐ,Ð,Ð,r   Úintc                ó`   •— | j         s|                      ¦   «          t          ¦   «         j        S )z/The number of parameter objects in the circuit.)r   r&   r   Únum_parametersr4   s    €r   rC   zBlueprintCircuit.num_parametersu   s)   ø€ ð Œ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒwÔ%Ð%r   r
   c                ó`   •— | j         s|                      ¦   «          t          ¦   «         j        S )u
  The parameters defined in the circuit.

        This attribute returns the :class:`.Parameter` objects in the circuit sorted
        alphabetically. Note that parameters instantiated with a :class:`.ParameterVector`
        are still sorted numerically.

        Examples:

            The snippet below shows that insertion order of parameters does not matter.

            .. code-block:: python

                >>> from qiskit.circuit import QuantumCircuit, Parameter
                >>> a, b, elephant = Parameter("a"), Parameter("b"), Parameter("elephant")
                >>> circuit = QuantumCircuit(1)
                >>> circuit.rx(b, 0)
                >>> circuit.rz(elephant, 0)
                >>> circuit.ry(a, 0)
                >>> circuit.parameters  # sorted alphabetically!
                ParameterView([Parameter(a), Parameter(b), Parameter(elephant)])

            Bear in mind that alphabetical sorting might be unintuitive when it comes to numbers.
            The literal "10" comes before "2" in strict alphabetical sorting.

            .. code-block:: python

                >>> from qiskit.circuit import QuantumCircuit, Parameter
                >>> angles = [Parameter("angle_1"), Parameter("angle_2"), Parameter("angle_10")]
                >>> circuit = QuantumCircuit(1)
                >>> circuit.u(*angles, 0)
                >>> circuit.draw()
                   â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”�
                q: â”¤ U(angle_1,angle_2,angle_10) â”œ
                   â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜
                >>> circuit.parameters
                ParameterView([Parameter(angle_1), Parameter(angle_10), Parameter(angle_2)])

            To respect numerical sorting, a :class:`.ParameterVector` can be used.

            .. code-block:: python

                >>> from qiskit.circuit import QuantumCircuit, Parameter, ParameterVector
                >>> x = ParameterVector("x", 12)
                >>> circuit = QuantumCircuit(1)
                >>> for x_i in x:
                ...     circuit.rx(x_i, 0)
                >>> circuit.parameters
                ParameterView([
                    ParameterVectorElement(x[0]), ParameterVectorElement(x[1]),
                    ParameterVectorElement(x[2]), ParameterVectorElement(x[3]),
                    ..., ParameterVectorElement(x[11])
                ])


        Returns:
            The sorted :class:`.Parameter` objects in the circuit.
        )r   r&   r   Ú
parametersr4   s    €r   rE   zBlueprintCircuit.parameters|   s*   ø€ ðv Œ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒwÔ!Ð!r   F©Ú_standard_gatec               ó„   •— | j         s|                      ¦   «          t          ¦   «                              ||||¬¦  «        S )NrF   )r   r&   r   Ú_append)r   ÚinstructionÚ_qargsÚ_cargsrG   r   s        €r   rI   zBlueprintCircuit._append»   s8   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw�Š˜{¨F°FÈ>ˆÑZÔZÐZr   ©ÚcopyÚ	var_remapÚinline_capturesc               óŽ   •— | j         s|                      ¦   «          t          ¦   «                              ||||||||d¬¦	  «	        S )NFrM   )r   r&   r   Úcompose)r   Úotherr)   r*   ÚfrontÚinplaceÚwraprN   rO   rP   r   s             €r   rR   zBlueprintCircuit.composeÀ   sV   ø€ ð Œ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw�ŠØØØØØØØØØ!ð ñ 

ô 

ð 
	
r   Ú	annotatedc                ó~   •— | j         s|                      ¦   «          t          ¦   «                              |¬¦  «        S )N)rW   )r   r&   r   Úinverse)r   rW   r   s     €r   rY   zBlueprintCircuit.inverseÛ   s2   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw�Š¨ˆÑ3Ô3Ð3r   c                ó*   — t          | j        ¦  «        S r7   )Úlenr3   r%   s    r   Ú__len__zBlueprintCircuit.__len__à   s   € Ý�4”9‰~Œ~Ðr   c                ó   — | j         |         S r7   )r3   )r   Úitems     r   Ú__getitem__zBlueprintCircuit.__getitem__ã   s   € ØŒy˜ŒÐr   c                ól   •— | j         s|                      ¦   «           t          ¦   «         j        |i |¤ŽS r7   )r   r&   r   Úsizer=   s      €r   ra   zBlueprintCircuit.sizeæ   r@   r   c                ó€   •— | j         s|                      ¦   «          t          ¦   «                              ||¬¦  «        S ©N)Úlabel)r   r&   r   Úto_instruction©r   Úparameter_maprd   r   s      €r   re   zBlueprintCircuit.to_instructionë   s7   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw×%Ò% m¸5Ð%ÑAÔAÐAr   c                ó€   •— | j         s|                      ¦   «          t          ¦   «                              ||¬¦  «        S rc   )r   r&   r   Úto_gaterf   s      €r   ri   zBlueprintCircuit.to_gateð   s4   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw�Š˜}°EˆÑ:Ô:Ð:r   c                ól   •— | j         s|                      ¦   «           t          ¦   «         j        |i |¤ŽS r7   )r   r&   r   Údepthr=   s      €r   rk   zBlueprintCircuit.depthõ   s5   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMØ�u‰wŒwŒ}˜dÐ- fÐ-Ð-Ð-r   c                óz   •— | j         s|                      ¦   «          t          ¦   «                              ¦   «         S r7   )r   r&   r   Ú	count_opsr4   s    €r   rm   zBlueprintCircuit.count_opsú   s0   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw× Ò Ñ"Ô"Ð"r   c                óz   •— | j         s|                      ¦   «          t          ¦   «                              ¦   «         S r7   )r   r&   r   Únum_nonlocal_gatesr4   s    €r   ro   z#BlueprintCircuit.num_nonlocal_gatesÿ   s0   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw×)Ò)Ñ+Ô+Ð+r   c                ó~   •— | j         s|                      ¦   «          t          ¦   «                              |¬¦  «        S )N)Úunitary_only)r   r&   r   Únum_connected_components)r   rq   r   s     €r   rr   z)BlueprintCircuit.num_connected_components  s5   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰wŒw×/Ò/¸\Ð/ÑJÔJÐJr   Úalike)Ú	vars_modec               óœ   •— | j         s|                      ¦   «          t          ¦   «                              ||¬¦  «        }| j        |_        |S )N)r   rt   )r   r&   r   Úcopy_empty_liker+   )r   r   rt   Úcpyr   s       €r   rv   z BlueprintCircuit.copy_empty_like	  sH   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‰gŒg×%Ò%¨4¸9Ð%ÑEÔEˆð  Ô,ˆÔØˆ
r   c                óš   •— | j         s|                      ¦   «          t          ¦   «                              |¬¦  «        }| j         |_         |S )Nr   )r   r&   r   rN   )r   r   Úcircuit_copyr   s      €r   rN   zBlueprintCircuit.copy  sA   ø€ ØŒ~ð 	Ø�KŠK‰MŒMˆMÝ‘w”w—|’|¨�|Ñ.Ô.ˆØ!%¤ˆÔØÐr   )r   r   r   r   )T)r   r    r   r    )r   r   )Nr5   )r   rA   )r   r
   )NN)NNFFF)F)rW   r    r7   ) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r&   r,   Úpropertyr.   Úsetterr3   r8   r<   rC   rE   rI   rR   rY   r\   r_   ra   re   ri   rk   rm   ro   rr   rv   rN   Ú__classcell__)r   s   @r   r   r      sa  ø€ € € € € ðð ð 26ð $ð $ð $ð $ð $ð $ð $ð $ð ð"ð "ð "ð "ñ „^ð"ð ðð ð ñ „^ððð ð ð ð ðð ñ „Xðð „\ð"ð "ñ „\ð"ð ð	ð 	ð 	ð 	ñ „Xð	ð;ð ;ð ;ð ;ð ;ð ;ð
-ð -ð -ð -ð -ð
 ð&ð &ð &ð &ð &ñ „Xð&ð ð<"ð <"ð <"ð <"ð <"ñ „Xð<"ð|[Èuð [ð [ð [ð [ð [ð [ð [ð ØØØØð
ð ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð64ð 4ð 4ð 4ð 4ð 4ð 4ð
ð ð ðð ð ð-ð -ð -ð -ð -ð
Bð Bð Bð Bð Bð Bð
;ð ;ð ;ð ;ð ;ð ;ð
.ð .ð .ð .ð .ð
#ð #ð #ð #ð #ð
,ð ,ð ,ð ,ð ,ð
Kð Kð Kð Kð Kð Kð
°gð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð r   r   N)r}   Ú
__future__r   Úabcr   r   Úqiskit._accelerate.circuitr   Úqiskit.circuitr   r   r	   Úqiskit.circuit.parametertabler
   r   © r   r   ú<module>r‡      s¹   ðð  Ð à "Ð "Ð "Ð "Ð "Ð "Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #à 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ 7Ð 7Ð 7Ð 7Ð 7Ð 7ðAð Að Að Að A�~ sñ Aô Að Að Að Ar   