Repository: pytorch/ignite

Issue:
[docs] Add doctests for parameter schedulers
### 📚 Documentation

Following #2230 , I listed the parameter schedulers places (suggested by @sdesrozis) where doctests can be added.

- [x] StateParamScheduler (Abstract class, no test needed)
- [x] ConcatScheduler (#2384) 
- [x] CosineAnnealingScheduler (#2384)
- [x] CyclicalScheduler (Abstract class, no test needed)
- [x] LRScheduler (#2389)
- [x] LinearCyclicalScheduler (#2327)
- [x] ParamGroupScheduler (#2389)
- [x] ParamScheduler (Abstract class, no test needed)
- [x] PiecewiseLinear (#2290)
- [x] create_lr_scheduler_with_warmup (#2389)
- [x] LambdaStateScheduler (#2402)
- [x] PiecewiseLinearStateScheduler (#2400)
- [x] ExpStateScheduler (#2391)
- [x] StepStateScheduler (#2394)
- [x] MultiStepStateScheduler (#2399)

This is a great issue for first comers and those who want to learn more about Sphinx. This issue is the community effort.
If you want to contribute, please comment on this issue with the metric you want to add doctest (one by one).

Example on how to add doctest, see #2241 

Thanks!


Discussion:
Hey @ydcjeff! I'd like to contribute to add the doctests, I'm a little unfamiliar with using doctests with Sphinx, I'll study up a bit on that and hopefully send a PR as soon as possible, I'll start with the StateParamScheduler if that's fine?
Hi @theory-in-progress , yes you can start with StateParamScheduler. You can refer to #2241 as an example.
@ydcjeff what have to be done for StateParamScheduler. Docstring does not produce any number: https://pytorch.org/ignite/v0.4.7/generated/ignite.handlers.state_param_scheduler.StateParamScheduler.html#stateparamscheduler
@vfdev-5 There is no doctest in docstring of StateParamScheduler, so it won't show any number.

Resolving patch:
diff --git a/ignite/handlers/state_param_scheduler.py b/ignite/handlers/state_param_scheduler.py
--- a/ignite/handlers/state_param_scheduler.py
+++ b/ignite/handlers/state_param_scheduler.py
@@ -281,21 +281,36 @@ class ExpStateScheduler(StateParamScheduler):
 
     Examples:
 
-        .. code-block:: python
+        .. testsetup::
 
-            ...
-            engine = Engine(train_step)
+            engine = get_default_trainer()
+
+        .. testcode::
 
             param_scheduler = ExpStateScheduler(
-                param_name="param", initial_value=10, gamma=0.99
+                param_name="param", initial_value=1, gamma=0.9, create_new=True
             )
 
+            # parameter is param, initial_value sets param to 1, gamma is set as 0.9
+            # Epoch 1, param changes from 1 to 1*0.9, param = 0.9
+            # Epoch 2, param changes from 0.9 to 0.9*0.9, param = 0.81
+            # Epoch 3, param changes from 0.81 to 0.81*0.9, param = 0.729
+            # Epoch 4, param changes from 0.81 to 0.729*0.9, param = 0.6561
+
             param_scheduler.attach(engine, Events.EPOCH_COMPLETED)
 
-            # basic handler to print scheduled state parameter
-            engine.add_event_handler(Events.EPOCH_COMPLETED, lambda _ : print(engine.state.param))
+            @engine.on(Events.EPOCH_COMPLETED)
+            def print_param():
+                print(engine.state.param)
 
-            engine.run([0] * 8, max_epochs=2)
+            engine.run([0], max_epochs=4)
+
+        .. testoutput::
+
+            0.9
+            0.81
+            0.7290...
+            0.6561
 
     .. versionadded:: 0.5.0
 


Test patch: