Support classically controlled gates in Stim#3417
Open
joao-boechat wants to merge 6 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support classically-controlled gates (
rectargets) in the Stim → QIR compilerWhat this is (in Stim)
Stim lets certain two-qubit controlled gates take a measurement record target
(
rec[-k]) in place of a qubit control. This turns the gate into aclassically-controlled (feed-forward) operation: if the recorded measurement
bit is set, apply the target Pauli to the target qubit.
A
recis only valid where the gate has a Z-basis control, which limits it to:recallowed onCX/CNOT/ZCXXon targetCY/ZCYYon targetCZ/ZCZZon the other qubitXCZXon the 1st qubitYCZYon the 1st qubitDocs: Stim gate reference
(see the
CX,CZ, andXCZentries).What changed
Previously these gates went through
broadcast_pair, which assumes both targetsare qubits and rejects a
recas an unsupported target. The changes:broadcast_controlled— a new dispatch for controlled gates. For each targetpair it either emits the fully-quantum decomposition (both qubits) or, when a
target is a
rec, emits a classically-controlled operation.classical_control— emits the feed-forward pattern (reusing the existingREQUIREmachinery): read the measurement result, branch, apply the gate'ssingle-qubit Pauli to the target, then rejoin.
AllowedRecPosition(First/Second/Either) — encodes which side of agate may carry a
rec, soCXaccepts it only on the control,XCZonly on thesecond target, and
CZon either.CX/CY/CZ/XCZ/YCZnow callbroadcast_controlled, eachsupplying its quantum decomposition and its single-qubit classical action.
"unsupported target":
MisplacedMeasurementRecord—recon a side the gate doesn't allow.NegatedMeasurementRecord— a negated control (!rec[-1]).MeasurementRecordWithoutQubit— both targets are records (no qubit to act on).qir/tests/measurement_record_targets.rscovers every gate and everyerror case.