BQM Generation Using SUM() Results in Float Variable

I'm trying to follow the "Ocean Programs for Beginners", 2.2 "Building a Quadratic Model".

I coded and ran this line (with supporting code) in my workspace:

bqm = sum(-x[i]-x[j]+2*x[i]*x[j] for i,j in G.edges)

The editor tells me "bqm" is a float variable, not a BQM object.

I'm wondering if Ocean Programs for Beginners is out-of-date?

Is there another document for beginners that's up-to-date?

Thanks, Ed

0

Comments

1 comment
  • Hi Ed,

    I am unable to reproduce the error that you noticed but I was able to run the following code without an error:

    >>>import networkx as nx
    >>>from dimod import Binary
    >>>G = nx.Graph()
    >>>G.add_edges_from([(1,2),(1,3),(2,4),(3,4),(3,5),(4,5)])
    >>>x = {n: Binary(n) for n in G.nodes}
    >>>bqm = sum(-x[i]-x[j]+2*x[i]*x[j] for i,j in G.edges)
    >>>bqm
    BinaryQuadraticModel({1: -2.0, 2: -2.0, 3: -3.0, 4: -3.0, 5: -2.0}, {(2, 1): 2.0, (3, 1): 2.0, (4, 2): 2.0, (4, 3): 2.0, (5, 3): 2.0, (5, 4): 2.0}, 0.0, 'BINARY')

    If you continue to get an error or want to learn what might be causing the issue, a code snippet will help.

    I noticed that you submitted other posts and it seems like you found the beginners guide difficult to follow. If that's the case, your feedback will help us improve it for users such as yourself.

    As I was working to reproduce the error, I found referring to the links listed in the guide helpful; mainly, the Maximum cut example.

    Also, here is a post that lists a few additional beginner friendly resources: 

    https://support.dwavesys.com/hc/en-us/community/posts/12116712151703/comments/13531065458327

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post