[doctest] Provide definition of `default_evaluator` and other default objects
See original GitHub issue📚 Documentation
It was already discussed and also pointed out in the forum that it is unclear how default objects are defined inside doctest examples. For example: https://pytorch.org/ignite/generated/ignite.metrics.Accuracy.html#ignite.metrics.Accuracy
metric = Accuracy()
metric.attach(default_evaluator, "accuracy")
y_true = torch.Tensor([1, 0, 1, 1, 0, 1])
y_pred = torch.Tensor([1, 0, 1, 0, 1, 1])
state = default_evaluator.run([[y_pred, y_true]])
print(state.metrics["accuracy"])
We can think of different solutions:
-
- for all doctests, add a link on https://github.com/pytorch/ignite/blob/111fc7a0c57bb4d96d94f300f8c2f188f7bda148/docs/source/conf.py#L334-L378
-
- visible code is as above but if code is copied we add automatically all defaults (not good as a solution)
-
- other ideas ?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (8 by maintainers)
Top Results From Across the Web
doctest — Test interactive Python examples — Python 3.11.1 ...
Test examples associated with object f; for example, f may be a string, a module, a function, or a class object. A shallow...
Read more >Python's doctest: Document and Test Your Code at Once
In this tutorial, you'll learn how to add usage examples to your code's documentation and docstrings and how to use these examples to...
Read more >How To Write Doctests in Python - DigitalOcean
Python's standard library comes equipped with a test framework module called doctest. The doctest module programmatically searches Python ...
Read more >doctest — Testing Through Documentation — PyMOTW 3
It works by parsing the help text to find examples, running them, then comparing the output text against the expected value.
Read more >doctest/assertions.md at master - GitHub
doctest is different (but it's like Catch in this regard). ... A doctest::Context object still has to be created somewhere and set as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @vfdev-5 @sdesrozis, I was trying a few options to resolve this problem
I ended up with this using the
sphinx_togglebutton
extensionhttps://user-images.githubusercontent.com/72960463/153129453-84a1aeba-f0b8-4396-8059-e809cf9c181f.mp4
Currently, I am using code docstring below:
But as mentioned,
I tried the below, but was not able to get it to work:
@DevPranjal I just tried to use
.. include::
directive here and looks like it works:Can you try this in your fork to see if everything could work with toggle ?
Docs for include directive: https://docutils.sourceforge.io/docs/ref/rst/directives.html#include
EDIT: I think we have to manually copy
defaults.rst
tosource/generated
in order to be discovered from the docstring. I updated my fork. You can borrow the code from it and send a PR.