Skip to content

program_converter

Openqasm3ToQiskitProgramConverter

Converter that transforms programs in OpenQASM3 format to Qiskit's format.

convert

convert(program: str) -> QuantumCircuit

Convert the specified OpenQASM3 format program to Qiskit's format.

Parameters:

  • program (str) –

    A string representing a quantum program in OpenQASM3 format.

Returns:

  • QuantumCircuit ( QuantumCircuit ) –

    A quantum circuit in Qiskit format.

Openqasm3ToTketProgramConverter

Converter that transforms OpenQASM3 to tket format quantum circuits.

convert

convert(program: str) -> Circuit

Convert a quantum program in OpenQASM3 format to tket format.

Parameters:

  • program (str) –

    A string representing a quantum program in OpenQASM3 format.

Returns:

  • Circuit ( Circuit ) –

    A quantum circuit in tket format.

PassThroughProgramConverter

A converter that returns the input program as is.

It is used internally in Tranqu as a placeholder when a converter is not needed during transpilation.

convert

convert(program: Any) -> Any

Return the input program as is.

Parameters:

  • program (Any) –

    The program to be converted.

Returns:

  • Any ( Any ) –

    The program returned without any conversion.

ProgramConverter

Abstract base class for converting programs 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(program: Any) -> Any

Convert a given program to a different format or representation.

Subclasses should implement this method to define specific conversion logic.

Parameters:

  • program (Any) –

    The program to be converted, which can be of any type.

Returns:

  • Any ( Any ) –

    The converted program in the desired format or representation.

ProgramConverterAlreadyRegisteredError

Raised when attempting to re-register an already registered converter.

ProgramConverterManager

ProgramConverterManager()

Manage ProgramConverters for converting between different programs.

Provides functionality to register, retrieve, and check converters. Converters are objects that perform conversions from a specific source program to a target program.

fetch_converter

fetch_converter(from_lib: str, to_lib: str) -> ProgramConverter

Retrieve a converter from the specified program to another program.

Parameters:

  • from_lib (str) –

    The name of the source program.

  • to_lib (str) –

    The name of the target program.

Returns:

  • ProgramConverter ( ProgramConverter ) –

    An instance of the converter corresponding to the specified source and target programs. If the source and target are the same, it returns an instance of PassThroughProgramConverter.

Raises:

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 (string)

  • to_lib (str) –

    The name of the target device (string)

Returns:

  • bool ( bool ) –

    True if a converter exists, False otherwise

register_converter

register_converter(from_lib: str, to_lib: str, converter: ProgramConverter, *, allow_override: bool = False) -> None

Register a converter between the specified programs.

Parameters:

  • from_lib (str) –

    The name of the source program.

  • to_lib (str) –

    The name of the target program.

  • converter (ProgramConverter) –

    The converter instance to register.

  • allow_override (bool, default: False ) –

    When False, prevents overwriting existing registrations. Defaults to False.

Raises:

ProgramConverterNotFoundError

Raised when the requested converter is not found.

QiskitToOpenqasm3ProgramConverter

Converter for converting from Qiskit to OpenQASM3 format.

convert

convert(program: QuantumCircuit) -> str

Convert a Qiskit quantum circuit to OpenQASM3 format.

Parameters:

  • program (QuantumCircuit) –

    The Qiskit quantum circuit to be converted.

Returns:

  • str ( str ) –

    The converted OpenQASM3 format code.

QiskitToTketProgramConverter

Converter to transform Qiskit circuits to tket format.

convert

convert(program: QuantumCircuit) -> Circuit

Convert a Qiskit quantum circuit to tket format.

Parameters:

  • program (QuantumCircuit) –

    The Qiskit quantum circuit to be converted.

Returns:

  • Circuit ( Circuit ) –

    The converted tket format quantum circuit.

TketToOpenqasm3ProgramConverter

Converter that transforms Tket format quantum circuits to OpenQASM3 format.

convert

convert(program: Circuit) -> str

Convert a Tket format quantum circuit to OpenQASM 3 format.

Parameters:

  • program (Circuit) –

    Quantum circuit in Tket format.

Returns:

  • str ( str ) –

    A string representing the quantum circuit in OpenQASM 3 format.

TketToQiskitProgramConverter

Converter for transforming quantum circuits from Tket to Qiskit.

convert

convert(program: Circuit) -> QuantumCircuit

Convert a TketCircuit to a Qiskit QuantumCircuit.

Parameters:

  • program (TketCircuit) –

    The Tket quantum circuit to be converted.

Returns:

  • QiskitCircuit ( QuantumCircuit ) –

    The converted Qiskit quantum circuit.