About CQM model solving

Hi,

I had some problems with the D-Wave CQM solution. Under the condition of constraint is seldom, still can't find the optimal solution (using the classic solver validated results). Here is my objective function:

x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15

Here is the file contents of my constraints:

1*x0+1*x5+1*x10+1*x15+1*x16+1*x17+1*x18+1*x19-5*d0>=0

1*d0-1*x0>=0

1*d0-1*x5>=0

1*d0-1*x10>=0

1*d0-1*x15>=0

1*d0-1*x16>=0

1*d0-1*x17>=0

1*d0-1*x18>=0

1*d0-1*x19>=0

1*x1+1*x6+1*x11+1*x12+1*x20+1*x21+1*x22+1*x23-5*d1>=0

1*d1-1*x1>=0

1*d1-1*x6>=0

1*d1-1*x11>=0

1*d1-1*x12>=0

1*d1-1*x20>=0

1*d1-1*x21>=0

1*d1-1*x22>=0

1*d1-1*x23>=0

1*x2+1*x7+1*x8+1*x13+1*x24+1*x25+1*x26+1*x27-5*d2>=0

1*d2-1*x2>=0

1*d2-1*x7>=0

1*d2-1*x8>=0

1*d2-1*x13>=0

1*d2-1*x24>=0

1*d2-1*x25>=0

1*d2-1*x26>=0

1*d2-1*x27>=0

1*x3+1*x4+1*x9+1*x14+1*x28+1*x29+1*x30+1*x31-5*d3>=0

1*d3-1*x3>=0

1*d3-1*x4>=0

1*d3-1*x9>=0

1*d3-1*x14>=0

1*d3-1*x28>=0

1*d3-1*x29>=0

1*d3-1*x30>=0

1*d3-1*x31>=0

1*x0+1*x1+1*x2+1*x3+1*x4+1*x5+1*x6+1*x7+1*x8+1*x9+1*x10+1*x11+1*x12+1*x13+1*x14+x15>=1

Here is my using quantum annealing to solve the objective function of the python code snippet:

variable_num_x = Rounds * 32
variable_num_d = Rounds * 4
for i in range(variable_num_x):
    exec('x' + str(i) + '=Binary(' + str(i) + ')')
for i in range(variable_num_d):
    exec('d' + str(i) + '=Binary(' + str(i) + ')')
for i in range(Rounds * 16):
    fun += eval('x' + str(i))
cqm.set_objective(fun)
with open('./AES_quantum.lp', 'r') as file:
    for line in file:
        line_ = eval(line.replace("\n", ""))
        cqm.add_constraint(line_)
result = set()
print('---------Annealing---------')
for i in range(1000):
    response = LeapHybridCQMSampler(profile=num_dwave).sample_cqm(cqm)
for sample, satisfied, energy in response.data(['sample', 'is_feasible', 'energy']):
    if not satisfied:
        continue
    if energy < minenergy:
        minenergy = energy
        result.clear()
        temp = []
        for i in range(1, Rounds*16 + 1):
            temp.append((2 * int(sample[i]) - 1) * i)
        lenth = len(result)
        result.add(tuple(temp))
        if lenth < len(result) and minenergy == 1:
            print(temp)
    elif energy == minenergy:
        temp = []
        for i in range(1, Rounds*16 + 1):
            temp.append((2 * int(sample[i]) - 1) * i)
        lenth = len(result)
        result.add(tuple(temp))
        if lenth < len(result) and minenergy == 1:
            print(temp)

 

I knew that D-Wave was known for solving large scale problems, and I was wondering if the situation I was experiencing was a problem with my code (e.g., a problem with the format that D-Wave solves), or how I could get the right answer. Your answer is urgently needed.

 

0

Comments

1 comment
  • Hello,

    The best approach to verifying that your code has been written correctly is to start with a minimal code example and verifying the results match with expected results.

    Starting with 2 or 3 variables and working up to 4 or 5 variables is an ideal starting point. 
    The above is a little difficult to debug with so many moving parts out of the gate.

    It is also advisable to have the code example be completely contained, rather than including files, as this adds a layer of uncertainty.

    Ideally you would be able to copy and paste the code example and run it in a Python interpreter to be able to reproduce the behaviour.

    Along with the code example, a description of what the code example aims to do is also crucial. It is hard to know if the code is headed in the right direction without knowing the desired outcome. 
    Adding in-line comments makes it clear what each line is believed to do so corrections can be made more easily.

    Thanks so much for joining in the community and sharing your project!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post