
    z	i)                         S r SSKrSSKrSSKJr  SSKrSSKJr  SSK	J
r
JrJr  SSKJr  SSKJr  SS jrSS	 jrS
 rSS jrSS jrSS jrSS jrSS jrS rSS jrSS jrSS jrg)a  Read schedule and schedule instructions.

This module is kept post pulse-removal to allow reading legacy
payloads containing pulse gates without breaking the load flow.
The purpose of the `_read` and `_load` methods below is just to advance
the file handle while consuming pulse data.    N)BytesIO)QiskitError)formatscommon	type_keys)value)QpyErrorc                 ^    [         R                  " U 5        [        R                  " X0 5        g N)r   read_type_keyr   
read_valuefile_objversions     X/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/qpy/binary_io/schedules.py_read_channelr       s     
"	X+    c                 p   [         R                  R                  [        R                  " [         R
                  U R                  [         R                  5      5      5      nU R                  UR                  5      n[        R                  " U[        R                  5        [        R                  " X0 5        g r   )r   WAVEFORM_makestructunpackWAVEFORM_PACKreadWAVEFORM_SIZE	data_sizer   data_from_binarynploadr   r   )r   r   headersamples_raws       r   _read_waveformr"   %   sy    ##!!MM'//0	
F -- 0 01K
K1	X+r   c                 H   U S:X  a/  [        U5       n[        R                  " U[        X#S9sSSS5        $ U S:X  a/  [        U5       n[        R                  " U[        X#S9sSSS5        $ [
        R                  " XX#5      $ ! , (       d  f       g= f! , (       d  f       g= f)zWraps `value.loads_value` to deserialize binary data to dictionary
or list objects which are not supported by `value.loads_value`.
   Dr   deserializerr   vectorsN   l)r   r   read_mapping
_loads_objread_sequencer   loads_value)type_keybinary_datar   r'   	containers        r   r*   r*   1   s     4[!Y&&"W "! 
T	[!Y''"W "!
   II "!
 "!s   BB
B
B!c                 h    [         R                  " U [        U0 S9  [        R                  " X0 5        g Nr%   r   r)   r*   r   r   r   s     r   _read_kernelr3   C   s.    
	 
X+r   c                 h    [         R                  " U [        U0 S9  [        R                  " X0 5        g r1   r2   r   s     r   _read_discriminatorr5   M   s.    
	 
X+r   c                    [         R                  R                  n[         R                  n[         R                  nU" [
        R                  " UU R                  U5      5      5      nU R                  UR                  5      R                  [        R                  5      nU R                  UR                  5        U R                  UR                  5        U R                  UR                  5        [        R                  " U [         R"                  U0 S9  / SQnSnXg;   a  Sn[         R$                  " X0 5        [         R$                  " X0 5        US;  a  ['        SU S35      eg )Nr&   r   r'   )GaussianGaussianSquareDragConstantSymbolicPulseScalableSymbolicPulse   r<   r=   Unknown class '')r   SYMBOLIC_PULSEr   SYMBOLIC_PULSE_PACKSYMBOLIC_PULSE_SIZEr   r   r   	type_sizedecoder   ENCODEenvelope_sizeconstraints_sizevalid_amp_conditions_sizer)   r   r,   r   NotImplementedError)	r   r   makepacksizer    
pulse_typelegacy_library_pulses
class_names	            r   _read_symbolic_pulserQ   X   s%   !!''D&&D&&DMM$	
F v//077FJMM&&&'MM&))*MM&223
&&	 O J*,
	X+	X+CC!OJ<q"ABB Dr   c                 "   [         R                  R                  n[         R                  n[         R                  nU" [
        R                  " UU R                  U5      5      5      nU R                  UR                  5      R                  [        R                  5      nU R                  UR                  5      R                  [        R                  5        U R                  UR                  5        U R                  UR                  5        U R                  UR                  5        [        R                   " U ["        R$                  U0 S9  ["        R&                  " X0 5        ["        R&                  " X0 5        US;  a  [)        SU S35      eg )Nr7   r>   r?   r@   )r   SYMBOLIC_PULSE_V2r   SYMBOLIC_PULSE_PACK_V2SYMBOLIC_PULSE_SIZE_V2r   r   r   class_name_sizerE   r   rF   rD   rG   rH   rI   r)   r   r,   r   rJ   )r   r   rK   rL   rM   r    rP   s          r   _read_symbolic_pulse_v6rW      s/   $$**D))D))DMM$	
F v556==fmmLJMM&""#**6==9MM&&&'MM&))*MM&223
&&	 
X+	X+CC!OJ<q"ABB Dr   c                 z    [         R                  " U 5        [         R                  " U [        R                  U0 S9  g )Nr7   )r   r   r+   r   r,   r   s     r   _read_alignment_contextrY      s0    
"
&&	r   c                    U [         R                  R                  :X  a  [        R                  " U[
        US9$ U [         R                  R                  :X  a:  US:  a  [        R                  " U[        US9$ [        R                  " U[        US9$ U [         R                  R                  :X  a  [        R                  " U[        US9$ U [         R                  R                  :X  a  UR                  [        R                  5      $ U [         R                  R                  :X  a  [        R                  " U[        US9$ U [         R                  R                   :X  a  [        R                  " U["        US9$ [$        R&                  " XU0 5      $ )N)r      )r   ScheduleOperandr   r   r   r"   rA   rQ   rW   CHANNELr   OPERAND_STRrE   rF   KERNELr3   DISCRIMINATORr5   r   r,   )r-   
data_bytesr   s      r   _loads_operandrb      s?   9,,555&&z>7SS9,,;;;Q;**:7KU\]]**:7NX_``9,,444&&z='RR9,,888  //9,,333&&
 	

 9,,:::&&
 	
 X7B??r   c                     [         R                  " U 5      nU[        R                  R                  :X  a  [        XX#5      $ [         R                  " U [        US9  [        R                  " X0 5        g )N)r&   r   )
r   r   r   ProgramSCHEDULE_BLOCKread_schedule_blockr+   rb   r   r   )r   r   metadata_deserializeruse_symenginer-   s        r   _read_elementri      sb    ##H-H9$$333"86K[[ # 
X+r   c                     U [         R                  R                  :X  a  g U [         R                  R                  :X  a  [
        R                  " U[        UUS9$ [        SU  S35      e)N)r&   r   rg   zKLoaded schedule reference item is neither None nor ScheduleBlock. Type key zd is not valid data type for a reference items. This data cannot be loaded. Please check QPY version.)	r   ValueNULLrd   re   r   r   rf   r	   )r-   ra   rg   r   s       r   _loads_reference_itemrm      so    9??'''9$$333&&,"7	
 	
 : @	@ r   c                 d   US:  a  [        SU S35      e[        R                  R                  [        R
                  " [        R                  U R                  [        R                  5      5      5      nU R                  UR                  5      R                  [        R                  5        U R                  UR                  5      n[        R                  " XRS9  [!        X5        [#        UR$                  5       H  n['        XX#5        M     US:  a  [        R(                  " U [*        UUS9  gg)az  Consume a single ScheduleBlock from the file like object.

Args:
    file_obj (File): A file like object that contains the QPY binary data.
    version (int): QPY version.
    metadata_deserializer (JSONDecoder): An optional JSONDecoder class
        that will be used for the ``cls`` kwarg on the internal
        ``json.load`` call used to deserialize the JSON payload used for
        the :attr:`.ScheduleBlock.metadata` attribute for a schedule block
        in the file-like object. If this is not specified the circuit metadata will
        be parsed as JSON with the stdlib ``json.load()`` function using
        the default ``JSONDecoder`` class.
    use_symengine (bool): If True, symbolic objects will be serialized using symengine's
        native mechanism. This is a faster serialization alternative, but not supported in all
        platforms. Please check that your target platform is supported by the symengine library
        before setting this option, as it will be required by qpy to deserialize the payload.
Returns:
    QuantumCircuit: Returns a dummy QuantumCircuit object, containing just name and metadata.
    This function exists just to allow reading legacy payloads containing pulse information
    without breaking the entire load flow.

Raises:
    TypeError: If any of the instructions is invalid data format.
    QiskitError: QPY version is earlier than block support.
   zQPY version z  does not support ScheduleBlock.)cls   )r   r&   r   rg   N)r   r   SCHEDULE_BLOCK_HEADERr   r   r   SCHEDULE_BLOCK_HEADER_PACKr   SCHEDULE_BLOCK_HEADER_SIZE	name_sizerE   r   rF   metadata_sizejsonloadsrY   rangenum_elementsri   r)   rm   )r   r   rg   rh   datametadata_raw_s          r   rf   rf      s    4 {L	1QRSS((....MM'<<=	
D MM$..!((7==!3!34LJJ|7H.4$$%h)>N & !|."7		
 r   )returnN)NF)__doc__rw   r   ior   numpyr   qiskit.exceptionsr   
qiskit.qpyr   r   r   qiskit.qpy.binary_ior   qiskit.qpy.exceptionsr	   r   r"   r*   r3   r5   rQ   rW   rY   rb   ri   rm   rf    r   r   <module>r      sh   /     ) 1 1 & *,
	,J$,,(CVC>@8$$2
r   