netqasm.sdk.builder

Conversion from Python code into an NetQASM subroutines.

This module contains the Builder class, which is used by a Connection to transform Python application script code into NetQASM subroutines.

class netqasm.sdk.builder.EntRequestParams(remote_node_id, epr_socket_id, number, post_routine, sequential, time_unit=<TimeUnit.MICRO_SECONDS: 0>, max_time=0, random_basis_local=None, random_basis_remote=None, rotations_local=(0, 0, 0), rotations_remote=(0, 0, 0))

Bases: object

Parameters
  • remote_node_id (int) –

  • epr_socket_id (int) –

  • number (int) –

  • post_routine (Optional[Callable[[ForwardRef, Union[FutureQubit, List[Future]], Register], None]]) –

  • sequential (bool) –

  • time_unit (TimeUnit) –

  • max_time (int) –

  • random_basis_local (Optional[RandomBasis]) –

  • random_basis_remote (Optional[RandomBasis]) –

  • rotations_local (Tuple[int, int, int]) –

  • rotations_remote (Tuple[int, int, int]) –

remote_node_id: int
epr_socket_id: int
number: int
post_routine: Optional[Callable[[Builder, Union[netqasm.sdk.qubit.FutureQubit, List[netqasm.sdk.futures.Future]], netqasm.lang.operand.Register], None]]
sequential: bool
time_unit: netqasm.qlink_compat.TimeUnit = 0
max_time: int = 0
random_basis_local: Optional[netqasm.qlink_compat.RandomBasis] = None
random_basis_remote: Optional[netqasm.qlink_compat.RandomBasis] = None
rotations_local: Tuple[int, int, int] = (0, 0, 0)
rotations_remote: Tuple[int, int, int] = (0, 0, 0)
class netqasm.sdk.builder.Builder(connection, app_id, max_qubits=5, log_config=None, compiler=None, return_arrays=True)

Bases: object

Object that transforms Python script code into `PreSubroutine`s.

A Connection uses a Builder to handle statements in application script code. The Builder converts the statements into pseudo-NetQASM instructions that are assembled into a PreSubroutine. When the connectin flushes, the PreSubroutine is is compiled into a NetQASM subroutine.

Parameters
  • app_id (int) –

  • max_qubits (int) –

  • log_config (Optional[LogConfig]) –

  • compiler (Optional[Type[SubroutineCompiler]]) –

  • return_arrays (bool) –

ENT_INFO = {<EPRType.K: 0>: <class 'netqasm.qlink_compat.LinkLayerOKTypeK'>, <EPRType.M: 1>: <class 'netqasm.qlink_compat.LinkLayerOKTypeM'>, <EPRType.R: 2>: <class 'netqasm.qlink_compat.LinkLayerOKTypeR'>}
__init__(connection, app_id, max_qubits=5, log_config=None, compiler=None, return_arrays=True)

Builder constructor. Typically not used directly by the Host script.

Parameters
  • connection – Connection that this builder builds for

  • app_id (int) – ID of the application as given by the quantum node controller

  • max_qubits (int) – maximum number of qubits allowed (as registered with the quantum node controller)

  • log_config (Optional[LogConfig]) – logging configuration, typically just passed as-is by the connection object

  • compiler (Optional[Type[SubroutineCompiler]]) – which compiler class to use for the translation from PreSubroutine to Subroutine

  • return_arrays (bool) – whether to add ret_arr NetQASM instructions at the end of each subroutine (for all arrays that are used in the subroutine). May be set to False if the quantum node controller does not support returning arrays.

property app_id
Return type

int

inactivate_qubits()
Return type

None

new_qubit_id()
Return type

int

new_array(length=1, init_values=None)
Parameters
  • length (int) –

  • init_values (Optional[List[Optional[int]]]) –

Return type

Array

new_register(init_value=0)
Parameters

init_value (int) –

Return type

RegFuture

add_pending_commands(commands)
Parameters

commands (List[Union[ICmd, BranchLabel]]) –

Return type

None

add_pending_command(command)
Parameters

command (Union[ICmd, BranchLabel]) –

Return type

None

property committed_subroutines
Return type

List[Subroutine]

add_single_qubit_rotation_commands(instruction, virtual_qubit_id, n=0, d=0, angle=None)
Parameters
  • instruction (GenericInstr) –

  • virtual_qubit_id (int) –

  • n (int) –

  • d (int) –

  • angle (Optional[float]) –

Return type

None

add_single_qubit_commands(instr, qubit_id)
Parameters
Return type

None

add_two_qubit_commands(instr, control_qubit_id, target_qubit_id)
Parameters
  • instr (GenericInstr) –

  • control_qubit_id (int) –

  • target_qubit_id (int) –

Return type

None

add_measure_commands(qubit_id, future, inplace)
Parameters
  • qubit_id (int) –

  • future (Union[Future, RegFuture]) –

  • inplace (bool) –

Return type

None

add_new_qubit_commands(qubit_id)
Parameters

qubit_id (int) –

Return type

None

add_init_qubit_commands(qubit_id)
Parameters

qubit_id (int) –

Return type

None

add_qfree_commands(qubit_id)
Parameters

qubit_id (int) –

Return type

None

create_epr(tp, params)

Receives EPR pair with a remote node

Parameters
Return type

Union[List[Qubit], List[LinkLayerOKTypeK], List[LinkLayerOKTypeM], List[LinkLayerOKTypeR]]

recv_epr(tp, params)

Receives EPR pair with a remote node

Parameters
Return type

Union[List[Qubit], List[LinkLayerOKTypeK], List[LinkLayerOKTypeM], List[LinkLayerOKTypeR]]

if_eq(a, b, body)

An effective if-statement where body is a function executing the clause for a == b

Parameters
  • a (Union[int, ForwardRef, ForwardRef]) –

  • b (Union[int, ForwardRef, ForwardRef]) –

  • body (Callable[[ForwardRef], None]) –

Return type

None

if_ne(a, b, body)

An effective if-statement where body is a function executing the clause for a != b

Parameters
  • a (Union[int, ForwardRef, ForwardRef]) –

  • b (Union[int, ForwardRef, ForwardRef]) –

  • body (Callable[[ForwardRef], None]) –

Return type

None

if_lt(a, b, body)

An effective if-statement where body is a function executing the clause for a < b

Parameters
  • a (Union[int, ForwardRef, ForwardRef]) –

  • b (Union[int, ForwardRef, ForwardRef]) –

  • body (Callable[[ForwardRef], None]) –

Return type

None

if_ge(a, b, body)

An effective if-statement where body is a function executing the clause for a >= b

Parameters
  • a (Union[int, ForwardRef, ForwardRef]) –

  • b (Union[int, ForwardRef, ForwardRef]) –

  • body (Callable[[ForwardRef], None]) –

Return type

None

if_ez(a, body)

An effective if-statement where body is a function executing the clause for a == 0

Parameters
  • a (Union[int, ForwardRef, ForwardRef]) –

  • body (Callable[[ForwardRef], None]) –

Return type

None

if_nz(a, body)

An effective if-statement where body is a function executing the clause for a != 0

Parameters
  • a (Union[int, ForwardRef, ForwardRef]) –

  • body (Callable[[ForwardRef], None]) –

Return type

None

loop(stop, start=0, step=1, loop_register=None)
Parameters
  • stop (int) –

  • start (int) –

  • step (int) –

  • loop_register (Optional[Register]) –

Return type

Iterator[Register]

loop_body(body, stop, start=0, step=1, loop_register=None)

An effective loop-statement where body is a function executed, a number of times specified by start, stop and step.

Parameters
  • body (Callable[[ForwardRef], None]) –

  • stop (int) –

  • start (int) –

  • step (int) –

  • loop_register (Optional[Register]) –

Return type

None

insert_breakpoint(action, role=<BreakpointRole.CREATE: 0>)
Parameters
Return type

None