qcodes.math_utils

The math_utils module contains math related utility functions and classes such as coordinate system mappings.

Classes:

FieldVector([x, y, z, r, theta, phi, rho])

A convenient class to keep track of vectors representing physical fields.

class qcodes.math_utils.FieldVector(x: float | None = None, y: float | None = None, z: float | None = None, r: float | None = None, theta: float | None = None, phi: float | None = None, rho: float | None = None)[source]

Bases: object

A convenient class to keep track of vectors representing physical fields. The idea is that a vector instance stores a representation in Cartesian, spherical and cylindrical coordinates. All arguments are optional, however the user needs to provide one of the combinations of either (x, y, z) values or (rho, phi, z) values or (r, theta, phi) values at instantiation for a meaningful computation of the other representation, immediately.

Parameters:
  • x – represents the norm of the projection of the vector along the x-axis

  • y – represents the norm of the projection of the vector along the y-axis

  • z – represents the norm of the projection of the vector along the z-axis

  • r – represents the norm of the vector

  • theta – represents the angle of the vector with respect to the positive z-axis

  • rho – represents the norm of the projection of the vector on to the xy-plane

  • phi – represents the angle of rho with respect to the positive x-axis

Attributes:

Methods:

copy(other)

Copy the properties of other vector to yourself.

set_vector(**new_values)

Reset the the values of the vector.

set_component(**new_values)

Set a single component of the vector to some new value.

get_components(*names)

Get field components by name.

is_equal(other)

Returns True if other is equivalent to self, False otherwise.

norm([ord])

Returns the norm of this field vector.

distance(other[, ord])

repr_cartesian()

repr_spherical()

repr_cylindrical()

as_homogeneous()

from_homogeneous(hvec)

attributes: ClassVar[list[str]] = ['x', 'y', 'z', 'r', 'theta', 'phi', 'rho']
repr_format = 'cartesian'
copy(other: T) None[source]

Copy the properties of other vector to yourself.

set_vector(**new_values: float) None[source]

Reset the the values of the vector.

Examples

>>> f = FieldVector(x=0, y=2, z=6)
>>> f.set_vector(x=9, y=3, z=1)
>>> f.set_vector(r=1, theta=30.0, phi=10.0)
# The following should raise a value error:
# "Can only set vector with a complete value set"
>>> f.set_vector(x=9, y=0)
# Although mathematically it is possible to compute the complete
# vector from the values given, this is too hard to implement with
# generality (and not worth it), so the following will raise the
# above-mentioned ValueError too.
>>> f.set_vector(x=9, y=0, r=3)
set_component(**new_values: float) None[source]

Set a single component of the vector to some new value. It is disallowed for the user to set vector components manually as this can lead to inconsistencies (e.g. x and rho are not independent of each other, setting one has to effect the other).

Examples

>>> f = FieldVector(x=2, y=3, z=4)
# Since r is part of the set (r, theta, phi) representing
# spherical coordinates, setting r means that theta and phi are
# kept constant and only r is changed. After changing r,
# (x, y, z) values are recomputed, as is the rho coordinate.
# Internally we arrange this by setting x, y, z and rho to None
# and calling self._compute_unknowns().
>>> f.set_component(r=10)
Parameters:

new_values (dict) – Keys representing parameter names and values the values to be set.

get_components(*names: str) list[float][source]

Get field components by name.

is_equal(other: FieldVector) bool[source]

Returns True if other is equivalent to self, False otherwise.

norm(ord: None | float | Literal['fro'] | Literal['nuc'] = 2) float[source]

Returns the norm of this field vector. See np.norm for the definition of the ord keyword argument.

distance(other: FieldVector, ord: None | float | Literal['fro'] | Literal['nuc'] = 2) float[source]
property x: float | None
property y: float | None
property z: float | None
property rho: float | None
property theta: float | None
property r: float | None
property phi: float | None
repr_cartesian() str[source]
repr_spherical() str[source]
repr_cylindrical() str[source]
as_homogeneous() ndarray[source]
classmethod from_homogeneous(hvec: ndarray) T[source]