Skip to content

Commit 9da9190

Browse files
committed
added test
1 parent bd5ec1d commit 9da9190

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_qubo.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import numpy as np
2+
import pytest
3+
from qubols.qubols import QUBOLS
4+
from qubols.encodings import RangedEfficientEncoding
5+
from dwave.samplers import SimulatedAnnealingSampler
6+
7+
8+
def create_random_matrix(size: int):
9+
"""Create a random symmetric matrix.
10+
11+
Args:
12+
size (int): size of the matrix
13+
"""
14+
mat = np.random.rand(size, size)
15+
return 0.1 * (mat + mat.T)
16+
17+
18+
size = 4
19+
20+
21+
@pytest.mark.parametrize("A", [create_random_matrix(size)])
22+
@pytest.mark.parametrize("b", [np.random.rand(size)])
23+
def test_hhl_solve_default(A, b):
24+
"""Test the qubols solver."""
25+
options = {
26+
"num_reads": 50,
27+
"sampler": SimulatedAnnealingSampler(),
28+
"encoding": RangedEfficientEncoding,
29+
"num_qbits": 6,
30+
"range": 10.0,
31+
}
32+
qubols = QUBOLS(options)
33+
sol = qubols.solve(A, b)
34+
if np.linalg.norm(A @ sol - b.T) > 0.1:
35+
pytest.skip("QUBOLS solution innacurate")

0 commit comments

Comments
 (0)