AttachedServer

class AttachedServer(num_workers=-1, port=7472, worker_port=7474)[source]

Bases: DetachedServer

BQSKit Runtime Server in attached mode.

In attached mode, the runtime is started by the client. The client owns the server and there is only one client on the server. Additionally, the client is responsible for shutting down the server. There are no managers in the attached architecture, only workers directly managed by a single server. This architecture is designed for single-machine shared-memory settings. BQSKit will, by default, create, manage, and shutdown an AttachedServer when a Compiler object is created.

__init__(num_workers=-1, port=7472, worker_port=7474)[source]

Create a server with num_workers workers.

Parameters:
  • num_workers (int) – The number of workers to spawn. If -1, then spawn as many workers as CPUs on the system. (Default: -1).

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

  • worker_port (int) – The port this server will listen for workers on. Default can be found in the default_worker_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)

A client disconnect in attached mode is equal to a shutdown.

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.