Skip to content

Commit

Permalink
update qiskit simulator usage, skip test on missing qiskit
Browse files Browse the repository at this point in the history
  • Loading branch information
danlkv committed Apr 25, 2024
1 parent 26cda54 commit 2f6a462
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion qtensor/optimisation/Optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions qtensor/tests/qiskit_qaoa_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions qtensor/tests/test_bucket_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qtensor/tests/test_composers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions qtensor/tests/test_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions qtensor/tests/test_qaoa_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
3 changes: 0 additions & 3 deletions qtensor/tests/test_simulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qtree
Submodule qtree updated from c88e79 to 349a38
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'matplotlib>=3.1.3'
,'google-api-core[grpc]<=1.14.0'
,'cirq'
,'qiskit'
,'qiskit-optimization'
,'pyrofiler>=0.1.5'
,'loguru'
Expand Down

0 comments on commit 2f6a462

Please sign in to comment.