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.)
Comments
Hi Tim,
The functionality to convert a NumPy array to a binary quadratic model is available in Ocean SDK. Here is a list of all the conversions to and from other formats that are supported: https://docs.ocean.dwavesys.com/projects/dimod/en/latest/reference/bqm/binary_quadratic_model.html#converting-to-and-from-other-formats
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:
For very large problems, dimod.AdjVectorBQM.from_numpy_matrix is recommended over dimod.BinaryQuadraticModel
.from_numpy_matrix.
Please let us know if you have any further questions.
Please sign in to leave a comment.