qpanda3_runtime.utils.exception#
Exception module for quantum computing runtime client.
This module provides error handling classes and utilities for the QPanda3 runtime client. It includes error type enumerations and response error containers for consistent error reporting across the quantum computing service stack.
Classes#
- ErrorType
Enumeration of error types for quantum computing runtime errors.
- ResponseError
Container class for response errors with serialization support.
Examples
>>> from qpanda3_runtime.utils.exception import ErrorType, ResponseError
>>>
>>> # Create a resource unavailable error
>>> error = ResponseError.resource_unavailable(
... 'quantum_device',
... 1001,
... 'Device calibration in progress',
... ['device_status', 'calibration_check']
... )
>>>
>>> # Convert to JSON for transmission
>>> json_str = error.json()
>>> print(json_str)
{"position": "quantum_device", "error_code": 1001, ...}
Submodules#
Classes#
Error type enumeration for response errors. |
|
Response error container for quantum computing runtime operations. |
Package Contents#
- class qpanda3_runtime.utils.exception.ErrorType(*args, **kwds)#
Bases:
enum.EnumError type enumeration for response errors.
This enum defines the types of errors that can occur in the quantum computing runtime system. Each error type corresponds to a specific category of failures.
- Variables:
Undefined (
int) – Default error type when the specific error category is not determined.ResourceUnavailable (
int) – Error type for when required resources (quantum devices, services, etc.) are not available or accessible.InvalidRequest (
int) – Error type for when the client request contains invalid parameters, malformed data, or violates system constraints.ServiceFailure (
int) – Error type for when internal service operations fail due to unexpected conditions or system errors.
- Undefined = 0#
- InvalidRequest = 4#
- ServiceFailure = 6#
- class qpanda3_runtime.utils.exception.ResponseError(position: str, error_code: int, error_info: str, error_type: ErrorType, trace_record: list | None)#
Response error container for quantum computing runtime operations.
This class encapsulates error information returned from quantum computing services, including error location, code, description, type, and trace records.
- Parameters:
position (
str) – The location or component where the error occurred (e.g., function name, module name, or service endpoint).error_code (
int) – Numeric error code identifying the specific error condition.error_info (
str) – Human-readable description of the error.error_type (
ErrorType) – Category of the error (see ErrorType enum).trace_record (
Union[list,None]) – List of trace records providing detailed error context, or None for no trace information.
- Variables:
position (
str) – Error location identifier.error_code (
int) – Numeric error code.error_info (
str) – Error description.error_type (
ErrorType) – Error category.trace_record (
list) – List of trace records for debugging.help_info (
str) – Additional help information (optional, initialized as empty string).
- position#
- error_code#
- error_info#
- help_info = ''#
- dict_data()#
Convert the error object to a dictionary representation.
- Returns:
Dictionary containing all error attributes with keys: - ‘position’: error location - ‘error_code’: numeric error code - ‘error_info’: error description - ‘error_type’: error type value (integer) - ‘trace_record’: list of trace records - ‘help_info’: additional help information
- Return type:
dict
Examples
>>> error = ResponseError('service_endpoint', 1001, 'Device not found', ... ErrorType.ResourceUnavailable, None) >>> error_dict = error.dict_data() >>> print(error_dict['error_code']) 1001
- json()#
Convert the error object to a JSON string representation.
- Returns:
JSON-formatted string containing all error attributes.
- Return type:
str
See also
dict_dataGet dictionary representation of the error.
Examples
>>> error = ResponseError('auth_service', 2001, 'Invalid API key', ... ErrorType.InvalidRequest, ['auth_check', 'key_validation']) >>> json_str = error.json() >>> print(json_str[:50]) {"position": "auth_service", "error_code": 2001, ...
- static from_dict(data)#
Create a ResponseError object from a dictionary.
- Parameters:
data (
dict) – Dictionary containing error information with keys: - ‘position’: error location (string) - ‘error_code’: numeric error code (int) - ‘error_info’: error description (string) - ‘error_type’: error type value (int) - ‘trace_record’: list of trace records (list) - ‘help_info’: optional help information (string, optional)- Returns:
New ResponseError instance populated from the dictionary data.
- Return type:
- Raises:
KeyError – If required dictionary keys are missing.
ValueError – If error_type value is not a valid ErrorType enum value.
Examples
>>> error_dict = { ... 'position': 'quantum_device', ... 'error_code': 3001, ... 'error_info': 'Device calibration failed', ... 'error_type': 6, # ServiceFailure ... 'trace_record': ['calibration', 'hardware_check'], ... 'help_info': 'Try restarting the device' ... } >>> error = ResponseError.from_dict(error_dict) >>> print(error.error_info) Device calibration failed
- static from_json(json_data)#
Create a ResponseError object from a JSON string.
- Parameters:
json_data (
str) – JSON-formatted string containing error information.- Returns:
New ResponseError instance populated from the JSON data.
- Return type:
Examples
>>> json_str = '''{ ... "position": "network_layer", ... "error_code": 4001, ... "error_info": "Connection timeout", ... "error_type": 5, ... "trace_record": ["socket_connect", "retry_attempt"] ... }''' >>> error = ResponseError.from_json(json_str) >>> print(error.position) network_layer
Create a ResponseError for resource unavailable errors.
- Parameters:
position (
str) – Location where the resource error occurred.error_code (
int) – Numeric error code specific to the resource issue.error_info (
str) – Description of the resource error.trace_record (
Union[list,None]) – Trace records for debugging, or None for no trace.
- Returns:
ResponseError instance with error_type set to ResourceUnavailable.
- Return type:
Examples
>>> error = ResponseError.resource_unavailable( ... 'quantum_processor', ... 5001, ... 'Quantum device is currently undergoing maintenance', ... ['device_status_check', 'maintenance_schedule'] ... ) >>> print(error.error_type) ErrorType.ResourceUnavailable
- static invalid_request(position: str, error_code: int, error_info: str, trace_record: list | None)#
Create a ResponseError for invalid request errors.
- Parameters:
position (
str) – Location where the request validation failed.error_code (
int) – Numeric error code specific to the validation failure.error_info (
str) – Description of why the request is invalid.trace_record (
Union[list,None]) – Trace records for debugging, or None for no trace.
- Returns:
ResponseError instance with error_type set to InvalidRequest.
- Return type:
Examples
>>> error = ResponseError.invalid_request( ... 'parameter_validation', ... 6001, ... 'Qubit count must be between 1 and 20', ... ['param_check', 'range_validation'] ... ) >>> print(error.error_type) ErrorType.InvalidRequest