
    i                     :   S r SSKJrJrJrJrJr  SSKrSSKrSSK	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JrJr  SS	KJr  S
\\   SS4S jrS
\\   SS4S jrS\\   S\SS4S jrS
\\\   \\   4   SS4S jrS\\   S\SS4S jrS\\\      SS4S jrg)zUtilities for data validation.    )ListSequenceOptionalAnyUnionN)QuantumCircuit)Target)
SamplerPub)EstimatorPub)is_isa_circuitare_circuits_dynamicis_valid_rzz_pub)IBMInputValueErrorpubsreturnc                 ,   [        U 5       GH  u  p[        UR                  R                  5      S:X  a  [        R
                  " SU S3[        5        UR                  R                   H  nUR                  S:X  a  [        SUR                   S35      eUR                  R                  5       (       d  [        SUR                   S35      e[        R                  " UR                  5      (       d  M  [        SUR                   S	35      e   GM     g
)a}  Validates the classical registers in the pub won't cause problems that can be caught client-side.

Args:
    pubs: The list of pubs to validate

Raises:
    IBMInputValueError: If any circuit has a size-0 creg.
    IBMInputValueError: If any circuit has a creg whose name is not a valid identifier.
    IBMInputValueError: If any circuit has a creg whose name is a Python keyword.
r   zThe zx-th circuit has no output classical registers so the result will be empty. Did you mean to add measurement instructions?zClassical register z# is of size 0, which is not allowedz8Classical register names must be valid identifiers, but zt is not. Valid identifiers contain only alphanumeric letters (a-z and A-Z), decimal digits (0-9), or underscores (_)z8Classical register names cannot be Python keywords, but z is such a keyword. You can see the Python keyword list here: https://docs.python.org/3/reference/lexical_analysis.html#keywordsN)	enumeratelencircuitcregswarningswarnUserWarningsizer   nameisidentifierkeyword	iskeyword)r   indexpubregs       ^/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/utils/validations.pyvalidate_classical_registersr#      s     o
s{{  !Q&MMug O O ;;$$Cxx1}()#((3VW  88((**(Nsxxj YN O 
   **(Nsxxj YY Z  % &    c                     U  H  nUR                   R                  S:X  a  [        S5      e[        R                  " UR                   R                  5       5       H.  nU H%  n[        S U 5       5      (       d  M  [        S5      e   M0     M     g)zValidates the estimator pubs won't cause problems that can be caught client-side.

Args:
    pubs: The list of pubs to validate

Raises:
    IBMInputValueError: If any observable array is of size 0
)r   z&Empty observables array is not allowedc              3   *   #    U  H	  oS ;  v   M     g7f))IXYZN ).0single_paulis     r"   	<genexpr>*validate_estimator_pubs.<locals>.<genexpr>R   s     ZTYL+??TYs   z-Observables alphabet is limited to I, X, Y, ZN)observablesshaper   nparrayravelany)r   r    obspaulis       r"   validate_estimator_pubsr8   C   st     ??  D($%MNN88COO1134CZTYZZZ,-\]]  5	 r$   circuitstargetc                 V    U  H#  n[        X!5      nU(       d  M  [        US-   5      e   g)zyValidate if all circuits are ISA circuits

Args:
    circuits: A list of QuantumCircuits.
    target: The backend target
av   Circuits that do not match the target hardware definition are no longer supported after March 4, 2024. See the transpilation documentation (https://quantum.cloud.ibm.com/docs/guides/transpile) for instructions to transform circuits and the primitive examples (https://quantum.cloud.ibm.com/docs/guides/primitives-examples) to see this coupled with operator transformations.N)r   r   )r9   r:   r   messages       r"   validate_isa_circuitsr=   V   s7      17$>>  r$   c                 P    U  H   n[        U5      nU(       d  M  [        U5      e   g)z\Validate that rzz angles are always in the range [0, pi/2]

Args:
    pubs: A list of pubs.
N)r   r   )r   r    r<   s      r"   validate_rzz_pubsr?   k   s(     "3'7$W-- r$   optionsc                     [        US5      (       a  UR                  R                  (       d  g[        U S5      (       a  [	        S5      eg)zValidate that if dynamical decoupling options are enabled,
no circuit in the pubs is dynamic

Args:
    circuits: A list of QuantumCircuits.
    options: The runtime options
dynamical_decouplingNFzCDynamical decoupling currently cannot be used with dynamic circuits)hasattrrB   enabler   r   )r9   r@   s     r"   $validate_no_dd_with_dynamic_circuitsrE   w   sE     72337;W;W;^;^He,, Q
 	
 -r$   job_tagsc                     U (       a8  [        U [        5      (       a  [        S U  5       5      (       d  [        S5      egg)zValidates input job tags.

Args:
    job_tags: Job tags to be validated.

Raises:
    IBMInputValueError: If the job tags are invalid.
c              3   B   #    U  H  n[        U[        5      v   M     g 7f)N)
isinstancestr)r,   tags     r"   r.   $validate_job_tags.<locals>.<genexpr>   s     1[RZ3*S#2F2FRZs   z'job_tags needs to be a list of strings.N)rI   listallr   )rF   s    r"   validate_job_tagsrO      s<     x&&c1[RZ1[.[.[ !JKK /\ r$   ) __doc__typingr   r   r   r   r   r   r   numpyr2   qiskitr   qiskit.transpilerr	   (qiskit.primitives.containers.sampler_pubr
   *qiskit.primitives.containers.estimator_pubr   qiskit_ibm_runtime.utils.utilsr   r   r   qiskit_ibm_runtime.exceptionsr   r#   r8   r=   r?   rE   rJ   rO   r+   r$   r"   <module>rY      s    % 7 7    ! $ ? C a a <%tJ'7 %D %P^$|"4 ^ ^&H^$< f QU *	.E$|"4d:6F"FG 	.D 	.
43G 
RU 
Z^ 
 Lc 3 L Lr$   