netqasm.sdk.shared_memory

Abstractions for the classical memory shared between the Host and the quantum node controller.

class netqasm.sdk.shared_memory.RegisterGroup

Bases: object

A register group (like “R”, or “Q”) in shared memory.

netqasm.sdk.shared_memory.setup_registers()
Return type

Dict[RegisterName, RegisterGroup]

class netqasm.sdk.shared_memory.Arrays

Bases: object

has_array(address)
Parameters

address (int) –

Return type

bool

init_new_array(address, length)
Parameters
  • address (int) –

  • length (int) –

Return type

None

class netqasm.sdk.shared_memory.SharedMemory

Bases: object

Representation of the classical memory that is shared between the Host and the quantum node controller.

Each application is associated with a single SharedMemory. Although the name contains “shared”, it is typically only used in one “direction”: the quantum node controller writes to it, and the Host reads from it.

Shared memory consists of two types of memory: registers and arrays. The quantum node controller writes to the shared memory if it executes a “return” NetQASM instruction (ret_reg or ret_arr). This is typically done at the end of a subroutine. The Host can then read the values from the shared memory, which means that the Host effectively receives the returned values.

When trying to use a value represented by a Future, it will try to get the value from the shared memory. So, only after the quantum node controller has executed a subroutine containing the relevant ret_reg or ret_arr NetQASM instruction, the shared memory is updated and the value from the Future can be used.

The specific runtime context determines how a shared memory is implemented and by which component it is controlled. In the case of a physical setup, where the Host and the quantum node controller may be separate devices, “writing to the shared memory” may simply be “sending values from the quantum node controller to the Host”. On the other hand, a simulator that runs the Host and the quantum node controller in the same process might e.g. use a global shared object.

get_register(register)
Parameters

register (Union[str, Register]) –

Return type

Optional[int]

set_register(register, value)
Parameters
  • register (Union[str, Register]) –

  • value (int) –

Return type

None

get_array_part(address, index)
Parameters
  • address (int) –

  • index (Union[int, slice]) –

Return type

Union[None, int, List[Optional[int]]]

set_array_part(address, index, value)
Parameters
  • address (int) –

  • index (Union[int, slice]) –

  • value (Union[None, int, List[Optional[int]]]) –

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

  • length (int) –

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

Return type

None

class netqasm.sdk.shared_memory.SharedMemoryManager

Bases: object

Global object that manages shared memories. Typically used by simulators.

This class can be used as a global object that stores SharedMemory objects. Simulators that simulate Hosts and the quantum node controllers in the same process may use this to have a single location for creating and accessing shared memories.

classmethod create_shared_memory(node_name, key=None)
Parameters
  • node_name (str) –

  • key (Optional[int]) –

Return type

SharedMemory

classmethod get_shared_memory(node_name, key=None)
Parameters
  • node_name (str) –

  • key (Optional[int]) –

Return type

Optional[SharedMemory]

classmethod reset_memories()
Return type

None