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

Add functions to check enabled checkpoints #26

Merged
merged 3 commits into from
May 27, 2021
Merged

Add functions to check enabled checkpoints #26

merged 3 commits into from
May 27, 2021

Conversation

bencottier
Copy link
Contributor

This PR adds two functions:

  1. is_enabled(name): returns true if the checkpoint name has been configured.
  2. enabled(): returns a vector of all enabled (configured) checkpoints.

I think both would be useful for users.

@codecov
Copy link

codecov bot commented May 27, 2021

Codecov Report

Merging #26 (9047404) into main (4ceb398) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #26      +/-   ##
==========================================
+ Coverage   94.89%   94.92%   +0.03%     
==========================================
  Files           5        5              
  Lines         137      138       +1     
==========================================
+ Hits          130      131       +1     
  Misses          7        7              
Impacted Files Coverage Δ
src/Checkpoints.jl 91.89% <100.00%> (+0.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ceb398...9047404. Read the comment docs.

Copy link
Contributor

@mzgubic mzgubic left a comment

Choose a reason for hiding this comment

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

Great work overall. Some suggestions but feel free to merge when ready.

enabled() = filter(is_enabled, available())

"""
is_enabled(name) -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
is_enabled(name) -> Bool
_isenabled(name) -> Bool

i.e. no _ to be consistent with julia convention, e.g. isa isqrt isone isodd isnan isinf isdir iszero isreal.

My preference is usually to keep the API as small as possible, because that reduces the probability of having to make a breaking change. So in this case I would just go with exporting enabled(). We can always export _isenabled later if there is a need.

p.s. we should export enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My preference is usually to keep the API as small as possible

That makes sense, I was thinking that we may as well make it "available" (not exported but not _'d either). But it's not needed yet.

I didn't export enabled by analogy to available not being exported. Does that change your view at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like config is not exported either (I think we should export it).

Let's export enabled, but not available (since there seems to be no use case for available outside of the package, but there is for enabled).

@oxinabox thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A reason I see for not exporting these functions is readability in user code. It's not obvious that config is about checkpoints if the call is e.g. config(["value1", "value2"], path). Even more so for enabled() on its own. If we exported it, I would prefer to call it enabled_checkpoints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mzgubic let me know if it looks good now

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM!

Returns `true` if the checkpoint `name`(s) are [`config`](@ref)ured.
"""
is_enabled(name) = haskey(CHECKPOINTS, name) && CHECKPOINTS[name] !== nothing
is_enabled(names...) = all(is_enabled.(names))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
is_enabled(names...) = all(is_enabled.(names))

Do we need that? Also, it is probably confusing to see is_enabled (i.e. singular) with several arguments.

@bencottier bencottier merged commit 9283756 into main May 27, 2021
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.

2 participants