+
    ‹°³j.  ã                  óˆ  € R t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
Ht . ROt]! R	4      t]! R
RR./]3R7      t]'       dA   ]'       d9   ]P                   t]P"                  P$                  t]P&                  P(                  t ! R R4      tR t/ 3R ltRR lt ! R R]	4      t ! R R]	4      t ! R R]4      tRR ltR# )aÉ  Matplotlib based plotting of quantum circuits.

Todo:

* Optimize printing of large circuits.
* Get this to work with single gates.
* Do a better job checking the form of circuits to make sure it is a Mul of
  Gates.
* Get multi-target gates plotting.
* Get initial and final states to plot.
* Get measurements to plot. Might need to rethink measurement as a gate
  issue.
* Get scale and figsize to be handled in a better way.
* Write some tests/examples!
)Úannotations)ÚMul)Úimport_module)ÚGateÚOneQubitGateÚCGateÚCGateSÚCircuitPlotÚMzÚMxÚCreateOneQubitGateÚnumpyÚ
matplotlibÚfromlistÚpyplot)Úimport_kwargsÚcatchc                  ó´   € ] tR t^/t$ RtRtRtRtRtRt	Rt
. tR]R&   / tR]R	&   R
tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tRtR# )r	   z$A class for managing a circuit plot.g      ð?g      4@gš™™™™™©?g333333Ã?z	list[str]Úlabelszdict[str, str]Úinitsç      à?c                	ón  € \         '       d   \        '       g   \        R 4      hWn        \	        V P                  P
                  4      V n        W n        V P                  V4       V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        R# )z"numpy or matplotlib not available.N)Únpr   ÚImportErrorÚcircuitÚlenÚargsÚngatesÚnqubitsÚupdateÚ_create_gridÚ_create_figureÚ_plot_wiresÚ_plot_gatesÚ_finish)ÚselfÚcr   Úkwargss   &&&,Úb/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/physics/quantum/circuitplot.pyÚ__init__ÚCircuitPlot.__init__<   s|   € ß‹rŸ›ÜÐBÓCÐCØŒÜ˜$Ÿ,™,×+Ñ+Ó,ˆŒØŒØ�‰�FÔØ×ÑÔØ×ÑÔØ×ÑÔØ×ÑÔØ�‰Žó    c                ó<   € V P                   P                  V4       R# )z'Load the kwargs into the instance dict.N)Ú__dict__r   )r%   r'   s   &&r(   r   ÚCircuitPlot.updateI   s   € à�‰×Ñ˜VÖ$r+   c                óî   € V P                   p\        P                  RV P                  V,          V\        R7      p\        P                  RV P
                  V,          V\        R7      pW n        W0n        R# )zCreate the grid of wires.g        )ÚdtypeN)Úscaler   Úaranger   Úfloatr   Ú
_wire_gridÚ
_gate_grid)r%   r1   Ú	wire_gridÚ	gate_grids   &   r(   r    ÚCircuitPlot._create_gridM   sS   € à—
‘
ˆÜ—I‘I˜c 4§<¡<°Õ#5°uÄE�IÓJˆ	Ü—I‘I˜c 4§;¡;¨uÕ#4°eÄ5�IÓIˆ	Ø#ŒØ#Žr+   c                ój  € \         P                  V P                  V P                  ,          V P                  V P                  ,          3RRR7      V n        V P
                  P                  ^^^RR7      pVP                  4        RV P                  ,          pVP                  V P                  ^ ,          V,
          V P                  R,          V,           4       VP                  V P                  ^ ,          V,
          V P                  R,          V,           4       VP                  R4       Wn        R# )	z"Create the main matplotlib figure.Úw)ÚfigsizeÚ	facecolorÚ	edgecolorT)Úframeonr   ÚequalNéÿÿÿÿ)r   Úfigurer   r1   r   Ú_figureÚadd_subplotÚset_axis_offÚset_xlimr5   Úset_ylimr4   Ú
set_aspectÚ_axes)r%   ÚaxÚoffsets   &  r(   r!   ÚCircuitPlot._create_figureU   sâ   € ä—}‘}Ø—[‘[ §¡Õ+¨T¯\©\¸$¿*¹*Õ-DÐEØØð %ó 
ˆŒð
 �\‰\×%Ñ%Øˆq�!Øð &ó 
ˆð 	�‰ÔØ�T—Z‘Z•ˆØ
�‰�D—O‘O AÕ&¨Õ/°·±ÀÕ1DÀvÕ1MÔNØ
�‰�D—O‘O AÕ&¨Õ/°·±ÀÕ1DÀvÕ1MÔNØ
�‰�gÔØŽ
r+   c                ó*  € V P                   ^ ,          pV P                   R,          pWP                  ,
          W P                  ,           3p\        V P                  4       EF  pV P                  V,          V P                  V,          3p\        W5RV P                  R7      pV P                  P                  V4       V P                  '       g   Kq  ^ pV P                  P                  V P                  V,          4      '       d   RpV P                  P                  V^ ,          V P                  ,
          V,
          V^ ,          \        V P                  V,          V P                  4      V P                  RRRR7       EK!  	  V P!                  4        R# )z&Plot the wires of the circuit diagram.Úk©ÚcolorÚlwg      Ð?Úcenter)ÚsizerO   ÚhaÚvaNr@   )r5   r1   Úranger   r4   ÚLine2DÚ	linewidthrH   Úadd_liner   r   ÚgetÚtextÚlabel_bufferÚrender_labelÚfontsizeÚ_plot_measured_wires)r%   ÚxstartÚxstopÚxdataÚiÚydataÚlineÚinit_label_buffers   &       r(   r"   ÚCircuitPlot._plot_wiresg   s$  € à—‘ Õ#ˆØ—‘ Õ#ˆØŸ*™*Õ$ e¯j©jÕ&8Ð9ˆÜ�t—|‘|×$ˆAØ—_‘_ QÕ'¨¯©¸Õ);Ð<ˆEÜØØØ—>‘>ôˆDð
 �J‰J×Ñ Ô%Ø�{�{Š{Ø$%Ð!Ø—:‘:—>‘> $§+¡+¨a¥.×1Ò1ÀtÐ3DØ—
‘
—‘Ø˜!•H˜T×.Ñ.Õ.Ð/@Õ@ÀÀqÅÜ  §¡¨Q¥°·
±
Ó;ØŸ™Ø ¨Xð	  ÷ 7ñ %ð  	×!Ñ!Ö#r+   c           	     	óÂ  € V P                  4       pV P                  R,          pRpV F•  pV P                  W,          ,          W P                  ,           3pV P                  V,          V,           V P                  V,          V,           3p\	        WVRV P
                  R7      pV P                  P                  V4       K—  	  \        V P                  4       4       EF   w  r‰\        V	\        \        34      '       g   K$  V	P                  V	P                  ,           p
V
 F¹  pW±9   g   K  V P                  V,          V P                  W,          ,          8”  g   K<  \        V
4      \!        V
4      3pV P                  V,          V,
          V P                  V,          V,
          3p\	        WVRV P
                  R7      pV P                  P                  V4       K»  	  EK  	  R# )é   g{®Gáz¤?rM   rN   Nr@   )Ú_measurementsr5   r1   r4   rV   rW   rH   rX   Ú	enumerateÚ_gatesÚ
isinstancer   r   ÚcontrolsÚtargetsÚminÚmax)r%   Ú
ismeasuredr`   ÚdyÚimra   rc   rd   rb   ÚgÚwiresÚwires   &           r(   r^   Ú CircuitPlot._plot_measured_wires~   sf  € Ø×'Ñ'Ó)ˆ
Ø—‘ Õ#ˆØˆãˆBØ—_‘_ Z¥^Õ4°U¿:¹:Õ5EÐFˆEØ—_‘_ RÕ(¨Õ+¨D¯O©O¸BÕ,?ÀÕ,BÐCˆEÜØØØ—>‘>ôˆDð
 �J‰J×Ñ Ö%ñ ô ˜TŸ[™[›]×+‰CˆAÜ˜!œe¤V˜_×-Ô-ØŸ
™
 Q§Y¡YÕ.�Û!�DØÖ)ØŸ?™?¨1Õ-°·±À
Õ@PÕ0QÖQÜ # E£
¬C°«JÐ 6˜Ø $§¡°Õ 2°2Õ 5°t·±ÀqÕ7IÈ"Õ7LÐ L˜Ü%Ø!Ø"%Ø#Ÿ~™~ô ˜ð
 Ÿ
™
×+Ñ+¨DÖ1ô "ó ,r+   c                ób  € . p\        V P                  \        4      '       dR   \        V P                  P                  4       F,  p\        V\
        4      '       g   K  VP                  V4       K.  	  V# \        V P                  \
        4      '       d   VP                  V P                  4       V# )z/Create a list of all gates in the circuit plot.)rl   r   r   Úreversedr   r   Úappend)r%   Úgatesrt   s   &  r(   rk   ÚCircuitPlot._gates›   sx   € àˆÜ�d—l‘l¤C×(Ò(Ü˜dŸl™l×/Ñ/Ö0�Ü˜a¤×&Ô&Ø—L‘L –Oñ 1ð
 ˆô ˜Ÿ™¤d×+Ò+Ø�L‰L˜Ÿ™Ô&Øˆr+   c                ól   € \        V P                  4       4       F  w  rVP                  W4       K  	  R# )z0Iterate through the gates and plot each of them.N)rj   rk   Ú	plot_gate)r%   rb   Úgates   &  r(   r#   ÚCircuitPlot._plot_gates¦   s%   € ä  §¡£Ö/‰GˆAØ�N‰N˜4Ö#ó 0r+   c                óÜ   € / p\        V P                  4       4       FL  w  r#\        VRR4      '       g   K  VP                   F"  pWA9   d   W,          V8”  d   W!V&   K  K  W!V&   K$  	  KN  	  V# )zReturn a dict ``{i:j}`` where i is the index of the wire that has
been measured, and j is the gate where the wire is measured.
ÚmeasurementF)rj   rk   Úgetattrrn   )r%   rq   rb   rt   Útargets   &    r(   ri   ÚCircuitPlot._measurements«   sm   € ð ˆ
Ü˜TŸ[™[›]Ö+‰CˆAÜ�q˜ u×-Ô-ØŸiœi�FØÔ+Ø%Õ-°Ô1Ø12 vÓ.ñ 2ð ./ 6Ó*ó (ñ ,ð Ðr+   c                	ój   € V P                   P                  4        F  pVP                  R 4       K  	  R# )FN)rB   ÚfindobjÚset_clip_on)r%   Úos   & r(   r$   ÚCircuitPlot._finishº   s%   € à—‘×%Ñ%Ö'ˆAØ�M‰M˜%Ö ó (r+   c                óÎ   € V P                   V,          pV P                  V,          pV P                  P                  WEVRRRRRRRRRRV P                  /V P
                  R	7       R
# )z#Draw a box for a single qubit gate.rM   rQ   ÚecÚfcr:   ÚfillTrP   )rO   rS   rT   ÚbboxrR   N)r5   r4   rH   rZ   rW   r]   )r%   ÚtÚgate_idxÚwire_idxÚxÚys   &&&&  r(   Úone_qubit_boxÚCircuitPlot.one_qubit_box¿   s`   € à�O‰O˜HÕ%ˆØ�O‰O˜HÕ%ˆØ�
‰
�‰Ø�!ØØØØ˜˜T 3¨°°d¸D¿N¹NÐKØ—‘ð 	ö 	
r+   c                óZ   € \        V P                  4       \        V P                  4       R# )z<Draw a box for a two qubit gate. Does not work yet.
        N)Úprintr5   r4   )r%   r�   r‘   r’   s   &&&&r(   Útwo_qubit_boxÚCircuitPlot.two_qubit_boxÌ   s   € ô
 	ˆd�o‰oÔÜˆd�o‰oÖr+   c                ó  € V P                   V,          V P                   V,          3pV P                  V,          V P                  V,          3p\        WERV P                  R7      pV P                  P                  V4       R# )zDraw a vertical control line.rM   rN   N)r5   r4   rV   rW   rH   rX   )r%   r‘   Úmin_wireÚmax_wirera   rc   rd   s   &&&&   r(   Úcontrol_lineÚCircuitPlot.control_lineÝ   se   € à—‘ Õ*¨D¯O©O¸HÕ,EÐFˆØ—‘ Õ*¨D¯O©O¸HÕ,EÐFˆÜØØØ�~‰~ô
ˆð
 	�
‰
×Ñ˜DÖ!r+   c           	     óø   € V P                   V,          pV P                  V,          pV P                  p\        W43WPP                  ,          RRRV P
                  R7      pV P                  P                  V4       R# )zDraw a control point.rM   T©rŒ   r�   rŽ   rP   N)r5   r4   Úcontrol_radiusÚCircler1   rW   rH   Ú	add_patch)r%   r‘   r’   r“   r”   Úradiusr&   s   &&&    r(   Úcontrol_pointÚCircuitPlot.control_pointè   sf   € à�O‰O˜HÕ%ˆØ�O‰O˜HÕ%ˆØ×$Ñ$ˆÜØˆFØ—:‘:ÕØØØØ�~‰~ô
ˆð 	�
‰
×Ñ˜QÖr+   c           	     ó^  € V P                   V,          pV P                  V,          pV P                  p\        W43VRRRV P                  R7      pV P
                  P                  V4       \        W33WE,
          WE,           3RV P                  R7      pV P
                  P                  V4       R# )z7Draw a NOT gates as the circle with plus in the middle.rM   r:   Fr¡   rN   N)	r5   r4   Ú
not_radiusr£   rW   rH   r¤   rV   rX   )r%   r‘   r’   r“   r”   r¥   r&   Úls   &&&     r(   Ú	not_pointÚCircuitPlot.not_point÷   s•   € à�O‰O˜HÕ%ˆØ�O‰O˜HÕ%ˆØ—‘ˆÜØˆFØØØØØ�~‰~ô
ˆð 	�
‰
×Ñ˜QÔÜØˆF�Q•Z ¥Ð,ØØ�~‰~ô
ˆð
 	�
‰
×Ñ˜AÖr+   c                óª  € V P                   V,          pV P                  V,          pV P                  p\        W5,
          W5,           3WE,
          WE,           3RV P                  R7      p\        W5,
          W5,           3WE,           WE,
          3RV P                  R7      pV P
                  P                  V4       V P
                  P                  V4       R# )zDraw a swap point as a cross.rM   rN   N)r5   r4   Ú
swap_deltarV   rW   rH   rX   )r%   r‘   r’   r“   r”   ÚdÚl1Úl2s   &&&     r(   Ú
swap_pointÚCircuitPlot.swap_point  s£   € à�O‰O˜HÕ%ˆØ�O‰O˜HÕ%ˆØ�O‰OˆÜØ�U�A•EˆNØ�U�A•EˆNØØ�~‰~ô	
ˆô Ø�U�A•EˆNØ�U�A•EˆNØØ�~‰~ô	
ˆð 	�
‰
×Ñ˜BÔØ�
‰
×Ñ˜BÖr+   )rH   rB   r5   r4   r   r   r   N) Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r1   r]   rW   r¢   r©   r®   r   Ú__annotations__r   r[   r)   r   r    r!   r"   r^   rk   r#   ri   r$   r•   r™   rž   r¦   r«   r²   Ú__static_attributes__© r+   r(   r	   r	   /   sŒ   ‡ Ù.à€EØ€HØ€IØ€NØ€JØ€JØ€FˆIÓØ€Eˆ>ÓØ€Lòò%ò$òò$$ò.2ò:	ò$ò
ò!ò

òò"	"ò òö* r+   c                ó   € \        W3/ VB # )a%  Draw the circuit diagram for the circuit with nqubits.

Parameters
==========

c : circuit
    The circuit to plot. Should be a product of Gate instances.
nqubits : int
    The number of qubits to include in the circuit. Must be at least
    as big as the largest ``min_qubits`` of the gates.
)r	   )r&   r   r'   s   &&,r(   Úcircuit_plotr½      s   € ô �qÑ, VÑ,Ð,r+   c                ó\   € VP                  V 4      pV'       d   RV : RV: R2# RV ,          # )zùSlightly more flexible way to render labels.

>>> from sympy.physics.quantum.circuitplot import render_label
>>> render_label('q0')
'$\\left|q0\\right\\rangle$'
>>> render_label('q0', {'q0':'0'})
'$\\left|q0\\right\\rangle=\\left|0\\right\\rangle$'
z$\left|z\right\rangle=\left|z\right\rangle$z$\left|%s\right\rangle$)rY   )Úlabelr   Úinits   && r(   r\   r\   .  s-   € ð �9‰9�UÓ€Dß€tÛCHË$ÐOÐOØ%¨Õ-Ð-r+   c                ón   € \        V 4       Uu. uF  pRWV,
          ^,
          3,          NK  	  up# u upi )aX  Autogenerate labels for wires of quantum circuits.

Parameters
==========

n : int
    number of qubits in the circuit.
symbol : string
    A character string to precede all gate labels. E.g. 'q_0', 'q_1', etc.

>>> from sympy.physics.quantum.circuitplot import labeller
>>> labeller(2)
['q_1', 'q_0']
>>> labeller(3,'j')
['j_2', 'j_1', 'j_0']
z%s_%d)rU   )ÚnÚsymbolrb   s   && r(   ÚlabellerrÄ   <  s2   € ô" /4°A¬hÓ7©h¨ˆG�v �c !�e�n×$Ð$©hÑ7Ð7ùÒ7s   Ž!2c                  ó&   € ] tR tRtRtRtR tRtRtR# )r
   iO  z~Mock-up of a z measurement gate.

This is in circuitplot rather than gate.py because it's not a real
gate, it just draws one.
TÚM_zr»   N©	r´   rµ   r¶   r·   r¸   r‚   Ú	gate_nameÚgate_name_latexrº   r»   r+   r(   r
   r
   O  ó   † ñð
 €KØ€IØ„Or+   c                  ó&   € ] tR tRtRtRtR tRtRtR# )r   iY  zMock-up of an x measurement gate.

This is in circuitplot rather than gate.py because it's not a real
gate, it just draws one.
TÚM_xr»   NrÇ   r»   r+   r(   r   r   Y  rÊ   r+   c                  ó    € ] tR tRtRR ltRtR# )r   ic  Nc                	óP   € V'       g   Tp\        VR ,           \        3RVRV/4      # )r   rÈ   rÉ   )Útyper   )ÚmclÚnameÚ	latexnames   &&&r(   Ú__new__ÚCreateOneQubitGate.__new__d  s.   € ßØˆIÜ�D˜6•M¤L ?Ø˜$Ð 1°9Ð=ó?ð 	?r+   r»   ©N)r´   rµ   r¶   r·   rÓ   rº   r»   r+   r(   r   r   c  s   † ÷?ð ?r+   Nc                ó>   a€ V'       g   T p\        W4      oV3R lpV# )z5Use a lexical closure to make a controlled gate.
    c                ó:   <€ \        \        V 4      S! V4      4      # rÕ   )r   Útuple)Úctrlsr„   Úonequbitgates   &&€r(   ÚControlledGateÚ#CreateCGate.<locals>.ControlledGatep  s   ø€ Ü”U˜5“\¡,¨vÓ"6Ó7Ð7r+   )r   )rÑ   rÒ   rÛ   rÚ   s   && @r(   ÚCreateCGaterÝ   j  s"   ø€ ÷ Øˆ	Ü% dÓ6€Lõ8àÐr+   )r	   r½   rÄ   r
   r   r   rÝ   )ÚqrÕ   )r¸   Ú
__future__r   Úsympy.core.mulr   Úsympy.externalr   Úsympy.physics.quantum.gater   r   r   r   Ú__all__r   ÚRuntimeErrorr   r   ÚlinesrV   Úpatchesr£   r	   r½   r\   rÄ   r
   r   rÏ   r   rÝ   r»   r+   r(   Ú<module>rç      sÇ   ðñõ  #å Ý (ß HÓ Hò€ñ �7Ó€ÙØ ¨h¨ZÐ 8Øˆ/ô€
÷ �*Ø×Ñ€FØ×Ñ×$Ñ$€FØ×Ñ×&Ñ&€F÷
o ñ o òb-ð !ô .ô8ô&ˆô ôˆô ô?˜ô ?ör+   