Utilities

Unit Conversion

qDNA.utils.get_conversion(start_unit, end_unit)

Converts a value from the start_unit to the end_unit.

Parameters:
start_unitstr

The unit to convert from.

end_unitstr

The unit to convert to.

Returns:
float

The conversion factor between the two units.

Examples

>>> 1/get_conversion("100meV", "rad/fs").
qDNA.utils.get_all_conversions()

Generates a dictionary with all possible conversions between units.

Returns:
Dict[str, float]

A dictionary where the keys are conversion descriptions and the values are the conversion factors.

qDNA.utils.get_conversion_dict(param_dict, start_unit, end_unit)

Convert the values in a dictionary from one unit to another.

Parameters:
param_dictdict

Dictionary containing the parameters to be converted. Keys are parameter names and values are the parameter values.

start_unitstr

The unit of the input values in param_dict.

end_unitstr

The unit to which the values in param_dict should be converted.

Returns:
dict

A new dictionary with the same keys as param_dict, but with values converted to end_unit.

Hamiltonian Analysis

qDNA.utils.calc_average_pop(eigs, init_state, end_state)

Calculates the time-averaged/ static population of the end state when initially in the initial state.

Parameters:
eigsnp.ndarray

Eigenvector matrix.

init_stateint

Initial state in the basis.

end_stateint

End state in the basis.

Returns:
float

The static population of the end state.

qDNA.utils.calc_amplitudes(eigs, init_state, end_state)

Calculates the amplitudes for transitions between states.

Parameters:
eigsnp.ndarray

Eigenvector matrix.

init_stateint

Initial state in the basis.

end_stateint

End state in the basis.

Returns:
np.ndarray

A list of amplitudes for transitions.

qDNA.utils.calc_frequencies(eigv)

Calculates the frequencies corresponding to energy level differences.

Parameters:
eigvnp.ndarray

Eigenvalue vector.

Returns:
np.ndarray

A list of frequencies.

qDNA.utils.get_pop_fourier(t, average_pop, amplitudes, frequencies)

Calculates the population using Fourier series.

Parameters:
tfloat

Time variable.

average_popfloat

Average population.

amplitudesnp.ndarray

Amplitudes for transitions.

frequenciesnp.ndarray

Frequencies corresponding to energy level differences.

Returns:
float

The population at time t.

qDNA.utils.calc_ipr_hamiltonian(eigs)

Calculates the inverse participation ratio (IPR) for each eigenstate of the Hamiltonian.

Parameters:
eigsnp.ndarray

Eigenvector matrix.

Returns:
list of float

The IPR values for each eigenstate.

Notes

Note

The IPR is a measure of the localization of an eigenstate. It is defined as the sum of the squared coefficients of the eigenvector. The IPR ranges from 1 to N, where N is the dimension of the Hilbert space. The IPR values can be used to distinguish between localized and delocalized eigenstates.

\[\mathrm{IPR} = 1/\sum_{i=1}^{N} |c_i|^4.\]
  • Localized state: \(\mathrm{IPR} = 1/N\)

  • Delocalized coherent state: \(\mathrm{IPR} = N\)

Density Matrix Analysis

qDNA.utils.calc_trace_distance(dm_1, dm_2)

Calculate the trace distance between two density matrices. The trace distance is a measure of the distinguishability between two quantum states represented by their density matrices. It is defined as half the trace of the absolute difference between the two density matrices.

Parameters:
dm_1numpy.ndarray

The first density matrix.

dm_2numpy.ndarray

The second density matrix.

Returns:
float

The trace distance between the two density matrices.

Raises:
ValueError

If the density matrices do not have the same shape.

qDNA.utils.calc_purity(dm)

Calculates the purity of a density matrix.

Parameters:
dmnp.ndarray

Density matrix.

Returns:
float

The purity of the density matrix.

qDNA.utils.calc_coherence(dm)

Calculates the coherence (absolute sum of the off-diagonals) of a density matrix.

Parameters:
dmnp.ndarray

Density matrix.

Returns:
float

The coherence of the density matrix.

qDNA.utils.calc_ipr_dm(dm)

Calculate the inverse participation ratio (IPR) of a density matrix.

Parameters:
dmnp.ndarray

The density matrix for which the IPR is calculated. Should be a square, complex-valued matrix.

Returns:
float

The inverse participation ratio of the density matrix, providing an indication of state localization.

Notes

Note

The IPR provides a measure of the localization of a quantum state

\[\mathrm{IPR} = \frac{\left( \sum_{i,j} |\rho_{i,j}| \right)^2}{N \sum_{i,j} |\rho_{i,j}|^2}\]
  • Localized state: \(IPR = 1/N\), where N is the dimension of the density matrix.

  • Delocalized (coherent) state: \(IPR = N\), indicating full coherence.

  • Maximally mixed state: \(IPR = 1\), representing maximal mixing.