Generative Adversarial Network (GAN) Quantum State Tomography

Generative Adversarial Network-based quantum state tomography as proposed by Ahmed et al. (2021) [2].

class qsttoolkit.tomography.dlqst.GAN_reconstructor.architecture.CholeskyLowerTriangular(*args, **kwargs)[source]

Bases: Layer

Custom layer to convert a 2D complex-valued tensor into a lower triangular Cholesky decomposition. input tensor is reshaped into a lower triangular matrix, and the diagonal is set to be real.

call(input)[source]

Define the forward pass logic.

compute_output_shape(input_shape)[source]

Compute the output shape of the layer.

get_config()[source]

Save the layer configuration for serialisation.

class qsttoolkit.tomography.dlqst.GAN_reconstructor.architecture.DensityMatrix(*args, **kwargs)[source]

Bases: Layer

Custom layer to convert a 2D complex-valued tensor into a density matrix. The input tensor is reshaped into a lower triangular matrix, and the diagonal is set to be real.

call(input)[source]

Define the forward pass logic.

compute_output_shape()[source]

Compute the output shape of the layer.

get_config()[source]

Save the layer configuration for serialisation.

qsttoolkit.tomography.dlqst.GAN_reconstructor.architecture.build_discriminator(data_vector_input_shape: tuple) Model[source]

Builds the discriminator to classify the reconstructed density matrices.

Parameters:

data_vector_input_shape (tuple) – Shape of the input measurement data vector.

Returns:

Discriminator model.

Return type:

tf.keras.Model

qsttoolkit.tomography.dlqst.GAN_reconstructor.architecture.build_generator(data_vector_input_shape: tuple) Model[source]

Builds the generator to reconstruct a density matrix Cholesky decomposition from measurement data vectors.

Parameters:
  • data_vector_input_shape (tuple) – Shape of the input measurement data vector.

  • noise_parameters_input_shape (list) – Shape of the input noise parameters. Defaults to []. Currently not implemented.

Returns:

Generator model.

Return type:

tf.keras.Model

class qsttoolkit.tomography.dlqst.GAN_reconstructor.model.GANQuantumStateTomography(data_dim: int = None, latent_dim=None, dim=None)[source]

Bases: QuantumStateTomography

A class for training and evaluating a GAN for quantum state tomography.

data_dim

Dimensions of the data vector.

Type:

int

plot_loss_space()[source]

Plots the loss functions against each other, coloured by the fidelities.

plot_losses()[source]

Plots the generator and discriminator losses over epochs.

reconstruct(measurement_data: list, measurement_operators: list, epochs: int = 100, gen_optimizer: ~keras.src.optimizers.optimizer.Optimizer = <keras.src.optimizers.adam.Adam object>, disc_optimizer: ~keras.src.optimizers.optimizer.Optimizer = <keras.src.optimizers.adam.Adam object>, loss_fn: ~keras.src.losses.loss.Loss = <LossFunctionWrapper(<function binary_crossentropy>, kwargs={'from_logits': False, 'label_smoothing': 0.0, 'axis': -1})>, verbose_interval: int = None, num_progress_saves: int = None, true_dm: ~tensorflow.python.framework.tensor.Tensor = None, time_log_interval: int = None)[source]

Trains the GAN to reconstruct the density matrix from measurement data.

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

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

  • epochs (int) – Number of epochs to train for. Defaults to 100.

  • gen_optimizer (tf.keras.optimizers.Optimizer) – Generator optimizer. Defaults to Adam with learning rate 0.0002.

  • disc_optimizer (tf.keras.optimizers.Optimizer) – Discriminator optimizer. Defaults to Adam with learning rate 0.0002.

  • loss_fn (tf.keras.losses.Loss) – Loss function to use. Defaults to BinaryCrossentropy.

  • 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.

qsttoolkit.tomography.dlqst.GAN_reconstructor.train.train(generator: ~keras.src.models.model.Model, discriminator: ~keras.src.models.model.Model, measurement_data: list, measurement_operators: list, epochs: int = 100, gen_optimizer: ~keras.src.optimizers.optimizer.Optimizer = None, disc_optimizer: ~keras.src.optimizers.optimizer.Optimizer = None, loss_fn: ~keras.src.losses.loss.Loss = <LossFunctionWrapper(<function binary_crossentropy>, kwargs={'from_logits': False, 'label_smoothing': 0.0, 'axis': -1})>, verbose_interval: int = None, num_progress_saves: int = None, true_dm: ~tensorflow.python.framework.tensor.Tensor = None, time_log_interval: int = None) tuple[source]

Trains the generator and discriminator networks adversarially using the given measurement data and projective measurement operators.

Parameters:
  • generator (tf.keras.Model) – Generator network.

  • discriminator (tf.keras.Model) – Discriminator network.

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

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

  • epochs (int) – Number of epochs to train for. Defaults to 100.

  • gen_optimizer (tf.keras.optimizers.Optimizer) – Generator optimizer. Defaults to Adam with learning rate 0.0002.

  • disc_optimizer (tf.keras.optimizers.Optimizer) – Discriminator optimizer. Defaults to Adam with learning rate 0.0002.

  • loss_fn (tf.keras.losses.Loss) – Loss function to use. Defaults to BinaryCrossentropy.

  • 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.

Returns:

  • list of tf.Tensor – Generator losses.

  • list of tf.Tensor – Discriminator losses.

  • list of np.ndarray – Intermediate progress saves.

  • list of float – Fidelities of the generator density matrices with respect to the true density matrix.

  • list of float – Time taken after each epoch.