qiboteam / qibo

A framework for quantum computing
https://qibo.science
Apache License 2.0
287 stars 58 forks source link

Test failing on `Pytorch` #1348

Open Sam-XiaoyueLi opened 3 months ago

Sam-XiaoyueLi commented 3 months ago

The following test is failing on pytorch only while everything else passes.

https://github.com/qiboteam/qibo/blob/ce7076a89acbec04fc3eb21eeb754709257db2be/tests/test_models_dbi.py#L128-L143

The error message is: FAILED tests/test_models_dbi.py::test_polynomial_energy_fluctuation[pytorch] - ValueError: No solution can be found with polynomial approximation. Increase `n...

In order to reproduce the error, navigate to branch DBI_gradient_train, commit https://github.com/qiboteam/qibo/commit/ce7076a89acbec04fc3eb21eeb754709257db2be. Run pytest tests/test_models_dbi.py.

@scarrazza @MatteoRobbiati @andrea-pasquale @alecandido If possible, please help take a look. Thanks!

MatteoRobbiati commented 3 months ago

Can you please extend the error message including all the lines? Thanks!

alecandido commented 3 months ago

The error cannot be reproduced universally.

Here the logs of a run on my Linux desktop

```py ❯ : poe test -k test_polynomial_energy_fluctuation Poe => pytest -k test_polynomial_energy_fluctuation ========================================= test session starts ========================================== platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.5.0 rootdir: /home/alessandro/Projects/quantum/qibo configfile: pyproject.toml testpaths: tests/ plugins: cov-4.1.0, anyio-4.4.0 collected 12929 items / 12925 deselected / 4 selected tests/test_models_dbi.py .... [100%] =========================================== warnings summary =========================================== .venv/lib/python3.11/site-packages/hyperopt/atpe.py:19 /home/alessandro/Projects/quantum/qibo/.venv/lib/python3.11/site-packages/hyperopt/atpe.py:19: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html import pkg_resources tests/test_models_dbi.py: 24 warnings /home/alessandro/Projects/quantum/qibo/src/qibo/models/dbi/double_bracket.py:106: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray. np.array(np.matrix(self.backend.to_numpy(operator)).getH()) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ---------- coverage: platform linux, python 3.11.8-final-0 ----------- Coverage HTML written to dir htmlcov Coverage XML written to file coverage.xml ========================================= slowest 60 durations ========================================= 0.18s call tests/test_models_dbi.py::test_polynomial_energy_fluctuation[tensorflow] 0.01s call tests/test_models_dbi.py::test_polynomial_energy_fluctuation[numpy] 0.01s call tests/test_models_dbi.py::test_polynomial_energy_fluctuation[pytorch] (9 durations < 0.005s hidden. Use -vv to show these durations.) =========================== 4 passed, 12925 deselected, 25 warnings in 8.17s =========================== ```

We already observed platform-dependent behaviors with Pytorch, especially related to MacOS. Cf. https://github.com/qiboteam/qibo/issues/1313

@Sam-XiaoyueLi could you provide information about your environment? (machine/architecture, system, python version and similar)

Simone-Bordoni commented 3 months ago

I am also etting the same error after merging the new DBI module in #1276 May this be related to #1351 ?

Sam-XiaoyueLi commented 3 months ago

The error cannot be reproduced universally.

Here the logs of a run on my Linux desktop We already observed platform-dependent behaviors with Pytorch, especially related to MacOS. Cf. #1313

@Sam-XiaoyueLi could you provide information about your environment? (machine/architecture, system, python version and similar)

Hi, my machine is MacOS 12.6, Python 3.11.7. Anything else I need to provide? Thanks for the help!

alecandido commented 3 months ago

Hi, my machine is MacOS 12.6, Python 3.11.7. Anything else I need to provide? Thanks for the help!

Being MacOS and py3.11 is most likely enough information.

In general, it could be relevant to know if your processor is Apple Silicon (M1, M2, ...) or an Intel processor. But more for missing dependencies issues, it should not be the case.

alecandido commented 3 months ago

I actually ran the same line above on the specified commit in a MacOS M2 system, on Python 3.11.8, and I did not get any failure (same Pytest output as above). The main difference could be the usage of nix-darwin for system packages, but the Python packages should be the exact same of any other Apple Silicon system, with the same Python version (taken from PyPI).

@Sam-XiaoyueLi could you please run the command in the first line of the hidden section in https://github.com/qiboteam/qibo/issues/1348#issuecomment-2151359817 and post the analogue output with the full failure and traceback?