Skip to content

Commit 1842431

Browse files
Align all providers to use "shots" and remove duplicate "count"/"shots" input parameter (#719)
* Align most QIR providers to "shots" parameter * Fix unit tests * Remove deprecation message if user still provides 'count' (#720) * Fix tests * Remove count param handling for ionq and qci * Revert "Fix tests" This reverts commit e983797. --------- Co-authored-by: Zulfat Nutfullin <rigidit@users.noreply.github.com>
1 parent 859d18f commit 1842431

File tree

9 files changed

+14
-84
lines changed

9 files changed

+14
-84
lines changed

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

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class AzureBackendBase(Backend, SessionHost):
290290

291291
# Name of the provider's input parameter which specifies number of shots for a submitted job.
292292
# If None, backend will not pass this input parameter.
293-
_SHOTS_PARAM_NAME = None
293+
_SHOTS_PARAM_NAME = "shots"
294294

295295
@abstractmethod
296296
def __init__(
@@ -451,12 +451,6 @@ def _get_input_params(self, options: Dict[str, Any], shots: int = None) -> Dict[
451451
if final_shots is None:
452452
final_shots = input_params.get(self.__class__._SHOTS_PARAM_NAME)
453453

454-
# Also add all possible shots options into input_params to make sure
455-
# that all backends covered.
456-
# TODO: Double check all backends for shots options in order to remove this extra check.
457-
input_params["shots"] = final_shots
458-
input_params["count"] = final_shots
459-
460454
# Safely removing "shots" and "count" from options as they will be passed in input_params now.
461455
_ = options.pop("shots", None)
462456
_ = options.pop("count", None)
@@ -830,29 +824,3 @@ def run(
830824
logger.info(input_data)
831825

832826
return job
833-
834-
def _get_shots_or_deprecated_count_input_param(
835-
param_name: str,
836-
shots: int = None,
837-
count: int = None,
838-
) -> Optional[int]:
839-
"""
840-
This helper function checks if the deprecated 'count' option is specified.
841-
In earlier versions it was possible to pass this option to specify shots number for a job,
842-
but now we only check for it for compatibility reasons.
843-
"""
844-
845-
final_shots = None
846-
847-
if shots is not None:
848-
final_shots = shots
849-
850-
elif count is not None:
851-
final_shots = count
852-
warnings.warn(
853-
"The 'count' parameter will be deprecated. "
854-
f"Please, use '{param_name}' parameter instead.",
855-
category=DeprecationWarning,
856-
)
857-
858-
return final_shots

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
AzureBackendConfig,
1616
AzureQirBackend,
1717
_ensure_backend_config,
18-
_get_shots_or_deprecated_count_input_param,
1918
)
2019
from qiskit.providers import Options
2120

@@ -84,18 +83,7 @@ def run(
8483
shots: int = None,
8584
**options,
8685
) -> AzureQuantumJob:
87-
88-
# In earlier versions, backends for all providers accepted the 'count' option,
89-
# but now we accept it only for a compatibility reasons and do not recommend using it.
90-
count = options.pop("count", None)
91-
92-
final_shots = _get_shots_or_deprecated_count_input_param(
93-
param_name=self.__class__._SHOTS_PARAM_NAME,
94-
shots=shots,
95-
count=count,
96-
)
97-
98-
return super().run(run_input, shots=final_shots, **options)
86+
return super().run(run_input, shots=shots, **options)
9987

10088

10189
class IonQSimulatorQirBackend(IonQQirBackendBase):
@@ -207,18 +195,7 @@ def run(
207195
shots: int = None,
208196
**options,
209197
) -> AzureQuantumJob:
210-
211-
# In earlier versions, backends for all providers accepted the 'count' option,
212-
# but now we accept it only for a compatibility reasons and do not recommend using it.
213-
count = options.pop("count", None)
214-
215-
final_shots = _get_shots_or_deprecated_count_input_param(
216-
param_name=self.__class__._SHOTS_PARAM_NAME,
217-
shots=shots,
218-
count=count,
219-
)
220-
221-
return super().run(run_input, shots=final_shots, **options)
198+
return super().run(run_input, shots=shots, **options)
222199

223200
@classmethod
224201
def _default_options(cls):

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
AzureBackendConfig,
1212
AzureQirBackend,
1313
_ensure_backend_config,
14-
_get_shots_or_deprecated_count_input_param,
1514
)
1615
from qiskit.providers import Options
1716
from qsharp import TargetProfile
@@ -66,18 +65,7 @@ def run(
6665
shots: int = None,
6766
**options,
6867
) -> AzureQuantumJob:
69-
70-
# In earlier versions, backends for all providers accepted the 'count' option,
71-
# but now we accept it only for a compatibility reasons and do not recommend using it.
72-
count = options.pop("count", None)
73-
74-
final_shots = _get_shots_or_deprecated_count_input_param(
75-
param_name=self.__class__._SHOTS_PARAM_NAME,
76-
shots=shots,
77-
count=count,
78-
)
79-
80-
return super().run(run_input, shots=final_shots, **options)
68+
return super().run(run_input, shots=shots, **options)
8169

8270

8371
class QCISimulatorBackend(QCIBackend):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _get_n_qubits(name):
6767
UserWarning(f"Number of qubits not known for target {name}. Defaulting to 20."))
6868
return 20
6969

70-
_QUANTINUUM_COUNT_INPUT_PARAM_NAME = "count"
70+
_QUANTINUUM_COUNT_INPUT_PARAM_NAME = "shots"
7171
_DEFAULT_SHOTS_COUNT = 500
7272

7373
class QuantinuumQirBackendBase(AzureQirBackend):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class RigettiBackend(AzureQirBackend):
2727
"""Base class for interfacing with a Rigetti backend in Azure Quantum"""
2828

29-
_SHOTS_PARAM_NAME = "count"
29+
_SHOTS_PARAM_NAME = "shots"
3030

3131
@abstractmethod
3232
def __init__(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ def queue_position(self):
115115
return None
116116

117117
def _shots_count(self):
118-
# Some providers use 'count', some other 'shots', give preference to 'count':
118+
# Some providers use 'count', some other 'shots', give preference to 'shots':
119119
input_params = self._azure_job.details.input_params
120120
options = self.backend().options
121121
shots = \
122-
input_params["count"] if "count" in input_params else \
123122
input_params["shots"] if "shots" in input_params else \
124-
options.get("count") if "count" in vars(options) else \
125-
options.get("shots")
123+
input_params["count"] if "count" in input_params else \
124+
options.get("shots") if "shots" in vars(options) else \
125+
options.get("count")
126126

127127
return shots
128128

azure-quantum/azure/quantum/target/quantinuum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Quantinuum(Target):
2222
"quantinuum.sim.h2-2e",
2323
)
2424

25-
_SHOTS_PARAM_NAME = "count"
25+
_SHOTS_PARAM_NAME = "shots"
2626

2727
def __init__(
2828
self,

azure-quantum/azure/quantum/target/rigetti/target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class Rigetti(Target):
130130

131131
target_names = tuple(target.value for target in RigettiTarget)
132132

133-
_SHOTS_PARAM_NAME = "count"
133+
_SHOTS_PARAM_NAME = "shots"
134134

135135
def __init__(
136136
self,

azure-quantum/tests/test_qiskit.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,8 @@ def test_quantinuum_request_construction_offline(monkeypatch: pytest.MonkeyPatch
254254
provider = AzureQuantumProvider(workspace=ws)
255255
backend = QuantinuumEmulatorBackend(name="quantinuum.sim.h2-1e", provider=provider)
256256

257-
# Quantinuum uses `count` as the provider-specific shots input param.
258257
with pytest.warns(UserWarning, match="conflicts"):
259-
input_params = backend._get_input_params({"count": 999}, shots=123)
258+
input_params = backend._get_input_params({"shots": 999}, shots=123)
260259

261260
job = backend._run(
262261
job_name="offline-quantinuum",
@@ -277,7 +276,6 @@ def test_quantinuum_request_construction_offline(monkeypatch: pytest.MonkeyPatch
277276
assert details.target == "quantinuum.sim.h2-1e"
278277
assert details.input_data_format == "honeywell.openqasm.v1"
279278
assert details.output_data_format == "honeywell.quantum-results.v1"
280-
assert details.input_params["count"] == 123
281279
assert details.input_params["shots"] == 123
282280
assert details.metadata.get("foo") == "bar"
283281
assert details.metadata.get("meta") == "value"
@@ -295,7 +293,7 @@ def test_rigetti_request_construction_offline(monkeypatch: pytest.MonkeyPatch):
295293
backend = RigettiSimulatorBackend(name=RigettiTarget.QVM.value, provider=provider)
296294

297295
with pytest.warns(UserWarning, match="subject to change"):
298-
input_params = backend._get_input_params({"count": 10}, shots=None)
296+
input_params = backend._get_input_params({"shots": 10}, shots=None)
299297

300298
job = backend._run(
301299
job_name="offline-rigetti",
@@ -315,7 +313,6 @@ def test_rigetti_request_construction_offline(monkeypatch: pytest.MonkeyPatch):
315313
assert details.provider_id == "rigetti"
316314
assert details.input_data_format == "qir.v1"
317315
assert details.output_data_format == "microsoft.quantum-results.v2"
318-
assert details.input_params["count"] == 10
319316
assert details.input_params["shots"] == 10
320317
assert details.metadata.get("foo") == "bar"
321318

0 commit comments

Comments
 (0)