dbac.dme

Density matrix exponentiation (DME): applying \(e^{it\rho}\) to a data state \(\sigma\) using copies of \(\rho\) instead of knowledge of \(\rho\). This is the subroutine inside every DBAC step.

The module offers the same channel four ways, so the implementations can be checked against each other. All take (data, instruction, t, M): the data and instruction density matrices, the total duration, and the number of Trotter steps (instruction copies used).

See Density matrix exponentiation for how DME works and which implementation to pick.

Note

DBAC steps do not call this module: they use dbac.dbqite.DME, which takes the arguments in the order (instruction, data, t, M).

dme_channel(data, instruction, t, M)

DME as on hardware: apply a partial SWAP exp(i (t / M) SWAP) to data (x) instruction, trace out the instruction, and repeat M times with a fresh instruction copy.

dme_channel_equivalent(data, instruction, t, M)

DME using the closed form of one channel step, cos^2 data + sin^2 instruction + i sin cos [instruction, data] (with angle t / M), which avoids building two-qubit matrices.

dme_qibo(data, instruction, t, M)

DME built from qibo's SWAP gate matrix and qibo's partial trace.

dme_expm(data, instruction, t[, M])

The exact evolution exp(i t instruction) data exp(-i t instruction), i.e. the M -> infinity limit that DME approximates.

ptrace(matrix[, index, n1, n2])

Partial trace of a bipartite (n1 * n2) x (n1 * n2) matrix.

Approximate DME (Trotterized)

dme_channel(data, instruction, t, M)[source]

DME as on hardware: apply a partial SWAP exp(i (t / M) SWAP) to data (x) instruction, trace out the instruction, and repeat M times with a fresh instruction copy.

Parameters:
  • data (np.ndarray) – 2x2 data density matrix.

  • instruction (np.ndarray) – 2x2 instruction density matrix.

  • t (float) – Total duration, split into M steps of t / M.

  • M (int) – Number of Trotter steps (instruction copies consumed).

Returns:

The final data state, and the data state after each step.

Return type:

tuple[np.ndarray, list[np.ndarray]]

Example

>>> import numpy as np
>>> from dbac.dme import dme_channel, dme_expm
>>> data = np.array([[1, 0], [0, 0]], dtype=complex)
>>> instruction = np.full((2, 2), 0.5, dtype=complex)
>>> exact = dme_expm(data, instruction, 1.0)
>>> [round(float(np.linalg.norm(exact - dme_channel(data, instruction, 1.0, M)[0])), 4)
...  for M in (1, 10, 100)]   # error shrinks like 1/M
[0.5969, 0.0757, 0.0079]
dme_channel_equivalent(data, instruction, t, M)[source]

DME using the closed form of one channel step, cos^2 data + sin^2 instruction + i sin cos [instruction, data] (with angle t / M), which avoids building two-qubit matrices.

Parameters:
  • data (np.ndarray) – 2x2 data density matrix.

  • instruction (np.ndarray) – 2x2 instruction density matrix.

  • t (float) – Total duration, split into M steps of t / M.

  • M (int) – Number of Trotter steps.

Returns:

The final data state, and the data state after each step.

Return type:

tuple[np.ndarray, list[np.ndarray]]

dme_qibo(data, instruction, t, M)[source]

DME built from qibo’s SWAP gate matrix and qibo’s partial trace.

Same channel as dme_channel; useful to cross-check the numpy implementation against qibo.

Parameters:
  • data (np.ndarray) – 2x2 data density matrix.

  • instruction (np.ndarray) – 2x2 instruction density matrix.

  • t (float) – Total duration, split into M steps of t / M.

  • M (int) – Number of Trotter steps.

Returns:

The final data state, and the data state after each step.

Return type:

tuple[np.ndarray, list[np.ndarray]]

Exact reference

dme_expm(data, instruction, t, M=None)[source]

The exact evolution exp(i t instruction) data exp(-i t instruction), i.e. the M -> infinity limit that DME approximates. The reference for the other implementations.

Parameters:
  • data (np.ndarray) – 2x2 data density matrix.

  • instruction (np.ndarray) – 2x2 instruction density matrix (the Hamiltonian).

  • t (float) – Duration.

  • M – Ignored; accepted so the signature matches the other implementations.

Returns:

The evolved 2x2 data density matrix (not a tuple).

Return type:

np.ndarray

Helpers

ptrace(matrix, index=1, n1=2, n2=2)[source]

Partial trace of a bipartite (n1 * n2) x (n1 * n2) matrix.

Parameters:
  • matrix (np.ndarray) – Operator on subsystems 1 (dimension n1) and 2 (dimension n2).

  • index (int) – Which subsystem to trace out: 1 traces out subsystem 2 and keeps subsystem 1; 2 traces out subsystem 1 and keeps subsystem 2.

  • n1 (int) – Dimensions of the two subsystems.

  • n2 (int) – Dimensions of the two subsystems.

Returns:

The reduced operator.

Return type:

np.ndarray