External qubo solver for dwave-hybrid

Hello! I have a quite simple problem. I have en external module that solves qubo problem. For example, it takes dimod.BinaryQuadraticModel end returns solution. I want to insert it, for example. instead of dwave solver in kerberos-like workflow. Are there any easy ways to do it?



  • Hello,

    Yes, it is very easy!

    You just need to implement a Runnable.

    If you look at the code for the dwave solver, you can just replace the function contents with your own custom code, and use it as a building block.

    Here is a link to the information on building blocks:

    Here is a link to the function for the dwave sampler (with automatic embedding).

    Here is a link to the code for the dwave sampler building block.

    Make note of the class signature and how it has Runnable in it.

    The most important part is the next() function:

        def next(self, state, **runopts):
            num_reads = runopts.get('num_reads', self.num_reads)
            sampling_params = runopts.get('sampling_params', self.sampling_params)
            params = sampling_params.copy()
            response = self.sampler.sample(state.subproblem, **params)
            return state.updated(subsamples=response)

    We can see here that the return function is being used to update the state for the next iteration of the loop, and that it is using the response object from the sample function call.

    Basically once you have written your own class which implements Runnable, you can then use it like any other building block!

    I hope this was helpful.

    If you get stuck or are not sure what to do, please let us know and we can help you!

    Comment actions Permalink
  • I think I don't quite understand what next() function should do.

    What I think:

    It gets a state - a current state of the general, undivided problem. It has a property "subproblem" that contains a bqm problem that must be solved inside the next() function. next() should return a copy of the state with additional property: subsamples that will be concatenated and compared with solutions from other samplers to generate new input state. 

    Comment actions Permalink
  • But 'subsamples' contains concatenated solution. The question is: how to create response of the type dimod.SampleSet if I have only solution for subproblem.  

    Comment actions Permalink
  • It sounds like you have the right idea.

    The next() function is the action to be taken in order to process the data and get to the next state.
    In this case, the sample function gets called on the input data.
    The input data is a subproblem of the bigger problem, which is broken down by decomposers. 

    The output of this step is then passed to the input of the next step.
    The mechanism by which this is done is in setting the subsamples in the state.updated() function as in the above code example:

    return state.updated(subsamples=response)

    If we override the functionality in the next() function, we can change how the runnable behaves and inject our own functionality into the hybrid workflow.

    Here is a link to the context where the above next function was taken from:

    Here is a link to information about the workflow which shows a decomposer and composer in line with a sampler:

    Why would you like to create a dimod.SampleSet?
    Does it look like it is needed as input for another set?

    Note that the output from the sample function is of type deimod.SampleSet.

    You can see this is the case by running the type() function on the response:

    >>> type(response)
    <class 'dimod.sampleset.SampleSet'>

    Please let me know if this helps!

    Comment actions Permalink
  • Hi Nikita,

    Yesterday we launched Leap 2 and I am happy to tell you that it is now much easier to solve problems that are larger than a D-Wave 2000Q QPU.  Please try using our new hybrid solver, which you will see on your Leap Dashboard as hybrid_v1. It accepts problems of up to 10,000 variables fully connected!

    Submit the problem through Ocean as you would any other problem to the D-Wave system, but specify the new LeapHybridSampler in your Python program:

    from dwave.system import LeapHybridSampler

    Take a look at our Knapsack example in Github, which is designed to demonstrate the usage of the hybrid solver.

    Let us know how it goes, 


    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post