Quantum Utils
This module defines functions and objects to manipulate quantum states.
This includes cached measurement of quantum states, and certain useful operators. These should not be used directly, but accessed by a QuantumManager instance or by a quantum state.
- sequence.kernel.quantum_utils.density_partial_trace(state: tuple[tuple[complex]], indices: tuple[int], num_systems: int, truncation: int = 1) array
Traces out subsystems systems at given indices.
- Parameters:
(tuple[tuple[complex]] (state) – input state.
indices (tuple[int]) – indices of subsystems to trace out of state. should be sorted in increasing order.
num_systems (int) – number of total subsystems in the state.
truncation (int) – fock space truncation, 1 for qubit system (default 1).
- Returns:
output state with reduced number of subsystems num_systems - len(indices).
- Return type:
array
- sequence.kernel.quantum_utils.measure_entangled_state_with_cache_fock_density(state: tuple[tuple[complex]], system_index: int, num_systems: int, povms: tuple[tuple[tuple[complex]]], truncation: int = 1) tuple[list[array], list[float]]
Measure one subsystem of a larger composite system.
The measurement SHOULD NOT be entangling measurement, and thus POVM operators should be precisely consisted of operators on the subsystem’s Hilbert space alone.
- Parameters:
state (tuple[tuple[complex]]) – state to measure
system_index (int) – index of measured subsystem within state.
num_systems (int) – number of total systems in the state.
povms (tuple[tuple[tuple[complex]]]) – tuple listing all POVM operators to use for measurement
truncation (int) – fock space truncation, 1 for qubit system (default 1).
- Returns:
- tuple with two sub-lists.
The first lists each output state, corresponding with the measurement of each POVM. The second lists the probability for each measurement.
- Return type:
tuple[list[array], list[float]]
- sequence.kernel.quantum_utils.measure_multiple_with_cache_fock_density(state: tuple[tuple[complex]], indices: tuple[int], num_systems: int, povms: tuple[tuple[tuple[complex]]], truncation: int = 1) tuple[list[array], list[float]]
Measure multiple subsystems of a larger composite system.
Should be called by Quantum Managers. This function will facilitate entangling measurement, e.g. BSM with two photon detectors behind a beamsplitter. Such measurement operators are consisted of mixed operators on different subsystems’ Hilbert spaces. For current implementation, the Hilbert space on which those mixed operators act on is separated from the rest of the total Hilbert space, and we assume that the involved subsystems have already been moved close in terms of keys. i.e., elements in indices argument are no less than 0 and no greater than num_systems (relative indices w.r.t. the measured state), and the elements MUST BE consecutive.
E.g. For a total system consisted of 4 subsystems (0, 1, 2, 3) each with dimension d, if the entangling measurement happens on (1, 2), then measurement operators on total space will be constructed as
O_tot = kron(kron(identity(d), O), identity(d)),
where the measurement operator on (1, 2) subspace needs to be generated beforehand to feed in the function.
- Parameters:
state (tuple[tuple[complex]]) – state to measure.
indices (tuple[int]) – indices within combined state to measure.
num_systems (int) – number of total systems in the state.
povms (tuple[tuple[tuple[complex]]]) – tuple listing all POVM operators to use for measurement.
truncation (int) – fock space truncation, 1 for qubit system (default 1).
- Returns:
- tuple with two sub-lists.
The first lists each output state, corresponding with the measurement of each POVM. The second lists the probability for each measurement.
- Return type:
tuple[list[array], list[float]]
- sequence.kernel.quantum_utils.pretty_ket(vector, precision: int = 4, tolerance: float = 1e-08) str
- Convert a state vector into a pretty-printed ket string.
- Parameters:
vector (array-like) – The state vector to convert.
precision (int) – The number of decimal places to round the coefficients.
tolerance (float) – The tolerance for considering a coefficient as zero.
- Returns:
A pretty-printed ket string representation of the state vector.
- Return type:
str
- sequence.kernel.quantum_utils.random_state() list
Generate a random pure state vector for a single qubit.
The function returns a list of two elements representing the amplitudes of the quantum state in the computational basis [|0>, |1>]. The first element is a real number (float) corresponding to the amplitude of |0>, and the second element is a complex number corresponding to the amplitude of |1>. :returns: [float, complex] – A list containing the amplitudes of the random qubit state. :rtype: list
- sequence.kernel.quantum_utils.verify_same_state_vector(state1: list, state2: list) bool
- Verify if two quantum state vectors are the same.
Note that two state vectors are the same regardless of the global phase
- Parameters:
state1 (list) – The first quantum state vector.
state2 (list) – The second quantum state vector.
- Returns:
True if the state vectors are the same, False otherwise.
- Return type:
bool