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 the optional install_pkgs keyword argument to the @load macro #346

Merged
merged 1 commit into from
Dec 14, 2020
Merged

Add the optional install_pkgs keyword argument to the @load macro #346

merged 1 commit into from
Dec 14, 2020

Conversation

DilumAluthge
Copy link
Member

@DilumAluthge DilumAluthge commented Nov 29, 2020

This pull request adds the optional install_pkgs keyword argument to the @load macro.

If install_pkgs is true, then any necessary packages will automatically be installed.

The default value is install_pkgs=false.

Example usage:

julia> using MLJModels

julia> @load NeuralNetworkClassifier install_pkgs=true

Motivation

@juliohm has brought up that installing all of the necessary packages is one of the pain points for Julia beginners when they first start out using MLJ.

Therefore, we can tell these beginner users to use install_pkgs=true, and then the necessary packages will automatically be installed for them.

@DilumAluthge DilumAluthge changed the title Add the install_packages keyword argument to the @load macro Add the optional install_packages keyword argument to the @load macro Nov 29, 2020
@DilumAluthge DilumAluthge changed the base branch from master to dev November 29, 2020 05:50
@DilumAluthge DilumAluthge marked this pull request as ready for review November 30, 2020 02:57
@ablaom
Copy link
Member

ablaom commented Nov 30, 2020

I really like this proposal.

@DilumAluthge In case install_packages is false and the package is not in the env, could we catch the error and issue a suggestion "Specify install_packages=true to automatically add the necessary package to your current environment"

@ablaom
Copy link
Member

ablaom commented Nov 30, 2020

Maybe for consistency with pkg=... option, we should call this new option install_pkg?? There would only be one pkg to install.

@juliohm
Copy link

juliohm commented Nov 30, 2020 via email

@ablaom
Copy link
Member

ablaom commented Nov 30, 2020

@juliohm Not sure I understand the suggestion here. I'm certainly not keen on interactive behaviour by default, if that is what you are suggesting. We could instead have the flag interactive=true, but that would add one more step (the user needing to answer the question "Do you want to install...?"), no?

@juliohm
Copy link

juliohm commented Nov 30, 2020

I was thinking about something along the lines of FileIO in the beginning of its development. Whenever someone tried to load a format with load("file.myformat") the package would figure out if the specific package was installed and would suggest to install it otherwise with a yes/no prompt. The user would just press ENTER and keep going with the original task.

Right now the user has to interrupt his/her flow of thought, jump in the package manager, and then later come back to what he/she was originally doing. Maybe a prompt=true option set by default could help instead of interactive.

@ablaom
Copy link
Member

ablaom commented Nov 30, 2020

So to flush out @juliohm 's proposal, we have a single new flag prompt=true (default) with this behaviour: If prompt=true then:

  • Ask use whether to install package if not already installed. The name of the environment should probably be mentioned in the prompt
  • Ask user which package to use if the same model name is duplicated in the registry
  • If either of these two scenarios occur, issue a notice that user can set prompt=false to overide interactive behaviour (unless verbosity <1, in which case no notice is given)

If prompt=false then keep current "throw informative error" behaviour.

@juliohm Is this close enough to what you have in mind?

This would be more convenient and beginner-friendly than the status quo. Here are the down-sides as I see them:

  • Interactive behaviour by default (might cause issues when used programatically, eg in a package module)
  • Mixes package management with package loading. Some might argue package management should be stay user's responsibility (dangers of "secret knowledge", etc).

This small bit of the interface has been a frequent discussion point and changes. Be great to get more feedback before proceeding.

@ExpandingMan @DilumAluthge @tlienart @CameronBieganek Your thoughts?

@DilumAluthge
Copy link
Member Author

  • Interactive behaviour by default (might cause issues when used programatically, eg in a package module)

This is a deal-breaker for me.

If we put interactive behavior into the @load macro, it should not be by default. E.g. if we have a kwarg interactive, the default value should be interactive=false.

If we really really need interactive behavior by default, that should go into a separate macro @load_interactive, where the name of this new macro makes it very clear that the behavior will be interactive. So then we can put all of this interactive functionality into the new @load_interactive macro, and we keep @load noninteractive.

@ExpandingMan
Copy link

I agree that it would be nice to have some kind of convenience feature for actually installing the packages, especially since the current ecosystem consists of a large number of disparate interface packages. Expecting users to manage these entirely on their own seems excessive, regardless of whether users are "beginners".

That said, I'm not yet sure what I think would be the best approach here. My first thought would be to have a completely separate macro for package installation. I also agree with your concern about the behavior being interactive "by default" (although the default would be prompt=false right?). On one hand, it might be ok because once you've installed a package, it'll appear in the manifest, which means that its installation would be (or could be) fully automated in the future. On the other, I'm concerned that this getting stuck in code without people being abundantly aware that it is potentially interactive (which they surely won't be) unfortunate shenanigans would follow.

So, at first glance, having a keyword argument maybe install which is false by default, which causes it to do Pkg.add if it's not already in the environment seems like a nice feature. I would suggest you think about it a while before implementing though. If I have more thoughts about it in the future, I'll post here.

@DilumAluthge DilumAluthge changed the title Add the optional install_packages keyword argument to the @load macro Add the optional install_pkgs keyword argument to the @load macro Dec 1, 2020
@codecov-io
Copy link

codecov-io commented Dec 1, 2020

Codecov Report

Merging #346 (cd37ff8) into dev (82e8297) will increase coverage by 0.35%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #346      +/-   ##
==========================================
+ Coverage   79.36%   79.72%   +0.35%     
==========================================
  Files          11       11              
  Lines         848      858      +10     
==========================================
+ Hits          673      684      +11     
+ Misses        175      174       -1     
Impacted Files Coverage Δ
src/loading.jl 88.65% <100.00%> (+2.45%) ⬆️

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 82e8297...cd37ff8. Read the comment docs.

@CameronBieganek
Copy link

CameronBieganek commented Dec 1, 2020

Now that #340 has been merged, maybe the way to go is to make @load default to interactive (prompt=true or interactive=true). The MLJ user manual can recommend that beginners use @load and that developers and more experienced users load models directly by importing from wherever load_path(model) says to import from.

@ablaom
Copy link
Member

ablaom commented Dec 1, 2020

Thanks for that feedback all. As @ExpandingMan suggests, let's sleep on it.

Copy link
Member

@ablaom ablaom left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@ablaom
Copy link
Member

ablaom commented Dec 13, 2020

Thanks all for the feedback. Although there is no consensus, the best compromise would in my view be:

  • merge the current PR as is; and

  • in a second PR, add a new method @load_interactive (or @iload??) for interactive loading

@DilumAluthge Are you happy for me to merge?

@DilumAluthge
Copy link
Member Author

Thanks all for the feedback. Although there is no consensus, the best compromise would in my view be:

* merge the current PR as is; and

* in a second PR, add a new method `@load_interactive` (or `@iload`??) for interactive loading

@DilumAluthge Are you happy for me to merge?

Sounds good to me!

@ablaom ablaom merged commit 6c40ec9 into JuliaAI:dev Dec 14, 2020
This was referenced Dec 14, 2020
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.

6 participants