§
    ¹³Ùg`  ã                  ó~   — d Z ddlmZ ddlZddlmZmZ ddlm	Z	 ddl
mZ  G d„ de¦  «        Z G d	„ d
e¦  «        ZdS )zGraph State circuit and gate.é    )ÚannotationsN)ÚQuantumCircuitÚGate)ÚCircuitError)Údeprecate_funcc                  óL   ‡ — e Zd ZdZ eddd¬¦  «        dˆ fd
„¦   «         Zˆ xZS )Ú
GraphStatea¢  Circuit to prepare a graph state.

    Given a graph G = (V, E), with the set of vertices V and the set of edges E,
    the corresponding graph state is defined as

    .. math::

        |G\rangle = \prod_{(a,b) \in E} CZ_{(a,b)} {|+\rangle}^{\otimes V}

    Such a state can be prepared by first preparing all qubits in the :math:`+`
    state, then applying a :math:`CZ` gate for each corresponding graph edge.

    Graph state preparation circuits are Clifford circuits, and thus
    easy to simulate classically. However, by adding a layer of measurements
    in a product basis at the end, there is evidence that the circuit becomes
    hard to simulate [2].

    **Reference Circuit:**

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

       from qiskit.circuit.library import GraphState
       from qiskit.visualization.library import _generate_circuit_library_visualization
       import rustworkx as rx
       G = rx.generators.cycle_graph(5)
       circuit = GraphState(rx.adjacency_matrix(G))
       _generate_circuit_library_visualization(circuit)

    **References:**

    [1] M. Hein, J. Eisert, H.J. Briegel, Multi-party Entanglement in Graph States,
        `arXiv:0307130 <https://arxiv.org/pdf/quant-ph/0307130.pdf>`_
    [2] D. Koh, Further Extensions of Clifford Circuits & their Classical Simulation Complexities.
        `arXiv:1512.07892 <https://arxiv.org/pdf/1512.07892.pdf>`_
    z1.3z2Use qiskit.circuit.library.GraphStateGate instead.T)ÚsinceÚadditional_msgÚpendingÚadjacency_matrixúlist | np.ndarrayÚreturnÚNonec                óJ  •— t          j        |¦  «        }t          j        ||                     ¦   «         ¦  «        st	          d¦  «        ‚t          |¦  «        }t          ¦   «                              |j        d|› �¬¦  «         |  	                    || j
        d¬¦  «         dS )a+  Create graph state preparation circuit.

        Args:
            adjacency_matrix: input graph as n-by-n list of 0-1 lists

        Raises:
            CircuitError: If adjacency_matrix is not symmetric.

        The circuit prepares a graph state with the given adjacency
        matrix.
        ú'The adjacency matrix must be symmetric.zgraph: ©ÚnameT)ÚqubitsÚinplaceN)ÚnpÚasarrayÚallcloseÚ	transposer   ÚGraphStateGateÚsuperÚ__init__Ú
num_qubitsÚcomposer   )Úselfr   Úgraph_state_gateÚ	__class__s      €úX/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/graph_state.pyr   zGraphState.__init__=   s£   ø€ õ$ œ:Ð&6Ñ7Ô7ÐÝŒ{Ð+Ð-=×-GÒ-GÑ-IÔ-IÑJÔJð 	JÝÐHÑIÔIÐIå)Ð*:Ñ;Ô;ÐÝ‰Œ×ÒÐ)Ô4Ð;WÐEUÐ;WÐ;WÐÑXÔXÐXØ�ŠÐ%¨d¬kÀ4ˆÑHÔHÐHÐHÐHó    ©r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__classcell__©r"   s   @r#   r	   r	      s{   ø€ € € € € ð#ð #ðJ €^ØØKØðñ ô ð
Ið Ið Ið Ið Iñô ð
Ið Ið Ið Ið Ir$   r	   c                  óL   ‡ — e Zd ZdZdˆ fd„Zd„ Zd„ Zed	„ ¦   «         Zd
„ Z	ˆ xZ
S )r   aÅ  A gate representing a graph state.

    Given a graph G = (V, E), with the set of vertices V and the set of edges E,
    the corresponding graph state is defined as

    .. math::

        |G\rangle = \prod_{(a,b) \in E} CZ_{(a,b)} {|+\rangle}^{\otimes V}

    Such a state can be prepared by first preparing all qubits in the :math:`+`
    state, then applying a :math:`CZ` gate for each corresponding graph edge.

    Graph state preparation circuits are Clifford circuits, and thus
    easy to simulate classically. However, by adding a layer of measurements
    in a product basis at the end, there is evidence that the circuit becomes
    hard to simulate [2].

    **Reference Circuit:**

    .. plot::
        :alt: Circuit diagram output by the previous code.
        :include-source:

        from qiskit.circuit import QuantumCircuit
        from qiskit.circuit.library import GraphStateGate
        import rustworkx as rx

        G = rx.generators.cycle_graph(5)
        circuit = QuantumCircuit(5)
        circuit.append(GraphStateGate(rx.adjacency_matrix(G)), [0, 1, 2, 3, 4])
        circuit.decompose().draw('mpl')

    **References:**

    [1] M. Hein, J. Eisert, H.J. Briegel, Multi-party Entanglement in Graph States,
        `arXiv:0307130 <https://arxiv.org/pdf/quant-ph/0307130.pdf>`_
    [2] D. Koh, Further Extensions of Clifford Circuits & their Classical Simulation Complexities.
        `arXiv:1512.07892 <https://arxiv.org/pdf/1512.07892.pdf>`_
    r   r   r   r   c                ó  •— t          j        |¦  «        }t          j        ||                     ¦   «         ¦  «        st	          d¦  «        ‚t          |¦  «        }t          ¦   «                              d||g¬¦  «         dS )zú
        Args:
            adjacency_matrix: input graph as n-by-n list of 0-1 lists

        Raises:
            CircuitError: If adjacency_matrix is not symmetric.

        The gate represents a graph state with the given adjacency matrix.
        r   Úgraph_state)r   r   ÚparamsN)r   r   r   r   r   Úlenr   r   )r    r   r   r"   s      €r#   r   zGraphStateGate.__init__�   s   ø€ õ œ:Ð&6Ñ7Ô7ÐÝŒ{Ð+Ð-=×-GÒ-GÑ-IÔ-IÑJÔJð 	JÝÐHÑIÔIÐIÝÐ)Ñ*Ô*ˆ
å‰Œ×Ò˜m¸
ÐL\ÐK]ÐÑ^Ô^Ð^Ð^Ð^r$   c                óZ  — | j         }t          | j        | j        ¬¦  «        }|                     t          | j        ¦  «        ¦  «         t          | j        ¦  «        D ]E}t          |dz   | j        ¦  «        D ]*}||         |         dk    r|                     ||¦  «         Œ+ŒF|| _        d S )Nr   é   )r   r   r   r   ÚhÚrangeÚczÚ
definition)r    r   ÚcircuitÚiÚjs        r#   Ú_definezGraphStateGate._define“   s±   € ØÔ0ÐÝ  ¤°t´yÐAÑAÔAˆØ�	Š	•%˜œÑ(Ô(Ñ)Ô)Ð)Ý�t”Ñ'Ô'ð 	%ð 	%ˆAÝ˜1˜q™5 $¤/Ñ2Ô2ð %ð %�Ø# AÔ& qÔ)¨QÒ.Ð.Ø—J’J˜q !Ñ$Ô$Ð$øð%ð "ˆŒˆˆr$   c                ó   — |S )zParameter validation© )r    Ú	parameters     r#   Úvalidate_parameterz!GraphStateGate.validate_parameter�   s   € àÐr$   c                ó   — | j         d         S )zReturns the adjacency matrix.r   )r/   )r    s    r#   r   zGraphStateGate.adjacency_matrix¡   s   € ð Œ{˜1Œ~Ðr$   c                ó�   — t          |t          ¦  «        o1| j        |j        k    o!t          j        | j        |j        k    ¦  «        S )N)Ú
isinstancer   r   r   Úallr   )r    Úothers     r#   Ú__eq__zGraphStateGate.__eq__¦   sE   € å�u�nÑ-Ô-ð HØ” 5Ô#3Ò3ðHå”�tÔ,°Ô0FÒFÑGÔGð	
r$   r%   )r&   r'   r(   r)   r   r:   r>   Úpropertyr   rD   r*   r+   s   @r#   r   r   X   s–   ø€ € € € € ð&ð &ðP_ð _ð _ð _ð _ð _ð$"ð "ð "ðð ð ð ðð ñ „Xðð
ð 
ð 
ð 
ð 
ð 
ð 
r$   r   )r)   Ú
__future__r   Únumpyr   Úqiskit.circuit.quantumcircuitr   r   Úqiskit.circuit.exceptionsr   Úqiskit.utils.deprecationr   r	   r   r<   r$   r#   ú<module>rK      sØ   ðð $Ð #à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3ð>Ið >Ið >Ið >Ið >I�ñ >Iô >Ið >IðBS
ð S
ð S
ð S
ð S
�Tñ S
ô S
ð S
ð S
ð S
r$   