netqasm.sdk.compiling

Transpilation of subroutines from one flavour to another.

This module contains the SubroutineCompiler interface which is a base class for transpilers that can convert a NetQASM subroutine into a subroutine with a specific flavour.

class netqasm.sdk.compiling.SubroutineCompiler(subroutine, debug=False)

Bases: abc.ABC

Parameters
abstract compile()

Compile the subroutine into one with a specific flavour.

Return type

Subroutine

class netqasm.sdk.compiling.NVSubroutineCompiler(subroutine, debug=False)

Bases: netqasm.sdk.compiling.SubroutineCompiler

A transpiler that converts a subroutine with the vanilla flavour to a subroutine with the NV flavour.

Parameters

subroutine (Subroutine) –

get_reg_value(reg)

Get the value of a register at this moment

Parameters

reg (Register) –

Return type

Immediate

get_unused_register()

Naive approach: try to use Q0 if possible, otherwise Q1, etc.

Return type

Register

swap(lineno, electron, carbon)

Swap the states of the electron and a carbon. See https://gitlab.tudelft.nl/qinc-wehner/netqasm/netqasm-docs/-/blob/master/nv-gates-docs.md for the circuit.

Parameters
Return type

List[NetQASMInstruction]

compile()

Very simple compiling pass: iterate over all instructions once and rewrite them in-line. While iterating, keep track of which registers are in use and what their values are.

Return type

Subroutine

netqasm.sdk.compiling.get_hardware_num_denom(instr)
Parameters

instr (RotationInstruction) –

Return type

Tuple[Immediate, Immediate]