From dc8235074a67c8d7c0aed6b840f155d537189e2d Mon Sep 17 00:00:00 2001 From: ptristan Date: Wed, 3 Apr 2024 11:45:56 -0300 Subject: [PATCH 01/11] add twirling options to SamplerV2 --- qiskit_ibm_runtime/options/sampler_options.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qiskit_ibm_runtime/options/sampler_options.py b/qiskit_ibm_runtime/options/sampler_options.py index 54ea3dbe8..923072c17 100644 --- a/qiskit_ibm_runtime/options/sampler_options.py +++ b/qiskit_ibm_runtime/options/sampler_options.py @@ -16,6 +16,7 @@ from pydantic import Field +from . import TwirlingOptions from .utils import Dict, Unset, UnsetType from .execution_options import ExecutionOptionsV2 from .options import OptionsV2 @@ -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. """ @@ -45,4 +48,5 @@ class SamplerOptions(OptionsV2): default_factory=DynamicalDecouplingOptions ) execution: Union[ExecutionOptionsV2, Dict] = Field(default_factory=ExecutionOptionsV2) + twirling: Union[TwirlingOptions, Dict] = Field(default_factory=TwirlingOptions) experimental: Union[UnsetType, dict] = Unset From 0b03695f6e7ead05038d9e230c5fa7d5723fac28 Mon Sep 17 00:00:00 2001 From: ptristan Date: Wed, 3 Apr 2024 12:03:41 -0300 Subject: [PATCH 02/11] linter fixes --- qiskit_ibm_runtime/options/sampler_options.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/options/sampler_options.py b/qiskit_ibm_runtime/options/sampler_options.py index 923072c17..5e4a63e82 100644 --- a/qiskit_ibm_runtime/options/sampler_options.py +++ b/qiskit_ibm_runtime/options/sampler_options.py @@ -16,13 +16,12 @@ from pydantic import Field -from . import TwirlingOptions from .utils import Dict, Unset, UnsetType from .execution_options import ExecutionOptionsV2 from .options import OptionsV2 from .utils import primitive_dataclass from .dynamical_decoupling_options import DynamicalDecouplingOptions - +from .twirling_options import TwirlingOptions @primitive_dataclass class SamplerOptions(OptionsV2): From c85b586a868ceb4f137aa37fb968caecf78491f4 Mon Sep 17 00:00:00 2001 From: ptristan Date: Wed, 3 Apr 2024 12:11:22 -0300 Subject: [PATCH 03/11] style fixes --- qiskit_ibm_runtime/options/sampler_options.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qiskit_ibm_runtime/options/sampler_options.py b/qiskit_ibm_runtime/options/sampler_options.py index 5e4a63e82..67c4242c6 100644 --- a/qiskit_ibm_runtime/options/sampler_options.py +++ b/qiskit_ibm_runtime/options/sampler_options.py @@ -23,6 +23,7 @@ from .dynamical_decoupling_options import DynamicalDecouplingOptions from .twirling_options import TwirlingOptions + @primitive_dataclass class SamplerOptions(OptionsV2): """Options for V2 Sampler. From a544b538fa269a2ac463ec672b0b25b406275b2b Mon Sep 17 00:00:00 2001 From: ptristan Date: Wed, 3 Apr 2024 12:32:30 -0300 Subject: [PATCH 04/11] add release note --- release-notes/unreleased/1557.feat.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 release-notes/unreleased/1557.feat.rst diff --git a/release-notes/unreleased/1557.feat.rst b/release-notes/unreleased/1557.feat.rst new file mode 100644 index 000000000..1568491f0 --- /dev/null +++ b/release-notes/unreleased/1557.feat.rst @@ -0,0 +1,2 @@ +The Sampler V2 starts to support twirling. +The twirling can only be applied on gates or measurements that are not used within a control flow. \ No newline at end of file From a4331bd197bca9c24d7eee261b7a7f9fb9eaccb6 Mon Sep 17 00:00:00 2001 From: ptristan3 <44805021+ptristan3@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:44:19 -0300 Subject: [PATCH 05/11] Update release-notes/unreleased/1557.feat.rst Co-authored-by: Kevin Tian --- release-notes/unreleased/1557.feat.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release-notes/unreleased/1557.feat.rst b/release-notes/unreleased/1557.feat.rst index 1568491f0..bb09c3d55 100644 --- a/release-notes/unreleased/1557.feat.rst +++ b/release-notes/unreleased/1557.feat.rst @@ -1,2 +1,2 @@ -The Sampler V2 starts to support twirling. +`SamplerV2` now supports twirling. The twirling can only be applied on gates or measurements that are not used within a control flow. \ No newline at end of file From 56c1de22068c5d2561d81a93e8bec9cfdfafe15f Mon Sep 17 00:00:00 2001 From: ptristan Date: Thu, 4 Apr 2024 16:49:53 -0300 Subject: [PATCH 06/11] update docstrings --- qiskit_ibm_runtime/options/twirling_options.py | 2 +- release-notes/unreleased/1557.feat.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/options/twirling_options.py b/qiskit_ibm_runtime/options/twirling_options.py index 62d4f579b..70d413e43 100644 --- a/qiskit_ibm_runtime/options/twirling_options.py +++ b/qiskit_ibm_runtime/options/twirling_options.py @@ -33,7 +33,7 @@ class TwirlingOptions: 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. + in the Primitive. 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 diff --git a/release-notes/unreleased/1557.feat.rst b/release-notes/unreleased/1557.feat.rst index bb09c3d55..ec3b811c4 100644 --- a/release-notes/unreleased/1557.feat.rst +++ b/release-notes/unreleased/1557.feat.rst @@ -1,2 +1,2 @@ `SamplerV2` now supports twirling. -The twirling can only be applied on gates or measurements that are not used within a control flow. \ No newline at end of file +The twirling can only be applied to those measurement registers not involved within a conditional logic. \ No newline at end of file From bda0daba3e56351fedd2c101855ddcab14653f3e Mon Sep 17 00:00:00 2001 From: ptristan Date: Thu, 4 Apr 2024 16:59:39 -0300 Subject: [PATCH 07/11] updated tests, included twirling option --- test/unit/test_sampler_options.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/test_sampler_options.py b/test/unit/test_sampler_options.py index 9e5866351..719c9a027 100644 --- a/test/unit/test_sampler_options.py +++ b/test/unit/test_sampler_options.py @@ -97,6 +97,7 @@ def test_program_inputs(self): {"execution": {"init_qubits": True}}, {"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.""" @@ -117,6 +118,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.""" From a8367fe4a19f10c71eba214b44bc7050e83645a3 Mon Sep 17 00:00:00 2001 From: ptristan Date: Fri, 5 Apr 2024 14:07:29 -0300 Subject: [PATCH 08/11] updated docstring from PR comment --- qiskit_ibm_runtime/options/twirling_options.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/options/twirling_options.py b/qiskit_ibm_runtime/options/twirling_options.py index 70d413e43..771b98b61 100644 --- a/qiskit_ibm_runtime/options/twirling_options.py +++ b/qiskit_ibm_runtime/options/twirling_options.py @@ -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 the Primitive. Default: True. + enable_measure: Whether to enable twirling of measurements. The twirling can 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 From c01db936c1c6f9a277a361603244f431b042297f Mon Sep 17 00:00:00 2001 From: ptristan Date: Mon, 8 Apr 2024 14:50:32 -0300 Subject: [PATCH 09/11] updated test_program_inputs --- test/unit/test_sampler_options.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit/test_sampler_options.py b/test/unit/test_sampler_options.py index 719c9a027..165e94355 100644 --- a/test/unit/test_sampler_options.py +++ b/test/unit/test_sampler_options.py @@ -62,6 +62,7 @@ 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, @@ -69,6 +70,7 @@ def test_program_inputs(self): simulator=simulator, default_shots=1000, dynamical_decoupling=dynamical_decoupling, + twirling=twirling, execution=execution, experimental={"foo": "bar", "execution": {"secret": 88}}, ) @@ -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, From 3b7cea196cf2debc89ac79cfcbfd98e17a9023d8 Mon Sep 17 00:00:00 2001 From: ptristan3 <44805021+ptristan3@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:24:14 -0300 Subject: [PATCH 10/11] Update qiskit_ibm_runtime/options/twirling_options.py Co-authored-by: Ian Hincks --- qiskit_ibm_runtime/options/twirling_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit_ibm_runtime/options/twirling_options.py b/qiskit_ibm_runtime/options/twirling_options.py index 771b98b61..d6523a63c 100644 --- a/qiskit_ibm_runtime/options/twirling_options.py +++ b/qiskit_ibm_runtime/options/twirling_options.py @@ -32,7 +32,7 @@ class TwirlingOptions: Args: enable_gates: Whether to apply 2-qubit gate twirling. Default: False. - enable_measure: Whether to enable twirling of measurements. The twirling can only be applied to + 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 From c1689ab658eceb050298439b332226bc8f60e51c Mon Sep 17 00:00:00 2001 From: ptristan3 <44805021+ptristan3@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:24:22 -0300 Subject: [PATCH 11/11] Update release-notes/unreleased/1557.feat.rst Co-authored-by: Ian Hincks --- release-notes/unreleased/1557.feat.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release-notes/unreleased/1557.feat.rst b/release-notes/unreleased/1557.feat.rst index ec3b811c4..f70273d9e 100644 --- a/release-notes/unreleased/1557.feat.rst +++ b/release-notes/unreleased/1557.feat.rst @@ -1,2 +1,2 @@ `SamplerV2` now supports twirling. -The twirling can only be applied to those measurement registers not involved within a conditional logic. \ No newline at end of file +Twirling will only be applied to those measurement registers not involved within a conditional logic. \ No newline at end of file