-
Notifications
You must be signed in to change notification settings - Fork 1
Description
While working on the implementation in #185 I wrote some tests and ran into some things when using the squin dialect that I think need to be improved in order for squin to be more user friendly.
The things raised here are related to, but not covered by, #191 #192 #193
I'll add more as I go along.
1. Applying a gate to a single qubit
Right now, you can only apply gates to lists of qubits. That means, you can't simply write something like this:
@squin.kernel
def main():
q = squin.qubit.new(3)
x = squin.op.x()
squin.qubit.apply(x, q[1])Instead, you'd have to insert identities to all positions, but the index of the qubit register.
We could think about adding a method such as squin.qubit.apply(x, q, index=1) to solve this.
You can just write: squin.qubit.apply(x, [q[1]]). Since a qubit is essentially just an address to the simulation register, the state will be properly updated in-place still.
2. Controlled gates
Right now, a control gate is constructed via
cx = squin.op.control(x, n_controls=1, is_unitary=True)A couple of things here:
- It's not clear which qubits are used as controls as you just supply an integer here. My guess would be that they precede the target.
- Similar to the above: there's no simple way here to apply the
cxto two qubits within a larger register. You again need to insert identities. Theis_unitary=Truecould probably be inferred here.is_unitaryis inferred and shouldn't be part of the wrapper.- While having generic
controls is great, there should be short-hand definitions for the most common ones, such as CX/CY/CZ/CP. Right now, you'll need to define e.g.xoutside of this in order to pass it into thecontrol. - Should we really specify
n_controlshere as an integer? That could lead to weird cases where you have more qubits than controls + target. You kind of can infer the number of controls & the target from theapplyif you assume all qubits before the last one are controls. Alternatively, we could also allow specifying indexes for controls and the target here rather than just a single integer.