From 9879ecd6999e89c010b9f3a01f3567c66c3370b2 Mon Sep 17 00:00:00 2001 From: niccololaurora Date: Wed, 20 Nov 2024 10:35:52 +0100 Subject: [PATCH] Added number of layers flag to reuploading --- src/qiboml/models/ansatze.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/qiboml/models/ansatze.py b/src/qiboml/models/ansatze.py index 137fa3b..ce10249 100644 --- a/src/qiboml/models/ansatze.py +++ b/src/qiboml/models/ansatze.py @@ -4,15 +4,20 @@ from qibo import Circuit, gates -def ReuploadingCircuit(nqubits: int, qubits: list[int] = None) -> Circuit: +def ReuploadingCircuit( + nqubits: int, qubits: list[int] = None, nlayers: int = 1 +) -> Circuit: if qubits is None: qubits = list(range(nqubits)) circuit = Circuit(nqubits) - for q in qubits: - circuit.add(gates.RY(q, theta=random.random() * np.pi, trainable=True)) - circuit.add(gates.RZ(q, theta=random.random() * np.pi, trainable=True)) - for i, q in enumerate(qubits[:-2]): - circuit.add(gates.CNOT(q0=q, q1=qubits[i + 1])) - circuit.add(gates.CNOT(q0=qubits[-1], q1=qubits[0])) + + for _ in range(nlayers): + for q in qubits: + circuit.add(gates.RY(q, theta=random.random() * np.pi, trainable=True)) + circuit.add(gates.RZ(q, theta=random.random() * np.pi, trainable=True)) + for i, q in enumerate(qubits[:-2]): + circuit.add(gates.CNOT(q0=q, q1=qubits[i + 1])) + circuit.add(gates.CNOT(q0=qubits[-1], q1=qubits[0])) + return circuit