forked from LucasBerger/quantum-vrp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f11219f
commit 8866b82
Showing
10 changed files
with
143 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
things to install: | ||
|
||
- LKH binary (either install from source or just download) | ||
- setup dwave.conf in user directory | ||
- install poetry to use as a package manager for the python libraries | ||
- install rust nightly version from 2023-07-01. use rustup to change the version used in this directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
qubo-solver | ||
# Python QUBO Solver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
from typing import Literal | ||
from dimod import BinaryQuadraticModel, Sampler, SimulatedAnnealingSampler, SampleSet | ||
|
||
from dimod import BinaryQuadraticModel, Sampler, SampleSet, SimulatedAnnealingSampler | ||
from dwave.system import DWaveSampler, EmbeddingComposite, LeapHybridSampler | ||
from hybrid import SimplifiedQbsolv, State | ||
|
||
solvertype = Literal['sim', 'hybrid', 'qbsolv', 'direct'] | ||
solvertype = Literal["sim", "hybrid", "qbsolv", "direct"] | ||
|
||
|
||
def solve_with(bqm: BinaryQuadraticModel, type: solvertype, label: str) -> SampleSet: | ||
|
||
if type == 'sim': | ||
if type == "sim": | ||
sampler: Sampler = SimulatedAnnealingSampler() | ||
return sampler.sample(bqm) | ||
elif type == 'direct': | ||
elif type == "direct": | ||
sampler: Sampler = EmbeddingComposite(DWaveSampler()) | ||
return sampler.sample( | ||
bqm, num_reads=250, label=f"DWaveSampler with embedding num_reads=250 {label}" | ||
bqm, | ||
num_reads=250, | ||
label=f"DWaveSampler with embedding num_reads=250 {label}", | ||
) | ||
elif type == 'hybrid': | ||
elif type == "hybrid": | ||
sampler: Sampler = LeapHybridSampler() | ||
return sampler.sample( | ||
bqm, time_limit=10, label=f"LeapHybridSampler num_reads=250: {label}" | ||
) | ||
elif type == 'qbsolv': | ||
elif type == "qbsolv": | ||
init_state = State.from_problem(bqm) | ||
workflow = SimplifiedQbsolv() | ||
final_state = workflow.run(init_state).result() | ||
return final_state.samples | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.