Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions bindings/mlir/qiskit/Qiskit2_5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,16 +1903,18 @@ class NativeTranslation final : public VersionedTranslation {
std::unique_ptr<VersionedTranslation>
MQT_QISKIT_VERSION_FACTORY() { // NOLINT(misc-use-internal-linkage): declared in
// the version registry.
if (qk_import() < 0) {
throwPythonError("failed to initialize the Qiskit " MQT_QISKIT_VERSION_LABEL
" C API");
}
const auto version = qk_api_version();
const auto major = (version >> 24U) & 0xffU;
const auto minor = (version >> 16U) & 0xffU;
static const auto VERSION = []() {
if (qk_import() < 0) {
throwPythonError(
"failed to initialize the Qiskit " MQT_QISKIT_VERSION_LABEL " C API");
}
return qk_api_version();
}();
const auto major = (VERSION >> 24U) & 0xffU;
const auto minor = (VERSION >> 16U) & 0xffU;
if (major != MQT_QISKIT_VERSION_EXPECTED_MAJOR ||
minor != MQT_QISKIT_VERSION_EXPECTED_MINOR ||
(MQT_QISKIT_VERSION_EXACT_API != 0 && version != QISKIT_VERSION_HEX)) {
(MQT_QISKIT_VERSION_EXACT_API != 0 && VERSION != QISKIT_VERSION_HEX)) {
throw std::runtime_error("Qiskit C API capsule version does not match the "
"selected " MQT_QISKIT_VERSION_LABEL
" translation");
Expand Down
13 changes: 13 additions & 0 deletions test/python/test_mlir_qiskit_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import re
import subprocess
import sys
from concurrent.futures import ThreadPoolExecutor
from typing import TYPE_CHECKING

import numpy as np
Expand Down Expand Up @@ -105,6 +106,18 @@
)


def test_native_api_initialization_supports_concurrent_translation() -> None:
"""Initialize and reuse the native Qiskit API from concurrent translations."""

def _round_trip(_: int) -> str:
circuit = QuantumCircuit(1)
circuit.x(0)
return QCProgram.from_qiskit(circuit).to_qiskit().data[0].operation.name

with ThreadPoolExecutor(max_workers=8) as executor:
assert list(executor.map(_round_trip, range(32))) == ["x"] * 32


@pytest.mark.parametrize("gate", STANDARD_GATES, ids=lambda gate: gate.name)
def test_standard_gates_round_trip(gate: Gate) -> None:
"""Translate each supported gate family in both directions."""
Expand Down
Loading