entropicalabs / openqaoa

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

type object 'VRP' has no attribute 'from_distance_matrix' #271

Closed mayank145678 closed 11 months ago

mayank145678 commented 11 months ago

Description

I've been exploring the openqaoa package for solving vehicle routing problems (VRP) and encountered an issue when trying to use the from_distance_matrix method with the VRP class. I have run the code using colab.

Steps to Reproduce

  1. Clone the repository and checkout the dev branch:

    !git clone https://github.com/entropicalabs/openqaoa 
    
    cd openqaoa 
    
    !git checkout dev
    
    !pip install .
  2. Run the following Python code:

    from openqaoa.problems import VRP
    distance_matrix = [ [0, 2, 5, 10, 9, 9], [2, 0, 17, 6, 8, 14], [5, 17, 0, 10, 4, 7], [10, 6, 10, 0, 7, 11],  [9, 8, 4, 7, 0, 16], [9, 14, 7, 11, 16, 0]]
    
    vrp = VRP.from_distance_matrix(matrix=distance_matrix, n_vehicles=2)

Expected Behavior

I expected to create a VRP instance using the from_distance_matrix method.

Actual Behavior

I encountered the following error:

AttributeError: type object 'VRP' has no attribute 'from_distance_matrix'

Additional Information

I noticed a couple of warnings regarding missing modules (azure and qiskit), but I'm not sure if they are related to this issue.

Any assistance or guidance would be greatly appreciated. Thanks!

vishal-ph commented 11 months ago

@KilianPoirier, can you take a look at this?

KilianPoirier commented 11 months ago

Hello @mayank145678 ! Thanks for trying out OpenQAOA and raising this issue.

Your error comes from conflicting versions of the package available locally and on PyPI. The version of openqaoa-core that you installed is in fact outdated.

When you use pip install . from /openqaoa, you install the local openqaoa package. Since we separated the package into different plugins, the openqaoa package only specifies the requirements for the installer that will use the plugins versions available on PyPI. To prevent that from happening, we recommend installing the plugins locally using the Makefile with the command make local-install. More details are available in README.md in the section "Install via git clone".

I tested your code using a local install with the Makefile and it works, you should be able to use OpenQAOA from there. Let us know if you face any other problems.

mayank145678 commented 11 months ago

Thank you for the reply. Finally, the issue got resolved. @vishal-ph @KilianPoirier