Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit f7a63d7

Browse files
authored
Merge pull request #14 from JoelPasvolsky/label
Add problem label
2 parents ecb3cfa + 05b990a commit f7a63d7

File tree

6 files changed

+48
-37
lines changed

6 files changed

+48
-37
lines changed

BQM_Functionality/bqm_conversion.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
# --------------------------------------------------------------------------#
1616

17-
# This program demonstrates a basic Ocean program that runs an Ising problem
18-
# (from a BQM) on the D-Wave QPU.
17+
# This program demonstrates a basic Ocean program that runs an Ising problem
18+
# (from a BQM) on the D-Wave QPU.
1919

2020
# --------------------------------------------------------------------------#
2121

@@ -24,10 +24,10 @@
2424
from dimod import BinaryQuadraticModel
2525

2626
# Define the problem as a Python dictionary and convert it to a BQM
27-
Q = {('B','B'): 1,
28-
('K','K'): 1,
29-
('A','C'): 2,
30-
('A','K'): -2,
27+
Q = {('B','B'): 1,
28+
('K','K'): 1,
29+
('A','C'): 2,
30+
('A','K'): -2,
3131
('B','C'): -2}
3232

3333
bqm = BinaryQuadraticModel.from_qubo(Q)
@@ -40,8 +40,9 @@
4040

4141
# Run the problem on the sampler and print the results
4242
sampleset = sampler.sample_ising(
43-
h = ising_model[0],
44-
J = ising_model[1],
45-
num_reads = 10)
46-
43+
h = ising_model[0],
44+
J = ising_model[1],
45+
num_reads = 10,
46+
label='Example - Simple Ocean Programs: Conversion')
47+
4748
print(sampleset)

BQM_Functionality/bqm_offsets.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# --------------------------------------------------------------------------#
1616

1717
# This program demonstrates a basic Ocean program that creates a
18-
# BinaryQuadraticModel with a non-zero offset to store a constant term.
18+
# BinaryQuadraticModel with a non-zero offset to store a constant term.
1919

2020
# --------------------------------------------------------------------------#
2121

@@ -24,24 +24,28 @@
2424
from dimod import BinaryQuadraticModel
2525

2626
# Define the problem as a Python dictionary and convert it to a BQM
27-
Q = {('B','B'): 1,
28-
('K','K'): 1,
29-
('A','C'): 2,
30-
('A','K'): -2,
27+
Q = {('B','B'): 1,
28+
('K','K'): 1,
29+
('A','C'): 2,
30+
('A','K'): -2,
3131
('B','C'): -2}
32-
32+
3333
bqm = BinaryQuadraticModel.from_qubo(Q, offset=1.0)
3434

3535
# Define the sampler that will be used to run the problem
3636
sampler = EmbeddingComposite(DWaveSampler())
3737

3838
# Run the problem on the sampler and print the results
39-
sampleset = sampler.sample(bqm, num_reads = 10)
39+
sampleset = sampler.sample(bqm,
40+
num_reads = 10,
41+
label='Example - Simple Ocean Programs: Offsets')
4042
print("QUBO samples:")
4143
print(sampleset)
4244

4345
# Convert the problem to an Ising model and run it on the sampler
4446
bqm.change_vartype('SPIN')
45-
sampleset = sampler.sample(bqm, num_reads = 10)
47+
sampleset = sampler.sample(bqm,
48+
num_reads = 10,
49+
label='Example - Simple Ocean Programs: Offsets')
4650
print("\nIsing samples:")
4751
print(sampleset)

BQM_Functionality/general_program_bqm.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
from dimod import BinaryQuadraticModel
2525

2626
# Define the problem as a Python dictionary and convert it to a BQM
27-
Q = {('B','B'): 1,
28-
('K','K'): 1,
29-
('A','C'): 2,
30-
('A','K'): -2,
27+
Q = {('B','B'): 1,
28+
('K','K'): 1,
29+
('A','C'): 2,
30+
('A','K'): -2,
3131
('B','C'): -2}
3232

3333
# Convert the problem to a BQM
@@ -37,5 +37,7 @@
3737
sampler = EmbeddingComposite(DWaveSampler())
3838

3939
# Run the problem on the sampler and print the results
40-
sampleset = sampler.sample(bqm, num_reads = 10)
40+
sampleset = sampler.sample(bqm,
41+
num_reads = 10,
42+
label='Example - Simple Ocean Programs: BQM')
4143
print(sampleset)

Basic_Programs/general_program_ising.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@
1414

1515
# --------------------------------------------------------------------------#
1616

17-
# This program demonstrates a basic Ocean program that runs an Ising problem
18-
# on the D-Wave QPU.
17+
# This program demonstrates a basic Ocean program that runs an Ising problem
18+
# on the D-Wave QPU.
1919

2020
# --------------------------------------------------------------------------#
2121

2222
# Import the functions and packages that are used
2323
from dwave.system import EmbeddingComposite, DWaveSampler
2424

25-
# Define the problem as two Python dictionaries:
25+
# Define the problem as two Python dictionaries:
2626
# h for linear terms, J for quadratic terms
27-
h = {}
28-
J = {('A','K'): -0.5,
27+
h = {}
28+
J = {('A','K'): -0.5,
2929
('B','C'): -0.5,
30-
('A','C'): 0.5}
30+
('A','C'): 0.5}
3131

3232
# Define the sampler that will be used to run the problem
3333
sampler = EmbeddingComposite(DWaveSampler())
3434

3535
# Run the problem on the sampler and print the results
36-
sampleset = sampler.sample_ising(h, J, num_reads = 10)
36+
sampleset = sampler.sample_ising(h, J,
37+
num_reads = 10,
38+
label='Example - Simple Ocean Programs: Ising')
3739
print(sampleset)

Basic_Programs/general_program_qubo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,25 @@
1515
# --------------------------------------------------------------------------#
1616

1717
# This program demonstrates a basic Ocean program that runs a QUBO problem on
18-
# the D-Wave QPU.
18+
# the D-Wave QPU.
1919

2020
# --------------------------------------------------------------------------#
2121

2222
# Import the functions and packages that are used
2323
from dwave.system import EmbeddingComposite, DWaveSampler
2424

2525
# Define the problem as a Python dictionary
26-
Q = {('B','B'): 1,
27-
('K','K'): 1,
28-
('A','C'): 2,
29-
('A','K'): -2,
26+
Q = {('B','B'): 1,
27+
('K','K'): 1,
28+
('A','C'): 2,
29+
('A','K'): -2,
3030
('B','C'): -2}
3131

3232
# Define the sampler that will be used to run the problem
3333
sampler = EmbeddingComposite(DWaveSampler())
3434

3535
# Run the problem on the sampler and print the results
36-
sampleset = sampler.sample_qubo(Q, num_reads = 10)
36+
sampleset = sampler.sample_qubo(Q,
37+
num_reads = 10,
38+
label='Example - Simple Ocean Programs: QUBO')
3739
print(sampleset)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
dwave-ocean-sdk>=3.1.1
1+
dwave-ocean-sdk>=3.3.0
22
matplotlib

0 commit comments

Comments
 (0)