
    z	iT                        S r SSKJr  SSKJrJr  SSKrSSKJ	r	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S jjrg)zQuantum Volume model circuit.    )annotations)OptionalUnionN)QuantumCircuitCircuitInstruction)PermutationGateUnitaryGate)quantum_volume)deprecate_funcc                  n   ^  \ rS rSrSr\" SSSS9   SSS.           SU 4S	 jjjj5       rS
rU =r$ )QuantumVolume   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.

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>`__
z2.2z?Use the function qiskit.circuit.library.quantum_volume instead.zin Qiskit 3.0)sinceadditional_msgremoval_timelineF)flattenc               h  > SSK nU=(       d    UnUS-  n[        U[        R                  R                  5      (       a  UO[        R                  R                  U5      nUn	U	c"  [        [        UR                  SS5      SS5      n	[        TU ]%  US[        XU	/5      R                  SS5      -   S	9  U(       a  UbL  [        R                  " [        R                  5      R                  n
UR                  U
[        R                  S
9n[!        XU5      nU R"                  Ul        U(       a  U R%                  USS9  gU R'                  [)        UR+                  5       [-        U R.                  5      5      5        gUc  U	nU(       a  U O[1        XR"                  S	9nUR2                  R4                  R7                  SX'-  U5      R9                  X'SS5      n[-        UR.                  5      nU H~  nUR;                  U5      nUR'                  [)        [=        U5      U5      5        [?        U5       H7  u  nn[A        USSS9nSU-  nUR'                  [)        UUUUS-    5      5        M9     M     U(       d=  U R'                  [)        UR+                  5       [-        U R.                  5      5      5        gg)a  
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_input
num_qubits)!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    depthseedclassical_permutationr   scipywidthrng	seed_name	max_valueqv_circbase	unitariesr5   rowpermwunitarygatequbit	__class__s                        _/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/quantum_volume.pyr*   QuantumVolume.__init__>   sA   2 	 #a ryy':':;;dAVAVW[A\	
  (9(9:t LiY]^I"S*Y)G%H%P%PQTVX%YY 	 	
 !HHRXX.22	||IRXX|>$Z=G99GLWd3/0F0F0H%PTP[P[J\]^| "4z		(RD 1155aLTTaI 4;;'F z2/0EvNO"+C.JAw&wEaPDEELL!3D&QR:S!TU #1 ! /0C0C0EuT[[GYZ[      )NNT)r    intr=   zOptional[int]r>   z)Optional[Union[int, np.random.Generator]]r?   boolr   rT   returnNone)	__name__
__module____qualname____firstlineno____doc__r   r*   __static_attributes____classcell__)rN   s   @rO   r   r      s    !F X(  $:>&*D\ D\D\ D\ 8	D\
  $D\ D\ 
D\ D\
D\rQ   r   c                B   [        U[        R                  R                  5      (       aL  [        R                  " [        R
                  5      R                  nUR                  U[        R
                  S9nU=(       d    U n[        R                  " [        XU5      5      $ )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.

Args:
    num_qubits: The number qubits to use for the generated circuit.
    depth: The number of layers for the generated circuit. If this
        is not specified it will default to ``num_qubits`` layers.
    seed: An optional RNG seed used for generating the random SU(4)
        matrices used in the output circuit. This can be either an
        integer or a numpy generator. If an integer is specfied it must
        be an value between 0 and 2**64 - 1.

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-   r.   r/   r0   r   _from_circuit_dataqv_rs)r    r=   r>   rD   s       rO   r
   r
      sl    V $		++,,HHRXX&**	}}Ybhh}7ZE,,U:d-KLLrQ   )NN)r    rS   r=   z
int | Noner>   z int | np.random.Generator | NonerU   r   )r[   
__future__r   typingr   r   numpyr#   qiskit.circuitr   r   (qiskit.circuit.library.generalized_gatesr   r	   "qiskit._accelerate.circuit_libraryr
   r`   qiskit.utils.deprecationr   r   rR   rQ   rO   <module>rh      sf    $ " "  = Q F 3m\N m\d -1/M/M/M +/M 	/MrQ   