Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.

Commit 6b86c69

Browse files
authored
Merge pull request #137 from arcondello/bug/python-timeout
Fix timeout issues
2 parents b513185 + 1c5c513 commit 6b86c69

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

python/dwave_qbsolv/qbsolv_binding.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def run_qbsolv(Q, num_repeats=50, seed=17932241798878, verbosity=-1,
9999
else:
100100
raise ValueError('unknown algorithm given')
101101

102-
if not isinstance(timeout, int) or timeout <= 0:
103-
raise ValueError("'timeout' must be a positive integer")
102+
if timeout <= 0:
103+
raise ValueError("'timeout' must be positive")
104104
global Time_
105105
Time_ = timeout # the maximum runtime of the algorithm in seconds before timeout (2592000 = a month's worth of seconds)
106106

python/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
dimod==0.7.2
2-
cython==0.28.4
1+
dimod==0.8.1
2+
cython==0.29.2
33

44
coverage
55
codecov

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
extra_compile_args = {
2020
'msvc': [],
21-
'unix': ['-std=c++11', '-Ofast', '-Wall', '-Wextra', '-flto'],
21+
'unix': ['-std=c++11', '-Ofast', '-Wall', '-Wextra'],
2222
# 'unix': ['-std=c++1y','-w','-O0', '-g', '-fipa-pure-const'],
2323
}
2424

@@ -78,7 +78,7 @@ def build_extensions(self):
7878
version='0.2.9',
7979
packages=packages,
8080
package_dir={'dwave_qbsolv': 'python/dwave_qbsolv'},
81-
install_requires=['dimod>=0.6.10,<0.8.0'],
81+
install_requires=['dimod>=0.6.10,<0.9.0'],
8282
ext_modules=extensions,
8383
cmdclass={'build_ext': build_ext_compiler_check},
8484
long_description=open('README.rst').read(),

tests/test_dwave_qbsolv.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
2+
import time
33
import itertools
44

55
import dwave_qbsolv as qbs
@@ -69,3 +69,18 @@ def test_energy_calculation(self):
6969

7070
for sample, energy in response.data(['sample', 'energy']):
7171
self.assertAlmostEqual(dimod.ising_energy(sample, h, J), energy)
72+
73+
# these tests are hard to automate for CI because different systems have different
74+
# speeds
75+
# def test_timeout_parameter(self):
76+
# # set up a problem we hope will take a long time
77+
# Q = {edge: random.uniform(-1, 1) for edge in itertools.combinations_with_replacement(range(500), 2)}
78+
79+
# timeout = 1 # in seconds
80+
81+
# t = time.time()
82+
83+
# response = qbs.QBSolv().sample_qubo(Q, timeout=timeout) # seconds to millisconds
84+
85+
# # let's be generous and give it 3x the timeout
86+
# self.assertLessEqual(time.time() - t, 3*timeout)

0 commit comments

Comments
 (0)