entropicalabs / openqaoa

Multi-backend SDK for quantum optimisation
MIT License
113 stars 59 forks source link

"ImportError: cannot import name 'MaximumCut' from 'openqaoa.problems.problem'" #250

Closed robliou closed 1 year ago

robliou commented 1 year ago

Prerequisites

Before raising this issue, I have already checked that I am:

Describe the bug

Hello!

I am trying to use openqaoa to solve a maximum-cut -type question. Based on the tutorial here: (https://openqaoa.entropicalabs.com/problems/maximum-cut/#maxcut-in-openqaoa), this is the sample code given to solve a small Max Cut question:

import numpy as np
import networkx as nx
#from openqaoa.utilities import plot_graph

# Generating a graph of nodes

G = nx.generators.fast_gnp_random_graph(n=6, p=0.6, seed=42)

from openqaoa.utilities import plot_graph
plot_graph(G)

from openqaoa.problems.problem import MaximumCut

maxcut_prob = MaximumCut(G)
maxcut_qubo = maxcut_prob.qubo

maxcut_qubo.hamiltonian.expression

However, after installing all dependencies and running the code, I get the following error:

image

To Reproduce

Steps to reproduce the behavior:

  1. Create an empty folder
  2. Place the above code into a python file
  3. Install necessary dependencies, especially openqaoa
  4. Run the file

Expected behavior

Metadata/ solution should be produced, not the error above.

vishal-ph commented 1 year ago

@robliou, thanks again for raising this issue! This seems like the case of outdated documentation that needs to reflect the new changes in the codebase. If you look inside the problems folder in openqaoa-core, you will see that each problem class is defined in their individual python files. Therefore, the correct syntax to import MaximumCut now, is the following: from openqaoa.problems import MaximumCut

P.S. We will fix this on the website

robliou commented 1 year ago

@vishal-ph

Awesome, yes, using this new syntax, I am able to get the program to finally run. However, it looks like at 100 nodes, I may be exceeding the maximum allowed dimension? If so, I will open up another issue for this,

In the meantime, feel free to close this issue and thanks for your help with this!

Best,

Rob