This repository was archived by the owner on Dec 4, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +48
-37
lines changed
Expand file tree Collapse file tree 6 files changed +48
-37
lines changed Original file line number Diff line number Diff line change 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
2424from 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
3333bqm = BinaryQuadraticModel .from_qubo (Q )
4040
4141# Run the problem on the sampler and print the results
4242sampleset = 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+
4748print (sampleset )
Original file line number Diff line number Diff line change 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
2424from 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+
3333bqm = BinaryQuadraticModel .from_qubo (Q , offset = 1.0 )
3434
3535# Define the sampler that will be used to run the problem
3636sampler = 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' )
4042print ("QUBO samples:" )
4143print (sampleset )
4244
4345# Convert the problem to an Ising model and run it on the sampler
4446bqm .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' )
4650print ("\n Ising samples:" )
4751print (sampleset )
Original file line number Diff line number Diff line change 2424from 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
3737sampler = 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' )
4143print (sampleset )
Original file line number Diff line number Diff line change 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
2323from 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
3333sampler = 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' )
3739print (sampleset )
Original file line number Diff line number Diff line change 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
2323from 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
3333sampler = 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' )
3739print (sampleset )
Original file line number Diff line number Diff line change 1- dwave-ocean-sdk >= 3.1.1
1+ dwave-ocean-sdk >= 3.3.0
22matplotlib
You can’t perform that action at this time.
0 commit comments