GithubHelp home page GithubHelp logo

dwavesystems / dimod Goto Github PK

View Code? Open in Web Editor NEW
120.0 120.0 75.0 5.95 MB

A shared API for QUBO/Ising samplers.

Home Page: https://docs.ocean.dwavesys.com/en/stable/docs_dimod/

License: Apache License 2.0

Python 77.95% C++ 11.86% Makefile 0.05% Cython 10.14%

dimod's People

Contributors

29rou avatar aidanproy avatar alejomonbar avatar arcondello avatar aszady avatar bellert avatar charleswhchan avatar conta877 avatar hbarovertwo avatar hsadeghidw avatar jackraymond avatar joelpasvolsky avatar joseppinilla avatar kenkoooo avatar kevinchern avatar mhlr avatar mhramani avatar myriagon avatar necaisej avatar odidev avatar oneklc avatar pau557 avatar randomir avatar schnorea avatar thisac avatar vgoliber avatar wbernoudy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dimod's Issues

Ignore "third state" of qubit in actual QPU samples

dimod.response.infer_vartype expects sample values to be binary {0,1} or {-1,1}, but the real QPU/SAPI response also includes the "third state" for missing qubits.

We can filter those out (in dimod.Response.from_futures) or support them (in infer_vartype).

Make sure that a returned result has all variables

When testing dimod solvers in qbsolv I ran into an issue where the returned solution was missing variables that should have been present (although may have been zero on all biases/couplings).

It was with either the random or SA ones.

Add documentation framework

Even if the documentation is incomplete - create the .rst files for everything so that we can get an idea of the form.

Clear API documentation and unittests

A clear documentation of the dimod API is needed.

Also, it would be good for dimod to expose a set of unittests that can be run for any response, sampler or composite that would verify that the API has been set up correctly. Right now there are GenericSamplerTests and GenericResponseTest classes, but they are not imported into dimod nor are they designed with only verifying the API in mind.

Instantiating a sampler with redundant edges should raise a more informative error message

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-980440423cf0> in <module>()
      1 dwave_sampler = DWaveSampler(solver_name, url=url, token=token, permissive_ssl=True)
----> 2 nodelist, edgelist, _ = dwave_sampler.structure

/usr/local/lib/python2.7/site-packages/dimod/core/structured.pyc in structure(self)
    114     def structure(self):
    115         """A :class:`~collections.namedtuple` :samp:`Structure(nodelist, edgelist, adjacency)`"""
--> 116         return _Structure(self.nodelist, self.edgelist, self.adjacency)

/usr/local/lib/python2.7/site-packages/dimod/core/structured.pyc in adjacency(self)
    104             for u, v in self.edgelist:
    105                 if v in adjacency[u]:
--> 106                     raise ValueError("Each edge in edgelist must be unique")
    107                 adjacency[u].add(v)
    108                 adjacency[v].add(u)

ValueError: Each edge in edgelist must be unique

Warning raised in unittests

self.assertAlmostEqual(bqm.energy(sample), sample_series.dot(bqm_df.dot(sample_series)))

In tests raises a warning:

RuntimeWarning: '<' not supported between instances of 'int' and 'str', sort order is undefined for incomparable objects
  self.assertAlmostEqual(bqm.energy(sample), sample_series.dot(bqm_df.dot(sample_series)))

Rescaling composite layer needed

A composite layer that rescales the Hamiltonian would add a lot of convenience. It would rescale the input Hamiltonian to fit within specified ranges, then reverse the rescaling so the energies match the original Hamiltonian.

I currently use the following function to rescale Hamiltonians, with an additional feature that allows clipping large values so that the Hamiltonian doesn't have to be scaled down as much (the tradeoff being that the Hamiltonian is not a faithful rescaling if clipping < 1).

def rescale(hh, jj, h_range, j_range, clipping=1.):
    """Rescale the Hamiltonian.

    Clipping truncates values at a certain fraction of the provided range to lessen the
    required compression.
    """

    # Unpack the bounds.
    min_h, max_h = map(float, h_range)
    min_j, max_j = map(float, j_range)

    # Find the natural rescaling factor
    scalars = [
        1.,
        max([h / min_h for h in hh]),
        max([h / max_h for h in hh]),
        max([j / min_j for j in jj.values()]),
        max([j / max_j for j in jj.values()]),
        ]

    scalar = max(scalars)
    # Adjust for clipping
    scalar *= clipping

    hh_scaled = [min_h if h/scalar <= min_h else max_h if h/scalar >= max_h else h/scalar for h in hh]
    jj_scaled = {k: min_j if v/scalar <= min_j else max_j if v/scalar >= max_j else v/scalar for k, v in jj.iteritems()}

    return hh_scaled, jj_scaled, scalar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.