qsttoolkit.tomography Subpackage

This subpackage contains models for performing quantum state tomography. Each model is implemented in its own class, each inheriting basic performance analysis and plotting functions from a parent class qsttoolkit.tomography.QST.

The fundamental aim of QSTToolkit is to provide modular, ‘drag-and-drop’ functions for researching, testing and comparing quantum state tomography methods in different experimental situations. This is enabled by the CustomQuantumStateTomography class, which allows a user to define a single pass of their own custom tomography training loop. Experimentation with combinations of tomography components is encouraged - for example, using a generator model with a different density matrix parametrization and loss function.

Traditional QST

Traditional quantum state tomography is implemented using Maximum Likelihood Estimation (MLE):

Deep Learning QST

Four deep learning models are currently implemented using TensorFlow: one for quantum state discrimination and three for quantum state tomography. Each model has a dedicated class:

Global QST Utility Functions

Functions used in both traditional and deep learning methods for quantum state tomography.

class qsttoolkit.tomography.QST.CustomQuantumStateTomography(model, training_step_fn)[source]

Bases: QuantumStateTomography

A class for designing custom quantum state tomography methods.

model

Model used for the reconstruction.

Type:

tf.keras.Model

training_step_fn

Function that defines the training step for the model. Arguments must include [model, measurement_data, measurement_operators]. Must return the generated density matrix and the loss.

Type:

callable

reconstruct(measurement_data, measurement_operators, epochs, optimizer, verbose_interval: int = None, num_progress_saves: int = None, true_dm: Tensor = None, time_log_interval: int = None, **kwargs)[source]

Reconstructs the density matrix using a custom method.

Parameters:
  • initial_dm (np.ndarray) – Initial density matrix.

  • measurement_data (np.ndarray) – Frequency of each measurement outcome.

  • measurement_operators (np.ndarray) – Projective operators corresponding to the measurement outcomes.

  • epochs (int) – Number of training epochs.

  • optimizer (tf.keras.optimizers.Optimizer) – Optimizer for the training step.

  • verbose_interval (int) – Interval at which to print progress updates. Defaults to None.

  • num_progress_saves (int) – Number of intermediate progress saves to make. Defaults to None.

  • true_dm (tf.Tensor) – True density matrix used for calculating fidelities. Defaults to None.

  • time_log_interval (int) – Interval at which to log the time taken after each epoch. Defaults to None.

class qsttoolkit.tomography.QST.QuantumStateTomography[source]

Bases: object

A parent class for all quantum state tomography methods.

fidelity(true_dm: ndarray) float[source]

Computes the fidelity between the true and reconstructed density matrices.

Parameters:

true_dm (np.ndarray) – True density matrix.

Returns:

Fidelity between the true and reconstructed density matrices.

Return type:

float

plot_comparison_Hintons(true_dm: ndarray)[source]

Deprecated alias for plot_comparison_hintons. Plots Hinton diagrams of the true and reconstructed density matrices.

plot_comparison_Husimi_Qs(true_dm: ndarray, xgrid: ndarray, pgrid: ndarray)[source]

Deprecated alias for plot_comparison_husimi_Qs. Plots the Husimi Q functions of the true and reconstructed density matrices.

plot_comparison_hintons(true_dm: ndarray)[source]

Plots Hinton diagrams of the true and reconstructed density matrices.

Parameters:

true_dm (np.ndarray) – True density matrix.

plot_comparison_husimi_Qs(true_dm: ndarray, xgrid: ndarray, pgrid: ndarray)[source]

Plots the Husimi Q functions of the true and reconstructed density matrices.

Parameters:
  • true_dm (np.ndarray) – True density matrix.

  • xgrid (np.ndarray) – Phase space X quadrature grid.

  • pgrid (np.ndarray) – Phase space P quadrature grid.

plot_comparison_wigners(true_dm: ndarray, xgrid: ndarray, pgrid: ndarray)[source]

Plots the Wigner functions of the true and reconstructed density matrices.

Parameters:
  • true_dm (np.ndarray) – True density matrix.

  • xgrid (np.ndarray) – Phase space X quadrature grid.

  • pgrid (np.ndarray) – Phase space P quadrature grid.

plot_fidelities(true_dm=None)[source]

Plots the fidelity between the true and reconstructed density matrices over epochs.

plot_intermediate_Hintons()[source]

Deprecated alias for plot_intermediate_hintons. Plots Hinton diagrams of the density matrices in the progress_saves attribute.

plot_intermediate_Husimi_Qs(xgrid: ndarray, pgrid: ndarray)[source]

Deprecated alias for plot_intermediate_husimi_Qs. Plots the Husimi Q functions of the density matrices in the progress_saves attribute.

plot_intermediate_hintons()[source]

Plots Hinton diagrams of the density matrices in the progress_saves attribute.

plot_intermediate_husimi_Qs(xgrid: ndarray, pgrid: ndarray)[source]

Plots the Husimi Q functions of the density matrices in the progress_saves attribute.

Parameters:
  • xgrid (np.ndarray) – Phase space X quadrature grid.

  • pgrid (np.ndarray) – Phase space P quadrature grid.

plot_intermediate_wigners(xgrid: ndarray, pgrid: ndarray)[source]

Plots the Wigner functions of the density matrices in the progress_saves attribute.

Parameters:
  • xgrid (np.ndarray) – Phase space X quadrature grid.

  • pgrid (np.ndarray) – Phase space P quadrature grid.

plot_losses()[source]

Plots the losses over epochs.

plot_times()[source]

Plots the cumulative time taken for each epoch.

qsttoolkit.tomography.QST.parameterise_density_matrix(rho: Tensor) Tensor[source]

Deprecated alias for parametrize_density_matrix.

qsttoolkit.tomography.QST.parametrize_density_matrix(rho: Tensor) Tensor[source]

parametrizes the density matrix using the Cholesky decomposition.

Parameters:

rho (tf.Tensor) – Density matrix to be parametrized.

Returns:

Cholesky decomposition of the density matrix.

Return type:

tf.Tensor

qsttoolkit.tomography.QST.positivity_constraint(params: ndarray) float[source]

Constraint to ensure the density matrix is positive semi-definite.

Parameters:

params (np.ndarray) – Flattened vector of real parameters.

Returns:

Smallest eigenvalue of the reconstructed density matrix.

Return type:

float

qsttoolkit.tomography.QST.reconstruct_density_matrix(params: Tensor, reg: float = 1e-10, dim=None) Tensor[source]

Reconstructs the density matrix from the Cholesky decomposition.

Parameters:

params (tf.Tensor) – Cholesky decomposition of the density matrix.

Returns:

Reconstructed density matrix.

Return type:

tf.Tensor

qsttoolkit.tomography.QST.trace_constraint(params: ndarray) float[source]

Constraint function to ensure the trace of the density matrix is 1.

Parameters:

params (np.ndarray) – Flattened vector of real parameters.

Returns:

Difference between the trace of the reconstructed density matrix and 1.

Return type:

float

Loss Functions

qsttoolkit.tomography.loss.kl_divergence(rho: Tensor, frequency_data: Tensor, measurement_operators: list, L1_reg: float = 0, thresh_reg: float = 0, thresh_reg_threshold: float = 0.01) Tensor[source]

Computes the Kullback-Leibler divergence of the data given the density matrix.

Parameters:
  • rho (tf.Tensor) – Density matrix.

  • frequency_data (tf.Tensor) – Frequency of each measurement outcome.

  • measurement_operators (list of Qobj) – Projective measurement operators corresponding to the measurement outcomes.

  • L1_reg (float) – L1 regularisation parameter. Defaults to 0.

  • thresh_reg (float) – Threshold regularisation parameter. Defaults to 0.

  • thresh_reg_threshold (float) – Threshold for the threshold regularisation. Defaults to 0.01.

Returns:

Kullback-Leibler divergence of the data given the density matrix.

Return type:

tf.Tensor

qsttoolkit.tomography.loss.log_likelihood(rho: Tensor, frequency_data: Tensor, measurement_operators: list, L1_reg: float = 0, thresh_reg: float = 0, thresh_reg_threshold: float = 0.01, dim=None) Tensor[source]

Computes the negative log-likelihood of the data given the density matrix.

Parameters:
  • rho (tf.Tensor) – Density matrix.

  • frequency_data (tf.Tensor) – Frequency of each measurement outcome.

  • measurement_operators (list of Qobj) – Projective measurement operators corresponding to the measurement outcomes.

  • L1_reg (float) – L1 regularisation parameter. Defaults to 0.

  • thresh_reg (float) – Threshold regularisation parameter. Defaults to 0.

  • thresh_reg_threshold (float) – Threshold for the threshold regularisation. Defaults to 0.01.

Returns:

negative log-likelihood of the data given the density matrix.

Return type:

tf.Tensor

qsttoolkit.tomography.loss.mean_absolute_error(rho: Tensor, frequency_data: Tensor, measurement_operators: list, L1_reg: float = 0, thresh_reg: float = 0, thresh_reg_threshold: float = 0.01) Tensor[source]

Computes the mean absolute error of the data given the density matrix.

Parameters:
  • rho (tf.Tensor) – Density matrix.

  • frequency_data (tf.Tensor) – Frequency of each measurement outcome.

  • measurement_operators (list of Qobj) – Projective measurement operators corresponding to the measurement outcomes.

  • L1_reg (float) – L1 regularisation parameter. Defaults to 0.

  • thresh_reg (float) – Threshold regularisation parameter. Defaults to 0.

  • thresh_reg_threshold (float) – Threshold for the threshold regularisation. Defaults to 0.01.

Returns:

Mean absolute error of the data given the density matrix.

Return type:

tf.Tensor

qsttoolkit.tomography.loss.mean_squared_error(rho: Tensor, frequency_data: Tensor, measurement_operators: list, L1_reg: float = 0, thresh_reg: float = 0, thresh_reg_threshold: float = 0.01) Tensor[source]

Computes the mean squared error of the data given the density matrix.

Parameters:
  • rho (tf.Tensor) – Density matrix.

  • frequency_data (tf.Tensor) – Frequency of each measurement outcome.

  • measurement_operators (list of Qobj) – Projective measurement operators corresponding to the measurement outcomes.

  • L1_reg (float) – L1 regularisation parameter. Defaults to 0.

  • thresh_reg (float) – Threshold regularisation parameter. Defaults to 0.

  • thresh_reg_threshold (float) – Threshold for the threshold regularisation. Defaults to 0.01.

Returns:

Mean squared error of the data given the density matrix.

Return type:

tf.Tensor

qsttoolkit.tomography.loss.squared_hellinger_distance(rho: Tensor, frequency_data: Tensor, measurement_operators: list, L1_reg: float = 0, thresh_reg: float = 0, thresh_reg_threshold: float = 0.01) Tensor[source]

Computes the squared Hellinger distance of the data given the density matrix.

Parameters:
  • rho (tf.Tensor) – Density matrix.

  • frequency_data (tf.Tensor) – Frequency of each measurement outcome.

  • measurement_operators (list of Qobj) – Projective measurement operators corresponding to the measurement outcomes.

  • L1_reg (float) – L1 regularisation parameter. Defaults to 0.

  • thresh_reg (float) – Threshold regularisation parameter. Defaults to 0.

  • thresh_reg_threshold (float) – Threshold for the threshold regularisation. Defaults to 0.01.

Returns:

Squared Hellinger distance of the data given the density matrix.

Return type:

tf.Tensor