From 147bf94eed3ec6c42290cdf8b1e2d632487ff5a5 Mon Sep 17 00:00:00 2001 From: robotAstray Date: Wed, 9 Aug 2023 00:14:33 +0100 Subject: [PATCH 1/2] Migration from QasmSimulator to qiskit_aer's AerSimulator --- src/qiskit_qec/analysis/faultenumerator.py | 3 ++- src/qiskit_qec/analysis/faultsampler.py | 3 ++- src/qiskit_qec/circuits/repetition_code.py | 8 ++++---- test/code_circuits/test_rep_codes.py | 7 ++++--- test/heavy_hex_codes/test_heavy_hex_decoder.py | 3 ++- test/matching/test_circuitmatcher.py | 3 ++- test/matching/test_repetitionmatcher.py | 3 ++- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/qiskit_qec/analysis/faultenumerator.py b/src/qiskit_qec/analysis/faultenumerator.py index 4df31677..7122630d 100644 --- a/src/qiskit_qec/analysis/faultenumerator.py +++ b/src/qiskit_qec/analysis/faultenumerator.py @@ -18,7 +18,8 @@ from qiskit import QuantumCircuit from qiskit.converters import circuit_to_dag from qiskit.circuit.library import IGate, XGate, YGate, ZGate -from qiskit import execute, Aer +from qiskit import execute +from qiskit_aer import Aer from qiskit_qec.analysis.extensions import C_FAULT_ENUMERATOR diff --git a/src/qiskit_qec/analysis/faultsampler.py b/src/qiskit_qec/analysis/faultsampler.py index c7db629e..ae7228bb 100644 --- a/src/qiskit_qec/analysis/faultsampler.py +++ b/src/qiskit_qec/analysis/faultsampler.py @@ -7,7 +7,8 @@ from qiskit.dagcircuit.dagnode import DAGNode from qiskit.converters import circuit_to_dag from qiskit.circuit.library import IGate, XGate, YGate, ZGate -from qiskit import execute, Aer +from qiskit import execute +from qiskit_aer import Aer from qiskit_qec.utils.dag import node_name_label diff --git a/src/qiskit_qec/circuits/repetition_code.py b/src/qiskit_qec/circuits/repetition_code.py index 04b64cb0..63811bd6 100644 --- a/src/qiskit_qec/circuits/repetition_code.py +++ b/src/qiskit_qec/circuits/repetition_code.py @@ -24,7 +24,7 @@ from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, transpile from qiskit.circuit.library import XGate, RZGate from qiskit.transpiler import PassManager, InstructionDurations -from qiskit.transpiler.passes import DynamicalDecoupling +from qiskit.transpiler.passes import ALAPScheduleAnalysis, PadDynamicalDecoupling from qiskit_qec.circuits.code_circuit import CodeCircuit from qiskit_qec.utils import DecodingGraphNode, DecodingGraphEdge @@ -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] @@ -1381,9 +1380,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 763fe70d..6a643f62 100644 --- a/test/code_circuits/test_rep_codes.py +++ b/test/code_circuits/test_rep_codes.py @@ -20,8 +20,9 @@ import itertools 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 from qiskit_qec.circuits.repetition_code import RepetitionCodeCircuit as RepetitionCode @@ -352,7 +353,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 = [ @@ -391,7 +392,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) diff --git a/test/heavy_hex_codes/test_heavy_hex_decoder.py b/test/heavy_hex_codes/test_heavy_hex_decoder.py index 7d7a9da7..ed0a2909 100644 --- a/test/heavy_hex_codes/test_heavy_hex_decoder.py +++ b/test/heavy_hex_codes/test_heavy_hex_decoder.py @@ -1,7 +1,8 @@ """Test a heavy-hexagon code decoder""" import unittest -from qiskit import execute, Aer +from qiskit import execute +from qiskit_aer import Aer from qiskit_qec.codes.hhc import HHC from qiskit_qec.circuits.hhc_circuit import HHCCircuit diff --git a/test/matching/test_circuitmatcher.py b/test/matching/test_circuitmatcher.py index 61de1252..7c1393fa 100644 --- a/test/matching/test_circuitmatcher.py +++ b/test/matching/test_circuitmatcher.py @@ -1,7 +1,8 @@ """Tests for the subsystem CSS circuit-level matching decoder.""" import unittest -from qiskit import execute, QuantumCircuit, Aer +from qiskit import execute, QuantumCircuit +from qiskit_aer import Aer from qiskit_qec.analysis.faultenumerator import FaultEnumerator from qiskit_qec.decoders.circuit_matching_decoder import temp_syndrome diff --git a/test/matching/test_repetitionmatcher.py b/test/matching/test_repetitionmatcher.py index 0f0642e9..52c666b6 100644 --- a/test/matching/test_repetitionmatcher.py +++ b/test/matching/test_repetitionmatcher.py @@ -1,7 +1,8 @@ """Tests for the subsystem CSS circuit-level matching decoder.""" import unittest -from qiskit import execute, Aer +from qiskit import execute +from qiskit_aer import Aer from qiskit_qec.analysis.faultenumerator import FaultEnumerator from qiskit_qec.decoders.circuit_matching_decoder import temp_syndrome From 53c76149bcaba4530e6e0eef3c34ea70df917d41 Mon Sep 17 00:00:00 2001 From: robotAstray Date: Tue, 19 Sep 2023 20:59:17 +0100 Subject: [PATCH 2/2] 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 --- src/qiskit_qec/analysis/faultenumerator.py | 1 - src/qiskit_qec/analysis/faultsampler.py | 1 - test/heavy_hex_codes/test_heavy_hex_decoder.py | 1 - test/matching/test_circuitmatcher.py | 2 +- test/matching/test_repetitionmatcher.py | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/qiskit_qec/analysis/faultenumerator.py b/src/qiskit_qec/analysis/faultenumerator.py index 8debda81..910ace1e 100644 --- a/src/qiskit_qec/analysis/faultenumerator.py +++ b/src/qiskit_qec/analysis/faultenumerator.py @@ -18,7 +18,6 @@ from qiskit import QuantumCircuit from qiskit.converters import circuit_to_dag from qiskit.circuit.library import IGate, XGate, YGate, ZGate -from qiskit import execute from qiskit_aer import Aer from qiskit_qec.analysis.extensions import C_FAULT_ENUMERATOR diff --git a/src/qiskit_qec/analysis/faultsampler.py b/src/qiskit_qec/analysis/faultsampler.py index 54b06c6d..99e7d040 100644 --- a/src/qiskit_qec/analysis/faultsampler.py +++ b/src/qiskit_qec/analysis/faultsampler.py @@ -7,7 +7,6 @@ from qiskit.dagcircuit.dagnode import DAGNode from qiskit.converters import circuit_to_dag from qiskit.circuit.library import IGate, XGate, YGate, ZGate -from qiskit import execute from qiskit_aer import Aer from qiskit_qec.utils.dag import node_name_label diff --git a/test/heavy_hex_codes/test_heavy_hex_decoder.py b/test/heavy_hex_codes/test_heavy_hex_decoder.py index 56714f3a..a02bebf8 100644 --- a/test/heavy_hex_codes/test_heavy_hex_decoder.py +++ b/test/heavy_hex_codes/test_heavy_hex_decoder.py @@ -1,7 +1,6 @@ """Test a heavy-hexagon code decoder""" import unittest -from qiskit import execute from qiskit_aer import Aer from qiskit_qec.codes.hhc import HHC diff --git a/test/matching/test_circuitmatcher.py b/test/matching/test_circuitmatcher.py index 88dfc960..d15c7a8e 100644 --- a/test/matching/test_circuitmatcher.py +++ b/test/matching/test_circuitmatcher.py @@ -1,7 +1,7 @@ """Tests for the subsystem CSS circuit-level matching decoder.""" import unittest -from qiskit import execute, QuantumCircuit +from qiskit import QuantumCircuit from qiskit_aer import Aer from qiskit_qec.analysis.faultenumerator import FaultEnumerator diff --git a/test/matching/test_repetitionmatcher.py b/test/matching/test_repetitionmatcher.py index 89967e8c..6de89203 100644 --- a/test/matching/test_repetitionmatcher.py +++ b/test/matching/test_repetitionmatcher.py @@ -1,7 +1,6 @@ """Tests for the subsystem CSS circuit-level matching decoder.""" import unittest -from qiskit import execute from qiskit_aer import Aer from qiskit_qec.analysis.faultenumerator import FaultEnumerator