mqt.core.plugins.qiskit.serializers¶
Registry of program serializers for QDMI program formats.
A QDMI device accepts a program in one or more program formats, listed by
ProgramFormat. A program serializer turns one Qiskit
QuantumCircuit into one program in one such format.
A format fixes the kind of payload it carries, so there are two signatures. A
text format takes a TextProgramSerializer, which returns str.
A binary format takes a BinaryProgramSerializer, which returns
bytes. is_binary_program_format() states which
kind a format carries.
MQT Core registers its own OpenQASM 2 and OpenQASM 3 serializers here. Every
other format belongs to the package that owns the device. Such a package
advertises its serializer through the mqt.core.qiskit.program_serializers
entry point group. The entry point name is the
ProgramFormat member name, and the value points to the
serializer:
`toml
[project.entry-points."mqt.core.qiskit.program_serializers"]
IQM_JSON = "iqm.qdmi.serializers:qiskit_to_iqm_json"
`
register_program_serializer() does the same at run time. A registration
takes precedence over an entry point for the same format.
A device usually accepts several formats. PROGRAM_FORMAT_PREFERENCE
records which one to use, from most to least preferred, and
preferred_program_formats() applies that order to the formats a device
reports.
Module Contents¶
- ENTRY_POINT_GROUP = 'mqt.core.qiskit.program_serializers'¶
- class TextProgramSerializer¶
Bases:
ProtocolSerializes a circuit into a program format whose payload is text.
- __call__(circuit: QuantumCircuit, backend: QDMIBackend, /) str¶
Serialize a circuit into a program string.
- Parameters:
circuit – The circuit to serialize. It has no unbound parameters.
backend – The backend that runs the circuit. Its
deviceproperty provides the site names and metadata a format may need, and itstargetproperty provides the supported operations.
- Returns:
The program in the serializer’s format.
- Raises:
UnsupportedOperationError – If the circuit contains an operation the format cannot express.
TranslationError – If serialization fails for another reason.
- class BinaryProgramSerializer¶
Bases:
ProtocolSerializes a circuit into a program format whose payload is binary.
- __call__(circuit: QuantumCircuit, backend: QDMIBackend, /) bytes¶
Serialize a circuit into program bytes.
- Parameters:
circuit – The circuit to serialize. It has no unbound parameters.
backend – The backend that runs the circuit. Its
deviceproperty provides the site names and metadata a format may need, and itstargetproperty provides the supported operations.
- Returns:
The program in the serializer’s format.
- Raises:
UnsupportedOperationError – If the circuit contains an operation the format cannot express.
TranslationError – If serialization fails for another reason.
- ProgramSerializer¶
- PROGRAM_FORMAT_PREFERENCE: tuple[ProgramFormat, ...]¶
- register_program_serializer(fmt: ProgramFormat, serializer: ProgramSerializer, *, replace: bool = False) None¶
Register a serializer for one program format.
- Parameters:
- Raises:
ValueError – If the format does not carry a serialized circuit, or if the format already has a serializer and
replaceis false.
- unregister_program_serializer(fmt: ProgramFormat) None¶
Remove the serializer for one program format.
- Parameters:
fmt – The program format whose serializer to remove. A format without a serializer is ignored.
- program_serializer(fmt: ProgramFormat) ProgramSerializer | None¶
Return the serializer for one program format.
- Parameters:
fmt – The program format to look up.
- Returns:
The registered serializer, or
Noneif no package provides one.
- preferred_program_formats(formats: Iterable[ProgramFormat]) list[ProgramFormat]¶
Order the program formats a device reports by
PROGRAM_FORMAT_PREFERENCE.- Parameters:
formats – The program formats the device accepts.
- Returns:
The given formats, most preferred first. A format that
PROGRAM_FORMAT_PREFERENCEdoes not name comes after every format it does name, in the order it was given.