§
    º³Ùgð ã                  ój  — d Z ddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZ ddlmZmZmZmZmZmZ ddlZddlZddlmZ ddlmZ ddlmZmZ dd	l m!Z! dd
l"m#Z#m$Z$ ddl%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ee2e2f         Z3	 ee!ee3         f         Z4	  G d„ d¦  «        Z5dJd„Z6 G d„ d¦  «        Z7d„ Z8 e/ddd¬¦  «         e8e5e7¦  «        	 	 	 	 	 	 	 	 	 	 	 	 dKdLd2„¦   «         ¦   «         Z9dMd8„Z:dNdOd:„Z;dPd<„Z<dQd?„Z=dRdB„Z>dSdE„Z?dTdI„Z@ee5e&f         ZA	 ee7e&f         ZBdS )Uaä  
=========
Schedules
=========

.. currentmodule:: qiskit.pulse

Schedules are Pulse programs. They describe instruction sequences for the control hardware.
The Schedule is one of the most fundamental objects to this pulse-level programming module.
A ``Schedule`` is a representation of a *program* in Pulse. Each schedule tracks the time of each
instruction occuring in parallel over multiple signal *channels*.

.. autosummary::
   :toctree: ../stubs/

   Schedule
   ScheduleBlock
é    )ÚannotationsN)ÚCallableÚIterable)ÚListÚTupleÚUnionÚDictÚAnyÚSequence)ÚParameterVector)Ú	Parameter)ÚParameterExpressionÚParameterValueType)ÚChannel)Ú
PulseErrorÚUnassignedReferenceError)ÚInstructionÚ	Reference)Úinstruction_duration_validation)ÚReferenceManager)Úis_main_process)Údeprecate_arg)Údeprecate_pulse_funcc                  óŒ  — e Zd ZdZdZ ej        ¦   «         Zedddœd^d„¦   «         Z	e
d_d`d„¦   «         Zedad„¦   «         Zedbd„¦   «         Zej        d„ ¦   «         Zedcd„¦   «         Zeddd„¦   «         Zeddd„¦   «         Zeddd„¦   «         Zeded„¦   «         Zedfd„¦   «         Zedgd!„¦   «         Zedhd#„¦   «         Zdid&„Zdid'„Zdid(„Zdjdkd+„Zdldmd/„Zd_dnd0„Zdod1„Z	 	 dldpd5„Zdqd6„Z 	 d_drd7„Z!	 dldsd8„Z"ddddd9d:œdtdE„Z#ddddd9d:œdtdF„Z$dudH„Z%dvdI„Z&dwdL„Z'dM„ Z(	 dxdydN„Z)dzdO„Z*	 d{d|dR„Z+d}dU„Z,dddV„Z-d~dX„Z.d~dY„Z/dodZ„Z0dd\„Z1dad]„Z2dS )€ÚSchedulea3  A quantum program *schedule* with exact time constraints for its instructions, operating
    over all input signal *channels* and supporting special syntaxes for building.

    Pulse program representation for the original Qiskit Pulse model [1].
    Instructions are not allowed to overlap in time
    on the same channel. This overlap constraint is immediately
    evaluated when a new instruction is added to the ``Schedule`` object.

    It is necessary to specify the absolute start time and duration
    for each instruction so as to deterministically fix its execution time.

    The ``Schedule`` program supports some syntax sugar for easier programming.

    - Appending an instruction to the end of a channel

      .. code-block:: python

          from qiskit.pulse import Schedule, Gaussian, DriveChannel, Play
          sched = Schedule()
          sched += Play(Gaussian(160, 0.1, 40), DriveChannel(0))

    - Appending an instruction shifted in time by a given amount

      .. code-block:: python

          sched = Schedule()
          sched += Play(Gaussian(160, 0.1, 40), DriveChannel(0)) << 30

    - Merge two schedules

      .. code-block:: python

          sched1 = Schedule()
          sched1 += Play(Gaussian(160, 0.1, 40), DriveChannel(0))

          sched2 = Schedule()
          sched2 += Play(Gaussian(160, 0.1, 40), DriveChannel(1))
          sched2 = sched1 | sched2

    A :obj:`.PulseError` is immediately raised when the overlap constraint is violated.

    In the schedule representation, we cannot parametrize the duration of instructions.
    Thus, we need to create a new schedule object for each duration.
    To parametrize an instruction's duration, the :class:`~qiskit.pulse.ScheduleBlock`
    representation may be used instead.

    References:
        [1]: https://arxiv.org/abs/2004.06755

    ÚschedN©ÚnameÚmetadataÚ	schedulesú5'ScheduleComponent' | tuple[int, 'ScheduleComponent']r   ú
str | Noner   údict | Nonec               ó   — ddl m} |€e| j        t          t	          | j        ¦  «        ¦  «        z   }t          j        dk    r,t          ¦   «         s|dt          j
        ¦   «         j        › �z  }|| _         |¦   «         | _        t          |t          ¦  «        s|�t!          d¦  «        ‚|pi | _        d| _        i | _        g | _        |D ]3}	 |\  }}n# t           $ r d|}}Y nw xY w|                      ||¦  «         Œ4dS )a   Create an empty schedule.

        Args:
            *schedules: Child Schedules of this parent Schedule. May either be passed as
                        the list of schedules, or a list of ``(start_time, schedule)`` pairs.
            name: Name of this schedule. Defaults to an autogenerated string if not provided.
            metadata: Arbitrary key value metadata to associate with the schedule. This gets
                stored as free-form data in a dict in the
                :attr:`~qiskit.pulse.Schedule.metadata` attribute. It will not be directly
                used in the schedule.
        Raises:
            TypeError: if metadata is not a dict.
        r   ©ÚParameterManagerNÚwin32ú-ú;Only a dictionary or None is accepted for schedule metadata)Úqiskit.pulse.parameter_managerr&   ÚprefixÚstrÚnextÚinstances_counterÚsysÚplatformr   ÚmpÚcurrent_processÚpidÚ_nameÚ_parameter_managerÚ
isinstanceÚdictÚ	TypeErrorÚ	_metadataÚ	_durationÚ
_timeslotsÚ	_childrenÚ_mutable_insert)Úselfr   r   r    r&   Ú
sched_pairÚtimer   s           úK/granary/edev/quantum/lib/python3.11/site-packages/qiskit/pulse/schedule.pyÚ__init__zSchedule.__init__}   s?  € ð( 	DÐCÐCÐCÐCÐCàˆ<Ø”;¥¥T¨$Ô*@Ñ%AÔ%AÑ!BÔ!BÑBˆDÝŒ|˜wÒ&Ð&­Ñ/@Ô/@Ð&ØÐ6�BÔ.Ñ0Ô0Ô4Ð6Ð6Ñ6�àˆŒ
Ø"2Ð"2Ñ"4Ô"4ˆÔå˜(¥DÑ)Ô)ð 	[¨hÐ.BÝÐYÑZÔZÐZØ!˜ RˆŒàˆŒð &(ˆŒØ@BˆŒØ#ð 	.ð 	.ˆJð,Ø(‘��e�eøÝð ,ð ,ð ,à �e���ð,øøøð × Ò   uÑ-Ô-Ð-Ð-ð	.ð 	.s   ÃCÃC$Ã#C$Úother_programr
   Úreturnú
'Schedule'c                óä   — 	 |p|j         }|j        r|j                             ¦   «         }nd} | ||¬¦  «        S # t          $ r*}t	          | j        › d|j        j        › d�¦  «        |‚d}~ww xY w)a­  Create new schedule object with metadata of another schedule object.

        Args:
            other_program: Qiskit program that provides metadata to new object.
            name: Name of new schedule. Name of ``schedule`` is used by default.

        Returns:
            New schedule object with name and metadata.

        Raises:
            PulseError: When `other_program` does not provide necessary information.
        Nr   ú- cannot be initialized from the program data ú.)r   r   ÚcopyÚAttributeErrorr   Ú__name__Ú	__class__)ÚclsrC   r   r   Úexs        rA   Úinitialize_fromzSchedule.initialize_from¬   s¬   € ð	ØÐ-˜=Ô-ˆDàÔ%ð  Ø(Ô1×6Ò6Ñ8Ô8��à�à�3˜D¨8Ð4Ñ4Ô4Ð4øÝð 	ð 	ð 	ÝØ”<ð 7ð 7Ø Ô*Ô3ð7ð 7ð 7ñô ð ðøøøøð	øøøs   ‚8; »
A/Á%A*Á*A/r,   c                ó   — | j         S )zName of this Schedule©r4   ©r>   s    rA   r   zSchedule.nameÉ   ó   € ð ŒzÐó    údict[str, Any]c                ó   — | j         S ©aÝ  The user provided metadata associated with the schedule.

        User provided ``dict`` of metadata for the schedule.
        The metadata contents do not affect the semantics of the program
        but are used to influence the execution of the schedule. It is expected
        to be passed between all transforms of the schedule and that providers
        will associate any schedule metadata with the results it returns from the
        execution of that schedule.
        ©r9   rR   s    rA   r   zSchedule.metadataÎ   ó   € ð Œ~ÐrT   c                ód   — t          |t          ¦  «        s|�t          d¦  «        ‚|pi | _        dS ©zUpdate the schedule metadataNr)   ©r6   r7   r8   r9   ©r>   r   s     rA   r   zSchedule.metadataÛ   ó:   € õ ˜(¥DÑ)Ô)ð 	[¨hÐ.BÝÐYÑZÔZÐZØ!˜ RˆŒˆˆrT   Ú	TimeSlotsc                ó   — | j         S )zTime keeping attribute.©r;   rR   s    rA   Ú	timeslotszSchedule.timeslotsâ   s   € ð ŒÐrT   Úintc                ó   — | j         S )zDuration of this schedule.)r:   rR   s    rA   ÚdurationzSchedule.durationç   s   € ð Œ~ÐrT   c                ó    —  | j         | j        Ž S )zStarting time of this schedule.)Úch_start_timeÚchannelsrR   s    rA   Ú
start_timezSchedule.start_timeì   s   € ð "ˆtÔ! 4¤=Ð1Ð1rT   c                ó   — | j         S )zStopping time of this schedule.©re   rR   s    rA   Ú	stop_timezSchedule.stop_timeñ   s   € ð Œ}ÐrT   útuple[Channel, ...]c                óN   — t          | j                             ¦   «         ¦  «        S )z)Returns channels that this schedule uses.)Útupler;   ÚkeysrR   s    rA   rh   zSchedule.channelsö   s    € õ �T”_×)Ò)Ñ+Ô+Ñ,Ô,Ð,rT   ú+tuple[tuple[int, 'ScheduleComponent'], ...]c                ó*   — t          | j        ¦  «        S )aÖ  Return the child schedule components of this ``Schedule`` in the
        order they were added to the schedule.

        Notes:
            Nested schedules are returned as-is. If you want to collect only instructions,
            use :py:meth:`~Schedule.instructions` instead.

        Returns:
            A tuple, where each element is a two-tuple containing the initial
            scheduled time of each ``NamedValue`` and the component
            itself.
        )ro   r<   rR   s    rA   ÚchildrenzSchedule.childrenû   s   € õ �T”^Ñ$Ô$Ð$rT   ú#tuple[tuple[int, Instruction], ...]c                óh   — d„ }t          t          |                      ¦   «         |¬¦  «        ¦  «        S )ú,Get the time-ordered instructions from self.c                ój   — | d         }| d         |j         t          d„ |j        D ¦   «         ¦  «        fS )Né   r   c              3  ó$   K  — | ]}|j         V — Œd S ©N©r   )Ú.0Úchans     rA   ú	<genexpr>z5Schedule.instructions.<locals>.key.<locals>.<genexpr>  s$   è è € Ð;`Ð;`È$¸D¼IÐ;`Ð;`Ð;`Ð;`Ð;`Ð;`rT   )re   Úsortedrh   )Útime_inst_pairÚinsts     rA   Úkeyz"Schedule.instructions.<locals>.key  s;   € Ø! !Ô$ˆDØ! !Ô$ d¤mµVÐ;`Ð;`ÐRVÔR_Ð;`Ñ;`Ô;`Ñ5`Ô5`Ð`Ð`rT   )r‚   )ro   r   Ú_instructions)r>   r‚   s     rA   ÚinstructionszSchedule.instructions  s=   € ð	að 	að 	aõ •V˜D×.Ò.Ñ0Ô0°cÐ:Ñ:Ô:Ñ;Ô;Ð;rT   úset[Parameter]c                ó   — | j         j        S )z1Parameters which determine the schedule behavior.)r5   Ú
parametersrR   s    rA   r‡   zSchedule.parameters  s   € ð Ô&Ô1Ð1rT   rh   r   c                ó   —  | j         |Ž S ©z¢Return the time of the end of the last instruction over the supplied channels.

        Args:
            *channels: Channels within ``self`` to include.
        )Úch_stop_time©r>   rh   s     rA   Úch_durationzSchedule.ch_duration  s   € ð !ˆtÔ  (Ð+Ð+rT   c                óv   ‡ — 	 ˆ fd„|D ¦   «         }t          d„ |D ¦   «         ¦  «        S # t          $ r Y dS w xY w)z¥Return the time of the start of the first instruction over the supplied channels.

        Args:
            *channels: Channels within ``self`` to include.
        c              3  óD   •K  — | ]}|‰j         v ¯‰j         |         V — Œd S rz   ra   ©r|   r}   r>   s     €rA   r~   z)Schedule.ch_start_time.<locals>.<genexpr>)  ó8   øè è € ÐdÐd¸ÈDÐTXÔTcÐLcÐLc˜dœo¨dÔ3ÐLcÐLcÐLcÐLcÐdÐdrT   c              3  ó2   K  — | ]}|d          d          V — ŒdS )r   N© ©r|   Ú	intervalss     rA   r~   z)Schedule.ch_start_time.<locals>.<genexpr>*  s*   è è € ÐGÐG¨9�y ”| A”ÐGÐGÐGÐGÐGÐGrT   r   )ÚminÚ
ValueError©r>   rh   Úchan_intervalss   `  rA   rg   zSchedule.ch_start_time"  s`   ø€ ð	ØdÐdÐdÐdÀÐdÑdÔdˆNÝÐGÐG¸ÐGÑGÔGÑGÔGÐGøÝð 	ð 	ð 	à�1�1ð	øøøó   ƒ&* ª
8·8c                óv   ‡ — 	 ˆ fd„|D ¦   «         }t          d„ |D ¦   «         ¦  «        S # t          $ r Y dS w xY w)z…Return maximum start time over supplied channels.

        Args:
            *channels: Channels within ``self`` to include.
        c              3  óD   •K  — | ]}|‰j         v ¯‰j         |         V — Œd S rz   ra   r�   s     €rA   r~   z(Schedule.ch_stop_time.<locals>.<genexpr>6  r�   rT   c              3  ó2   K  — | ]}|d          d         V — ŒdS )éÿÿÿÿrx   Nr’   r“   s     rA   r~   z(Schedule.ch_stop_time.<locals>.<genexpr>7  s+   è è € ÐHÐH¨I�y ”} QÔ'ÐHÐHÐHÐHÐHÐHrT   r   )Úmaxr–   r—   s   `  rA   rŠ   zSchedule.ch_stop_time/  s`   ø€ ð	ØdÐdÐdÐdÀÐdÑdÔdˆNÝÐHÐH¸ÐHÑHÔHÑHÔHÐHøÝð 	ð 	ð 	à�1�1ð	øøør™   r   r@   c              #  ó`   K  — | j         D ]#\  }}|                     ||z   ¦  «        E d{V —† Œ$dS )aP  Iterable for flattening Schedule tree.

        Args:
            time: Shifted time due to parent.

        Yields:
            Iterable[Tuple[int, Instruction]]: Tuple containing the time each
                :class:`~qiskit.pulse.Instruction`
                starts at and the flattened :class:`~qiskit.pulse.Instruction` s.
        N)rs   rƒ   )r>   r@   Úinsert_timeÚchild_scheds       rA   rƒ   zSchedule._instructions<  sZ   è è € ð )-¬ð 	Eð 	EÑ$ˆK˜Ø"×0Ò0°¸Ñ1CÑDÔDÐDÐDÐDÐDÐDÐDÐDÐDð	Eð 	ErT   FÚinplaceÚboolc                ó^   — |r|                       |¦  «        S |                      ||¬¦  «        S )a*  Return a schedule shifted forward by ``time``.

        Args:
            time: Time to shift by.
            name: Name of the new schedule. Defaults to the name of self.
            inplace: Perform operation inplace on this schedule. Otherwise
                return a new ``Schedule``.
        r{   )Ú_mutable_shiftÚ_immutable_shift)r>   r@   r   r¢   s       rA   ÚshiftzSchedule.shiftJ  s9   € ð ð 	-Ø×&Ò& tÑ,Ô,Ð,Ø×$Ò$ T°Ð$Ñ5Ô5Ð5rT   c                ól   — t                                | |¦  «        }|                     || d¬¦  «         |S )zÄReturn a new schedule shifted forward by `time`.

        Args:
            time: Time to shift by
            name: Name of the new schedule if call was mutable. Defaults to name of self
        T©r¢   )r   rO   Úinsert)r>   r@   r   Úshift_scheds       rA   r¦   zSchedule._immutable_shiftW  s:   € õ ×.Ò.¨t°TÑ:Ô:ˆØ×Ò˜4 ¨tÐÑ4Ô4Ð4àÐrT   c                ó.  ‡— t          ‰t          ¦  «        st          d¦  «        ‚i }| j                             ¦   «         D ]\  }}ˆfd„|D ¦   «         ||<   Œt          |¦  «         | j        ‰z   | _        || _        ˆfd„| j        D ¦   «         | _        | S )z²Return this schedule shifted forward by `time`.

        Args:
            time: Time to shift by

        Raises:
            PulseError: if ``time`` is not an integer.
        ú'Schedule start time must be an integer.c                ó<   •— g | ]}|d          ‰z   |d         ‰z   f‘ŒS ©r   rx   r’   )r|   Útsr@   s     €rA   ú
<listcomp>z+Schedule._mutable_shift.<locals>.<listcomp>q  s.   ø€ ÐSÐSÐSÀ  1¤¨¡¨b°¬e°d©lÐ;ÐSÐSÐSrT   c                ó$   •— g | ]\  }}|‰z   |f‘ŒS r’   r’   )r|   Ú	orig_timeÚchildr@   s      €rA   r±   z+Schedule._mutable_shift.<locals>.<listcomp>w  s(   ø€ ÐZÐZÐZÑ8H¸	À5˜9 tÑ+¨UÐ3ÐZÐZÐZrT   )	r6   rc   r   r;   ÚitemsÚ_check_nonnegative_timeslotr:   rs   r<   )r>   r@   rb   r}   Úch_timeslotss    `   rA   r¥   zSchedule._mutable_shiftc  s´   ø€ õ ˜$¥Ñ$Ô$ð 	HÝÐFÑGÔGÐGàˆ	Ø"&¤/×"7Ò"7Ñ"9Ô"9ð 	Tð 	TÑˆD�,ØSÐSÐSÐSÀlÐSÑSÔSˆI�d‰OˆOå# IÑ.Ô.Ð.àœ¨$Ñ.ˆŒØ#ˆŒØZÐZÐZÐZÈDÌMÐZÑZÔZˆŒØˆrT   ri   Úscheduleú'ScheduleComponent'c                ób   — |r|                       ||¦  «        S |                      |||¬¦  «        S )aˆ  Return a new schedule with ``schedule`` inserted into ``self`` at ``start_time``.

        Args:
            start_time: Time to insert the schedule.
            schedule: Schedule to insert.
            name: Name of the new schedule. Defaults to the name of self.
            inplace: Perform operation inplace on this schedule. Otherwise
                return a new ``Schedule``.
        r{   )r=   Ú_immutable_insert)r>   ri   r¸   r   r¢   s        rA   rª   zSchedule.insertz  s=   € ð  ð 	>Ø×'Ò'¨
°HÑ=Ô=Ð=Ø×%Ò% j°(ÀÐ%ÑFÔFÐFrT   c                óž   — |                       ||¦  «         | j                             ||f¦  «         | j                             |¦  «         | S )z¼Mutably insert `schedule` into `self` at `start_time`.

        Args:
            start_time: Time to insert the second schedule.
            schedule: Schedule to mutably insert.
        )Ú_add_timeslotsr<   Úappendr5   Úupdate_parameter_table)r>   ri   r¸   s      rA   r=   zSchedule._mutable_insertŽ  sQ   € ð 	×Ò˜J¨Ñ1Ô1Ð1ØŒ×Ò˜z¨8Ð4Ñ5Ô5Ð5ØÔ×6Ò6°xÑ@Ô@Ð@ØˆrT   c                ó”   — t                                | |¦  «        }|                     d| ¦  «         |                     ||¦  «         |S )a  Return a new schedule with ``schedule`` inserted into ``self`` at ``start_time``.
        Args:
            start_time: Time to insert the schedule.
            schedule: Schedule to insert.
            name: Name of the new ``Schedule``. Defaults to name of ``self``.
        r   )r   rO   r=   )r>   ri   r¸   r   Ú	new_scheds        rA   r»   zSchedule._immutable_insertš  sK   € õ ×,Ò,¨T°4Ñ8Ô8ˆ	Ø×!Ò! ! TÑ*Ô*Ð*Ø×!Ò! *¨hÑ7Ô7Ð7ØÐrT   c                óš   — t          | j        ¦  «        t          |j        ¦  «        z  } | j        |Ž }|                      ||||¬¦  «        S )a1  Return a new schedule with ``schedule`` inserted at the maximum time over
        all channels shared between ``self`` and ``schedule``.

        .. math::

            t = \textrm{max}(\texttt{x.stop_time} |\texttt{x} \in
                \texttt{self.channels} \cap \texttt{schedule.channels})

        Args:
            schedule: Schedule to be appended.
            name: Name of the new ``Schedule``. Defaults to name of ``self``.
            inplace: Perform operation inplace on this schedule. Otherwise
                return a new ``Schedule``.
        )r   r¢   )Úsetrh   rŠ   rª   )r>   r¸   r   r¢   Úcommon_channelsr@   s         rA   r¾   zSchedule.append«  sL   € õ" ˜dœmÑ,Ô,­s°8Ô3DÑ/EÔ/EÑEˆØ ˆtÔ  /Ð2ˆØ�{Š{˜4 °¸gˆ{ÑFÔFÐFrT   T)rh   Úinstruction_typesÚtime_rangesr”   Úcheck_subroutineÚfilter_funcsr   úIterable[Channel] | NonerÅ   ú#Iterable[abc.ABCMeta] | abc.ABCMetarÆ   ú Iterable[tuple[int, int]] | Noner”   úIterable[Interval] | NonerÇ   c               óv   — ddl m}m}  |||||¦  «        }	|	                     |¦  «          || |	d|¬¦  «        S )a¯  Return a new ``Schedule`` with only the instructions from this ``Schedule`` which pass
        though the provided filters; i.e. an instruction will be retained iff every function in
        ``filter_funcs`` returns ``True``, the instruction occurs on a channel type contained in
        ``channels``, the instruction type is contained in ``instruction_types``, and the period
        over which the instruction operates is *fully* contained in one specified in
        ``time_ranges`` or ``intervals``.

        If no arguments are provided, ``self`` is returned.

        Args:
            filter_funcs: A list of Callables which take a (int, Union['Schedule', Instruction])
                tuple and return a bool.
            channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``.
            instruction_types: For example, ``[PulseInstruction, AcquireInstruction]``.
            time_ranges: For example, ``[(0, 5), (6, 10)]``.
            intervals: For example, ``[(0, 5), (6, 10)]``.
            check_subroutine: Set `True` to individually filter instructions inside of a subroutine
                defined by the :py:class:`~qiskit.pulse.instructions.Call` instruction.
        r   ©Úcomposite_filterÚfilter_instructionsF©ÚfiltersÚnegateÚrecurse_subroutines©Úqiskit.pulse.filtersrÏ   rÐ   Úextend©
r>   rh   rÅ   rÆ   r”   rÇ   rÈ   rÏ   rÐ   rÒ   s
             rA   ÚfilterzSchedule.filterÀ  sj   € ð8 	OÐNÐNÐNÐNÐNÐNÐNà"Ð" 8Ð->ÀÈYÑWÔWˆØ�Š�|Ñ$Ô$Ð$à"Ð"Ø˜'¨%ÐEUð
ñ 
ô 
ð 	
rT   c               óv   — ddl m}m}  |||||¦  «        }	|	                     |¦  «          || |	d|¬¦  «        S )a‚  Return a ``Schedule`` with only the instructions from this Schedule *failing*
        at least one of the provided filters.
        This method is the complement of :py:meth:`~Schedule.filter`, so that::

            self.filter(args) | self.exclude(args) == self

        Args:
            filter_funcs: A list of Callables which take a (int, Union['Schedule', Instruction])
                tuple and return a bool.
            channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``.
            instruction_types: For example, ``[PulseInstruction, AcquireInstruction]``.
            time_ranges: For example, ``[(0, 5), (6, 10)]``.
            intervals: For example, ``[(0, 5), (6, 10)]``.
            check_subroutine: Set `True` to individually filter instructions inside of a subroutine
                defined by the :py:class:`~qiskit.pulse.instructions.Call` instruction.
        r   rÎ   TrÑ   rÕ   rØ   s
             rA   ÚexcludezSchedule.excludeå  sj   € ð2 	OÐNÐNÐNÐNÐNÐNÐNà"Ð" 8Ð->ÀÈYÑWÔWˆØ�Š�|Ñ$Ô$Ð$à"Ð"Ø˜'¨$ÐDTð
ñ 
ô 
ð 	
rT   ÚNonec                óþ  ‡— t          j        t          ‰¦  «        t           j        ¦  «        st	          d¦  «        ‚t          |¦  «        }t          | j        ‰|j        z   ¦  «        | _        |j	        D �]r}|| j
        vrF‰dk    r#t          j        ||         ¦  «        | j
        |<   nˆfd„||         D ¦   «         | j
        |<   ŒRt          ||         ¦  «        D �]	\  }}|d         ‰z   | j
        |         d         d         k    r<| j
        |                              ˆfd„||         |d…         D ¦   «         ¦  «          n£	 |d         ‰z   |d         ‰z   f}t          | j
        |         |¦  «        }| j
        |                              ||¦  «         Œ¼# t          $ rB}t	          d|j        pd	› d
| j        pd	› d‰› d|› d|d         › d|d         › d�¦  «        |‚d}~ww xY w�Œtt#          | j
        ¦  «         dS )a;  Update all time tracking within this schedule based on the given schedule.

        Args:
            time: The time to insert the schedule into self.
            schedule: The schedule to insert into self.

        Raises:
            PulseError: If timeslots overlap or an invalid start time is provided.
        r­   r   c                ó<   •— g | ]}|d          ‰z   |d         ‰z   f‘ŒS r¯   r’   ©r|   Úir@   s     €rA   r±   z+Schedule._add_timeslots.<locals>.<listcomp>  s;   ø€ ð 0ð 0ð 0Ø78˜˜1œ ™ a¨¤d¨T¡kÐ2ð0ð 0ð 0rT   r�   rx   c                ó<   •— g | ]}|d          ‰z   |d         ‰z   f‘ŒS r¯   r’   rß   s     €rA   r±   z+Schedule._add_timeslots.<locals>.<listcomp>%  s.   ø€ Ð\Ð\Ð\¸˜!˜Aœ$ ™+ q¨¤t¨d¡{Ð3Ð\Ð\Ð\rT   NzSchedule(name='Ú z*') cannot be inserted into Schedule(name='z') at time z$ because its instruction on channel z scheduled from time z to z' overlaps with an existing instruction.)ÚnpÚ
issubdtypeÚtypeÚintegerr   Ú_get_timeslotsrž   r:   re   rh   r;   rI   Ú	enumerater×   Ú_find_insertion_indexrª   r   r¶   )	r>   r@   r¸   Úother_timeslotsÚchannelÚidxÚintervalÚindexrN   s	    `       rA   r½   zSchedule._add_timeslots  s�  ø€ õ Œ}�T $™ZœZ­¬Ñ4Ô4ð 	HÝÐFÑGÔGÐGå(¨Ñ2Ô2ˆÝ˜Tœ^¨T°HÔ4EÑ-EÑFÔFˆŒàÔ(ð 	ñ 	ˆGØ˜dœoÐ-Ð-Ø˜1’9�9Ý/3¬y¸ÈÔ9QÑ/RÔ/R�D”O GÑ,Ð,ð0ð 0ð 0ð 0Ø<KÈGÔ<Tð0ñ 0ô 0�D”O GÑ,ð å!*¨?¸7Ô+CÑ!DÔ!Dð ñ ‘��XØ˜A”; Ñ%¨¬¸Ô)AÀ"Ô)EÀaÔ)HÒHÐHà”O GÔ,×3Ò3Ø\Ð\Ð\Ð\¸_ÈWÔ=UÐVYÐVZÐVZÔ=[Ð\Ñ\Ô\ñô ð ð �Eð
Ø (¨¤¨dÑ 2°H¸Q´KÀ$Ñ4FÐG�HÝ1°$´/À'Ô2JÈHÑUÔU�EØ”O GÔ,×3Ò3°E¸8ÑDÔDÐDÐDøÝ!ð ð ð Ý$ða¨(¬-Ð*=¸2ð að aØ*.¬)¨/°rðað aà $ðað aàJQðað að $ Aœ;ðað að -5°Q¬Kðað að añô ð
 ðøøøøðøøøùõ 	$ D¤OÑ4Ô4Ð4Ð4Ð4s   ÅAFÆ
G$Æ"=GÇG$c                ó  — t          |t          ¦  «        st          d¦  «        ‚|j        D ]×}|| j        vrt          d|› d�¦  «        ‚| j        |         }t          |¦  «        }||         D ]x}|rH|d         |z   |d         |z   f}t          ||¦  «        }||         |k    r|                     |¦  «         ŒLt          d|d         › d|d         › d|› d	|j        › d
�	¦  «        ‚|s| j                             |¦  «         ŒØdS )aM  Delete the timeslots if present for the respective schedule component.

        Args:
            time: The time to remove the timeslots for the ``schedule`` component.
            schedule: The schedule to insert into self.

        Raises:
            PulseError: If timeslots overlap or an invalid start time is provided.
        r­   zThe channel z is not present in the scheduler   rx   zCannot find interval (ú, z) to remove from channel z in Schedule(name='z').N)	r6   rc   r   rh   r;   rç   Ú_interval_indexÚpopr   )r>   r@   r¸   rë   Úchannel_timeslotsrê   rí   rî   s           rA   Ú_remove_timeslotszSchedule._remove_timeslots7  su  € õ ˜$¥Ñ$Ô$ð 	HÝÐFÑGÔGÐGàÔ(ð 	-ð 	-ˆGà˜dœoÐ-Ð-Ý Ð!X°Ð!XÐ!XÐ!XÑYÔYÐYà $¤°Ô 8ÐÝ,¨XÑ6Ô6ˆOà+¨GÔ4ð ð �Ø$ð !Ø (¨¤¨dÑ 2°H¸Q´KÀ$Ñ4FÐG�HÝ+Ð,=¸xÑHÔH�EØ(¨Ô/°8Ò;Ð;Ø)×-Ò-¨eÑ4Ô4Ð4Ø å ðN¨X°a¬[ð Nð N¸HÀQ¼Kð Nð NØ&ðNð NØ;C¼=ðNð Nð Nñô ð ð
 %ð -Ø”×#Ò# GÑ,Ô,Ð,øð-	-ð 	-rT   ÚoldÚnewc                ó^   — |                       ||¦  «         |                      ||¦  «         dS )a  Replace the timeslots of ``old`` if present with the timeslots of ``new``.

        Args:
            time: The time to remove the timeslots for the ``schedule`` component.
            old: Instruction to replace.
            new: Instruction to replace with.
        N)rô   r½   )r>   r@   rõ   rö   s       rA   Ú_replace_timeslotszSchedule._replace_timeslots\  s6   € ð 	×Ò˜t SÑ)Ô)Ð)Ø×Ò˜D #Ñ&Ô&Ð&Ð&Ð&rT   c                ó~   — | j                              ¦   «          | j        D ]\  }}|                      ||¦  «         ŒdS )z3Regenerate timeslots based on current instructions.N)r;   Úclearr„   r½   )r>   Út0r�   s      rA   Ú_renew_timeslotszSchedule._renew_timeslotsg  sO   € àŒ×ÒÑÔÐØÔ)ð 	*ð 	*‰HˆB�Ø×Ò  DÑ)Ô)Ð)Ð)ð	*ð 	*rT   c                ó  — ddl m} g } |¦   «         }| j        D ]d\  }}||k    r-|                     ||f¦  «         |                     |¦  «         Œ8|                     ||f¦  «         |                     |¦  «         Œe|r$|| _        || _        |                      ¦   «          | S 	 t           	                    | ¦  «        }	|D ]\  }}
|	 
                    ||
d¬¦  «         Œ|	S # t          $ r}t          d|› d|› d�¦  «        |‚d}~ww xY w)	a9  Return a ``Schedule`` with the ``old`` instruction replaced with a ``new``
        instruction.

        The replacement matching is based on an instruction equality check.

        .. code-block::

            from qiskit import pulse

            d0 = pulse.DriveChannel(0)

            sched = pulse.Schedule()

            old = pulse.Play(pulse.Constant(100, 1.0), d0)
            new = pulse.Play(pulse.Constant(100, 0.1), d0)

            sched += old

            sched = sched.replace(old, new)

            assert sched == pulse.Schedule(new)

        Only matches at the top-level of the schedule tree. If you wish to
        perform this replacement over all instructions in the schedule tree.
        Flatten the schedule prior to running::

        .. code-block::

            sched = pulse.Schedule()

            sched += pulse.Schedule(old)

            sched = sched.replace(old, new)

            assert sched == pulse.Schedule(new)

        Args:
            old: Instruction to replace.
            new: Instruction to replace with.
            inplace: Replace instruction by mutably modifying this ``Schedule``.

        Returns:
            The modified schedule with ``old`` replaced by ``new``.

        Raises:
            PulseError: If the ``Schedule`` after replacements will has a timing overlap.
        r   r%   Tr©   zReplacement of z with z% results in overlapping instructions.N)r*   r&   rs   r¾   r¿   r<   r5   rü   r   rO   rª   r   )r>   rõ   rö   r¢   r&   Únew_childrenÚnew_parametersr@   r´   rÁ   r�   Úerrs               rA   ÚreplacezSchedule.replacem  sn  € ðj 	DÐCÐCÐCÐCÐCàˆØ)Ð)Ñ+Ô+ˆàœ=ð 	=ð 	=‰KˆD�%Ø˜Š|ˆ|Ø×#Ò# T¨3 KÑ0Ô0Ð0Ø×5Ò5°cÑ:Ô:Ð:Ð:à×#Ò# T¨5 MÑ2Ô2Ð2Ø×5Ò5°eÑ<Ô<Ð<Ð<àð 	Ø)ˆDŒNØ&4ˆDÔ#Ø×!Ò!Ñ#Ô#Ð#ØˆKðÝ$×4Ò4°TÑ:Ô:�	Ø".ð ?ð ?‘J�D˜$Ø×$Ò$ T¨4¸Ð$Ñ>Ô>Ð>Ð>Ø Ð øÝð ð ð Ý Ø[ cÐ[Ð[°Ð[Ð[Ð[ñô àðøøøøðøøøs   Â&;C" Ã"
DÃ,DÄDc                ó4   — | j                              ¦   «         S ©z1Return True iff the instruction is parameterized.)r5   Úis_parameterizedrR   s    rA   r  zSchedule.is_parameterized¿  s   € àÔ&×7Ò7Ñ9Ô9Ð9rT   Ú
value_dictúddict[ParameterExpression | ParameterVector | str, ParameterValueType | Sequence[ParameterValueType]]c                ó”   — |s+t          j        | ¦  «        }|                     |d¬¦  «        S | j                             | |¬¦  «        S )aâ  Assign the parameters in this schedule according to the input.

        Args:
            value_dict: A mapping from parameters or parameter names (parameter vector
            or parameter vector name) to either numeric values (list of numeric values)
            or another parameter expression (list of parameter expressions).
            inplace: Set ``True`` to override this instance with new parameter.

        Returns:
            Schedule with updated parameters.
        Tr©   ©Úpulse_programr  )rI   ÚdeepcopyÚassign_parametersr5   )r>   r  r¢   Únew_schedules       rA   r  zSchedule.assign_parametersÃ  sR   € ð& ð 	LÝœ=¨Ñ.Ô.ˆLØ×1Ò1°*ÀdÐ1ÑKÔKÐKàÔ&×8Ò8ÀtÐXbÐ8ÑcÔcÐcrT   Úparameter_nameúlist[Parameter]c                ó6   — | j                              |¦  «        S )af  Get parameter object bound to this schedule by string name.

        Because different ``Parameter`` objects can have the same name,
        this method returns a list of ``Parameter`` s for the provided name.

        Args:
            parameter_name: Name of parameter.

        Returns:
            Parameter objects that have corresponding name.
        )r5   Úget_parameters)r>   r  s     rA   r  zSchedule.get_parametersÜ  s   € ð Ô&×5Ò5°nÑEÔEÐErT   c                ó*   — t          | j        ¦  «        S ©z.Return number of instructions in the schedule.)Úlenr„   rR   s    rA   Ú__len__zSchedule.__len__ê  s   € å�4Ô$Ñ%Ô%Ð%rT   Úotherc                ó,   — |                       |¦  «        S ©zPReturn a new schedule with ``other`` inserted within ``self`` at ``start_time``.©r¾   ©r>   r  s     rA   Ú__add__zSchedule.__add__î  ó   € à�{Š{˜5Ñ!Ô!Ð!rT   c                ó.   — |                       d|¦  «        S )z?Return a new schedule which is the union of `self` and `other`.r   )rª   r  s     rA   Ú__or__zSchedule.__or__ò  s   € à�{Š{˜1˜eÑ$Ô$Ð$rT   c                ó,   — |                       |¦  «        S )z;Return a new schedule which is shifted forward by ``time``.)r§   )r>   r@   s     rA   Ú
__lshift__zSchedule.__lshift__ö  s   € à�zŠz˜$ÑÔÐrT   Úobjectc                ó`  — t          |t          | ¦  «        t          f¦  «        sdS t          | j        ¦  «        t          |j        ¦  «        k    rdS t          | j        ¦  «        t          |j        ¦  «        k    rdS t          d„ t          | j        |j        ¦  «        D ¦   «         ¦  «        S )aÃ  Test if two Schedule are equal.

        Equality is checked by verifying there is an equal instruction at every time
        in ``other`` for every instruction in this ``Schedule``.

        .. warning::

            This does not check for logical equivalency. Ie.,

            ```python
            >>> Delay(10, DriveChannel(0)) + Delay(10, DriveChannel(0))
                == Delay(20, DriveChannel(0))
            False
            ```
        Fc              3  ó(   K  — | ]\  }}||k    V — Œd S rz   r’   )r|   Ú	self_instÚ
other_insts      rA   r~   z"Schedule.__eq__.<locals>.<genexpr>  s?   è è € ð 
ð 
á%�	˜:ð ˜Ò#ð
ð 
ð 
ð 
ð 
ð 
rT   )	r6   rå   r   rÃ   rh   r  r„   ÚallÚzipr  s     rA   Ú__eq__zSchedule.__eq__ú  s´   € õ" ˜%¥$ t¡*¤*­kÐ!:Ñ;Ô;ð 	Ø�5õ ˆtŒ}ÑÔ¥ U¤^Ñ!4Ô!4Ò4Ð4Ø�5õ ˆtÔ Ñ!Ô!¥S¨Ô);Ñ%<Ô%<Ò<Ð<Ø�5õ ð 
ð 
å),¨TÔ->ÀÔ@RÑ)SÔ)Sð
ñ 
ô 
ñ 
ô 
ð 	
rT   c                óø   — | j         rt          | j         ¦  «        nd}d                     d„ | j        d d…         D ¦   «         ¦  «        }t	          | j        ¦  «        dk    r|dz  }| j        j        › d|› d|› d	�S )
Nrâ   rð   c                ó,   — g | ]}t          |¦  «        ‘ŒS r’   ©Úrepr©r|   Úinstrs     rA   r±   z%Schedule.__repr__.<locals>.<listcomp>  s   € Ð!RÐ!RÐ!R°%¥$ u¡+¤+Ð!RÐ!RÐ!RrT   é2   é   ú, ...ú(ú, name="z"))r4   ÚformatÚjoinr„   r  rL   rK   )r>   r   r„   s      rA   Ú__repr__zSchedule.__repr__  s�   € Ø%)¤ZÐ7�v�d”jÑ!Ô!Ð!°RˆØ—y’yÐ!RÐ!R¸4Ô;LÈSÈbÈSÔ;QÐ!RÑ!RÔ!RÑSÔSˆÝˆtÔ Ñ!Ô! BÒ&Ð&Ø˜GÑ#ˆLØ”.Ô)ÐJÐJ¨LÐJÐJÀ$ÐJÐJÐJÐJrT   )r    r!   r   r"   r   r#   rz   )rC   r
   r   r"   rD   rE   ©rD   r,   ©rD   rU   )rD   r_   ©rD   rc   ©rD   rm   )rD   rq   )rD   rt   ©rD   r…   ©rh   r   rD   rc   ©r   )r@   rc   )NF)r@   rc   r   r"   r¢   r£   rD   rE   )r@   rc   r   r"   rD   rE   )r@   rc   rD   rE   )
ri   rc   r¸   r¹   r   r"   r¢   r£   rD   rE   )ri   rc   r¸   r¹   rD   rE   )ri   rc   r¸   r¹   r   r"   rD   rE   )r¸   r¹   r   r"   r¢   r£   rD   rE   )rÈ   r   rh   rÉ   rÅ   rÊ   rÆ   rË   r”   rÌ   rÇ   r£   rD   rE   )r@   rc   r¸   r¹   rD   rÜ   )r@   rc   r¸   r¹   )r@   rc   rõ   r¹   rö   r¹   )F)rõ   r¹   rö   r¹   r¢   r£   rD   rE   ©rD   r£   ©T)r  r  r¢   r£   rD   rE   ©r  r,   rD   r  )r  r¹   rD   rE   ©r  r   rD   r£   )3rK   Ú
__module__Ú__qualname__Ú__doc__r+   Ú	itertoolsÚcountr.   r   rB   ÚclassmethodrO   Úpropertyr   r   Úsetterrb   re   ri   rl   rh   rs   r„   r‡   rŒ   rg   rŠ   rƒ   r§   r¦   r¥   rª   r=   r»   r¾   rÙ   rÛ   r½   rô   rø   rü   r  r  r  r  r  r  r  r  r'  r5  r’   rT   rA   r   r   C   s¨  € € € € € ð1ð 1ðh €Fð (˜	œÑ)Ô)Ðàð  Ø $ð	,.ð ,.ð ,.ð ,.ð ,.ñ Ôð,.ð\ ðð ð ð ñ „[ðð8 ðð ð ñ „Xðð ð
ð 
ð 
ñ „Xð
ð „_ð(ð (ñ „_ð(ð ðð ð ñ „Xðð ðð ð ñ „Xðð ð2ð 2ð 2ñ „Xð2ð ðð ð ñ „Xðð ð-ð -ð -ñ „Xð-ð ð%ð %ð %ñ „Xð%ð ð<ð <ð <ñ „Xð<ð ð2ð 2ð 2ñ „Xð2ð,ð ,ð ,ð ,ðð ð ð ðð ð ð ðEð Eð Eð Eð Eð6ð 6ð 6ð 6ð 6ð
ð 
ð 
ð 
ð 
ðð ð ð ð6  ØðGð Gð Gð Gð Gð(
ð 
ð 
ð 
ð   ð	ð ð ð ð ð$ W\ðGð Gð Gð Gð Gð0 .2ØAEØ8<Ø/3Ø!%ð#
ð #
ð #
ð #
ð #
ð #
ðP .2ØAEØ8<Ø/3Ø!%ð 
ð  
ð  
ð  
ð  
ð  
ðD.5ð .5ð .5ð .5ð`#-ð #-ð #-ð #-ðJ	'ð 	'ð 	'ð 	'ð*ð *ð *ð ð	Pð Pð Pð Pð Pðd:ð :ð :ð :ð ðdð dð dð dð dð2Fð Fð Fð Fð&ð &ð &ð &ð"ð "ð "ð "ð%ð %ð %ð %ð ð  ð  ð  ð 
ð  
ð  
ð  
ðDKð Kð Kð Kð Kð KrT   r   Úfunctionr   rD   c                óF   ‡ — t          j        ‰ ¦  «        ˆ fd„¦   «         }|S )z§A method decorator to convert schedule block to pulse schedule.

    This conversation is performed for backward compatibility only if all durations are assigned.
    c                ó:   •— ddl m}  ‰ || ¦  «        g|¢R i |¤ŽS )Nr   )Úblock_to_schedule)Úqiskit.pulse.transformsrL  )r>   ÚargsÚkwargsrL  rI  s       €rA   Úwrapperz-_require_schedule_conversion.<locals>.wrapper*  sA   ø€ à=Ð=Ð=Ð=Ð=Ð=àˆxÐ)Ð)¨$Ñ/Ô/ÐA°$ÐAÐAÐA¸&ÐAÐAÐArT   )Ú	functoolsÚwraps)rI  rP  s   ` rA   Ú_require_schedule_conversionrS  $  s?   ø€ õ „_�XÑÔðBð Bð Bð Bñ ÔðBð
 €NrT   c                  ó0  — e Zd ZdZdZdZ ej        ¦   «         Ze		 dGdHd	„¦   «         Z
edIdJd„¦   «         ZedKd„¦   «         ZedLd„¦   «         Zej        d„ ¦   «         Zed„ ¦   «         ZdMd„ZeedNd„¦   «         ¦   «         ZedOd„¦   «         ZeedPd„¦   «         ¦   «         ZedQd„¦   «         ZedRd „¦   «         ZedSd"„¦   «         ZedTd%„¦   «         Z	 dUdVd)„Zddd&d*œdWd1„Zddd&d*œdWd2„Z	 dXdYd5„ZdMd6„ZdMd7„Z 	 dXdZd:„Z!	 dXd[d=„Z"d\d@„Z#dNdA„Z$d]dD„Z%dKdE„Z&d^dF„Z'dS )_ÚScheduleBlocka]  Time-ordered sequence of instructions with alignment context.

    :class:`.ScheduleBlock` supports lazy scheduling of context instructions,
    i.e. their timeslots is always generated at runtime.
    This indicates we can parametrize instruction durations as well as
    other parameters. In contrast to :class:`.Schedule` being somewhat static,
    :class:`.ScheduleBlock` is a dynamic representation of a pulse program.

    .. rubric:: Pulse Builder

    The Qiskit pulse builder is a domain specific language that is developed on top of
    the schedule block. Use of the builder syntax will improve the workflow of
    pulse programming. See :ref:`pulse_builder` for a user guide.

    .. rubric:: Alignment contexts

    A schedule block is always relatively scheduled.
    Instead of taking individual instructions with absolute execution time ``t0``,
    the schedule block defines a context of scheduling and instructions
    under the same context are scheduled in the same manner (alignment).
    Several contexts are available in :ref:`pulse_alignments`.
    A schedule block is instantiated with one of these alignment contexts.
    The default context is :class:`AlignLeft`, for which all instructions are left-justified,
    in other words, meaning they use as-soon-as-possible scheduling.

    If you need an absolute-time interval in between instructions, you can explicitly
    insert :class:`~qiskit.pulse.instructions.Delay` instructions.

    .. rubric:: Nested blocks

    A schedule block can contain other nested blocks with different alignment contexts.
    This enables advanced scheduling, where a subset of instructions is
    locally scheduled in a different manner.
    Note that a :class:`.Schedule` instance cannot be directly added to a schedule block.
    To add a :class:`.Schedule` instance, wrap it in a :class:`.Call` instruction.
    This is implicitly performed when a schedule is added through the :ref:`pulse_builder`.

    .. rubric:: Unsupported operations

    Because the schedule block representation lacks timeslots, it cannot
    perform particular :class:`.Schedule` operations such as :meth:`insert` or :meth:`shift` that
    require instruction start time ``t0``.
    In addition, :meth:`exclude` and :meth:`filter` methods are not supported
    because these operations may identify the target instruction with ``t0``.
    Except for these operations, :class:`.ScheduleBlock` provides full compatibility
    with :class:`.Schedule`.

    .. rubric:: Subroutine

    The timeslots-free representation offers much greater flexibility for writing pulse programs.
    Because :class:`.ScheduleBlock` only cares about the ordering of the child blocks
    we can add an undefined pulse sequence as a subroutine of the main program.
    If your program contains the same sequence multiple times, this representation may
    reduce the memory footprint required by the program construction.
    Such a subroutine is realized by the special compiler directive
    :class:`~qiskit.pulse.instructions.Reference` that is defined by
    a unique set of reference key strings to the subroutine.
    The (executable) subroutine is separately stored in the main program.
    Appended reference directives are resolved when the main program is executed.
    Subroutines must be assigned through :meth:`assign_references` before execution.

    One way to reference a subroutine in a schedule is to use the pulse
    builder's :func:`~qiskit.pulse.builder.reference`  function to declare an
    unassigned reference.  In this example, the program is called with the
    reference key "grand_child".  You can call a subroutine without specifying
    a substantial program.

    .. code-block::

        from qiskit import pulse
        from qiskit.circuit.parameter import Parameter

        amp1 = Parameter("amp1")
        amp2 = Parameter("amp2")

        with pulse.build() as sched_inner:
            pulse.play(pulse.Constant(100, amp1), pulse.DriveChannel(0))

        with pulse.build() as sched_outer:
            with pulse.align_right():
                pulse.reference("grand_child")
                pulse.play(pulse.Constant(200, amp2), pulse.DriveChannel(0))

        # Now assign the inner pulse program to this reference
        sched_outer.assign_references({("grand_child",): sched_inner})
        print(sched_outer.parameters)

    .. code-block:: text

       {Parameter(amp1), Parameter(amp2)}

    The outer program now has the parameter ``amp2`` from the inner program,
    indicating that the inner program's data has been made available to the
    outer program.
    The program calling the "grand_child" has a reference program description
    which is accessed through :attr:`ScheduleBlock.references`.

    .. code-block::

        print(sched_outer.references)

    .. code-block:: text

       ReferenceManager:
         - ('grand_child',): ScheduleBlock(Play(Constant(duration=100, amp=amp1,...

    Finally, you may want to call this program from another program.
    Here we try a different approach to define subroutine. Namely, we call
    a subroutine from the root program with the actual program ``sched2``.

    .. code-block::

        amp3 = Parameter("amp3")

        with pulse.build() as main:
            pulse.play(pulse.Constant(300, amp3), pulse.DriveChannel(0))
            pulse.call(sched_outer, name="child")

        print(main.parameters)

    .. code-block:: text

       {Parameter(amp1), Parameter(amp2), Parameter(amp3}

    This implicitly creates a reference named "child" within
    the root program and assigns ``sched_outer`` to it.

    Note that the root program is only aware of its direct references.

    .. code-block::

        print(main.references)

    .. code-block:: text

       ReferenceManager:
         - ('child',): ScheduleBlock(ScheduleBlock(ScheduleBlock(Play(Con...

    As you can see the main program cannot directly assign a subroutine to the "grand_child" because
    this subroutine is not called within the root program, i.e. it is indirectly called by "child".
    However, the returned :class:`.ReferenceManager` is a dict-like object, and you can still
    reach to "grand_child" via the "child" program with the following chained dict access.

    .. code-block::

        main.references[("child", )].references[("grand_child", )]

    Note that :attr:`ScheduleBlock.parameters` still collects all parameters
    also from the subroutine once it's assigned.
    )Ú_parentr4   Ú_reference_managerr5   Ú_alignment_contextÚ_blocksr9   ÚblockNr   r"   r   r#   c                ó  — ddl m} ddlm} |€e| j        t          t          | j        ¦  «        ¦  «        z   }t          j	        dk    r,t          ¦   «         s|dt          j        ¦   «         j        › �z  }d| _        || _         |¦   «         | _        t#          ¦   «         | _        |p	 |¦   «         | _        g | _        | j                             | j        ¦  «         t-          |t.          ¦  «        s|�t1          d¦  «        ‚|pi | _        dS )a†  Create an empty schedule block.

        Args:
            name: Name of this schedule. Defaults to an autogenerated string if not provided.
            metadata: Arbitrary key value metadata to associate with the schedule. This gets
                stored as free-form data in a dict in the
                :attr:`~qiskit.pulse.ScheduleBlock.metadata` attribute. It will not be directly
                used in the schedule.
            alignment_context (AlignmentKind): ``AlignmentKind`` instance that manages
                scheduling of instructions in this block.

        Raises:
            TypeError: if metadata is not a dict.
        r   r%   )Ú	AlignLeftNr'   r(   r)   )r*   r&   rM  r\  r+   r,   r-   r.   r/   r0   r   r1   r2   r3   rV  r4   r5   r   rW  rX  rY  r¿   r6   r7   r8   r9   )r>   r   r   Úalignment_contextr&   r\  s         rA   rB   zScheduleBlock.__init__Û  s  € ð$ 	DÐCÐCÐCÐCÐCØ5Ð5Ð5Ð5Ð5Ð5àˆ<Ø”;¥¥T¨$Ô*@Ñ%AÔ%AÑ!BÔ!BÑBˆDÝŒ|˜wÒ&Ð&­Ñ/@Ô/@Ð&ØÐ6�BÔ.Ñ0Ô0Ô4Ð6Ð6Ñ6�ð .2ˆŒàˆŒ
Ø"2Ð"2Ñ"4Ô"4ˆÔÝ"2Ñ"4Ô"4ˆÔØ"3Ð"B°y°y±{´{ˆÔØ/1ˆŒð 	Ô×6Ò6°tÔ7NÑOÔOÐOå˜(¥DÑ)Ô)ð 	[¨hÐ.BÝÐYÑZÔZÐZØ!˜ RˆŒˆˆrT   rC   r
   rD   ú'ScheduleBlock'c                ó  — 	 |p|j         }|j        r|j                             ¦   «         }nd}	 |j        }n# t          $ r d}Y nw xY w | |||¬¦  «        S # t          $ r*}t          | j        › d|j        j        › d�¦  «        |‚d}~ww xY w)a©  Create new schedule object with metadata of another schedule object.

        Args:
            other_program: Qiskit program that provides metadata to new object.
            name: Name of new schedule. Name of ``block`` is used by default.

        Returns:
            New block object with name and metadata.

        Raises:
            PulseError: When ``other_program`` does not provide necessary information.
        N)r   r   r]  rG   rH   )r   r   rI   r]  rJ   r   rK   rL   )rM   rC   r   r   r]  rN   s         rA   rO   zScheduleBlock.initialize_from
  sé   € ð	ØÐ-˜=Ô-ˆDàÔ%ð  Ø(Ô1×6Ò6Ñ8Ô8��à�ð)Ø$1Ô$CÐ!Ð!øÝ!ð )ð )ð )Ø$(Ð!Ð!Ð!ð)øøøð �3˜D¨8ÐGXÐYÑYÔYÐYøÝð 	ð 	ð 	ÝØ”<ð 7ð 7Ø Ô*Ô3ð7ð 7ð 7ñô ð ðøøøøð	øøøs7   ‚,A ¯7 ¶A ·AÁA ÁAÁA Á
BÁ!%BÂBr,   c                ó   — | j         S )zReturn name of this schedulerQ   rR   s    rA   r   zScheduleBlock.name,  rS   rT   rU   c                ó   — | j         S rW   rX   rR   s    rA   r   zScheduleBlock.metadata1  rY   rT   c                ód   — t          |t          ¦  «        s|�t          d¦  «        ‚|pi | _        dS r[   r\   r]   s     rA   r   zScheduleBlock.metadata>  r^   rT   c                ó   — | j         S )zNReturn alignment instance that allocates block component to generate schedule.)rX  rR   s    rA   r]  zScheduleBlock.alignment_contextE  s   € ð Ô&Ð&rT   r£   c                ó"  — | j         j        D ]}t          |t          ¦  «        r dS Œ| j        D ]_}t          |t
          ¦  «        r|                     ¦   «         s dS Œ/	 t          |j        t          ¦  «        s dS ŒN# t          $ r Y  dS w xY wdS )z.Return ``True`` if all durations are assigned.FT)
rX  Ú_context_paramsr6   r   ÚblocksrU  Úis_schedulablere   rc   r   )r>   Úcontext_paramÚelms      rA   rg  zScheduleBlock.is_schedulableJ  sË   € ð "Ô4ÔDð 	ð 	ˆMÝ˜-Õ)<Ñ=Ô=ð Ø�u�uðð ”;ð 		!ð 		!ˆCÝ˜#�}Ñ-Ô-ð !Ø×)Ò)Ñ+Ô+ð !Ø ˜5˜5ð!ð!Ý% c¤lµCÑ8Ô8ð %Ø$˜u˜uð%øå/ð !ð !ð !Ø ˜5˜5˜5ð!øøøàˆts   ÁA=Á=
BÂBrc   c                ó   — | j         S )z Duration of this schedule block.rk   rR   s    rA   re   zScheduleBlock.duration^  s   € ð Œ}ÐrT   rm   c                óØ   — t          ¦   «         }| j        D ]F}t          |t          ¦  «        rt	          d|j        › d�¦  «        ‚|t          |j        ¦  «        z  }ŒGt          |¦  «        S )z/Returns channels that this schedule block uses.z,This schedule contains unassigned reference z@ and channels are ambiguous. Please assign the subroutine first.)rÃ   rf  r6   r   r   Úref_keysrh   ro   )r>   Úchansri  s      rA   rh   zScheduleBlock.channelsd  s‚   € õ "™eœeˆØ”;ð 	.ð 	.ˆCÝ˜#�yÑ)Ô)ð Ý.ðVÀ3Ä<ð Vð Vð Vñô ð ð �C ¤Ñ-Ô-Ñ-ˆEˆEÝ�U‰|Œ|ÐrT   útuple[tuple[int, Instruction]]c                ó   — | j         S )rv   )r„   rR   s    rA   r„   zScheduleBlock.instructionsq  s   € ð Ô Ð rT   útuple['BlockComponent', ...]c                óÐ   — g }| j         D ]N}t          |t          ¦  «        r"| j                             |j        d¦  «        p|}|                     |¦  «         ŒOt          |¦  «        S )aD  Get the block elements added to self.

        .. note::

            The sequence of elements is returned in order of addition. Because the first element is
            schedule first, e.g. FIFO, the returned sequence is roughly time-ordered.
            However, in the parallel alignment context, especially in
            the as-late-as-possible scheduling, or :class:`.AlignRight` context,
            the actual timing of when the instructions are issued is unknown until
            the :class:`.ScheduleBlock` is scheduled and converted into a :class:`.Schedule`.
        N)rY  r6   r   Ú
referencesÚgetrl  r¾   ro   )r>   rf  ri  s      rA   rf  zScheduleBlock.blocksw  sl   € ð ˆØ”<ð 	ð 	ˆCÝ˜#�yÑ)Ô)ð EØ”o×)Ò)¨#¬,¸Ñ=Ô=ÐDÀ�Ø�MŠM˜#ÑÔÐÐÝ�V‰}Œ}ÐrT   r…   c                ó’   — t          ¦   «         }|| j        j        z  }| j                             ¦   «         D ]}|€Œ||j        z  }Œ|S )z,Return unassigned parameters with raw names.)rÃ   r5   r‡   rr  Úvalues)r>   Ú
out_paramsÚ
subroutines      rA   r‡   zScheduleBlock.parameters‹  sX   € õ ‘U”Uˆ
à�dÔ-Ô8Ñ8ˆ
Øœ/×0Ò0Ñ2Ô2ð 	0ð 	0ˆJØÐ!ØØ˜*Ô/Ñ/ˆJˆJàÐrT   r   c                ó6   — | j         �| j         j        S | j        S )z0Return a reference manager of the current scope.)rV  rr  rW  rR   s    rA   rr  zScheduleBlock.references™  s    € ð Œ<Ð#Ø”<Ô*Ð*ØÔ&Ð&rT   rh   r   c                ó   —  | j         |Ž S r‰   )rŒ   r‹   s     rA   rŒ   zScheduleBlock.ch_duration   s   € ð  ˆtÔ Ð*Ð*rT   Tú'BlockComponent'r¢   c                óH  — t          |t          t          f¦  «        st          d|j        j        › d�¦  «        ‚|s;t          j        | ¦  «        }|p| j        |_	        | 
                    |d¬¦  «         |S t          |t          ¦  «        r|j        | j        vrd| j        |j        <   nÄt          |t          ¦  «        r¯t          j        |¦  «        }|                     ¦   «         r€|j        �7t!          |j        ¦  «        D ]!}|j        |j                 | j        |j        <   Œ"nB|j                             ¦   «         D ]\  }}|| j        |<   Œ|j                             ¦   «          | |_        | j         
                    |¦  «         | j                             |¦  «         | S )aN  Return a new schedule block with ``block`` appended to the context block.
        The execution time is automatically assigned when the block is converted into schedule.

        Args:
            block: ScheduleBlock to be appended.
            name: Name of the new ``Schedule``. Defaults to name of ``self``.
            inplace: Perform operation inplace on this schedule. Otherwise,
                return a new ``Schedule``.

        Returns:
            Schedule block with appended schedule.

        Raises:
            PulseError: When invalid schedule type is specified.
        zAppended `schedule` zI is invalid type. Only `Instruction` and `ScheduleBlock` can be accepted.Tr©   N)r6   rU  r   r   rL   rK   rI   r
  r   r4   r¾   r   rl  rr  Úis_referencedrV  Ú_get_referencesrY  rW  rµ   rú   r5   r¿   )r>   rZ  r   r¢   r¸   Úrefrl  s          rA   r¾   zScheduleBlock.append©  s½  € õ$ ˜%¥-µÐ!=Ñ>Ô>ð 	ÝðJ u¤Ô'?ð Jð Jð Jñô ð ð
 ð 	Ý”} TÑ*Ô*ˆHØ!Ð. T¤YˆHŒNØ�OŠO˜E¨4ˆOÑ0Ô0Ð0ØˆOå�e�YÑ'Ô'ð 	!¨E¬NÀ$Ä/Ð,QÐ,QØ.2ˆDŒO˜EœNÑ+Ð+å˜�}Ñ-Ô-ð 	!Ý”M %Ñ(Ô(ˆEð ×"Ò"Ñ$Ô$ð 5Ø”=Ð,õ  /¨u¬}Ñ=Ô=ð Wð W˜Ø8=Ô8HÈÌÔ8V˜œ¨¬Ñ5Ð5ðWð
 */Ô)A×)GÒ)GÑ)IÔ)Ið 8ð 8™˜ #Ø47˜œ¨Ñ1Ð1ØÔ,×2Ò2Ñ4Ô4Ð4à ˆEŒMàŒ×Ò˜EÑ"Ô"Ð"ØÔ×6Ò6°uÑ=Ô=Ð=àˆrT   )rh   rÅ   rÇ   rÈ   úCallable[..., bool]rÉ   rÅ   rÊ   rÇ   c               ór   — ddl m}m}  |||¦  «        }|                     |¦  «          || |d|¬¦  «        S )aò  Return a new ``ScheduleBlock`` with only the instructions from this ``ScheduleBlock``
        which pass though the provided filters; i.e. an instruction will be retained if
        every function in ``filter_funcs`` returns ``True``, the instruction occurs on
        a channel type contained in ``channels``, and the instruction type is contained
        in ``instruction_types``.

        .. warning::
            Because ``ScheduleBlock`` is not aware of the execution time of
            the context instructions, filtering out some instructions may
            change the execution time of the remaining instructions.

        If no arguments are provided, ``self`` is returned.

        Args:
            filter_funcs: A list of Callables which take a ``Instruction`` and return a bool.
            channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``.
            instruction_types: For example, ``[PulseInstruction, AcquireInstruction]``.
            check_subroutine: Set `True` to individually filter instructions inside a subroutine
                defined by the :py:class:`~qiskit.pulse.instructions.Call` instruction.

        Returns:
            ``ScheduleBlock`` consisting of instructions that matches with filtering condition.
        r   rÎ   FrÑ   rÕ   ©r>   rh   rÅ   rÇ   rÈ   rÏ   rÐ   rÒ   s           rA   rÙ   zScheduleBlock.filteræ  sf   € ð< 	OÐNÐNÐNÐNÐNÐNÐNà"Ð" 8Ð->Ñ?Ô?ˆØ�Š�|Ñ$Ô$Ð$à"Ð"Ø˜'¨%ÐEUð
ñ 
ô 
ð 	
rT   c               ór   — ddl m}m}  |||¦  «        }|                     |¦  «          || |d|¬¦  «        S )a™  Return a new ``ScheduleBlock`` with only the instructions from this ``ScheduleBlock``
        *failing* at least one of the provided filters.
        This method is the complement of :py:meth:`~ScheduleBlock.filter`, so that::

            self.filter(args) + self.exclude(args) == self in terms of instructions included.

        .. warning::
            Because ``ScheduleBlock`` is not aware of the execution time of
            the context instructions, excluding some instructions may
            change the execution time of the remaining instructions.

        Args:
            filter_funcs: A list of Callables which take a ``Instruction`` and return a bool.
            channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``.
            instruction_types: For example, ``[PulseInstruction, AcquireInstruction]``.
            check_subroutine: Set `True` to individually filter instructions inside of a subroutine
                defined by the :py:class:`~qiskit.pulse.instructions.Call` instruction.

        Returns:
            ``ScheduleBlock`` consisting of instructions that do not match with
            at least one of filtering conditions.
        r   rÎ   TrÑ   rÕ   r�  s           rA   rÛ   zScheduleBlock.exclude  sf   € ð: 	OÐNÐNÐNÐNÐNÐNÐNà"Ð" 8Ð->Ñ?Ô?ˆØ�Š�|Ñ$Ô$Ð$à"Ð"Ø˜'¨$ÐDTð
ñ 
ô 
ð 	
rT   rõ   rö   c                ó¾  — |s,t          j        | ¦  «        }|                     ||d¬¦  «        S || j        vr| S t	          ¦   «         }t          |t          ¦  «        rNt          j        |¦  «        }|                     |j        ¦  «         |j	         
                    ¦   «          | |_        | j                             ¦   «         D ]5\  }}||v r't          j        d|› d|j        › d�t           ¦  «         Œ0|||<   Œ6| j         
                    ¦   «          | j                             | j        ¦  «         g }| j        D ]9}	|	|k    r|}	| j                             |	¦  «         |                     |	¦  «         Œ:|| _        | j         
                    ¦   «          | }
|
j        �|
j        }
|
j        ­t+          |
j        ¦  «        D ]}||j                 | j        |j        <   Œ| S )a›  Return a ``ScheduleBlock`` with the ``old`` component replaced with a ``new``
        component.

        Args:
            old: Schedule block component to replace.
            new: Schedule block component to replace with.
            inplace: Replace instruction by mutably modifying this ``ScheduleBlock``.

        Returns:
            The modified schedule block with ``old`` replaced by ``new``.
        Tr©   z
Reference z$ conflicts with substituted program z:. Existing reference has been replaced with new reference.)rI   r
  r  rY  r   r6   rU  Úupdaterr  rW  rú   rV  rµ   ÚwarningsÚwarnr   ÚUserWarningr5   r¿   rX  r¾   r}  rl  )r>   rõ   rö   r¢   r¸   Úall_referencesÚref_keyrw  Únew_elmsri  Úrootr~  s               rA   r  zScheduleBlock.replace3  s  € ð" ð 	<Ý”} TÑ*Ô*ˆHØ×#Ò# C¨°dÐ#Ñ;Ô;Ð;à�d”lÐ"Ð"àˆKõ *Ñ+Ô+ˆÝ�c�=Ñ)Ô)ð 	Ý”- Ñ$Ô$ˆCØ×!Ò! #¤.Ñ1Ô1Ð1ØÔ"×(Ò(Ñ*Ô*Ð*ØˆCŒKØ#'¤?×#8Ò#8Ñ#:Ô#:ð 	1ð 	1ÑˆG�ZØ˜.Ð(Ð(Ý”ðO ð Oð OÈcÌhð Oð Oð Oåñô ð ð
 Ø&0ˆN˜7Ñ#Ð#ð
 	Ô×%Ò%Ñ'Ô'Ð'ØÔ×6Ò6°tÔ7NÑOÔOÐOàˆØ”<ð 	!ð 	!ˆCØ�cŠzˆzØ�ØÔ#×:Ò:¸3Ñ?Ô?Ð?Ø�OŠO˜CÑ Ô Ð Ð ØˆŒð
 	Œ×ÒÑÔÐØˆØŒlÐ&Ø”<ˆDð ŒlÐ&å" 4¤<Ñ0Ô0ð 	Ið 	IˆCØ,:¸3¼<Ô,HˆDŒO˜CœLÑ)Ð)àˆrT   c                ó*   — t          | j        ¦  «        S r  )Úanyr‡   rR   s    rA   r  zScheduleBlock.is_parameterizedw  s   € å�4”?Ñ#Ô#Ð#rT   c                ó2   — t          | j        ¦  «        dk    S )zLReturn True iff the current schedule block contains reference to subroutine.r   )r  rr  rR   s    rA   r|  zScheduleBlock.is_referenced{  s   € å�4”?Ñ#Ô# aÒ'Ð'rT   r  r  c                ó  — |s+t          j        | ¦  «        }|                     |d¬¦  «        S | j                             | |¬¦  «         | j                             ¦   «         D ]}|€Œ|                     |d¬¦  «         Œ| S )a8  Assign the parameters in this schedule according to the input.

        Args:
            value_dict: A mapping from parameters or parameter names (parameter vector
            or parameter vector name) to either numeric values (list of numeric values)
            or another parameter expression (list of parameter expressions).
            inplace: Set ``True`` to override this instance with new parameter.

        Returns:
            Schedule with updated parameters.

        Raises:
            PulseError: When the block is nested into another block.
        Tr©   r  N)r  r¢   )rI   r
  r  r5   rW  ru  )r>   r  r¢   r  rw  s        rA   r  zScheduleBlock.assign_parameters  s    € ð, ð 	LÝœ=¨Ñ.Ô.ˆLØ×1Ò1°*ÀdÐ1ÑKÔKÐKð 	Ô×1Ò1ÀÐQ[Ð1Ñ\Ô\Ð\àÔ1×8Ò8Ñ:Ô:ð 	Nð 	NˆJð Ð!ØØ×(Ò(°JÈÐ(ÑMÔMÐMÐMàˆrT   Úsubroutine_dictú,dict[str | tuple[str, ...], 'ScheduleBlock']c                ó†  — |s+t          j        | ¦  «        }|                     |d¬¦  «        S |                     ¦   «         D ]~\  }}|| j        vrTd                     t          t          | j                             ¦   «         ¦  «        ¦  «        }t          d|› d|› �¦  «        ‚t          j        |¦  «        | j        |<   Œ| S )a²	  Assign schedules to references.

        It is only capable of assigning a schedule block to immediate references
        which are directly referred within the current scope.
        Let's see following example:

        .. code-block:: python

            from qiskit import pulse

            with pulse.build() as nested_prog:
                pulse.delay(10, pulse.DriveChannel(0))

            with pulse.build() as sub_prog:
                pulse.reference("A")

            with pulse.build() as main_prog:
                pulse.reference("B")

        In above example, the ``main_prog`` can refer to the subroutine "root::B" and the
        reference of "B" to program "A", i.e., "B::A", is not defined in the root namespace.
        This prevents breaking the reference "root::B::A" by the assignment of "root::B".
        For example, if a user could indirectly assign "root::B::A" from the root program,
        one can later assign another program to "root::B" that doesn't contain "A" within it.
        In this situation, a reference "root::B::A" would still live in
        the reference manager of the root.
        However, the subroutine "root::B::A" would no longer be used in the actual pulse program.
        To assign subroutine "A" to ``nested_prog`` as a nested subprogram of ``main_prog``,
        you must first assign "A" of the ``sub_prog``,
        and then assign the ``sub_prog`` to the ``main_prog``.

        .. code-block:: python

            sub_prog.assign_references({("A", ): nested_prog}, inplace=True)
            main_prog.assign_references({("B", ): sub_prog}, inplace=True)

        Alternatively, you can also write

        .. code-block:: python

            main_prog.assign_references({("B", ): sub_prog}, inplace=True)
            main_prog.references[("B", )].assign_references({("A", ): nested_prog}, inplace=True)

        Here :attr:`.references` returns a dict-like object, and you can
        mutably update the nested reference of the particular subroutine.

        .. note::

            Assigned programs are deep-copied to prevent an unexpected update.

        Args:
            subroutine_dict: A mapping from reference key to schedule block of the subroutine.
            inplace: Set ``True`` to override this instance with new subroutine.

        Returns:
            Schedule block with assigned subroutine.

        Raises:
            PulseError: When reference key is not defined in the current scope.
        Tr©   rð   zReference instruction with z% doesn't exist in the current scope: )
rI   r
  Úassign_referencesrµ   rr  r4  Úmapr+  Ú
unassignedr   )r>   r�  r¢   r  r‚   rw  Úunassigned_keyss          rA   r“  zScheduleBlock.assign_references¦  sÛ   € ðB ð 	QÝœ=¨Ñ.Ô.ˆLØ×1Ò1°/È4Ð1ÑPÔPÐPà.×4Ò4Ñ6Ô6ð 	=ð 	=‰OˆC�Ø˜$œ/Ð)Ð)Ø"&§)¢)­Cµ°d´o×6PÒ6PÑ6RÔ6RÑ,SÔ,SÑ"TÔ"T�Ý ð?°#ð ?ð ?Ø-<ð?ð ?ñô ð õ $(¤=°Ñ#<Ô#<ˆDŒO˜CÑ Ð àˆrT   r  r  c                ó.   ‡— ˆfd„| j         D ¦   «         }|S )aÄ  Get parameter object bound to this schedule by string name.

        Note that we can define different parameter objects with the same name,
        because these different objects are identified by their unique uuid.
        For example,

        .. code-block:: python

            from qiskit import pulse, circuit

            amp1 = circuit.Parameter("amp")
            amp2 = circuit.Parameter("amp")

            with pulse.build() as sub_prog:
                pulse.play(pulse.Constant(100, amp1), pulse.DriveChannel(0))

            with pulse.build() as main_prog:
                pulse.call(sub_prog, name="sub")
                pulse.play(pulse.Constant(100, amp2), pulse.DriveChannel(0))

            main_prog.get_parameters("amp")

        This returns a list of two parameters ``amp1`` and ``amp2``.

        Args:
            parameter_name: Name of parameter.

        Returns:
            Parameter objects that have corresponding name.
        c                ó*   •— g | ]}|j         ‰k    ¯|‘ŒS r’   r{   )r|   Úpr  s     €rA   r±   z0ScheduleBlock.get_parameters.<locals>.<listcomp>  s%   ø€ ÐJÐJÐJ˜°´¸>Ò1IÐ1I�1Ð1IÐ1IÐ1IrT   )r‡   )r>   r  Úmatcheds    ` rA   r  zScheduleBlock.get_parametersö  s&   ø€ ð> KÐJÐJÐJ˜dœoÐJÑJÔJˆØˆrT   c                ó*   — t          | j        ¦  «        S r  )r  rf  rR   s    rA   r  zScheduleBlock.__len__  s   € å�4”;ÑÔÐrT   r  r   c                ó  — t          |t          | ¦  «        ¦  «        sdS | j        |j        k    rdS t          | ¦  «        t          |¦  «        k    rdS ddlm} t          j         || ¦  «         ||¦  «        d„ ¦  «        sdS dS )aæ  Test if two ScheduleBlocks are equal.

        Equality is checked by verifying there is an equal instruction at every time
        in ``other`` for every instruction in this ``ScheduleBlock``. This check is
        performed by converting the instruction representation into directed acyclic graph,
        in which execution order of every instruction is evaluated correctly across all channels.
        Also ``self`` and ``other`` should have the same alignment context.

        .. warning::

            This does not check for logical equivalency. Ie.,

            ```python
            >>> Delay(10, DriveChannel(0)) + Delay(10, DriveChannel(0))
                == Delay(20, DriveChannel(0))
            False
            ```
        Fr   )Úblock_to_dagc                ó   — | |k    S rz   r’   )ÚxÚys     rA   ú<lambda>z&ScheduleBlock.__eq__.<locals>.<lambda>>  s   € ÈqÐTUÊv€ rT   T)r6   rå   r]  r  Úqiskit.pulse.transforms.dagr�  ÚrxÚis_isomorphic_node_match)r>   r  Údags      rA   r'  zScheduleBlock.__eq__  s¡   € õ( ˜%¥ d¡¤Ñ,Ô,ð 	Ø�5ð Ô! UÔ%<Ò<Ð<Ø�5õ ˆt‰9Œ9�˜E™
œ
Ò"Ð"Ø�5ð 	DÐCÐCÐCÐCÐCåÔ*¨3¨3¨t©9¬9°c°c¸%±j´jÐBUÐBUÑVÔVð 	Ø�5àˆtrT   c           	     ó"  — | j         rt          | j         ¦  «        nd}d                     d„ | j        d d…         D ¦   «         ¦  «        }t	          | j        ¦  «        dk    r|dz  }| j        j        › d|› d|› d	t          | j        ¦  «        › d
�S )Nrâ   rð   c                ó,   — g | ]}t          |¦  «        ‘ŒS r’   r*  r,  s     rA   r±   z*ScheduleBlock.__repr__.<locals>.<listcomp>E  s   € ÐFÐFÐF¨E�D ™KœKÐFÐFÐFrT   r.  r/  r0  r1  r2  z", transform=ú))	r4   r3  r4  rf  r  rL   rK   r+  r]  )r>   r   rf  s      rA   r5  zScheduleBlock.__repr__C  s³   € Ø%)¤ZÐ7�v�d”jÑ!Ô!Ð!°RˆØ—’ÐFÐF°T´[ÀÀ"ÀÔ5EÐFÑFÔFÑGÔGˆÝˆtŒ{ÑÔ˜bÒ Ð Ø�gÑˆFàŒ~Ô&ð :ð :¨ð :ð :¸ð :ð :Ý˜tÔ5Ñ6Ô6ð:ð :ð :ð	
rT   c                ó,   — |                       |¦  «        S r  r  r  s     rA   r  zScheduleBlock.__add__M  r  rT   )NNN)r   r"   r   r#   rz   )rC   r
   r   r"   rD   r^  r6  r7  r=  r8  r9  )rD   rn  )rD   rp  r:  )rD   r   r;  )NT)rZ  rz  r   r"   r¢   r£   rD   r^  )rÈ   r  rh   rÉ   rÅ   rÊ   rÇ   r£   r>  )rõ   rz  rö   rz  r¢   r£   rD   r^  )r  r  r¢   r£   rD   r^  )r�  r‘  r¢   r£   rD   r^  r?  r@  )r  rz  rD   r^  )(rK   rA  rB  rC  Ú	__slots__r+   rD  rE  r.   r   rB   rF  rO   rG  r   r   rH  r]  rg  rS  re   rh   r„   rf  r‡   rr  rŒ   r¾   rÙ   rÛ   r  r  r|  r  r“  r  r  r'  r5  r  r’   rT   rA   rU  rU  3  s|  € € € € € ðUð Uðn€Ið €Fð (˜	œÑ)Ô)ÐààW[ð,(ð ,(ð ,(ð ,(ñ Ôð,(ð\ ðð ð ð ñ „[ððB ðð ð ñ „Xðð ð
ð 
ð 
ñ „Xð
ð „_ð(ð (ñ „_ð(ð ð'ð 'ñ „Xð'ðð ð ð ð( Ø!ðð ð ñ "Ô!ñ „Xðð ð
ð 
ð 
ñ „Xð
ð Ø!ð!ð !ð !ñ "Ô!ñ „Xð!ð ðð ð ñ „Xðð& ðð ð ñ „Xðð ð'ð 'ð 'ñ „Xð'ð "ð+ð +ð +ñ "Ô!ð+ð QUð;ð ;ð ;ð ;ð ;ð@ .2ØAEØ!%ð%
ð %
ð %
ð %
ð %
ð %
ðT .2ØAEØ!%ð$
ð $
ð $
ð $
ð $
ð $
ðT ð	Bð Bð Bð Bð BðH$ð $ð $ð $ð(ð (ð (ð (ð ð%ð %ð %ð %ð %ðT ðNð Nð Nð Nð Nð` ð  ð  ð  ðD ð  ð  ð  ð%ð %ð %ð %ðN
ð 
ð 
ð 
ð"ð "ð "ð "ð "ð "rT   rU  c                 ó   ‡ — ˆ fd„}|S )aÞ  A function decorator to attach the function to specified classes as a method.

    .. note:: For developer: A method attached through this decorator may hurt readability
        of the codebase, because the method may not be detected by a code editor.
        Thus, this decorator should be used to a limited extent, i.e. huge helper method.
        By using this decorator wisely, we can reduce code maintenance overhead without
        losing readability of the codebase.
    c                ó~   •‡ — t          j        ‰ ¦  «        ˆ fd„¦   «         }‰D ]}t          |‰ j        |¦  «         Œ‰ S )Nc                 ó   •—  ‰| i |¤ŽS rz   r’   )rN  rO  Úmethods     €rA   rP  z2_common_method.<locals>.decorator.<locals>.wrapper]  s   ø€ à�6˜4Ð* 6Ð*Ð*Ð*rT   )rQ  rR  ÚsetattrrK   )r®  rP  rM   Úclassess   `  €rA   Ú	decoratorz!_common_method.<locals>.decorator\  s_   øø€ Ý	Œ˜Ñ	 Ô	 ð	+ð 	+ð 	+ð 	+ñ 
!Ô	 ð	+ð ð 	3ð 	3ˆCÝ�C˜œ¨'Ñ2Ô2Ð2Ð2ØˆrT   r’   )r°  r±  s   ` rA   Ú_common_methodr²  R  s$   ø€ ðð ð ð ð ð ÐrT   Úshow_barriersÚplot_barriersz1.4)Ú	new_aliasÚsinceÚdtTÚmpl2dÚstyleúdict[str, Any] | NoneÚ
time_rangeútuple[int, int] | NoneÚ	time_unitr,   Údisable_channelsúlist[Channel] | NoneÚshow_snapshotr£   Úshow_framechangeÚshow_waveform_infoÚplot_barrierÚplotterÚaxisú
Any | NoneÚshow_barrierc                ó>   — ddl m} ~ || |||||||||	|
|¬¦  «        S )a	  Plot the schedule.

    Args:
        style: Stylesheet options. This can be dictionary or preset stylesheet classes. See
            :py:class:`~qiskit.visualization.pulse_v2.stylesheets.IQXStandard`,
            :py:class:`~qiskit.visualization.pulse_v2.stylesheets.IQXSimple`, and
            :py:class:`~qiskit.visualization.pulse_v2.stylesheets.IQXDebugging` for details of
            preset stylesheets.
        backend (Optional[BaseBackend]): Backend object to play the input pulse program.
            If provided, the plotter may use to make the visualization hardware aware.
        time_range: Set horizontal axis limit. Tuple ``(tmin, tmax)``.
        time_unit: The unit of specified time range either ``dt`` or ``ns``.
            The unit of `ns` is available only when ``backend`` object is provided.
        disable_channels: A control property to show specific pulse channel.
            Pulse channel instances provided as a list are not shown in the output image.
        show_snapshot: Show snapshot instructions.
        show_framechange: Show frame change instructions. The frame change represents
            instructions that modulate phase or frequency of pulse channels.
        show_waveform_info: Show additional information about waveforms such as their name.
        plot_barrier: Show barrier lines.
        plotter: Name of plotter API to generate an output image.
            One of following APIs should be specified::

                mpl2d: Matplotlib API for 2D image generation.
                    Matplotlib API to generate 2D image. Charts are placed along y axis with
                    vertical offset. This API takes matplotlib.axes.Axes as ``axis`` input.

            ``axis`` and ``style`` kwargs may depend on the plotter.
        axis: Arbitrary object passed to the plotter. If this object is provided,
            the plotters use a given ``axis`` instead of internally initializing
            a figure object. This object format depends on the plotter.
            See plotter argument for details.
        show_barrier: DEPRECATED. Show barrier lines.

    Returns:
        Visualization output data.
        The returned data type depends on the ``plotter``.
        If matplotlib family is specified, this will be a ``matplotlib.pyplot.Figure`` data.
    r   )Úpulse_drawer)Úprogramr¹  Úbackendr»  r½  r¾  rÀ  rÁ  rÂ  rÃ  rÄ  rÅ  )Úqiskit.visualizationrÉ  )r>   r¹  rË  r»  r½  r¾  rÀ  rÁ  rÂ  rÃ  rÄ  rÅ  rÇ  rÉ  s                 rA   ÚdrawrÍ  h  sW   € ðr 2Ð1Ð1Ð1Ð1Ð1àØˆ<ØØØØØØ)Ø#Ø)Ø-Ø!ØØðñ ô ð rT   r”   úlist[Interval]rí   ÚIntervalrc   c                ól   — t          | |¦  «        }| |         }||k    rt          d|› d| › �¦  «        ‚|S )a0  Find the index of an interval.

    Args:
        intervals: A sorted list of non-overlapping Intervals.
        interval: The interval for which the index into intervals will be found.

    Returns:
        The index of the interval.

    Raises:
        PulseError: If the interval does not exist.
    zThe interval: z does not exist in intervals: )Ú_locate_interval_indexr   )r”   rí   rî   Úfound_intervals       rA   rñ   rñ   ´  sM   € õ # 9¨hÑ7Ô7€EØ˜uÔ%€NØ˜Ò!Ð!ÝÐ]¨(Ð]Ð]ÐR[Ð]Ð]Ñ^Ô^Ð^Ø€LrT   rî   c                ó  — | rt          | ¦  «        dk    r|S t          | ¦  «        dz  }| |         }|d         |d         k    r ||k    rt          | d|…         ||¬¦  «        S t          | |d…         |||z   ¬¦  «        S )a¶  Using binary search on start times, find an interval.

    Args:
        intervals: A sorted list of non-overlapping Intervals.
        interval: The interval for which the index into intervals will be found.
        index: A running tally of the index, for recursion. The user should not pass a value.

    Returns:
        The index into intervals that new_interval would be inserted to maintain
        a sorted list of intervals.
    rx   é   r   N)rî   )r  rÑ  )r”   rí   rî   Úmid_idxÚmids        rA   rÑ  rÑ  È  s—   € ð ð �˜I™œ¨!Ò+Ð+Øˆå�)‰nŒn Ñ!€GØ
�GÔ
€CØ�„{�c˜!”fÒÐ (¨c¢/ /Ý% i°°°Ô&9¸8È5ÐQÑQÔQÐQå% i°°°Ô&9¸8È5ÐSZÉ?Ð[Ñ[Ô[Ð[rT   Únew_intervalc                óÔ   — t          | |¦  «        }|t          | ¦  «        k     rDt          | |         |¦  «        rt          d¦  «        ‚|d         | |         d         k    r|n|dz   S |S )a)  Using binary search on start times, return the index into `intervals` where the new interval
    belongs, or raise an error if the new interval overlaps with any existing ones.
    Args:
        intervals: A sorted list of non-overlapping Intervals.
        new_interval: The interval for which the index into intervals will be found.
    Returns:
        The index into intervals that new_interval should be inserted to maintain a sorted list
        of intervals.
    Raises:
        PulseError: If new_interval overlaps with the given intervals.
    z$New interval overlaps with existing.rx   r   )rÑ  r  Ú	_overlapsr   )r”   r×  rî   s      rA   ré   ré   ß  sv   € õ # 9¨lÑ;Ô;€EØ�s�9‰~Œ~ÒÐÝ�Y˜uÔ% |Ñ4Ô4ð 	EÝÐCÑDÔDÐDØ$ Qœ¨9°UÔ+;¸AÔ+>Ò>Ð>ˆuˆuÀEÈAÁIÐMØ€LrT   ÚfirstÚsecondc                óš   — | d         |d         cxk    r|d         k    rn ndS | d         |d         k    r|| }} |d         | d         k     S )z„Return True iff first and second overlap.
    Note: first.stop may equal second.start, since Interval stop times are exclusive.
    r   rx   Fr’   )rÚ  rÛ  s     rA   rÙ  rÙ  ó  sf   € ð ˆQ„x�6˜!”9Ð)Ð)Ò)Ð)  q¤	Ò)Ð)Ð)Ð)Ð)àˆuØˆQ„x�&˜”)ÒÐØ ˆvˆØ�!Œ9�u˜Q”xÒÐrT   rb   r_   c                óˆ   — |                       ¦   «         D ],\  }}|r%|d         d         dk     rt          d|› d�¦  «        ‚Œ-dS )zwTest that a channel has no negative timeslots.

    Raises:
        PulseError: If a channel timeslot is negative.
    r   zAn instruction on z has a negative starting time.N)rµ   r   )rb   r}   Úchan_timeslotss      rA   r¶   r¶   ÿ  si   € ð !*§¢Ñ 1Ô 1ð \ð \ÑˆˆnØð 	\Ø˜aÔ  Ô# aÒ'Ð'Ý Ð!Z°dÐ!ZÐ!ZÐ!ZÑ[Ô[Ð[øð\ð \rT   r¸   r¹   c                ó   ‡— t          | t          ¦  «        r*| j        Št          ‰¦  «         ˆfd„| j        D ¦   «         }n=t          | t
          ¦  «        r| j        }n t          dt          | ¦  «        › d�¦  «        ‚|S )z·Generate timeslots from given schedule component.

    Args:
        schedule: Input schedule component.

    Raises:
        PulseError: When invalid schedule type is specified.
    c                ó   •— i | ]}|d ‰fg“Œ	S r<  r’   )r|   rë   re   s     €rA   ú
<dictcomp>z"_get_timeslots.<locals>.<dictcomp>  s!   ø€ ÐOÐOÐO°'�W  8˜}˜oÐOÐOÐOrT   zInvalid schedule type z is specified.)	r6   r   re   r   rh   r   rb   r   rå   )r¸   rb   re   s     @rA   rç   rç     s�   ø€ õ �(�KÑ(Ô(ð RØÔ$ˆÝ'¨Ñ1Ô1Ð1ØOÐOÐOÐO¸XÔ=NÐOÑOÔOˆ	ˆ	Ý	�H�hÑ	'Ô	'ð RØÔ&ˆ	ˆ	åÐPµ$°x±.´.ÐPÐPÐPÑQÔQÐQàÐrT   Ú
block_elmsúlist['BlockComponent']úset[Reference]c                óÚ   — t          ¦   «         }| D ]Y}t          |t          ¦  «        r|t          |j        ¦  «        z  }Œ/t          |t
          ¦  «        r|                     |¦  «         ŒZ|S )zÎRecursively get reference instructions in the current scope.

    Args:
        block_elms: List of schedule block elements to investigate.

    Returns:
        A set of unique reference instructions.
    )rÃ   r6   rU  r}  rY  r   Úadd)râ  rr  ri  s      rA   r}  r}     so   € õ ‘”€JØð  ð  ˆÝ�c�=Ñ)Ô)ð 	 Ø�/¨#¬+Ñ6Ô6Ñ6ˆJˆJÝ˜�YÑ'Ô'ð 	 Ø�NŠN˜3ÑÔÐøØÐrT   )rI  r   rD   r   )NNNr·  NTTTTr¸  NT)r¹  rº  r»  r¼  r½  r,   r¾  r¿  rÀ  r£   rÁ  r£   rÂ  r£   rÃ  r£   rÄ  r,   rÅ  rÆ  rÇ  r£   )r”   rÎ  rí   rÏ  rD   rc   r<  )r”   rÎ  rí   rÏ  rî   rc   rD   rc   )r”   rÎ  r×  rÏ  rD   rc   )rÚ  rÏ  rÛ  rÏ  rD   r£   )rb   r_   )r¸   r¹   rD   r_   )râ  rã  rD   rä  )CrC  Ú
__future__r   ÚabcrI   rQ  rD  Úmultiprocessingr1   r/   r…  Úcollections.abcr   r   Útypingr   r   r   r	   r
   r   Únumpyrã   Ú	rustworkxr£  Úqiskit.circuitr   Úqiskit.circuit.parameterr   Ú"qiskit.circuit.parameterexpressionr   r   Úqiskit.pulse.channelsr   Úqiskit.pulse.exceptionsr   r   Úqiskit.pulse.instructionsr   r   Úqiskit.pulse.utilsr   Úqiskit.pulse.reference_managerr   Úqiskit.utils.multiprocessingr   Úqiskit.utilsr   Úqiskit.utils.deprecate_pulser   rc   rÏ  r_   r   rS  rU  r²  rÍ  rñ   rÑ  ré   rÙ  r¶   rç   r}  ÚScheduleComponentÚBlockComponentr’   rT   rA   ú<module>rû     s—  ððð ð$ #Ð "Ð "Ð "Ð "Ð "Ø 
€
€
€
Ø €€€Ø Ð Ð Ð Ø Ð Ð Ð Ø Ð Ð Ð Ø 
€
€
€
Ø €€€Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :à Ð Ð Ð Ø Ð Ð Ð à *Ð *Ð *Ð *Ð *Ð *Ø .Ð .Ð .Ð .Ð .Ð .Ø VÐ VÐ VÐ VÐ VÐ VÐ VÐ VØ )Ð )Ð )Ð )Ð )Ð )Ø HÐ HÐ HÐ HÐ HÐ HÐ HÐ HØ <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø >Ð >Ð >Ð >Ð >Ð >Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø &Ð &Ð &Ð &Ð &Ð &Ø =Ð =Ð =Ð =Ð =Ð =ð ��c�Œ?€Ø Zà�˜$˜xœ.Ð(Ô)€	Ø Bð^Kð ^Kð ^Kð ^Kð ^Kñ ^Kô ^Kð ^KðBð ð ð ð\"ð \"ð \"ð \"ð \"ñ \"ô \"ð \"ð~ð ð ð, €ˆ¨/ÀÐGÑGÔGØ€�˜-Ñ(Ô(ð $(ØØ)-ØØ-1ØØ!Ø#ØØØØðGð Gð Gð Gñ )Ô(ñ HÔGðGðTð ð ð ð(\ð \ð \ð \ð \ð.ð ð ð ð(	 ð 	 ð 	 ð 	 ð	\ð 	\ð 	\ð 	\ðð ð ð ð*ð ð ð ð4 ˜( KÐ/Ô0Ð Ø 0à�} kÐ1Ô2€Ø 6Ð 6rT   