Ansatz
The ansatz submodule provides ready-to-use circuit templates (Ansätze) and a lightweight framework for writing your own. To author a custom template:
Call
super().__init__(nqubits=...)inside__init__to set the circuit width.Add gates in any order with
self.add(gate), loops are fine, and you can keep references to anyParameterobjects you want to expose later.
Example
from qilisdk.core.variables import Parameter
from qilisdk.digital import H, RX, CZ
from qilisdk.digital.ansatz import Ansatz
class NewAnsatz(Ansatz):
def __init__(self, nqubits: int, beta: float):
super().__init__(nqubits=nqubits)
self.beta = Parameter("beta", value=beta)
# Layer 1: put each qubit in superposition
for q in range(self.nqubits):
self.add(H(q))
# Layer 2: simple linear entangler
for q in range(self.nqubits - 1):
self.add(CZ(q, q + 1))
# Layer 3: parameterized mixer
for q in range(self.nqubits):
self.add(RX(q, theta=self.beta))
Once defined, the subclass behaves exactly like any other circuit: you can draw it, bind parameters, or hand it off to backends.
For a prebuilt option, consider any of:
HardwareEfficientAnsatz for a simple layered structure that can be adapted to various hardware topologies.
TrotterizedSchedule for simulating analog dynamics with Trotterization.
QAOA for combinatorial optimization problems.