in src/braket/ocean_plugin/braket_sampler.py [0:0]
def sample_qubo_quantum_task(self, Q: Dict[Tuple[int, int], int], **kwargs) -> QuantumTask:
"""
Sample from the specified QUBO and return a `QuantumTask`. This has the same inputs
as `BraketSampler.sample_qubo`
Args:
Q (dict):
Coefficients of a quadratic unconstrained binary optimization (QUBO) model.
**kwargs:
Optional keyword arguments for the sampling method in Braket boto3 format
Returns:
:class:`dimod.SampleSet`: A `dimod` :obj:`~dimod.SampleSet` object.
Raises:
BinaryQuadraticModelStructureError: If problem graph is incompatible with solver
ValueError: If keyword argument is unsupported by solver
Examples:
This example submits a two-variable QUBO mapped directly to qubits
0 and 4 on a sampler on the D-Wave 2000Q device.
>>> from braket.ocean_plugin import BraketSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6"
>>> sampler = BraketSampler(s3_destination_folder, device_arn_1)
>>> Q = {(0, 0): -1, (4, 4): -1, (0, 4): 2}
>>> task = sampler.sample_qubo_quantum_task(Q, resultFormat="HISTOGRAM", shots=100)
>>> sampleset = BraketSampler.get_task_sample_set(task)
>>> for sample in sampleset.samples():
... print(sample)
...
{0: 0, 4: 1}
{0: 1, 4: 0}
This example submits a two-variable QUBO mapped directly to qubits
30 and 31 on a sampler on the D-Wave Advantage4 device.
>>> from braket.ocean_plugin import BraketSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/Advantage_system4"
>>> sampler = BraketSampler(s3_destination_folder, device_arn_1)
>>> Q = {(30, 30): -1, (31, 31): -1, (30, 31): 2}
>>> task = sampler.sample_qubo_quantum_task(Q, resultFormat="HISTOGRAM", shots=100)
>>> sampleset = BraketSampler.get_task_sample_set(task)
>>> for sample in sampleset.samples():
... print(sample)
...
{30: 0, 31: 1}
{30: 1, 31: 0}
"""
solver_kwargs = self._process_solver_kwargs(**kwargs)
sorted_edges = frozenset((u, v) if u < v else (v, u) for u, v in Q)
print(self._access_optimized_edgelist())
for u, v in sorted_edges:
if u not in self._access_optimized_nodelist():
raise BinaryQuadraticModelStructureError(
"Problem graph incompatible with solver. Qubit "
+ str(u)
+ " is not in the device's qubit set."
)
if v not in self._access_optimized_edgelist().get(u, ()) and u != v:
raise BinaryQuadraticModelStructureError(
"Problem graph incompatible with solver. Solver nodes "
+ str(u)
+ " and "
+ str(v)
+ " are not connected."
)
linear = {}
quadratic = {}
for (u, v), bias in Q.items():
if u == v:
linear[u] = bias
else:
quadratic[(u, v)] = bias
return self.solver.run(
Problem(ProblemType.QUBO, linear, quadratic),
self._s3_destination_folder,
logger=self._logger,
**solver_kwargs,
)