Skip to content

Commit

Permalink
Add twirling options to SamplerV2 (#1583)
Browse files Browse the repository at this point in the history
* add twirling options to SamplerV2

* linter fixes

* style fixes

* add release note

* Update release-notes/unreleased/1557.feat.rst

Co-authored-by: Kevin Tian <[email protected]>

* update docstrings

* updated tests, included twirling option

* updated docstring from PR comment

* updated test_program_inputs

* Update qiskit_ibm_runtime/options/twirling_options.py

Co-authored-by: Ian Hincks <[email protected]>

* Update release-notes/unreleased/1557.feat.rst

Co-authored-by: Ian Hincks <[email protected]>

---------

Co-authored-by: Kevin Tian <[email protected]>
Co-authored-by: Ian Hincks <[email protected]>
Co-authored-by: Jessie Yu <[email protected]>
  • Loading branch information
4 people authored Apr 15, 2024
1 parent be51a45 commit 7c9979e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions qiskit_ibm_runtime/options/sampler_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .options import OptionsV2
from .utils import primitive_dataclass
from .dynamical_decoupling_options import DynamicalDecouplingOptions
from .twirling_options import TwirlingOptions


@primitive_dataclass
Expand All @@ -36,6 +37,8 @@ class SamplerOptions(OptionsV2):
execution: Execution time options. See :class:`ExecutionOptionsV2` for all available options.
twirling: Pauli twirling options. See :class:`TwirlingOptions` for all available options.
experimental: Experimental options.
"""

Expand All @@ -47,4 +50,5 @@ class SamplerOptions(OptionsV2):
execution: Union[SamplerExecutionOptionsV2, Dict] = Field(
default_factory=SamplerExecutionOptionsV2
)
twirling: Union[TwirlingOptions, Dict] = Field(default_factory=TwirlingOptions)
experimental: Union[UnsetType, dict] = Unset
4 changes: 2 additions & 2 deletions qiskit_ibm_runtime/options/twirling_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class TwirlingOptions:
Args:
enable_gates: Whether to apply 2-qubit gate twirling. Default: False.
enable_measure: Whether to enable twirling of expectation value measurements
in Estimator. Default: True.
enable_measure: Whether to enable twirling of measurements. Twirling will only be applied to
those measurement registers not involved within a conditional logic. Default: True.
num_randomizations: The number of random samples to use when twirling or
peforming sampled mitigation. If "auto", the value will be chosen automatically
Expand Down
2 changes: 2 additions & 0 deletions release-notes/unreleased/1557.feat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`SamplerV2` now supports twirling.
Twirling will only be applied to those measurement registers not involved within a conditional logic.
9 changes: 9 additions & 0 deletions test/unit/test_sampler_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def test_program_inputs(self):
environment = {"log_level": "INFO"}
dynamical_decoupling = {"enable": True, "sequence_type": "XX"}
execution = {"init_qubits": True, "rep_delay": 0.01}
twirling = {"enable_gates": True, "enable_measure": True, "strategy": "active-circuit"}

opt = SamplerOptions(
max_execution_time=100,
environment=environment,
simulator=simulator,
default_shots=1000,
dynamical_decoupling=dynamical_decoupling,
twirling=twirling,
execution=execution,
experimental={"foo": "bar", "execution": {"secret": 88}},
)
Expand All @@ -80,6 +82,11 @@ def test_program_inputs(self):
options = {
"default_shots": 1000,
"dynamical_decoupling": dynamical_decoupling,
"twirling": {
"enable_gates": True,
"enable_measure": True,
"strategy": "active-circuit",
},
"execution": execution,
"experimental": {"foo": "bar"},
"simulator": simulator,
Expand All @@ -97,6 +104,7 @@ def test_program_inputs(self):
{"execution": {"init_qubits": True, "meas_type": "avg_kerneled"}},
{"dynamical_decoupling": {"enable": True, "sequence_type": "XX"}},
{"environment": {"log_level": "ERROR"}},
{"twirling": {"enable_gates": True, "strategy": "active"}},
)
def test_init_options_with_dictionary(self, opts_dict):
"""Test initializing options with dictionaries."""
Expand All @@ -117,6 +125,7 @@ def test_init_options_with_dictionary(self, opts_dict):
"sequence_type": "XX",
"log_level": "INFO",
},
{"twirling": {"enable_gates": True, "strategy": "active"}},
)
def test_update_options(self, new_opts):
"""Test update method."""
Expand Down

0 comments on commit 7c9979e

Please sign in to comment.