
    z	i;              
          S r SSKrSSKJrJrJrJrJr  SSKJ	r	J
r
  SSKJr  SSKJrJr  S\R                   S\\\4   S	\\\R$                  \R&                  4      4S
 jr SS\R                   S\\\4   S\\
   S	\\R$                     4S jjrS\l        S\R                   S\\\4   S	\\R$                     4S jrS\R0                  S\\\4   S	\\R&                     4S jr SS\R0                  S\\\4   S\\
   S	\\R$                     4S jjrS\l        S\R6                  S\\\4   S	\\R8                     4S jrS\R<                  S\\\4   S	\\R>                     4S jr g)a  
A collection of functions that generate drawings from formatted input data.
See :py:mod:`~qiskit.visualization.timeline.types` for more info on the required data.

An end-user can write arbitrary functions that generate custom drawings.
Generators in this module are called with the `formatter` kwarg. This data provides
the stylesheet configuration.


There are 4 types of generators in this module.

1. generator.gates

In this stylesheet entry the input data is `types.ScheduledGate` and generates gate objects
such as time buckets and gate name annotations.

The function signature of the generator is restricted to:

    ```python

    def my_object_generator(
            gate: types.ScheduledGate,
            formatter: Dict[str, Any]) -> List[ElementaryData]:

        # your code here: create and return drawings related to the gate object.
    ```

If a generator object has the attribute ``accepts_program`` set to ``True``, then the generator will
be called with an additional keyword argument ``program: QuantumCircuit``.

2. generator.bits

In this stylesheet entry the input data is `types.Bits` and generates timeline objects
such as zero line and name of bit associated with the timeline.

The function signature of the generator is restricted to:

    ```python

    def my_object_generator(
            bit: types.Bits,
            formatter: Dict[str, Any]) -> List[ElementaryData]:

        # your code here: create and return drawings related to the bit object.
    ```

If a generator object has the attribute ``accepts_program`` set to ``True``, then the generator will
be called with an additional keyword argument ``program: QuantumCircuit``.

3. generator.barriers

In this stylesheet entry the input data is `types.Barrier` and generates barrier objects
such as barrier lines.

The function signature of the generator is restricted to:

    ```python

    def my_object_generator(
            barrier: types.Barrier,
            formatter: Dict[str, Any]) -> List[ElementaryData]:

        # your code here: create and return drawings related to the barrier object.
    ```

If a generator object has the attribute ``accepts_program`` set to ``True``, then the generator will
be called with an additional keyword argument ``program: QuantumCircuit``.

4. generator.gate_links

In this stylesheet entry the input data is `types.GateLink` and generates barrier objects
such as barrier lines.

The function signature of the generator is restricted to:

    ```python

    def my_object_generator(
            link: types.GateLink,
            formatter: Dict[str, Any]) -> List[ElementaryData]:

        # your code here: create and return drawings related to the link object.
    ```

If a generator object has the attribute ``accepts_program`` set to ``True``, then the generator will
be called with an additional keyword argument ``program: QuantumCircuit``.

Arbitrary generator function satisfying the above format can be accepted.
Returned `ElementaryData` can be arbitrary subclasses that are implemented in
the plotter API.
    N)ListUnionDictAnyOptional)QubitQuantumCircuit)CircuitError)typesdrawingsgate	formatterreturnc                     [        U R                  R                  5       5      n U R                  R
                  =(       d    SnU R                  R                  UU R                  U R                  U R                  USR                  [        [         U R                  R                  5      5      S.nUS   R                  U R                  R                  US   5      nU R                  S:  a  US   UUS   US	   S
.nU R                  R                  S:X  a  [        R                  R                   nO[        R                  R"                  n[$        R&                  " UU R                  U R                  U R                  -   /SUS   -  SUS   -  /U R                  U R(                     UUS9nU/$ US   UUS   SSS.nUS   n	US   n
[$        R*                  " [        R,                  R.                  U R                  U R(                     U R                  SU	U
US9nU/$ ! [        [        4 a    Sn GNf = f! [         a    Sn GNf = f)a  Generate time bucket or symbol of scheduled gate.

If gate duration is zero or frame change a symbol is generated instead of time box.
The face color of gates depends on the operand type.

Stylesheet:
    - The `gate` style is applied for finite duration gate.
    - The `frame_change` style is applied for zero duration gate.
    - The `gate_face_color` style is applied for face color.

Args:
    gate: Gate information source.
    formatter: Dictionary of stylesheet settings.

Returns:
    List of `TextData` or `BoxData` drawings.
zn/a, )namelabelbitst0durationunitary
parameterscolor.gatescolor.default_gater   z
layer.gatez
alpha.gatezline_width.gate)zorder	facecoloralpha	linewidthdelay      zbox_height.gate      ?)	data_typexvalsyvalsbitmetastyleszlayer.frame_changeztext_size.frame_changecenterr   colorsizevahazunicode_symbol.frame_changezlatex_symbol.frame_change)r"   r%   xvalyvaltextlatexr'   )stroperand	to_matrixAttributeErrorr
   r   r   r   r   r   joinmapparamsgetr   BoxTypeDELAY
SCHED_GATEr   BoxDatabit_positionTextData
SymbolTypeFRAME)r   r   r   r   r&   r*   r'   r"   drawingunicode_symbollatex_symbols              b/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/visualization/timeline/generators.pygen_sched_gaterF   q   s8   *dll,,./""+e
 !!		ggMMiiC)<)< =>D m$(():):IFZ<[\E}}q  -|,"#45	
 <<'++I00I""77DGGdmm34)$566iHY>Z8Z[		$++,
< 9'   4567
 ##@A !<=##&&,,		$++,
 9E L) 
  s"   #H H8 H54H58IIprogramc           
        ^ U R                   S:  a  SnSnOSnUS   nUS   US   US   USS.nS	U R                  R                   S
3nUS   R                  U R                  R                  U5      nU R                  R                   nU n	[	        U R
                  5      S:  a]  Tc#  SR                  S U R
                   5       5      n
O%SR                  U4S jU R
                   5       5      n
USU
 S3-  nU	SU
 S3-  n	/ nU R                  R                   H   n UR                  [        U5      S 5        M"     SR                  U5      nU(       a,  U R                  R                  S:w  a  USU S3-  nU	SU S3-  n	U R                   S:  a&  USU R                    S3-  nU	SU R                    S3-  n	U R                  R                  S:X  a  [        R                  R                  nO[        R                  R                  n[        R                   " UU R"                  SU R                   -  -   UU R
                  U R$                     UU	US9nU/$ ! [         a    UR                  U 5         GM[  f = f)a  Generate gate name.

Parameters and associated bits are also shown.

Stylesheet:
    - `gate_name` style is applied.
    - `gate_latex_repr` key is used to find the latex representation of the gate name.

Args:
    gate: Gate information source.
    formatter: Dictionary of stylesheet settings.
    program: Optional program that the bits are a part of.

Returns:
    List of `TextData` drawings.
r   r(   bottomlabel_offset.frame_changelayer.gate_namecolor.gate_nametext_size.gate_namer)   {\rm }latex_symbol.gates   r   c              3   P   #    U  H  n[        [        U5      5      S S v   M     g7f)N)r2   id).0r%   s     rE   	<genexpr>%gen_full_gate_name.<locals>.<genexpr>   s      HisRWbc!2is   $&c              3   \   >#    U  H!  nTR                  U5      R                   v   M#     g 7fN)find_bitindex)rU   r%   rG   s     rE   rV   rW      s(      WYcG$4$4S$9$?$?#@!AYs   ),[]z.2fr   ()r!   r"   r.   r/   r%   r0   r1   r'   )r   r3   r   r9   lenr   r6   r8   appendfloat
ValueErrorr   	LabelTyper;   	GATE_NAMEr   r?   r   r>   )r   r   rG   v_alignv_posr'   default_name
latex_namelabel_plainlabel_latexbits_strr8   val
params_strr"   rB   s     `             rE   gen_full_gate_namerp      sy   & }}q 56 -.,-/0F T\\../r2L/044T\\5F5FUJ\\&&'K \K 499~? yy Hdii HHHyy WTYY WWH8*A&8*A& F||""	$MMU3Z,. #
 6"Jdll''72:,a((:,a(( }}q4==/++4==/++ ||G#OO))	OO--	WWsT]]**IId''(G 9;  	$MMSE##	$s   II65I6Tc           
      P   U R                   S:  a  SnSnOSnUS   nUS   US   US   USS.nS	U R                  R                   S
3nUS   R                  U R                  R                  U5      nU R                  R                   nU nU R                  R                  S:X  a  [        R
                  R                  n	O[        R
                  R                  n	[        R                  " U	U R                  SU R                   -  -   UU R                  U R                     UUUS9n
U
/$ )a@  Generate gate name.

Only operand name is shown.

Stylesheet:
    - `gate_name` style is applied.
    - `gate_latex_repr` key is used to find the latex representation of the gate name.

Args:
    gate: Gate information source.
    formatter: Dictionary of stylesheet settings.

Returns:
    List of `TextData` drawings.
r   r(   rI   rJ   rK   rL   rM   r)   rN   rO   rP   r   r!   r`   )r   r3   r   r9   r   re   r;   rf   r   r?   r   r   r>   )r   r   rg   rh   r'   ri   rj   rk   rl   r"   rB   s              rE   gen_short_gate_namerr   *  s.   $ }}q 56 -.,-/0F T\\../r2L/044T\\5F5FUJ\\&&'KLK ||G#OO))	OO--	WWsT]]**IId''(G 9    r%   c                    US   US   US   US   S.n[         R                  " [        R                  R                  [        R
                  R                  [        R
                  R                  /SUS   -  SUS   -  /U US	9nU/$ )
zGenerate time slot of associated bit.

Stylesheet:
    - `timeslot` style is applied.

Args:
    bit: Bit object associated to this drawing.
    formatter: Dictionary of stylesheet settings.

Returns:
    List of `BoxData` drawings.
zlayer.timeslotzalpha.timeslotzline_width.timeslotzcolor.timeslot)r   r   r   r   r    zbox_height.timeslotr!   r"   r#   r$   r%   r'   )r   r=   r   r:   TIMELINEAbstractCoordinateLEFTRIGHT)r%   r   r'   rB   s       rE   gen_timeslotrz   f  s     ,-+,45/0	F --(('',,e.F.F.L.LMi 566iH]>^8^_G 9rs   c           
      j   US   US   US   SSS.nUc5  [         R                  " SSS	9  [        U [        5      (       a  S
OSnSU S3nOUR	                  U 5      nUR
                  (       aP  UR
                  S   S   R                  nSUR
                  S   S   R                   SUR
                  S   S    S3nO,[        U [        5      (       a  S
OSnSU SUR                   S3n[        R                  " [        R                  R                  [        R                  R                  SU UUUS9nU/$ )a  Generate bit label.

Stylesheet:
    - `bit_name` style is applied.

Args:
    bit: Bit object associated to this drawing.
    formatter: Dictionary of stylesheet settings.
    program: Optional program that the bits are a part of.

Returns:
    List of `TextData` drawings.
zlayer.bit_namezcolor.bit_nameztext_size.bit_namer(   rightr)   z;bits cannot be accurately named without passing a 'program'   )
stacklevelqcrN   rO   r   z}_{rQ   r`   )warningswarn
isinstancer   rZ   	registersr   prefixr[   r   r?   r   re   BIT_NAMErw   rx   )r%   r   rG   r'   rk   rl   locrB   s           rE   gen_bit_namer     s?   & ,-+,./F S`ab'U33c}B/s#==--+A.33K#CMM"$5a$8$?$?#@cmmTVFWXYFZE[[]^K!+C!7!7#SK#K=cii[CK//**%%**G 9rs   barrierc                     US   US   US   US   US   S.n[         R                  " [        R                  R                  U R
                  U R
                  /SS/U R                  U R                     US	9nU/$ )
zGenerate barrier line.

Stylesheet:
    - `barrier` style is applied.

Args:
    barrier: Barrier instruction.
    formatter: Dictionary of stylesheet settings.

Returns:
    List of `LineData` drawings.
zalpha.barrierzlayer.barrierzline_width.barrierzline_style.barrierzcolor.barrierr   r   r   	linestyler*   r    r!   ru   )r   LineDatar   LineTypeBARRIERr   r   r>   )r   r   r'   rB   s       rE   gen_barrierr     s     ?+O,3434?+F ..((zz7::&SkLL--.G 9rs   linkc                     US   R                  U R                  US   5      nUS   US   US   US   US.n[        R                  " U R                  U R
                  US9nU/$ )	a4  Generate gate link line.

Line color depends on the operand type.

Stylesheet:
    - `gate_link` style is applied.
    - The `gate_face_color` style is applied for line color.

Args:
    link: Gate link object.
    formatter: Dictionary of stylesheet settings.

Returns:
    List of `GateLinkData` drawings.
r   r   zalpha.gate_linkzlayer.gate_linkzline_width.gate_linkzline_style.gate_linkr   )r   r.   r'   )r9   opnamer   GateLinkDatar   r   )r   r   r*   r'   rB   s        rE   gen_gate_linkr     s{    $ m$((i@T6UVE ,--.5656F ##PG9rs   rY   )!__doc__r   typingr   r   r   r   r   qiskit.circuitr   r	   qiskit.circuit.exceptionsr
   qiskit.visualization.timeliner   r   ScheduledGater2   r?   r=   rF   rp   accepts_programrr   Bitsrz   r   Barrierr   r   GateLinkr   r    rs   rE   <module>r      s  Zx  3 3 0 2 9Y


YCH~Y 
%!!8#3#33
45Yz _cW


W*.sCx.WCKNC[W	(

Wt &*  "9


9*.sCx.9	(

9xejj T#s(^ XEUEU@V D )-1	1CH~1 n%1 
(

	1h  $  4S> d8K\K\F] @ 4S> d8K`K`Fa rs   