Preparing the catalog and filters…Katalog ve filtreler hazırlanıyor…
Starter code
module triangle_qaoa;
@seed(23);
param gamma: Angle = 0.7;
param beta: Angle = 0.4;
fn main() {
let q = qreg[3];
H(q[0]);
H(q[1]);
H(q[2]);
RZZ(q[0], q[1], gamma);
RZZ(q[1], q[2], gamma);
RZZ(q[0], q[2], gamma);
Rx(q[0], beta);
Rx(q[1], beta);
Rx(q[2], beta);
let cut = expect -0.5 Z(q[0]) Z(q[1]) -0.5 Z(q[1]) Z(q[2]) -0.5 Z(q[0]) Z(q[2]);
// The expected triangle cut is 1.5 + cut, so maximize this observable.
train {
objective: maximize cut;
optimizer: adam(lr = 0.15);
steps: 50;
}
return cut;
}Expected output
Three qubits encode graph nodes
RZZ gates encode all three edges
The train block optimizes gamma and beta
The exact triangle max cut is 2
Debugging checklist
Run the triangle source
Inspect gamma and beta history
Identify all RZZ edge terms
Compare the best bitstring with maxCut=2
Extension challenge
Build a four-cycle with p=2 and target an approximation ratio of at least 0.9.