Setting the solver at runtime from python
Hi,
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,
Riccardo
Comments
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:
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).
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:
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.
Thanks! The second option works nicely. As for the third, should I call e.g.
to point to the Advantage backend I defined in the config file? Also, would it work with hybrid solvers, e.g.
I believe the answer is no, but just asking.
Many thanks,
Riccardo
Good question! Sorry I missed that part. For the third option, you would call it like this:
Hybrid solvers don't work with DWaveSampler, but the same configuration approach applies to the LeapHybridSampler. You would call that like this:
Amazing! Thanks, I made it work now!
Glad to hear it!
Txs, very useful
Please sign in to leave a comment.