§
    ¹³Ùg¢  ã                  ó„   — d Z ddlmZ ddlmZmZ ddlZddlm	Z	m
Z
 ddlmZmZ ddlmZ  G d„ d	e	¦  «        Z	 	 ddd„ZdS )zQuantum Volume model circuit.é    )Úannotations)ÚOptionalÚUnionN)ÚQuantumCircuitÚCircuitInstruction)ÚPermutationGateÚUnitaryGate)Úquantum_volumec                  ó2   ‡ — e Zd ZdZ	 	 	 dddœdˆ fd„Zˆ xZS )ÚQuantumVolumea‰  A quantum volume model circuit.

    The model circuits are random instances of circuits used to measure
    the Quantum Volume metric, as introduced in [1].

    The model circuits consist of layers of Haar random
    elements of SU(4) applied between corresponding pairs
    of qubits in a random bipartition.

    **Reference Circuit:**

    .. plot::
       :alt: Diagram illustrating the previously described circuit.

       from qiskit.circuit.library import QuantumVolume
       circuit = QuantumVolume(5, 6, seed=10)
       circuit.draw('mpl')

    **Expanded Circuit:**

    .. plot::
       :alt: Diagram illustrating the previously described circuit.

       from qiskit.circuit.library import QuantumVolume
       from qiskit.visualization.library import _generate_circuit_library_visualization
       circuit = QuantumVolume(5, 6, seed=10, classical_permutation=False)
       _generate_circuit_library_visualization(circuit.decompose())

    **References:**

    [1] A. Cross et al. Validating quantum computers using
    randomized model circuits, Phys. Rev. A 100, 032328 (2019).
    [`arXiv:1811.12926 <https://arxiv.org/abs/1811.12926>`_]
    NTF)ÚflattenÚ
num_qubitsÚintÚdepthúOptional[int]Úseedú)Optional[Union[int, np.random.Generator]]Úclassical_permutationÚboolr   ÚreturnÚNonec               óÐ  •— ddl }|p|}|dz  }t          |t          j        j        ¦  «        r|nt          j                             |¦  «        }|}	|	€%t          t          |j        dd¦  «        dd¦  «        }	t          ¦   «          	                    |dt          |||	g¦  «                             dd¦  «        z   ¬	¦  «         |rÇ|�Dt          j        t          j        ¦  «        j        }
|                     |
t          j        ¬
¦  «        }t!          |||¦  «        }| j        |_        |r|                      |d¬¦  «         dS |                      t)          |                     ¦   «         t-          | j        ¦  «        ¦  «        ¦  «         dS |€|	}|r| nt1          || j        ¬	¦  «        }|j        j                             d||z  |¦  «                             ||dd¦  «        }t-          |j        ¦  «        }|D ]¡}|                     |¦  «        }|                     t)          t=          |¦  «        |¦  «        ¦  «         t?          |¦  «        D ]J\  }}tA          |dd¬¦  «        }d|z  }|                     t)          ||||dz   …         ¦  «        ¦  «         ŒKŒ¢|sI|                      t)          |                     ¦   «         t-          | j        ¦  «        ¦  «        ¦  «         dS dS )ax  Create quantum volume model circuit of size num_qubits x depth.

        Args:
            num_qubits: number of active qubits in model circuit.
            depth: layers of SU(4) operations in model circuit.
            seed: Random number generator or generator seed.
            classical_permutation: use classical permutations at every layer,
                rather than quantum.
            flatten: If ``False`` (the default), construct a circuit that contains a single
                instruction, which in turn has the actual volume structure.  If ``True``, construct
                the volume structure directly.
        r   Né   Úseed_seqÚentropyÚquantum_volume_ú Ú )Úname©ÚdtypeT)Úinplaceé   F)Úcheck_inputr   )!Úscipy.statsÚ
isinstanceÚnpÚrandomÚ	GeneratorÚdefault_rngÚgetattrÚbit_generatorÚsuperÚ__init__ÚstrÚreplaceÚiinfoÚint64ÚmaxÚintegersr
   r   ÚcomposeÚ_appendr   Úto_instructionÚtupleÚqubitsr   ÚstatsÚunitary_groupÚrvsÚreshapeÚpermutationr   Ú	enumerater	   )Úselfr   r   r   r   r   ÚscipyÚwidthÚrngÚ	seed_nameÚ	max_valueÚqv_circÚbaseÚ	unitariesr9   ÚrowÚpermÚwÚunitaryÚgateÚqubitÚ	__class__s                        €ú[/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/quantum_volume.pyr.   zQuantumVolume.__init__=   sü  ø€ ð* 	ÐÐÐð Ð#˜ˆØ˜a‘ˆÝ  ¥r¤yÔ':Ñ;Ô;Ð\ˆdˆdÅÄ×AVÒAVÐW[ÑA\ÔA\ˆØˆ	ØÐõ
  ¥¨Ô(9¸:ÀtÑ LÔ LÈiÐY]Ñ^Ô^ˆIå‰Œ×ÒØØ"¥S¨*°e¸YÐ)GÑ%HÔ%H×%PÒ%PÐQTÐVXÑ%YÔ%YÑYð 	ñ 	
ô 	
ð 	
ð !ð 	\ØÐÝœH¥R¤XÑ.Ô.Ô2�	Ø—|’| IµR´X�|Ñ>Ô>�Ý$ Z°¸Ñ=Ô=ˆGØœ9ˆGŒLØð _Ø—’˜W¨d�Ñ3Ô3Ð3Ð3Ð3à—’Õ/°×0FÒ0FÑ0HÔ0HÍ%ÐPTÔP[ÑJ\ÔJ\Ñ]Ô]Ñ^Ô^Ð^Ð^Ð^àˆ|Ø �à"ÐR�4�4­°zÈÌ	Ð(RÑ(RÔ(RˆDð œÔ1×5Ò5°a¸À¹ÈÑLÔL×TÒTØ�u˜a ñô ˆIõ ˜4œ;Ñ'Ô'ˆFØ ð Vð V�Ø—’ zÑ2Ô2�Ø—’Õ/µÀÑ0EÔ0EÀvÑNÔNÑOÔOÐOÝ"+¨C¡.¤.ð Vð V‘J�A�wÝ& w¸EÈaÐPÑPÔP�DØ ™E�EØ—L’LÕ!3°D¸&ÀÈÐQRÉÐARÔ:SÑ!TÔ!TÑUÔUÐUÐUðVð ð \Ø—’Õ/°×0CÒ0CÑ0EÔ0EÅuÈTÌ[ÑGYÔGYÑZÔZÑ[Ô[Ð[Ð[Ð[ð\ð \ó    )NNT)r   r   r   r   r   r   r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.   Ú__classcell__)rO   s   @rP   r   r      s�   ø€ € € € € ð!ð !ðL  $Ø:>Ø&*ðE\ð ðE\ð E\ð E\ð E\ð E\ð E\ð E\ð E\ð E\ð E\ð E\ð E\rQ   r   r   r   r   ú
int | Noner   ú int | np.random.Generator | Noner   r   c                óÐ   — t          |t          j        j        ¦  «        r!|                     dt          j        ¬¦  «        }|p| }t          j        t          | ||¦  «        ¦  «        S )a.  A quantum volume model circuit.

    The model circuits are random instances of circuits used to measure
    the Quantum Volume metric, as introduced in [1].

    The model circuits consist of layers of Haar random
    elements of SU(4) applied between corresponding pairs
    of qubits in a random bipartition.

    This function is multithreaded and will launch a thread pool with threads equal to the number
    of CPUs by default. You can tune the number of threads with the ``RAYON_NUM_THREADS``
    environment variable. For example, setting ``RAYON_NUM_THREADS=4`` would limit the thread pool
    to 4 threads.

    **Reference Circuit:**

    .. plot::
       :alt: Diagram illustrating the previously described circuit.

       from qiskit.circuit.library import quantum_volume
       circuit = quantum_volume(5, 6, seed=10)
       circuit.draw('mpl')

    **References:**

    [1] A. Cross et al. Validating quantum computers using
    randomized model circuits, Phys. Rev. A 100, 032328 (2019).
    `arXiv:1811.12926 <https://arxiv.org/abs/1811.12926>`__
    r   r    )	r&   r'   r(   r)   r4   Úuint64r   Ú_from_circuit_dataÚqv_rs)r   r   r   s      rP   r
   r
   …   sZ   € õD �$�œ	Ô+Ñ,Ô,ð 1Ø�}Š}˜Q¥b¤iˆ}Ñ0Ô0ˆØÐ�Z€EÝÔ,­U°:¸uÀdÑ-KÔ-KÑLÔLÐLrQ   )NN)r   r   r   rW   r   rX   r   r   )rU   Ú
__future__r   Útypingr   r   Únumpyr'   Úqiskit.circuitr   r   Ú(qiskit.circuit.library.generalized_gatesr   r	   Ú"qiskit._accelerate.circuit_libraryr
   r\   r   © rQ   rP   ú<module>rd      sò   ðð $Ð #à "Ð "Ð "Ð "Ð "Ð "à "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø QÐ QÐ QÐ QÐ QÐ QÐ QÐ QØ FÐ FÐ FÐ FÐ FÐ Fði\ð i\ð i\ð i\ð i\�Nñ i\ô i\ð i\ð\ Ø-1ð%Mð %Mð %Mð %Mð %Mð %Mð %MrQ   