qat.purr.integrations.qasm module

class AbstractParser

Bases: object

can_parse(qasm_str)
Return type:

ParseResults

parser_language()
Return type:

Languages

abstract walk_node(node, context, builder, **kwargs)
class BitRegister(bits=None)

Bases: object

class CloudQasmParser

Bases: RestrictedQasm2Parser

QASM parser used in our QCaaS system.

class CregIndexValue(register_name, index, value)

Bases: object

Used to reference when we’re looking at a particular index in a creg variable.

property variable
class LarkOpenPulseContext(registers=None, gates=None, variables=None, cali_methods=None)

Bases: QasmContext

class LarkPatchingParser(order_result_vars=False, raw_results=False)

Bases: Qasm2Parser

Parser built to route the lark limited QASM 3 requests into and through.

add_cnot(control_qbs, target_qbs, builder)
add_creg(reg_name, reg_length, context)
add_delay(delay, qubits, builder)
add_ecr(qubits, builder)
add_if(left, right, if_body, context, builder)
add_measure(qubits, bits, builder)
add_qreg(reg_name, reg_length, context, builder)
add_reset(qubits, builder)
add_unitary(theta, phi, _lambda, qubit_or_register, builder)
base_include_str = '\n    OPENQASM 2.0;\n    include "qelib1.inc";\n    '
load_default_gates(builder)

Loads the default QASM 2 gates for further processing.

class ParseResults(success, errors=None)

Bases: object

Results object for attempted parse. When coerced to a boolean matches against if parse was successful.

static failure(message)
static success()
class Qasm2Parser(order_result_vars=False, raw_results=False)

Bases: AbstractParser

can_parse(qasm)
Return type:

ParseResults

ecr_gate = <qiskit.qasm.node.gate.Gate object>
ecr_qasm_str = '\n    OPENQASM 2.0;\n    include "qelib1.inc";\n    gate ecr q0, q1 { }\n    '
modify(qasm)

Allows children to transform the program before validation/transforming into our AST occurs.

parse(builder, qasm)
parser_language()
Return type:

Languages

process_barrier(node, context, builder, **kwargs)
process_cnot(node, context, builder, **kwargs)
process_creg(node, context, builder, **kwargs)
process_gate(method, context, builder, **kwargs)

Process a gate call.

process_gate_definition(node, context, _, **kwargs)
process_if(node, context, builder, **kwargs)
process_intrinsic(method, context, builder)
process_measure(node, context, builder, **kwargs)
process_program(builder, qasm)
process_qreg(node, context, builder, **kwargs)
process_reset(node, context, builder, **kwargs)
process_unitary(node, context, builder, **kwargs)

Unitary in QASM terms is just U(...).

validate(qasm)
walk_node(node, context, builder, **kwargs)

Process each individual QASM node, builds context or forwards processing to relevant process_x method associated with each node type.

class Qasm3Parser

Bases: Interpreter, AbstractParser

assignment(tree)
bit_declaration_statement(tree)
cal_block(tree)
calibration_definition(tree)
calibration_grammar_declaration(tree)
can_parse(qasm_str)
Return type:

ParseResults

complex_declaration_statement(tree)
extern_frame(tree)
extern_or_subroutine_call(tree)
extern_port(tree)
frame_attribute_assignment(tree)
frame_definition(tree)
gate_definition(tree)
generate_expr_list_defcal_name(name, expr_list)
get_waveform_samples(wf)
initalize(builder)
lark_parser = Lark(open('<string>'), parser='earley', lexer='dynamic', ...)
parse(builder, qasm_str)
parser_language()
Return type:

Languages

quantum_barrier(tree)
quantum_declaration(tree)
quantum_gate_call(tree)
quantum_measurement(tree)

Throwaway measurement that doesn’t store results into any variable.

quantum_measurement_assignment_statement(tree)
quantum_reset(tree)
return_statement(tree)
timing_box(tree)
timing_instruction(tree)

This is actually a delay instruction.

transform_to_value(child_tree, walk_variable=True, return_variable=False)
version(tree)
walk_node(node, context, builder, **kwargs)
waveform_definition(tree)
class QasmContext(registers=None, gates=None, variables=None)

Bases: object

Container object for all data relating to the scope/pass of QASM currently under analysis.

class QasmMethodWrapper(qasm_method, qubit_args, classic_args)

Bases: CustomUnitary

Create the custom gate node.

class QubitRegister(qubits=None)

Bases: object

class Registers

Bases: object

class RestrictedQasm2Parser(allowed_gates=None, disable_if=False, *args, **kwargs)

Bases: Qasm2Parser

Parser which only allows certain gates to be passed.

validate(qasm)
class UntargetedPulse(pulse_class, *args, **kwargs)

Bases: object

Pulse that currently has no device to send it down.

build_with_target(channel)
property ref_instance
extern_port_name(physical_channel)
fetch_gate_node(qasm, gate_name)

Used to fetch particular nodes out of a minimalistic QASM program. Not used for execution, more for retrieving particular things for insertion into Qiskit’s QASM parser later on.

get_frame_mappings(model)

Generate the names for frames we allow in open pulse ‘extern’ statements. Returns a dictionary mapping name->pulse channel.

get_port_mappings(model)

Generate the names for ports we allow in open pulse ‘extern’ statements. Returns a dictionary mapping name->physical channel.

get_qasm_parser(qasm_str)

Gets the appropriate QASM parser for the passed-in QASM string.

qasm_from_file(file_path)

Get QASM from a file.