Multitask Regression/Classification Network Quantum State Reconstruction
Multitask regression/classification network-based quantum state reconstruction as proposed by Luu et al. (2024) [3].
- qsttoolkit.tomography.dlqst.multitask_reconstructor.architecture.build_classification_tail(input_features: Tensor, num_classes: int) Tensor[source]
Builds the classification tail of the multitask reconstructor model.
- Parameters:
input_features (tf.Tensor) – Input feature vector.
num_classes (int) – Number of classes to classify into.
- Returns:
Output tensor of the classification tail.
- Return type:
tf.Tensor
- qsttoolkit.tomography.dlqst.multitask_reconstructor.architecture.build_feature_extractor(input_shape: tuple) Model[source]
Builds the feature extractor branch of the multitask reconstructor model.
- Parameters:
input_shape (tuple) – Shape of the input data.
- Returns:
Feature extractor model.
- Return type:
tf.keras.Model
- qsttoolkit.tomography.dlqst.multitask_reconstructor.architecture.build_multitask_reconstructor(input_shape: tuple, num_classes: int, num_regression_outputs: int) Model[source]
Builds the multitask reconstructor model.
- Parameters:
input_shape (tuple) – Shape of the input data.
num_classes (int) – Number of classes to classify.
num_regression_outputs (int) – Number of regression outputs.
- Returns:
Multitask reconstructor model.
- Return type:
tf.keras.Model
- qsttoolkit.tomography.dlqst.multitask_reconstructor.architecture.build_regression_tail(input_features: Tensor, num_outputs: int) Tensor[source]
Builds the regression tail of the multitask reconstructor model.
- Parameters:
input_features (tf.Tensor) – Input feature vector.
num_outputs (int) – Number of regression outputs.
- Returns:
Output tensor of the regression tail.
- Return type:
tf.Tensor
- class qsttoolkit.tomography.dlqst.multitask_reconstructor.model.MultitaskQuantumStateTomography(X_train: ndarray, X_test: ndarray, y_train: ndarray, y_test: ndarray, label_encoder: LabelEncoder, early_stopping_patience: int = 30, lr_scheduler_factor: float = 0.5, lr_scheduler_patience: int = 15, dim=None)[source]
Bases:
objectA class for training and evaluating a multitask regression/classification model for quantum state tomography.
- X_train
Training data.
- Type:
np.ndarray
- X_test
Test data.
- Type:
np.ndarray
- y_train
Dictionary containing both the training classification and regression labels.
- Type:
dict
- y_test
Dictionary containing both the test classification and regression labels.
- Type:
dict
- label_encoder
Label encoder for the classification labels.
- Type:
sklearn.preprocessing.LabelEncoder
- early_stopping_patience
Number of epochs with no improvement after which training will be stopped. Defaults to 30.
- Type:
int
- lr_scheduler_factor
Factor by which the learning rate will be reduced. Must be < 1. Defaults to 0.5.
- Type:
float
- lr_scheduler_patience
Number of epochs with no improvement after which learning rate will be reduced. Defaults to 15.
- Type:
int
- evaluate_classification(include_confusion_matrix: bool = True, include_classification_report: bool = True)[source]
Evaluates the classification performance of the model.
- Parameters:
include_confusion_matrix (bool) – Whether to include the confusion matrix in the evaluation. Defaults to True.
include_classification_report (bool) – Whether to include the classification report in the evaluation. Defaults to True.
- evaluate_regression()[source]
Evaluates the regression performance of the model by plotting the predictions vs true values for each class.
- infer(data: ndarray)[source]
Infers the quantum state label and key parameter from input data.
- Parameters:
data (np.ndarray) – Input data.
- Returns:
Predicted quantum state labels.
- Return type:
np.ndarray
- train(optimizer=<keras.src.optimizers.adam.Adam object>, classification_loss='sparse_categorical_crossentropy', regression_loss='mse', classification_loss_weight: float = 1.0, regression_loss_weight: float = 0.5, classification_metric: str = 'accuracy', regression_metric: str = 'mae', epochs: int = 30, batch_size: int = 32, validation_split: float = 0.2, verbose='auto')[source]
Compiles and trains the model.
- Parameters:
optimizer – Optimizer to use in the training. Defaults to Adam with learning rate 0.0005, beta_1=0.9, and beta_2=0.999.
classification_loss – Classification loss function to use in the training. Defaults to ‘sparse_categorical_crossentropy’.
regression_loss – Regression loss function to use in the training. Defaults to ‘mse’.
classification_loss_weight (float) – Weight of the classification loss in the total loss. Defaults to 1.0.
regression_loss_weight (float) – Weight of the regression loss in the total loss. Defaults to 1.0.
classification_metric (str) – Metric to measure classification performance during training. Defaults to ‘accuracy’.
regression_metric (str) – Metric to measure regression performance during training. Defaults to ‘mse’.
epochs (int) – Number of epochs to train the model. Defaults to 30.
batch_size (int) – Training batch size. Defaults to 32.
validation_split (float) – Fraction of the training data to use as validation data. Defaults to 0.2.
verbose – Verbosity mode. Defaults to ‘auto’.
- class qsttoolkit.tomography.dlqst.multitask_reconstructor.reconstruction.StateReconstructor[source]
Bases:
objectClass to reconstruct states from the predicted labels and key parameters. Reconstructed states are stored in the predictions_df DataFrame, along with the true states and density matrices.
- add_data(true_labels: list[str], predicted_labels: list[str], true_state_parameters: list[float], predicted_state_parameters: list[float], true_dms: list[ndarray] = None, true_states=None)[source]
Supplies the true and predicted labels and state parameters, and true state density matrices, to the predictions_df DataFrame.
- Parameters:
true_labels (list of str) – List of true labels.
predicted_labels (list of str) – List of predicted labels.
true_state_parameters (list of float) – List of true state parameters.
predicted_state_parameters (list of float) – List of predicted state parameters.
true_dms (list of np.ndarray) – List of true state density matrices.
- calculate_fidelities()[source]
Calculates the fidelities between the true and reconstructed states, and stores them in the self.predictions_df DataFrame ‘fidelity’ column.
- plot_Husimi_Qs(state_range: list[int, int], xgrid: ndarray = None, ygrid: ndarray = None)[source]
Deprecated alias for plot_comparison_Husimi_Qs.
- plot_comparison_Hintons(state_range: list[int, int])[source]
Plots Hinton diagrams of the true and reconstructed density matrices for a given range of states.
- Parameters:
state_range (list of int) – List of two integers, the minimum and maximum state indices to plot.
- plot_comparison_Husimi_Qs(state_range: list[int, int], xgrid: ndarray = None, ygrid: ndarray = None)[source]
Plots Husimi Q functions of the true and reconstructed states for a given range of states.
- Parameters:
state_range (list of int) – List of two integers, the minimum and maximum state indices to plot.
xgrid (np.ndarray) – Grid for the real part of the coherent state parameter. Defaults to np.linspace(-5, 5, 100).
ygrid (np.ndarray) – Grid for the imaginary part of the coherent state parameter. Defaults to np.linspace(-5, 5, 100).
- plot_fidelities(color_by_true_label: bool = False)[source]
Plots a histogram of the fidelities between the true and reconstructed states.
- Parameters:
color_by_true_label (bool) – If True, the fidelities are colored by the true label. Defaults to False.
- reconstruct(Nc=None)[source]
Reconstructs the states from the restricted predicted state parameters, and stores the reconstructed states and density matrices in the self.predictions_df DataFrame.
- restrict_parameters(fock_n_range: list[int, int], binomial_S_range: list[int, int])[source]
Restricts the predicted state parameters to be within a certain set range, depending on the predicted label, in order to enforce physicality of reconstructed states. Restricted predicted state parameters are stored in the self.predictions_df DataFrame.
- Parameters:
fock_n_range (list of int) – List of two integers, the minimum and maximum Fock state parameter values.
binomial_S_range (list of int) – List of two integers, the minimum and maximum binomial state parameter values.