entropicalabs / openqaoa

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

Add support to python 3.11 #311

Open rodolfocarobene opened 1 month ago

rodolfocarobene commented 1 month ago

Fixes #307.

Description

For the moment I've just upgraded all the setup.py and the workflows. I will remove this PR from draft mode as soon as I'm finished with the changes. In particular, I want to check that the code is all compatible with python3.11 or if modifications are required. I've yet to check the correctness of the dependencies in the opeqaoa-core: they may be outdated or require changes with the python version

Checklist

Type of change

Please delete options that are not relevant.

rodolfocarobene commented 1 month ago

Hi, locally all the testes pass correctly (or fail because they are using connections I cannot access) so I would say it is all working. We should check with the workflows if everything is truly good.

Tbh, I think this project could benefit of some modification in the setup.py / pyproject / version / dependencies organization. It seems to me that there is some duplication in the versioning and that the setup.py could be completely removed in favor of the pyproject. Moreover, having something like poetry to manage dependency could help automatize some of the things I did today :-)

KilianPoirier commented 1 month ago

Hi @rodolfocarobene , thanks for filing a PR to solve this issue.

I have a few comments/questions:

If you want to contribute further and reorganise setup.py / pyproject / version / dependencies, feel free to do so. I would be happy to help you integrate these changes as well. Since this is a Unitary Hack related PR, you may as well tackle this cleaning task after we approve this PR. Let me know what you think!

rodolfocarobene commented 1 month ago

Sorry @KilianPoirier , I think I had slightly misunderstood the issue. I've now removed all the setup.py files and the requirements.txt, moving everything to the pyproject.toml as it is advised (I believe). Since "setuptools" is in the build-system requirements, it should be installed correctly when installing the packages.

I've tried it on a new environment and the installation of every specific package seemed to work. Please let me know if it is ok for you r if there are still modification required.

(Sorry for the useless line diffs, my editor removes automatically leading spaces... If you want I can remove them)

KilianPoirier commented 1 month ago

Hey @rodolfocarobene thank you for revisiting your PR and migrating all of the setup instructions to pyproject.toml. It looks good at first glance.

I have approved the test workflow but it seemed like it fails at installation. I think it is due to the requirements on the version of ipython that is not compatible with the lowest versions of python we are supporting.

I think the best way to ensure that the test pass both locally and in the GH workflow is to use at least two environments, one with python 3.8 and one with a higher version, I think 3.12 should do the trick. I'll wait for the nest changes to approve the tests and review the code once the tests are clear.

rodolfocarobene commented 1 month ago

Hi, I was trying to fix the errors, but I noticed that mitiq is at the moment not compatible with Python 3.12... https://github.com/unitaryfund/mitiq/blob/d35b7aad59b393aa539ceb2cb52244e84c19c1ee/setup.py#L70

Since openqaoa-core requires it (in dev) I'm afraid that Python3.12 cannot be fully supported

KilianPoirier commented 1 month ago

Alright, then I think it's fair to keep it to python 3.11, I also noticed that they recently dropped support for python 3.8. Maybe we can change our minimum requirements to >=3.9 too.

rodolfocarobene commented 1 month ago

Alright, then I think it's fair to keep it to python 3.11, I also noticed that they recently dropped support for python 3.8. Maybe we can change our minimum requirements to >=3.9 too.

I think it makes sense, python 3.8 is a bit outdated right now. I'm working on the updates :-)

rodolfocarobene commented 1 month ago

Now the installation should work both for python3.9 and python3.11. Some tests are failing locally, but I think it's just because I don't have the "right hardware" (api.QVMError: Could not communicate with QVM at http://127.0.0.1:5000)

rodolfocarobene commented 1 month ago

Fixing dependencies once again (maybe one of the last time? :-)). For the moment I limited the version of some libraries, while I think we should instead modify the code to support higher versions of those libraries, but maybe in another PR.

In particular I limited:

Locally the installation works fine, some tests of pyquil fail. In general because of connections, a couple for some other reason that I am having some trouble understanding:

from openqaoa.backends.qaoa_device import create_device
device = create_device(location="qcs", name="7q-noisy-qvm")

>>>ValueError: Invalid device location, Choose from: dict_keys(['local', 'azure', 'aws', 'ibmq'])

Also in the workflow the same error is being raised, is it a version thing or something else?

KilianPoirier commented 1 month ago

Nice! Let's see how the workflow runs this time.

I'm currently pushing some changes for the mitiq issue as you have noticed but other problems arose when fixing this, it may take a bit more time than expected. No worries though if the only error is this one on your side, I'll approve your PR and fix it myself.

Concerning the QVM issue it may be due to a problem with pyquil, if you don't have the qvm installed separately, the tests won't pass locally. This should be caught by the GH workflow.

rodolfocarobene commented 1 month ago

There is still some problem with the pyquil tests...

KilianPoirier commented 1 month ago

Hey @rodolfocarobene , the error seems to come from a faulty install of pyquil since the pyquil backends are not resolved in the list of backends in the tests.

I also tried to branch out from your changes and test locally but the make command doesn't resolve. Have you tried looking into this? The makefile only runs an install of the pip install -e ./openqaoa-*/.

Here is what happens when I try installing locally using your modified pyproject.toml

image

Maybe the first step to try and debug this would be to make changes one by one, first upgrading the version of python and related dependencies, making sure the tests pass both locally and on the GH workflow. Then, migrate all of the changes to the pyproject.toml. Let me know what you think about this, or if you have any other suggestion.

rodolfocarobene commented 1 month ago

What version of python are you using? I don't see the see behavior... quite weird. I'm gonna work on this, if I cannot do it I will revert to the setup.py and split this in half :-)

rodolfocarobene commented 1 month ago

Hey, @KilianPoirier, I've added the explicit location of the packages (for some reason it was required for me, but I suppose it doesn't hurt). While for the pyquil plugin I had written "braket" instead "pyquil" so it made sense that it wasn't working... it should be fixed

KilianPoirier commented 1 month ago

Good news, the tests seem to pass! Nice job fixing all of the issues I will have a proper review of the code but it should be pretty quick at this point.

rodolfocarobene commented 1 month ago

Sorry, I had forgot to check some stuff (mainly docs and workflows) that had some outdated stuff. At the same time, with the introduction of the pyproject.toml the _version.py and some other configuration files became obsolete, I should have updated everything in a reasonable manner. Therefore, the last commit is touching many files, but is mostly redundant/not important things.

Maybe in the future could be convenient a script to update the version (both of python and the packages) in all the repository at once. :-)

KilianPoirier commented 1 month ago

I just approved the PR and assigned you to the issue and bounty! Good job tackling this issue and glad to count you as an openqaoa contributor :)

rodolfocarobene commented 1 month ago

Thanks @KilianPoirier ! It was a pleasure for me :-) . Maybe for the hackaton the issue should be closed? Since it seems to me that it still not "resolved" (link)