Skip to main content

D-Wave Problem Inspector tool

Project description

Last version on PyPI Linux/Mac build status Coverage report

D-Wave Inspector

A tool for visualizing problems submitted to, and answers received from, a D-Wave structured solver such as a D-Wave 2000Q quantum computer.

Overview

dwave-inspector provides a graphic interface for examining D-Wave quantum computers’ problems and answers. As described in the Ocean documentation’s Getting Started, the D-Wave system solves problems formulated as binary quadratic models (BQM) that are mapped to its qubits in a process called minor-embedding. Because the way you choose to minor-embed a problem (the mapping and related parameters) affects solution quality, it can be helpful to see it.

For example, embedding a K3 fully-connected graph, such as the Boolean AND gate example into a D-Wave 2000Q, with its Chimera topology, requires representing one of the three variables with a “chain” of two physical qubits:

https://raw.githubusercontent.com/dwavesystems/dwave-inspector/master/docs/_images/and_gate.png

The AND gate’s original BQM is represented on the left; its embedded representation, on the right, shows a two-qubit chain of qubits 1195 and 1199 for one variable.

The problem inspector shows you your chains at a glance: you see lengths, any breakages, and physical layout.

Installation or Building

If D-Wave Ocean SDK 2.0+ is installed:

dwave install inspector

Otherwise, install the package from PyPI:

pip install dwave-inspector

and then install the closed-source dependencies with:

pip install dwave-inspectorapp --extra-index=https://pypi.dwavesys.com/simple

Alternatively, clone and build from source:

git clone https://github.com/dwavesystems/dwave-inspector.git
cd dwave-inspector
pip install -r requirements.txt
python setup.py install

When building from source, the closed-source component still needs to be installed as above.

Usage and Examples

Import the problem inspector to enable it[1] to hook into your problem submissions.

Use the show() method to visualize the embedded problem, and optionally the logical problem, in your default browser.

Inspecting an Embedded Problem

This example shows the canonical usage: samples representing physical qubits on a quantum processing unit (QPU).

>>> from dwave.system import DWaveSampler
>>> import dwave.inspector
...
>>> # Get solver
>>> sampler = DWaveSampler(solver = {'qpu': True})
...
>>> # Define a problem (actual qubits depend on the selected QPU's working graph)
>>> h = {}
>>> all (edge in sampler.edgelist for edge in {(0, 4), (0, 5), (1, 4), (1, 5)})
True
>>> J = {(0, 4): 1, (0, 5): 1, (1, 4): 1, (1, 5): -1}
...
>>> # Sample
>>> response = sampler.sample_ising(h, J, num_reads=100)
...
>>> # Inspect
>>> dwave.inspector.show(response)
https://raw.githubusercontent.com/dwavesystems/dwave-inspector/master/docs/_images/physical_qubits.png

Edge values between qubits 0, 1, 4, 5, and the selected solution, are shown by color on the left; a histogram, on the right, shows the energies of returned samples.

Inspecting a Logical Problem

This example visualizes a problem specified logically and then automatically minor-embedded by Ocean’s EmbeddingComposite. For illustrative purposes it sets a weak chain_strength to show broken chains.

import dimod
import dwave.inspector
from dwave.system import DWaveSampler, EmbeddingComposite

# Define problem
bqm = dimod.BQM.from_ising({}, {'ab': 1, 'bc': 1, 'ca': 1})

# Get sampler
sampler = EmbeddingComposite(DWaveSampler(solver=dict(qpu=True)))

# Sample with low chain strength
sampleset = sampler.sample(bqm, num_reads=1000, chain_strength=0.1)

# Inspect
dwave.inspector.show(sampleset)
https://raw.githubusercontent.com/dwavesystems/dwave-inspector/master/docs/_images/logical_problem.png

The logical problem, on the left, shows that the value for variable b is based on a broken chain; the embedded problem, on the right, highlights the broken chain (its two qubits have different values) in bold red.

show() Method

The show() method requires the SampleSet returned from the quantum computer or the SAPI problem ID[2]; other problem inputs—the binary quadratic model in BQM, Ising, or QUBO formats, and an emebedding—are optional. However, to visualize a logical problem if dimod’s EmbeddingComposite or derived classes are not used, you must supply the embedding.

Below are some options for providing problem data to the show() method, where response was returned for a problem defined directly on physical qubits and sampleset returned from a problem submitted using EmbeddingComposite:

show(response)
show('69ace80c-d3b1-448a-a028-b51b94f4a49d')   # Using a SAPI problem ID
show((h, J), response)
show(Q, response)
show((h, J), response, dict(embedding=embedding, chain_strength=5))

show(sampleset)
show(bqm, sampleset)

The show() method supports flow control for scripts with the block parameter. For example, the default setting of once (dwave.inspector.Block.ONCE) blocks until your problem is loaded from the inspector web server and forever blocks until you terminate with a CNTL-C/SIGTERM.

License

Released under the Apache License 2.0. See LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dwave-inspector-0.1.4.tar.gz (21.4 kB view hashes)

Uploaded Source

Built Distribution

dwave_inspector-0.1.4-py2.py3-none-any.whl (26.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page