From 38a767277c3e6b7b2eae2b892979419aef811230 Mon Sep 17 00:00:00 2001 From: Toshinari Itoko Date: Fri, 26 May 2023 20:52:05 +0900 Subject: [PATCH 1/4] Fix circuit ordering in InterleavedRB --- .../randomized_benchmarking/interleaved_rb_experiment.py | 4 +++- .../randomized_benchmarking/test_interleaved_rb.py | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py b/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py index 0231145298..f32ef3a796 100644 --- a/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py +++ b/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py @@ -12,6 +12,7 @@ """ Interleaved RB Experiment class. """ +import itertools import warnings from typing import Union, Iterable, Optional, List, Sequence, Tuple @@ -198,7 +199,8 @@ def circuits(self) -> List[QuantumCircuit]: "physical_qubits": self.physical_qubits, "interleaved": True, } - return reference_circuits + interleaved_circuits + # arrange circuits as ref-int-ref-int-ref-int + return list(itertools.chain.from_iterable(zip(reference_circuits, interleaved_circuits))) def _to_instruction( self, elem: SequenceElementType, basis_gates: Optional[Tuple[str]] = None diff --git a/test/library/randomized_benchmarking/test_interleaved_rb.py b/test/library/randomized_benchmarking/test_interleaved_rb.py index 93b3f3dc36..10e7f72255 100644 --- a/test/library/randomized_benchmarking/test_interleaved_rb.py +++ b/test/library/randomized_benchmarking/test_interleaved_rb.py @@ -104,10 +104,16 @@ def test_generate_interleaved_circuits(self, interleaved_element, qubits, length interleaved_element=interleaved_element, physical_qubits=qubits, lengths=[length], - num_samples=1, + num_samples=2, ) circuits = exp.circuits() self.assertAllIdentity(circuits) + # check order of circuits + for i, circ in enumerate(circuits): + if i % 2 == 0: # even <=> reference sequence + self.assertFalse(circ.metadata["interleaved"]) + else: # odd <=> interleaved sequence + self.assertTrue(circ.metadata["interleaved"]) @data([SXGate(), [3], 4], [CXGate(), [4, 7], 5]) @unpack From fcb75df43ab24ca287b321bcd93abf0737a7fe84 Mon Sep 17 00:00:00 2001 From: Toshinari Itoko Date: Wed, 31 May 2023 22:51:13 +0900 Subject: [PATCH 2/4] Add circuit_order to experiment options --- .../interleaved_rb_experiment.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py b/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py index f32ef3a796..775c0cde2d 100644 --- a/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py +++ b/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py @@ -26,6 +26,7 @@ from qiskit.quantum_info import Clifford from qiskit.transpiler.exceptions import TranspilerError from qiskit_experiments.warnings import deprecate_arguments +from qiskit_experiments.framework import Options from qiskit_experiments.framework.backend_timing import BackendTiming from .clifford_utils import _truncate_inactive_qubits from .clifford_utils import num_from_1q_circuit, num_from_2q_circuit @@ -160,6 +161,21 @@ def __init__( self.analysis = InterleavedRBAnalysis() self.analysis.set_options(outcome="0" * self.num_qubits) + @classmethod + def _default_experiment_options(cls) -> Options: + """Default InterleavedRB experiment options. + + Experiment Options: + circuit_order (str): How to order the reference and the interleaved circuits. + * ``"RIRIRI"``(default): Alternate a reference and an interleaved circuit. + * ``"RRRIII"``: Push all reference circuits first, then all interleaved ones. + """ + options = super()._default_experiment_options() + options.update_options( + circuit_order="RIRIRI", + ) + return options + def circuits(self) -> List[QuantumCircuit]: """Return a list of RB circuits. @@ -199,7 +215,10 @@ def circuits(self) -> List[QuantumCircuit]: "physical_qubits": self.physical_qubits, "interleaved": True, } - # arrange circuits as ref-int-ref-int-ref-int + + if self.experiment_options.circuit_order == "RRRIII": + return reference_circuits + interleaved_circuits + # Default order: RIRIRI return list(itertools.chain.from_iterable(zip(reference_circuits, interleaved_circuits))) def _to_instruction( From 9af8062fa874d3bd0d32c42bb623b3a9e586c5ca Mon Sep 17 00:00:00 2001 From: Toshinari Itoko Date: Wed, 31 May 2023 22:52:06 +0900 Subject: [PATCH 3/4] Add circuit_order argument in InverleavedRB constructor --- .../randomized_benchmarking/interleaved_rb_experiment.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py b/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py index 775c0cde2d..a01be23f8e 100644 --- a/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py +++ b/qiskit_experiments/library/randomized_benchmarking/interleaved_rb_experiment.py @@ -68,6 +68,7 @@ def __init__( num_samples: int = 3, seed: Optional[Union[int, SeedSequence, BitGenerator, Generator]] = None, full_sampling: bool = False, + circuit_order: str = "RIRIRI", ): """Initialize an interleaved randomized benchmarking experiment. @@ -92,6 +93,9 @@ def __init__( all lengths. If False for sample of lengths longer sequences are constructed by appending additional Clifford samples to shorter sequences. + circuit_order: How to order the reference and the interleaved circuits. + ``"RIRIRI"`` (default) - Alternate a reference and an interleaved circuit. Or + ``"RRRIII"`` - Push all reference circuits first, then all interleaved ones. Raises: QiskitError: When interleaved_element has different number of qubits @@ -158,6 +162,7 @@ def __init__( self._interleaved_cliff = interleaved_clifford.to_circuit() self._interleaved_element = interleaved_element # Original interleaved element self._interleaved_op = None # Transpiled interleaved element for speed + self.set_experiment_options(circuit_order=circuit_order) self.analysis = InterleavedRBAnalysis() self.analysis.set_options(outcome="0" * self.num_qubits) @@ -167,8 +172,8 @@ def _default_experiment_options(cls) -> Options: Experiment Options: circuit_order (str): How to order the reference and the interleaved circuits. - * ``"RIRIRI"``(default): Alternate a reference and an interleaved circuit. - * ``"RRRIII"``: Push all reference circuits first, then all interleaved ones. + ``"RIRIRI"`` (alternate a reference and an interleaved circuit) or + ``"RRRIII"`` (push all reference circuits first, then all interleaved ones). """ options = super()._default_experiment_options() options.update_options( From f6925bdc08a80ad3bfa13aac0a1760ffbec70b6e Mon Sep 17 00:00:00 2001 From: Toshinari Itoko Date: Wed, 31 May 2023 23:13:12 +0900 Subject: [PATCH 4/4] Add reno --- .../notes/irb-circuit-order-619845a707519c44.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 releasenotes/notes/irb-circuit-order-619845a707519c44.yaml diff --git a/releasenotes/notes/irb-circuit-order-619845a707519c44.yaml b/releasenotes/notes/irb-circuit-order-619845a707519c44.yaml new file mode 100644 index 0000000000..f0837e8600 --- /dev/null +++ b/releasenotes/notes/irb-circuit-order-619845a707519c44.yaml @@ -0,0 +1,15 @@ +--- +features: + - | + A new experiment option ``circuit_order`` was added to :class:`~.InterleavedRB`. + It allows to change the order of the reference and the interleaved circuits + and hence slightly alter the impact of noise on interleaved RB results. + The default value is set to ``"RIRIRI"`` that alternate a reference and + an interleaved circuit. +fixes: + - | + Changed the ordering of circuits generated by :class:`~.InterleavedRB` back to + RIRIRI (R: Reference, I: Interleaved) order. + It was accidentally changed into RRRIII order in + `#898 `_. + Before that, it had been RIRIRI order.