Skip to content

bloqade.qasm2.passes.parallel.UOpToParallel

← Module overview

classUOpToParallelsource

bloqade.qasm2.passes.parallel.UOpToParallel

Bases: Pass

Pass to convert single gates into parallel gates.

Signature
class UOpToParallel(merge_policy_type: Type[MergePolicyABC] = SimpleOptimalMergePolicy, rewrite_to_native_first: bool = False)

This pass looks for single gates from the qasm2.uop dialect that can be combined into parallel gates from the qasm2.parallel dialect and performs a rewrite to do so.

# Define kernel
@qasm2.main
def test():
q = qasm2.qreg(4)
theta = 0.1
phi = 0.2
lam = 0.3
qasm2.u(q[1], theta, phi, lam)
qasm2.u(q[3], theta, phi, lam)
qasm2.cx(q[1], q[3])
qasm2.u(q[2], theta, phi, lam)
qasm2.u(q[0], theta, phi, lam)
qasm2.cx(q[0], q[2])
# Run rewrite
UOpToParallel(main.dialects)(main)

The individual qasm2.u statements have now been combined into a single qasm2.parallel.u statement.

qasm2.parallel.u(qargs = [q[0], q[1], q[2], q[3]], theta, phi, lam)
qasm2.uop.CX(q[1], q[3])
qasm2.uop.CX(q[0], q[2])

Parameters

NameTypeDefaultDescription
merge_policy_typeType[MergePolicyABC]SimpleOptimalMergePolicy
rewrite_to_native_firstboolFalse

Attributes

NameTypeDefaultDescription
merge_policy_typeType[MergePolicyABC]SimpleOptimalMergePolicy
rewrite_to_native_firstboolFalse
constpropconst.Propagatefield(init=False)

methodunsafe_runsource

bloqade.qasm2.passes.parallel.UOpToParallel.unsafe_run

def unsafe_run(mt: ir.Method) -> abc.RewriteResult

Parameters

NameTypeDescription
mtir.Method

Returns

abc.RewriteResult

source