# Utility Functions

Here are the various functions used throughout the PyCCE code. There is no real structure in this section.

Module with helper functions to obtain CPMG coherence from the noise autocorrelation function.

filterfunc(ts, tau, npulses)

Time-domain filter function for the given CPMG sequence.

Parameters
• ts (ndarray with shape (n,)) – Time points at which filter function will be computed.

• tau (float) – Delay between pulses.

• npulses (int) – Number of pulses in CPMG sequence.

Returns

Filter function for the given CPMG sequence

Return type

ndarray with shape (n,)

gaussian_phase(timespace, corr, npulses, units='khz')

Compute average random phase squared assuming Gaussian noise.

Parameters
• timespace (ndarray with shape (n,)) – Time points at which correlation function was computed.

• corr (ndarray with shape (n,)) – Noise autocorrelation function.

• npulses (int) – Number of pulses in CPMG sequence.

• units (str) – If units contain frequency or angular frequency (‘rad’ in units).

Returns

Random phase accumulated by the qubit.

Return type

ndarray with shape (n,)

rotmatrix(initial_vector, final_vector)

Generate 3D rotation matrix which applied on initial vector will produce vector, aligned with final vector.

Examples

>>> R = rotmatrix([0,0,1], [1,1,1])
>>> R @ np.array([0,0,1])
array([0.577, 0.577, 0.577])

Parameters
• initial_vector (ndarray with shape(3, )) – Initial vector.

• final_vector (ndarray with shape (3, )) – Final vector.

Returns

Rotation matrix.

Return type

ndarray with shape (3, 3)

expand(matrix, i, dim)

Expand matrix M from it’s own dimensions to the total Hilbert space.

Parameters
• matrix (ndarray with shape (dim[i], dim[i])) – Inital matrix.

• i (int) – Index of the spin dimensions in dim parameter.

• dim (ndarray) – Array pf dimensions of all spins present in the cluster.

Returns

Expanded matrix.

Return type

ndarray with shape (prod(dim), prod(dim))

dimensions_spinvectors(nspin, central_spin=None)

Generate two arrays, containing dimensions of the spins in the cluster and the vectors with spin matrices.

Parameters
• nspin (BathArray with shape (n,)) – Array of the n spins within cluster.

• central_spin (float, optional) – If provided, include dimensions of the central spin with the total spin s.

Returns

tuple containing:

• ndarray with shape (n,): Array with dimensions for each spin.

• list: List with vectors of spin matrices for each spin in the cluster (Including central spin if central_spin is not None). Each with shape (3, N, N) where N = prod(dimensions).

Return type

tuple

spinvec(s, j, dimensions)

Generate spin vector for the particle, containing 3 spin matrices in the total basis of the system.

Parameters
• s (float) – Spin of the particle.

• j (j) – Particle index in dimensions array.

• dimensions (ndarray) – Array with dimensions of all spins in the cluster.

Returns

Vector of spin matrices for the given spin in the cluster.

Return type

ndarray with shape (3, prod(dimensions), prod(dimensions))

generate_projections(state_a, state_b=None)

Generate vector with the spin projections of the given spin states:

$[\bra{a}\hat{S}_x\ket{b}, \bra{a}\hat{S}_y\ket{b}, \bra{a}\hat{S}_z\ket{b}],$

where $$\ket{a}$$ and $$\ket{b}$$ are the given spin states.

Parameters
• state_a (ndarray) – state a of the central spin in $$\hat{S}_z$$ basis.

• state_b (ndarray) – state b of the central spin in $$\hat{S}_z$$ basis.

Returns

$$[\braket{\hat{S}_x}, \braket{\hat{S}_y}, \braket{\hat{S}_z}]$$ projections.

Return type

ndarray with shape (3,)

zfs_tensor(D, E=0)

Generate (3, 3) ZFS tensor from observable parameters D and E.

Parameters
• D (float or ndarray with shape (3, 3)) – Longitudinal splitting (D) in ZFS OR total ZFS tensor.

• E (float) – Transverse splitting (E) in ZFS.

Returns

Total ZFS tensor.

Return type

ndarray with shape (3, 3)

project_bath_states(states)

Generate projections of bath states on $$S_z$$ axis from any type of states input. :param states: Array of bath spin states. :type states: array-like

Returns

Array of $$S_z$$ projections of the bath states

Return type

ndarray

partial_inner_product(avec, total, dimensions, index=- 1)

Returns partial inner product $$\ket{b}=\bra{a}\ket{\psi}$$, where $$\ket{a}$$ provided by avec contains degrees of freedom to be “traced out” and $$\ket{\psi}$$ provided by total is the total statevector.

Parameters
• avec (ndarray with shape (a,)) –

• total (ndarray with shape (a*b,)) –

• dimensions (ndarray with shape (n,)) –

• () (index) –

Returns:

class SpinMatrix(s)

Class containing the spin matrices in Sz basis.

Parameters

s (float) – Total spin.

class MatrixDict(*spins)

Class for storing the SpinMatrtix objects.

keys()a set-like object providing a view on D’s keys