braket.ocean_plugin.braket_dwave_sampler module

class braket.ocean_plugin.braket_dwave_sampler.BraketDWaveSampler(s3_destination_folder: Optional[braket.aws.aws_session.S3DestinationFolder] = None, device_arn: Optional[str] = None, aws_session: Optional[braket.aws.aws_session.AwsSession] = None, logger: logging.Logger = <Logger braket.ocean_plugin.braket_dwave_sampler (WARNING)>)[source]

Bases: braket.ocean_plugin.braket_sampler.BraketSampler

A class for using DWave-formatted parameters and properties with Amazon Braket as a sampler.

Parameters:
  • s3_destination_folder (AwsSession.S3DestinationFolder) – NamedTuple with bucket (index 0) and key (index 1) that is the results destination folder in S3.
  • device_arn (str) – AWS quantum device arn. Default is the latest D-Wave QPU device ARN.
  • aws_session (AwsSession) – AwsSession to call AWS with.
  • logger (Logger) – Python Logger object with which to write logs, such as QuantumTask statuses while polling for task to complete. Default is getLogger(__name__)

Examples

>>> from braket.ocean_plugin import BraketDWaveSampler
>>> s3_destination_folder = ('test_bucket', 'test_folder')
>>> sampler = BraketDWaveSampler(s3_destination_folder)
properties

Solver properties in D-Wave format.

D-Wave System Documentation describes the parameters and properties supported on the D-Wave system.

Solver properties are dependent on the selected solver and subject to change; for example, new released features may add properties.

Type:FrozenDict[str, Any]
parameters

Solver parameters in the form of a dict, where keys are keyword parameters in D-Wave format and values are lists of properties in BraketSampler.properties for each key.

D-Wave System Documentation describes the parameters and properties supported on the D-Wave system.

Solver parameters are dependent on the selected solver and subject to change; for example, new released features may add parameters.

Type:FrozenDict[str, List]
sample_ising(h: Union[Dict[int, float], List[float]], J: Dict[Tuple[int, int], float], **kwargs) → dimod.sampleset.SampleSet[source]

Sample from the specified Ising model.

Parameters:
  • h (dict/list) – Linear biases of the Ising model. If a dict, should be of the form {v: bias, ...} where v is a spin-valued variable and bias is its associated bias. If a list, it is treated as a list of biases where the indices are the variable labels, except in the case of missing qubits in which case 0 biases are ignored while a non-zero bias set on a missing qubit raises an error.
  • J (dict[(int, int) – float]): Quadratic biases of the Ising model.
  • **kwargs – Optional keyword arguments for the sampling method in D-Wave format
Returns:

dimod.SampleSet – A dimod SampleSet object.

Examples

This example submits a two-variable Ising problem mapped directly to qubits 0 and 1 on a D-Wave 2000Q device.

>>> from braket.ocean_plugin import BraketDWaveSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6"
>>> sampler = BraketDWaveSampler(device_arn_1)
>>> h = {0: -1, 1: 1}
>>> sampleset = sampler.sample_ising(h, {}, answer_mode="HISTOGRAM")
>>> for sample in sampleset.samples():
...    print(sample)
...
{0: 1, 1: -1}

This example submits a two-variable Ising problem mapped directly to qubits 0 and 1 on a D-Wave Advantage4 device.

>>> from braket.ocean_plugin import BraketDWaveSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/Advantage_system4"
>>> sampler = BraketDWaveSampler(device_arn_1)
>>> h = {30: -1, 31: 1}
>>> sampleset = sampler.sample_ising(h, {}, answer_mode="HISTOGRAM")
>>> for sample in sampleset.samples():
...    print(sample)
...
{30: 1, 31: -1}
sample_ising_quantum_task(h: Union[Dict[int, float], List[float]], J: Dict[Tuple[int, int], float], **kwargs) → braket.tasks.quantum_task.QuantumTask[source]

Sample from the specified Ising model and return a QuantumTask. This has the same inputs as BraketDWaveSampler.sample_ising.

Parameters:
  • h (dict/list) – Linear biases of the Ising model. If a dict, should be of the form {v: bias, ...} where v is a spin-valued variable and bias is its associated bias. If a list, it is treated as a list of biases where the indices are the variable labels, except in the case of missing qubits in which case 0 biases are ignored while a non-zero bias set on a missing qubit raises an error.
  • J (dict[(int, int) – float]): Quadratic biases of the Ising model.
  • **kwargs – Optional keyword arguments for the sampling method in D-Wave format
Returns:

dimod.SampleSet – A dimod SampleSet object.

Examples

This example submits a two-variable Ising problem mapped directly to qubits 0 and 1 on a D-Wave 2000Q device.

>>> from braket.ocean_plugin import BraketDWaveSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6"
>>> sampler = BraketDWaveSampler(device_arn_1)
>>> Q = {0: 1, 1: 1}
>>> task = sampler.sample_ising_quantum_task(Q, {}, answer_mode="HISTOGRAM")
>>> sampleset = BraketDWaveSampler.get_task_sample_set(task)
>>> for sample in sampleset.samples():
...    print(sample)
...
{0: 1, 1: -1}

This example submits a two-variable Ising problem mapped directly to qubits 0 and 1 on a D-Wave Advantage4 device.

>>> from braket.ocean_plugin import BraketDWaveSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/Advantage_system4"
>>> sampler = BraketDWaveSampler(device_arn_1)
>>> Q = {30: 1, 31: 1}
>>> task = sampler.sample_ising_quantum_task(Q, {}, answer_mode="HISTOGRAM")
>>> sampleset = BraketDWaveSampler.get_task_sample_set(task)
>>> for sample in sampleset.samples():
...    print(sample)
...
{30: 1, 31: -1}
sample_qubo(Q: Dict[Tuple[int, int], float], **kwargs) → dimod.sampleset.SampleSet[source]

Sample from the specified QUBO.

Parameters:
  • Q (dict) – Coefficients of a quadratic unconstrained binary optimization (QUBO) model.
  • **kwargs – Optional keyword arguments for the sampling method in D-Wave format
Returns:

dimod.SampleSet – A dimod SampleSet object.

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 BraketDWaveSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6"
>>> sampler = BraketDWaveSampler(device_arn_1)
>>> Q = {(0, 0): -1, (4, 4): -1, (0, 4): 2}
>>> sampleset = sampler.sample_qubo(Q, postprocess="SAMPLING", num_reads=100)
>>> 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 BraketDWaveSampler >>> device_arn_1 = “arn:aws:braket:::device/qpu/d-wave/Advantage_system4” >>> sampler = BraketDWaveSampler(device_arn_1) >>> Q = {(30, 30): -1, (31, 31): -1, (30, 31): 2} >>> sampleset = sampler.sample_qubo(Q, num_reads=100) >>> for sample in sampleset.samples(): … print(sample) … {30: 0, 31: 1} {30: 1, 31: 0}

sample_qubo_quantum_task(Q: Dict[Tuple[int, int], float], **kwargs) → braket.tasks.quantum_task.QuantumTask[source]

Sample from the specified QUBO and return a QuantumTask. This has the same inputs as BraketDWaveSampler.sample_qubo.

Parameters:
  • Q (dict) – Coefficients of a quadratic unconstrained binary optimization (QUBO) model.
  • **kwargs – Optional keyword arguments for the sampling method in D-Wave format
Returns:

dimod.SampleSet – A dimod SampleSet object.

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 BraketDWaveSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/DW_2000Q_6"
>>> sampler = BraketDWaveSampler(device_arn_1)
>>> Q = {(0, 0): -1, (4, 4): -1, (0, 4): 2}
>>> task = sampler.sample_qubo_quantum_task(Q, answer_mode="HISTOGRAM", num_reads=100)
>>> sampleset = BraketDWaveSampler.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 BraketDWaveSampler
>>> device_arn_1 = "arn:aws:braket:::device/qpu/d-wave/Advantage_system4"
>>> sampler = BraketDWaveSampler(device_arn_1)
>>> Q = {(30, 30): -1, (31, 31): -1, (30, 31): 2}
>>> task = sampler.sample_qubo_quantum_task(Q, answer_mode="HISTOGRAM", num_reads=100)
>>> sampleset = BraketDWaveSampler.get_task_sample_set(task)
>>> for sample in sampleset.samples():
...    print(sample)
...
{30: 0, 31: 1}
{30: 1, 31: 0}