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

Fix circuit ordering in InterleavedRB #1191

Merged
merged 4 commits into from
Jun 2, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""
Interleaved RB Experiment class.
"""
import itertools
import warnings
from typing import Union, Iterable, Optional, List, Sequence, Tuple

Expand All @@ -25,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
Expand Down Expand Up @@ -66,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.

Expand All @@ -90,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
Expand Down Expand Up @@ -156,9 +162,25 @@ 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)

@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"`` (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(
circuit_order="RIRIRI",
)
return options

def circuits(self) -> List[QuantumCircuit]:
"""Return a list of RB circuits.

Expand Down Expand Up @@ -198,7 +220,11 @@ def circuits(self) -> List[QuantumCircuit]:
"physical_qubits": self.physical_qubits,
"interleaved": True,
}
return reference_circuits + interleaved_circuits

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(
self, elem: SequenceElementType, basis_gates: Optional[Tuple[str]] = None
Expand Down
15 changes: 15 additions & 0 deletions releasenotes/notes/irb-circuit-order-619845a707519c44.yaml
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/Qiskit/qiskit-experiments/pull/898>`_.
Before that, it had been RIRIRI order.
8 changes: 7 additions & 1 deletion test/library/randomized_benchmarking/test_interleaved_rb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down