quil-rs icon indicating copy to clipboard operation
quil-rs copied to clipboard

GateError: unknown gate `XY` to turn into parameterized matrix

Open bramathon opened this issue 4 months ago • 2 comments

Quil 0.16.0

Reproduce

import numpy as np
from quil.instructions import Gate, Qubit
from quil.expression import Expression

gate = Gate(name="XY", parameters=[Expression.from_number(complex(np.pi/3))], qubits=[Qubit.from_fixed(0), Qubit.from_fixed(1)], modifiers=[])
gate.to_unitary_mut(2)

bramathon avatar Aug 25 '25 19:08 bramathon

Thanks for reporting this. Indeed, we don't currently have an implementation for the $\mathbf{XY}$, even though it is a Standard Gate within the Quil Specification.

I wanted to confirm the definition, which lead me down a bit of a rabbit hole. The definition shown in the spec matches the one described by PyQuil:

\mathbf{XY}\left(\theta\right) = \exp\left(-i \theta \left(\mathbf{X}^{\otimes 2} + \mathbf{Y}^{\otimes 2}\right) \right)
=
\begin{bmatrix}
1 & 0 & 0 & 0\\
0 & \cos\left(\frac{\theta}{2}\right) & i\sin\left(\frac{\theta}{2}\right)  & 0\\
0 & i\sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right)  & 0\\
0 & 0 & 0 & 1
\end{bmatrix}

And that's the definition in quilc, but there, @ecpeterson noted:

there has been some internal debate about whether this gate should be parameterized by -1.0*%theta instead. we seem to have picked this one for good, but it's still not 100% clear to me that this is the "right" move.

There was some discussion about it many years ago, and the conclusion was to use the definition shown above. That discussion also describes the alias $\mathbf{PISWAP\left(\theta\right)}$, another standard gate we currently are missing. Since we intend to support the standard gates in the spec, when we add $\mathbf{XY}$, we should also add $\mathbf{PISWAP}$ and finally $\mathbf{CAN}\left( \alpha, \beta, \gamma \right)$ to round out the set.

Let me know if that all sounds good to you.

asaites avatar Aug 27 '25 01:08 asaites

Yes this definition is a bit unconventional but it's ultimate arbitrary and we don't want to change it.

Image

bramathon avatar Aug 27 '25 06:08 bramathon