qpanda3_runtime.device.qdevice#
Classes#
Interface to real quantum computing devices. |
Module Contents#
- class qpanda3_runtime.device.qdevice.QDevice(runtime_service, dev_info, update_basic_info=True)#
Bases:
qpanda3_runtime.device.device_abc.DeviceABCInterface to real quantum computing devices.
Represents a physical quantum computer/chip backend, providing access to device information, configuration, and the ability to create simulated counterparts for testing.
- Parameters:
runtime_service (
RuntimeService) – Local management object for the QPanda3 Runtime Service, used for defining and submitting quantum computing tasks.dev_info (
Dict) – Metadata dictionary containing device information such as: - ‘chip_id’: Unique identifier for the device - ‘channel’: Access channel identifier - ‘nameDetail’: Human-readable device name - ‘qubitNum’: Number of qubits (may be populated later)update_basic_info (
bool, optional) – Whether to immediately update device information from the server. Default is True.
- Variables:
_basic_info (
Dict) – Basic device information (name, ID, qubit count, etc.)._config_info (
Dict) – Detailed configuration information (topology, gates, noise, etc.)._runtime_service (
RuntimeService) – Runtime service for device management and task submission.
Notes
This class represents actual quantum hardware, not simulations.
Device information is lazily loaded when accessed.
Can generate a FakeBackend for simulation based on real device data.
Implements the DeviceABC interface for serialization.
Examples
>>> from qpanda3_runtime import RuntimeService >>> from qpanda3_runtime.device import QDevice >>> >>> # Create a QDevice from device list >>> runtime = RuntimeService() >>> devices = runtime.list_devices() >>> real_device = QDevice(runtime, devices[0].basic_info()) >>> >>> # Access device information >>> print(f"Device: {real_device.name()}, Qubits: {real_device.qubit_num()}") >>> >>> # Create a simulated version for testing >>> fake_device = real_device.fake_backend()
See also
FakeBackendSimulated version of a quantum device.
DeviceABCAbstract base class for quantum devices.
RuntimeService.list_devicesGet available quantum devices.
- channel()#
Get the access channel for the quantum device.
- Returns:
Access channel identifier (e.g., ‘qcloud’, ‘local_simulator’).
- Return type:
str
Notes
The channel determines how the device is accessed (cloud, local, etc.).
Used internally for routing quantum computing tasks.
Typically set during device initialization.
Examples
>>> device = QDevice(runtime, dev_info) >>> print(f"Access channel: {device.channel()}")
- chip_id()#
Get the unique identifier of the quantum device.
- Returns:
Unique device identifier (e.g., ‘chip_001’, ‘quantum_backend_1’).
- Return type:
str
Notes
The chip ID is used to uniquely identify the device in the system.
Required for device-specific operations and configuration queries.
Should be present in the dev_info provided during initialization.
Examples
>>> device = QDevice(runtime, dev_info) >>> print(f"Device ID: {device.chip_id()}")
- basic_info()#
Get the basic information dictionary for the quantum device.
- Returns:
Dictionary containing basic device information, typically including: - ‘chip_id’: Unique device identifier - ‘channel’: Access channel - ‘nameDetail’: Human-readable name - ‘qubitNum’: Number of qubits (may be None initially) - Other device-specific metadata
- Return type:
Dict
Notes
This is the same dictionary passed during initialization.
May be updated by update_basic_info().
Useful for debugging or displaying device information.
Examples
>>> device = QDevice(runtime, dev_info) >>> info = device.basic_info() >>> print(f"Device info keys: {list(info.keys())}")
- update_basic_info()#
Update basic device information from the server.
Fetches the latest device information from the runtime service and updates the local basic_info dictionary.
Notes
Queries the server for the most up-to-date device information.
Updates fields like nameDetail, qubitNum, and other metadata.
Called automatically during initialization if update_basic_info=True.
Can be called manually to refresh device information.
Examples
>>> device = QDevice(runtime, dev_info, update_basic_info=False) >>> # Later, update information >>> device.update_basic_info() >>> print(f"Updated name: {device.name()}")
See also
basic_infoGet the current basic information.
nameGet the device name (calls update_basic_info if needed).
- name()#
Get the human-readable name of the quantum device.
- Returns:
Device name (e.g., ‘Origin Quantum Chip v1.0’, ‘IBM Quantum Montreal’).
- Return type:
str
Notes
The name is stored in the ‘nameDetail’ field of basic_info.
If not available locally, updates basic_info from the server.
Useful for user interfaces and logging.
Examples
>>> device = QDevice(runtime, dev_info) >>> print(f"Device name: {device.name()}")
- available_qubits()#
Get the list of available qubits on the quantum device.
- Returns:
List of qubit indices that are available for use.
- Return type:
list
- config_info()#
Get the detailed configuration information dictionary.
- Returns:
Dictionary containing detailed device configuration, typically including: - ‘BasicQGate’: List of supported basic quantum gates - ‘CompensateAngle’: Angle compensation mapping - ‘adjMatrix’: Adjacency matrix for qubit connectivity - ‘QGateClock’: Gate timing information - ‘QubitParamsOrigin’: Qubit-specific parameters (T1, T2, etc.)
- Return type:
Dict
Notes
Configuration information is lazily loaded on first access.
Contains technical details needed for circuit compilation.
Used by FakeBackend to create accurate simulations.
Examples
>>> device = QDevice(runtime, dev_info) >>> config = device.config_info() >>> print(f"Supported gates: {config.get('BasicQGate', [])}")
- update_config_info()#
Update configuration information from the server.
Fetches the latest device configuration from the runtime service and updates the local config_info dictionary.
Notes
Queries the server for detailed device configuration.
Updates fields like gate set, topology, noise parameters.
Called automatically when configuration information is first accessed.
Can be called manually to refresh configuration.
Examples
>>> device = QDevice(runtime, dev_info) >>> # Force update of configuration >>> device.update_config_info() >>> print(f"Updated gate set: {device.basic_gates()}")
See also
config_infoGet the current configuration information.
basic_gatesGet supported gates (calls update_config_info if needed).
- basic_gates(update_info: bool = False)#
Get the basic quantum gates supported by the device.
- Parameters:
update_info (
bool, optional) – If True, force an update from the server before returning. If False, use cached information if available. Default is False.- Returns:
List of basic quantum gate names supported at the physical level.
- Return type:
List[str]
Notes
These are the gates that can be directly executed on the hardware.
Circuit transpilation decomposes higher-level gates into these.
Information is cached after first retrieval.
Examples
>>> device = QDevice(runtime, dev_info) >>> gates = device.basic_gates() >>> print(f"Device supports: {gates}") >>> >>> # Force update from server >>> gates = device.basic_gates(update_info=True)
- compensate_angle_map(update_info: bool = False)#
Get the angle compensation mapping for two-qubit gates.
- Parameters:
update_info (
bool, optional) – If True, force an update from the server before returning. If False, use cached information if available. Default is False.- Returns:
Dictionary mapping qubit pairs to angle compensation values. Used to correct systematic errors in two-qubit gate operations.
- Return type:
Dict
Notes
Compensation angles are device-specific calibration data.
Applied during circuit transpilation to improve gate fidelity.
Information is cached after first retrieval.
Examples
>>> device = QDevice(runtime, dev_info) >>> comp_map = device.compensate_angle_map() >>> print(f"Compensation map has {len(comp_map)} entries")
- chip_topo_adjoint_matrix(update_info: bool = False)#
Get the qubit connectivity as an adjacency matrix.
- Parameters:
update_info (
bool, optional) – If True, force an update from the server before returning. If False, use cached information if available. Default is False.- Returns:
Adjacency matrix representation of qubit connectivity. Keys are qubit indices, values are lists of connected qubits with additional information (e.g., {‘v’: connected_qubit_index}).
- Return type:
Dict[int,List[Dict[str,int]]]
Notes
Represents which qubit pairs can directly interact.
Used for circuit compilation and qubit mapping.
Information is cached after first retrieval.
Examples
>>> device = QDevice(runtime, dev_info) >>> adj_matrix = device.chip_topo_adjoint_matrix() >>> print(f"Qubit 0 connects to: {adj_matrix.get(0, [])}")
- chip_topo_edges(update_info: bool = False)#
Get the qubit connectivity as a list of edges.
- Parameters:
update_info (
bool, optional) – If True, force an update from the server before returning. If False, use cached information if available. Default is False.- Returns:
List of edges representing qubit connectivity. Each edge is [q1, q2] where q1 < q2 and qubits can directly interact.
- Return type:
List[List[int]]
Notes
Derived from the adjacency matrix for easier processing.
Each edge appears only once (q1 < q2).
Used by FakeBackend and circuit transpilation algorithms.
Information is cached after first computation.
Examples
>>> device = QDevice(runtime, dev_info) >>> edges = device.chip_topo_edges() >>> print(f"Device has {len(edges)} direct connections") >>> for q1, q2 in edges[:5]: >>> print(f" {q1} -- {q2}")
- gate_clock(update_info: bool = False)#
Get the timing information for quantum gate operations.
- Parameters:
update_info (
bool, optional) – If True, force an update from the server before returning. If False, use cached information if available. Default is False.- Returns:
Dictionary containing gate timing information, typically including execution times for different gate types (single-qubit, two-qubit, etc.).
- Return type:
Dict
Notes
Gate timing affects decoherence error modeling in simulations.
Used by FakeBackend to create accurate noise models.
Information is cached after first retrieval.
Examples
>>> device = QDevice(runtime, dev_info) >>> clock_info = device.gate_clock() >>> print(f"Gate timing: {clock_info}")
- qubit_info(update_info: bool = False)#
Get detailed information about individual qubits.
- Parameters:
update_info (
bool, optional) – If True, force an update from the server before returning. If False, use cached information if available. Default is False.- Returns:
Dictionary mapping qubit indices (as strings) to qubit parameter dictionaries. Each qubit dictionary typically includes: - ‘T1’: T1 decoherence time - ‘T2’: T2 decoherence time - ‘FidelityMat’: Readout fidelity matrix - Other qubit-specific calibration data
- Return type:
Dict[str,Dict]
Notes
Used for noise modeling in simulations.
Qubit parameters vary across the device due to manufacturing variations.
Information is cached after first retrieval.
Examples
>>> device = QDevice(runtime, dev_info) >>> qubits = device.qubit_info() >>> q0_info = qubits.get('0', {}) >>> print(f"Qubit 0 T1: {q0_info.get('T1', 'N/A')}")
- fake_backend()#
Create a simulated version of this quantum device.
- Returns:
A FakeBackend object configured with this device’s topology, gate set, and noise characteristics.
- Return type:
FakeBackend
Notes
The FakeBackend uses the same configuration as this real device.
Useful for testing algorithms before running on real hardware.
Noise models are derived from device calibration data.
Examples
>>> device = QDevice(runtime, dev_info) >>> # Create a simulated version for testing >>> simulator = device.fake_backend() >>> # Test circuit on simulator >>> result = simulator.sample(test_circuit, shots=1000)
See also
FakeBackendThe simulated quantum device class.
- to_json_dict()#
Serialize the QDevice to a JSON-serializable dictionary.
- Returns:
Dictionary containing all necessary information to reconstruct the QDevice, including: - ‘type’: Always ‘QDevice’ - ‘basic_info’: Basic device information - ‘config_info’: Detailed configuration information
- Return type:
Dict
Notes
Implements the abstract method from DeviceABC.
The dictionary is JSON-serializable for storage or transmission.
Can be used with from_json_dict to recreate the object.
Configuration information may be empty if not yet loaded.
See also
from_json_dictReconstruct a QDevice from serialized data.
DeviceABC.to_json_dictAbstract base class method.
- static from_json_dict(runtime_service, dev_data)#
Reconstruct a QDevice from serialized data.
- Parameters:
runtime_service (
RuntimeService) – Runtime service for device management.dev_data (
Dict) – Dictionary containing serialized QDevice data, as returned by to_json_dict().
- Returns:
Reconstructed QDevice object.
- Return type:
Notes
This is a static method for object reconstruction.
The reconstructed device will have cached configuration if present.
Basic information update is disabled during reconstruction.
See also
to_json_dictSerialize a QDevice to dictionary.