
    z	i(              
      L   S r SSKJr  SSKJrJrJrJrJr  SSK	r
SSK	JrJrJrJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr   " S S5      r\\\\\\\      \\\\      \4      \\\\\\      \\\\      4      \\\\\\      \\4      \\\\\\      \4      \4   rg)z<Durations of instructions, one of transpiler configurations.    )annotations)OptionalListTupleUnionIterableN)BarrierDelayInstructionParameterExpression)duration_in_dt)Backend)	BackendV2)TranspilerError)apply_prefixc                      \ rS rSrSr S   SS jjrS r\SS j5       rSSS jjr	  S         SS jjr
 S         SS	 jjrSS
 jrSS jrSrg)InstructionDurations   a  Helper class to provide durations of instructions for scheduling.

It stores durations (gate lengths) and dt to be used at the scheduling stage of transpiling.
It can be constructed from ``backend`` or ``instruction_durations``,
which is an argument of :func:`transpile`. The duration of an instruction depends on the
instruction (given by name), the qubits, and optionally the parameters of the instruction.
Note that these fields are used as keys in dictionaries that are used to retrieve the
instruction durations. Therefore, users must use the exact same parameter value to retrieve
an instruction duration as the value with which it was added.
Nc                l    0 U l         0 U l        0 U l        X l        U(       a  U R	                  U5        g g N)duration_by_nameduration_by_name_qubitsduration_by_name_qubits_paramsdtupdate)selfinstruction_durationsr   s      a/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/instruction_durations.py__init__InstructionDurations.__init__&   s>     ?A]_$  	+  KK-. !    c                Z   SnU R                   R                  5        H-  u  p#X-  nUS-  nU[        US   5      S-   US   -   -  nUS-  nM/     U R                  R                  5        H?  u  p#XS   [        US   5      -   -  nUS-  nU[        US   5      S-   US   -   -  nUS-  nMA     U$ )z7Return a string representation of all stored durations. z: r       
)r   itemsstrr   )r   stringkvs       r   __str__InstructionDurations.__str__2   s    ))//1DAKFdNFc!A$i#o!,,FdNF	 2
 00668DAdS1Y&&FdNFc!A$i#o!,,FdNF	 9
 r!   c                v    [        U[        5      (       a  UR                  R                  5       $ [	        S5      e)aj  Construct an :class:`InstructionDurations` object from the backend.

Args:
    backend: backend from which durations (gate lengths) and dt are extracted.

Returns:
    InstructionDurations: The InstructionDurations constructed from backend.

Raises:
    TranspilerError: If dt and dtm is different in the backend.
    TypeError: If the backend is the wrong type
z#Unsupported backend type: {backend})
isinstancer   target	durations	TypeError)clsbackends     r   from_backend!InstructionDurations.from_backendA   s0     gy))>>++--=>>r!   c                   U(       a  X l         Uc  U $ [        U[        5      (       aq  U R                  R	                  UR                  5        U R
                  R	                  UR
                  5        U R                  R	                  UR                  5        U $ [        U5       H  u  p4[        US   [        5      (       d  / UQSP7n[        U5      S:X  a  / USS QSPUS   P7X'   OXAU'   [        X   5      S:w  a  [        SX    S35      eX   S	   b  Mu  [        S
X    S35      e   U H  u  pVpxn	[        U[        5      (       a  U/n[        U[        [        45      (       a  U/nUc  Xy4U R                  U'   MR  Uc  Xy4U R
                  U[        U5      4'   Mr  U[        U5      [        U5      4n
Xy4U R                  U
'   M     U $ )ap  Update self with inst_durations (inst_durations overwrite self).

Args:
    inst_durations: Instruction durations to be merged into self (overwriting self).
    dt: Sampling duration in seconds of the target backend.

Returns:
    InstructionDurations: The updated InstructionDurations.

Raises:
    TranspilerError: If the format of instruction_durations is invalid.
Nr            zEach entry of inst_durations dictionary must be (inst_name, qubits, duration) or (inst_name, qubits, duration, unit) or(inst_name, qubits, duration, parameters) or(inst_name, qubits, duration, parameters, unit) received .   zNone duration for )r   r/   r   r   r   r   r   	enumerater(   lenr   intfloattuple)r   inst_durationsr   ir'   namequbitsduration
parametersunitkeys              r   r   InstructionDurations.updateT   s    G!Kn&:;;!!(()H)HI((//0V0VW//66==T M &n5!%)S11*eNTNEu:?(D%)(DT(D58(DN%(-1% ~()Q.)$
 %3$5#6a9  "$Q'/),>~?P>QQR*STT+ 6. =K8hDfc**$XFj3,77",J>2:.D))$/'JR.D00$f1FGvj0ABC?G~D77< =K r!   c                   [        U[        5      (       a  g[        U[        5      (       a'  U R                  UR                  UR
                  U5      $ [        U[        5      (       a  UR                  nOUn[        U[        5      (       a  U/n U R                  XRX45      $ ! [         a  n[        SU SU S35      UeSnAff = f)a  Get the duration of the instruction with the name, qubits, and parameters.

Some instructions may have a parameter dependent duration.

Args:
    inst: An instruction or its name to be queried.
    qubits: Qubit indices that the instruction acts on.
    unit: The unit of duration to be returned. It must be 's' or 'dt'.
    parameters: The value of the parameters of the desired instruction.

Returns:
    float|int: The duration of the instruction on the qubits.

Raises:
    TranspilerError: No duration is defined for the instruction.
r   zDuration of z on qubits z is not found.N)r/   r	   r
   _convert_unitrG   rI   r   rE   r@   _getr   )r   instrF   rI   rH   	inst_nameexs          r   getInstructionDurations.get   s    . dG$$e$$%%dmmTYYEEdK((		IIfc""XF	99YAA 	!ykVHNK	s   B" "
C,B??Cc                f   US:X  a  gUb  U[        U5      [        U5      4nOU[        U5      4nXPR                  ;   a  U R                  U   u  pgOPXPR                  ;   a  U R                  U   u  pgO/XR                  ;   a  U R                  U   u  pgO[	        SU 35      eU R                  XgU5      $ )zJGet the duration of the instruction with the name, qubits, and parameters.barrierr   zNo value is found for key=)rB   r   r   r   r   rM   )r   rE   rF   to_unitrH   rJ   rG   rI   s           r   rN   InstructionDurations._get   s     9!vj(9:Cv'C555!@@ENHd000!99#>NHd***!2248NHd!$>se"DEE!!('::r!   c                   UR                  S5      (       a  US:w  a  [        X5      nSnX#:X  a  U$ U R                  c  [        SU SU S35      eUS:X  a>  US:X  a8  [	        U[
        5      (       a  XR                  -  $ [        XR                  5      $ US:X  a  US:X  a  XR                  -  $ [        SU SU S35      e)Nsz+dt is necessary to convert durations from 'z' to ''r   zConversion from 'z' is not supported)endswithr   r   r   r/   r   r   )r   rG   	from_unitrV   s       r   rM   "InstructionDurations._convert_unit   s    c""yC'7#H8HI O77?!=i[wiWXY  4($788''))!(GG44$7c>gg%%!$5i[wiOa"bccr!   c                    [        5       nU R                  R                  5        H  u  p#UR                  U5        M     U R                  R                  5        H  u  p#UR                  U5        M     U$ )z|Get the set of all units used in this instruction durations.

Returns:
    Set of units used in this instruction durations.
)setr   valuesaddr   )r   
units_used_rI   s       r   rb   InstructionDurations.units_used   s_     U
33::<GANN4  =,,335GANN4  6r!   )r   r   r   r   )NN)r   !'InstructionDurationsType' | Noner   rA   )r4   r   r   )rC   re   r   rA   )r   N)
rO   z str | qiskit.circuit.InstructionrF   zint | list[int]rI   r(   rH   zlist[float] | NonereturnrA   )
rE   r(   rF   z	list[int]rV   r(   rH   zIterable[float] | Nonerf   rA   )rG   rA   r\   r(   rV   r(   rf   rA   )rf   zset[str])__name__
__module____qualname____firstlineno____doc__r   r,   classmethodr5   r   rR   rN   rM   rb   __static_attributes__ r!   r   r   r      s    	 \`
/%F
/SX
/ ? ?$@L )-).)  ) 	)
 ') 
)` .2;; ; 	;
 +; 
;6d,r!   r   )rk   
__future__r   typingr   r   r   r   r   qiskit.circuitqiskitr	   r
   r   r   qiskit.circuit.durationr   qiskit.providersr   qiskit.providers.backendr   qiskit.transpiler.exceptionsr   qiskit.utils.unitsr   r   r(   r@   rA   InstructionDurationsTypern   r!   r   <module>ry      s    C " 9 9  K K 2 $ . 8 +c cL !sHXc]+UHXe_4MsR	STsHXc]+UHXe_4MM	NOsHXc]+UC7	89sHXc]+U2	34	  \r!   