qbitbridge package

Submodules

qbitbridge.clusters module

qbitbridge.options module

options class for handling arguments of workflow. Not yet implemented

class qbitbridge.options.vQPUWorkflow(*args: Any, **kwargs: Any)[source]

Bases: BaseModel

Arguments to workflow

nqubits: int = 2

Number of qubits

quantum_kernels_file: str = ''

File containing quantum kernel(s) to run

qbitbridge.utils module

Collection of functions and tooling intended for general usage. The key functionality to explore here is the EventFile class.

class qbitbridge.utils.EventFile(name: str, loc: str, sampling: float = 0.01, id: str | None = None, etime: str | None = None, eset: int | None = None)[source]

Bases: object

Simple class to create a file for a given event.

clean() None[source]

Clean the file if present, unsetting the event

event_loc: str

directory where to store file event locks

event_name: str

The name of the event

event_set: int

Counter for number of times set

event_time: str

Time of event creation

fname: str

File name where event will be saved

classmethod from_dict(data: Dict)[source]

Create an object from a dictionary

identifer: str

unique identifer

sampling: float

how often to check for event file

set(meta_data: str | Dict | List | None = None) None[source]

Set the event by creating a file. If already set, read the file and return an exception. @todo Might want to add explicit lock to file when writing to it.

Raises:

RunTimeError saying event has already been set.

to_dict() Dict[source]

Converts class to dictionary for serialisation

async wait() None | str[source]

Wait till file indicating event set to exist and then return. Function should be called with await.

class qbitbridge.utils.SlurmInfo(hostname: str, resource: str | None = None, job_id: str | None = None, task_id: str | None = None, time: str | None = None)[source]

Bases: NamedTuple

Simple class to store slurm information

hostname: str

The hostname of the slurm job

job_id: str | None

The job ID of the slurm job

resource: str

The slurm resource request

task_id: str | None

The task ID of the slurm job

time: str | None

The time time the job information was gathered

async qbitbridge.utils.async_create_markdown_artifcat(key, markdown, description) None[source]

create a markdown artifact in a asynchronous fashion. Wrapper allows more complexity to be added.

qbitbridge.utils.check_python_installation(library: str)[source]

Check if library present and otherwise catch ImporError and report missing library

Args:

qbitbridge.utils.get_argparse_args(arguments: str, parser: ArgumentParser) Namespace[source]

Parse a string based on an argparser and also strip out _ from an argument

Parameters:
  • arguments (str) – string of arguments

  • parser (argparse.ArgumentParser) – parser that processes list of strings

Returns:

The argparser namespace

qbitbridge.utils.get_environment_variable(variable: str | None, default: str | None = None) str | None[source]

Get the value of an environment variable if it exists. If it does not a None is returned.

Parameters:
  • variable (Union[str,None]) – The variable to lookup. If it starts with $ it is removed. If None is provided None is returned.

  • default (Optional[str], optional) – If the variable lookup is not resolved this is returned. Defaults to None.

Returns:

Value of environment variable if it exists. None if it does not.

Return type:

Union[str,None]

async qbitbridge.utils.get_flow_runs(flow_run_filter: prefect.client.schemas.filters.FlowRunFilter, sort: str = '-start_time', limit: int = 100) List[prefect.client.schemas.objects.FlowRun][source]

Get list of flow runs that satisfy some filter

qbitbridge.utils.get_job_info(mode: str = 'slurm') SlurmInfo[source]

Get the job information for the supplied mode

Parameters:

mode (str, optional) – Which mode to poll information for. Defaults to “slurm”.

Raises:

ValueError – Raised if the mode is not supported

Returns:

The specified mode

Return type:

Union[SlurmInfo]

qbitbridge.utils.get_num_gpus() Tuple[int, str][source]

Poll node for number of gpus on host

Returns:

int number of gpus on a node and the type

qbitbridge.utils.get_slurm_info() SlurmInfo[source]

Collect key slurm attributes of a job

Returns:

Collection of slurm items from the job environment

Return type:

SlurmInfo

qbitbridge.utils.get_task_run_id() str[source]

Get the Task ID of the task calling this function. If there is no context, then the task_run_id is set to a descriptive, non-unique value

qbitbridge.utils.log_slurm_job_environment(logger) SlurmInfo[source]

Log components of the slurm environment.

Returns:

Collection of slurm items from the job environment

Return type:

SlurmInfo

qbitbridge.utils.measure_time(func)[source]

measure the time taken by a function

qbitbridge.utils.multinodenumberofgpus()[source]

Get the number of gpus per host

qbitbridge.utils.run_a_process(shell_cmd: list, add_output_to_log: bool = False, logger=None)[source]

Runs a process given by the shell command. If given a logger and asked to append, adds to the logger.

Returns:

new proccess spawned by the shell_cmd

Return type:

subprocess

qbitbridge.utils.run_a_process_bg(shell_cmd: list, add_output_to_log: bool = False, sleeplength: float = 5, logger=None) None[source]

Runs a process given by the shell command. If given a logger and asked to append, adds to the logger.

Returns:

new proccess spawned by the shell_cmd

Return type:

subprocess

qbitbridge.utils.run_a_srun_process(shell_cmd: list, srunargs: list = [], add_output_to_log: bool = False, logger=None) Popen[source]

runs a srun process given by the shell command. If given a logger and asked to append, adds to the logger.

Returns:

new proccess spawned by the shell_cmd

Return type:

subprocess.Popen

async qbitbridge.utils.save_artifact(data: Any, key: str = 'key', description: str = 'Data to be shared between subflows')[source]

Use this to save data between workflows and tasks. Best used for small artifacts

Parameters:
  • () (data) – data to be saved

  • key (str) – key for accessing the data

  • description (str) – description of the data

Returns :

a markdown artifact to transmit data between workflows

async qbitbridge.utils.upload_image_as_artifact(image_path: Path, key: str = '', description: str | None = None) None[source]

Create and submit a markdown artifact tracked by prefect for an input image. Currently supporting png formatted images.

The input image is converted to a base64 encoding, and embedded directly within the markdown string. Therefore, be mindful of the image size as this is tracked in the postgres database.

Parameters:
  • image_path (Path) – Path to the image to upload

  • key (str) – A key. Defaults to filename with lower_case.

  • description (Optional[str], optional) – A description passed to the markdown artifact. Defaults to None.

qbitbridge.utils.validate_keys(allowed_keys)[source]

Ensure dictionary data passed to a function only contains specific keys

qbitbridge.vqpubase module

qbitbridge.vqpuflow module

qbitbridge.vqpubraket module

qbitbridge.vqpuquera module