Description
Right now, if a user loads a cirq circuit that contains noise as a squin kernel and tries to simulate it, they receive an error such as
InterpreterError: no implementation for stmt squin.noise.depolarize(p=%0) : !py.Op from <class 'bloqade.pyqrack.base.PyQrackInterpreter'>
which is mostly useless for users. The actual issue is that there is no implementation for depolarize
since we need to run the RewriteNoiseStmts
pass before simulating. That pass rewrites all noise statements to the generic StochasticUnitaryChannel
statement, which has an implementation.
It would be nice to have that pass run automatically before simulation. At the same time, we may not want to update the given kernel in-place behind the scenes and we also don't want to run the pass multiple times, so I'm not exactly sure how to achieve this.
It might also be viable for now to just throw a more informative error message, but I'm also not sure how to do that since it's a generic error message.
Here's an MRE:
from bloqade import squin
from bloqade.pyqrack import StackMemorySimulator
from bloqade.squin.noise.rewrite import RewriteNoiseStmts
@squin.kernel
def main():
q = squin.qubit.new(1)
h = squin.op.h()
squin.qubit.apply(h, q)
depolar = squin.noise.depolarize(0.1)
squin.qubit.apply(depolar, q)
return q
sim = StackMemorySimulator(min_qubits=1)
# uncomment line below to make things work
# RewriteNoiseStmts(main.dialects)(main)
sim.run(main)