DetachedServer

class DetachedServer(ipports, port=7472)[source]

Bases: ServerBase

BQSKit Runtime Server in detached mode.

In detached mode, the runtime is started separately from the client. Clients can connect and disconnect while not shutting down the server. This architecture is designed for the distributed setting, where managers manage workers in shared memory and communicate with the server over a network.

__init__(ipports, port=7472)[source]

Create a server and connect to the managers at ipports.

Parameters:
  • ipports (list[tuple[str, int]]) – The ip and port pairs were managers are expected to be listening for server connections.

  • port (int) – The port this server will listen for clients on. Default can be found in the default_server_port global variable.

Attributes

clients

Tracks all connected clients and all the tasks they have created.

tasks

Tracks all active CompilationTasks submitted to the cluster.

mailbox_to_task_dict

Used to convert internal RuntimeTasks to client CompilationTasks.

mailboxes

Mapping from mailbox ids to mailboxes.

mailbox_counter

Counter to ensure all mailboxes have unique IDs.

upper_id_bound

The node starts with an ID range from 0 -> 2^30.

running

True while the node is running.

sel

Used to efficiently idle and wake when communication is ready.

logger

Logger used to print operational log messages.

employees

Tracks this node's employees, which are managers or workers.

conn_to_employee_dict

Used to find the employee associated with a message.

Methods

assign_tasks(tasks)

Go through the tasks and assign each one to an employee.

broadcast_cancel(addr)

Broadcast a cancel message to my employees.

connect_to_manager(ip, port, lb, ub)

Connect to a manager at the endpoint given by ip and port.

connect_to_managers(ipports)

Connect to all managers given by endpoints in ipports.

connect_to_workers([num_workers, port])

Connect to worker processes.

get_employee_responsible_for(worker_id)

Return the employee that manages worker_id.

handle_cancel_comp_task(request)

Cancel a compilation task in the system.

handle_disconnect(conn)

Disconnect a client connection from the runtime.

handle_error(error_payload)

Forward an error to the appropriate client and disconnect it.

handle_log(log_payload)

Forward logs to appropriate client.

handle_message(msg, direction, conn, payload)

Process the message coming from direction.

handle_new_comp_task(conn, task)

Convert a CompilationTask into an internal one.

handle_request(conn, request)

Record the requested task, and ship it as soon as it's ready.

handle_result(result)

Either store the result here or ship it to the destination worker.

handle_shutdown()

Shutdown the runtime.

handle_status(conn, request)

Inform the client if the task is finished or not.

handle_system_error(error_str)

Handle an error in runtime code as opposed to client code.

handle_waiting(conn, new_idle_count)

Record that an employee is idle with nothing to do.

is_my_worker(worker_id)

Return true if worker_id is one of my workers (recursively).

listen_once(ip, port)

Listen on ip:port for a connection and return on first one.

run()

Main loop.

schedule_tasks(tasks)

Schedule tasks between this node's employees.

send_result_down(result)

Send the result to the appropriate employee.

spawn_workers([num_workers, port])

Spawn worker processes.