
    z	i                    p    S r SSKJr  SSKrSSKJrJr  SSKJ	r	  SSK
Jr   " S S\5      r " S	 S
\5      rg)zGraph State circuit and gate.    )annotationsN)QuantumCircuitGate)CircuitError)deprecate_funcc                  F   ^  \ rS rSrSr\" SSSS9S	U 4S jj5       rSrU =r$ )

GraphState   aV  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))
   circuit.name = "Graph state"
   _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2.1z2Use qiskit.circuit.library.GraphStateGate instead.zin Qiskit 3.0)sinceadditional_msgremoval_timelinec                  > [         R                  " U5      n[         R                  " XR                  5       5      (       d  [	        S5      e[        U5      n[        TU ]  UR                  SU 3S9  U R                  X R                  SS9  g)zCreate 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   )selfadjacency_matrixgraph_state_gate	__class__s      \/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/graph_state.pyr   GraphState.__init__>   s}    $ ::&67{{+-G-G-IJJHII)*:;)44WEUDV;WX%kk4H     r   zlist | np.ndarrayreturnNone)	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classcell__r    s   @r!   r	   r	      s-    $L K(
I
Ir#   r	   c                  R   ^  \ rS rSrSrS	U 4S jjrS rS r\S 5       r	S r
SrU =r$ )
r   Y   aJ  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>`_
c                   > [         R                  " U5      n[         R                  " XR                  5       5      (       d  [	        S5      e[        U5      n[        TU ]  SX!/S9  g)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   GraphStateGate.__init__   sZ     ::&67{{+-G-G-IJJHII)*
m
K]^r#   c                `   U R                   n[        U R                  U R                  S9nUR	                  [        U R                  5      5        [        U R                  5       HA  n[        US-   U R                  5       H!  nX   U   S:X  d  M  UR                  X45        M#     MC     X l        g )Nr      )r   r   r   r   hrangecz
definition)r   r   circuitijs        r!   _defineGraphStateGate._define   s    00 tyyA		%()t'A1q5$//2#&q)Q.JJq$ 3 ( "r#   c                    U$ )zParameter validationr$   )r   	parameters     r!   validate_parameter!GraphStateGate.validate_parameter   s    r#   c                     U R                   S   $ )zReturns the adjacency matrix.r   )r4   )r   s    r!   r   GraphStateGate.adjacency_matrix   s     {{1~r#   c                    [        U[        5      =(       aM    U R                  UR                  :H  =(       a-    [        R                  " U R
                  UR
                  :H  5      $ )N)
isinstancer   r   r   allr   )r   others     r!   __eq__GraphStateGate.__eq__   sL    un- H5#3#33Ht,,0F0FFG	
r#   )r<   r%   )r(   r)   r*   r+   r,   r   r@   rD   propertyr   rL   r-   r.   r/   s   @r!   r   r   Y   s7    'R_$"  
 
r#   r   )r,   
__future__r   numpyr   qiskit.circuit.quantumcircuitr   r   qiskit.circuit.exceptionsr   qiskit.utils.deprecationr   r	   r   r$   r#   r!   <module>rT      s6    $ "  > 2 3?I ?IDT
T T
r#   