Skip to content

Commit 1bfca2e

Browse files
Avoid wrapping non-QIR targets for Cirq and Qiskit generic wrappers (#733)
1 parent 6698781 commit 1bfca2e

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

azure-quantum/azure/quantum/cirq/service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ def targets(
9696
cirq_targets.append(target)
9797
continue
9898

99+
# Only apply the generic QIR fallback to targets that advertise a QIR
100+
# target profile. Providers like Pasqal use pulse-level input formats
101+
# (e.g. pasqal.pulser.v1) that are incompatible with QIR submission.
102+
# target_profile is None for non-QIR targets.
103+
if not status.target_profile:
104+
continue
105+
99106
cirq_targets.append(
100107
AzureGenericQirCirqTarget.from_target_status(
101108
self._workspace, pid, status, **kwargs

azure-quantum/azure/quantum/qiskit/provider.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ def backends(self, name=None, **kwargs):
143143
if (target_id, pid) in existing_pairs:
144144
continue
145145
status = status_by_target.get((target_id, pid))
146+
# Only create a generic QIR backend for targets that advertise a QIR
147+
# target profile. Providers like Pasqal use pulse-level input formats
148+
# (e.g. pasqal.pulser.v1) that are incompatible with QIR submission.
149+
# target_profile is None for non-QIR targets.
150+
if status is not None and not status.target_profile:
151+
continue
146152
backend_list.append(
147153
AzureGenericQirBackend(
148154
name=target_id,

azure-quantum/tests/mock_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,21 @@ def _target(
766766
],
767767
}
768768
),
769+
# A non-QIR provider (no target_profile) that should never get a generic
770+
# QIR backend/target wrapper — mirrors real-world Pasqal behavior.
771+
ProviderStatus(
772+
{
773+
"id": "pasqal",
774+
"currentAvailability": "Available",
775+
"targets": [
776+
_target(
777+
target_id="pasqal.sim.emu-tn",
778+
num_qubits=100,
779+
target_profile=None,
780+
)
781+
],
782+
}
783+
),
769784
]
770785

771786
ws._client.services.providers._store[:] = providers

azure-quantum/tests/test_cirq.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,38 @@ def test_cirq_generic_to_cirq_result_drops_non_binary_shots_and_exposes_raw():
233233
)
234234

235235

236+
def test_cirq_service_targets_excludes_non_qir_target():
237+
"""Targets without a target_profile (e.g. Pasqal) must not be wrapped as
238+
AzureGenericQirCirqTarget — they use pulse-level input formats incompatible
239+
with QIR submission.
240+
"""
241+
pytest.importorskip("cirq")
242+
pytest.importorskip("cirq_ionq")
243+
244+
from azure.quantum.cirq.service import AzureQuantumService
245+
from azure.quantum.cirq.targets.generic import AzureGenericQirCirqTarget
246+
247+
from mock_client import create_default_workspace
248+
249+
ws = create_default_workspace()
250+
_freeze_workspace_client_recreation(ws)
251+
service = AzureQuantumService(workspace=ws)
252+
253+
targets = service.targets()
254+
target_names = [t.name for t in targets]
255+
256+
# The Pasqal target (target_profile=None) should be completely absent.
257+
assert not any(
258+
"pasqal" in name for name in target_names
259+
), f"Non-QIR Pasqal target unexpectedly appeared in service.targets(): {target_names}"
260+
# Specifically, no AzureGenericQirCirqTarget should have been created for it.
261+
assert not any(
262+
isinstance(t, AzureGenericQirCirqTarget) and "pasqal" in t.name for t in targets
263+
)
264+
# QIR-capable targets should still be present.
265+
assert any("microsoft.estimator" in name for name in target_names)
266+
267+
236268
def test_cirq_service_targets_discovers_provider_specific_and_generic_wrappers(
237269
monkeypatch: pytest.MonkeyPatch,
238270
):

azure-quantum/tests/test_qiskit.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,23 @@ def test_qir_target_profile_from_deprecated_target_capability():
519519
assert "target_profile" not in input_params
520520

521521

522+
def test_generic_qir_backend_not_created_for_non_qir_target():
523+
"""Targets without a target_profile (e.g. Pasqal) must not receive an
524+
AzureGenericQirBackend — they use pulse-level input formats incompatible
525+
with QIR submission.
526+
527+
The default mock workspace already includes pasqal.sim.emu-tn with
528+
target_profile=None via seed_providers in mock_client.py.
529+
"""
530+
from qiskit.providers.exceptions import QiskitBackendNotFoundError
531+
532+
ws = create_default_workspace()
533+
provider = AzureQuantumProvider(workspace=ws)
534+
535+
with pytest.raises(QiskitBackendNotFoundError):
536+
provider.get_backend("pasqal.sim.emu-tn")
537+
538+
522539
def test_generic_qir_backend_created_for_unknown_workspace_target(
523540
monkeypatch: pytest.MonkeyPatch,
524541
):

0 commit comments

Comments
 (0)