Compiler
- class Compiler(ip=None, port=7472, num_workers=-1, runtime_log_level=30, worker_port=7474, num_blas_threads=1)[source]
Bases:
objectA compiler is responsible for accepting and managing compilation tasks.
The compiler class either spins up a parallel runtime or connects to a distributed one, which compilation tasks can then access to parallelize their operations. The compiler is implemented as a context manager and it is recommended to use it as one. If the compiler is not used in a context manager, it is the responsibility of the user to call close().
Examples
1. Use in a context manager: >>> with Compiler() as compiler: … circuit = compiler.compile(circuit, workflow)
2. Use compiler without context manager: >>> compiler = Compiler() >>> circuit = compiler.compile(circuit, workflow) >>> compiler.close()
3. Connect to an already running distributed runtime: >>> with Compiler(‘localhost’) as compiler: … circuit = compiler.compile(circuit, workflow)
4. Start and attach to a runtime with 4 worker processes: >>> with Compiler(num_workers=4) as compiler: … circuit = compiler.compile(circuit, workflow)
- __init__(ip=None, port=7472, num_workers=-1, runtime_log_level=30, worker_port=7474, num_blas_threads=1)[source]
Construct a Compiler object.
This will either spawn a parallel runtime if ip is None, or attempt to connect to a distributed one if ip is provided.
- Parameters:
ip (
str|None) – If left as None, spawn a parallel runtime, otherwise attempt a connection with an already running runtime at this address. Defaults to None.port (
int) – The port where a runtime is expected to be listening.num_workers (
int) – The number of workers to spawn. Ignored if ip is None. If negative spawn as many workers as cpus on the system. (Defaults to -1)runtime_log_level (
int) – The runtime’s logging level. This is separate from the compilation logging. If you would like logs from your compilation workflow, that setting is set during task creation incompiler.compile()orcompiler.submit().worker_port (
int) – The optional port to pass to an attached runtime. SeeAttachedServerfor more info.num_blas_threads (
int) – The number of threads to use in the BLAS libraries on the worker nodes. (Defaults to 1)
Methods
cancel(task_id)Cancel the execution of a task in the system.
close()Shutdown the compiler.
compile(circuit, workflow[, request_data, ...])result(task_id)Block until the task is finished, return its result.
status(task_id)Retrieve the status of the specified task.
submit(circuit, workflow[, request_data, ...])Submit a compilation job to the Compiler.