simulaqron.sdk package

Submodules

simulaqron.sdk.broadcast_channel module

class simulaqron.sdk.broadcast_channel.BroadcastChannel(app_name: str, remote_app_names: List[str], **kwargs)[source]

Bases: BroadcastChannelBySockets

Implement a Broadcast channel over sockets

Warning

This class is candidate to be deleted. Test and delete if possible!

BroadcastChannel constructor.

Parameters:
  • app_name – application/Host name of self

  • remote_app_names – list of receiving remote Hosts

simulaqron.sdk.connection module

class simulaqron.sdk.connection.GetQubitStateMessage(app_id: int = 0, qubit_id: int = 0)[source]

Bases: Message

Implements a specific NetQASM message to get the state of a qubit from the SimulaQron simulator.

Parameters:
  • app_id (int) – The app ID to get the qubit from.

  • qubit_id (int) – The qubit ID to retrieve the state.

TYPE = 202
app_id

Structure/Union member

qubit_id

Structure/Union member

class simulaqron.sdk.connection.NewMessageType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

GET_QUBIT_STATE = 202
INIT_NEW_APP = 0
OPEN_EPR_SOCKET = 1
SIGNAL = 4
STOP_APP = 3
SUBROUTINE = 2
class simulaqron.sdk.connection.NewReturnMessageType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

DONE = 0
ERR = 1
RET_ARR = 2
RET_QUBIT_STATE = 254
RET_REG = 3
class simulaqron.sdk.connection.ReturnQubitStateMessage(qubit_id: int, real_part: List[List[float]], imag_part: List[List[float]])[source]

Bases: ReturnMessage

Specific NetQASM message used to transmit the qubit state back to the application.

Parameters:
  • qubit_id (int) – The qubit ID.

  • real_part (List[List[float]]) – The real part of the qubit state.

  • imag_part (List[List[float]]) – The imaginary part of the qubit state.

TYPE = 254
dim

Structure/Union member

property dimension: int
get_imag_part() List[List[float]][source]
get_real_part() List[List[float]][source]
imag_part

Structure/Union member

qubit_id

Structure/Union member

real_part

Structure/Union member

class simulaqron.sdk.connection.RichErrorMessage(err_code: ErrorCode, err_msg: str, msg_id: int = 0)[source]

Bases: ReturnMessage

Enriched message to the Host that an error occurred at the quantum node controller.

Parameters:
  • err_code (ErrorCode) – The error code to report.

  • err_msg (str) – The error message.

  • msg_id (int) – The ID of the subroutine message that caused the error, so the client can unblock its _wait_for_done loop for that message.

TYPE = 1
err_code

Structure/Union member

err_msg

Structure/Union member

err_msg_len

Structure/Union member

get_err_msg() str[source]
msg_id

Structure/Union member

class simulaqron.sdk.connection.SimulaQronConnection(app_name: str, app_id: int | None = None, max_qubits: int = 5, log_config: LogConfig | None = None, epr_sockets: List[EPRSocket] | None = None, compiler: Type[SubroutineTranspiler] | None = None, socket_address=None, conn_retry_time: float = 0.1, network_name: str = 'default')[source]

Bases: BaseNetQASMConnection

Main class representing the connection from NetQASM to the SimulaQron simulator. This class implements the

Parameters:
  • app_name (str) – Name of the app to run.

  • app_id (int | None) – The ID of the application. If not given, a new one will be created.

  • max_qubits (int) – Maximum number of qubits tu simulate in the simulator.

  • log_config (LogConfig) – Configuration of the logging. Check the documentation of netqasm.sdk.config.LogConfig for more information about this.

  • epr_sockets (List[EPRSocket]) – List of EPRSocket s to use in the simulator.

  • compiler (Type[SubroutineTranspiler] | None) – A transpiler object that transpiles the NetQASM instructions.

  • socket_address (Tuple[str, int]) – A tuple containing a hostname and port to use to connect to the QNodeOS server.

  • conn_retry_time (float) – Maximum time in seconds to wait between attempts to connect to the QNoseOS server.

  • network_name (str) – The name of the network to connect to

NON_STABILIZER_INSTR = [<GenericInstr.T: 30>]
PROCESS_POOL: Pool | None = None
block()[source]

Blocks the handling of new messages until all the pending message IDs are acknowledged.

close(clear_app: bool = True, stop_backend: bool = False, exception: bool = False) None[source]

Closes the SimulaQron connection. It also sends the corresponding messages to the backend to clean up the states associated with the connection. This leaves the quantum backend ready to be used with a new client.

Parameters:
  • clear_app (bool) – Clear the application before closing the connection.

  • stop_backend (bool) – Stop the backend when closing the connection.

  • exception (bool) – Whether the app is stopping due to an exception or not.

get_qubit_state(app_id: int, qubit_id: int) List[complex][source]
static try_connection(name: str, socket_address: Tuple[str, int] | None = None, network_name: str = 'default')[source]

Try to establish a connection to the specified node name. The connection can be made by specifying the socket_address tuple (as a hostname and port number tuple) or by specifying the node and network names. In the latter case, SimulaQron will search for that node and network names on the loaded network configuration, and get the corresponding socket configuration (hostname and port number) to connect to.

Parameters:
  • name (str) – The name of the node to connect to.

  • socket_address (Tuple[str, int] | None) – A hostname-port pair to specify the hostname and port number to connect to. This argument is optional.

  • network_name (str) – The name of the network to search the node name.

class simulaqron.sdk.connection.SimulaQronNetworkInfo[source]

Bases: NetworkInfo

classmethod get_node_id_for_app(app_name: str) int[source]

Returns the node id for the app with the given name.

Parameters:

app_name (str) – The app name.

Returns:

The node ID.

Return type:

int

classmethod get_node_name_for_app(app_name: str) str[source]

Returns the node name for the app with the given name.

Parameters:

app_name (str) – The app name.

Returns:

The node name.

Return type:

str

simulaqron.sdk.socket module

class simulaqron.sdk.socket.Socket(app_name: str, remote_app_name: str, socket_id: int = 0, timeout: int | None = None, use_callbacks: bool = False, network_name: str = 'default', log_config=None, as_server: bool | None = None)[source]

Bases: Socket

Socket constructor.

Parameters:
  • app_name – application/Host name of this socket’s owner

  • remote_app_name – application/Host name of this socket’s remote

  • socket_id – local ID to use for this socket

  • timeout – maximum amount of real time to try to connect to the remote socket

  • use_callbacks – whether to call the recv_callback method upon receiving a message

  • log_config – logging configuration for this socket

MAX_RETRIES = 20
RETRY_TIME = 0.2
close()[source]

Closes this socket. Mo more messages can be sent or received after invoking this method.

recv(block: bool = True, timeout: float | None = None, maxsize: int | None = 1024) str[source]

Receive a message from the remote node.

Parameters:
  • block (bool) – Whether the underlying read operation should be blocking or not.

  • timeout (float | None) – Max time (in seconds) to wait for a message from the remote.

  • maxsize (int | None) – Maximum size of bytes to read from the remote.

Returns:

The received message as a string.

Return type:

str

recv_silent(block: bool = True, timeout: float | None = None, maxsize: int | None = None) str[source]

Receives a message without logging it. All arguments passed to this invocation are ignored. For more fine-grain control, please check the recv() method.

Parameters:
  • block (bool) – Ignored

  • timeout (float | None) – Ignored

  • maxsize (int | None) – Ignored

Returns:

The received message.

Return type:

str

recv_structured(block: bool = True, timeout: float | None = None, maxsize: int | None = 1024) StructuredMessage[source]

Receives a message from the remote node and parses it as a StructuredMessage.

Parameters:
  • block (bool) – Whether the underlying read operation should be blocking or not.

  • timeout (float | None) – Max time (in seconds) to wait for a message from the remote.

  • maxsize (int | None) – Maximum size of bytes to read from the remote.

Returns:

The parsed message.

Return type:

StructuredMessage

send(msg: str)[source]

Sends a message to the remote node.

Parameters:

msg (str) – The message to send.

send_silent(msg: str)[source]

Sends a message to the remote node without logging it.

Parameters:

msg (str) – The message to send.

send_structured(msg: StructuredMessage)[source]

Sends a message to the remote node as a StructuredMessage object.

Parameters:

msg (StructuredMessage) – The message to send.

Module contents