-
Notifications
You must be signed in to change notification settings - Fork 139
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
Implement warnings in Parcels #1672
Implement warnings in Parcels #1672
Conversation
for more information, see https://pre-commit.ci
Wow, thank you so much for this PR, @andrew-s28! I had a quick lok through it, and it's beautifully concise and seems pretty complete! @VeckoTheGecko and I will go more carefully through it in the coming days; but this certainly is a fantastic starting point for (if not a complete version of) this refectoring! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @andrew-s28 ! This is exactly the direction we're wanting to take the codebase.
Additional feedback:
Here, I have implemented three custom warning classes,
FieldSetWarning
,KernelWarning
, andFileWarning
that I think encompass the majority of warnings that Parcels was raising. A few warnings (e.g.,ParticleSet is empty...
) did not fit neatly into these categories, so I assigned themRuntimeWarning
.
I like this structure of warnings.
It is worth noting that I was unable to completely remove the logger module
I think its worth keeping the logging module, and will be useful in future. Though its nice to have the .warning_once
/.info_once
stuff cleaned away.
I think it could make sense to bring the warnings, statuscode exceptions, and logger all under the same module (perhaps
exceptions.py
)
I agree with the note about structure, but this would be a breaking change for users that I'm not comfortable rolling out in a minor release. It would require an update to tutorials, and (as you mention) there is no "home" for StatusCodes
. Let's keep with the current structure.
Co-authored-by: Vecko <[email protected]>
…only check line for expected warning
…arning functionality in fieldfilebuffer
Thanks for the feedback @VeckoTheGecko and @erikvansebille. I think I have incorporated most or all of your suggested changes with the recent commits.
I didn't really consider that this would be a breaking change, so this makes sense to me. Perhaps something to keep in mind for future major version releases then 😄. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice implementation, no further comments!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just waiting on ✅. Just merged with master
and pushed some minor edits (e.g., .. deprecated
docstring syntax not working with individual parameters, only on a function/object/module level)
Resolves #1600 by implementing the warnings module in Parcels.
This is presented as a draft PR since I think some of the details of the implementation will benefit from discussion to make sure that things are in their best state.
Here, I have implemented three custom warning classes,
FieldSetWarning
,KernelWarning
, andFileWarning
that I think encompass the majority of warnings that Parcels was raising. A few warnings (e.g.,ParticleSet is empty...
) did not fit neatly into these categories, so I assigned themRuntimeWarning
.I also added these warnings to the documentation, with a short description of each that would hopefully be a resource for users trying to address the warning. The naming of warnings and their docstrings is something that could probably benefit from the input of Parcels maintainers.
Tests were added for a few of the warnings (i.e., the test makes sure the warning is properly raised), but I couldn't get test cases working for all of the possible cases, since some are fairly complicated to raise (especially those that have to do with I/O or chunking, like the
FileWarning
). Input here is welcome also.Warning Classes
FieldSetWarning
FileWarning
KernelWarning
It is worth noting that I was unable to completely remove the logger module, since Parcels uses it to print info (which is distinct from the warnings). See below for the list of where this logging remains. I left a bare-bones logging implementation in the
logging.py
module to support these. It is also worth noting that Parcels also implements custom exceptions in thestatuscodes.py
module.Remaining Logging Info
fieldset.py
logger.info(f"Generating FieldSet output with basename: {filename}")
kernel.py
logger.info(f"Compiled {self.name} ==> {self.src_file}")
particleset.py
logger.info(f"Output files are stored in {output_file.fname}.")
rng.py
logger.info(f"Compiled ParcelsRandom ==> {self.src_file}")
I think it could make sense to bring the warnings, statuscode exceptions, and logger all under the same module (perhaps
exceptions.py
?) but that does potentially leave theStatusCode
class in a weird place. I do think making this change would simplify code base. If we are in favor of making this change, then I can update the PR accordingly (or open a new one if it does not fit into the scope of this one).