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

Switch samplers #14

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import sys
import unittest
import random
import math

import neal
import dimod
import numpy as np
from dwave.samplers import SimulatedAnnealingSampler
from dwave.system import LeapHybridSampler

import demo
import demo_numpy
Expand Down Expand Up @@ -58,7 +60,7 @@ def test_num_new_cs(self):

bqm = demo.build_bqm(potential_new_cs_nodes, num_poi, pois, num_cs, charging_stations, num_new_cs)

sampler = neal.SimulatedAnnealingSampler()
sampler = SimulatedAnnealingSampler()
new_charging_nodes = demo.run_bqm_and_collect_solutions(bqm, sampler, potential_new_cs_nodes)

self.assertEqual(num_new_cs, len(new_charging_nodes))
Expand All @@ -77,8 +79,8 @@ def test_close_to_pois(self):
bqm = demo.build_bqm(potential_new_cs_nodes, num_poi, pois, num_cs, charging_stations, num_new_cs)

# random.seed(1)
sampler = neal.SimulatedAnnealingSampler()
new_charging_nodes = demo.run_bqm_and_collect_solutions(bqm, sampler, potential_new_cs_nodes, seed=42)
sampler = LeapHybridSampler()
new_charging_nodes = demo.run_bqm_and_collect_solutions(bqm, sampler, potential_new_cs_nodes)

new_cs_x = new_charging_nodes[0][0]
new_cs_y = new_charging_nodes[0][1]
Expand All @@ -97,13 +99,10 @@ def test_solution_quality(self):
bqm = demo.build_bqm(potential_new_cs_nodes, num_poi, pois, num_cs, charging_stations, num_new_cs)

# random.seed(1)
sampler = neal.SimulatedAnnealingSampler()
new_charging_nodes = demo.run_bqm_and_collect_solutions(bqm, sampler, potential_new_cs_nodes, seed=1)
sampler = LeapHybridSampler()
new_charging_nodes = demo.run_bqm_and_collect_solutions(bqm, sampler, potential_new_cs_nodes)

new_cs_dist = 0
for i in range(num_new_cs):
for j in range(i+1, num_new_cs):
new_cs_dist += abs(new_charging_nodes[i][0]-new_charging_nodes[j][0])+abs(new_charging_nodes[i][1]-new_charging_nodes[j][1])
new_cs_dist = math.sqrt(demo.distance(new_charging_nodes[0], new_charging_nodes[1]))

self.assertGreater(new_cs_dist, 10)

Expand Down