Parametric Sweeps
A sweep is a dimension you step through at the bottom of the circuit builder - different wire indices, gate choices, rotation angles, or LOOP counts - while the rest of the program stays put.
Sweep brackets
Write a sweep as angle brackets around an inner list. The same inner forms as Wire Ranges apply: comma lists, ranges, stepped lists, and angle lists with deg suffixes.
j = <0..5> // wire indices 0 through 5 g = <H,X,Y> // gate name per combo a = <1..35deg> // angle sweep in degrees step = <0.(0.5).3> // scalar angle steps (RX parameter)
Assign a bracket to a variable, or put it inline on the line that consumes it (see below).
Named sweep variables
name = <…> declares a sweep dimension. The name shows up in the combo bar; each combo picks one value from the bracket.
j = <0..5> H j // Hadamard on the current j wire k = j+2 H j,k // two wires from one combo index
Reassigning a sweep variable before it is used replaces that dimension (handy when you meant <1..3> not <1..5>). After the name appears on a gate line, reassignment is blocked.
Inline sweeps
Skip the assignment when the bracket only appears once:
<H,X> 0
<H,Y,X,RX>(45deg) 0
LOOP <0..4> {
H 0
}
Inline gate sweeps pick the gate type from the bracket; a shared angle in parentheses after the bracket applies to rotation gates in the set (RX, RY, RZ, P) and is ignored for H, X, Y. You can also put the angle after the wire: <H,Y,X,RX> 0 45deg.
LOOP <0..4> and LOOP countVar work when the count is a scalar sweep dimension (including 0 in the bracket where you need it).
Stepping combos in the builder
When the scanner finds at least one sweep dimension, a control row appears under the circuit:
- Combo - global index through the Cartesian product of all dimensions.
- Per-dimension fields - jump to a value or type an index/label for that axis.
- Order arrows (two or more dimensions) - swap which axis advances faster when you step combos. Last in the order changes fastest.
The circuit diagram and analysis view always reflect the active combo. Invalid pairings (e.g. duplicate wires after a derived offset) surface as ordinary validation errors on the lines that break.
Circuit builder ↔ code sync
Editing the diagram rewrites the main editor, but sweep assignments and variable names are kept deliberately:
- Lines like
j = <0..5>andk = j+2are never dropped when you add gates from the palette. - On a gate line you already wrote with variables (
H j,k), those tokens stay for the wires they referred to. Add a gate on wire1in the same column →H j,1,k. Remove that gate → back toH j,k. - Wires you place on a new column, or wires that never had a name on that line, stay as plain indices (
H 3,MEASURE (0,1,2)). The builder does not guess sweep-relative names likej+3for you.
H j,1,k is valid source even if some combos later collide; the validator will tell you when they do.
What can be swept
| Bracket contents | Typical use |
|---|---|
0..max, 1,3,5, stepped lists | Wire-index sweeps - use the variable as a register |
H,X,RX, … | Gate-type sweeps on one wire |
1..90deg, 0.(pi/8).pi | Rotation angles bound to RX(abc) or trailing angle syntax |
| Scalar lists without wire indices | LOOP counts and numeric gate parameters |
Angle sweeps and gate sweeps cannot be fed into generic scalar expressions; wire-index sweeps can, via derived assignments like k = j+1.
Performance
#settings UseOptimizedSweep true (default) speeds up full sweep runs and combo stepping. Turn it off only when you are comparing against an older code path.