
    z	i"                        S r SSKJr  SSKrSSKJ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   " S
 S\5      r\" \5        g)z
ScalarOp class
    )annotationsN)Number)QiskitError)BaseOperator)LinearOp)Operator)generate_apidocsc                     ^  \ rS rSrSrSSU 4S jjjrSS jrS r\S 5       r	S r
S rSS	 jrS
 rSS jrSSS jjrSS jrSS jrSS jrSS jrS r\SS j5       rSrU =r$ )ScalarOp   aa  Scalar identity operator class.

This is a symbolic representation of an scalar identity operator on
multiple subsystems. It may be used to initialize a symbolic scalar
multiplication of an identity and then be implicitly converted to other
kinds of operator subclasses by using the :meth:`compose`, :meth:`dot`,
:meth:`tensor`, :meth:`expand` methods.
c                t   > [        U[        5      (       d  [        SU S35      eX l        [        TU ]  XS9  g)zInitialize an operator object.

Args:
    dims (int or tuple): subsystem dimensions.
    coeff (Number): scalar coefficient for the identity
                    operator (Default: 1).

Raises:
    QiskitError: If the optional coefficient is invalid.
zcoeff z must be a number.
input_dimsoutput_dimsN)
isinstancer   r   _coeffsuper__init__)selfdimscoeff	__class__s      a/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/operators/scalar_op.pyr   ScalarOp.__init__'   s<     %((ug-?@AAD;    c                l    USL a  [        S5      eU R                  5       nUc  U$ UR                  USS9$ )NFz,could not produce matrix without calculationcopy)
ValueError	to_matrixastype)r   dtyper   arrs       r   	__array__ScalarOp.__array__7   s=    5=KLLnnmsFE)FFr   c                D    SU R                  5        SU R                   S3$ )Nz	ScalarOp(z, coeff=))r   r   r   s    r   __repr__ScalarOp.__repr__=   s#    4??,-Xdjj\CCr   c                    U R                   $ )zReturn the coefficientr   r(   s    r   r   ScalarOp.coeff@   s     {{r   c                p    U R                  5       n[        R                  " U R                  5      Ul        U$ N)r   np	conjugater   r   )r   rets     r   r1   ScalarOp.conjugateE   s&    iik\\$**-

r   c                "    U R                  5       $ r/   r   r(   s    r   	transposeScalarOp.transposeJ   s    yy{r   c                    Uc  U R                   nUc  U R                  n[        R                  " [        R                  " U R
                  5      SXS9$ )z,Return True if operator is a unitary matrix.   )atolrtol)r9   r:   r0   iscloseabsr   )r   r9   r:   s      r   
is_unitaryScalarOp.is_unitaryM   s>    <99D<99Dzz"&&,adFFr   c                n    U R                   u  p[        R                  " U[        S9nU R                  U-  $ )zConvert to a Numpy matrix.)r"   )dimr0   eyecomplexr   )r   r@   _idens       r   r    ScalarOp.to_matrixU   s,    vvc)zzD  r   c                l    [        U R                  5       U R                  5       U R                  5       S9$ )zConvert to an Operator object.r   )r   r    r   r   r(   s    r   to_operatorScalarOp.to_operator[   s-    NN):HXHXHZ
 	
r   c                   Uc  [        USS 5      n[        U[        5      (       d  [        U5      nU R                  R                  UR                  X#5      n[        U[        5      (       a<  [        R                  " U 5      nU R                  UR                  -  Ul
        XEl        U$ Uc=  [        R                  " U5      nXEl        U R                  S:X  a  U$ U R                  U-  $ UR                  U 5      R                  XUS9$ )Nqargsr8   )rJ   front)getattrr   r   r   	_op_shapecomposer   _copyr   r   r   r   )r   otherrJ   rK   	new_shaper2   s         r   rN   ScalarOp.composea   s    =E7D1E%..UOENN**5??EI	 eX&&**T"Cekk1CJ%MJ =**U#C%M zzQ
::## t$,,Uu,MMr   c                N    U R                  5       nU R                  U-  Ul        U$ )zReturn the power of the ScalarOp.

Args:
    n (float): the exponent for the scalar op.

Returns:
    ScalarOp: the ``coeff ** n`` ScalarOp.
)r   r   r   )r   nr2   s      r   powerScalarOp.power   s#     iikZZ]

r   c                N   [        U[        5      (       d  [        U5      n[        U[        5      (       a`  [        R
                  " U 5      nU R                  UR                  -  Ul        U R                  R                  UR                  5      Ul        U$ UR                  U 5      $ r/   )r   r   r   r   rO   r   r   r   rM   tensorexpandr   rP   r2   s      r   rX   ScalarOp.tensor   u    %..UOEeX&&**T"Cekk1CJ NN11%//BCMJ||D!!r   c                N   [        U[        5      (       d  [        U5      n[        U[        5      (       a`  [        R
                  " U 5      nU R                  UR                  -  Ul        U R                  R                  UR                  5      Ul        U$ UR                  U 5      $ r/   )r   r   r   r   rO   r   r   r   rM   rY   rX   rZ   s      r   rY   ScalarOp.expand   r\   r   c                X   Uc  [        USS5      n[        U[        5      (       d  [        U5      nU R                  R                  UR                  U5        [        U[        5      (       a/  [        U R                  5       U R                  UR                  -   S9$ [        R                  XU5      nU R                  S:X  a.  UR                  U R                  5       U R                  5       5      $ UR                  U R                  5       U R                  5       5      R                  U 5      $ )a  Return the operator self + other.

If ``qargs`` are specified the other operator will be added
assuming it is identity on all other subsystems.

Args:
    other (BaseOperator): an operator object.
    qargs (None or list): optional subsystems to subtract on
                          (Default: None)

Returns:
    ScalarOp: if other is an ScalarOp.
    BaseOperator: if other is not an ScalarOp.

Raises:
    QiskitError: if other has incompatible dimensions.
NrJ   )r   r   )rL   r   r   r   rM   _validate_addr   r   r   _pad_with_identityreshaper   _add)r   rP   rJ   s      r   rc   ScalarOp._add   s    $ =E7D1E%..UOE$$U__e< eX&&DOO-TZZ%++5MNN
 ++D? ::?==!2D4D4D4FGG
 }}T__.0@0@0BCHHNNr   c                    [        U[        5      (       d  [        SU S35      eU R                  5       nXR                  -  Ul        U$ )zReturn the ScalarOp other * self.

Args:
    other (Number): a complex number.

Returns:
    ScalarOp: the scaled identity operator other * self.

Raises:
    QiskitError: if other is not a valid complex number.
zother (z) is not a number)r   r   r   r   r   r   rZ   s      r   	_multiplyScalarOp._multiply   sD     %((w.?@AAiikZZ'

r   c                X    Uc  U$ [        U R                  5       5      R                  XS9$ )zPad another operator with identities.

Args:
    current (BaseOperator): current operator.
    other (BaseOperator): other operator.
    qargs (None or list): qargs

Returns:
    BaseOperator: the padded operator.
)rJ   )r   r   rN   )currentrP   rJ   s      r   ra   ScalarOp._pad_with_identity   s0     =L**,-55e5IIr   r,   )Nr8   )r   zint | tuple | Noner   r   )NN)returnr   )NF)rP   r   rJ   zlist | NonerK   boolrk   r   )rT   floatrk   r   )rP   r   rk   r   r/   )__name__
__module____qualname____firstlineno____doc__r   r$   r)   propertyr   r1   r5   r=   r    rG   rN   rU   rX   rY   rc   rf   staticmethodra   __static_attributes____classcell__)r   s   @r   r   r      s    < < GD  
G!
#NJ
"
"-O^$ J Jr   r   )rr   
__future__r   r   rO   numbersr   numpyr0   qiskit.exceptionsr   +qiskit.quantum_info.operators.base_operatorr   'qiskit.quantum_info.operators.linear_opr   &qiskit.quantum_info.operators.operatorr   $qiskit.quantum_info.operators.mixinsr	   r    r   r   <module>r      sB    #    ) D < ; A]Jx ]JB  r   