Flux.jl: Transition examples in docs to doctests

Created on 17 Jan 2019  ยท  7Comments  ยท  Source: FluxML/Flux.jl

Doctests in the Julia documentation has IMHO been a great success, it is very often that documentation that would be wrong has to be updated before a PR is merged. Doing the same for Flux would likely be a good idea.

As an example, just trying to run the very first example in the gradient docs gives:

julia> d2f(2) # 6.0 (tracked)
ERROR: Use `gradient(...; nest = true)` for nested derivatives
help wanted

All 7 comments

I would like to work on this issue. :smile:

Please do! I'll happily take a PR to the docs to update them. You'll probably want to look at Documenter.jl, if you haven't already.

Hi when I do, I get a lot of errors are those intentionally kept as such? (Trimmed output present below)

julia> using Flux, Documenter

julia> doctest(Flux)
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
โ”Œ Error: doctest failure in ~/.julia/dev/Flux/src/optimise/train.jl:126-132
โ”‚
โ”‚ ```jldoctest
โ”‚ julia> Flux.@epochs 2 println("hello")
โ”‚ [ Info: Epoch 1
โ”‚ hello
โ”‚ [ Info: Epoch 2
โ”‚ hello
โ”‚ ```
โ”‚
โ”‚ Subexpression:
โ”‚
โ”‚ Flux.@epochs 2 println("hello")
โ”‚
โ”‚ Evaluated output:
โ”‚
โ”‚ ERROR: LoadError: UndefVarError: Flux not defined
โ”‚ in expression starting at none:1
โ”‚
โ”‚ Expected output:
โ”‚
โ”‚ [ Info: Epoch 1
โ”‚ hello
โ”‚ [ Info: Epoch 2
โ”‚ hello
โ”‚
โ”‚   diff =
โ”‚    [ Info: Epoch 1
โ”‚    hello
โ”‚    [ Info: Epoch 2
โ”‚    helloERROR: LoadError: UndefVarError: Flux not defined
โ”‚    in expression starting at none:1
โ”” @ Documenter.DocTests ~/.julia/packages/Documenter/6vUwN/src/DocTests.jl:369
โ”Œ Error: doctest failure in ~/.julia/dev/Flux/src/layers/conv.jl:539-547
โ”‚
โ”‚ ```jldoctest
โ”‚ julia> xs = rand(Float32, 100, 100, 3, 50);  # batch of 50 RGB images
โ”‚
โ”‚ julia> AdaptiveMaxPool((25, 25))(xs) |> size
โ”‚ (25, 25, 3, 50)
โ”‚
โ”‚ julia> MaxPool((4,4))(xs) โ‰ˆ AdaptiveMaxPool((25, 25))(xs)
โ”‚ true
โ”‚ ```
โ”‚
โ”‚ Subexpression:
โ”‚
โ”‚ MaxPool((4,4))(xs) โ‰ˆ AdaptiveMaxPool((25, 25))(xs)
โ”‚
โ”‚ Evaluated output:
โ”‚
โ”Œ Error: Doctesting failed
โ”‚   exception =
โ”‚    `makedocs` encountered a doctest error. Terminating build
โ”‚    Stacktrace:
โ”‚     [1] error(::String) at ./error.jl:33
โ”‚     [2] runner(::Type{Documenter.Builder.Doctest}, ::Documenter.Documents.Document) at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Builder.jl:217
โ”‚     [3] dispatch(::Type{Documenter.Builder.DocumentPipeline}, ::Documenter.Documents.Document) at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Utilities/Selectors.jl:170
โ”‚     [4] #2 at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:247 [inlined]
โ”‚     [5] cd(::Documenter.var"#2#3"{Documenter.Documents.Document}, ::String) at ./file.jl:104
โ”‚     [6] makedocs(; debug::Bool, format::Documenter.Writers.HTMLWriter.HTML, kwargs::Base.Iterators.Pairs{Symbol,Any,NTuple{6,Symbol},NamedTuple{(:root, :source, :sitename, :doctest, :modules, :doctestfilters),Tuple{String,String,String,Symbol,Array{Module,1},Array{Regex,1}}}}) at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:246
โ”‚     [7] (::Documenter.var"#all_doctests#35"{Bool,Array{Regex,1},Array{Module,1}})() at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:811
โ”‚     [8] macro expansion at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:828 [inlined]
โ”‚     [9] macro expansion at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Test/src/Test.jl:1115 [inlined]
โ”‚     [10] doctest(::String, ::Array{Module,1}; fix::Bool, testset::String, doctestfilters::Array{Regex,1}) at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:828
โ”‚     [11] doctest(::Module; manual::Bool, testset::Nothing, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:767
โ”‚     [12] doctest(::Module) at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:754
โ”‚     [13] top-level scope at REPL[2]:1
โ”‚     [14] eval(::Module, ::Any) at ./boot.jl:331
โ”‚     [15] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:134
โ”‚     [16] repl_backend_loop(::REPL.REPLBackend) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:195
โ”‚     [17] start_repl_backend(::REPL.REPLBackend, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:180
โ”‚     [18] run_repl(::REPL.AbstractREPL, ::Any; backend_on_current_task::Bool) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:292
โ”‚     [19] run_repl(::REPL.AbstractREPL, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:288
โ”‚     [20] (::Base.var"#807#809"{Bool,Bool,Bool,Bool})(::Module) at ./client.jl:399
โ”‚     [21] #invokelatest#1 at ./essentials.jl:710 [inlined]
โ”‚     [22] invokelatest at ./essentials.jl:709 [inlined]
โ”‚     [23] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:383
โ”‚     [24] exec_options(::Base.JLOptions) at ./client.jl:313
โ”‚     [25] _start() at ./client.jl:506
โ”” @ Documenter ~/.julia/packages/Documenter/6vUwN/src/Documenter.jl:821
Doctests: Flux: Test Failed at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:828
  Expression: all_doctests()
Stacktrace:
 [1] macro expansion at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:828 [inlined]
 [2] macro expansion at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Test/src/Test.jl:1115 [inlined]
 [3] doctest(::String, ::Array{Module,1}; fix::Bool, testset::String, doctestfilters::Array{Regex,1}) at /Users/gaurav/.julia/packages/Documenter/6vUwN/src/Documenter.jl:828
Test Summary:  | Fail  Total
Doctests: Flux |    1      1
ERROR: Some tests did not pass: 0 passed, 1 failed, 0 errored, 0 broken.

julia>

Sorry for a really long output, I can pastebin somewhere if you want me to..

Can I request you to compress the output. You might want to check how our ci does doc tests, you need to set the docsmeta to set some preprocessing :)

I tried using by copying the commands from https://github.com/FluxML/Flux.jl/runs/1478546117 , I still seems to be getting the same warnings, even the logs in the link do have those warnings. The ones against the command julia --project=docs docs/make.jl.
Below is my versionInfo:

Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, haswell)
Environment:
  JULIA_PROJECT = @.

the output I'm getting includes warnings like:

โ”Œ Warning: unable to get the binding for '[`Flux.binarycrossentropy`](@ref)' in src/models/losses.md from expression ':(Flux.binarycrossentropy)' in module Flux.Losses
โ”‚   exception = UndefVarError: Flux not defined

Also, I'm not really sure if running the doctests this way would run the docstrings present in FluxML/src/layers/basic.jl, does it do that?

As I can see the makedocs here, doesn't have path to src/layers/basic.jl, or am I missing something?

Hi @DhairyaLGandhi , please if have any input on the above let me know..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sheemon7 picture Sheemon7  ยท  3Comments

MikeInnes picture MikeInnes  ยท  3Comments

ssfrr picture ssfrr  ยท  5Comments

MikeInnes picture MikeInnes  ยท  4Comments

mkborregaard picture mkborregaard  ยท  5Comments