From a73997ca081cb269ab96ed5e8953152b60a51f1b Mon Sep 17 00:00:00 2001 From: J F Kong Date: Tue, 19 Mar 2024 00:25:03 +0800 Subject: [PATCH 1/3] added module docstring --- src/qibo/models/qcnn.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qibo/models/qcnn.py b/src/qibo/models/qcnn.py index f56ed804cf..618d6c79fc 100644 --- a/src/qibo/models/qcnn.py +++ b/src/qibo/models/qcnn.py @@ -1,3 +1,8 @@ +""" This module implements a Quantum Convolutional Neural Network (QCNN) for classification tasks. The QCNN model was originally proposed in: arXiv:1810.03787 _ for the identification of quantum phases. + +The QuantumCNN class in this module provides methods to construct the QCNN. +""" + import numpy as np from qibo import gates, get_backend From 555c502bda32b69ed6ecc8dfeb61d28a49edeb47 Mon Sep 17 00:00:00 2001 From: J F Kong Date: Tue, 19 Mar 2024 00:39:49 +0800 Subject: [PATCH 2/3] updated docstrings for QuantumCNN class --- src/qibo/models/qcnn.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/qibo/models/qcnn.py b/src/qibo/models/qcnn.py index 618d6c79fc..c98fc28019 100644 --- a/src/qibo/models/qcnn.py +++ b/src/qibo/models/qcnn.py @@ -59,6 +59,21 @@ def __init__( twoqubitansatz=None, copy_init_state=None, ): + """ + Initializes the QuantumCNN object. + + Args: + nqubits (int): The number of qubits in the QCNN. + nlayers (int): The number of layers in the QCNN. + nclasses (int, optional): The number of classes for the classification task. Defaults to 2. + params (np.ndarray, optional): The initial parameters for the QCNN. If None, random parameters are generated. Defaults to None. + twoqubitansatz (qibo.core.circuit.Circuit, optional): A two-qubit ansatz for the convolutional layers. If None, a default ansatz is used. Defaults to None. + copy_init_state (bool, optional): Whether to copy the initial state for each shot in the simulation. If None, the behavior depends on the backend. Defaults to None. + + Raises: + ValueError: If nqubits is not larger than 1. + """ + self.nclasses = nclasses self.nqubits = nqubits self.nlayers = nlayers @@ -262,9 +277,6 @@ def Classifier_circuit(self, theta): """ Args: theta: list or numpy.array with the biases and the angles to be used in the circuit. - nlayers: int number of layers of the varitional circuit ansatz. - RY: if True, parameterized Rx,Rz,Rx gates are used in the circuit. - if False, parameterized Ry gates are used in the circuit (default=False). Returns: Circuit implementing the variational ansatz for angles "theta". """ @@ -318,7 +330,6 @@ def Cost_function(self, theta, data=None, labels=None, nshots=10000): """ Args: theta: list or numpy.array with the biases and the angles to be used in the circuit. - nlayers: int number of layers of the varitional circuit ansatz. data: numpy.array data[page][word] (this is an array of kets). labels: list or numpy.array with the labels of the quantum states to be classified. nshots: int number of runs of the circuit during the sampling process (default=10000). From fd296e3dd8cd7fe40f88da4a6ca2429380e9fee3 Mon Sep 17 00:00:00 2001 From: J F Kong Date: Tue, 19 Mar 2024 00:59:18 +0800 Subject: [PATCH 3/3] corrected docstrings --- src/qibo/models/qcnn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibo/models/qcnn.py b/src/qibo/models/qcnn.py index c98fc28019..a616d85e4d 100644 --- a/src/qibo/models/qcnn.py +++ b/src/qibo/models/qcnn.py @@ -67,7 +67,7 @@ def __init__( nlayers (int): The number of layers in the QCNN. nclasses (int, optional): The number of classes for the classification task. Defaults to 2. params (np.ndarray, optional): The initial parameters for the QCNN. If None, random parameters are generated. Defaults to None. - twoqubitansatz (qibo.core.circuit.Circuit, optional): A two-qubit ansatz for the convolutional layers. If None, a default ansatz is used. Defaults to None. + twoqubitansatz (qibo.models.circuit.Circuit, optional): A two-qubit ansatz for the convolutional layers. If None, a default ansatz is used. Defaults to None. copy_init_state (bool, optional): Whether to copy the initial state for each shot in the simulation. If None, the behavior depends on the backend. Defaults to None. Raises: