Skip to content

Squin identity sites should be an argument instead of an attribute #479

@david-pl

Description

@david-pl

When you want to "build up" an operator that acts on multiple qubits, you'll often find yourself in a situation where you'll have to write

$$ X_i = \mathbb{1} \otimes \mathbb{1} \otimes ... \otimes X \otimes \mathbb{1} ... $$

in order to "embed" a single qubit operator on a larger Hilbert space.

In squin, you'd do something like

x = squin.op.x()
id_lhs = squin.op.identity(sites=i)
id_rhs = squin.op.identity(sites=n - i - 1)
x_i = squin.op.kron(id_lhs, squin.op.kron(x, id_rhs))

Unfortunately, you can't use this approach unless n and i are actual constant values. That means you can neither define a short-hand embed(n: int, idx: int, op: Op) (which we'd probably want as part of stdlib) nor can you use the above in a for loop. Also, you can't define an operator for different n.

To solve this, we'll have to make sites an argument rather than an attribute. The obvious downside is that a couple of different analysis will have a more difficult implementation, since you won't always be able to infer the number of sites from the identity anymore.

Metadata

Metadata

Assignees

Labels

breakingbreaking changes or proposed changes that would break existing APIssquinsquin related issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions