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

Commit 1c5c513

Browse files
committed
Fix the timeout flag in the python wrapper
The timeout was incorrectly expressed as an integer in terms of milliseconds. It now correctly works as a float in terms of seconds.
1 parent 2d0f2d8 commit 1c5c513

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
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

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)