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

Add twirling options to SamplerV2 #1583

Merged
merged 16 commits into from
Apr 15, 2024
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
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