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) p = <10%.10%.90%> // stepped probability sweep from 0.1 to 0.9
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
}
X tolist(<0b0000000.0b100.0b1111111>)
qft(0..6)
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.
A bitstring sweep inside tolist() (or len()) is the same idea: each combo substitutes the current 0b… value, then tolist turns set bits into wires. The all-zero mask is a no-op X (no wires). Stepped form is start.step.end, so <0b0000000.0b100.0b1111111> walks 7-bit patterns in steps of 4.
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.
Slides and Videos From Circuit use that same combo. Change the combo bar first, then generate the deck or video, if you want a different binding.
sweepstate
If you assign a bitstring to the name sweepstate, Parametric Sweep fills its target pattern from that value until you edit the field. Qubit 0 is the least-significant bit (rightmost in 0b… writing). The pattern is padded on the left with zeros to the allocated register width, so 0 and 0b0 mean the all-zero ket, not “qubit 0 is 0 and the rest are free.”
Simulation, slides, and videos still start in |00…0⟩. Put X gates on the wires you want flipped if you need a different start state. Use sweepstate for the ket you are plotting (Grover marked state, for example).
bitstring sweepstate = 0b101 H (0,1,2) MEASURE (0,1,2)
Without sweepstate, the sweep tab defaults to the full-zero pattern. The name is ordinary (not reserved); only the bitstring type is special.
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.