Setting the solver at runtime from python


   I would like to compare the execution of a program I wrote some time ago using either the Advange or the DW_2000Q_6 QPU. In my program, I define the sampler like this:

sampler = EmbeddingComposite(DWaveSampler(solver={'qpu': True}))
Now, I would like to create two samplers, e.g. sampler_2000Q_6 and sampler_advantage, leave all the rest the same, and call the functions that perform the calculation twice in the same script. I can't figure out how to do this. I don't want to change by hand the dwave.config file and run twice the program. I suspect one has to pass a paramter to DWaveSampler but I'm not sure how.
Thank you in advance,


  • Hi Riccardo, 

    There are a number of options for specifying a particular QPU solver. 


    Option 1: Use feature based solver selection to set the topology type

    To do this, you can create a sampler the same way you did before. This time you'll want to use the topology__type parameter like this:

    # Choose Advantage
    sampler = EmbeddingComposite(DWaveSampler(solver={'topology__type': 'pegasus'}))

    # Choose DW_2000Q_6
    sampler = EmbeddingComposite(DWaveSampler(solver={'topology__type': 'chimera'}))


    Option 2: Specify the solver's name

    This method uses the solver's name. The drawback is that you have to remember to modify your code when the solvers change (for example, during a maintenance event or when we decommission one solver and bring a new one online).

    # Choose Advantage
    sampler = EmbeddingComposite(DWaveSampler(solver='Advantage_system1.1'))

    # Choose DW_2000Q_6
    sampler = EmbeddingComposite(DWaveSampler(solver='DW_2000Q_6'))


    Option 3: Add another profile to your configuration file

    You can use your configuration file to save multiple configurations. Here's what your config file would look like:

    endpoint =
    token = ********************

    endpoint =
    token = *******************
    solver = Advantage_system1.1

    endpoint =
    token = *****************
    solver = DW_2000Q_6

    Note that the default profile at the top is necessary. If you don't have a profile at the top of your config file that doesn't specify a solver, you won't be able to run hybrid solvers if your first profile specifies a QPU solver (and vice versa). 

    I hope this helps! Let me know if you have any more questions.

    Comment actions Permalink
  • Thanks! The second option works nicely. As for the third, should I call e.g.

    sampler = EmbeddingComposite(DWaveSampler(solver='advantage'))

    to point to the Advantage backend I defined in the config file? Also, would it work with hybrid solvers, e.g.

    sampler = EmbeddingComposite(DWaveSampler(solver='hybrid_binary_quadratic_model_version2'))

    I believe the answer is no, but just asking.


    Many thanks,

    Comment actions Permalink
  • Good question! Sorry I missed that part. For the third option, you would call it like this:

    sampler = EmbeddingComposite(DWaveSampler(profile='advantage'))


    Hybrid solvers don't work with DWaveSampler, but the same configuration approach applies to the LeapHybridSampler. You would call that like this:

    # Call the sampler using a profile configuration that's called 'hybrid_bqm'
    hybrid_sampler = LeapHybridSampler(profile='hybrid_bqm')

    # Call the sampler by specifying the solver
    hybrid_sampler = LeapHybridSampler(solver='hybrid_binary_quadratic_model_version2')
    Comment actions Permalink
  • Amazing! Thanks, I made it work now!

    Comment actions Permalink
  • Glad to hear it!

    Comment actions Permalink
  • Txs, very useful

    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post