Skip to content

Commit

Permalink
remove parameter table handling in custom transpile
Browse files Browse the repository at this point in the history
  • Loading branch information
nkanazawa1989 committed Jun 19, 2024
1 parent b07645f commit 188eb5c
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 188eb5c

Please sign in to comment.