Skip to main content

Access D-Wave system from IBM Qiskit via MinimumEigensolver interface.

Project description

D-Wave Ocean plugin for IBM Qiskit

Enables Qiskit users to obtain ground state(s) of Ising Hamiltonians using D-Wave's QPU available via Leap.

The package provides an implementation of Qiskit's MinimumEigensolver interface (available as DWaveMinimumEigensolver) which can be used directly on qubit operators, or via qikist.optimization's MinimumEigenOptimizer.

Examples

Solve a QuadraticProgram with MinimumEigenOptimizer (see Qiskit's tutorial) using DWaveMinimumEigensolver:

>>> from qiskit.optimization import QuadraticProgram
>>> from qiskit.optimization.algorithms import MinimumEigenOptimizer
>>> from dwave.plugins.qiskit import DWaveMinimumEigensolver
...
>>> # Construct a simple quadratic program
>>> qp = QuadraticProgram()
>>> qp.binary_var('x')
>>> qp.binary_var('y')
>>> qp.minimize(quadratic={'xy': 1})
...
>>> # Solve using Qiskit's MinimumEigenOptimizer on D-Wave QPU as a minimum eigen solver
>>> dwave_mes = DWaveMinimumEigensolver()
>>> optimizer = MinimumEigenOptimizer(dwave_mes)
>>> result = optimizer.solve(qp)
...
>>> print(result)
optimal function value: 0.0
optimal value: [0. 1.]
status: SUCCESS
>>> result.samples
[('01', 0.0, 0.39), ('00', 0.0, 0.25), ('10', 0.0, 0.36)]

Solve a 6-city TSP (or some other Ising model).

>>> from qiskit.optimization.applications.ising import tsp
>>> from qiskit.optimization.applications.ising.common import sample_most_likely
>>> from dwave.plugins.qiskit import DWaveMinimumEigensolver
...
>>> six_cities_tsp = tsp.random_tsp(6, seed=123)
>>> operator, offset = tsp.get_operator(six_cities_tsp)
...
>>> print(operator.print_details())
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIZ	(-400141.5+0j)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIZIIIIIII	(-400152.5+0j)
IIIIIIIIIIIIIIIIIIIIIIIIIIIIZIIIIIIZ	(12+0j)
# snipped for brevity
>>> print(operator.num_qubits)
36
...
>>> dwave_mes = DWaveMinimumEigensolver(num_reads=1000)
>>> result = dwave_mes.compute_minimum_eigenvalue(operator)
...
>>> x = sample_most_likely(result.eigenstate)
>>> tsp.tsp_feasible(x)
True
>>> tsp.get_tsp_solution(x)
[2, 3, 5, 1, 4, 0]

For comparison, trying this on NumPyMinimumEigensolver produces:

>>> from qiskit.aqua.algorithms import NumPyMinimumEigensolver
>>> result = NumPyMinimumEigensolver().compute_minimum_eigenvalue(operator)
# snipped for brevity
MemoryError: Unable to allocate 512. GiB for an array with shape (68719476737,) and data type uint64

and trying with QAOA backed with "qasm_simulator" produces:

>>> from qiskit import BasicAer
>>> from qiskit.aqua import QuantumInstance
>>> from qiskit.aqua.algorithms import QAOA

>>> quantum_instance = QuantumInstance(BasicAer.get_backend('qasm_simulator'))
>>> qaoa_mes = QAOA(quantum_instance=quantum_instance, initial_point=[0., 0.])
>>> result = qaoa_mes.compute_minimum_eigenvalue(operator)
# snipped for brevity
BasicAerError: 'Number of qubits 36 is greater than maximum (24) for "qasm_simulator".'

Installation

Compatible with Python 3.6+, Qiskit 0.23.0+, and Ocean 3.1.0+.

pip install dwave-qiskit-plugin

To install from source:

pip install -r requirements.txt
python setup.py install

Test requirements are in tests/requirements.txt.

Note: Configured access to D-Wave API is required.

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-qiskit-plugin-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

dwave_qiskit_plugin-0.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file dwave-qiskit-plugin-0.1.0.tar.gz.

File metadata

  • Download URL: dwave-qiskit-plugin-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for dwave-qiskit-plugin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e5404e312a73a2ed77f2c30e60219b2446bdbfbcc27c510473ec88b773be2682
MD5 221f3049f80c2f4f24ed0a0c900bca3f
BLAKE2b-256 da54c43e84cd7f310e8b85b1a80cf8371b0c0961d85b4ef2493e63ffb61bd64f

See more details on using hashes here.

File details

Details for the file dwave_qiskit_plugin-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dwave_qiskit_plugin-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for dwave_qiskit_plugin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ed86cbfa92f90d6901529674ceb94c11e9c12336b71bc0f835a329899997579
MD5 1c6d1bad631a1f5b5cfff9d1590a95d1
BLAKE2b-256 15f2e4c00ebb6739e5162cd4b055bd7b2d58e75bf3ce70baa6b8c0b956ab374a

See more details on using hashes here.

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