@@ -90,6 +90,56 @@ Simple Sampling Example
90
90
91
91
.. _qpu_workflow_simple_example :
92
92
93
- .. todo :: add example: Simple Workflow Example
94
-
95
- Simple Workflow Example (title)
93
+ Simple Workflow Example
94
+ =======================
95
+
96
+ This example uses the :ref: `Ocean software <index_ocean_sdk >` package,
97
+ :ref: `index_dimod `, to formulate a small objective function: the
98
+ :func: `~dimod.generators.combinations ` function generates a :term: `BQM ` that
99
+ represents the problem of selecting exactly :math: `k` of :math: `n` binary
100
+ variables.
101
+
102
+ The following code creates a BQM that is minimized when exactly two
103
+ (:math: `k=2 `) of the three (:math: `n=3 `) variables :code: `a, b, c ` are
104
+ :math: `1 `:
105
+
106
+ >>> import dimod
107
+ >>> bqm = dimod.generators.combinations([' a' , ' b' , ' c' ], 2 )
108
+
109
+ Now solve on a |dwave_short | quantum computer using the
110
+ :class: `~dwave.system.samplers.DWaveSampler ` sampler from Ocean software's
111
+ :ref: `index_system ` package. Also use its
112
+ :class: `~dwave.system.composites.EmbeddingComposite ` composite to map the
113
+ unstructured problem (variables such as :math: `a` etc.) to the sampler's
114
+ :ref: `graph structure <qpu_topologies >` (the QPU's numerically indexed qubits)
115
+ in a process known as :term: `minor-embedding `.
116
+
117
+ The next code sets up a D-Wave quantum computer as the sampler.
118
+
119
+ .. include :: ../shared/examples.rst
120
+ :start-after: start_default_solver_config
121
+ :end-before: end_default_solver_config
122
+
123
+ >>> from dwave.system import DWaveSampler, EmbeddingComposite
124
+ >>> sampler = EmbeddingComposite(DWaveSampler())
125
+
126
+ Because the sampled solution is probabilistic, returned solutions may differ
127
+ between runs. Typically, when submitting a problem to the system, you ask for
128
+ many samples, not just one. This way, you see multiple “best” answers and reduce
129
+ the probability of settling on a suboptimal answer. Below, ask for 1000 samples.
130
+
131
+ >>> sampleset = sampler.sample(bqm, num_reads = 1000 , label = ' SDK Examples - QPU Workflow' )
132
+ >>> print (sampleset) # doctest: +SKIP
133
+ a b c energy num_oc. chain_.
134
+ 0 1 1 0 0.0 323 0.0
135
+ 1 1 0 1 0.0 339 0.0
136
+ 2 0 1 1 0.0 336 0.0
137
+ 3 1 1 1 1.0 1 0.0
138
+ 4 1 0 0 1.0 1 0.0
139
+ ['BINARY', 5 rows, 1000 samples, 3 variables]
140
+
141
+ Almost all the returned samples represent valid value assignments for the
142
+ :math: `\binom {N}{k}` problem, and minima (low-energy states) of the BQM, and
143
+ with high likelihood the best (lowest-energy: here :math: `0.0 ` in the
144
+ :code: `energy ` column) samples satisfy the formulation (two :math: `1 `\ s among
145
+ the three variables columns, :code: `a, b, c `).
0 commit comments