Skip to content

Commit

Permalink
Add warning on provider-specific shots option. (#549)
Browse files Browse the repository at this point in the history
* Add warning when not using shots parameter.

* chore: changed warning verbiage + added missing test recordings

---------

Co-authored-by: ArturKamalov <v-akamalov@microsoft.com>
Co-authored-by: Kirill Komissarov <kikomiss@microsoft.com>
  • Loading branch information
3 people committed Jan 10, 2024
1 parent eccbfed commit 1bb1d96
Show file tree
Hide file tree
Showing 18 changed files with 9,031 additions and 163 deletions.
6 changes: 5 additions & 1 deletion azure-quantum/azure/quantum/qiskit/backends/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ def _get_input_params(self, options, shots: int = None) -> Dict[str, Any]:
if shots is not None and options_shots is not None:
warnings.warn(
f"Parameter 'shots' conflicts with the '{self.__class__._SHOTS_PARAM_NAME}' parameter. "
"Please provide only one option for setting shots. Defaulting to 'shots' parameter."
"Please, provide only one option for setting shots. Defaulting to 'shots' parameter."
)
final_shots = shots

elif shots is not None:
final_shots = shots
else:
warnings.warn(
f"Parameter '{self.__class__._SHOTS_PARAM_NAME}' is subject to change in future versions. "
"Please, use 'shots' parameter instead."
)
final_shots = options_shots

# If nothing is found, try to get from default values.
Expand Down
14 changes: 9 additions & 5 deletions azure-quantum/azure/quantum/target/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _get_entrypoint(input_data):
if shots is not None and input_params_shots is not None:
warnings.warn(
f"Parameter 'shots' conflicts with the '{self.__class__._SHOTS_PARAM_NAME}' field of the 'input_params' "
"parameter. Please provide only one option for setting shots. Defaulting to 'shots' parameter."
"parameter. Please, provide only one option for setting shots. Defaulting to 'shots' parameter."
)
final_shots = shots

Expand All @@ -242,6 +242,10 @@ def _get_entrypoint(input_data):
final_shots = shots
# if nothing, try a provider-specific option.
else:
warnings.warn(
f"Field '{self.__class__._SHOTS_PARAM_NAME}' from the 'input_params' parameter is subject to change in future versions. "
"Please, use 'shots' parameter instead."
)
final_shots = input_params_shots

if final_shots is not None:
Expand Down Expand Up @@ -294,15 +298,15 @@ def _determine_shots_or_deprecated_num_shots(
num_shots: int = None,
) -> int:
"""
This helper function checks if the deprecated 'num_shots' option is specified.
In earlier versions it was possible to pass this option to specify shots number for a job,
This helper function checks if the deprecated 'num_shots' parameter is specified.
In earlier versions it was possible to pass this parameter 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 and num_shots is not None:
warnings.warn(
"Both 'shots' and 'num_shots' options are specified. Defaulting to 'shots' option. "
"Please use 'shots' since 'num_shots' will be deprecated.",
"Both 'shots' and 'num_shots' parameters were specified. Defaulting to 'shots' parameter. "
"Please, use 'shots' since 'num_shots' will be deprecated.",
category=DeprecationWarning,
)
final_shots = shots
Expand Down
Loading

0 comments on commit 1bb1d96

Please sign in to comment.