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

Examples in the docs: base PR for cleaning up notebook workflow #303

Merged
merged 70 commits into from
Jun 30, 2021

Conversation

st--
Copy link
Member

@st-- st-- commented Jun 16, 2021

Following #314, this PR adds READMEs for how to build & add to the docs and examples, as well as tidying the workflow up a bit more. It makes all current examples run (with a warning to say they're under construction). This PR is NOT intended to clean up the notebooks themselves - that'll come in later PRs.

docs/make.jl Outdated
Comment on lines 13 to 17
const BLACKLIST = [
"deepkernellearning",
"kernelridgeregression",
"svm",
]
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
const BLACKLIST = [
"deepkernellearning",
"kernelridgeregression",
"svm",
]
const BLACKLIST = ["deepkernellearning", "kernelridgeregression", "svm"]

Copy link
Member Author

Choose a reason for hiding this comment

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

This is really nice, but showing how I could batch-format the code before committing/pushing would be even nicer. :) @devmotion
(one of the things I would like to cover in #251)

Copy link
Member

Choose a reason for hiding this comment

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

in case you need it:

using JuliaFormatter # you should add it to your global env
format(".")

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it's in the Makefile in #251:)

st-- and others added 4 commits June 16, 2021 17:59
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@@ -0,0 +1,35 @@
# How to build the docs locally
Copy link
Member Author

Choose a reason for hiding this comment

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

Happy to get improvements to the workflow. :)

docs/README.md Outdated Show resolved Hide resolved
@@ -1,6 +1,12 @@
[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be cleaner and probably easier to maintain (less conflicting dependencies etc) if docs/Project.toml only contains the dependencies for the actual documentation and each example uses a separate project environment with its own pinned dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree - I was wondering how you would make that work but the Pkg.activate() context manager is really neat, so I'll try to add that :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Mhm, that would mean having to run the Pkg.develop in every single example subdirectory if you want to work on them though, and would that not make it harder to check the examples run consistently with any future changes to KernelFunctions (in a PR)?

Copy link
Member

Choose a reason for hiding this comment

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

Mhm, that would mean having to run the Pkg.develop in every single example subdirectory if you want to work on them

Yes, the main point is to have independent environments. In this way you can avoid that dependencies of different examples are conflicting and it is clear which packages and which versions were used to run the individual examples.

They are re-run every time the documentation is built so one would just check that the build passes and the webpage looks fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, for the examples to actually pull in the in-development version of the package I think your make.jl would need to also include a Pkg.develop(path=joinpath(@__DIR__, "..")), but with that I think it should work:)

I think it'd still be good to provide a Makefile or some other way of making it easy for contributors to locally run tests, formatter, etc..

docs/README.md Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
docs/README.md Outdated Show resolved Hide resolved
st-- and others added 2 commits June 17, 2021 14:59
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
docs/make.jl Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
@devmotion
Copy link
Member

Currently the rest of the build takes ~40 minutes anyways so that shouldn't make it longer overall.

IMO this is a motivation for splitting the tests into different groups that are run in parallel (similar what we do in the SciML ecosystem: https://github.com/SciML/OrdinaryDiffEq.jl/blob/master/test/runtests.jl) rather than running the examples in serial.

@st--

This comment has been minimized.

Co-authored-by: David Widmann <[email protected]>
@devmotion

This comment has been minimized.

docs/literate.jl Outdated Show resolved Hide resolved
#md # notebook can be viewed in [nbviewer](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb).
#nb # HTML output can be viewed [here](https://juliagaussianprocesses.github.io/KernelFunctions.jl/dev/examples/@__NAME__/).
#md # The corresponding notebook can be viewed in [nbviewer](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb).*
#nb # The rendered HTML can be viewed [in the docs](https://juliagaussianprocesses.github.io/KernelFunctions.jl/dev/examples/@__NAME__/).*
Copy link
Member Author

Choose a reason for hiding this comment

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

How difficult would it be to change the dev to whichever build it actually is?

Copy link
Member

Choose a reason for hiding this comment

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

Not difficult but a bit annoying it seems. Literate automatically derives the url for the repo and nbviewer when running it with Github actions which are used to replace @__NBVIEWER_ROOT_URL__ and @__REPO_ROOT_URL__ after the custom user-defined replacements. However, we can't use these urls or subparts of them in our preprocessing and there are no similar "magic" variables for the github.io webpage (which seems reasonable somehow since one can use e.g. custom domains and hence it is not clear what the correct url for the webpage should be). So I think one has to copy the logic in https://github.com/fredrikekre/Literate.jl/blob/8d8caac6e651eb02ded5699835384d0f0b139e78/src/Literate.jl#L248-L258 to derive the deploy_folder and use it instead of dev. Maybe one could ask if Literate could add an automatic replacement for @__DEPLOY_FOLDER__, similar to @__REPO_ROOT_URL__.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for looking into this. Would you be willing to write it up as an issue in the Literate.jl repo ?

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Awesome, thank you @fredrikekre !

@st--

This comment has been minimized.

@devmotion

This comment has been minimized.

docs/Project.toml Show resolved Hide resolved
docs/README.md Outdated Show resolved Hide resolved
Comment on lines -42 to -44
using LinearAlgebra
using Random
using PDMats: PDMats
Copy link
Member

Choose a reason for hiding this comment

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

Are these not needed anymore for the doctests?

Copy link
Member Author

Choose a reason for hiding this comment

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

clearly not :)

examples/README.md Outdated Show resolved Hide resolved
examples/README.md Show resolved Hide resolved
Comment on lines +56 to +68
plots = []
for i in 1:10
grads = Zygote.gradient(() -> loss(k, λ), ps)
Flux.Optimise.update!(opt, ps, grads)
p = Plots.scatter(x, y; lab="data", title="Loss = $(loss(k,λ))")
Plots.plot!(x, f(X, k, λ); lab="Prediction", lw=3.0)
display(p)
push!(plots, p)
end

#

l = @layout grid(10, 1)
plot(plots...; layout=l, size=(300, 1500))
Copy link
Member

Choose a reason for hiding this comment

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

Probably better to generate a gif but IMO it's OK to leave this for a future PR.

examples/kernel-ridge-regression/script.jl Show resolved Hide resolved
examples/kernel-ridge-regression/script.jl Show resolved Hide resolved
examples/kernel-ridge-regression/script.jl Show resolved Hide resolved
Comment on lines +54 to 61
plots = []
for i in 1:10
grads = Zygote.gradient(() -> loss(k, λ), ps)
Flux.Optimise.update!(opt, ps, grads)
p = Plots.scatter(x, y; lab="data", title="Loss = $(loss(k,λ))")
Plots.plot!(x_test, f(X_test, k, λ); lab="Prediction", lw=3.0)
display(p)
push!(plots, p)
end
Copy link
Member

Choose a reason for hiding this comment

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

Again might want to change this to an animation later on.

examples/README.md Outdated Show resolved Hide resolved
@st-- st-- mentioned this pull request Jun 30, 2021
examples/support-vector-machine/Project.toml Outdated Show resolved Hide resolved
examples/kernel-ridge-regression/Project.toml Outdated Show resolved Hide resolved
examples/deep-kernel-learning/Project.toml Outdated Show resolved Hide resolved
@st-- st-- mentioned this pull request Jun 30, 2021
@st-- st-- changed the title Examples in the docs: base PR for generating notebooks Examples in the docs: base PR for cleaning up notebook workflow Jun 30, 2021
@st-- st-- mentioned this pull request Jun 30, 2021
@st-- st-- merged commit f9ddee8 into master Jun 30, 2021
@st-- st-- deleted the st/examples-base branch June 30, 2021 19:48
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.

5 participants