Getting a large QUBO matrix (1,000 rows and columns) from Excel into Python/IDE

Is there a way to bring a large QUBO matrix, with say 1,000 rows and columns, from Excel (i.e. values in cells) into Python code used by the Leap IDE Workspace? (If it was a small QUBO matrix then it is straightforward to use text to create the QUBO matrix in the Python code.) 

0

Comments

1 comment
  • Hi Tim,

    The functionality to convert a NumPy array to a binary quadratic model is available in Ocean SDK. There is a list of all the conversions to and from other formats that are supported in the documentation.

    So, in order to import data from an excel worksheet, save it to a csv file. This csv file can be loaded as a NumPy array by using numpy.loadtxt().

    Here is an example:

    import numpy as np
    import dimod

    f = open("Q_excel.csv")
    Q = np.loadtxt(f,delimiter = ",")

    bqm = dimod.BinaryQuadraticModel.from_numpy_matrix(Q)

    AdjVectorBQM has been deprecated and BinaryQuadraticModel can be used for large problems.

    Please let us know if you have any further questions.

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post