Skip to content

Commit 1e86d65

Browse files
authored
Adjust QuantumError.to_dict() to handle lack of Instruction.condition (#2301)
* Adjust QuantumError.to_dict() to handle lack of Instruction.condition In Qiskit 2.0 the Instruction.condition attribute will be removed following it's deprecation in 1.3.0. This attribute has been superseded by the IfElseOp which covers the use case but offers more functionality. The removal is pending in Qiskit/qiskit#13506 and the use of qiskit-aer in Qiskit's tests is blocking progress on that PR. This commit makes the usage of .condition optional to maintain compatibility with Qiskit<2.0 but also work in >=2.0 with the attribute removed. * Handle condition for AerJump as a custom attribute With the removal of .condition from the base instruction data model the .c_if() method was also removed. To handle the conditional jump that AerJump was used for a custom attribute .condition is added to the instruction. This enables retaining the functionality, but doesn't rely on the base data model to provide the attribute or method.
1 parent 0bd1716 commit 1e86d65

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

qiskit_aer/library/control_flow_instructions/jump.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class AerJump(Instruction):
2929
def __init__(self, jump_to, num_qubits, num_clbits=0):
3030
super().__init__("jump", num_qubits, num_clbits, [jump_to])
3131
self.condition_expr = None
32+
self.condition = None
3233

3334
def set_conditional(self, cond):
3435
"""Set condition to perform this jump instruction.
@@ -42,5 +43,5 @@ def set_conditional(self, cond):
4243
if isinstance(cond, Expr):
4344
self.condition_expr = cond
4445
else:
45-
self.c_if(*cond)
46+
self.condition = cond
4647
return self

qiskit_aer/noise/errors/quantum_error.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ def to_dict(self):
319319
inst_dict["params"] = inst.operation.params
320320
if inst.operation.label:
321321
inst_dict["label"] = inst.operation.label
322-
if inst.operation.condition:
323-
inst_dict["condition"] = inst.operation.condition
322+
condition = getattr(inst.operation, "condition", None)
323+
if condition:
324+
inst_dict["condition"] = condition
324325
circ_inst.append(inst_dict)
325326
instructions.append(circ_inst)
326327
# Construct error dict

0 commit comments

Comments
 (0)