How does the DWaveSampler/DWaveCliqueSampler select a solver?

In the latest version of the Ocean SDK, Ocean 3.0, the DWaveSampler and DWaveCliqueSampler handle selecting a solver differently than they have in previous versions. Depending on how your local system is set up and on how you instantiate the samplers you will see a range of behavior. The following sections explain how to get these Ocean samplers to select a QPU solver based on certain criteria. 

1. The solver with the highest number of qubits

If you have a fresh install of Ocean and have not added any default configurations to your local dwave.conf file or environment variables, these samplers will look for the QPU solver that has the highest number of qubits when they are instantiated without parameters. This is overridden whenever defaults are available on your system or when a solver is specified in the constructor. 

The examples below use the default constructors without parameters:

#Examples of using the default constructors

sampler = DWaveSampler()
clique_sampler = DWaveCliqueSampler()


The following examples are not guaranteed to select a solver with the highest number of qubits.

#Examples of specifying a solver programmatically 

sampler_advantage = DWaveSampler(solver='DW_2000Q_6')
sampler_lowest_load = DWaveSampler(solver={'qpu': True})


In the Leap IDE the DWaveSampler and DWaveCliqueSampler select the QPU solver with the highest number of qubits whenever the default constructor is used, unless the DWAVE_API_SOLVER environment variable has explicitly been set. In that case, the solver specified in the environment variable will be selected. 


2. The default solver in your config file or environment variables

If you have a default QPU solver specified in your configuration file or environment variables it will be selected when you instantiate DWaveSampler or DWaveCliqueSampler with empty constructors. For example, if the first entry in your configuration file is

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


The Advantage_solver1.1 will be selected when you call DWaveSampler() or DWaveCliqueSampler().

Removing the 'solver=' line in your configuration file will allow Ocean to select the solver for you (based on option 1 above) when you do not specify it programmatically. 


3. The solver with the least average load 

When the DWaveSampler or DWaveCliqueSampler is instantiated with the instruction to select any QPU solver, it will choose the solver that has the least average load. If a D-Wave 2000Q and an Advantage solver are both online, the solver with the least amount of traffic, or queued jobs, will be selected. The following code snippet will result in this behavior on your local machine and in the Leap IDE.

sampler = DWaveSampler(solver={'qpu': True})


4.  The most performant solver based on the parameter you specify

The preferred selection criteria is customizable when using the DWaveSampler or DWaveCliqueSampler. For example, if there was more than one QPU solver online and you wanted to select the one with the highest number of anneal schedule points, you could do so with

sampler = DWaveSampler(solver=dict(order_by='-properties.max_anneal_schedule_points'))

These samplers use the cloud-client to gain access to and select a solver. The 'order_by' option in the example above is provided by the cloud-client. For more information see here.


Common pitfalls

If you try to instantiate a specific solver without having the correct setup you will see an error. For example, if your dwave.conf file looks like this:

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

and you try to instantiate the DWaveSampler you will see the error below. 


This happens because the first profile in your configuration file specifies a hybrid solver, yet you tried to instantiate a QPU solver. The solution to this problem is to delete the solver field in your [defaults] profile, so that the [defaults]  profile only contains entries for the endpoint and token. That allows Ocean to programmatically select a solver. If you have multiple profiles you can still specify a solver in the subsequent profiles. For example,

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

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


For troubleshooting tips or more information on solver selection, check out the dwave-system wiki here.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.