app.utils

Utils used throughout the whole application.

Module Contents

app.utils.opt_call(func: collections.abc.Callable[[TParam], TReturn], arg: TParam | None) TReturn | None

Optional chaining for function calls.

Parameters:
  • func (collections.abc.Callable[[TParam], TReturn]) – Function to call if arg is not None

  • arg (TParam | None) – Argument to pass to func

Returns:

Result of func or None

Return type:

TReturn | None

app.utils.not_none(value: not_none.T | None, error_msg: str) not_none.T

Returns value if not none or raises exception.

Parameters:
  • value (not_none.T | None) – Value to check.

  • error_msg (str) – Message to throw.

Returns:

The none-none value.

Return type:

not_none.T

app.utils.not_none_or(value: not_none_or.T | None, default_value: not_none_or.T) not_none_or.T

Nullish coalescence - ?? operator. Returns value if not None. Else, returns default_value.

Parameters:
  • value (not_none_or.T | None)

  • default_value (not_none_or.T)

Return type:

not_none_or.T

app.utils.duplicates(list: duplicates.list[duplicates.T]) set[duplicates.T]

Returns set of duplicate items.

Parameters:

list (duplicates.list[duplicates.T])

Return type:

set[duplicates.T]

class app.utils.StoredFilePayload

Represents a binary payload stored in the database.

app.utils.safe_generate_implementation_node(node_id: str, impl: openqasm3.ast.Program | str) app.model.CompileRequest.ImplementationNode

Generate an ImplementationNode without raising an error.

This is used when an error occurred to get the implementation during failure. :param node_id: the id used in the frontend :param impl: the implementation to use

Parameters:
Return type:

app.model.CompileRequest.ImplementationNode

async app.utils.add_status_response_to_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, status: app.model.StatusResponse.StatusResponse, compilation_target: str, *, name: str | None = None, description: str | None = None) None

Add the StatusResponse to the database

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine) – Database to insert the StatusResponse in

  • status (app.model.StatusResponse.StatusResponse) – The StatusResponse to add to the database

  • compilation_target (str) – Compilation target associated with this request

  • name (str | None) – Optional name originating from the request metadata

  • description (str | None) – Optional description originating from the request metadata

Return type:

None

async app.utils.update_status_response_in_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, new_state: app.model.StatusResponse.StatusResponse, compilation_target: str, *, name: str | None = None, description: str | None = None) None

Update the StatusResponse in the database by replacing the row.

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine) – Database engine to use.

  • new_state (app.model.StatusResponse.StatusResponse) – New status information to persist.

  • compilation_target (str) – Compilation target associated with this request.

  • name (str | None) – Optional updated name metadata.

  • description (str | None) – Optional updated description metadata.

Return type:

None

async app.utils.get_status_response_from_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID) app.model.StatusResponse.StatusResponse | None

Get the instance of StatusResponse with the given uuid from the database

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine) – Database engine to get the StatusResponse from

  • uuid (uuid.UUID) – UUID of the StatusResponse to retrieve

Returns:

The StatusResponse if found, otherwise None

Return type:

app.model.StatusResponse.StatusResponse | None

async app.utils.add_result_to_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID, results: str | list[app.model.CompileRequest.ImplementationNode], compilation_target: str) None

Add a result to the database for the given uuid

Parameters:
Return type:

None

async app.utils.get_results_overview_from_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, status: app.model.StatusResponse.StatusType | None = None) list[dict[str, object]]

Retrieve basic metadata for every stored request.

Parameters:
Return type:

list[dict[str, object]]

async app.utils.store_compile_request_payload(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID, payload: str) None

Persist the original compile request payload.

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine)

  • uuid (uuid.UUID)

  • payload (str)

Return type:

None

async app.utils.get_compile_request_payload(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID) str | None

Retrieve the original compile request payload if available.

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine)

  • uuid (uuid.UUID)

Return type:

str | None

async app.utils.store_qrms(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID, qrms: StoredFilePayload | None) None

Persist the Quantum Resource Models for the given request UUID.

Parameters:
Return type:

None

async app.utils.get_qrms(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID) StoredFilePayload | None

Retrieve stored Quantum Resource Models for the given request UUID.

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine)

  • uuid (uuid.UUID)

Return type:

StoredFilePayload | None

async app.utils.store_service_deployment_models(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID, service_models: StoredFilePayload | None) None

Persist the Service Deployment Models for the given request UUID.

Parameters:
Return type:

None

async app.utils.get_service_deployment_models(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID) StoredFilePayload | None

Retrieve stored Service Deployment Models for the given request UUID.

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine)

  • uuid (uuid.UUID)

Return type:

StoredFilePayload | None

async app.utils.list_service_deployment_ids(engine: sqlalchemy.ext.asyncio.AsyncEngine) list[uuid.UUID]

Return all UUIDs that have an associated service deployment payload.

Parameters:

engine (sqlalchemy.ext.asyncio.AsyncEngine)

Return type:

list[uuid.UUID]

async app.utils.list_qrm_ids(engine: sqlalchemy.ext.asyncio.AsyncEngine) list[uuid.UUID]

Return all UUIDs that have an associated QRM payload.

Parameters:

engine (sqlalchemy.ext.asyncio.AsyncEngine)

Return type:

list[uuid.UUID]