Quantum Manager

This module defines the quantum manager class, to track quantum states.

The states may currently be defined in two possible ways:
  • KetState

  • DensityMatrix

  • FockDensityMatrix

  • Bell Diagonal

The manager defines an API for interacting with quantum states.

class sequence.kernel.quantum_manager.QuantumManager(truncation: int = 1)

Class to track and manage quantum states (abstract).

All states stored are of a single formalism (by default as a ket vector).

Class Attributes:

_registry (dict): mapping of formalism names to manager classes. _global_formalism_lock (Lock): lock for managing global formalism. _global_formalism (str): global formalism.

states

mapping of state keys to quantum state objects.

Type:

dict[int, State]

_least_available

tracking the total number of quantum states in the quantum network

Type:

int

truncation

maximally allowed number of excited states for elementary subsystems. Default is 1 for qubit.

Type:

int

dim

subsystem Hilbert space dimension. dim = truncation + 1

Type:

int

classmethod create(*args, **kwargs) QuantumManager

Create a new instance of the quantum manager.

get(key: int) State

Method to get quantum state stored at an index.

Parameters:

key (int) – key for quantum state.

Returns:

quantum state at supplied key.

Return type:

State

abstractmethod new(state) int

Method to create a new quantum state.

Parameters:

state – complex amplitudes of new state. Type depends on type of subclass.

Returns:

key for new state generated.

Return type:

int

classmethod register(name: str, manager_class=None)

Register a quantum manager class.

Parameters:
  • name (str) – The name of the quantum manager.

  • manager_class (type, optional) – The manager class to register.

remove(key: int) None

Method to remove state stored at key.

Parameters:

key (int) – The key of the state to remove.

abstractmethod run_circuit(circuit: Circuit, keys: list[int], meas_samp=None)

Method to run a circuit on a given set of quantum states.

Parameters:
  • circuit (Circuit) – quantum circuit to apply.

  • keys (list[int]) – list of keys for quantum states to apply circuit to.

  • meas_samp (float) – random sample used for measurement.

Returns:

dictionary mapping qstate keys to measurement results.

Return type:

dict[int, int]

abstractmethod set(keys: list[int], amplitudes: Any) None

Method to set quantum state at a given key(s).

Parameters:
  • keys (list[int]) – key(s) of state(s) to change.

  • amplitudes (any) – Amplitudes to set state to, type determined by type of subclass.

classmethod set_global_manager_formalism(formalism: str)

Set the global manager formalism.

Parameters:

formalism (str) – The formalism to set as the global manager formalism.

set_states(states: dict)

Set multiple quantum states.

Parameters:

states (dict) – A dictionary mapping keys to their corresponding quantum states.

class sequence.kernel.quantum_manager.QuantumManagerBellDiagonal(**kwargs)

Class to track and manage quantum states with the bell diagonal formalism.

To be aligned with analytical formulae, we have assumed that successfully generated EPR pair is in Phi+ form. And note that the 4 BDS elements are in I, Z, X, Y order.

  • BDS is only used for entanglement distribution (generation, swapping, purification), assuming underlying errors being purely Pauli.

  • All manipulation results can be tracked analytically, without explicit quantum gates / channels / measurements.

get(key: int)

Method to get quantum state stored at an index.

Parameters:

key (int) – key for quantum state.

Returns:

quantum state at supplied key.

Return type:

State

new(state=None) int

Generates new quantum state key for quantum manager.

NOTE: since this generates only one state, there will be no corresponding entangled state stored. The Bell diagonal state formalism assumes entangled states; thus, attempting to call get will return an exception until entangled. The purpose of this function is thus mainly to avoid state key collisions.

Parameters:

state (Any) – to conform to type definition (does nothing).

Returns:

quantum state key corresponding to state.

Return type:

int

run_circuit(*args, **kwargs)

Method to run a circuit on a given set of quantum states.

Parameters:
  • circuit (Circuit) – quantum circuit to apply.

  • keys (list[int]) – list of keys for quantum states to apply circuit to.

  • meas_samp (float) – random sample used for measurement.

Returns:

dictionary mapping qstate keys to measurement results.

Return type:

dict[int, int]

set(keys: list[int], diag_elems: list[float]) None

Method to set quantum state at a given key(s).

Parameters:
  • keys (list[int]) – key(s) of state(s) to change.

  • amplitudes (any) – Amplitudes to set state to, type determined by type of subclass.

class sequence.kernel.quantum_manager.QuantumManagerDensity(**kwargs)

Class to track and manage states with the density matrix formalism.

get_ascending_keys(key: int) DensityState
Method to get quantum state stored at an index.

Reorders qubits (in-place) in ascending order of keys before returning.

Parameters:

key (int) – key for quantum state.

Returns:

quantum state at supplied key.

Return type:

DensityState

new(state=([1 + 0j, 0j], [0j, 0j])) int

Method to create a new density matrix state.

Parameters:

state (list[list[complex]]) – density matrix state.

Returns:

key of the new state.

Return type:

int

reorder_qubits_ascending_keys(state: DensityState) None
Update the quantum state (in-place) to match the ascending order of keys.

Meanwhile, the reordered state is also set in the quantum manager.

Parameters:

state (DensityState) – The quantum state to reorder.

run_circuit(circuit: Circuit, keys: list[int], meas_samp=None) dict[int, int]

Method to run a circuit on a given list of keys.

Parameters:
  • circuit (Circuit) – quantum circuit to apply.

  • keys (list[int]) – list of keys to apply circuit to.

  • meas_samp (float) – random number between 0 and 1 used for measurement.

Returns:

dictionary mapping qstate keys to measurement results. If non-measurement, dict: empty dictionary.

Return type:

If measurement, dict[int, int]

set(keys: list[int], state: list[list[complex]]) None

Method to set the quantum state at the given keys.

The state argument should be passed as list[list[complex]], where each internal list is a row. However, the state may also be given as a one-dimensional pure state. If the list is one-dimensional, will be converted to matrix with the outer product operation.

Parameters:
  • keys (list[int]) – list of quantum manager keys to modify.

  • state – quantum state to set input keys to.

set_to_one(key: int)

Set the qubit at the given key to the |1><1| state.

Parameters:

key (int) – key of the qubit to set to |1><1|.

set_to_zero(key: int)

Set the qubit at the given key to the |0><0| state.

Parameters:

key (int) – key of the qubit to set to |0><0|.

class sequence.kernel.quantum_manager.QuantumManagerDensityFock(truncation: int = 1, **kwargs)

Class to track and manage Fock states with the density matrix formalism.

add_loss(key, loss_rate)

Method to apply generalized amplitude damping channel on a single subspace corresponding to key.

Parameters:
  • key (int) – key for the subspace experiencing loss.

  • loss_rate (float) – loss rate for the quantum channel.

build_ladder()

Generate matrix of creation and annihilation (ladder) operators on truncated Hilbert space.

measure(keys: list[int], povms: list[ndarray[tuple[Any, ...], dtype[_ScalarT]]], meas_samp: float) int

Method to measure subsystems at given keys in POVM formalism.

Serves as wrapper for private _measure method, performing quantum manager specific operations.

Parameters:
  • keys (list[int]) – list of keys to measure.

  • povms – (list[array]): list of POVM operators to use for measurement.

  • meas_samp (float) – random measurement sample to use for computing resultant state.

Returns:

measurement as index of matching POVM in supplied tuple.

Return type:

int

new(state=None) int

Method to create a new state with key

Parameters:

state (str | list[complex] | list[list[complex]]) – amplitudes of new state. Default value is ‘gnd’: create zero-excitation state with current truncation. Other inputs are passed to the constructor of DensityState.

run_circuit(circuit: Circuit, keys: list[int], meas_samp=None) dict[int, int]

Currently the Fock states do not support quantum circuits. This method is only to implement abstract method of parent class and SHOULD NOT be called after instantiation.

set(keys: list[int], state: list[list[complex]]) None

Method to set the quantum state at the given keys.

The state argument should be passed as list[list[complex]], where each internal list is a row. However, the state may also be given as a one-dimensional pure state. If the list is one-dimensional, will be converted to matrix with the outer product operation.

Parameters:
  • keys (list[int]) – list of quantum manager keys to modify.

  • state – quantum state to set input keys to.

set_to_zero(key: int)

set the state to ground (zero) state.

class sequence.kernel.quantum_manager.QuantumManagerKet(**kwargs)

Class to track and manage quantum states with the ket vector formalism.

get_ascending_keys(key: int) KetState
Method to get quantum state stored at an index.

Reorders qubits (in-place) in ascending order of keys before returning.

Parameters:

key (int) – key for quantum state.

Returns:

quantum state at supplied key.

Return type:

KetState

new(state=[1 + 0j, 0j]) int

Method to create a new ket state.

Parameters:

state (list[complex]) – amplitudes of new state.

Returns:

the key of the new state.

Return type:

int

reorder_qubits_ascending_keys(state: KetState) None
Update the quantum state (in-place) to match the ascending order of keys.

Meanwhile, the reordered state is also set in the quantum manager.

Parameters:

state (KetState) – The quantum state to reorder.

run_circuit(circuit: Circuit, keys: list[int], meas_samp=None) dict[int, int]

Method to run a circuit on a given list of keys.

Parameters:
  • circuit (Circuit) – quantum circuit to apply.

  • keys (list[int]) – list of keys to apply circuit to.

  • meas_samp (float) – random sample used for measurement result.

Returns:

dictionary mapping qstate keys to measurement results. If non-measurement, dict: empty dictionary.

Return type:

If measurement, dict[int, int]

set(keys: list[int], amplitudes: list[complex]) None

Set the quantum state for the given keys.

Parameters:
  • keys (list[int]) – list of keys of the quantum state.

  • amplitudes (list[complex]) – amplitudes to set the state to.

set_to_one(key: int) None

Set the qubit at the given key to the |1> state.

Parameters:

key (int) – key of the qubit to set to |1>.

set_to_zero(key: int) None

Set the qubit at the given key to the |0> state.

Parameters:

key (int) – key of the qubit to set to |0>.