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

Commit

Permalink
Fix the timeout flag in the python wrapper
Browse files Browse the repository at this point in the history
The timeout was incorrectly expressed as an integer in terms of
milliseconds. It now correctly works as a float in terms of
seconds.
  • Loading branch information
arcondello committed Jan 3, 2019
1 parent 2d0f2d8 commit 1c5c513
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python/dwave_qbsolv/qbsolv_binding.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def run_qbsolv(Q, num_repeats=50, seed=17932241798878, verbosity=-1,
else:
raise ValueError('unknown algorithm given')

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

Expand Down
17 changes: 16 additions & 1 deletion tests/test_dwave_qbsolv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest

import time
import itertools

import dwave_qbsolv as qbs
Expand Down Expand Up @@ -69,3 +69,18 @@ def test_energy_calculation(self):

for sample, energy in response.data(['sample', 'energy']):
self.assertAlmostEqual(dimod.ising_energy(sample, h, J), energy)

# these tests are hard to automate for CI because different systems have different
# speeds
# def test_timeout_parameter(self):
# # set up a problem we hope will take a long time
# Q = {edge: random.uniform(-1, 1) for edge in itertools.combinations_with_replacement(range(500), 2)}

# timeout = 1 # in seconds

# t = time.time()

# response = qbs.QBSolv().sample_qubo(Q, timeout=timeout) # seconds to millisconds

# # let's be generous and give it 3x the timeout
# self.assertLessEqual(time.time() - t, 3*timeout)

0 comments on commit 1c5c513

Please sign in to comment.