Skip to content

bloqade.qasm2.emit.target.QASM2

← Module overview

classQASM2source

bloqade.qasm2.emit.target.QASM2

QASM2 target for Bloqade kernels.

Signature
class QASM2(qelib1: bool = True, allow_parallel: bool = False, allow_global: bool = False, custom_gate: bool = True, unroll_ifs: bool = True, allow_noise: bool = True)

QASM2 target that accepts a Bloqade kernel and produces an AST that you can then obtain a string for printing or saving as a file.

Parameters

NameTypeDefaultDescription
qelib1boolTrueInclude the `include "qelib1.inc"` line in the resulting QASM2 AST that's submitted to qBraid. Defaults to `True`.
allow_parallelboolFalseAllow parallel gate in the resulting QASM2 AST. Defaults to `False`. In the case its False, and the input kernel uses parallel gates, they will get rewrite into uop gates.
allow_globalboolFalseAllow global gate in the resulting QASM2 AST. Defaults to `False`. In the case its False, and the input kernel uses global gates, they will get rewrite into parallel gates. If both `allow_parallel` and `allow_global` are False, the input kernel will be rewritten to use uop gates.
custom_gateboolTrueInclude the custom gate definitions in the resulting QASM2 AST. Defaults to `True`. If `False`, all the qasm2.gate will be inlined.
unroll_ifsboolTrueUnrolls if statements with multiple qasm2 statements in the body in order to produce valid qasm2 output, which only allows a single operation in an if body. Defaults to `True`.
allow_noiseboolTrue

Attributes

NameTypeDefaultDescription
main_target—qasm2.main
gate_target—qasm2.gate
qelib1—qelib1
custom_gate—custom_gate
allow_parallel—allow_parallel
allow_global—allow_global
unroll_ifs—unroll_ifs

methodemitsource

bloqade.qasm2.emit.target.QASM2.emit

def emit(entry: ir.Method) -> ast.MainProgram

Emit a QASM2 AST from the Bloqade kernel.

Parameters

NameTypeDescription
entryir.MethodThe Bloqade kernel to convert to the QASM2 AST

Returns

ast.MainProgramA QASM2 AST object

source

methodemit_strsource

bloqade.qasm2.emit.target.QASM2.emit_str

def emit_str(entry: ir.Method) -> str

Emit a QASM2 AST from the Bloqade kernel.

Parameters

NameTypeDescription
entryir.MethodThe Bloqade kernel to convert to the QASM2 AST

Returns

strstr: A string with the QASM2 representation of the kernel

source