
    z	i                    j    S r SSKJr  SSKrSSKr\R                  (       a  SSKJr  SS jr	SS	S jjr
g)
zSI unit utilities    )annotationsN)ParameterExpressionc                    SSSSSSSSSS	S
S.nU(       a  [        U5      S:X  a  U $ US   U;  a  [        SU 35      eX!S      nUS:  a  U [        SU* 5      -  $ U [        SU5      -  $ )a  
Given a SI unit prefix and value, apply the prefix to convert to
standard SI unit.

Args:
    value: The number to apply prefix to.
    unit: String prefix.

Returns:
    Converted value.

.. note::

    This may induce tiny value error due to internal representation of float object.
    See https://docs.python.org/3/tutorial/floatingpoint.html for details.

Raises:
    ValueError: If the ``units`` aren't recognized.
      	         )fpnu   µmkMGTP   r   zCould not understand unit: 
   )len
ValueErrorpow)valueunit
prefactorspow10s       L/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/utils/units.pyapply_prefixr%      s    * J 3t9>Awj 6tf=>>AwE qys2v&&3r5>!!    c                   SSSSSSSSS	S
SS.n[         R                  " U 5      (       d  [        SU  S35      e[         R                  " U 5      S:w  aN  [	        [         R
                  " [         R                  " [         R                  " U 5      5      S-  5      S-  5      nOSnUS:  a  U [        SU5      -  nOU [        SU* 5      -  nUb&  [         R                  " XA5      nUS:  a
  US-  nUS-  nX2;  a  [        SU  35      eXBU   4$ )ah  
Given a SI unit value, find the most suitable prefix to scale the value.

For example, the ``value = 1.3e8`` will be converted into a tuple of ``(130.0, "M")``,
which represents a scaled value and auxiliary unit that may be used to display the value.
In above example, that value might be displayed as ``130 MHz`` (unit is arbitrary here).

Example:

    >>> value, prefix = detach_prefix(1e4)
    >>> print(f"{value} {prefix}Hz")
    10 kHz

Args:
    value: The number to find prefix.
    decimal: Optional. An arbitrary integer number to represent a precision of the value.
        If specified, it tries to round the mantissa and adjust the prefix to rounded value.
        For example, 999_999.91 will become 999.9999 k with ``decimal=4``,
        while 1.0 M with ``decimal=3`` or less.

Returns:
    A tuple of scaled value and prefix.

.. note::

    This may induce tiny value error due to internal representation of float object.
    See https://docs.python.org/3/tutorial/floatingpoint.html for details.

Raises:
    ValueError: If the ``value`` is out of range.
    ValueError: If the ``value`` is not real number.
r   r   r   r   r    r   r   r   r   r   )r   r   r   r	   r
   r   r   r   r   r   r   z,Input should be real number. Cannot convert .r   r   r   i  zValue is out of range: )	npisrealr   absintfloorlog10r   round)r    decimalr"   r#   mants        r$   detach_prefixr3   J   s   D J 99UGwaPQQ	vve}BHHRXXbffUm4q89A=> qys2u~%s2v& xx&4<DLDQJE25':;;E"""r&   )r    float | ParameterExpressionr!   strreturnr4   )N)r    floatr1   z
int | Noner6   ztuple[float, str])__doc__
__future__r   typingnumpyr*   TYPE_CHECKING"qiskit.circuit.parameterexpressionr   r%   r3    r&   r$   <module>r?      s+     "  	F/"dH#r&   