Add syntactic sugar for squin.two_qubit_pauli_channel#764
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
david-pl
left a comment
There was a problem hiding this comment.
I'm not so sure about this change. It's a little weird because it lowers an ast.Dict, when kirin actually doesn't support it.
Something like this errors
@squin.kernel
def main():
q = squin.qalloc(2)
probs = {"XX": 0.1, "YY": 0.2, "ZZ": 0.15}
squin.two_qubit_pauli_channel(probs, q[0], q[1])with BuildError: Cannot lower Dict node: <ast.Dict object at 0x10ae5a4d0>
What's worse, however, is this silent footgun:
from bloqade import squin
probs = {"XX": 0.1, "YY": 0.2, "ZZ": 0.15}
@squin.kernel
def main():
q = squin.qalloc(2)
squin.two_qubit_pauli_channel(probs, q[0], q[1])This seemingly works fine, but inspecting the IR, you see that it silently inserts the actual dict object and uses this as argument
func.func @main() -> !py.NoneType {
^0(%main_self):
│ %0 = py.constant.constant 2 : !py.int
│ %q = func.invoke qalloc(%0) : !py.IList[!py.Qubit, !Any] maybe_pure=False
│ %1 = py.constant.constant {'XX': 0.1, 'YY': 0.2, 'ZZ': 0.15} : !Bottom
│ %2 = py.constant.constant 0 : !py.int
│ %3 = py.indexing.getitem(%q, %2) : !py.Qubit
│ %4 = py.ilist.new(values=(%3)){elem_type=!py.Qubit} : !py.IList[!py.Qubit, Literal(1,int)]
│ %5 = py.constant.constant 1 : !py.int
│ %6 = py.indexing.getitem(%q, %5) : !py.Qubit
│ %7 = py.ilist.new(values=(%6)){elem_type=!py.Qubit} : !py.IList[!py.Qubit, Literal(1,int)]
│ squin.noise.two_qubit_pauli_channel(probabilities=%1, controls=%4, targets=%7)
│ %8 = func.const.none() : !py.NoneType
│ func.return %8This will only fail later with spurious rewrite failures or an unhelpful error message.
| broadcast.two_qubit_pauli_channel( | ||
| probabilities, ilist.IList([control]), ilist.IList([target]) | ||
| ) | ||
| two_qubit_pauli_channel = noise.two_qubit_pauli_channel |
There was a problem hiding this comment.
Er, what's this? This just aliases the wrapper right? That shouldn't be the case.
There was a problem hiding this comment.
Oh, I see, you can't support this signature in a kernel, right? Hm, well but this makes two_qubit_pauli_channel subtly different from all other channels and gates. Not sure if that's so great...
Summary
Closes #341.
Adds syntax sugar for SQUIN two-qubit Pauli channels so users can pass Cirq-style
Pauli product probability dictionaries instead of manually constructing the full
15-entry probability list.
Omitted Pauli products default to
0.0.The existing 15-entry probability list form and broadcast-style control/target lists continue to work.
Changes
squin.noise.stmts.TwoQubitPauliChannel"XX","YY", and"ZZ"IList[Qubit, N]ILists during loweringILists for broadcast usePAULI_PRODUCT_ORDERand reuse it from Cirq lowering/emission and fidelity analysisIList[float, Literal[15]]Verification