From 2f6a462926742c19236e762b8b4b44a68091fbe8 Mon Sep 17 00:00:00 2001 From: Danylo Lykov Date: Wed, 24 Apr 2024 20:03:08 -0500 Subject: [PATCH] update qiskit simulator usage, skip test on missing qiskit --- qtensor/optimisation/Optimizer.py | 2 +- qtensor/tests/qiskit_qaoa_energy.py | 8 +++----- qtensor/tests/test_bucket_backends.py | 3 --- qtensor/tests/test_composers.py | 2 +- qtensor/tests/test_optimizers.py | 2 -- qtensor/tests/test_qaoa_energy.py | 1 + qtensor/tests/test_simulators.py | 3 --- qtree | 2 +- setup.py | 1 - 9 files changed, 7 insertions(+), 17 deletions(-) diff --git a/qtensor/optimisation/Optimizer.py b/qtensor/optimisation/Optimizer.py index e8fdfd93..81091845 100644 --- a/qtensor/optimisation/Optimizer.py +++ b/qtensor/optimisation/Optimizer.py @@ -104,7 +104,7 @@ def _get_max_tw(self): log.info('Memory available: {}', avail) # Cost = 16*2**tw # tw = log(cost/16) = log(cost) - 4 - return np.int(np.log2(avail)) - 4 + return int(np.log2(avail)) - 4 def _split_graph(self, p_graph, max_tw): searcher = GreedyParvars(p_graph) diff --git a/qtensor/tests/qiskit_qaoa_energy.py b/qtensor/tests/qiskit_qaoa_energy.py index 2599558d..5a008df7 100644 --- a/qtensor/tests/qiskit_qaoa_energy.py +++ b/qtensor/tests/qiskit_qaoa_energy.py @@ -2,10 +2,6 @@ import networkx as nx from functools import partial -from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister -from qiskit import Aer, execute -from qiskit.circuit import Parameter - def maxcut_obj(x, G): """ @@ -66,6 +62,7 @@ def create_qaoa_circ(G, theta): Returns: qc: qiskit circuit """ + from qiskit import QuantumCircuit nqubits = len(G.nodes()) p = len(theta)//2 # number of alternating unitaries qc = QuantumCircuit(nqubits) @@ -94,7 +91,8 @@ def get_expectation(G, shots=512): p: int, Number of repetitions of unitaries """ - backend = Aer.get_backend('qasm_simulator') + from qiskit_aer import AerSimulator + backend = AerSimulator(method='statevector') def execute_circ(theta): qc = create_qaoa_circ(G, theta) diff --git a/qtensor/tests/test_bucket_backends.py b/qtensor/tests/test_bucket_backends.py index b139c057..41fb9bad 100644 --- a/qtensor/tests/test_bucket_backends.py +++ b/qtensor/tests/test_bucket_backends.py @@ -7,9 +7,6 @@ def get_test_problem(): - w = np.array([[0,1,1,0],[1,0,1,1],[1,1,0,1],[0,1,1,0]]) - G = nx.from_numpy_matrix(w) - G = nx.random_regular_graph(5, 14) gamma, beta = [np.pi/3], [np.pi/2] return G, gamma, beta diff --git a/qtensor/tests/test_composers.py b/qtensor/tests/test_composers.py index aa8b710f..582e8125 100644 --- a/qtensor/tests/test_composers.py +++ b/qtensor/tests/test_composers.py @@ -10,7 +10,7 @@ def get_test_problem(): w = np.array([[0,1,1,0],[1,0,1,1],[1,1,0,1],[0,1,1,0]]) - G = nx.from_numpy_matrix(w) + G = nx.from_numpy_array(w) gamma, beta = [np.pi/3], [np.pi/2] return G, gamma, beta diff --git a/qtensor/tests/test_optimizers.py b/qtensor/tests/test_optimizers.py index 0f052495..1332191f 100644 --- a/qtensor/tests/test_optimizers.py +++ b/qtensor/tests/test_optimizers.py @@ -11,8 +11,6 @@ import pytest def get_test_problem(n=14, p=2, d=3): - w = np.array([[0,1,1,0],[1,0,1,1],[1,1,0,1],[0,1,1,0]]) - G = nx.from_numpy_matrix(w) G = nx.random_regular_graph(d, n) gamma, beta = [np.pi/3]*p, [np.pi/2]*p diff --git a/qtensor/tests/test_qaoa_energy.py b/qtensor/tests/test_qaoa_energy.py index 99a1679a..cc471ef7 100644 --- a/qtensor/tests/test_qaoa_energy.py +++ b/qtensor/tests/test_qaoa_energy.py @@ -11,6 +11,7 @@ from qtensor.FeynmanSimulator import FeynmanSimulator from qtensor.optimisation.Optimizer import TamakiTrimSlicing, TreeTrimSplitter from qtensor.tests.qiskit_qaoa_energy import simulate_qiskit_amps +qiskit_aer = pytest.importorskip('qiskit_aer') @lru_cache def get_test_problem(n=10, p=2, d=3, type='random'): diff --git a/qtensor/tests/test_simulators.py b/qtensor/tests/test_simulators.py index 836abbf4..61e14891 100644 --- a/qtensor/tests/test_simulators.py +++ b/qtensor/tests/test_simulators.py @@ -10,9 +10,6 @@ def get_test_problem(n=14, p=2, d=3): - w = np.array([[0,1,1,0],[1,0,1,1],[1,1,0,1],[0,1,1,0]]) - G = nx.from_numpy_matrix(w) - G = nx.random_regular_graph(d, n) gamma, beta = [np.pi/3]*p, [np.pi/2]*p return G, gamma, beta diff --git a/qtree b/qtree index c88e79f7..349a3846 160000 --- a/qtree +++ b/qtree @@ -1 +1 @@ -Subproject commit c88e79f7865628b5140d5ed1ac3f2cc49232ea1a +Subproject commit 349a38463fc03ce3dd53198623f579c32b2397b0 diff --git a/setup.py b/setup.py index f491bce6..c47f75f1 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,6 @@ 'matplotlib>=3.1.3' ,'google-api-core[grpc]<=1.14.0' ,'cirq' - ,'qiskit' ,'qiskit-optimization' ,'pyrofiler>=0.1.5' ,'loguru'