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.
|
Rotate start by |
|
Fidelity |
Reference ground state |
|
|
Depolarize a density matrix: |
|
Diagonal thermal (Gibbs) state of a single qubit, |
Draw a random full-rank density matrix of dimension dim (Hilbert-Schmidt measure: |
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, withtheta = 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 iscos(theta)|0> - i sin(theta)|1>. This is the paper’s conventionR_X(theta) = exp(-i theta X), so a fraction of 1 reaches|1>. In the common conventionR_X(phi) = exp(-i phi X / 2)it isphi = 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>; passnp.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 Ffor 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:
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 ddensity 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_bwith 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