uniqc.backend_adapter.task.optional_deps module

Optional dependency management with clear error messages.

This module provides utilities for handling optional dependencies across different quantum cloud platforms. When a dependency is not installed, users receive clear instructions on how to install it.

Usage:

# Check if dependency is available
from uniqc.backend_adapter.task.optional_deps import QUAFU_AVAILABLE
if QUAFU_AVAILABLE:
    from uniqc.backend_adapter.task.adapters.quafu_adapter import QuafuAdapter

# Require dependency with error message
from uniqc.backend_adapter.task.optional_deps import require
quafu = require("quafu", "quafu")  # Raises MissingDependencyError if not installed
uniqc.backend_adapter.task.optional_deps.check_pyqpanda3()[source]

Check if the pyqpanda3 package is available.

Returns:

True if pyqpanda3 can be imported, False otherwise.

Return type:

bool

uniqc.backend_adapter.task.optional_deps.check_qiskit()[source]

Check if the qiskit and qiskit_ibm_runtime packages are available.

Returns:

True if both packages can be imported, False otherwise.

Return type:

bool

uniqc.backend_adapter.task.optional_deps.check_quafu()[source]

Check if the quafu package is available.

Returns:

True if quafu can be imported, False otherwise.

Return type:

bool

uniqc.backend_adapter.task.optional_deps.check_quark()[source]

Check if the QuarkStudio package is available.

Returns:

True if from quark import Task succeeds, False otherwise.

Return type:

bool

uniqc.backend_adapter.task.optional_deps.check_quarkcircuit()[source]

Check if QuarkStudio’s circuit metadata module is available.

Return type:

bool

uniqc.backend_adapter.task.optional_deps.check_qutip()[source]

Check if the QuTiP-based simulation stack is available.

Returns:

True if qutip and qutip_qip can be imported, False otherwise.

Return type:

bool

uniqc.backend_adapter.task.optional_deps.check_simulation(target='cpp')[source]

Check simulation support for a specific backend family.

Parameters:

target (str) – Which simulation capability to check. - "cpp": built-in C++ simulator extension (default) - "qutip": QuTiP-based simulation stack - "all": both C++ simulator and QuTiP stack

Returns:

True if the requested simulation target is available, False otherwise.

Raises:

ValueError – If target is not one of "cpp", "qutip", or "all".

Return type:

bool

uniqc.backend_adapter.task.optional_deps.check_uniqc_cpp()[source]

Check if the uniqc_cpp C++ simulator extension is available.

Returns:

True if uniqc_cpp can be imported, False otherwise.

Return type:

bool

uniqc.backend_adapter.task.optional_deps.require(name, extra, install_hint=None)[source]

Import an optional module with a clear error message if missing.

Parameters:
  • name (str) – The module name to import (e.g., ‘quafu’, ‘qiskit’).

  • extra (str) – The pip extras name for installation (e.g., ‘qiskit’). Note: as of the current release, qiskit is a core dependency (no extra) and quafu no longer has an extra — see install_hint.

  • install_hint (str | None) – Optional explicit install / recovery hint that overrides the default unified-quantum[{extra}] message. Used for deprecated paths (e.g., quafu) where there is no extras name.

Returns:

The imported module.

Raises:

MissingDependencyError – If the module cannot be imported.