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

Current logic in the frontend prevents using the default filename #153

Open
markelg opened this issue Feb 28, 2022 · 4 comments
Open

Current logic in the frontend prevents using the default filename #153

markelg opened this issue Feb 28, 2022 · 4 comments

Comments

@markelg
Copy link

markelg commented Feb 28, 2022

Current logic in the frontend does not let me to use the default filename

        # some logic about reusing weights with either filename or weights args
        if reuse_weights and (filename is None) and (weights is None):
            raise ValueError('To reuse weights, you need to provide either filename or weights.')

I think it should try to load the weights from default filename instead of raising an error. Am I missing something?

The pattern used to build the default filename is good and useful. I can find some time to write a PR if you want.

@raphaeldussin
Copy link
Contributor

agreed, I think something in the logic has been broken. @huard and @aulemahal any thoughts on this?
One workaround is for you to specify explicitly the name of the weights file you want to write.

PRs are always welcome!

@aulemahal
Copy link
Collaborator

I agree that this would make sense! I don't think it ever worked, though, seems to me that the current behaviour was introduced when reuse_weights was introduced, but I might be mistaken.

It think it would be a matter of setting self.filename prior to this check and then add a check to see if the file exists.

@markelg
Copy link
Author

markelg commented Mar 21, 2022

I am testing the solution proposed. Not unexpectedly, it breaks this test:

    # check fails if no weights are provided
    with pytest.raises(ValueError):
        regridder_reuse = xe.Regridder(ds_in, ds_out, method, reuse_weights=True)

Because that combination of arguments now compute and save the weights to the default file.

I am not sure about how to proceeded in order to not to break this behavior. Maybe add a special case with filename="default"?

@huard
Copy link
Contributor

huard commented May 18, 2022

The filename logic dates back to the time ESMF wrote the weights to file, and xESMF had to read them from disk. About two years ago, ESMF introduced a mechanism to share the weights in memory. The current code is the result of trying to support both the older file-based and memory-based approaches without breaking legacy code.

I'm not sure I would want xESMF to automatically read from a default file name that is not directly visible from the docstring. It feels error-prone.

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

No branches or pull requests

4 participants