Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use attribute docstrings for options #1897

Merged
merged 26 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2996e95
Use attribute docstrings for options
kt474 Aug 29, 2024
b9abfe6
Merge branch 'main' into update-option-docstrings
ptristan3 Sep 3, 2024
bc63b71
Merge branch 'main' into update-option-docstrings
kt474 Sep 3, 2024
77296fc
Merge branch 'main' into update-option-docstrings
kt474 Sep 4, 2024
213d97b
Merge branch 'main' into update-option-docstrings
ptristan3 Sep 9, 2024
7756849
Merge branch 'main' into update-option-docstrings
ptristan3 Sep 16, 2024
3ee79cf
Merge branch 'main' into update-option-docstrings
kt474 Sep 17, 2024
bba077f
Merge branch 'main' into update-option-docstrings
kt474 Sep 19, 2024
3544a71
Merge branch 'main' into update-option-docstrings
kt474 Sep 24, 2024
b668d97
Merge branch 'main' into update-option-docstrings
kt474 Sep 26, 2024
d569f56
formatting
kt474 Sep 26, 2024
7a1aea0
formatting again
kt474 Sep 26, 2024
0775a6d
Update qiskit_ibm_runtime/options/estimator_options.py
kt474 Sep 27, 2024
cf314bb
Update qiskit_ibm_runtime/options/estimator_options.py
kt474 Sep 27, 2024
bc2e170
Update qiskit_ibm_runtime/options/estimator_options.py
kt474 Sep 27, 2024
a1d12c1
Update qiskit_ibm_runtime/options/layer_noise_learning_options.py
kt474 Sep 27, 2024
c9fa219
Update qiskit_ibm_runtime/options/resilience_options.py
kt474 Sep 27, 2024
6c76ff0
Update qiskit_ibm_runtime/options/resilience_options.py
kt474 Sep 27, 2024
1461453
Update qiskit_ibm_runtime/options/simulator_options.py
kt474 Sep 27, 2024
bbbefc8
Update qiskit_ibm_runtime/options/resilience_options.py
kt474 Sep 27, 2024
4848ca4
Update qiskit_ibm_runtime/options/resilience_options.py
kt474 Sep 27, 2024
17228ed
Update qiskit_ibm_runtime/options/resilience_options.py
kt474 Sep 27, 2024
9c7a270
Update qiskit_ibm_runtime/options/resilience_options.py
kt474 Sep 27, 2024
02dc64c
Update qiskit_ibm_runtime/options/resilience_options.py
kt474 Sep 27, 2024
fbb5d81
Remove comma
kt474 Sep 27, 2024
1d0c6f0
Merge branch 'main' into update-option-docstrings
kt474 Sep 30, 2024
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
51 changes: 28 additions & 23 deletions qiskit_ibm_runtime/options/dynamical_decoupling_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,37 @@

@primitive_dataclass
class DynamicalDecouplingOptions:
"""Options for dynamical decoupling (DD).
"""Options for dynamical decoupling (DD)."""

Args:
enable: Whether to enable DD as specified by the other options in this class.
Default: False.

sequence_type: Which dynamical decoupling sequence to use. Default: "XX".

* ``"XX"``: use the sequence ``tau/2 - (+X) - tau - (+X) - tau/2``
* ``"XpXm"``: use the sequence ``tau/2 - (+X) - tau - (-X) - tau/2``
* ``"XY4"``: : use the sequence
``tau/2 - (+X) - tau - (+Y) - tau (-X) - tau - (-Y) - tau/2``

extra_slack_distribution: Where to put extra timing delays due to rounding issues.
Rounding issues arise because the discrete time step ``dt`` of the system cannot
be divided. This option takes following values. Default: "middle".

* ``"middle"``: Put the extra slack to the interval at the middle of the sequence.
* ``"edges"``: Divide the extra slack as evenly as possible into intervals at
beginning and end of the sequence.
enable: Union[UnsetType, bool] = Unset
r"""Whether to enable DD as specified by the other options in this class.

scheduling_method: Whether to schedule gates as soon as ("asap") or
as late as ("alap") possible. Default: "alap".
Default: False.
"""

enable: Union[UnsetType, bool] = Unset
sequence_type: Union[UnsetType, Literal["XX", "XpXm", "XY4"]] = Unset
r"""Which dynamical decoupling sequence to use.

Default: "XX".

* ``"XX"``: use the sequence ``tau/2 - (+X) - tau - (+X) - tau/2``
* ``"XpXm"``: use the sequence ``tau/2 - (+X) - tau - (-X) - tau/2``
* ``"XY4"``: : use the sequence
``tau/2 - (+X) - tau - (+Y) - tau (-X) - tau - (-Y) - tau/2``
"""
extra_slack_distribution: Union[UnsetType, Literal["middle", "edges"]] = Unset
r"""Where to put extra timing delays due to rounding issues.
Rounding issues arise because the discrete time step ``dt`` of the system cannot
be divided. This option takes following values.

Default: "middle".

* ``"middle"``: Put the extra slack to the interval at the middle of the sequence.
* ``"edges"``: Divide the extra slack as evenly as possible into intervals at
beginning and end of the sequence.
"""
scheduling_method: Union[UnsetType, Literal["alap", "asap"]] = Unset
r"""Whether to schedule gates as soon as ("asap") or
as late as ("alap") possible.

Default: "alap".
"""
38 changes: 19 additions & 19 deletions qiskit_ibm_runtime/options/environment_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@

@primitive_dataclass
class EnvironmentOptions:
"""Options related to the execution environment.
"""Options related to the execution environment."""

Args:
log_level: logging level to set in the execution environment. The valid
log levels are: ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, and ``CRITICAL``.
Default: ``WARNING``.

callback: Callback function to be invoked for any interim results and final result.
The callback function will receive 2 positional parameters:

1. Job ID
2. Job result.
log_level: LogLevelType = "WARNING"
r"""logging level to set in the execution environment. The valid
log levels are: ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, and ``CRITICAL``.

Default: ``None``.
Default: ``WARNING``.
"""
callback: Optional[Callable] = None
r"""Callback function to be invoked for any interim results and final result.
The callback function will receive 2 positional parameters:

job_tags: Tags to be assigned to the job. The tags can subsequently be used
as a filter in the :meth:`qiskit_ibm_runtime.qiskit_runtime_service.jobs()`
function call. Default: ``None``.
1. Job ID
2. Job result.

private: Boolean value for marking jobs as private.
Default: ``None``.
"""

log_level: LogLevelType = "WARNING"
callback: Optional[Callable] = None
job_tags: Optional[List] = None
r"""Tags to be assigned to the job. The tags can subsequently be used
as a filter in the :meth:`qiskit_ibm_runtime.qiskit_runtime_service.jobs()`
function call.

Default: ``None``.
"""
private: Optional[bool] = False
r"""Boolean value for marking jobs as private."""
125 changes: 64 additions & 61 deletions qiskit_ibm_runtime/options/estimator_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,86 +34,89 @@

@primitive_dataclass
class EstimatorOptions(OptionsV2):
"""Options for V2 Estimator.
"""Options for V2 Estimator."""

Args:
default_precision: The default precision to use for any PUB or ``run()``
call that does not specify one.
Each estimator pub can specify its own precision. If the ``run()`` method
is given a precision, then that value is used for all PUBs in the ``run()``
call that do not specify their own. Default: 0.015625 (1 / sqrt(4096)).

default_shots: The total number of shots to use per circuit per configuration.

.. note::
If set, this value overrides :attr:`~default_precision`.

A configuration is a combination of a specific parameter value binding set and a
physical measurement basis. A physical measurement basis groups together some
collection of qubit-wise commuting observables for some specific circuit/parameter
value set to create a single measurement with basis rotations that is inserted into
hardware executions.

If twirling is enabled, the value of this option will be divided over circuit,
randomizations, with a smaller number of shots per randomization. See the
:attr:`~twirling` options.

Default: ``None``.

optimization_level: (DEPRECATED) How much optimization to perform on the circuits.
Higher levels generate more optimized circuits,
at the expense of longer processing times.

* 0: no optimization
* 1: light optimization

Default: 0.

resilience_level: How much resilience to build against errors.
Higher levels generate more accurate results,
at the expense of longer processing times.
# Sadly we cannot use pydantic's built in validation because it won't work on Unset.
default_precision: Union[UnsetType, float] = Unset
r"""The default precision to use for any PUB or ``run()``
call that does not specify one.
Each estimator pub can specify its own precision. If the ``run()`` method
kt474 marked this conversation as resolved.
Show resolved Hide resolved
is given a precision, then that value is used for all PUBs in the ``run()``
call that do not specify their own.

Default: 0.015625 (1 / sqrt(4096)).
"""
default_shots: Union[UnsetType, int, None] = Unset
r"""The total number of shots to use per circuit per configuration.

* 0: No mitigation.
* 1: Minimal mitigation costs. Mitigate error associated with readout errors.
* 2: Medium mitigation costs. Typically reduces bias in estimators but
is not guaranteed to be zero bias.
.. note::
If set, this value overrides :attr:`~default_precision`.

Refer to the
`Configure error mitigation for Qiskit Runtime
<https://docs.quantum.ibm.com/guides/configure-error-mitigation>`_.
for more information about the error mitigation methods used at each level.
A configuration is a combination of a specific parameter value binding set and a
physical measurement basis. A physical measurement basis groups together some
collection of qubit-wise commuting observables for some specific circuit/parameter
value set to create a single measurement with basis rotations that is inserted into
hardware executions.

Default: 1.
If twirling is enabled, the value of this option will be divided over circuit,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"divided over circuit, randomizations," reads oddly to me but maybe it is codespeak?

randomizations, with a smaller number of shots per randomization. See the
:attr:`~twirling` options.

seed_estimator: Seed used to control sampling. Default: ``None``.
Default: ``None``.
"""
optimization_level: Union[UnsetType, int] = Unset
r"""(DEPRECATED) How much optimization to perform on the circuits.
Higher levels generate more optimized circuits,
at the expense of longer processing times.

dynamical_decoupling: Suboptions for dynamical decoupling. See
:class:`DynamicalDecouplingOptions` for all available options.
* 0: no optimization
* 1: light optimization

resilience: Advanced resilience options to fine tune the resilience strategy.
See :class:`ResilienceOptionsV2` for all available options.
Default: 0.
"""
resilience_level: Union[UnsetType, int] = Unset
r"""How much resilience to build against errors.
Higher levels generate more accurate results,
at the expense of longer processing times.

execution: Execution time options. See :class:`ExecutionOptionsV2` for all available options.
* 0: No mitigation.
* 1: Minimal mitigation costs. Mitigate error associated with readout errors.
* 2: Medium mitigation costs. Typically reduces bias in estimators but
is not guaranteed to be zero bias.

twirling: Pauli twirling options. See :class:`TwirlingOptions` for all available options.
Refer to the
`Configure error mitigation for Qiskit Runtime
<https://docs.quantum.ibm.com/guides/configure-error-mitigation>`_.
kt474 marked this conversation as resolved.
Show resolved Hide resolved
for more information about the error mitigation methods used at each level.

experimental: Experimental options. These options are subject to change without notification, and
stability is not guaranteed.
Default: 1.
"""

# Sadly we cannot use pydantic's built in validation because it won't work on Unset.
default_precision: Union[UnsetType, float] = Unset
default_shots: Union[UnsetType, int, None] = Unset
optimization_level: Union[UnsetType, int] = Unset
resilience_level: Union[UnsetType, int] = Unset
seed_estimator: Union[UnsetType, int] = Unset
r"""Seed used to control sampling.

Default: ``None``.
"""
dynamical_decoupling: Union[DynamicalDecouplingOptions, Dict] = Field(
default_factory=DynamicalDecouplingOptions
)
r"""Suboptions for dynamical decoupling. See
:class:`DynamicalDecouplingOptions` for all available options.
"""
resilience: Union[ResilienceOptionsV2, Dict] = Field(default_factory=ResilienceOptionsV2)
r"""Advanced resilience options to fine tune the resilience strategy.
kt474 marked this conversation as resolved.
Show resolved Hide resolved
See :class:`ResilienceOptionsV2` for all available options.
"""
execution: Union[ExecutionOptionsV2, Dict] = Field(default_factory=ExecutionOptionsV2)
r"""Execution time options. See :class:`ExecutionOptionsV2` for all available options.
"""
twirling: Union[TwirlingOptions, Dict] = Field(default_factory=TwirlingOptions)
r"""
Pauli twirling options. See :class:`TwirlingOptions` for all available options.
"""
experimental: Union[UnsetType, dict] = Unset
r"""Experimental options. These options are subject to change without notification, and
stability is not guaranteed.
"""

_gt0 = make_constraint_validator("default_precision", gt=0)
_ge0 = make_constraint_validator("default_shots", ge=0)
Expand Down
53 changes: 30 additions & 23 deletions qiskit_ibm_runtime/options/layer_noise_learning_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,42 @@ class LayerNoiseLearningOptions:
These options are only used when the resilience level or options specify a
technique that requires layer noise learning.

Args:
max_layers_to_learn: The max number of unique layers to learn.
A ``None`` value indicates that there is no limit.
If there are more unique layers present, then some layers will not be learned or
mitigated. The learned layers are prioritized based on the number of times they
occur in a set of run estimator PUBs, and for equally occurring layers are
further sorted by the number of two-qubit gates in the layer. Default: 4.

shots_per_randomization: The total number of shots to use per random learning circuit.
A learning circuit is a random circuit at a specific learning depth with a specific
measurement basis that is executed on hardware. Default: 128.

num_randomizations: The number of random circuits to use per learning circuit
configuration. A configuration is a measurement basis and depth setting.
For example, if your experiment has six depths, and nine required measurement bases,
then setting this value to 32 will result in a total of ``32 * 9 * 6`` circuits
that need to be executed (at :attr:`~shots_per_randomization` each). Default: 32.

layer_pair_depths: The circuit depths (measured in number of pairs) to use in learning
experiments. Pairs are used as the unit because we exploit the order-2 nature of
our entangling gates in the noise learning implementation. A value of ``3``
would correspond to 6 layers of the layer of interest, for example.
Default: (0, 1, 2, 4, 16, 32).
"""

max_layers_to_learn: Union[UnsetType, int, None] = Unset
r"""The max number of unique layers to learn.
A ``None`` value indicates that there is no limit.
If there are more unique layers present, then some layers will not be learned or
mitigated. The learned layers are prioritized based on the number of times they
occur in a set of run estimator PUBs, and for equally occurring layers are
kt474 marked this conversation as resolved.
Show resolved Hide resolved
further sorted by the number of two-qubit gates in the layer.

Default: 4.
"""
shots_per_randomization: Union[UnsetType, int] = Unset
r"""The total number of shots to use per random learning circuit.
A learning circuit is a random circuit at a specific learning depth with a specific
measurement basis that is executed on hardware.

Default: 128.
"""
num_randomizations: Union[UnsetType, int] = Unset
r"""The number of random circuits to use per learning circuit
configuration. A configuration is a measurement basis and depth setting.
For example, if your experiment has six depths, and nine required measurement bases,
then setting this value to 32 will result in a total of ``32 * 9 * 6`` circuits
that need to be executed (at :attr:`~shots_per_randomization` each).

Default: 32.
"""
layer_pair_depths: Union[UnsetType, List[int]] = Unset
r"""The circuit depths (measured in number of pairs) to use in learning
experiments. Pairs are used as the unit because we exploit the order-2 nature of
our entangling gates in the noise learning implementation. A value of ``3``
would correspond to 6 layers of the layer of interest, for example.

Default: (0, 1, 2, 4, 16, 32).
"""

_ge0 = make_constraint_validator("max_layers_to_learn", ge=0)
_ge1 = make_constraint_validator("shots_per_randomization", "num_randomizations", ge=1)
Expand Down
18 changes: 11 additions & 7 deletions qiskit_ibm_runtime/options/measure_noise_learning_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ class MeasureNoiseLearningOptions:
These options are only used when the resilience level or options specify a
technique that requires measurement noise learning.

Args:
num_randomizations: The number of random circuits to draw for the measurement
learning experiment. Default: 32.

shots_per_randomization: The number of shots to use for the learning experiment
per random circuit. If "auto", the value will be chosen automatically
based on the input PUBs. Default: "auto".
"""

num_randomizations: Union[UnsetType, int] = Unset
r"""The number of random circuits to draw for the measurement
learning experiment.

Default: 32.
"""
shots_per_randomization: Union[UnsetType, int, Literal["auto"]] = Unset
r"""The number of shots to use for the learning experiment
per random circuit. If "auto", the value will be chosen automatically
based on the input PUBs.

Default: "auto".
"""

_ge1 = make_constraint_validator("num_randomizations", "shots_per_randomization", ge=1)
Loading