Open
Description
from bloqade import qasm2
from bloqade.qasm2.passes import UOpToParallel
@qasm2.extended
def main():
q = qasm2.qreg(n_qubits=4)
c = qasm2.creg(4)
qasm2.h(q[0])
qasm2.measure(q, c)
if c[0] == 0:
qasm2.x(q[0])
qasm2.x(q[1])
else:
qasm2.x(q[2])
qasm2.x(q[3])
return q
UOpToParallel(main.dialects,rewrite_to_native_first=True)(main)
main.print()
This ideally would parallelize the if-blocks but currently it does not:
func.func main() -> !py.IList[!py.Qubit, !Any] {
^0(%main_self):
│ %0 = py.constant.constant 4 : !py.int
│ %q = qasm2.core.qreg.new(n_qubits=%0) : !py.IList[!py.Qubit, !Any]
│ %c = qasm2.core.creg.new(n_bits=%0) : !py.CReg
│ %1 = py.constant.constant 0 : !py.int
│ %2 = qasm2.core.qreg.get(reg=%q, idx=%1) : !py.Qubit
│ %3 = py.constant.constant 1.5707963267949 : !py.float
│ %4 = py.constant.constant 0.0 : !py.float
│ %5 = py.constant.constant 3.14159265358979 : !py.float
│ qasm2.uop.U(qarg=%2, theta=%3, phi=%4, lam=%5)
│ qasm2.core.measure(qarg=%q, carg=%c)
│ %6 = qasm2.core.creg.get(reg=%c, idx=%1) : !py.Bit
│ %7 = py.cmp.eq(lhs=%6, rhs=%1) : !py.bool
│ scf.if %7 {
│ │ ^1(%14):
│ │ │ %8 = py.constant.constant 0 : !py.int
│ │ │ %9 = qasm2.core.qreg.get(reg=%q, idx=%8) : !py.Qubit
│ │ │ %10 = py.constant.constant 3.14159265358979 : !py.float
│ │ │ %11 = py.constant.constant 0.0 : !py.float
│ │ │ qasm2.uop.U(qarg=%9, theta=%10, phi=%11, lam=%10)
│ │ │ %12 = py.constant.constant 1 : !py.int
│ │ │ %13 = qasm2.core.qreg.get(reg=%q, idx=%12) : !py.Qubit
│ │ │ qasm2.uop.U(qarg=%13, theta=%10, phi=%11, lam=%10)
│ │ │ scf.yield
│ } else {
│ │ ^2(%21):
│ │ │ %15 = py.constant.constant 2 : !py.int
│ │ │ %16 = qasm2.core.qreg.get(reg=%q, idx=%15) : !py.Qubit
│ │ │ %17 = py.constant.constant 3.14159265358979 : !py.float
│ │ │ %18 = py.constant.constant 0.0 : !py.float
│ │ │ qasm2.uop.U(qarg=%16, theta=%17, phi=%18, lam=%17)
│ │ │ %19 = py.constant.constant 3 : !py.int
│ │ │ %20 = qasm2.core.qreg.get(reg=%q, idx=%19) : !py.Qubit
│ │ │ qasm2.uop.U(qarg=%20, theta=%17, phi=%18, lam=%17)
│ │ │ scf.yield
│ } -> purity=False
│ func.return %q
} // func.func main