qutone/lightstim/logical-coupler-design
Claude Code and agent skill by qutone/lightstim
- community
Checking that the SKILL.md file is still in the repository.
Design a new LogicalCouplerProtocol in LightStim to implement inter-patch joint measurements (lattice surgery). Use this skill when the user wants to: implement a new logical coupler for a code that doesn't have one yet, understand how the Unrotated Surface Code coupler works internally, design a coupler for a new code family (e.g. BB code logical measurement), or extend an existing coupler with a new boundary configuration. This skill is the key to replicating papers that describe custom "logi…
Install
npx vskill@latest install qutone/lightstim/logical-coupler-designSKILL.md
Logical Coupler Design
The core idea
A joint measurement between two logical patches (e.g. measuring ZZ = Z_L ⊗ Z_L) is implemented by temporarily activating a "coupler patch" whose stabilizers span the boundary between both patches. The coupler's joint stabilizers let the syndrome qubits at the boundary "see" data qubits from both patches simultaneously, effectively measuring the product of the two logical operators.
The coupler patch is a factory output — it contains only the corridor qubits and boundary-redefined stabilizers. It is registered inactive and activated/deactivated during circuit construction.
The LogicalCouplerProtocol interface
create_coupler_patch() (public, inherited) calls:
_validate_patch_count(patches)— checksEXPECTED_PATCH_COUNT- Constructs
LogicalCouplerPatch(name=name)— an empty container - Calls
_build_coupler_geometry(coupler_patch, patches, **params)— your code - Returns the filled
coupler_patch
Three things _build_coupler_geometry must do
1. Register corridor qubits
The role pattern must be consistent with both neighboring patches so SE blocks can be built using the same extraction logic (same _infer_role_from_anchor parity convention).
2. Register stabilizers (including redefined boundary ones)
Coupler stabilizers use coordinate keys in the pauli dict (not local integer keys), because corridor qubits don't have global indices yet when the coupler patch is built. QECSystem.add_patch() translates coords → global indices automatically.
Key: boundary stabilizers are redefined here — a boundary Z-stabilizer on the ctrl patch normally touches 2 data qubits. As a coupler stabilizer, it is replaced by a joint stabilizer touching 3+ qubits (2 from the ctrl patch + 1+ from the corridor).
3. Mark conflicting boundary stabilizers for pausing
When system.activate_coupler() is called, it finds all stabilizers in system.active_stabilizer_indices whose syn_coord is in conflicting_stabilizer_coords and removes them, replacing them with the coupler's redefined joint stabilizers.
How the Unrotated Surface Code coupler works (concrete example)
The UnrotatedTwoPatchCoupler implements ZZ or XX lattice surgery between two unrotated surface code patches.
Step 1: Geometry analysis (_analyze_geometry)
Determines logical operator orientation:
- ZZ interaction → logical Z runs horizontally → patches must be vertically stacked
(left edge of one patch at the same x as the left edge of the other)
- XX interaction → logical X runs vertically → patches must be horizontally stacked
Checks:
- Both patches have the same rotation/transposition
- One patch's extent along the non-gap axis contains the other's (the smaller
is the "anchor")
- Gap size in both dimensions is even (required for consistent parity tiling)
Returns: (logical_op_orientation, anchor_patch, gap_bounds) as a 4-tuple (x_min, x_max, y_min, y_max).
Step 2: Geometry construction (_construct_coupling_region)
Sweeps from the anchor patch toward the target patch, filling the gap column by column (or row by row for horizontal orientation). At each position, _infer_role_from_anchor determines whether the qubit should be data, syndrome_x, or syndrome_z based on parity distance from the anchor's reference qubits:
The last column/row adjacent to the target patch adapts its y-range (or x-range) to match the target patch's extent (handles asymmetric sizes).
Step 3: Stabilizer construction (_init_stabilizers)
Phase 1 — New corridor syndrome qubits: Each new syndrome qubit probes its 4 neighbors (up/down/left/right). If a neighbor is a data qubit (in the corridor or in either patch), it is added to the stabilizer support. This auto-detects the stabilizer weight: boundary ancillas near one patch get 3 neighbors, interior ancillas get 4.
Phase 2 — Existing boundary syndrome qubits: _find_boundary_syndrome_candidates scans existing syndrome qubits at the patch boundary (x or y coordinate equal to gap_min or gap_max). For each:
- Resolves the syndrome type from the patch it belongs to
- Calls
_probe_and_create_stabilizerto redefine the stabilizer with the
extended support (now including corridor data qubits)
- Adds to
conflicting_stabilizer_coords
The result: boundary syndrome qubits get a new stabilizer record that covers both patch data qubits AND corridor data qubits — this is the "joint" stabilizer that makes the measurement non-trivial.
Decision checklist for designing a new coupler
For any code pair:
- What logical observable are you measuring?
- ZZ → need Z-type joint stabilizers along the logical Z boundary of both patches
- XX → need X-type joint stabilizers along the logical X boundary
- Where do the logical operators live?
- In an unrotated SC: Z logical runs along a row of data qubits (horizontal strip)
- In a rotated SC: Z logical runs diagonally
- In a BB code: Z logical is a sparse operator (weight ~12) on a subset of data qubits
→ The coupler's joint stabilizers must be supported on the same qubits as the logical operator, so measuring them projects onto the logical ZZ eigenspace.
- What corridor geometry do you need?
- For patch codes (SC, CC): a strip of data + syndrome qubits bridging the gap
- For LDPC codes (BB, PQRM): there may be no geometric gap — the "coupler" defines
new syndrome qubits whose support overlaps both patches' logical operator support
- What boundary stabilizers need to be redefined?
- Any boundary syndrome qubit that previously measured only one patch's data qubits
must now also include corridor data qubits (and possibly target patch data qubits)
- Mark these with
conflicting_stabilizer_coords
- Parity consistency:
- Corridor qubit roles must follow the same parity convention as the anchor patch
- All new syndrome qubit coords must be at half-integer steps from data qubit coords
(for unrotated SC: data at integer coords, syndromes at integer+0.5)
Multi-patch coupler (UnrotatedMultiPatchCoupler)
For N-patch joint measurements (ZZZ, ZZZZ, ...):
Internally creates a single corridor connecting all N patches. Each side patch contributes boundary data qubits to the joint stabilizers running along the corridor.
Protocol lifecycle in circuit construction
Working examples
lightstim/qec_code/surface_code/unrotated/two_patch_coupler.py—UnrotatedTwoPatchCoupler: canonical two-patch ZZ/XX coupler implementationlightstim/qec_code/surface_code/unrotated/multi_patch_coupler.py—UnrotatedMultiPatchCoupler: N-patch bus coupler
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/logical-coupler-design/SKILL.md
Popularity
- Repository stars
- 50
- Repository forks
- 8
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/qutone/lightstim/logical-coupler-design)