Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix legacy accesses of CircuitInstruction #2179

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qiskit_aer/backends/aer_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ def _assemble_type(expr_type):

def _iter_var_recursive(circuit):
yield from circuit.iter_vars()
for data in circuit.data:
for param in data[0].params:
for instruction in circuit.data:
for param in instruction.operation.params:
if isinstance(param, QuantumCircuit):
yield from _iter_var_recursive(param)

Expand Down
4 changes: 2 additions & 2 deletions qiskit_aer/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def circuit_optypes(circuit):
if not isinstance(circuit, QuantumCircuit):
return set()
optypes = set()
for inst, _, _ in circuit._data:
optypes.update(type(inst).mro())
for instruction in circuit.data:
optypes.update(type(instruction.operation).mro())
optypes.discard(object)
return optypes
9 changes: 5 additions & 4 deletions qiskit_aer/noise/errors/quantum_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def ideal(self):
pass

# Component-wise check for non-Clifford circuits
for op, _, _ in circ:
for instruction in circ:
op = instruction.operation
if isinstance(op, IGate):
continue
if isinstance(op, PauliGate):
Expand Down Expand Up @@ -310,9 +311,9 @@ def to_dict(self):
instructions = []
for circ in self._circs:
circ_inst = []
for inst, qargs, _ in circ.data:
qobj_inst = inst.assemble()
qobj_inst.qubits = [circ.find_bit(q).index for q in qargs]
for inst in circ.data:
qobj_inst = inst.operation.assemble()
qobj_inst.qubits = [circ.find_bit(q).index for q in inst.qubits]
circ_inst.append(qobj_inst.to_dict())
instructions.append(circ_inst)
# Construct error dict
Expand Down
19 changes: 10 additions & 9 deletions qiskit_aer/utils/noise_model_inserter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ def insert_noise(circuits, noise_model, transpile=False):
qubit_indices = {bit: index for index, bit in enumerate(transpiled_circuit.qubits)}
result_circuit = transpiled_circuit.copy(name=transpiled_circuit.name + "_with_noise")
result_circuit.data = []
for inst, qargs, cargs in transpiled_circuit.data:
result_circuit.data.append((inst, qargs, cargs))
qubits = tuple(qubit_indices[q] for q in qargs)
for inst in transpiled_circuit.data:
result_circuit.data.append(inst)
qubits = tuple(qubit_indices[q] for q in inst.qubits)
# Priority for error model used:
# local error > default error
if inst.name in local_errors and qubits in local_errors[inst.name]:
error = local_errors[inst.name][qubits]
result_circuit.append(error.to_instruction(), qargs)
elif inst.name in default_errors.keys():
error = default_errors[inst.name]
result_circuit.append(error.to_instruction(), qargs)
name = inst.operation.name
if name in local_errors and qubits in local_errors[name]:
error = local_errors[name][qubits]
result_circuit.append(error.to_instruction(), inst.qubits)
elif name in default_errors.keys():
error = default_errors[name]
result_circuit.append(error.to_instruction(), inst.qubits)
result_circuits.append(result_circuit)
return result_circuits if is_circuits_list else result_circuits[0]
Loading