device_converter
¶
DeviceConverter
¶
Abstract base class for converting devices to different formats.
Provides abstract methods to be implemented by subclasses for specific conversion logic. The actual implementation of the conversion will be done in each subclass.
convert
abstractmethod
¶
convert(device: Any) -> Any
Convert a given device to a different format or representation.
Subclasses should implement this method to define specific conversion logic.
Parameters:
-
device(Any) –The device to be converted, which can be of any type.
Returns:
-
Any(Any) –The converted device in the desired format or representation.
DeviceConverterAlreadyRegisteredError
¶
Raised when attempting to register a device converter that already exists.
invalid_backend_type
classmethod
¶
invalid_backend_type(backend_type: object | None = None) -> DeviceConverterError
Create an error for invalid backend type.
Returns:
-
DeviceConverterError(DeviceConverterError) –The error instance.
DeviceConverterError
¶
Base exception for device converter-related errors.
invalid_backend_type
classmethod
¶
invalid_backend_type(backend_type: object | None = None) -> DeviceConverterError
Create an error for invalid backend type.
Returns:
-
DeviceConverterError(DeviceConverterError) –The error instance.
DeviceConverterManager
¶
DeviceConverterManager()
Manages conversions between devices.
Provides methods to register, retrieve, and check converters between devices. Converters are used to perform conversions from a specific source device to a target device.
fetch_converter
¶
fetch_converter(from_lib: str, to_lib: str) -> DeviceConverter
Retrieve a converter from the specified device to another device.
Parameters:
-
from_lib(str) –The name of the source device
-
to_lib(str) –The name of the target device
Returns:
-
DeviceConverter(DeviceConverter) –An instance of the converter corresponding to the specified source and target devices. If the source and target are the same, it returns an instance of PassThroughDeviceConverter.
Raises:
-
DeviceConverterNotFoundError–Raised when the requested converter is not found.
has_converter
¶
has_converter(from_lib: str, to_lib: str) -> bool
Check if a converter exists between the specified devices.
Parameters:
-
from_lib(str) –The name of the source device
-
to_lib(str) –The name of the target device
Returns:
-
bool(bool) –True if a converter exists, False otherwise
register_converter
¶
register_converter(from_lib: str, to_lib: str, converter: DeviceConverter, *, allow_override: bool = False) -> None
Register a converter between the specified devices.
Parameters:
-
from_lib(str) –The name of the source device
-
to_lib(str) –The name of the target device
-
converter(DeviceConverter) –The converter instance to register
-
allow_override(bool, default:False) –When False, prevents overwriting existing registrations. Defaults to False.
Raises:
-
DeviceConverterAlreadyRegisteredError–Raises if trying to re-register an already registered converter and allow_override is False.
DeviceConverterNotFoundError
¶
Raised when the requested converter is not found.
invalid_backend_type
classmethod
¶
invalid_backend_type(backend_type: object | None = None) -> DeviceConverterError
Create an error for invalid backend type.
Returns:
-
DeviceConverterError(DeviceConverterError) –The error instance.
OqtopusToOuquTpDeviceConverter
¶
Device converter for converting from Oqtopus to ouqu-tp format.
convert
staticmethod
¶
convert(device: dict[str, Any]) -> str
Convert a Oqtopus device to ouqu-tp format.
Parameters:
-
device(dict[str, Any]) –The Oqtopus device to be converted.
Returns:
-
str(str) –The converted ouqu-tp format device.
OqtoqusToQiskitDeviceConverter
¶
Device converter for converting from Oqtopus to Qiskit format.
convert
¶
convert(device: Any) -> BackendV2
Convert a Oqtopus device to Qiskit device format.
Parameters:
-
device(Any) –The Oqtopus device to be converted.
Returns:
-
BackendV2(BackendV2) –The converted Qiskit format device.
Raises:
-
DeviceConverterError–If the conversion fails.
PassThroughDeviceConverter
¶
A converter that returns the input device as is.
It is used internally in Tranqu as a placeholder when a converter is not needed during transpilation.
convert
¶
convert(device: Any) -> Any
Return the input device as is.
Parameters:
-
device(Any) –The device to be converted.
Returns:
-
Any(Any) –The device returned without any conversion.
QiskitDevice
¶
QiskitDevice(name: str, target: Target)
Device class extending Qiskit's BackendV2.
This class represents a target device used in Qiskit's transpiler.
Parameters:
-
name(str) –Name of the device.
-
target(Target) –Target information used in the transpiler.
max_circuits
property
¶
max_circuits: Any
Raise an exception for unsupported functionality.
Raises:
-
NotImplementedError–'max_circuits' function is not supported.
target
property
¶
target: Any
Retrieve the target information of the device.
Returns:
-
Target(Any) –Target information used in the transpiler.
run
¶
run(_run_input: Any, **_options: dict[str, Any]) -> Any
Raise an exception for unsupported functionality.
Parameters:
-
_run_input(Any) –Quantum circuit to execute.
-
**_options(dict[str, Any], default:{}) –Execution options.
Raises:
-
NotImplementedError–'run' function is not supported.
QiskitToOuquTpDeviceConverter
¶
Device converter for converting from Qiskit to ouqu-tp format.
convert
¶
convert(device: BackendV2) -> str
Convert a Qiskit device to ouqu-tp format.
Parameters:
-
device(BackendV2) –The Qiskit device to be converted.
Returns:
-
str(str) –The converted ouqu-tp format device.
QiskitToTketDeviceConverter
¶
Converter that transforms Qiskit backends to tket device information.
convert
staticmethod
¶
convert(device: BackendV2) -> Backend
Convert a Qiskit device to a tket device.
Parameters:
-
device(BackendV2) –Qiskit device to convert.
Returns:
-
Backend(Backend) –Converted tket device.
Raises:
-
DeviceConverterError–If the device is not a BackendV2 instance.