question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make documentation examples runnable without changes

See original GitHub issue

UPDATE: Updated title based on discussion to make examples runnable without changes as opposed to just including imports.

Many of the self contained examples in the documentation do not include imports, which can make getting started tough for new users. For example, many examples use nn.Module, and a new user may try from flax import nn instead of import flax.linen as nn when trying to run the example on their own. I think all standalone snippets should include all necessary imports, so one can simply paste the example and run.

Here’s an initial list of examples I think could use imports:

I noticed Flax uses doctest to ensure examples in the documentation run, is there any way to mark/enforce that certain examples are self-contained (i.e. have the required imports)?

cc @8bitmp3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
avitalcommented, May 18, 2021

As for from flax import nn - @avital why don’t we currently have a deprecation warning on import?

It’s because we re-export flax.nn in flax/__init__.py so that import flax flax.nn.<...> works. But that seems like a bad answer. We should get rid of that, but honestly it’s probably time to remove flax.nn.

2reactions
andsteingcommented, May 18, 2021

Actually, these examples are run with the Sphinx doctest extension:

https://github.com/google/flax/blob/491ce18759622506588784b4fca0e4bf05f8c8cd/docs/conf.py#L54

Maybe we should transform the testsetup blocks into testcode blocks so the imports are shown in the docs as well?

@n2cholas would you really want every snippet to contain all the imports or would it be enough to have a list of imports at the top of the file? The first might be a bit too verbose and it should be easy enough to copy the imports from the same page when copying the snippet…

As for from flax import nn - @avital why don’t we currently have a deprecation warning on import? Because that indeed seems like a thing a beginner would do, and it might be rather confusing to have to discover that “Linen is the new nn”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Runnable Documentation: Code for Humans
When creating and optimizing Runnable Documentation you should apply code refactoring principles to make it better.
Read more >
GNU make
GNU make. This file documents the GNU make utility, which determines automatically which pieces of a large program need to be recompiled, ...
Read more >
Runnable (Java Platform SE 7 )
For example, Runnable is implemented by class Thread . Being active simply means that a thread has been started and has not yet...
Read more >
Best practices for writing Dockerfiles
Best practices for writing Dockerfiles. This document covers recommended best practices and methods for building efficient images.
Read more >
Choose when to run jobs - GitLab Docs
Get started · Approvals · Approval rules · Approval settings · Changes · Cherry pick changes · Collaborate across forks · Commit message...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found