lanl/qmasm

boolean-vs-Ising variables

frederic-bapst opened this issue · 6 comments

I'm a bit confused with the support of "boolean-vs-Ising variables", together with the -q and --values=bool options:

  • Does the -q flag mean that the input QMASM file defines a boolean (0/1) optimization problem (instead of a spin (-1/+1) problem), as is possible e.g. with the BQPJSON tool, or does it indicate that the input has a different syntax (maybe the QUBO syntax of qbsolve)? I get an error when running a *.qmasm file (with qbsolv) with that flag.

  • does the --values have any effect when we use qmasm without a DWave (such as in qbsolv mode)? I don't see any difference (but I'm no so sure what I'm doing is correct).

Thanks in advance.
[don't hesitate to tell if such questions should preferably be asked by email]

Does the -q flag mean that the input QMASM file defines a boolean (0/1) optimization problem (instead of a spin (-1/+1) problem), as is possible e.g. with the BQPJSON tool, or does it indicate that the input has a different syntax (maybe the QUBO syntax of qbsolve)?

The former.

I get an error when running a *.qmasm file (with qbsolv) with that flag.

What error do you get? Could you please post a sample .qmasm file and command line I can run to try to reproduce the error?

does the --values have any effect when we use qmasm without a DWave (such as in qbsolv mode)?

It's supposed to, and as of half an hour ago (commits 9e5be93 and a896291), I believe it now does. Thanks for reporting the problem.

— Scott

Thanks a lot for the fast answer and bug fix.

My own files are too ugly to show here, but I also get errors with four of the seven instances in the /examples folder: circsat, comparator, gates, sort4. Here are some traces:

$ qmasm gates.qmasm --format qbsolv --run  -q --extra-args "-t 3"
  File "/usr/local/bin/qmasm", line 51, in <module>
    logical_ising = logical_either.convert_to_ising()
  File "/usr/local/lib/python2.7/dist-packages/qmasm/problem.py", line 140, in convert_to_ising
  File "/usr/local/lib/python2.7/dist-packages/qmasm/fake_dwave.py", line 77, in qubo_to_ising
ValueError: max() arg is an empty sequence
-----------
Traceback (most recent call last):
  File "/usr/local/bin/qmasm", line 51, in <module>
    logical_ising = logical_either.convert_to_ising()
  File "/usr/local/lib/python2.7/dist-packages/qmasm/problem.py", line 142, in convert_to_ising
  File "/usr/local/lib/python2.7/dist-packages/qmasm/problem.py", line 142, in <dictcomp>
KeyError: 4
-----------
Traceback (most recent call last):
  File "/usr/local/bin/qmasm", line 51, in <module>
    logical_ising = logical_either.convert_to_ising()
  File "/usr/local/lib/python2.7/dist-packages/qmasm/problem.py", line 140, in convert_to_ising
  File "/usr/local/lib/python2.7/dist-packages/qmasm/fake_dwave.py", line 74, in qubo_to_ising
KeyError: 207

circsat and sort4 should work; comparator and gates should not. The latter two define macros (to be used by the former two) but no top-level code. They're like a C++ program with no main() function.

That said, QMASM is supposed to issue a Nothing to do error message, not crash. (It does in fact issue a proper error message when QMASM finds D-Wave's libraries.) I believe you should now get a proper error message with 0592f76, but please confirm.

Another case in which QMASM has nothing to do is when -O1 or -O2 is specified and you give QMASM too simple of a problem. With optimizations enabled, QMASM eliminates variables whose final value can be determined a priori using roof duality. If this step eliminates all variables, QMASM also issues a Nothing to do message and aborts.

Thanks! Ok, now circsat & sort4 run correctly with -q, and the comparator & gates correctly outputs the right message (sorry for having blindly tried to run them!). So perfect for everything in /examples.

Now I still get an error with my own sample files, but I've just seen it's my mistake: I give coupler strengths about variables that have no weight. Yet it's worth mentioning that it runs fine without the -q flag, and perhaps you'll want to improve the coherence between the two modes. Here is a small example, with the error message:

# 2018-06-21 08:23:35.367638 
# This is a QUBO/boolean model, not a Spin/Ising model 
a -1
b -1
c -1
d -1
d b 2
!assert 1 >= b + d
d c 2
!assert 1 >= c + d
a f 0.0012751461843001648
b a 0.0025522909203907623
c b 0.005563954823864527
d a 0.00171879516735896
e c 0.0027009146108732565
e d 0.0026249048111142326
$ qmasm e1.qmasm --format qbsolv --run
# 6 bits,  find Min, SubMatrix= 47, -a o, timeout=2592000.0 sec
# 100101
# -12.01306 Energy of solution
# 0 Number of Partitioned calls, 1 output sample
#  0.63120 seconds of classic cpu time

Solution #1 (energy = -12.01, tally = 1):

    Name  Spin  Boolean
    ----  ----  --------
    a       +1  True   
    b       -1  False  
    c       -1  False  
    d       +1  True   
    e       +1  True   
    f       -1  False  

$ qmasm e1.qmasm --format qbsolv --run -q
Traceback (most recent call last):
  File "/usr/local/bin/qmasm", line 51, in <module>
    logical_ising = logical_either.convert_to_ising()
  File "/usr/local/lib/python2.7/dist-packages/qmasm/problem.py", line 140, in convert_to_ising
    hvals, new_obj.strengths, qoffset = qubo_to_ising(qmatrix)
  File "/usr/local/lib/python2.7/dist-packages/qmasm/fake_dwave.py", line 74, in qubo_to_ising
    hs[j] += s/4.0
KeyError: 5

Now I still get an error with my own sample files, but I've just seen it's my mistake: I give coupler strengths about variables that have no weight. Yet it's worth mentioning that it runs fine without the -q flag, and perhaps you'll want to improve the coherence between the two modes.

That's not your mistake; QMASM is supposed to let you to apply coupler strengths to variables that have no weight, in both Ising and QUBO modes. See if 47535ce corrects the problem.

Yes, it's now fine. Thanks a lot, and congrats again for this nice tool!