Skip to content

Commit ff785e6

Browse files
committed
added more tests
1 parent 0f4f39a commit ff785e6

File tree

3 files changed

+25
-65
lines changed

3 files changed

+25
-65
lines changed

qhdopt/backend/baseline_backend.py

-47
This file was deleted.

qhdopt/qhd_base.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sympy import lambdify, Symbol, Function
55
import jax.numpy as jnp
66

7-
from qhdopt.backend import dwave_backend, ionq_backend, qutip_backend, baseline_backend
7+
from qhdopt.backend import dwave_backend, ionq_backend, qutip_backend
88
from qhdopt.response import Response
99
from qhdopt.utils.function_preprocessing_utils import decompose_function
1010

@@ -152,23 +152,6 @@ def qutip_setup(
152152
gamma=gamma,
153153
)
154154

155-
def baseline_setup(
156-
self,
157-
shots: int = 100,
158-
) -> None:
159-
"""
160-
Sets up a classical baseline backend.
161-
162-
Args:
163-
shots: Number of sampling shots for baseline method.
164-
"""
165-
self.backend = baseline_backend.BaselineBackend(
166-
dimension=self.dimension,
167-
univariate_dict=self.univariate_dict,
168-
bivariate_dict=self.bivariate_dict,
169-
shots=shots,
170-
)
171-
172155
def compile_only(self):
173156
self.backend.compile(self.info)
174157
return self.backend

tests/test_backend.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
3+
from qhdopt import QHD
4+
from qhdopt.backend.dwave_backend import DWaveBackend
5+
6+
def test_backend_performance():
7+
Q = [[-2, 1],
8+
[1, -1]]
9+
bt = [3 / 4, -1 / 4]
10+
sol = -.75
11+
model = QHD.QP(Q, bt)
12+
response = model.classically_optimize(solver="IPOPT", verbose=1)
13+
assert abs(response.minimum - sol) < 1e-3
14+
15+
model.qutip_setup(resolution=6, time_discretization=40)
16+
model.optimize(verbose=1)
17+
assert abs(response.minimum - sol) < 1e-3
18+
model.ionq_setup(resolution=6, api_key='ionq_API_key', time_discretization=5,
19+
shots=1000, on_simulator=True)
20+
ionq_backend = model.compile_only()
21+
assert len(ionq_backend.qs.evos) == 5
22+
23+
24+

0 commit comments

Comments
 (0)