Combining Results of Paralellized Simulated Annealing

Hi, I am working on a fairly large qubo model (1134 variables). I was looking into parallelizing the simulated annealer - to run multiple instances of the solver at once. But that made me think and I realised that the results of each run are going to be separated, and I will have to apply my post processing on each of the run's result separately.

So my question is, is parallelizing the simulated annealer possible or does it already utilize all cores, and if yes, then how do I combine the results of the multiple runs into a single result.

In simpler words, if I run 2 instances of simulated annealing with num reads set to 1000, how do I combine the results to be able to treat them as a result of a single run with num_reads set to 2000

def solver(numreads, timelimit):
  print("running solver")
  # sampler = LeapHybridSampler()
  # sampleset = sampler.sample(new_bqm, time_limit = timelimit,)
  sampler = neal.SimulatedAnnealingSampler()
  sampleset = sampler.sample(new_bqm,num_reads = numreads)
  # sampler = EmbeddingComposite(DWaveSampler())
  # sampleset = sampler.sample(new_bqm, num_reads = 1000)
    return sampleset

t1 = time.perf_counter()
numreads = 10000
timelimit = 90
samplesets = []

with concurrent.futures.ThreadPoolExecutor() as executor:

    results = [executor.submit(solver, numreads,timelimit) for _ in range(8)]

    for f in concurrent.futures.as_completed(results):

        samplesets.append(f.result())

        # print(f.result())

if __name__ == '__solver__':

    solver(numreads,timelimit)

t2 = time.perf_counter()

print(f'solver finished in {t2-t1} seconds')
0

Comments

3 comments
  • Hello,

    Currently the SimulatedAnnealingSampler runs in serial, but could be run in parallel using multithreading.

    SampleSet objects can be combined using dimod.concatenate().

    Please let us know if you have any questions.

    0
    Comment actions Permalink
  • Hi David,
    I am using multithreading as in the codeblock on my original post. My question arose due to a doubt, that do running simulated annealers in parallel take into account overlaps of the samples? If I set num_reads to 2000 and run the annealer on 4 different threads, is it equivalent to running a simulated annealer on a single thread with numreads set to 8000?
    By my understanding, running 4 simulated annealing samplers in parallel won't have data from each other, so it's possible multiple threads waste processing time on the same samples. So realistically 4 annealers in parallel with num_reads at 2000 might end up having less than 8000 unique samples total.

    Please let me know if I am correct or if I have misunderstood the working of simulated annealing.

    0
    Comment actions Permalink
  • Hello,

    The SimulatedAnnealingSampler is a classical heuristic algorithm that runs locally. Depending on how the problem is configured, there might be many unique solutions or only a few.

    The advantage of running the samplers in parallel in this case is that they could be delegated to different CPUs on the local machine, gaining a speed boost by running in parallel. 

    If four simulated annealing samplers were run in parallel, it would be the same as running one sampler for four times the number of reads. 

    For each sample call, the results don't affect the next sample call by default. This is the same for a single solver running in a single thread, or multiple solvers running in parallel threads. Any interactions between two runs need to be explicitly programmed by having the output of one run affect the input of the next run. Reads within a run are all completely independent of one another as well by default. 

    Once the run has finished, the best of the available results is selected. In general, the results will have varying energy values, some lower than others.

    There are a number of parameters and customizations you can make to each sample call that can change the default behaviour. To get an idea of what's available, you can take a look at the neal.sampler.SimulatedAnnealingSampler.sample documentation, which provides a list of method parameters with descriptions. 

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post