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

Duration/Memory Convenience Click Types #448

Merged
merged 7 commits into from
Jan 13, 2025

Conversation

TimothyWillard
Copy link
Contributor

Describe your changes.

This pull request add convenience click types for durations and memory. This is particularly useful in specifying time/memory limits for batch jobs in a user friendly way (i.e. --time=30min or --memory=4GB). While memory is probably specific to batch, durations could be used in other actions such as specifying forecast intervals.

Does this pull request make any user interface changes? If so please describe.

The user interface changes are adding DurationParamType and MemoryParamType to gempyor.shared_cli, but these changes are new and have no affect on existing user interfaces.

Those are reflected in updates to the documentation in docstrings of added functionality.

What does your pull request address? Tag relevant issues.

This pull request was spun out of GH-394, while it does not correspond to an exact issue it does help move GH-365 along by shrinking that PR's size.

Added the `DurationParamType` for specifying custom durations in a user
friendly way for CLI interfaces along with corresponding unit tests.
Also added unit tests, but still need to add documentation.
Fleshed out documentation for the `gempyor.shared_cli` module. Added
the ability to optionally return the converted memory as an int instead
of as a float to `MemoryParamType`. Removed pre-instantiated custom
click param types.
Bug in `MemoryParamType.convert` was failing if a unit was not given
with a value. Similar to `DurationParamType` it assumes that numbers
without a unit are given in the default unit of the type.
@TimothyWillard TimothyWillard added enhancement Request for improvement or addition of new feature(s). gempyor Concerns the Python core. medium priority Medium priority. next release Marks a PR as a target to include in the next release. labels Jan 7, 2025
@TimothyWillard TimothyWillard linked an issue Jan 7, 2025 that may be closed by this pull request
Copy link
Contributor

@pearsonca pearsonca left a comment

Choose a reason for hiding this comment

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

Seems mostly fine. One question about forbidding years (seems like the type should conceptually support it, even if we don't actually yet or don't want to accept values that large).

Also feels like shared_cli might be getting a bit bloated (even before adding these).

Does it make sense to start having a click extensions submodule or somesuch? And then shared_cli is importing generic capabilities from there?



@pytest.mark.parametrize("nonnegative", (True, False))
@pytest.mark.parametrize("value", ("abc", "$12.34", "12..3", "12years", "12.a2"))
Copy link
Contributor

Choose a reason for hiding this comment

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

is forbidding "years" about that being conceptually wrong or simply a duration we don't want to contemplate? seems as a generic thing, its appropriate for the tool to potentially support years, so a bit weird to explicitly test that it doesn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two issues with years: 1) years do not have a constant length (2024 was 366 days but most years are 365 days), and 2) python's timedelta class which doesn't have a years argument: https://docs.python.org/3/library/datetime.html#datetime.timedelta.

I could however see an argument for adding micro/milliseconds on conceptual ground if you would like? I just excluded those since it was too short for most practical use cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

so this is a duration we explicitly don't want to contemplate (primarily because it's an ambiguous unit for our case) - that's fine! It does feel worth noting somewhere that we don't allow this unit of time - like maybe in the method documentation? But I don't think we need, say, a special error message for years.

re ms - I think it's fine to not support it at this time. I think you're saying this would be one that we'd be willing to contemplate (i.e. we aren't testing to ensure its exclusion), but that we haven't bothered to yet support (because we don't think its practically useful).

flepimop/gempyor_pkg/src/gempyor/shared_cli.py Outdated Show resolved Hide resolved
@TimothyWillard
Copy link
Contributor Author

Also feels like shared_cli might be getting a bit bloated (even before adding these).

Do you want me to move these to _click?

@pearsonca
Copy link
Contributor

Also feels like shared_cli might be getting a bit bloated (even before adding these).

Do you want me to move these to _click?

If that's the standard approach to these kind of external-dependency extension/customizations, that seems the best way to manage it.

@pearsonca
Copy link
Contributor

Docs question: where are we capturing how bare numbers behave for these types? As in, where would I look, other than code, to see if --time=5 is 5 seconds vs 5 minutes?

@TimothyWillard
Copy link
Contributor Author

Docs question: where are we capturing how bare numbers behave for these types? As in, where would I look, other than code, to see if --time=5 is 5 seconds vs 5 minutes?

I'll document.

* Added parameters to explicitly control the behavior of unitless values
  to both `DurationParamType` and `MemoryParamType`.
* Fleshed out documentation for custom types.
Extracted `DurationParamType` and `MemoryParamType` out of
`gempyor.shared_cli` into `gempyor._click`.
@TimothyWillard
Copy link
Contributor Author

  • Extracted these two custom types from gempyor.shared_cli to gempyor._click,
  • Added extra behavior around unitless values for both custom types including a way to outright reject said values if wanted along with corresponding docs/tests, and
  • Corrected documentation typos.

@TimothyWillard TimothyWillard merged commit 533fcd9 into dev Jan 13, 2025
3 checks passed
@TimothyWillard TimothyWillard deleted the feature/365/convenience-click-types branch January 13, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request for improvement or addition of new feature(s). gempyor Concerns the Python core. medium priority Medium priority. next release Marks a PR as a target to include in the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request]: EMCEE integration with inference_job.py
4 participants