Skip to content

tranqu

Tranqu

Tranqu()

Manage the transpilation of quantum circuits.

Handles converters for transforming between different quantum program formats and transpilers for optimizing quantum circuits.

register_default_transpiler_lib

register_default_transpiler_lib(default_transpiler_lib: str, *, allow_override: bool = False) -> None

Register the default transpiler library.

Parameters:

  • default_transpiler_lib (str) –

    The name of the default transpiler library to register.

  • allow_override (bool, default: False ) –

    When True, allows overwriting of existing default transpiler lib.

register_device_converter

register_device_converter(from_device_lib: str, to_device_lib: str, converter: DeviceConverter, *, allow_override: bool = False) -> None

Register a device converter.

This method allows you to register a converter for transforming between different device types.

Parameters:

  • from_device_lib (str) –

    The identifier for the source device type of the converter to be registered.

  • to_device_lib (str) –

    The identifier for the target device type of the converter to be registered.

  • converter (DeviceConverter) –

    The device converter to be registered (subclass of DeviceConverter).

  • allow_override (bool, default: False ) –

    When True, allows overwriting of existing converters. Defaults to False.

Examples:

To register a converter that transforms from "foo" to "bar", you would call:

tranqu.register_device_converter("foo", "bar", FooToBarDeviceConverter)

register_device_type

register_device_type(device_lib: str, device_type: type, *, allow_override: bool = False) -> None

Register a mapping between a device type and its library identifier.

This method enables automatic detection of the device library based on the device type when calling transpile().

Parameters:

  • device_lib (str) –

    The identifier for the device library (e.g., "qiskit", "oqtopus")

  • device_type (type) –

    The type class to be associated with the library

  • allow_override (bool, default: False ) –

    When True, allows overwriting of existing type registrations. Defaults to False.

Examples:

To register Qiskit's backend type: tranqu.register_device_type("qiskit", BackendV2)

register_program_converter

register_program_converter(from_program_lib: str, to_program_lib: str, converter: ProgramConverter, *, allow_override: bool = False) -> None

Register a program converter.

This method allows you to register a converter for transforming between different program types.

Parameters:

  • from_program_lib (str) –

    The identifier for the source program type of the converter to be registered.

  • to_program_lib (str) –

    The identifier for the target program type of the converter to be registered.

  • converter (ProgramConverter) –

    The program converter to be registered (subclass of ProgramConverter).

  • allow_override (bool, default: False ) –

    When True, allows overwriting of existing converters. Defaults to False.

Examples:

To register a converter that transforms from "foo" to "bar", you can call:

tranqu.register_program_converter(
    "foo", "bar",
    FooToBarProgramConverter)

register_program_type

register_program_type(program_lib: str, program_type: type, *, allow_override: bool = False) -> None

Register a mapping between a program type and its library identifier.

This method allows automatic detection of the program library based on the program's type when calling transpile().

Parameters:

  • program_lib (str) –

    The identifier for the program library (e.g., "qiskit", "tket")

  • program_type (type) –

    The type class to be associated with the library

  • allow_override (bool, default: False ) –

    When True, allows overwriting of existing type registrations. Defaults to False.

Examples:

To register Qiskit's QuantumCircuit type: tranqu.register_program_type("qiskit", QuantumCircuit)

register_transpiler

register_transpiler(transpiler_lib: str, transpiler: Any, *, allow_override: bool = False) -> None

Register a transpiler for optimizing quantum circuits.

This method allows you to register a transpiler for optimizing quantum circuits.

Parameters:

  • transpiler_lib (str) –

    The name of the transpiler library.

  • transpiler (Any) –

    The transpiler to be registered.

  • allow_override (bool, default: False ) –

    When True, allows overwriting of existing transpilers

transpile

transpile(program: Any, program_lib: str | None = None, transpiler_lib: str | None = None, *, transpiler_options: dict[str, Any] | None = None, device: Any | None = None, device_lib: str | None = None) -> TranspileResult

Transpile the program using the specified transpiler.

Parameters:

  • program (Any) –

    The program to be transformed.

  • program_lib (str | None, default: None ) –

    The library or format of the program. If None, will attempt to detect based on program type.

  • transpiler_lib (str | None, default: None ) –

    The name of the transpiler to be used.

  • transpiler_options (dict[str, Any], default: None ) –

    Options passed to the transpiler.

  • device (Any | None, default: None ) –

    Information about the device on which the program will be executed.

  • device_lib (str | None, default: None ) –

    Specifies the type of the device.

Returns:

TranquError

Base exception for errors related to Tranqu.

TranspileResult

TranspileResult(transpiled_program: Any, stats: dict[str, dict[str, int]], virtual_physical_mapping: dict[str, dict[int, int]])

Hold transpilation results.

Parameters:

  • transpiled_program (Any) –

    The quantum program after transpilation.

  • stats (dict[str, dict[str, int]]) –

    Statistical information before and after transpilation.

  • virtual_physical_mapping (dict[str, dict[int, int]]) –

    Mapping between virtual quantum bits and physical quantum bits.

to_dict

to_dict() -> dict[str, Any]

Convert the TranspileResult to a dictionary.

Returns:

  • dict[str, Any]

    dict[str, Any]: A dictionary representation of the TranspileResult,

  • dict[str, Any]

    containing the statistical information and the virtual-physical

  • dict[str, Any]

    qubit and bit mappings.