Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Run to time limit for Neal and Greedy #27

Open
kevinchern opened this issue Jun 22, 2022 · 2 comments
Open

[Feature Request] Run to time limit for Neal and Greedy #27

kevinchern opened this issue Jun 22, 2022 · 2 comments

Comments

@kevinchern
Copy link
Contributor

Would be useful to have a time_limit argument for Neal and Greedy.
Both Neal (for a fixed num_sweeps) and Greedy can implement a run-to-time-limit feature by adding timing calls per read, i.e., variable number of reads depending on time constraint. Example from RandomSampler.

@CatherineCMcGeoch
Copy link

Pau has implemented a smart runtime estimator that self-adjusts its convergence rate if necessary. It works pretty well, I believe, might want to ask him about it when he gets back. (Or maybe he has put it in github I dunno)

@jackraymond
Copy link
Contributor

jackraymond commented Jun 30, 2023

If you wish to evaluate a criteria only after each complete anneal this feature already exists through the interrupt function:

import time
t0 = time.perf_counter_ns()
def interrupt_function():
    time_limit = 0 #Any value in nanoseconds
    if time.perf_counter_ns() - t0 > delay:
        return True
    else:
        return False
from dwave.samplers.sa import SimulatedAnnealingSampler
num_reads = 1000 #example 
resp  = SimulatedAnnealingSampler().sample_ising({i: 1}, {}, interrupt_function, num_reads = num_reads)
assert len(resp.record) == 1  # because time_limit of 0 nanoseconds is immediately exceeded.

For greater flexibility the code could be rewritten so that interrupt function takes sample information (in order to do things like time to energy/diversity criteria). Another possibility would be to evaluate the interrupt function before the anneal completes, but I think there wouldn't be many use cases for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants