Skip to content

Miscellaneous

oqd_trical.misc

constants

Module containing relevant constants, in SI units, for TrICal

c: float = 299792458.0 module-attribute

Speed of light

e: float = 1.602176634e-19 module-attribute

Elementary charge

hbar: float = 1.054571817e-34 module-attribute

Reduced Planck constant

k_e: float = 8987551792.3 module-attribute

Coulomb constant

epsilon_0: float = 8.8541878188e-12 module-attribute

Permittivity of free space

m_u: float = 1.66053906892e-27 module-attribute

Atomic mass unit

natural_l(m, q, omega)

Calculates a natural length scale for a trapped ion system

Parameters:

Name Type Description Default
m float

Mass of ion

required
q float

Charge of ion

required
omega float

Trapping strength

required

Returns:

Type Description
float

Natural length scale

Source code in oqd-trical/src/oqd_trical/misc/constants.py
def natural_l(m, q, omega):
    """
    Calculates a natural length scale for a trapped ion system

    Args:
        m (float): Mass of ion
        q (float): Charge of ion
        omega (float): Trapping strength

    Returns:
        (float): Natural length scale
    """
    return (2 * k_e * q**2 / (m * omega**2)) ** (1 / 3)

natural_V(m, q, omega)

Calculates a natural energy scale for a trapped ion system

Parameters:

Name Type Description Default
m float

Mass of ion

required
q float

Charge of ion

required
omega float

Trapping strength

required

Returns:

Type Description
float

Natural energy scale

Source code in oqd-trical/src/oqd_trical/misc/constants.py
def natural_V(m, q, omega):
    """
    Calculates a natural energy scale for a trapped ion system

    Args:
        m (float): Mass of ion
        q (float): Charge of ion
        omega (float): Trapping strength

    Returns:
        (float): Natural energy scale
    """
    return k_e * q**2 / natural_l(m, q, omega)

linalg

Module containing relevant linear algebra functions for TrICal.

orthonormal_subset(x, tol=0.001)

Finds an approximate orthonormal subset of a set of vectors, after normalization.

Parameters:

Name Type Description Default
x ndarray[float]

Set of vectors of interest.

required
tol float

Tolerance when classifying 2 vectors as orthonormal.

0.001

Returns:

Type Description
ndarray[float]

Orthonormal subset of the set of vectors of interest, after normalization.

Source code in oqd-trical/src/oqd_trical/misc/linalg.py
def orthonormal_subset(x, tol=1e-3):
    """
    Finds an approximate orthonormal subset of a set of vectors, after normalization.

    Args:
        x (np.ndarray[float]): Set of vectors of interest.
        tol (float): Tolerance when classifying 2 vectors as orthonormal.

    Returns:
        (np.ndarray[float]): Orthonormal subset of the set of vectors of interest, after normalization.
    """
    nx = np.linalg.norm(x, axis=-1)
    idcs = (-nx).argsort()
    x = x[idcs]
    nx = nx[idcs]
    x = x / nx.reshape(-1, 1)

    i = 0
    while i < len(x):
        idcs = (
            np.logical_not(
                np.isclose(np.einsum("i,ni->n", x[i], x[i + 1 :]), 0, atol=tol)
            ).nonzero()[0]
            + i
            + 1
        )
        x = np.delete(x, idcs, axis=0)
        i += 1
    return x

multispecies

Module containing useful functions relavent for multi-species systems.

dc_trap_geometry(omega)

Calculates the trap geometry of a trapped ion system.

Parameters:

Name Type Description Default
omega ndarray[float]

Trap strengths of primary species

required

Returns:

Type Description
ndarray[float]

Trap geometry factors of the system

Source code in oqd-trical/src/oqd_trical/misc/multispecies.py
def dc_trap_geometry(omega):
    """
    Calculates the trap geometry of a trapped ion system.

    Args:
        omega (np.ndarray[float]): Trap strengths of primary species

    Returns:
        (np.ndarray[float]): Trap geometry factors of the system
    """
    gamma_diff = (omega[1] ** 2 - omega[0] ** 2) / omega[2] ** 2
    gamma_x = (gamma_diff + 1) / 2
    gamma_y = 1 - gamma_x
    gamma = np.array([gamma_x, gamma_y, 1])
    return gamma

ms_trap_strength(m, m0, omega)

Calculates the transverse trap frequencies of non-primary species.

Parameters:

Name Type Description Default
m ndarray[float]

Mass of ions

required
m0 float

Mass of primary species

required
omega ndarray[float]

Trap strengths of primary species

required

Returns:

Type Description
ndarray[float]

Trap strengths of the ions

Source code in oqd-trical/src/oqd_trical/misc/multispecies.py
def ms_trap_strength(m, m0, omega):
    """
    Calculates the transverse trap frequencies of non-primary species.

    Args:
        m (np.ndarray[float]): Mass of ions
        m0 (float): Mass of primary species
        omega (np.ndarray[float]): Trap strengths of primary species

    Returns:
        (np.ndarray[float]): Trap strengths of the ions
    """
    omega_dc = omega[2]

    gamma = dc_trap_geometry(omega)[:2]
    omega_rf = np.sqrt(omega[0] ** 2 + omega_dc**2 * gamma[0])

    omega_axial = np.sqrt(m0 / m) * omega[2]
    omega_trans = np.sqrt(
        (m0 / m) ** 2 * omega_rf**2 - np.outer(gamma, (m0 / m)) * omega_dc**2
    )

    omegas = np.vstack((omega_trans, omega_axial))
    return omegas

optimize

Module containing default optimization function generators for TrICal.

dflt_opt(ti, **kwargs)

Default optimization function generator for equilibrium_position method of TrappedIons class.

Parameters:

Name Type Description Default
ti TrappedIons

Trapped ion system of interest.

required

Returns:

Type Description
Callable

Default optimization function that finds the equilibrium position of the trapped ions system of interest via the minimization of the potential.

Source code in oqd-trical/src/oqd_trical/misc/optimize.py
def dflt_opt(ti, **kwargs):
    """
    Default optimization function generator for equilibrium_position method of TrappedIons class.

    Args:
        ti (TrappedIons): Trapped ion system of interest.

    Returns:
        (Callable): Default optimization function that finds the equilibrium position of the trapped ions system of interest via the minimization of the potential.
    """
    opt_params = {"method": "SLSQP", "options": {"maxiter": 1000}, "tol": 1e-15}
    opt_params.update(kwargs)

    if ti.dim == 1:
        x_guess = np.linspace(-(ti.N - 1) / 2, (ti.N - 1) / 2, ti.N)
    else:
        x_guess = np.append(
            np.concatenate([np.zeros(ti.N)] * (ti.dim - 1)),
            np.linspace(-(ti.N - 1) / 2, (ti.N - 1) / 2, ti.N),
        )

    def _dflt_opt(f):
        res = opt.minimize(f, x_guess, **opt_params)
        assert res.success, res.__str__()
        return res.x

    return _dflt_opt

dflt_ls_opt(deg)

Default optimization function generator for multivariate_polyfit function.

Parameters:

Name Type Description Default
deg ndarray[int]

Degree of polynomial used in the fit.

required

Returns:

Type Description
Callable

Default optimization function that finds the best polynomial, of the specified degree, fit for the data .

Source code in oqd-trical/src/oqd_trical/misc/optimize.py
def dflt_ls_opt(deg):
    """
    Default optimization function generator for multivariate_polyfit function.

    Args:
        deg (np.ndarray[int]): Degree of polynomial used in the fit.

    Returns:
        (Callable): Default optimization function that finds the best polynomial, of the specified degree, fit for the data .
    """

    def _dflt_ls_opt(a, b):
        res = opt.lsq_linear(a, b)
        assert res.success
        return res.x

    return _dflt_ls_opt

polynomial

Module containing relevant functions regarding polynomials for TrIcal.

multivariate_polyfit(x, vals, deg, l=1, opt=dflt_ls_opt)

Fits a set of data with a multivariate polynomial.

Parameters:

Name Type Description Default
x ndarray[float]

Independent values.

required
vals ndarray[float]

Dependent value.

required
deg ndarray[int]

Degree of polynomial used in the fit.

required
l float

Length scale used when fitting, defaults to 1.

1
opt Callable

Generator of the appropriate optimization function for the fit.

dflt_ls_opt

Returns:

Type Description
ndarray[float]

Coefficients of the best fit multivariate polynomial, of the specified degree.

Source code in oqd-trical/src/oqd_trical/misc/polynomial.py
def multivariate_polyfit(x, vals, deg, l=1, opt=dflt_ls_opt):  # noqa: E741
    """
    Fits a set of data with a multivariate polynomial.

    Args:
        x (np.ndarray[float]): Independent values.
        vals (np.ndarray[float]): Dependent value.
        deg (np.ndarray[int]): Degree of polynomial used in the fit.
        l (float): Length scale used when fitting, defaults to 1.
        opt (Callable): Generator of the appropriate optimization function for the fit.

    Returns:
        (np.ndarray[float]): Coefficients of the best fit multivariate polynomial, of the specified degree.
    """
    dim = len(deg)
    shape = np.array(deg) + 1

    a = {1: poly.polyvander, 2: poly.polyvander2d, 3: poly.polyvander3d}[dim](
        *(x / l).transpose(), deg
    )
    b = vals
    return opt(deg)(a, b).reshape(shape) / l ** np.indices(shape).sum(0)