From 3c92e4887ea76109a2eba55e9099a0accdb4ad96 Mon Sep 17 00:00:00 2001 From: robotAstray Date: Wed, 20 Sep 2023 20:02:01 +0100 Subject: [PATCH] Issue #367 - Migration from QasmSimulator to qiskit_aer's AerSimulator (#378) * Migration from QasmSimulator to qiskit_aer's AerSimulator * eliminate execute from imports (#1) * remove execute import from faultsampler.py * remove execute imports from faultenumerator.py * remove execute import from test_heavy_hex_decoder.py * remove execute import from test_repetitionmatcher.py * remove execute import from test_circuitmatcher.py --------- Co-authored-by: grace-harper <119029214+grace-harper@users.noreply.github.com> --- src/qiskit_qec/circuits/repetition_code.py | 12 ++++++------ test/code_circuits/test_rep_codes.py | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/qiskit_qec/circuits/repetition_code.py b/src/qiskit_qec/circuits/repetition_code.py index 780ea834..e2009b9e 100644 --- a/src/qiskit_qec/circuits/repetition_code.py +++ b/src/qiskit_qec/circuits/repetition_code.py @@ -21,9 +21,9 @@ import numpy as np import rustworkx as rx from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, transpile -from qiskit.circuit.library import RZGate, XGate -from qiskit.transpiler import InstructionDurations, PassManager -from qiskit.transpiler.passes import DynamicalDecoupling +from qiskit.circuit.library import XGate, RZGate +from qiskit.transpiler import PassManager, InstructionDurations +from qiskit.transpiler.passes import ALAPScheduleAnalysis, PadDynamicalDecoupling from qiskit_qec.circuits.code_circuit import CodeCircuit from qiskit_qec.utils import DecodingGraphEdge, DecodingGraphNode @@ -1268,7 +1268,6 @@ def check_nodes(self, nodes, ignore_extra_boundary=False, minimal=False): # if neutral for maximal, it's neutral # otherwise, it is whatever it is for the minimal for c in cs: - neutral = base_neutral num_errors = num_nodes[c] flipped_logicals = flipped_logicals_all[c] @@ -1379,9 +1378,10 @@ def transpile(self, backend, echo=("X", "X"), echo_num=(2, 0)): qubits = None pm = PassManager( [ - DynamicalDecoupling( + ALAPScheduleAnalysis(durations), + PadDynamicalDecoupling( durations, dd_sequence, qubits=qubits, spacing=spacings[j] - ) + ), ] ) circuits = pm.run(circuits) diff --git a/test/code_circuits/test_rep_codes.py b/test/code_circuits/test_rep_codes.py index ebb0118a..14d4de75 100644 --- a/test/code_circuits/test_rep_codes.py +++ b/test/code_circuits/test_rep_codes.py @@ -20,8 +20,9 @@ import unittest from random import choices -from qiskit import Aer, QuantumCircuit, execute +from qiskit import QuantumCircuit, execute from qiskit.providers.fake_provider import FakeJakarta +from qiskit_aer import Aer, AerSimulator from qiskit_aer.noise import NoiseModel from qiskit_aer.noise.errors import depolarizing_error @@ -353,7 +354,7 @@ def test_single_error_202s(self): else: error_qc.x(code.link_qubit[code.link_index[q]]) error_qc.append(gate) - counts = Aer.get_backend("qasm_simulator").run(error_qc).result().get_counts() + counts = AerSimulator().run(error_qc).result().get_counts() for string in counts: # look at only bulk non-conjugate nodes nodes = [ @@ -392,7 +393,7 @@ def test_feedforward(self): for gate in qc: test_qc.append(gate) test_qcs.append(test_qc) - result = Aer.get_backend("qasm_simulator").run(test_qcs).result() + result = AerSimulator().run(test_qcs).result() # check result strings are correct for j in range(2): counts = result.get_counts(j)