uniqc.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.task.optional_deps import QUAFU_AVAILABLE
if QUAFU_AVAILABLE:
from uniqc.task.adapters.quafu_adapter import QuafuAdapter
# Require dependency with error message
from uniqc.task.optional_deps import require
quafu = require("quafu", "quafu") # Raises MissingDependencyError if not installed
- exception uniqc.task.optional_deps.MissingDependencyError(package, extra=None, install_hint=None)[source]#
Bases:
ImportErrorRaised when an optional dependency is not installed.
Provides a clear error message indicating which package is missing and, when available, how to install or rebuild the required support.
- uniqc.task.optional_deps.check_pyqpanda3()[source]#
Check if the pyqpanda3 package is available.
- Returns:
True if pyqpanda3 can be imported, False otherwise.
- Return type:
- uniqc.task.optional_deps.check_qiskit()[source]#
Check if the qiskit and qiskit_ibm_provider packages are available.
- Returns:
True if both packages can be imported, False otherwise.
- Return type:
- uniqc.task.optional_deps.check_quafu()[source]#
Check if the quafu package is available.
- Returns:
True if quafu can be imported, False otherwise.
- Return type:
- uniqc.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:
- uniqc.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
targetis not one of"cpp","qutip", or"all".- Return type:
- uniqc.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:
- uniqc.task.optional_deps.require(name, extra)[source]#
Import an optional module with a clear error message if missing.
- Parameters:
- Returns:
The imported module.
- Raises:
MissingDependencyError – If the module cannot be imported.
Example
>>> quafu = require("quafu", "quafu") >>> # If quafu is not installed: >>> # MissingDependencyError: Package 'quafu' is required...