diff --git a/mindquantum/core/circuit/circuit.py b/mindquantum/core/circuit/circuit.py index b6f16ba299911f2b35c405e7677c55ac3c18988e..a0488122e61b5102e3df83deaab0d9dc58a2a3cb 100644 --- a/mindquantum/core/circuit/circuit.py +++ b/mindquantum/core/circuit/circuit.py @@ -1026,7 +1026,16 @@ class Circuit(list): # pylint: disable=too-many-instance-attributes,too-many-pu coeff.const += pr[k] * v coeff.pop(k) coeffs.append(coeff) - circuit += gate.__class__(*coeffs).on(gate.obj_qubits, gate.ctrl_qubits) + try: + new_gate = gate(*coeffs) + except TypeError as first_exc: + if len(coeffs) == 1: + raise + try: + new_gate = gate(coeffs) + except TypeError as second_exc: + raise first_exc from second_exc + circuit += new_gate return circuit @staticmethod