Skip to content

Commit

Permalink
feat: complete example
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoRobbiati committed Nov 6, 2024
1 parent a489220 commit 0e9018e
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 140 deletions.
5 changes: 4 additions & 1 deletion src/qiboml/models/ansatze.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

import numpy as np
from qibo import Circuit, gates
from qibo.config import raise_error


def entangling_circuit(nqubits: int, entangling_gate: gates.Gate = gates.CNOT):
"""Construct entangling layer."""
if nqubits < 2:
raise_error(ValueError, "This layer cannot be used if nqubits is < 2.")
circuit = Circuit(nqubits)
for q in range(nqubits):
circuit.add(entangling_gate(q0=q % nqubits, q1=(q + 1) % nqubits))
Expand All @@ -31,7 +34,7 @@ def layered_ansatz(
for q in qubits:
for gate in gates_list:
circuit.add(gate(q, theta=random.random(), trainable=True))
if entanglement:
if entanglement and nqubits > 1:
circuit += entangling_circuit(nqubits, gates.CNOT)

return circuit
Loading

0 comments on commit 0e9018e

Please sign in to comment.