From 188eb5c8f18f042486c2cd98282dfdc9f1598271 Mon Sep 17 00:00:00 2001 From: Naoki Kanazawa Date: Thu, 20 Jun 2024 00:11:56 +0900 Subject: [PATCH] remove parameter table handling in custom transpile --- .../randomized_benchmarking/clifford_utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/qiskit_experiments/library/randomized_benchmarking/clifford_utils.py b/qiskit_experiments/library/randomized_benchmarking/clifford_utils.py index acf0935d4b..dda05b1b55 100644 --- a/qiskit_experiments/library/randomized_benchmarking/clifford_utils.py +++ b/qiskit_experiments/library/randomized_benchmarking/clifford_utils.py @@ -15,6 +15,7 @@ import itertools import os +import warnings from functools import lru_cache from numbers import Integral from typing import Optional, Union, Tuple, Sequence, Iterable @@ -52,16 +53,21 @@ 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 - # Note that the resulting circuit depends on the input circuit, - # that means the changes on the input circuit may affect the resulting circuit. - # For example, the resulting circuit shares the parameter_table of the input circuit, res = circuit.copy_empty_like() - res._parameter_table = circuit._parameter_table for inst in circuit: if inst.operation.name.startswith("Clifford"): # Decompose rule = inst.operation.definition.data @@ -89,7 +95,6 @@ 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) - res._parameter_table = circuit._parameter_table return res