From 83feccea334792119a13668ed3f297f86835db0b Mon Sep 17 00:00:00 2001 From: Naoki Kanazawa Date: Thu, 20 Jun 2024 02:44:49 +0900 Subject: [PATCH] readd parameter table management --- .../randomized_benchmarking/clifford_utils.py | 14 ++++---------- .../notes/fix-broken-codes-ec927b67b528c862.yaml | 8 -------- 2 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 releasenotes/notes/fix-broken-codes-ec927b67b528c862.yaml diff --git a/qiskit_experiments/library/randomized_benchmarking/clifford_utils.py b/qiskit_experiments/library/randomized_benchmarking/clifford_utils.py index dda05b1b55..95dbeb610b 100644 --- a/qiskit_experiments/library/randomized_benchmarking/clifford_utils.py +++ b/qiskit_experiments/library/randomized_benchmarking/clifford_utils.py @@ -15,7 +15,6 @@ import itertools import os -import warnings from functools import lru_cache from numbers import Integral from typing import Optional, Union, Tuple, Sequence, Iterable @@ -53,21 +52,14 @@ def _transpile_clifford_circuit( circuit: QuantumCircuit, physical_qubits: Sequence[int] ) -> QuantumCircuit: # Simplified transpile that only decomposes Clifford circuits and creates the layout. - if circuit.num_parameters > 0: - warnings.warn( - f"Input circuit {circuit.name} contains some parameterized instructions. " - "The custom transpile code being used assumes non-parameterized circuit as an input, " - "and the parameter table is not carried over to the transpiled circuit. " - "This indicates the transpiled circuit doesn't work normally when " - "the .assign_parameters method is called to bind instruction parameters.", - RuntimeWarning, - ) return _apply_qubit_layout(_decompose_clifford_ops(circuit), physical_qubits=physical_qubits) def _decompose_clifford_ops(circuit: QuantumCircuit) -> QuantumCircuit: # Simplified QuantumCircuit.decompose, which decomposes only Clifford ops res = circuit.copy_empty_like() + if hasattr(circuit, "_parameter_table"): + res._parameter_table = circuit._parameter_table for inst in circuit: if inst.operation.name.startswith("Clifford"): # Decompose rule = inst.operation.definition.data @@ -95,6 +87,8 @@ def _apply_qubit_layout(circuit: QuantumCircuit, physical_qubits: Sequence[int]) for reg in circuit.cregs: res.add_register(reg) _circuit_compose(res, circuit, qubits=physical_qubits) + if hasattr(circuit, "_parameter_table"): + res._parameter_table = circuit._parameter_table return res diff --git a/releasenotes/notes/fix-broken-codes-ec927b67b528c862.yaml b/releasenotes/notes/fix-broken-codes-ec927b67b528c862.yaml deleted file mode 100644 index 6ce7cfe190..0000000000 --- a/releasenotes/notes/fix-broken-codes-ec927b67b528c862.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -fixes: - - | - Custom transpile code used in the :mod:`.randomized_benchmark` module - was upgraded to support change in the :class:`.QuantumCircuit` data model - made in the qiskit >= 1.2. - After this code fix, transpile of Clifford circuits including - parameters will no longer work.