uniqc.backend module#
Unified backend management for quantum computing platforms.
This module provides a centralized Backend management system with: - Abstract base class QuantumBackend defining a unified interface - Factory pattern for backend instance creation/retrieval - Caching mechanism for backend instances - Integration with existing adapters (OriginQ, Quafu, IBM)
Usage:
# Get or create a backend instance
backend = get_backend('originq')
# List all available backends
available = list_backends()
# Submit a circuit
task_id = backend.submit(circuit, shots=1000)
# Query task status
result = backend.query(task_id)
- class uniqc.backend.IBMBackend(name=None, config=None, cache_dir=None)[source]#
Bases:
QuantumBackendBackend for IBM Quantum via Qiskit.
This backend connects to IBM Quantum services for executing quantum circuits on IBM quantum computers and simulators.
- Proxy Configuration:
Proxies can be configured in multiple ways (in priority order): 1. Explicit config dict passed to constructor 2. Environment variables (HTTP_PROXY, HTTPS_PROXY) 3. uniqc.yml configuration file
Example
>>> # Using config file >>> backend = get_backend('ibm') >>> # Check proxy availability >>> backend.check_proxy() True >>> # Test IBM connectivity >>> result = backend.test_connectivity() >>> print(result['success']) True
- check_proxy()[source]#
Check if the configured proxy is available.
- Returns:
True if proxy is configured and reachable, False otherwise.
- Return type:
Note
If no proxy is configured, returns True (direct connection).
- class uniqc.backend.OriginQBackend(name=None, config=None, cache_dir=None)[source]#
Bases:
QuantumBackendBackend for OriginQ Cloud (本源量子云).
This backend connects to the OriginQ Cloud service for executing quantum circuits on OriginQ quantum computers and simulators.
- class uniqc.backend.QuafuBackend(name=None, config=None, cache_dir=None)[source]#
Bases:
QuantumBackendBackend for BAQIS Quafu (ScQ) quantum cloud platform.
This backend connects to the Quafu service for executing quantum circuits on superconducting quantum computers.
- VALID_CHIP_IDS = frozenset({'Dongling', 'ScQ-P10', 'ScQ-P10C', 'ScQ-P136', 'ScQ-P18'})#
- class uniqc.backend.QuantumBackend(name=None, config=None, cache_dir=None)[source]#
Bases:
ABCAbstract base class for quantum backend management.
This class provides a unified interface for all quantum computing backends, wrapping the underlying adapters and providing caching capabilities.
- Variables:
name – The name of this backend instance.
platform (ClassVar[str]) – The platform identifier (e.g., ‘originq’, ‘quafu’, ‘ibm’).
adapter – The underlying quantum adapter instance.
config – Backend-specific configuration dictionary.
- Parameters:
- property adapter: QuantumAdapter#
Get or create the underlying adapter instance.
- Returns:
The quantum adapter for this backend.
- Raises:
RuntimeError – If the adapter cannot be initialized.
- get_circuit_adapter()[source]#
Get the circuit adapter for translating circuits.
- Returns:
The quantum adapter that handles circuit translation.
- Return type:
- classmethod get_instance(name=None, config=None, use_cache=True, cache_dir=None)[source]#
Get or create a backend instance (factory method).
- Parameters:
- Returns:
A backend instance.
- Return type:
- is_available()[source]#
Check if this backend is available.
- Returns:
True if the backend is properly configured and ready to use.
- Return type:
- classmethod list_available()[source]#
Check if this backend type is available.
- Returns:
True if the backend can be instantiated and is configured.
- Return type:
- classmethod load_from_cache(cache_dir=None)[source]#
Load a backend instance from cache.
- Parameters:
cache_dir (Path | str | None) – Optional custom cache directory path.
- Returns:
Loaded backend instance or None if cache doesn’t exist or is invalid.
- Return type:
‘QuantumBackend’ | None
- query(task_id)[source]#
Query a task’s status and result.
- Parameters:
task_id (str) – Task identifier.
- Returns:
‘status’: ‘success’ | ‘failed’ | ‘running’
’result’: Execution result (when status is ‘success’ or ‘failed’)
- Return type:
Dict with keys
- uniqc.backend.get_backend(name, *, config=None, use_cache=True, cache_dir=None)[source]#
Get or create a backend instance by name.
This is the main factory function for obtaining backend instances. It uses the BACKENDS registry to look up the appropriate backend class and returns a configured instance.
- Parameters:
- Returns:
A configured QuantumBackend instance.
- Raises:
ValueError – If the backend name is not recognized.
RuntimeError – If the backend cannot be initialized.
- Return type:
Example
>>> backend = get_backend('originq') >>> task_id = backend.submit(circuit, shots=1000)
- uniqc.backend.list_backends()[source]#
List all available backends and their status.
- Returns:
A dictionary mapping backend names to their information, e.g.:
{ 'originq': {'available': True, 'platform': 'originq'}, 'quafu': {'available': False, 'platform': 'quafu'}, ... }
- Return type:
Example
>>> backends = list_backends() >>> for name, info in backends.items(): ... print(f"{name}: {'available' if info['available'] else 'unavailable'}")
- uniqc.backend.register_backend(name, backend_class, allow_override=False)[source]#
Register a custom backend class.
- Parameters:
name (str) – The platform name to register.
backend_class (Type[QuantumBackend]) – The backend class to register.
allow_override (bool) – Whether to allow overriding existing registrations.
- Raises:
ValueError – If the name is already registered and override is False.
- Return type:
None
Example
>>> class MyBackend(QuantumBackend): ... platform = "my_platform" ... def _create_adapter(self): ... return MyAdapter() ... >>> register_backend("my_platform", MyBackend)
- uniqc.backend.unregister_backend(name)[source]#
Unregister a backend.
- Parameters:
name (str) – The platform name to unregister.
- Raises:
ValueError – If the backend is not registered.
- Return type:
None