• No se han encontrado resultados

One of the more powerful techniques for reasoning about circuit behavior and opti- mizing those circuits is equational reasoning. Using a set of basic circuit identities, we could rewrite Qwire circuits, shrinking them and making them easier to run on a real-world quantum computer. One common identity (a unitary followed by its ad- joint is equal to the identity) is given in Section 7.3.1. Here, we present some other useful transformations, drawn from Staton’s (2015) equational theory for quantum computation.

Rather than negate a qubit and then measure it, we can always measure the qubit and then negate it. We can represent this as the equivalence of the following circuits:

meas

Definition X_meas := box q ⇒ meas $ X $ q.

meas

Definition meas_NOT := box q ⇒ BNOT $ meas $ q. BNOT here is simply the classical (bit-valued) NOT gate.

We can prove this by crunching matrices, but it also proves to be straightforward algebraically: The denotation of X is equal to the denotation of BNOT and commutes with measurement. Many of the equalities in this section will be similarly easy to prove via computation or matrix rewriting.

The equality of the following two circuits is obvious in the classical setting but less intuitive in the presence of entanglement, where measurement may disturb multiple qubits:

U meas

Definition U_meas_discard U := box q ⇒ discard $ meas $ U $ q.

meas

Definition meas_discard := box q ⇒ discard $ meas $ q.

This says that applying a unitary to a qubit and then measuring and discarding it is the same as simply measuring and then discarding the qubit. We prove the equality of these circuits computationally.

A number of additional equalities drawn from Staton’s theory are available in the file Equations.v in the Coq development.

Our rewriting system should also account for dynamic lifting and optimize around it when called for. The following dynamically lifted circuit with is equal to the identity circuit on one Bit:

Definition lift_new : Box Bit Bit := box b ⇒

lift x ← b; new x $ ().

Here, new x is new1 whenx is true and, otherwise, new0.

While we have a small library for rewriting circuits, an optimizing compiler is still a work-in-progress. Substantial work has gone into rewriting libraries for quantum circuits, most notably using the ZX-calculus (Coecke and Duncan, 2008; Backens, 2014) and the related Quantomatic tool (Kissinger, 2011). This tool faces two chal- lenges, in that ZX graphs are more expressive than quantum circuits, and its rewrite rules are not directed, making it hard to write a terminating procedure for shrink- ing circuits. A recent paper by Fagan and Duncan (2018) makes some headway on these issues, but we have yet to address the second in the Qwire setting. Fortu- nately, Qwire circuits correspond precisely to valid quantum circuits, so we don’t have to convert between representations; however, graphs may well be more amenable to rewriting than sequences of gate applications. This form of rewriting would be a significant step forward for automated circuit optimization and motivates the need for compositionality lemmas of the style proposed in Section 6.2).

Chapter 8

Reversibility

8.1

Ancillae and Assertions

Many quantum algorithms rely heavily on quantum oracles, classical programs ex- ecuted inside quantum circuits. Toffoli (1980) proved that any classical, boolean- valued functionf(x) can be implemented as a unitary circuit fu satisfying fu(x, z)=

(x, zf(x)). Toffoli’s construction for quantum oracles is used in many quantum algorithms, such as the modular arithmetic of Shor’s algorithm (1999). As a concrete example, Figure 8.1 shows quantum circuits that implement the boolean functions and () and or ().

Unfortunately, Toffoli’s construction introduces significant overhead. Consider a circuit meant to compute the boolean formula (ab)∧(cd). The circuit needs two additional scratch wires, or ancillae, to carry the outputs of(ab) and (cd), as seen in Figure 8.2. The annotation 0 at the start of a wire means that qubit is initialized in the state ∣0⟩. When constructed in this naive way, the resulting circuit no longer corresponds to a unitary transformation and cannot be safely used in a larger quantum circuit.

The solution is to uncompute the intermediate values ab and cd and then discard them at the end of the quantum circuit (Figure 8.3). The annotation 0 at the end of a wire is an assertion that the qubit at that point is in the zero state, at which point we can safely discard it without affecting the remainder of the state. (If we measured and discarded a non-zero qubit, we would affect whatever qubits it was

a a b b z z⊕(ab) a a b b z z⊕(ab)

Figure 8.1: Quantum oracles implementing the booleanand. Thegates represent negation, and represents control.

a a b b 0 ab c a d b 0 cd z z⊕((ab)∧(cd))

Figure 8.2: An non-unitary quantum oracle for (ab)∧(cd)

a a b b 0 0 c a d b 0 0 z z⊕((ab)∧(cd))

Figure 8.3: A unitary quantum oracle for (ab)∧(cd)with ancillae entangled with.)

How can we verify that such an assertion is actually true? We cannot dynamically check the assertion, since we can only access the value of a qubit by measuring it, thereby collapsing the qubit in question to a 0or 1state. However, we can statically reason that the qubit must be in the state∣0⟩ by analyzing the circuit semantics.

The claim that a qubit is in the0state is asemanticassertion about the behavior of the circuit. Unfortunately, this makes it hard to verify—computing the semantics of a quantum program is computationally intractable in the general case. Circuit programming languages often allow users to make such assertions but not to verify that they are true. For example, Quipper (Green et al., 2013a) allows programmers to make assertions about the state of ancillae, but these assertions are never checked. Likewise, in Q# (Svore et al., 2018) the assertion will be checked by a simulator but cannot be checked when a program is run on a quantum computer. Hence, when the qubit is reused, a common use for ancillae which Q# emphasizes, it may be in the wrong state. The QCL quantum circuit language (Ömer, 2005) provides a built-in method for creating reversible circuits from classical functions, but the programmer must trust this method to safely manage ancillae. In a step in the right direction, the ReVerC compiler (Amy et al., 2017) for the (non-quantum) reversible computing

language Revs (Parent et al., 2017) provides a similar approach to compilation and verifies that it correctly uncomputes its ancilla. However, other assertions in Revs that a wire is correctly in the 0 state are ignored if they cannot be automatically verified.

In this chapter, we develop verification techniques for safely working with ancillae. Our approach allows the programmer to discard qubits that are in the state 0⟩ or

∣1⟩, provided that she first formally proves that the qubits are in the specified state. Inspired by the ReVerC compiler (Amy et al., 2017), we also provide syntactic conditions that the programmer may satisfy to guarantee that her assertions are true. However, our quantum circuits do not need to match this syntactic specification: a programmer may instead manually prove that her circuit safely discards qubits using the denotational semantics of the language. This gives the programmer the flexibility to use ancillae where the proofs of such assertions are non-trivial.

This chapter makes the follow core contributions: • We extend Qwire with assertion-bearing ancillae.

• We give semantic conditions for the closely related properties of (a) when a circuit is reversible and (b) when a circuit contains only valid assertions about its ancillae.

• We provide syntactic conditions that guarantee the correctness of these asser- tions for common use-cases.

• We implement a compiler that transforms boolean expressions into reversible

Qwire circuits and prove its correctness.

• We show how this compilation can be used perform quantum arithmetic via a quantum adder.

We should note that the results of this chapter have not yet been fully verified in Coq. In particular, our section on syntactic guarantees for circuits (Section 8.3) describes a number of lemmas that have mostly been sketched out in Coq or proved based on admitted lemmas. Our section on oracles also admits the denotation of two functions that apply CNOT and Toffoli gates to wires based on their positions within the circuit (as in “wire number 7”) instead of referencing named patterns. More broadly, this chapter assumes the correctness of two important lemmas from Section 6.2: compose_correct and inPar_correct, which say that the denotation of circuits arranged in sequence and in parallel correspond to functional composition and the tensor product, respectively. The lemmas assumed in this chapter (excluding the lemmas of Section 8.3) are summarized in Table 8.1.

Assumption Description

denote_compose The composition of circuits is equal to the compo- sition of their denotations (Section 6.2)

inPar_correct Gives the denotation of circuits composed in parallel

valid_ancillae_box_equal Our two notations of assertion validity are equiva- lent

valid_ancillae_unbox Relates the validity of assertions on boxed and un- boxed circuits

[gate]_at_spec Describes the denotation of the [gate]_at[indices] circuit, which applies a gate to the given indices

ancilla_free_[gate]_at [gate]_at has no ancillae

ancilla_free_seq The composition of two ancilla free circuits has no ancillae

strip_one_l_out_eq Converting aBox W(One⊗ W')to aBox W W'preserves its denotation

strip_one_r_out_eq The same for Box W(W' One)

valid_ancillae_box'_equiv Denotationally equivalent circuits must have the same validity

valid_inSeq The composition of two valid circuits is valid

HOAS_Equiv_inSeq' Ifc1c1 and c2c2 then c1; ;c2c1; ;c2

Table 8.1: Assumptions underlying the reversible computing development. The first two are in Composition.v, the next two are in Ancilla.v, two instances of [gate]

_at_spec are in Oracles.v and the remaining assumptions are in Symmetric.v.

Documento similar