dbac.utils

Helpers for preparing single-qubit states and measuring how cold they are. Use rx_sweep to build the initial states of a sweep and fidelity_with_0 to score the result; the noise helpers build mixed inputs.

See States and conventions for the conventions behind these functions, in particular the angle convention of rx_sweep.

rx_sweep(theta_fraction[, start])

Rotate start by exp(-i theta X) for a sweep of angles, with theta = theta_fraction * pi/2.

fidelity_with_0(state[, reference])

Fidelity <reference| rho |reference> of a state with a reference pure state, by default the ground state |0>.

state_0

Reference ground state |0> (flat vector [1, 0]) that DBAC/HBAC try to reset towards.

apply_depolarizing_noise(rho[, p])

Depolarize a density matrix: (1 - p) rho + p I / d.

thermal_state(epsilon)

Diagonal thermal (Gibbs) state of a single qubit, diag(e^epsilon, e^-epsilon) / Z.

random_density_matrix(dim)

Draw a random full-rank density matrix of dimension dim (Hilbert-Schmidt measure: A A^dagger / Tr with complex Gaussian A).

Initial states

rx_sweep(theta_fraction, start=array([[1. + 0.j], [0. + 0.j]]))[source]

Rotate start by exp(-i theta X) for a sweep of angles, with theta = theta_fraction * pi/2. This is the initial-state sweep used throughout the package.

theta is the state-vector angle: for start = |0> the result is cos(theta)|0> - i sin(theta)|1>. This is the paper’s convention R_X(theta) = exp(-i theta X), so a fraction of 1 reaches |1>. In the common convention R_X(phi) = exp(-i phi X / 2) it is phi = 2 theta.

Parameters:
  • theta_fraction (sequence[float]) – Angles as fractions of pi/2.

  • start (np.ndarray) – (2, 1) state vector to rotate. Defaults to |0>; pass np.array([[0], [1]], dtype=complex) to sweep away from |1>.

Returns:

Array of shape (len(theta_fraction), 2, 1), one state vector per angle.

Return type:

np.ndarray

Example

>>> from dbac.utils import rx_sweep, fidelity_with_0
>>> psis = rx_sweep([0, 0.5, 1])           # |0>, halfway, |1>
>>> [round(fidelity_with_0(p), 3) for p in psis]
[1.0, 0.5, 0.0]
state_0

Reference ground state |0> (flat vector [1, 0]) that DBAC/HBAC try to reset towards.

Measuring cooling

fidelity_with_0(state, reference=array([1. + 0.j, 0. + 0.j]))[source]

Fidelity <reference| rho |reference> of a state with a reference pure state, by default the ground state |0>.

For a qubit, fidelity and energy carry the same information: E = 1 - 2 F for the Hamiltonian H = -Z.

Parameters:
  • state (np.ndarray) – A state vector (any shape with 2 entries, e.g. (2, 1)) or a 2x2 density matrix.

  • reference (np.ndarray) – Flat reference state vector. Defaults to state_0.

Returns:

Fidelity between 0 (orthogonal) and 1 (identical).

Return type:

float

Example

>>> import numpy as np
>>> from dbac.utils import fidelity_with_0
>>> plus = np.array([[1], [1]]) / np.sqrt(2)
>>> round(fidelity_with_0(plus), 3)
0.5

Mixed states

apply_depolarizing_noise(rho, p=0.5)[source]

Depolarize a density matrix: (1 - p) rho + p I / d.

Parameters:
  • rho (np.ndarray) – d x d density matrix (any number of qubits).

  • p (float) – Depolarizing probability, from 0 (unchanged) to 1 (maximally mixed).

Returns:

The depolarized density matrix.

Return type:

np.ndarray

thermal_state(epsilon)[source]

Diagonal thermal (Gibbs) state of a single qubit, diag(e^epsilon, e^-epsilon) / Z.

Note this uses a Boltzmann factor epsilon, while dbac.hbac parametrizes its bath by the polarization epsilon_b with populations (1 +- epsilon_b) / 2.

Parameters:

epsilon (float) – Inverse temperature times energy gap; 0 gives the maximally mixed state, large values approach |0><0|.

Returns:

2x2 diagonal density matrix.

Return type:

np.ndarray

random_density_matrix(dim)[source]

Draw a random full-rank density matrix of dimension dim (Hilbert-Schmidt measure: A A^dagger / Tr with complex Gaussian A).

Parameters:

dim (int) – Dimension, e.g. 2 for one qubit.

Returns:

A dim x dim density matrix.

Return type:

np.ndarray