quil-lang / quil

Specification of Quil: A Practical Quantum Instruction Set Architecture
https://quil-lang.github.io/
Apache License 2.0
105 stars 16 forks source link

Controlled Gate Modifier and global phases #55

Closed Spin1Half closed 7 months ago

Spin1Half commented 2 years ago

Global phase is a typically benign side effect that may vary between two functionally identical quantum gates. Two states A B (or unitaries/gates) are said to be "equivalent up to a global phase" if A = cB where c is a number of the form e^(i*theta) for any real theta. Furthermore, the bloch sphere representation for the state of a single qubit is invariant to global phase, as a consequence, representing single qubit gates as "rotations about the bloch sphere" are also invariant to global phase.

For example: The S gate is defined as a 90 degree rotation about the Z axis of the bloch sphere:

DEFGATE S:
    1, 0 
    0, i

The RZ gate can be defined by a pauli sum, but notice that the unitary for the RZ(pi/2) is only equivalent to the canonical S matrix up to a global phase (in this case, the phase is e^(i*pi/4) = (1 + i)/sqrt(2)):

Screen Shot 2022-04-12 at 4 04 38 PM

Quil defines the CONTROLLED gate modifier in the following manner:

Screen Shot 2022-04-12 at 4 07 34 PM

The key here is that a global phase mismatch for two unitaries (A, B) will result in a local phase mismatch if they are used in a "controlled" manner. More specifically CONTROLLED S and CONTROLLED RZ(pi/2) have observably different properties (are not equivalent up to a global phase) despite the fact that T and RZ(pi/2) do not have observably different properties (only a global phase mismatch).

There are some ideas floating around about how to deal with this, but there does not seem to be an obvious best solution.

Spin1Half commented 2 years ago

I will add that for back of the hand calculations, a typical way I mitigate global phase is to multiply a matrix by a unit-normalized complex conjugate of its first non zero term (starting at the top left, going left to right).

We could similarly employ this strategy whenever a CONTROLLED gate is created, but this would likely come without its own set of issues.

ecpeterson commented 2 years ago

I don’t feel that this is something to be fixed. The “controlled” construction doesn't descend to an operation from PU(2^n) to PU(2^(n+1)), and that situation just is what it is.

Or: you can’t ignore “global” phase if it isn’t actually global.

ecpeterson commented 2 years ago

QISKit deals with this by adding an explicit phase slot to their circuits, so that if a compiler replaces the G in CONTROLLED G with a H1 … Hn, it remembers to add the correct RZ when building CONTROLLED H1 … CONTROLLED Hn. I find this distasteful, but it is an option.

stylewarning commented 7 months ago

My resolution is to add this caveat to the spec with a nice colored box.