Skip to content

Commit

Permalink
Added number of layers flag to reuploading
Browse files Browse the repository at this point in the history
  • Loading branch information
niccololaurora committed Nov 20, 2024
1 parent 05f8d48 commit 9879ecd
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/qiboml/models/ansatze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9879ecd

Please sign in to comment.