-
Notifications
You must be signed in to change notification settings - Fork 1
Description
I ran into this problem debugging the SquinToStimPass
in @david-pl 's ongoing PR #436 which uses all squin statements against relevant passes/analyses to ensure they're all accounted for.
I suppose this RFC is a combination of asking what the best way to resolve this is and pushing for something I thought of some time ago but feel wouldn't hurt to have now.
The Adjoint
statement in squin has a boolean attribute that determines if it's unitary. By default, it's set to False
. However, there has to be some logic to be able to set it to True
when the operator inside the adjoint is unitary. The motivating example for this is currently if I have something like:
op = adjoint(sqrt_x)
This will not get properly expressed as SQRT_X_DAG in the rewrite to Stim. The reason is because there is some guard logic I believe @kaihsin implemented where if the adjoint is not unitary, then the squin qubit dialect to stim rewrite immediately stops.
I can see the following solutions to the problem:
- Just make the guard a bit more relaxed and check if what's inside the adjoint is a SqrtX, SqrtY, or SqrtZ to allow things to go through
- Have a rewrite that looks at instances of such adjoints and fixes up the boolean to reflect the unitarity
This brings me to another idea that I don't think is too much work. This is more directly related to what @david-pl has in his test where he has adjoint(x)
(x being Pauli X). There's currently no adjoint canonicalization pass but I think it would quite trivial to have some rewrite that can see see such things and realize the adjoint can be removed altogether or a chain of adjoints can be collapsed.
Please feel free to let me know if I should take the simplest route here to make the SquinToStimPass happy or if it's worth killing two birds with one stone 🪨 🐦 🐦