dimod.make_quadratic returns error

Hi,

   I'm trying to convert a hamiltonian like this:

H = sum_ijkl A_ijkl q_i q_j q_k q_l

into a QUBO. I came across the dimod module called higherorder . To my understanding, it creates additional variables to convert a polynominal binary function to a quadratic binary function. I did a few tests "by hand" and it worked fine at least technically. 

However, if I try a combination like this:

H = {
(0, 1, 0, 1): -4.61898,
(0, 1, 1, 0): 4.61898,
(0, 2, 0, 2): -5.18353,
(0, 2, 2, 0): 5.18353,
(1, 0, 0, 1): 4.61898,
(1, 0, 1, 0): -4.61898,
(1, 2, 2, 1): 4.97017,
(2, 0, 0, 2): 5.18353,
(2, 0, 2, 0): -5.18353,
(2, 1, 1, 2): 4.97017,
}

and then

bqm = dimod.make_quadratic(Q, strength, dimod.BINARY)

I get the following error:

Traceback (most recent call last):

  File "./nbody.py", line 136, in <module>

    bqm = dimod.make_quadratic(Q, strength, dimod.BINARY)

  File "/Users/disipio/dwave/lib/python3.7/site-packages/dimod/higherorder/utils.py", line 136, in make_quadratic

    return _reduce_degree(bqm, new_poly, vartype, strength)

  File "/Users/disipio/dwave/lib/python3.7/site-packages/dimod/higherorder/utils.py", line 198, in _reduce_degree

    return _reduce_degree(bqm, new_poly, vartype, scale)

  File "/Users/disipio/dwave/lib/python3.7/site-packages/dimod/higherorder/utils.py", line 144, in _reduce_degree

    bqm.add_interactions_from(poly)

  File "/Users/disipio/dwave/lib/python3.7/site-packages/dimod/binary_quadratic_model.py", line 651, in add_interactions_from

    for (u, v), bias in iteritems(quadratic):

ValueError: not enough values to unpack (expected 2, got 1)

I'm not sure what it means. Is it a problem with the indices, or is it just not possible to convert such hamiltonian to QUBO? The error message seems very cryptic to me.

Cheers,
Riccardo

0

Comments

1 comment
  • Hi Riccardo,

    Thanks for posting this! It is a bug and has now been fixed. The reduction broke when it encountered a squared variable. It should just reduce the squared variables to variables with a power of 1. 

    You should be good to go as soon as this pull request is merged!

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post