Skip to content

squin usability improvements #203

@david-pl

Description

@david-pl

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 cx to two qubits within a larger register. You again need to insert identities.
  • The is_unitary=True could probably be inferred here. is_unitary is 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. x outside of this in order to pass it into the control.
  • Should we really specify n_controls here 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 the apply if 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.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsquinsquin related issuestriagerequest for triage. A decision will be made on the issue or PR.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions