Problem with VirtualGraphComposite


I am facing a problem with virtualGraphComposite. I will show you two versions of my program.

The first version of the program is using EmdeddingComposite and it works. But when I replace with VirtualGraphComposite I get problems.

Here is the relevant part of the original program

Initialize diagonal elements of Q
Initialize non diagonal elemens of Q
sampler_wo_e = DWaveSampler(config_file='/home/manoj/.config/dwave/dwave.conf',profile='old',)
sampler = EmbeddingComposite(sampler_wo_e)
num_reads = 1000
annealing_time= 200['default_programming_thermalization']

response = sampler.sample_qubo(Q, num_reads=num_reads, annealing_time=annealing_time, programming_thermalization=programming_thermalization)

The above program works well - no issues.

I am trying to solve the same problem with VirtualGraphComposite

Now here is how I replace with VirtualGraphComposite

Initialize diagonal elements of Q
Initialize non diagonal elemens of Q. Set the same elements of S to 1
sampler_wo_e = DWaveSampler(config_file='/home/manoj/.config/dwave/dwave.conf',profile='old',)
A = sampler_wo_e.edgelist
embeddings, valid = find_embedding(S, A, verbose=1, return_overlap=1)
sampler = VirtualGraphComposite(sampler_wo_e, embeddings)
num_reads = 1000
annealing_time= 200

response = sampler.sample_qubo(Q, num_reads=num_reads, annealing_time=annealing_time)

The last line "sampler.sample_qubo" in the VirtualGraphComposite code sample above results in the following error message as I see in my jupyter notebook.

SolverFailureError Traceback (most recent call last)
<ipython-input-8-9a34c8322c83> in <module>()
4 #print programming_thermalization
----> 6 response = sampler.sample_qubo(Q, num_reads=num_reads, annealing_time=annealing_time)
7 # programming_thermalization=programming_thermalization)

/home/manoj/.local/lib/python2.7/site-packages/dimod/core/sampler.pyc in sample_qubo(self, Q, **parameters)
210 """
211 bqm = BinaryQuadraticModel.from_qubo(Q)
--> 212 response = self.sample(bqm, **parameters)
213 return response

/home/manoj/.local/lib/python2.7/site-packages/dimod/decorators.pyc in new_f(sampler, bqm, **kwargs)
85 raise BinaryQuadraticModelStructureError("given bqm does not match the sampler's structure")
---> 87 return f(sampler, bqm, **kwargs)
89 return new_f

/home/manoj/.local/lib/python2.7/site-packages/dwave/system/composites/virtual_graph.pyc in sample(self, bqm, apply_flux_bias_offsets, **kwargs)
358 kwargs[FLUX_BIAS_KWARG] = self.flux_biases
--> 360 return child.sample(bqm, **kwargs)

/home/manoj/.local/lib/python2.7/site-packages/dimod/decorators.pyc in new_f(sampler, bqm, **kwargs)
85 raise BinaryQuadraticModelStructureError("given bqm does not match the sampler's structure")
---> 87 return f(sampler, bqm, **kwargs)
89 return new_f

/home/manoj/.local/lib/python2.7/site-packages/dwave/system/composites/embedding.pyc in sample(self, bqm, chain_strength, chain_break_fraction, **parameters)
419 parameters['initial_state'] = _embed_state(embedding, parameters['initial_state'])
--> 421 response = child.sample(bqm_embedded, **parameters)
423 return dimod.unembed_response(response, embedding, source_bqm=bqm,

/home/manoj/.local/lib/python2.7/site-packages/dimod/core/sampler.pyc in sample(self, bqm, **parameters)
192 h, J, offset = bqm.to_ising()
193 response = self.sample_ising(h, J, **parameters)
--> 194 response.change_vartype(Vartype.BINARY, energy_offset=offset)
195 return response
196 else:

/home/manoj/.local/lib/python2.7/site-packages/dimod/decorators.pyc in new_f(*args, **kwargs)
176 _enforce_single_arg(name, final_args, final_kwargs)
--> 178 return f(*final_args, **final_kwargs)
180 return new_f

/home/manoj/.local/lib/python2.7/site-packages/dimod/sampleset.pyc in change_vartype(self, vartype, energy_offset, inplace)
643 if energy_offset:
--> 644 = + energy_offset
646 if vartype is self.vartype:

/home/manoj/.local/lib/python2.7/site-packages/dimod/sampleset.pyc in record(self)
428 """
429 if hasattr(self, '_future'):
--> 430 self._resolve_future()
431 return self._record

/home/manoj/.local/lib/python2.7/site-packages/dimod/sampleset.pyc in _resolve_future(self)
332 def _resolve_future(self):
--> 333 samples = self._result_hook(self._future)
334 self.__init__(samples.record, samples.variables,, samples.vartype)
335 del self._future

/home/manoj/.local/lib/python2.7/site-packages/dwave/system/samplers/dwave_sampler.pyc in _hook(computation)
415 def _result_to_response_hook(variables, vartype):
416 def _hook(computation):
--> 417 result = computation.result()
419 # get the samples. The future will return all spins so filter for the ones in variables

/home/manoj/.local/lib/python2.7/site-packages/dwave/cloud/computation.pyc in result(self)
492 """
--> 493 self._load_result()
494 return self._result

/home/manoj/.local/lib/python2.7/site-packages/dwave/cloud/computation.pyc in _load_result(self)
656 if self.error is not None:
657 if self._exc_info is not None:
--> 658 six.reraise(*self._exc_info)
659 if isinstance(self.error, Exception):
660 raise self.error

/home/manoj/.local/lib/python2.7/site-packages/dwave/cloud/client.pyc in _handle_problem_status(self, message, future)
1059 raise SolverOfflineError(errmsg)
1060 else:
-> 1061 raise SolverFailureError(errmsg)
1063 except Exception as error:

SolverFailureError: Linear coefficients out of h_range.


Can anyone tell me whats wrong with the VirtualGraphComposite code sample?

Also I see more QPU time consumed from my monthly usage quota with the VirtualGraphComposite code. Any clues?

Manoj Nambiar




  • Hi Manoj - Do you have a standalone program that you are running? Something in a public repository you can link to, or a short piece of code you can paste?


    Comment actions Permalink
  • Hello Manoj - thanks for sharing your issue.

    The major change from EmbeddingComposite to VirtualGraphComposite is the embedding step. I think it would be particularly helpful to see the code that you use in this step:

    "Initialize non diagonal elemens of Q. Set the same elements of S to 1"

    The error message "given bqm does not match the sampler's structure" makes me think that S may not be put together properly. This would cause the find_embeddings step to create an embedding that does not match the graphs properly.

    About your second question - if the DWaveSampler object you create is using the QPU solver (DW2000Q_2_1) then any composite sampler you build with this will take up time on the QPU. If you want to conserve your QPU time during debugging, you can switch the DWaveSampler object for a classical solver or reduce the number of reads.

    Comment actions Permalink
  • Thanks for commenting Thomas and Luca.

    The files I am working with is in the following repository -

    The relevant jupyter notebooks are

    EmbeddingComposite example - assignment_dwave_ocean-Copy3.ipynb

    VirtualGraphComposite example (currently non-working) - assignment_dwave_ocean-VirtualGraph.ipynb

    Regarding the excessive QPU time - the problem is consistent with the VirtualGraphComposite code. Nos such problem with the EmbeddingComposite code.

    I need the DW2000Q_2_1 solver as I am trying to get better results with the QPU hardware (atleast one correct sample in 1000 reads for n > 6 : n is a variable in the program). Software solvers will not do for me. Hence my move to VirtualGraphComposite. That is a different problem for this discussion - probably needs another thread once I am done with VitualGraphComposite.

    Manoj Nambiar


    Comment actions Permalink
  • Hello Manoj,

    Thank you for providing your GitHub repository link. The construction of your embedding looks good to me.

    The error message SolverFailureError: Linear coefficients out of h_range could be because the QUBO biases are too large. When the QUBO is translated into Ising format, the resulting h and J values may lie outside of the accepted h and J ranges.

    Setting the auto_scale parameter to True will fix this issue. However, VirtualGraphComposite does not currently allow auto_scale with flux_bias values. There is an active GitHub issue for this feature which you can follow for updates.

    In the mean time, you can scale the QUBO biases in your code. Note that QUBO and Ising biases are not the same - more detail on this topic can be found on the community post Difference between BQM, Ising and QUBO problems?

    Hope this helps!

    Comment actions Permalink
  • Thanks Luca.

    Does auto_scale work for EmbeddingComposite?

    Wondering if I should try that on EmbeddingComposite to get better accuracy numbers.

    Manoj Nambiar

    Comment actions Permalink
  • Hi Manoj,

    Yes, auto_scale will work with both EmbeddingComposite and FixedEmbeddingComposite

    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post