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.LabelManager
Bases:
objectSimple manager class for providing unique branch labels.
- new_label(start_with='')
- Parameters:
start_with (
str)- Return type:
str
- class netqasm.sdk.builder.SdkIfContext(id, builder, condition, op0, op1)
Bases:
objectContext object for if statements in SDK code such as with conn.if_eq().
- class netqasm.sdk.builder.SdkForEachContext(id, builder, array, return_index)
Bases:
objectContext object for foreach statements in SDK code such as with conn.foreach().
- class netqasm.sdk.builder.SdkLoopUntilContext(id, builder, max_iterations)
Bases:
objectContext object for loop_until() statements in SDK code.
- Parameters:
id (
int)builder (
Builder)max_iterations (
int)
- set_exit_condition(constraint)
Set the exit condition for this while loop.
- Parameters:
constraint (
SdkConstraint)- Return type:
None
- property exit_condition: SdkConstraint | None
Get the exit condition for this while loop.
- set_cleanup_code(cleanup_code)
Set the cleanup code for this while loop.
- Parameters:
cleanup_code (T_CleanupRoutine)
- Return type:
None
- property cleanup_code: T_CleanupRoutine | None
Get the cleanup code for this while loop.
- set_loop_register(register)
Set the register used that holds the iteration index for this while loop.
- Parameters:
register (
RegFuture)- Return type:
None
- property loop_register: RegFuture | None
Get the register used that holds the iteration index for this while loop.
- property max_iterations: int
Get the maximum number of iterations for this while loop.
- class netqasm.sdk.builder.Builder(connection, app_id, hardware_config=None, log_config=None, compiler=None, return_arrays=True)
Bases:
objectObject that transforms Python script code into `ProtoSubroutine`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 ProtoSubroutine. When the connectin flushes, the ProtoSubroutine is is compiled into a NetQASM subroutine.
- Parameters:
connection (
BaseNetQASMConnection)app_id (
int)hardware_config (
Optional[HardwareConfig])log_config (
Optional[LogConfig])compiler (
Optional[type[SubroutineTranspiler]])return_arrays (
bool)
- __init__(connection, app_id, hardware_config=None, log_config=None, compiler=None, return_arrays=True)
Builder constructor. Typically not used directly by the Host script.
- Parameters:
connection (
BaseNetQASMConnection) – Connection that this builder builds forapp_id (
int) – ID of the application as given by the quantum node controllermax_qubits – 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 objectcompiler (
Optional[type[SubroutineTranspiler]]) – which compiler class to use for the translation from ProtoSubroutine to Subroutinereturn_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.hardware_config (
Optional[HardwareConfig])
- property app_id: int
- inactivate_qubits()
- Return type:
None
- new_qubit_id()
- Return type:
int
- alloc_array(length=1, init_values=None)
- Parameters:
length (
int)init_values (
Optional[list[Optional[int]]])
- Return type:
- new_register(init_value=0, return_reg=True)
- Parameters:
init_value (
int)return_reg (
bool)
- Return type:
- subrt_add_pending_commands(commands)
- Parameters:
commands (
list[Union[ICmd,BranchLabel]])- Return type:
None
- subrt_add_pending_command(command)
- Parameters:
command (
Union[ICmd,BranchLabel])- Return type:
None
- subrt_pop_all_pending_commands()
- Return type:
list[Union[ICmd,BranchLabel]]
- subrt_pop_pending_subroutine()
- Return type:
Optional[ProtoSubroutine]
- subrt_compile_subroutine(pre_subroutine)
Convert a ProtoSubroutine into a Subroutine.
- Parameters:
pre_subroutine (
ProtoSubroutine)- Return type:
- property committed_subroutines: list[Subroutine]
- if_context_enter(context_id)
- Parameters:
context_id (
int)- Return type:
None
- if_context_exit(context_id, condition, op0, op1)
- Parameters:
context_id (
int)condition (
GenericInstr)
- Return type:
None
- sdk_epr_keep(role, params, reset_results_array=False)
Build commands for an EPR keep operation and return the result futures.
- sdk_epr_measure(role, params)
Build commands for an EPR measure operation and return the result futures.
- Parameters:
role (
EPRRole)params (
EntRequestParams)
- Return type:
list[EprMeasureResult]
- sdk_epr_rsp_create(params)
Build commands for a ‘create remote state preparation’ EPR operation and return the result futures.
- Parameters:
params (
EntRequestParams)- Return type:
list[EprMeasureResult]
- sdk_epr_rsp_recv(params)
Build commands for a ‘receive remote state preparation’ EPR operation and return the created qubits and result futures.
- Parameters:
params (
EntRequestParams)- Return type:
tuple[list[Qubit],list[EprKeepResult]]
- sdk_create_epr_keep(params)
Build commands for a ‘create and keep’ EPR operation and return the created qubits and result futures.
- Parameters:
params (
EntRequestParams)- Return type:
tuple[list[Qubit],list[EprKeepResult]]
- sdk_recv_epr_keep(params)
Build commands for a ‘receive and keep’ EPR operation and return the created qubits and result futures.
- Parameters:
params (
EntRequestParams)- Return type:
tuple[list[Qubit],list[EprKeepResult]]
- sdk_create_epr_measure(params)
Build commands for a ‘create and measure’ EPR operation and return the result futures.
- Parameters:
params (
EntRequestParams)- Return type:
list[EprMeasureResult]
- sdk_recv_epr_measure(params)
Build commands for a ‘receive and measure’ EPR operation and return the result futures.
- Parameters:
params (
EntRequestParams)- Return type:
list[EprMeasureResult]
- sdk_create_epr_rsp(params)
Build commands for a ‘create remote state preparation’ EPR operation and return the result futures.
- Parameters:
params (
EntRequestParams)- Return type:
list[EprMeasureResult]
- sdk_recv_epr_rsp(params)
Build commands for a ‘receive remote state preparation’ EPR operation and return the created qubits and result futures.
- Parameters:
params (
EntRequestParams)- Return type:
tuple[list[Qubit],list[EprKeepResult]]
- sdk_loop_context(stop, start=0, step=1, loop_register=None)
Build commands for a ‘loop’ context and return the context object.
- sdk_loop_body(body, stop, start=0, step=1, loop_register=None)
Build commands for looping the code in the specified body.
- Parameters:
body (T_LoopRoutine)
stop (int)
start (int)
step (int)
loop_register (operand.Register | str | None)
- Return type:
None
- sdk_if_eq(op0, op1, body)
An effective if-statement where body is a function executing the clause for a == b
- Parameters:
op0 (T_CValue)
op1 (T_CValue)
body (T_BranchRoutine)
- Return type:
None
- sdk_if_ne(op0, op1, body)
An effective if-statement where body is a function executing the clause for a != b
- Parameters:
op0 (T_CValue)
op1 (T_CValue)
body (T_BranchRoutine)
- Return type:
None
- sdk_if_lt(op0, op1, body)
An effective if-statement where body is a function executing the clause for a < b
- Parameters:
op0 (T_CValue)
op1 (T_CValue)
body (T_BranchRoutine)
- Return type:
None
- sdk_if_ge(op0, op1, body)
An effective if-statement where body is a function executing the clause for a >= b
- Parameters:
op0 (T_CValue)
op1 (T_CValue)
body (T_BranchRoutine)
- Return type:
None
- sdk_if_ez(op0, body)
An effective if-statement where body is a function executing the clause for a == 0
- Parameters:
op0 (T_CValue)
body (T_BranchRoutine)
- Return type:
None
- sdk_if_nz(op0, body)
An effective if-statement where body is a function executing the clause for a != 0
- Parameters:
op0 (T_CValue)
body (T_BranchRoutine)
- Return type:
None
- sdk_new_if_context(condition, op0, op1)
Build commands for an ‘if’ context and return the context object.
- Parameters:
condition (
GenericInstr)
- Return type:
- sdk_new_foreach_context(array, return_index)
Build commands for an ‘foreach’ context and return the context object.
- Parameters:
array (
Array)return_index (
bool)
- Return type:
- sdk_new_loop_until_context(max_iterations)
Build commands for a ‘loop_until’ context and return the context object.
- Parameters:
max_iterations (
int)- Return type:
Iterator[SdkLoopUntilContext]
- sdk_try_context(max_tries=1)
Build commands for a ‘try’ context.
- Parameters:
max_tries (
int)- Return type:
Iterator[None]
- sdk_create_epr_context(params)
Build commands for an EPR context and return an iterator over the EPR qubits and indices created in this context.
- Parameters:
params (
EntRequestParams)- Return type:
Iterator[tuple[FutureQubit,RegFuture]]