Skip to content

Commit

Permalink
Merge pull request #1275 from qiboteam/qcnn-docs
Browse files Browse the repository at this point in the history
Qcnn docs
  • Loading branch information
scarrazza committed Apr 5, 2024
2 parents 7c4e8bc + fd296e3 commit d6209f4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/qibo/models/qcnn.py
Original file line number Diff line number Diff line change
@@ -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 <https://arxiv.org/abs/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
Expand Down Expand Up @@ -54,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.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:
ValueError: If nqubits is not larger than 1.
"""

self.nclasses = nclasses
self.nqubits = nqubits
self.nlayers = nlayers
Expand Down Expand Up @@ -257,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".
"""
Expand Down Expand Up @@ -313,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).
Expand Down

0 comments on commit d6209f4

Please sign in to comment.