diff --git a/qiskit_ibm_runtime/qpy/binary_io/circuits.py b/qiskit_ibm_runtime/qpy/binary_io/circuits.py index c0f86e2cb2..b8fbb07dc3 100644 --- a/qiskit_ibm_runtime/qpy/binary_io/circuits.py +++ b/qiskit_ibm_runtime/qpy/binary_io/circuits.py @@ -336,6 +336,9 @@ def _parse_custom_operation( # type: ignore[no-untyped-def] base_gate = _read_instruction( base_gate_obj, None, registers, custom_operations, version, vectors ) + if ctrl_state < 2**num_ctrl_qubits - 1: + # If open controls, we need to discard the control suffix when setting the name. + gate_name = gate_name.rsplit("_", 1)[0] inst_obj = ControlledGate( gate_name, num_qubits, @@ -549,7 +552,7 @@ def _write_instruction( # type: ignore[no-untyped-def] has_condition = False condition_register = b"" condition_value = 0 - if instruction.operation.condition: + if getattr(instruction.operation, "condition", None): has_condition = True if isinstance(instruction.operation.condition[0], Clbit): bit_index = index_map["c"][instruction.operation.condition[0]] @@ -667,14 +670,21 @@ def _write_custom_operation( # type: ignore[no-untyped-def] has_definition = True data = common.data_to_binary(operation, _write_pauli_evolution_gate) size = len(data) - elif operation.definition is not None: + elif type_key == type_keys.CircuitInstruction.CONTROLLED_GATE: + # For ControlledGate, we have to access and store the private `_definition` rather than the + # public one, because the public one is mutated to include additional logic if the control + # state is open, and the definition setter (during a subsequent read) uses the "fully + # excited" control definition only. has_definition = True - data = common.data_to_binary(operation.definition, write_circuit) + data = common.data_to_binary(operation._definition, write_circuit) size = len(data) - if type_key == type_keys.CircuitInstruction.CONTROLLED_GATE: num_ctrl_qubits = operation.num_ctrl_qubits ctrl_state = operation.ctrl_state base_gate = operation.base_gate + elif operation.definition is not None: + has_definition = True + data = common.data_to_binary(operation.definition, write_circuit) + size = len(data) if base_gate is None: base_gate_raw = b"" else: diff --git a/requirements.txt b/requirements.txt index 97f5f4bdfc..76b4b09127 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -qiskit-terra>=0.21.1 +qiskit-terra>=0.21.2 requests>=2.19 requests_ntlm>=1.1.0 numpy>=1.13 diff --git a/setup.py b/setup.py index 0a81fa1e54..c43f033402 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import setuptools REQUIREMENTS = [ - "qiskit-terra>=0.21.1", + "qiskit-terra>=0.21.2", "requests>=2.19", "requests-ntlm>=1.1.0", "numpy>=1.13",