Skip to content

Commit e6b450a

Browse files
authored
migrate QIR backends to V2 output format by default (#625)
* feat: upgrade QIR backends to V2 output format and populate memory field
1 parent e4a63c7 commit e6b450a

File tree

50 files changed

+7537
-5789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+7537
-5789
lines changed

azure-quantum/azure/quantum/qiskit/backends/backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def _azure_config(self) -> Dict[str, str]:
279279
"blob_name": "inputData",
280280
"content_type": "qir.v1",
281281
"input_data_format": "qir.v1",
282+
"output_data_format": "microsoft.quantum-results.v2",
282283
}
283284

284285
def run(

azure-quantum/azure/quantum/qiskit/backends/ionq.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from qiskit.providers import Options, Provider
2121

2222
from qiskit_ionq.helpers import (
23-
ionq_basis_gates,
2423
GATESET_MAP,
2524
qiskit_circ_to_ionq_circ,
2625
)
@@ -52,6 +51,25 @@
5251
_IONQ_SHOTS_INPUT_PARAM_NAME = "shots"
5352
_DEFAULT_SHOTS_COUNT = 500
5453

54+
IONQ_BASIS_GATES = [
55+
"measure",
56+
"m",
57+
"cx",
58+
"cz",
59+
"h",
60+
"reset",
61+
"rx",
62+
"ry",
63+
"rz",
64+
"s",
65+
"swap",
66+
"t",
67+
"x",
68+
"y",
69+
"z",
70+
"id",
71+
]
72+
5573
class IonQQirBackendBase(AzureQirBackend):
5674
"""Base class for interfacing with an IonQ QIR backend"""
5775

@@ -115,7 +133,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
115133
"local": False,
116134
"coupling_map": None,
117135
"description": "IonQ simulator on Azure Quantum",
118-
"basis_gates": ionq_basis_gates,
136+
"basis_gates": IONQ_BASIS_GATES,
119137
"memory": False,
120138
"n_qubits": 29,
121139
"conditional": False,
@@ -147,7 +165,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
147165
"local": False,
148166
"coupling_map": None,
149167
"description": "IonQ QPU on Azure Quantum",
150-
"basis_gates": ionq_basis_gates,
168+
"basis_gates": IONQ_BASIS_GATES,
151169
"memory": False,
152170
"n_qubits": 11,
153171
"conditional": False,
@@ -179,7 +197,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
179197
"local": False,
180198
"coupling_map": None,
181199
"description": "IonQ Aria QPU on Azure Quantum",
182-
"basis_gates": ionq_basis_gates,
200+
"basis_gates": IONQ_BASIS_GATES,
183201
"memory": False,
184202
"n_qubits": 23,
185203
"conditional": False,
@@ -211,7 +229,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
211229
"local": False,
212230
"coupling_map": None,
213231
"description": "IonQ Forte QPU on Azure Quantum",
214-
"basis_gates": ionq_basis_gates,
232+
"basis_gates": IONQ_BASIS_GATES,
215233
"memory": False,
216234
"n_qubits": 35,
217235
"conditional": False,

azure-quantum/azure/quantum/qiskit/backends/microsoft.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
from qiskit.providers.models import BackendConfiguration
1313
from qiskit.providers import Options, Provider
1414

15-
QIR_BASIS_GATES = [
15+
MICROSOFT_BASIS_GATES = [
1616
"measure",
1717
"m",
18-
"ccx",
1918
"cx",
2019
"cz",
2120
"h",
@@ -24,10 +23,8 @@
2423
"ry",
2524
"rz",
2625
"s",
27-
"sdg",
2826
"swap",
2927
"t",
30-
"tdg",
3128
"x",
3229
"y",
3330
"z",
@@ -93,7 +90,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
9390
"local": False,
9491
"coupling_map": None,
9592
"description": "Resource estimator on Azure Quantum",
96-
"basis_gates": QIR_BASIS_GATES,
93+
"basis_gates": MICROSOFT_BASIS_GATES,
9794
"memory": False,
9895
"n_qubits": 0xFFFFFFFFFFFFFFFF, # NOTE: maximum 64-bit unsigned value
9996
"conditional": True,

azure-quantum/azure/quantum/qiskit/backends/qci.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from qiskit.providers.models import BackendConfiguration
1616
from qiskit.providers import Options, Provider
1717

18-
QIR_BASIS_GATES = [
18+
QCI_BASIS_GATES = [
1919
"measure",
2020
"m",
2121
"barrier",
@@ -27,10 +27,8 @@
2727
"ry",
2828
"rz",
2929
"s",
30-
"sdg",
3130
"swap",
3231
"t",
33-
"tdg",
3432
"x",
3533
"y",
3634
"z",
@@ -110,7 +108,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
110108
"local": False,
111109
"coupling_map": None,
112110
"description": "QCI simulator on Azure Quantum",
113-
"basis_gates": QIR_BASIS_GATES,
111+
"basis_gates": QCI_BASIS_GATES,
114112
"memory": False,
115113
"n_qubits": 29,
116114
"conditional": True,
@@ -142,7 +140,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
142140
"local": False,
143141
"coupling_map": None,
144142
"description": "QCI QPU on Azure Quantum",
145-
"basis_gates": QIR_BASIS_GATES,
143+
"basis_gates": QCI_BASIS_GATES,
146144
"memory": False,
147145
"n_qubits": 11,
148146
"conditional": True,

azure-quantum/azure/quantum/qiskit/backends/quantinuum.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@
4040
"cx",
4141
"cz",
4242
"s",
43-
"sdg",
4443
"t",
45-
"tdg",
4644
"v",
4745
"vdg",
48-
"zz",
46+
"rzz",
4947
"measure",
5048
"reset",
5149
]
@@ -119,7 +117,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
119117
"coupling_map": None,
120118
"description": f"Quantinuum Syntax Checker on Azure Quantum",
121119
"basis_gates": QUANTINUUM_BASIS_GATES,
122-
"memory": False,
120+
"memory": True,
123121
"n_qubits": self._get_n_qubits(name),
124122
"conditional": False,
125123
"max_shots": None,
@@ -156,7 +154,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
156154
"coupling_map": None,
157155
"description": f"Quantinuum emulator on Azure Quantum",
158156
"basis_gates": QUANTINUUM_BASIS_GATES,
159-
"memory": False,
157+
"memory": True,
160158
"n_qubits": self._get_n_qubits(name),
161159
"conditional": False,
162160
"max_shots": None,
@@ -193,7 +191,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
193191
"coupling_map": None,
194192
"description": f"Quantinuum QPU on Azure Quantum",
195193
"basis_gates": QUANTINUUM_BASIS_GATES,
196-
"memory": False,
194+
"memory": True,
197195
"n_qubits": self._get_n_qubits(name),
198196
"conditional": False,
199197
"max_shots": 10000,

azure-quantum/azure/quantum/qiskit/backends/rigetti.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from qiskit.providers.models import BackendConfiguration
1313
from qiskit.providers import Options, Provider
1414

15-
QIR_BASIS_GATES = [
15+
RIGETTI_BASIS_GATES = [
1616
"measure",
1717
"m",
1818
"cx",
@@ -23,9 +23,7 @@
2323
"ry",
2424
"rz",
2525
"s",
26-
"sdg",
2726
"t",
28-
"tdg",
2927
"x",
3028
"y",
3129
"z",
@@ -85,8 +83,8 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
8583
"local": False,
8684
"coupling_map": None,
8785
"description": "Rigetti simulator on Azure Quantum",
88-
"basis_gates": QIR_BASIS_GATES,
89-
"memory": False,
86+
"basis_gates": RIGETTI_BASIS_GATES,
87+
"memory": True,
9088
"n_qubits": RigettiTarget.num_qubits(name),
9189
"conditional": False,
9290
"max_shots": 10000,
@@ -117,8 +115,8 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
117115
"local": False,
118116
"coupling_map": None,
119117
"description": "Rigetti QPU on Azure Quantum",
120-
"basis_gates": QIR_BASIS_GATES,
121-
"memory": False,
118+
"basis_gates": RIGETTI_BASIS_GATES,
119+
"memory": True,
122120
"n_qubits": RigettiTarget.num_qubits(name),
123121
"conditional": False,
124122
"max_shots": 10000,

azure-quantum/azure/quantum/qiskit/job.py

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -273,45 +273,32 @@ def _format_unknown_results(self):
273273

274274
def _translate_microsoft_v2_results(self):
275275
""" Translate Microsoft's batching job results histograms into a format that can be consumed by qiskit libraries. """
276-
az_result = self._azure_job.get_results()
277-
278-
if not "DataFormat" in az_result:
279-
raise ValueError("DataFormat missing from Job results")
280-
281-
if not "Results" in az_result:
282-
raise ValueError("Results missing from Job results")
283-
276+
az_result_histogram = self._azure_job.get_results_histogram()
277+
az_result_shots = self._azure_job.get_results_shots()
278+
279+
# If it is a non-batched result, format to be in batch format so we can have one code path
280+
if isinstance(az_result_histogram, dict):
281+
az_result_histogram = [az_result_histogram]
282+
az_result_shots = [az_result_shots]
283+
284284
histograms = []
285-
results = az_result["Results"]
286-
for circuit_results in results:
285+
286+
for (histogram, shots) in zip(az_result_histogram, az_result_shots):
287287
counts = {}
288288
probabilities = {}
289289

290-
if not "TotalCount" in circuit_results:
291-
raise ValueError("TotalCount missing from Job results")
290+
total_count = len(shots)
292291

293-
total_count = circuit_results["TotalCount"]
294-
295-
if total_count <= 0:
296-
raise ValueError("TotalCount must be a positive non-zero integer")
297-
298-
if not "Histogram" in circuit_results:
299-
raise ValueError("Histogram missing from Job results")
300-
301-
histogram = circuit_results["Histogram"]
302-
for result in histogram:
303-
if not "Display" in result:
304-
raise ValueError("Dispaly missing from histogram result")
305-
306-
if not "Count" in result:
307-
raise ValueError("Count missing from histogram result")
308-
309-
bitstring = AzureQuantumJob._qir_to_qiskit_bitstring(result["Display"])
310-
count = result["Count"]
292+
for (display, result) in histogram.items():
293+
bitstring = AzureQuantumJob._qir_to_qiskit_bitstring(display)
294+
count = result["count"]
311295
probability = count / total_count
312296
counts[bitstring] = count
313297
probabilities[bitstring] = probability
314-
histograms.append((total_count, {"counts": counts, "probabilities": probabilities}))
298+
299+
formatted_shots = [AzureQuantumJob._qir_to_qiskit_bitstring(shot) for shot in shots]
300+
301+
histograms.append((total_count, {"counts": counts, "probabilities": probabilities, "memory": formatted_shots}))
315302
return histograms
316303

317304
def _get_entry_point_names(self):

0 commit comments

Comments
 (0)