Convolutional Neural Network (CNN) Quantum State Discrimination
Convolutional Neural Network-based quantum state discrimination as proposed by Ahmed et al. (2021) [1].
- qsttoolkit.tomography.dlqst.CNN_classifier.architecture.build_classifier(data_input_shape: tuple) Model[source]
Builds a CNN classifier network for QST data.
- Parameters:
data_input_shape (tuple) – Shape of the input data.
- Returns:
Classifier model.
- Return type:
tf.keras.Model
- class qsttoolkit.tomography.dlqst.CNN_classifier.model.CNNQuantumStateDiscrimination(X_train: ndarray, X_test: ndarray, y_train: ndarray, y_test: ndarray, label_encoder: LabelEncoder, early_stopping_patience: int = 5, lr_scheduler_factor: float = 0.5, lr_scheduler_patience: int = 3, dim=None)[source]
Bases:
objectA class for training and evaluating a CNN classifier for quantum state discrimination.
- X_train
Training data.
- Type:
np.ndarray
- X_test
Test data.
- Type:
np.ndarray
- y_train
Training labels.
- Type:
np.ndarray
- y_test
Test labels.
- Type:
np.ndarray
- label_encoder
Label encoder.
- Type:
sklearn.preprocessing.LabelEncoder
- early_stopping_patience
Number of epochs with no improvement after which training will be stopped. Defaults to 5.
- Type:
int
- lr_scheduler_factor
Factor by which the learning rate will be reduced. Defaults to 0.5.
- Type:
float
- lr_scheduler_patience
Number of epochs with no improvement after which learning rate will be reduced. Defaults to 3.
- Type:
int
- classify(X: ndarray) ndarray[source]
Classifies a set of quantum states using the trained model.
- Parameters:
X (np.ndarray) – Quantum states to classify.
- Returns:
Predicted labels.
- Return type:
np.ndarray
- evaluate_classification(include_confusion_matrix: bool = True, include_classification_report: bool = True)[source]
Evaluates the model on the test data.
- 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.
- train(optimizer='adam', loss='sparse_categorical_crossentropy', metrics: list[str] = ['accuracy'], epochs: int = 20, 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’.
loss – Loss function to use in the training. Defaults to ‘sparse_categorical_crossentropy’.
metrics (list[str]) – Metrics to measure model performance during training. Defaults to [‘accuracy’].
epochs (int) – Number of epochs to train the model. Defaults to 20.
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’.