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

deprecate ModuleAvailableCache with RequirementCache #147

Merged
merged 16 commits into from
Sep 18, 2023
Merged

Conversation

Borda
Copy link
Member

@Borda Borda commented Jul 12, 2023

Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did all existing and newly added tests pass locally?

What does this PR do?

these two classes have almost identical code API and so it is confusing which shall be used when

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.

@Borda Borda requested review from carmocca and awaelchli as code owners July 12, 2023 09:39
@Borda Borda changed the title deprecate ModuleAvailableCache deprecate ModuleAvailableCache with RequirementCache Jul 12, 2023
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

This is not right. RequirementCache may check if the module is available but the functionality is different in the classes. I would agree with deprecating ModuleAvailableCache because we don't use it but the RequirementCache implementation should not be changed

@Borda
Copy link
Member Author

Borda commented Jul 12, 2023

I would agree with deprecating ModuleAvailableCache because we don't use it but the RequirementCache implementation should not be changed

So how can you use with RequirementCache("my.custom.subpackage")?
also, the base functionality does not change, it is extended...

@Borda Borda requested a review from carmocca July 12, 2023 15:37
@carmocca
Copy link
Contributor

For that sort of check you have ModuleAvailableCache (stateful) or module_available (functional). There's no need to cram everything into a single class. If we find that checking for module paths is useful in a stateful manner then we shouldn't deprecate ModuleAvailableCache

@Borda
Copy link
Member Author

Borda commented Jul 12, 2023

well, I don't understand... on one side you are fine with deprecation but then not extending functionality such that you do use only the module path... 😖

@carmocca
Copy link
Contributor

I'm proposing one of two paths:

  • Deprecate ModuleAvailableCache, use module_available if you want to check whether a module is available. There's no use of ModuleAvailableCache in the lightning repository
  • Do not deprecate ModuleAvailableCache.

@Borda
Copy link
Member Author

Borda commented Jul 12, 2023

Deprecate ModuleAvailableCache, use module_available if you want to check whether a module is available. There's no use of ModuleAvailableCache in the lightning repository

  • yes, but we may not know if someone else is using it ins a project based on PL so we need to preserve functionality
  • but module_available does not have cache so it is not the same equivalent

Do not deprecate ModuleAvailableCache.

so what is the difference when RequirementCache has almost the same functionality as ModuleAvailableCache so why not add an option just pass module the so the functionality overlap will be complete and can seamlessly use just one

@carmocca
Copy link
Contributor

yes, but we may not know if someone else is using it ins a project based on PL so we need to preserve functionality
but module_available does not have cache so it is not the same equivalent

I agree with this analysis. Why deprecate it then?

so what is the difference when RequirementCache has almost the same functionality as ModuleAvailableCache so why not add an option just pass module the so the functionality overlap will be complete and can seamlessly use just one

It's not the same functionality, one checks for packages, other for modules. Just as we have package_available and module_available. There's no need to create a mix of both classes with if checks to differentiate what the user passed just for the sake of having a single class.

@Borda
Copy link
Member Author

Borda commented Jul 12, 2023

I agree with this analysis. Why deprecate it then?

The primary intention was not to deprecate but reduce variety when one class does 90%. Why not add the missing 10% instead of creating a special class for the 10% and duplicating 50% of the code
also, typing had a problem with

req = []
if a == 1:
  req.append(RequirementCache(...))
else:
  req.append(ModuleAvailableCache(...))

It's not the same functionality, one checks for packages, other for modules. Just as we have package_available and module_available.

so what RequirementCache has even argument module?

@carmocca
Copy link
Contributor

You can annotate it with List[Union[RequirementCache, ModuleAvailableCache]] or you can introduce an interface that conforms to both and defines bool, and str

The module argument in RequirementCache is an optional last-ditch effort to check if the package is importable, to address issues where the requires() returns False but in reality the package was importable (example). Since the package name doesn't necessarily equal to the root module name, it had to be added. But it's not meant to be the principal mechanism to check whether a module is available. There's the other class/function for that.

@Borda
Copy link
Member Author

Borda commented Jul 14, 2023

You can annotate it with List[Union[RequirementCache, ModuleAvailableCache]] or you can introduce an interface that conforms to both and defines bool, and str

Sure, user is always welcome to write whole lit utils or lightning package, but

The module argument in RequirementCache is an optional last-ditch effort to check if the package is importable, to address issues where the requires() returns False but in reality the package was importable (example).

Cool, that is what I am saying, the feature is already there...

Since the package name doesn't necessarily equal to the root module name, it had to be added. But it's not meant to be the principal mechanism to check whether a module is available. There's the other class/function for that.

If requirement does not cover cases like sklesrn|scikit-learn we have design issue and shall not hack it extra module

Overall you are adding arguments why to do this change =)

@carmocca
Copy link
Contributor

What do you think here @awaelchli? Would you put the functionality of ModuleAvailableCache and RequirementCache class together in one class where we choose what implementation to call based on some checks (as currently implemented), or would you keep them separate?

@awaelchli
Copy link
Contributor

awaelchli commented Jul 14, 2023

Afaik we needed to have separate functions module_available and package_available with quite different logic. We iterated many times to find the right way to implement these so I don't think we should put them together again. This separation seems to work well.

So I would say then it makes the most sense to also keep the classes separate.

If there is a concern for code duplication, maybe a better approach would be to have utility functions to share code, instead of using inheritance (when it makes sense, I haven't looked closely).

@Borda
Copy link
Member Author

Borda commented Jul 14, 2023

So I would say then it makes the most sense to also keep the classes separate.

that is fine with me but then we shall remove module argument from RequirementCache

@awaelchli
Copy link
Contributor

This looks like it is used in several places for convenience. Removing it would break quite severely, since utilities is a core dependency of several Lightning packages. IMO none of these removals are worth the trouble for us and the users, this just looks like more work than it is worth it.

@Borda
Copy link
Member Author

Borda commented Jul 15, 2023

So to sumiraze, RequirementCache has a functionality which is half baked and you say we canot drop because people may use it and we canot fix/finish it becase you don't like it...

@Borda
Copy link
Member Author

Borda commented Jul 25, 2023

@carmocca could review this fix? 🐿️

@Borda Borda added the bug Something isn't working label Jul 25, 2023
@Borda Borda added the enhancement New feature or request label Jul 25, 2023
@carmocca
Copy link
Contributor

I dont have anything else to add to the discussion. I strongly suggest not continuing with this refactor. Is any bug or feature blocked by this PR?

@carmocca carmocca dismissed their stale review July 26, 2023 19:57

Nothing else to add

@Borda
Copy link
Member Author

Borda commented Jul 26, 2023

I strongly suggest not continuing with this refactor.

Still the module argument is very confusing...

@Borda Borda requested a review from justusschock September 15, 2023 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants