Answered

"no self-loops allowed" with sampler.sample_ising() and VirtualGraphComposite()

I am getting a "no self-loops allowed" error when I use VirtualGraphComposite() and sampler.sample_ising() together.

I ran code (listed below) to create an AND gate using an Ising model. (Based off the example, which uses QUBO.) However, sample_ising() returns this error:

 File "/usr/local/lib/python3.7/site-packages/dimod/binary_quadratic_model.py", line 516, in add_interaction
raise ValueError("no self-loops allowed, therefore ({}, {}) is not an allowed interaction".format(u, v))
ValueError: no self-loops allowed, therefore (z, z) is not an allowed interaction

If I delete the self-referential coupling of z (qubits 0 and 4), I clearly get incorrect results. Am I doing something wrong? Is sample_ising() incompatible with VirtualGraphComposite()?

Example code (raises "no-self loops allowed" error):

 embedding = {'x1': {1}, 'x2': {5}, 'z': {0, 4}}
sampler = VirtualGraphComposite(DWaveSampler(), embedding)
h = {'x1': 0, 'x2': 0, 'z': 0}
J = {('x1', 'x2'): 1, ('x1', 'z'): -2, ('x2', 'z'): -2, ('z', 'z'): 2.5}
response = sampler.sample_ising(h, J, num_reads=60)

 

0

Comments

4 comments
  • The J couples separate qubits, it's the h that takes the bias, so your h should be {'z': 3, 'x1': 0.0, 'x2': 0.0} and then J is {('x1', 'x2'): 1, ('x1', 'z'): -2, ('x2', 'z'): -2} without the ('z', 'z'). 

    0
    Comment actions Permalink
  • I do not want a bias on z; I want a strong coupling between qubits 0 and 4. For the sample_qubo() method, putting a ('z','z'):2.5 in the quadratic is how I accomplish this.

    For sample_ising() used with VirtualGraphComposite(), how do I ensure two arbitrary qubits are strongly coupled to act as a single virtual qubit?

     

    0
    Comment actions Permalink
  • For your AND example, the coupling between qubits 0 and 4 comes from "'z': {0, 4}" in your line "embedding = {'x1': {1}, 'x2': {5}, 'z': {0, 4}}". 

     

    0
    Comment actions Permalink
  • Got it -- thanks.

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post