§
    º³ÙgB%  ã                  óÖ   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	Z
ddlmZ ddlmZ dd	lmZ  G d
„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )av	  
Drawing objects for pulse drawer.

Drawing objects play two important roles:
    - Allowing unittests of visualization module. Usually it is hard for image files to be tested.
    - Removing program parser from each plotter interface. We can easily add new plotter.

This module is based on the structure of matplotlib as it is the primary plotter
of the pulse drawer. However this interface is agnostic to the actual plotter.

Design concept
~~~~~~~~~~~~~~
When we think about dynamically updating drawings, it will be most efficient to
update only the changed properties of drawings rather than regenerating entirely from scratch.
Thus the core :py:class:`qiskit.visualization.pulse_v2.core.DrawerCanvas` generates
all possible drawings in the beginning and then the canvas instance manages
visibility of each drawing according to the end-user request.

Data key
~~~~~~~~
In the abstract class ``ElementaryData`` common attributes to represent a drawing are
specified. In addition, drawings have the `data_key` property that returns an
unique hash of the object for comparison.
This key is generated from a data type and the location of the drawing in the canvas.
See py:mod:`qiskit.visualization.pulse_v2.types` for detail on the data type.
If a data key cannot distinguish two independent objects, you need to add a new data type.
The data key may be used in the plotter interface to identify the object.

Drawing objects
~~~~~~~~~~~~~~~
To support not only `matplotlib` but also multiple plotters, those drawings should be
universal and designed without strong dependency on modules in `matplotlib`.
This means drawings that represent primitive geometries are preferred.
It should be noted that there will be no unittest for each plotter API, which takes
drawings and outputs image data, we should avoid adding a complicated geometry
that has a context of the pulse program.

For example, a pulse envelope is complex valued number array and may be represented
by two lines with different colors associated with the real and the imaginary component.
We can use two line-type objects rather than defining a new drawing that takes
complex value. As many plotters don't support an API that visualizes complex-valued
data arrays, if we introduced such a drawing and wrote a custom wrapper function
on top of the existing API, it could be difficult to prevent bugs with the CI tools
due to lack of the effective unittest.
é    )Úannotations)ÚABC)ÚEnum)ÚAnyN)ÚChannel)Útypes)ÚVisualizationErrorc                  óJ   — e Zd ZdZdZ	 	 	 	 ddd„Zed„ ¦   «         Zd„ Zd„ Z	dS )ÚElementaryDataz0Base class of the pulse visualization interface.NFÚ	data_typeú
str | EnumÚxvalsú
np.ndarrayÚyvalsÚchannelsúChannel | list[Channel] | NoneÚmetaúdict[str, Any] | NoneÚignore_scalingÚboolÚstylesc                ó^  — |rt          |t          ¦  «        r|g}t          |t          ¦  «        r|j        }t	          |¦  «        | _        t          j        |t          ¬¦  «        | _	        t          j        |t          ¬¦  «        | _
        |pg | _        |pi | _        || _        |pi | _        dS )a  Create new drawing.

        Args:
            data_type: String representation of this drawing.
            xvals: Series of horizontal coordinate that the object is drawn.
            yvals: Series of vertical coordinate that the object is drawn.
            channels: Pulse channel object bound to this drawing.
            meta: Meta data dictionary of the object.
            ignore_scaling: Set ``True`` to disable scaling.
            styles: Style keyword args of the object. This conforms to `matplotlib`.
        )ÚdtypeN)Ú
isinstancer   r   ÚvalueÚstrr   ÚnpÚarrayÚobjectr   r   r   r   r   r   )Úselfr   r   r   r   r   r   r   s           ú\/granary/edev/quantum/lib/python3.11/site-packages/qiskit/visualization/pulse_v2/drawings.pyÚ__init__zElementaryData.__init__L   s£   € ð* ð 	"�
 8­WÑ5Ô5ð 	"Ø �zˆHå�i¥Ñ&Ô&ð 	(Ø!œˆIå˜Y™œˆŒÝ”X˜e­6Ð2Ñ2Ô2ˆŒ
Ý”X˜e­6Ð2Ñ2Ô2ˆŒ
Ø'/ ~°2ˆŒØ�J˜BˆŒ	Ø,ˆÔØ�l ˆŒˆˆó    c           
     ó¨   — t          t          | j        j        | j        t          | j        ¦  «        t          | j        ¦  «        f¦  «        ¦  «        S )z"Return unique hash of this object.)r   ÚhashÚ	__class__Ú__name__r   Útupler   r   ©r    s    r!   Údata_keyzElementaryData.data_keyo   sG   € õ Ý�$”.Ô)¨4¬>½5ÀÄÑ;LÔ;LÍeÐTXÔT^ÑN_ÔN_Ð`ÑaÔañ
ô 
ð 	
r#   c                ó@   — | j         j        › d| j        › d| j        › d�S )Nz(type=z, key=ú))r&   r'   r   r*   r)   s    r!   Ú__repr__zElementaryData.__repr__v   s*   € Ø”.Ô)ÐWÐW°´ÐWÐWÀtÄ}ÐWÐWÐWÐWr#   c                óL   — t          || j        ¦  «        o| j        |j        k    S )N)r   r&   r*   )r    Úothers     r!   Ú__eq__zElementaryData.__eq__y   s"   € Ý˜% ¤Ñ0Ô0ÐT°T´]ÀeÄnÒ5TÐTr#   ©NNFN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
r'   Ú
__module__Ú__qualname__Ú__doc__Ú__hash__r"   Úpropertyr*   r-   r0   © r#   r!   r   r   G   sˆ   € € € € € Ø:Ð:à€Hð 48Ø&*Ø$Ø(,ð!#ð !#ð !#ð !#ð !#ðF ð
ð 
ñ „Xð
ðXð Xð XðUð Uð Uð Uð Ur#   r   c                  ó0   ‡ — e Zd ZdZ	 	 	 	 	 ddˆ fd„Zˆ xZS )ÚLineDataztDrawing object to represent object appears as a line.

    This is the counterpart of `matplotlib.pyplot.plot`.
    FNr   r   r   ú#np.ndarray | list[types.Coordinate]r   Úfillr   r   r   r   r   r   r   c	           	     óf   •— || _         t          ¦   «                              |||||||¬¦  «         dS )aH  Create new drawing.

        Args:
            data_type: String representation of this drawing.
            channels: Pulse channel object bound to this drawing.
            xvals: Series of horizontal coordinate that the object is drawn.
            yvals: Series of vertical coordinate that the object is drawn.
            fill: Set ``True`` to fill the area under curve.
            meta: Meta data dictionary of the object.
            ignore_scaling: Set ``True`` to disable scaling.
            styles: Style keyword args of the object. This conforms to `matplotlib`.
        ©r   r   r   r   r   r   r   N)r;   Úsuperr"   )
r    r   r   r   r;   r   r   r   r   r&   s
            €r!   r"   zLineData.__init__ƒ   sL   ø€ ð. ˆŒ	å‰Œ×ÒØØØØØØ)Øð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r#   )FNNFN)r   r   r   r:   r   r:   r;   r   r   r   r   r   r   r   r   r   ©r'   r2   r3   r4   r"   Ú__classcell__©r&   s   @r!   r9   r9   }   s]   ø€ € € € € ðð ð Ø37Ø&*Ø$Ø(,ð!
ð !
ð !
ð !
ð !
ð !
ð !
ð !
ð !
ð !
ð !
r#   r9   c                  ó0   ‡ — e Zd ZdZ	 	 	 	 	 ddˆ fd„Zˆ xZS )ÚTextDataztDrawing object to represent object appears as a text.

    This is the counterpart of `matplotlib.pyplot.text`.
    NFr   r   r   r:   r   Útextr   Úlatexú
str | Noner   r   r   r   r   r   r   c
           	     óx   •— || _         |pd| _        t          ¦   «                              |||||||	¬¦  «         dS )a”  Create new drawing.

        Args:
            data_type: String representation of this drawing.
            channels: Pulse channel object bound to this drawing.
            xvals: Series of horizontal coordinate that the object is drawn.
            yvals: Series of vertical coordinate that the object is drawn.
            text: String to show in the canvas.
            latex: Latex representation of the text (if backend supports latex drawing).
            meta: Meta data dictionary of the object.
            ignore_scaling: Set ``True`` to disable scaling.
            styles: Style keyword args of the object. This conforms to `matplotlib`.
        Ú r=   N)rD   rE   r>   r"   )r    r   r   r   rD   rE   r   r   r   r   r&   s             €r!   r"   zTextData.__init__­   sW   ø€ ð2 ˆŒ	Ø�[˜bˆŒ
å‰Œ×ÒØØØØØØ)Øð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r#   )NNNFN)r   r   r   r:   r   r:   rD   r   rE   rF   r   r   r   r   r   r   r   r   r?   rA   s   @r!   rC   rC   §   s]   ø€ € € € € ðð ð !Ø37Ø&*Ø$Ø(,ð$
ð $
ð $
ð $
ð $
ð $
ð $
ð $
ð $
ð $
ð $
r#   rC   c                  ó.   ‡ — e Zd ZdZ	 	 	 	 ddˆ fd„Zˆ xZS )ÚBoxDataznDrawing object that represents box shape.

    This is the counterpart of `matplotlib.patches.Rectangle`.
    NFr   r   r   r:   r   r   r   r   r   r   r   r   c           	     óÂ   •— t          |¦  «        dk    st          |¦  «        dk    rt          d¦  «        ‚t          ¦   «                              |||||||¬¦  «         dS )a^  Create new box.

        Args:
            data_type: String representation of this drawing.
            xvals: Left and right coordinate that the object is drawn.
            yvals: Top and bottom coordinate that the object is drawn.
            channels: Pulse channel object bound to this drawing.
            meta: Meta data dictionary of the object.
            ignore_scaling: Set ``True`` to disable scaling.
            styles: Style keyword args of the object. This conforms to `matplotlib`.

        Raises:
            VisualizationError: When number of data points are not equals to 2.
        é   z*Length of data points are not equals to 2.r=   N)Úlenr	   r>   r"   )	r    r   r   r   r   r   r   r   r&   s	           €r!   r"   zBoxData.__init__Ú   sq   ø€ õ0 ˆu‰:Œ:˜Š?ˆ?�c %™jœj¨Ašo˜oÝ$Ð%QÑRÔRÐRå‰Œ×ÒØØØØØØ)Øð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r#   r1   )r   r   r   r:   r   r:   r   r   r   r   r   r   r   r   r?   rA   s   @r!   rJ   rJ   Ô   sZ   ø€ € € € € ðð ð 48Ø&*Ø$Ø(,ð#
ð #
ð #
ð #
ð #
ð #
ð #
ð #
ð #
ð #
ð #
r#   rJ   )r4   Ú
__future__r   Úabcr   Úenumr   Útypingr   Únumpyr   Úqiskit.pulse.channelsr   Úqiskit.visualization.pulse_v2r   Úqiskit.visualization.exceptionsr	   r   r9   rC   rJ   r7   r#   r!   ú<module>rV      sY  ðð,ð ,ðZ #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð à )Ð )Ð )Ð )Ð )Ð )Ø /Ð /Ð /Ð /Ð /Ð /Ø >Ð >Ð >Ð >Ð >Ð >ð3Uð 3Uð 3Uð 3Uð 3U�Sñ 3Uô 3Uð 3Uðl'
ð '
ð '
ð '
ð '
ˆ~ñ '
ô '
ð '
ðT*
ð *
ð *
ð *
ð *
ˆ~ñ *
ô *
ð *
ðZ)
ð )
ð )
ð )
ð )
ˆnñ )
ô )
ð )
ð )
ð )
r#   