Calibrating conditional reset
Summary
This proposal extends Quil with the ability to define the behavior of RESET 0 to be a conditional RESET made up of existing measurements and gates. Conditional reset uses measurement as a building block, and so this proposal interacts with how measurement is specified in Quil; thus, this proposal as written builds on the "named measurements" proposal, although alternatives that don't are also presented.
Motivation
Quil provides a RESET instruction for resetting qubit state. However, the Quil-T pulse-level control extension doesn't provide any way to lower RESETs to analog control instructions, as it does for arbitrary gates and measurements; the details of RESET are left entirely opaque. This is understandable, as there are many different ways one might implement RESET, not all of which are expressible in Quil-T as it stands. However, as NISQ systems grow more capable, we'd like to begin having the ability to talk about RESET.
In particular, this proposal focuses on conditional RESET, which is almost but not quite expressible in plain Quil. Recall that conditionally resetting a qubit, in outline, is implemented by the following algorithm:
- Measure the qubit.
- If it was found to be in the 1 state, execute an
X gate on it.
- Repeat this process n times for some positive integer n.
This is almost equivalent to the following Quil program:
# An almost-implementation of `RESET q`
DECLARE reset_count INTEGER # Loop counter
DECLARE reset_ro BIT # Readout result
# Set up the "repeat n" loop
MOVE reset_count n
LABEL @reset_loop
# Reset q one time
MEASURE q reset_ro
JUMP-UNLESS @reset_done reset_ro
X q
LABEL @reset_done
# Loop
SUB reset_count 1
JUMP-WHEN @reset_loop reset_count
However, the problem with this program is that it occupies the whole quantum abstract machine; nothing can happen in parallel while the machine is jumping around. At both the abstract machine level and the pulse-control level, it is important that RESET 0 not require juggling the program counter of the full Quil program around. Thus, we need some way to specify the behavior of conditional reset at a lower level than plain Quil-T.
This focuses on conditional reset, but that's not the only way to reset a qubit. The change proposed here is deliberately designed to be forwards-compatible with future ways of calibrating RESET such as a pulse-based unconditional RESET; we want to provide the features we need currently without foreclosing further evolution.
Proposed change
Recall the outline of conditional reset provided above:
- Measure the qubit.
- If it was found to be in the 1 state, execute an
X gate on it.
- Repeat this process n times for some positive integer n.
Even if we assume that Quil's RESET is to be realized as as conditional RESET, each of these three steps must be lowered to the hardware separately:
- Which measurement calibration do we use?
- Which
X gate calibration do we use?
- How many times should we repeat this (i.e., what's n)?
Quil-T has existing facilities for specifying measurement and gate calibrations; all that remains is providing a way to link these calibrations to RESET and to specify the repeat count. We propose handling this by using a pragma to specify each of these three things for an individual RESET operation. For instance, to specify that RESET 0 should be implemented using MEASURE[midcircuit] for the measure, using RX(pi) for the X gate, and executing three iterations, we might write:
PRAGMA RESET 0 CONDITIONAL 3 "MEASURE[midcircuit]; RX(pi)"
The grammar for this pragma is as follows:
⟨Conditional Reset Pragma⟩ ::= PRAGMA RESET ⟨Formal qubit⟩ CONDITIONAL ⟨Integer⟩ "⟨Conditional Reset Calibrations⟩"
⟨Conditional Reset Calibrations⟩ ::= MEASURE ([ ⟨Identifier⟩ ])? ; ⟨Identifier⟩ (( ⟨Expression List⟩ ))?
The name of the pragma is RESET, and it is followed by the qubit whose behavior is being specified; if this is a formal qubit, it defines the behavior for every explicit single-qubit RESET that does not reset a qubit which has a concrete PRAGMA RESET. The qubit is then followed by the word CONDITIONAL to indicate that we are defining this RESET to be conditional reset; this allows PRAGMA RESET to be extended in the future to define other forms of reset. Finally, we provide the three parameters that define conditional reset: a positive integer specifying the number of iterations (it is an error for this to be zero or negative), and then, in quotes, the name of the measurement operation and the name of the X gate separated with a semicolon. (This presumes the "named measurements" proposal has been adopted; see the "Alternative designs" section for details on how we might approach this without that proposal in place.) The provided qubit to reset will then be measured with the provided measurement and flipped with the provided X gate; for instance, our above PRAGMA RESET would produce the following more precise outline of conditional reset.
-
Perform a MEASURE[midcircuit] 0 reset_ro for some reserved memory location reset_ro that is a BIT.
-
If reset_ro is 1, perform an RX(pi) 0
-
Repeat this process 3 times.
It is almost the case that this would be entirely sufficient to calibrate conditional reset without needing to modify the Quil specification, since it lives entirely in a PRAGMA, but it would still be worthwhile to include it in the specification. This is because a PRAGMA RESET, coupled with an actual RESET that matches it, causes the measurement and gate in that pragma to be used in the program. Existing tooling that, say, tries to remove unused DEFCALs might see a program containing the above PRAGMA RESET but no other references to MEASURE[midcircuit] 0 addr or RX(pi) 0 and attempt to remove the corresponding DEFCALs, causing the simplified program to be invalid. (This is not a hypothetical; Rigetti's initial implementation of active RESET ran into precisely this problem even without user-provided calibrations!) For more discussion on this, see the "Issues" section.
Unresolved questions
PRAGMA vs. a new DEFCAL vs. a new keyword
It is a little bit unusual to specify this calibration-like structure by using a PRAGMA, which usually corresponds to a form of interaction with the system running the program. One can argue this is the case for RESET, but it feels a lot like a calibration. We could thus alternatively specify the behavior of RESET by introducing a new form of DEFCAL, specifically DEFCAL RESET qubit AS CONDITIONAL, which allows us to specify the repeat count, measurement, and X gate in its body. For example, to replace the PRAGMA RESET 0 CONDITIONAL "MEASURE[midcircuit]; RX(pi)" from above, we could write
DEFCAL RESET 0 AS CONDITIONAL:
REPEAT 3
MEASURE[midcircuit]
RX(pi)
Unlike existing DEFCALs, this would not correspond to a simple replacement of RESET 0 with the body of the DEFCAL; RESET would remain an atomic operation even in a Quil-T program that has had all other calibrations expanded. Indeed, the body of DEFCAL RESET _ AS CONDITIONAL is not legal Quil: it contains the keyword RESET, an integer, and then the names of two operations.
This might feel too dissimilar from existing DEFCALs, so we could also introduce a new Quil-T operation just for RESET:
DEFRESET 0 AS CONDITIONAL:
REPEAT 3
MEASURE[midcircuit]
RX(pi)
This would have the same semantics as the above, but – like DEFFRAME – could not be removed from the program even after calibrations have been fully expanded. It would technically break existing programs that use a gate or variable named DEFRESET (and, depending on how we implement it, CONDITIONAL), but I don't expect this to be a problem in practice.
I am genuinely not sure which of the three options is the best. The advantage of PRAGMA RESET is that it almost doesn't require updating existing implementations that ignore unknown pragmas, and in fact barely needs to be included in the Quil-T specification at all. But perhaps we don't want to shoehorn every new feature into a PRAGMA?
Names vs. instructions
Should the user have to specify full measure and gate applications instead of just their names? Right now, we assume that measurement and X for conditional reset will always be operations that apply precisely to the qubit being reset, and so we provide a short form for the calibration. But we could be more explicit and future-proof things:
PRAGMA RESET 0 CONDITIONAL 3 "MEASURE[midcircuit] 0 _; RX(pi) 0"
DEFCAL RESET 0 AS CONDITIONAL:
REPEAT 3
MEASURE[midcircuit] 0 _
RX(pi) 0
DEFRESET 0 AS CONDITIONAL:
REPEAT 3
MEASURE[midcircuit] 0 _
RX(pi) 0
Ultimately I think this does not provide any extra clarity, and raises questions about what to put for the memory location that is to be measured into (left as an underscore above).
Alternative designs
If implemented as specified above, the design of this feature as requires the "named measurements" proposal, and if we use DEFCAL RESET or DEFRESET, it requires updating the Quil specification as well. But we can provide an implementation of this feature without named measurements, working solely with pragmas. There are two approaches here, both corresponding to alternative designs outlined in the "named measurements" proposal; for calibrating conditional RESET, they may be more useful, even if only as a stopgap measure until named measurements are adopted.
First, we could replace the MEASURE[midcircuit] part of the PRAGMA RESET with a gate name, and then use a PRAGMA to indicate that a DEFCAL for a gate is actually for a measurement. In this case, the pragma would provide the address parameter that would normally be part of a DEFCAL MEASURE. For our running example, that would look like
PRAGMA DEFCAL MEASURE midcircuit dest
DEFCAL midcircuit 0:
... dest ...
PRAGMA RESET 0 CONDITIONAL 3 "midcircuit; RX(pi)"
As outlined in the "named measurements" proposal, while this doesn't require any parsing extensions to Quil, tooling may still need to be aware of it; simplification of calibrations would try to remove this calibration for what looks like an "unused" gate named midcircuit, and tooling that attempted to check that DEFCAL bodies were well-formed would be caught off guard by the undefined dest. (See the "Issues" section for related discussion.)
More aggressively, we could simply inline the measurement calibration into the PRAGMA. In this case, I would propose using multiple pragmas, such as the following:
PRAGMA RESET 0 CONDITIONAL REPEAT 3
PRAGMA RESET 0 CONDITIONAL MEASURE "some; very; long; Quil-T; code"
PRAGMA RESET 0 CONDITIONAL X "some; other; very; long; Quil-T; code"
The primary virtue of this design is that it would require no updates to any tooling that wasn't thinking about RESET. The downside is that it's unergonomic to write and there's an additional constraint that we specify all three of these pragmas. Any feature can be defined to live in a PRAGMA in this way, but although it might be worthwhile here, there's a reason we don't generally do that.
Note also that I have expanded the calibration of the X, rather than writing PRAGMA RESET 0 CONDITIONAL X "RX(pi) 0". This is to make sure that the design here is entirely independent of existing tooling; in particular, it avoids the simplification issue described above, where a simplification pass could break programs by eliminating a seemingly-unused RX(pi) 0 calibration if RX(pi) 0 is only used in PRAGMA RESET CONDITIONAL X. (This is also discussed further in the "Issues" section.) Because the primary virtue of this design is that it is entirely compatible with existing tooling, avoiding this seems particularly beneficial.
Issues
I have not yet written the necessary text for §12.6 "Defining Calibrations" in Annex T. I am presently waiting until the design is specified precisely to write up the concrete text, but I expect it to borrow very heavily from this proposal document.
As discussed above, tooling may still need to be aware of this proposal even if it is implemented through PRAGMAs due to RESET making the measurement and gate mentioned in the PRAGMA RESET used. This raises the concern that a user might write a Quil program using PRAGMA RESET, pass it through existing tooling that is unaware of PRAGMA RESET, and silently get a buggy program back. If DEFCAL RESET or DEFRESET were used, this would not be an issue because the program would not be accepted by the unupdated tooling; if the three-PRAGMA implementation were used, then this would not be an issue because the behavior of RESET could be specified without reference to existing calibrations at all.
This change requires extending some existing implementations of Quil, including quil-rs and possibly also Quilc. This is not prohibitive, but is work that would need to be done. The PRAGMA-based designs attempt to avoid changes to Quilc, although due to the simplification issues mentioned above, it's not clear if they succeed. I would be happy to make the necessary changes to both the aforementioned projects.
Calibrating conditional reset
Summary
This proposal extends Quil with the ability to define the behavior of
RESET 0to be a conditionalRESETmade up of existing measurements and gates. Conditional reset uses measurement as a building block, and so this proposal interacts with how measurement is specified in Quil; thus, this proposal as written builds on the "named measurements" proposal, although alternatives that don't are also presented.Motivation
Quil provides a
RESETinstruction for resetting qubit state. However, the Quil-T pulse-level control extension doesn't provide any way to lowerRESETs to analog control instructions, as it does for arbitrary gates and measurements; the details ofRESETare left entirely opaque. This is understandable, as there are many different ways one might implementRESET, not all of which are expressible in Quil-T as it stands. However, as NISQ systems grow more capable, we'd like to begin having the ability to talk aboutRESET.In particular, this proposal focuses on conditional
RESET, which is almost but not quite expressible in plain Quil. Recall that conditionally resetting a qubit, in outline, is implemented by the following algorithm:Xgate on it.This is almost equivalent to the following Quil program:
However, the problem with this program is that it occupies the whole quantum abstract machine; nothing can happen in parallel while the machine is jumping around. At both the abstract machine level and the pulse-control level, it is important that
RESET 0not require juggling the program counter of the full Quil program around. Thus, we need some way to specify the behavior of conditional reset at a lower level than plain Quil-T.This focuses on conditional reset, but that's not the only way to reset a qubit. The change proposed here is deliberately designed to be forwards-compatible with future ways of calibrating
RESETsuch as a pulse-based unconditionalRESET; we want to provide the features we need currently without foreclosing further evolution.Proposed change
Recall the outline of conditional reset provided above:
Even if we assume that Quil's
RESETis to be realized as as conditionalRESET, each of these three steps must be lowered to the hardware separately:Xgate calibration do we use?Quil-T has existing facilities for specifying measurement and gate calibrations; all that remains is providing a way to link these calibrations to
RESETand to specify the repeat count. We propose handling this by using a pragma to specify each of these three things for an individualRESEToperation. For instance, to specify thatRESET 0should be implemented usingMEASURE[midcircuit]for the measure, usingRX(pi)for theXgate, and executing three iterations, we might write:The grammar for this pragma is as follows:
The name of the pragma is
RESET, and it is followed by the qubit whose behavior is being specified; if this is a formal qubit, it defines the behavior for every explicit single-qubitRESETthat does not reset a qubit which has a concretePRAGMA RESET. The qubit is then followed by the wordCONDITIONALto indicate that we are defining thisRESETto be conditional reset; this allowsPRAGMA RESETto be extended in the future to define other forms of reset. Finally, we provide the three parameters that define conditional reset: a positive integer specifying the number of iterations (it is an error for this to be zero or negative), and then, in quotes, the name of the measurement operation and the name of theXgate separated with a semicolon. (This presumes the "named measurements" proposal has been adopted; see the "Alternative designs" section for details on how we might approach this without that proposal in place.) The provided qubit to reset will then be measured with the provided measurement and flipped with the providedXgate; for instance, our abovePRAGMA RESETwould produce the following more precise outline of conditional reset.Perform a
MEASURE[midcircuit] 0 reset_rofor some reserved memory locationreset_rothat is aBIT.If
reset_rois1, perform anRX(pi) 0Repeat this process 3 times.
It is almost the case that this would be entirely sufficient to calibrate conditional reset without needing to modify the Quil specification, since it lives entirely in a
PRAGMA, but it would still be worthwhile to include it in the specification. This is because aPRAGMA RESET, coupled with an actualRESETthat matches it, causes the measurement and gate in that pragma to be used in the program. Existing tooling that, say, tries to remove unusedDEFCALs might see a program containing the abovePRAGMA RESETbut no other references toMEASURE[midcircuit] 0 addrorRX(pi) 0and attempt to remove the correspondingDEFCALs, causing the simplified program to be invalid. (This is not a hypothetical; Rigetti's initial implementation of activeRESETran into precisely this problem even without user-provided calibrations!) For more discussion on this, see the "Issues" section.Unresolved questions
PRAGMAvs. a newDEFCALvs. a new keywordIt is a little bit unusual to specify this calibration-like structure by using a
PRAGMA, which usually corresponds to a form of interaction with the system running the program. One can argue this is the case forRESET, but it feels a lot like a calibration. We could thus alternatively specify the behavior ofRESETby introducing a new form ofDEFCAL, specificallyDEFCAL RESET qubit AS CONDITIONAL, which allows us to specify the repeat count, measurement, andXgate in its body. For example, to replace thePRAGMA RESET 0 CONDITIONAL "MEASURE[midcircuit]; RX(pi)"from above, we could writeUnlike existing
DEFCALs, this would not correspond to a simple replacement ofRESET 0with the body of theDEFCAL;RESETwould remain an atomic operation even in a Quil-T program that has had all other calibrations expanded. Indeed, the body ofDEFCAL RESET _ AS CONDITIONALis not legal Quil: it contains the keywordRESET, an integer, and then the names of two operations.This might feel too dissimilar from existing
DEFCALs, so we could also introduce a new Quil-T operation just forRESET:This would have the same semantics as the above, but – like
DEFFRAME– could not be removed from the program even after calibrations have been fully expanded. It would technically break existing programs that use a gate or variable namedDEFRESET(and, depending on how we implement it,CONDITIONAL), but I don't expect this to be a problem in practice.I am genuinely not sure which of the three options is the best. The advantage of
PRAGMA RESETis that it almost doesn't require updating existing implementations that ignore unknown pragmas, and in fact barely needs to be included in the Quil-T specification at all. But perhaps we don't want to shoehorn every new feature into aPRAGMA?Names vs. instructions
Should the user have to specify full measure and gate applications instead of just their names? Right now, we assume that measurement and
Xfor conditional reset will always be operations that apply precisely to the qubit being reset, and so we provide a short form for the calibration. But we could be more explicit and future-proof things:Ultimately I think this does not provide any extra clarity, and raises questions about what to put for the memory location that is to be measured into (left as an underscore above).
Alternative designs
If implemented as specified above, the design of this feature as requires the "named measurements" proposal, and if we use
DEFCAL RESETorDEFRESET, it requires updating the Quil specification as well. But we can provide an implementation of this feature without named measurements, working solely with pragmas. There are two approaches here, both corresponding to alternative designs outlined in the "named measurements" proposal; for calibrating conditionalRESET, they may be more useful, even if only as a stopgap measure until named measurements are adopted.First, we could replace the
MEASURE[midcircuit]part of thePRAGMA RESETwith a gate name, and then use aPRAGMAto indicate that aDEFCALfor a gate is actually for a measurement. In this case, the pragma would provide the address parameter that would normally be part of aDEFCAL MEASURE. For our running example, that would look likeAs outlined in the "named measurements" proposal, while this doesn't require any parsing extensions to Quil, tooling may still need to be aware of it; simplification of calibrations would try to remove this calibration for what looks like an "unused" gate named
midcircuit, and tooling that attempted to check thatDEFCALbodies were well-formed would be caught off guard by the undefineddest. (See the "Issues" section for related discussion.)More aggressively, we could simply inline the measurement calibration into the
PRAGMA. In this case, I would propose using multiple pragmas, such as the following:The primary virtue of this design is that it would require no updates to any tooling that wasn't thinking about
RESET. The downside is that it's unergonomic to write and there's an additional constraint that we specify all three of these pragmas. Any feature can be defined to live in aPRAGMAin this way, but although it might be worthwhile here, there's a reason we don't generally do that.Note also that I have expanded the calibration of the
X, rather than writingPRAGMA RESET 0 CONDITIONAL X "RX(pi) 0". This is to make sure that the design here is entirely independent of existing tooling; in particular, it avoids the simplification issue described above, where a simplification pass could break programs by eliminating a seemingly-unusedRX(pi) 0calibration ifRX(pi) 0is only used inPRAGMA RESET CONDITIONAL X. (This is also discussed further in the "Issues" section.) Because the primary virtue of this design is that it is entirely compatible with existing tooling, avoiding this seems particularly beneficial.Issues
I have not yet written the necessary text for §12.6 "Defining Calibrations" in Annex T. I am presently waiting until the design is specified precisely to write up the concrete text, but I expect it to borrow very heavily from this proposal document.
As discussed above, tooling may still need to be aware of this proposal even if it is implemented through
PRAGMAs due toRESETmaking the measurement and gate mentioned in thePRAGMA RESETused. This raises the concern that a user might write a Quil program usingPRAGMA RESET, pass it through existing tooling that is unaware ofPRAGMA RESET, and silently get a buggy program back. IfDEFCAL RESETorDEFRESETwere used, this would not be an issue because the program would not be accepted by the unupdated tooling; if the three-PRAGMAimplementation were used, then this would not be an issue because the behavior ofRESETcould be specified without reference to existing calibrations at all.This change requires extending some existing implementations of Quil, including quil-rs and possibly also Quilc. This is not prohibitive, but is work that would need to be done. The
PRAGMA-based designs attempt to avoid changes to Quilc, although due to the simplification issues mentioned above, it's not clear if they succeed. I would be happy to make the necessary changes to both the aforementioned projects.