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
34 changes: 1 addition & 33 deletions azure-quantum/azure/quantum/qiskit/backends/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class AzureBackendBase(Backend, SessionHost):

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

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

# Also add all possible shots options into input_params to make sure
# that all backends covered.
# TODO: Double check all backends for shots options in order to remove this extra check.
input_params["shots"] = final_shots
input_params["count"] = final_shots

# Safely removing "shots" and "count" from options as they will be passed in input_params now.
_ = options.pop("shots", None)
_ = options.pop("count", None)
Expand Down Expand Up @@ -830,29 +824,3 @@ def run(
logger.info(input_data)

return job

def _get_shots_or_deprecated_count_input_param(
param_name: str,
shots: int = None,
count: int = None,
) -> Optional[int]:
"""
This helper function checks if the deprecated 'count' option is specified.
In earlier versions it was possible to pass this option to specify shots number for a job,
but now we only check for it for compatibility reasons.
"""

final_shots = None

if shots is not None:
final_shots = shots

elif count is not None:
final_shots = count
warnings.warn(
"The 'count' parameter will be deprecated. "
f"Please, use '{param_name}' parameter instead.",
category=DeprecationWarning,
)

return final_shots
27 changes: 2 additions & 25 deletions azure-quantum/azure/quantum/qiskit/backends/ionq.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
AzureBackendConfig,
AzureQirBackend,
_ensure_backend_config,
_get_shots_or_deprecated_count_input_param,
)
from qiskit.providers import Options

Expand Down Expand Up @@ -84,18 +83,7 @@ def run(
shots: int = None,
**options,
) -> AzureQuantumJob:

# In earlier versions, backends for all providers accepted the 'count' option,
# but now we accept it only for a compatibility reasons and do not recommend using it.
count = options.pop("count", None)

final_shots = _get_shots_or_deprecated_count_input_param(
param_name=self.__class__._SHOTS_PARAM_NAME,
shots=shots,
count=count,
)

return super().run(run_input, shots=final_shots, **options)
return super().run(run_input, shots=shots, **options)


class IonQSimulatorQirBackend(IonQQirBackendBase):
Expand Down Expand Up @@ -207,18 +195,7 @@ def run(
shots: int = None,
**options,
) -> AzureQuantumJob:

# In earlier versions, backends for all providers accepted the 'count' option,
# but now we accept it only for a compatibility reasons and do not recommend using it.
count = options.pop("count", None)

final_shots = _get_shots_or_deprecated_count_input_param(
param_name=self.__class__._SHOTS_PARAM_NAME,
shots=shots,
count=count,
)

return super().run(run_input, shots=final_shots, **options)
return super().run(run_input, shots=shots, **options)

@classmethod
def _default_options(cls):
Expand Down
14 changes: 1 addition & 13 deletions azure-quantum/azure/quantum/qiskit/backends/qci.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
AzureBackendConfig,
AzureQirBackend,
_ensure_backend_config,
_get_shots_or_deprecated_count_input_param,
)
from qiskit.providers import Options
from qsharp import TargetProfile
Expand Down Expand Up @@ -66,18 +65,7 @@ def run(
shots: int = None,
**options,
) -> AzureQuantumJob:

# In earlier versions, backends for all providers accepted the 'count' option,
# but now we accept it only for a compatibility reasons and do not recommend using it.
count = options.pop("count", None)

final_shots = _get_shots_or_deprecated_count_input_param(
param_name=self.__class__._SHOTS_PARAM_NAME,
shots=shots,
count=count,
)

return super().run(run_input, shots=final_shots, **options)
return super().run(run_input, shots=shots, **options)


class QCISimulatorBackend(QCIBackend):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _get_n_qubits(name):
UserWarning(f"Number of qubits not known for target {name}. Defaulting to 20."))
return 20

_QUANTINUUM_COUNT_INPUT_PARAM_NAME = "count"
_QUANTINUUM_COUNT_INPUT_PARAM_NAME = "shots"
_DEFAULT_SHOTS_COUNT = 500

class QuantinuumQirBackendBase(AzureQirBackend):
Expand Down
2 changes: 1 addition & 1 deletion azure-quantum/azure/quantum/qiskit/backends/rigetti.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class RigettiBackend(AzureQirBackend):
"""Base class for interfacing with a Rigetti backend in Azure Quantum"""

_SHOTS_PARAM_NAME = "count"
_SHOTS_PARAM_NAME = "shots"

@abstractmethod
def __init__(
Expand Down
8 changes: 4 additions & 4 deletions azure-quantum/azure/quantum/qiskit/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ def queue_position(self):
return None

def _shots_count(self):
# Some providers use 'count', some other 'shots', give preference to 'count':
# Some providers use 'count', some other 'shots', give preference to 'shots':
input_params = self._azure_job.details.input_params
options = self.backend().options
shots = \
input_params["count"] if "count" in input_params else \
input_params["shots"] if "shots" in input_params else \
options.get("count") if "count" in vars(options) else \
options.get("shots")
input_params["count"] if "count" in input_params else \
options.get("shots") if "shots" in vars(options) else \
options.get("count")

return shots

Expand Down
2 changes: 1 addition & 1 deletion azure-quantum/azure/quantum/target/quantinuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Quantinuum(Target):
"quantinuum.sim.h2-2e",
)

_SHOTS_PARAM_NAME = "count"
_SHOTS_PARAM_NAME = "shots"

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion azure-quantum/azure/quantum/target/rigetti/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Rigetti(Target):

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

_SHOTS_PARAM_NAME = "count"
_SHOTS_PARAM_NAME = "shots"

def __init__(
self,
Expand Down
7 changes: 2 additions & 5 deletions azure-quantum/tests/test_qiskit.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,8 @@ def test_quantinuum_request_construction_offline(monkeypatch: pytest.MonkeyPatch
provider = AzureQuantumProvider(workspace=ws)
backend = QuantinuumEmulatorBackend(name="quantinuum.sim.h2-1e", provider=provider)

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

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

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

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

Expand Down
Loading