Skip to content

Proposal: Multi-qubit measurements #92

@antalsz

Description

@antalsz

Multi-qubit measurements

Summary

This proposal extends Quil's MEASURE instruction to support measuring multiple qubits at once, as in MEASURE 0 ro[0], 1 ro[1], so that it can use a calibration optimized for measuring multiple qubits simultaneously. The proposal as written builds on the "named measurements" proposal, but this is inessential; it's done this way just in order to avoid rewriting text if the named measurements proposal is accepted. None of the semantic details depend on named measurements.

Motivation

Currently, Quil only supports measuring a single qubit at a time. However, quantum engineers can provide an optimized implementation of measurement for multiple qubits at once, so we want to provide a specific physical realization for e.g. MEASURE 0, 1 that would be distinct from the physical realization of MEASURE 0; MEASURE 1.

Proposed change

We propose generalizing the MEASURE instruction to take multiple qubits, allowing the user to write MEASURE 0 ro[0], 1 ro[1]. This would have the same semantics as MEASURE 0 ro[0]; MEASURE 1 ro[1] at the level of the quantum abstract machine, but could be realized via a more efficient calibration. The precise syntax we want for this is unsettled; see the "Unresolved questions" section for a discussion of the options.

Concretely, this involves changing §7 "Measurement" to update the definition of MEASURE and §12.6 "Defining Calibrations" in Annex T to update DEFCAL MEASURE correspondingly.

The precise updated specification text in this proposal assumes that the "named measurements" proposal has been adopted, but this is not essential; semantically speaking, the changes are independent of each other.

The necessary changes to §7 "Measurement" are as follows:

  • Changing ⟨Measurement for Effect⟩ and ⟨Measurement for Record⟩ nonterminals to support multiple arguments.

  • Updating the operational semantics of these instructions to refer correctly to multiple qubits.

  • Clarifying existing wording in the presence of these content changes.

The result is the following new text:

7. Measurement

[…]

Measurement-for-effect measures qubits and discards the results of those measurements.

Measurement for Effect⟩ ::= MEASURE ([Identifier])? ⟨Formal Qubit⟩ (,Formal Qubit⟩)*

This measurement will stochastically project each of the specified qubits into either […]

Measurement-for-record is the same as measurement-for-effect, but also returns the resulting states to the Quil program:

Measurement for Record⟩ ::= MEASURE ([Identifier])? ⟨Formal Qubit⟩ ⟨Memory Reference⟩ (,Formal Qubit⟩ ⟨Memory Reference⟩)*

Here, the memory references must all be either of type BIT or INTEGER. Regardless of their types, for each pair of a qubit and memory reference, a 0 is deposited at the given memory location if its corresponding qubit was measured to be in the zero-state, and a 1 is deposited there otherwise. […]

Note that there is no way in Quil to measure all qubits simultaneously; the set of qubits to be measured must be given explicitly.

The same changes must be reflected in the DEFCAL MEASURE calibration specified in Annex T. We need to make the following changes to §12.6 "Defining Calibrations":

  • Changing the ⟨Measurement Calibration⟩ nonterminal to match MEASURE instructions by supporting multiple arguments.

  • Adding text clarifying how measurement calibrations are matched to MEASUREs when there are multiple qubits involved.

The result is the following new text:

12.6. Defining Calibrations

[…]

Measure for Effect Calibration⟩ ::= DEFCAL MEASURE ([Identifier])? ⟨Formal Qubit⟩ (,Formal Qubit⟩)* : ⟨Instruction⟩+

Measure for Record Calibration⟩ ::= DEFCAL MEASURE ([Identifier])? ⟨Formal Qubit⟩ ⟨Identifier⟩ (,Formal Qubit⟩ ⟨Identifier⟩)* : ⟨Instruction⟩+

Measure Calibration⟩ ::= ⟨Measure for Effect Calibration⟩ | ⟨Measure for Record Calibration

[…] Similarly, calibrations for measurements can be defined by mapping a combination of (optional measurement name, list of qubits and optional identifiers) to a sequence of analog control instructions.

Multiple gate calibration definitions can be defined for different parameter and qubit values. […]

[…]

An analogous but simpler system applies for MEASURE. […] The behavior of matching on qubits is the same as for gate calibrations; the particular identifiers used for measurement-for-record, just like the particular identifiers used for formal qubits, never matter when matching.

It is important to note that measurement calibrations are sensitive to the order the qubits are specified in. While semantically, it does not matter which order measurement happens in, we require qubits to match in-order as is done for gates. To provide symmetry, a calibration may be provided that forwards to the correspond MEASURE with its qubits in the canonical order; for instance, we could defined

DEFCAL MEASURE 1 dest1, 0 dest0:
    MEASURE 0 dest0, 1 dest1

For example, given the following list of calibration definitions in this order:

[…]

  1. DEFCAL MEASURE 0 dest0, 1 dest1:

The instruction MEASURE 0 ro[0], 1 ro[1] would match (5), […], and both the instruction MEASURE[midcircuit] 1 and MEASURE 1 ro[1], 0 ro[0] would not match anything.

Examples:

[…]

# Multi-qubit measurement
DEFCAL MEASURE 0 dest0, 1 dest1:
    DECLARE iq0 REAL[2]
    DECLARE iq1 REAL[2]
    CAPTURE 0 "out0" flat(1e-6, 1+2i) iq0 # different waveform than either of the above
    CAPTURE 1 "out1" flat(1e-6, 3+4i) iq1
    LT dest0 iq0[0] 0.5 # thresholding
    LT dest1 iq1[0] 0.5 # thresholding

Unresolved questions

Syntax

The precise syntax specified above is not set in stone. The ideal syntax would probably be

MEASURE 0 1 ro[0] ro[1]

but unfortunately this suffers from a fatal ambiguity: as the qubits provided to MEASURE can be formal qubits, they would be ambiguous with bare memory identifiers, so that MEASURE x y could be understood as either (1) a 2-qubit measure-for-effect of formal qubits x and y, or (2) a 1-qubit measure-for-record of formal qubit x into the memory location y[0].

Consequently, we need to provide some more imaginative syntax, but we are further constrained by not breaking backwards compatibility. We could, for instance, imagine writing

MEASURE 0 1 -> ro[0] ro[1]

but this implies that we would need to write MEASURE 0 -> ro, which would break all old programs. We could work around this by coupling this multi-qubit–aware syntax with named measurements and introducing both at the same time, so that you could write

MEASURE 0
MEASURE 0 ro
MEASURE[midcircuit] 0
MEASURE[midcircuit] 0 -> ro
MEASURE[midcircuit] 0 1
MEASURE[midcircuit] 0 1 -> ro[0] ro[1]

but you could never write MEASURE 0 1. Then all existing Quil code would continue to work, as it would not be using named measurements; however, named measurements and bare measurements would be frustratingly asymmetric.

Thus, as far as I can see there are two options:

  • We require a sigil of some sort to denote multi-qubit measurement, and use a separator such as the arrow. For instance, to introduce a multi-qubit measurement, you could be required to include a leading colon:

    MEASURE: 0 1 -> ro[0] ro[1]
    MEASURE: 0 1
    # Degenerate case, but would work fine
    MEASURE: 0 -> ro
    MEASURE: 0
    # Old style
    MEASURE 0 ro
    MEASURE 0
    

    This would then leave the sigil-less form as old convenience syntax for the single-qubit case. This works but is a very aggressive change that leaves the resulting syntax looking irregular.

  • Some form of syntax that introduces a separator after the first qubit-and-optional-identifier, like the comma-separated one presented above. Commas certainly aren't the only options; there's also MEASURE 0 ro[0] & 1 ro[1] or any one of a number of different characters.

I'm open to suggestions here, or to somebody being clever about the syntax and coming up with something yet better.

Measuring every qubit

We could say that a bare MEASURE now measures every qubit, simply by replacing the final sentence of §7 with

A measure-for-effect with no qubits specified measures every qubit. Note that there is no way in Quil to measure-for-record all qubits simultaneously. (Where would you put the results?)

and updating the corresponding grammar productions. It is unclear precisely how to specify the corresponding DEFCAL MEASURE, but this could be resolved. I suspect there is no reason to make this change – and perhaps a reason it was originally forbidden – but it also would not be difficult to do.

Qubit ordering

As specified above, we require that MEASUREs match DEFCAL MEASUREs whose qubits are in the same order, and proposed specifying calibrations for MEASURE 1, 0 that simply forward to MEASURE 0, 1. While this works for the 2-qubit case, it gets much worse much faster for the n-qubit case; we don't want to have to specify all n! permutations. We could resolve this by saying that DEFCAL MEASUREs are unordered, and qubit matching is done on the set of provided qubits. This is odd in the presence of formal qubits, but works fine; if you have MEASURE 0, 1, 2, 3 and the two calibrations DEFCAL MEASURE 0, 1, x, y and DEFCAL MEASURE 2, 3, z, w, you simply pick the one specified last, as you do for gates. It's worth noting that it would be almost backwards-compatible to initially require precise ordering matching and then later relax this to unordered matching if this is a problem; it would simply require deleting the forwarding calibrations.

Repeated qubits

Nothing prevents the user from writing MEASURE 0 ro[0], 0 ro[1]. It's not clear that this is actually a problem. Presumably there either wouldn't be a corresponding calibration, or if there is it would be because it has a specific meaning. But we could also choose to forbid repeated qubits in a single MEASURE if we want. It does get more challenging to specify in the unordered-qubit case, but we could say that the order of the same qubits is preserved.

Measuring into a vector

The design proposed above requires specifying separate memory locations for every qubit in a measure-for-record. We could imagine instead specifying the behavior of multi-qubit measure to read into a vector, so that MEASURE 0, 1, 2 INTO ro would measure qubit 0 into ro[0], qubit 1 into ro[1], and qubit 2 into ro[2]. This is subject to the same questions of syntax as before, as well as questions of semantics: If ro is too long, does this just read into a prefix? Is there a way to read into ro starting at a different index (say, MEASURE 0, 1, 2 INTO ro FROM 3)? Should this coexist with the per-qubit memory locations described above as simply a (possibly more efficient) shorthand, or should it be the only way to perform measurement? It's also not clear if this is compatible with unordered measurement calibrations, as there are then two possible orders (the MEASURE order and the DEFCAL order).

Alternative designs

While we want to provide the ability to use these optimized multi-qubit measurement calibrations, we could avoid the need to provide a multi-qubit measurement instruction by specifying that consecutive measures with the same name are coalesced: if the user writes

MEASURE 0
MEASURE 1

then we first look for a DEFCAL MEASURE 0, 1 calibration before looking for two separate DEFCAL MEASURE 0 and DEFCAL MEASURE 1 calibrations. If the user wants to prevent this coalescing, they can insert a NOP between successive MEASUREs.

This design also works, but requires carefully specifying the calibration matching behavior. Suppose we have the instructions

MEASURE 0
MEASURE 1
MEASURE 2
MEASURE 3
MEASURE 4

in the presence of the following calibrations:

DEFCAL MEASURE 0: …
DEFCAL MEASURE 1: …
DEFCAL MEASURE 2: …
DEFCAL MEASURE 3: …
DEFCAL MEASURE 4: …

DEFCAL MEASURE 0, 1: …
DEFCAL MEASURE 2, 3, 4: …
DEFCAL MEASURE 3, 4: …

How should this be matched? There are a few possibilities:

  • Without a specific DEFCAL MEASURE 0, 1, 2, 3, 4, this should simply match the 5 individual DEFCAL MEASURE qs.

  • Greedily match the last possible calibration, so that we match DEFCAL MEASURE 3, 4, DEFCAL MEASURE 2, and DEFCAL MEASURE 0, 1.

  • Match the longest possible calibration, so that we match DEFCAL MEASURE 0, 1 and DEFCAL MEASURE 2, 3, 4.

Any of these is liable to become confusing, and requires Quil to do more analysis than it has had to previously. The simpler behavior of allowing the user to write multi-qubit MEASURE directly is probably preferable.

Issues

There are a number of unanswered questions, and we want to make sure we pick the right design: one that provides the people interacting with the hardware the power they need, that's easy to use for Quil programmers, and that's possible to implement for people writing Quil tooling. This will require careful thought and coordination with all of the aforementioned groups.

This change requires extending all implementations of Quil, including both quil-rs and Quilc. This is not prohibitive, but is work that would need to be done. I would be happy to make the necessary changes to both the aforementioned projects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions