diff --git a/qiskit/dagcircuit/dagcircuit.py b/qiskit/dagcircuit/dagcircuit.py index 45204edb3870..5fa7238946cd 100644 --- a/qiskit/dagcircuit/dagcircuit.py +++ b/qiskit/dagcircuit/dagcircuit.py @@ -987,7 +987,9 @@ def substitute_node_with_dag(self, node, input_dag, wires=None): replay_node.cargs) if in_dag.global_phase: - self.global_phase += in_dag.global_phase + from sympy import evaluate + with evaluate(False): + self.global_phase += in_dag.global_phase if wires is None: wires = in_dag.wires diff --git a/qiskit/transpiler/passes/basis/basis_translator.py b/qiskit/transpiler/passes/basis/basis_translator.py index e05f6d732b97..504f61f92d25 100644 --- a/qiskit/transpiler/passes/basis/basis_translator.py +++ b/qiskit/transpiler/passes/basis/basis_translator.py @@ -162,7 +162,9 @@ def run(self, dag): dag.substitute_node(node, dag_op, inplace=True) if bound_target_dag.global_phase: - dag.global_phase += bound_target_dag.global_phase + from sympy import evaluate + with evaluate(False): + dag.global_phase += bound_target_dag.global_phase else: dag.substitute_node_with_dag(node, bound_target_dag) else: diff --git a/releasenotes/notes/5405-Slow-transpilation-of-ExcitationPreserving-297f3afd4a987cac.yaml b/releasenotes/notes/5405-Slow-transpilation-of-ExcitationPreserving-297f3afd4a987cac.yaml new file mode 100644 index 000000000000..7205ea7b6836 --- /dev/null +++ b/releasenotes/notes/5405-Slow-transpilation-of-ExcitationPreserving-297f3afd4a987cac.yaml @@ -0,0 +1,19 @@ +--- +upgrade: + - | + Following transpilation of a parameterized :class:`~qiskit.circuit.QuantumCircuit`, + the :attr:`~qiskit.circuit.QuantumCircuit.global_phase` attribute of output circuit + may no longer be returned in a simplified form, if the global phase is a + :class:`~qiskit.circuit.ParameterExpression`. + + For example,:: + + qc = QuantumCircuit(1) + theta = Parameter('theta') + + qc.rz(theta, 0) + qc.rz(-theta, 0) + + transpile(qc, basis_gates=['p']).global_phase + + previously returned ``0``, but will now return ``-0.5*theta + 0.5*theta``.