Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore pytest deprecation warning for monty dependency of pymatgen #6680

Closed

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Jan 1, 2025

It is just annoy to have pymatgen as the dependency we REALLLY need to move it out.

@unkcpz unkcpz requested a review from agoscinski as a code owner January 1, 2025 23:52
@unkcpz unkcpz force-pushed the ignore-deprecate-warning-from-pymatgen branch 3 times, most recently from a799eb8 to a1c8dd4 Compare January 2, 2025 00:12
@unkcpz unkcpz marked this pull request as draft January 2, 2025 00:42
@unkcpz unkcpz force-pushed the ignore-deprecate-warning-from-pymatgen branch from a1c8dd4 to c358ee9 Compare January 2, 2025 00:45
@unkcpz
Copy link
Member Author

unkcpz commented Jan 2, 2025

This is how they raise deprecation warnings to fail tests run in downstream libraries' CI, it is ridiculous! Took me quite long to figure out why the failed "warning" was only happened on CI but not locally. They literally RAISE the warning, very confuse.

        if (
            _deadline is not None
            and os.getenv("CI") is not None
            and datetime.now() > _deadline
            and _is_in_owner_repo()
        ):
            raise DeprecationWarning(
                f"This function should have been removed on {_deadline:%Y-%m-%d}."
            )

@unkcpz unkcpz force-pushed the ignore-deprecate-warning-from-pymatgen branch from c358ee9 to 8e0581b Compare January 2, 2025 01:53
@unkcpz
Copy link
Member Author

unkcpz commented Jan 2, 2025

@mikibonacci do you think we can move it to aiida-atomistic?

@unkcpz unkcpz force-pushed the ignore-deprecate-warning-from-pymatgen branch from 8e0581b to 6050b5a Compare January 2, 2025 01:55
@unkcpz unkcpz marked this pull request as ready for review January 2, 2025 01:55
@mikibonacci
Copy link
Contributor

Hi @unkcpz, are you saying we should move all the pymatgen-related tests (and pymatgne dependency) in aiida-atomistic? For me should be fine, however we still have the LegacyStructureData in aiida-core, so I am not sure it is the best way - at least for now.
Additionally, would the tests fail for aiida-atomistic then? I am not sure I got 100% of the issue here.

Thanks a lot for catching this, BTW!

@mikibonacci
Copy link
Contributor

Also: I was fixing the aiida-atomistic PR, but now I see that indeed the tests are failing due to this issue 😞

@bastonero
Copy link
Contributor

Just passing since i saw tests failing on aiida-quantumespresso. Please, do not remove the core StructureData as I have put tons of work on HubbardStructureData and associated plugin (also, now people started using it for XPS, XAS), and we use a lot pymatgen since they implement very useful routines, which we would otherwise need to reimplement. I also don't know how much it will take to transition to the newer StructureData of aiida-atomistic, since i won't have time and i don't know who will have it

@bastonero
Copy link
Contributor

PS: since this is blocking any aiida related plugin, do you think we can quickly fix and merge this PR?

@unkcpz
Copy link
Member Author

unkcpz commented Jan 6, 2025

I also don't know how much it will take to transition to the newer StructureData of aiida-atomistic, since i won't have time and i don't know who will have it

Make sense. But we have to struggle when pymatgen did bad things fail downstream libs like this one. I was thinking to move all pymatgen related tests to run in a separate CI and make it the test not mandatory to pass if it is the problem from upstream pymatgen. What do you think?? @bastonero

PS: since this is blocking any aiida related plugin, do you think we can quickly fix and merge this PR?

No quick fix from our side, because pymatgen raise the warning where it should be just using warning.warn to print to the pytest summary. Either we wait them to fix or we as I mentioned above we move it to separate CI test bundle. Not sure if they fix the issue, would you mind to open an issue there (the source of the issue is from monty library)?

@bastonero
Copy link
Contributor

Now that I am thinking better, I guess this will affect as well aiida-quantumespresso, since we import pymatgen functions, AFAIR. I honestely still didn't understand well what is the problem, but the fact they raise the warning instead of using the right function. Maybe it's better if you give it go, so you know better how to state the problem?

@unkcpz
Copy link
Member Author

unkcpz commented Jan 6, 2025

Sure, I'll open the issue. Here it is materialsvirtuallab/monty#738

Copy link
Contributor

@agoscinski agoscinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a newer version of monty released this year that has changed the dev.py. Maybe we can try to use this one. But in any case I am fine to exclude these tests temporary. Would just be more specific in the skip function (see my comment)

@@ -113,8 +113,14 @@ def test_obj():
assert left == right


skip_pymatgen_anyhow = pytest.mark.skipif(not has_pymatgen(), reason='Unable to import pymatgen')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this a temporary fix that should be removed after it has been fixed upstream. Could we use not has_pymatgen but a custom function

def is_pymatgen_upstream_issue738() -> bool:
    """Checks if we encounter the upstream bug in pymatgen referenced in materialsvirtuallab/monty issue #738.

    We cannot fix the bug for now and have to skip the tests that encounter this bug.
    """
    try:
        from pymatgen.core.structure import Molecule
    except DeprecationWarning as exc:
        exc.args[0] == "This function should have been removed on 2025-01-01."
        return True

    return False

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then maybe

Suggested change
skip_pymatgen_anyhow = pytest.mark.skipif(not has_pymatgen(), reason='Unable to import pymatgen')
skip_pymatgen_issue738 = pytest.mark.skipif(is_pymatgen_upstream_issue738(), reason='upstream issue
#738 in materialsvirtuallab/monty ')

@danielhollas
Copy link
Collaborator

Incidentally, I am updating the uv lockfile in #6676. In that PR, only Python 3.9 tests are now failing.
I like the suggestion from the monty issue tracker of simply unsetting the CI environment variable. That way we could avoid any changes to the test suite. I'll give it a try.

@danielhollas
Copy link
Collaborator

NOTE: A good discussion about the issue is happening in the pymatgen repo here:
materialsproject/pymatgen#4243
I'll make a comment there and try to convince them to make a release for Python 3.9.

@unkcpz
Copy link
Member Author

unkcpz commented Jan 7, 2025

I like the suggestion from the monty issue tracker of simply unsetting the CI environment variable.

I'd rather not change this even though it seems safe for the moment. The env variable is global from github and we don't know if github will use this for something else of not.

@danielhollas
Copy link
Collaborator

@unkcpz I agree it's not an ideal solution. But this workaround is quite targeted, only in two specific job steps, and only for Python 3.9. Since will be dropping Python 3.9 support sometimes this year anyway I believe this is acceptable, and is much simpler then mucking around with the test suite. Please see #6676

unkcpz pushed a commit that referenced this pull request Jan 8, 2025
Recreate the uv lockfile (`uv.lock`) with a newer uv version that uses an updated resolution strategy.

Previously, it tried to find a version of the package that would be compatible with all supported Python versions, which in turn meant that if a package dropped support for 3.9 for example, we'd be stuck on an old version.
In the new uv version, this is not the case, and uv will try to find the newest version of a package for a given python version.

Incidentally, this also help partly resolve the pymatgen issue, see #6680. The issue has been fixed in a new version of monty package, which however does not support Python 3.9. So in the updated lockfile, the issue is fixed for Python >=3.10.

For Python 3.9, a workaround suggested in materialsproject/pymatgen#4243, and unset the CI environmental variable.
Since this workaround is quite targeted (only in two specific job steps, and only for Python 3.9), I believe this is acceptable, and we will be dropping Python 3.9 support sometimes this year anyway.
@unkcpz
Copy link
Member Author

unkcpz commented Jan 8, 2025

superseded by #6676

@unkcpz unkcpz closed this Jan 8, 2025
@unkcpz unkcpz deleted the ignore-deprecate-warning-from-pymatgen branch January 8, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants