Skip to content

docs: add how-to guides for custom algorithms, datasets and optimizers - #60

Closed
wenh06 wants to merge 3 commits into
masterfrom
docs-tutorials-d
Closed

wenh06 wants to merge 3 commits into
masterfrom
docs-tutorials-d

Conversation

@wenh06

@wenh06 wenh06 commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • howto-custom-algorithm: walks through the complete custom algorithm in test-files/custom_alg.py — config classes with validators, the server downlink/aggregation hooks, the client typed uplink contract with its parallel-safety rationale, named parameter exchange, registration, and the two layers (golden regression + hook contract) that protect registered algorithms. The legacy communicate(self, target) style is documented as sequential-only.
  • howto-custom-dataset: the full FedVisionDataset-based example, plus a minimal "NumPy arrays to federated dataset" template that was verified by execution while writing it. The template documents three easy-to-miss conventions discovered on the way: the abstract FedDataset base has no constructor of its own (a custom __init__ accepting (datadir, transform, seed) is required); get_dataloader must handle client_idx=None (the framework requests global loaders); candidate_models should return fl-sim models (they carry the .device attribute device allocation relies on).
  • howto-custom-optimizer: the optimizer registry, ProxSGD subclassing, name-based selection with the trailing-suffix rule, and the caveats (per-client construction, algorithm-fixed optimizers, server-side optimizers being a separate mechanism).
  • test-files/custom_*.py: literalinclude fragment markers added (comments only; test/test_custom.py passes unchanged).
  • index.rst: new How-to guides toctree section; the CLI tutorial's next-steps now link the how-tos instead of promising them.
  • zh_CN translations for the new and updated pages.

Validation

  • pytest test/test_tutorial_scripts.py test/test_custom.py: 8 passed (includes the CI harness that runs the three custom example files via custom_conf.yml).
  • The minimal dataset template from the how-to was executed end to end (registered via FedDataArgs, trained 2 FedAvg iterations) before being embedded.
  • English and zh_CN docs builds: zero warnings beyond the pre-existing optimizers-docstring one on master.

- tutorial-visualization.rst: merge a two-seed experiment into one mean
  curve with error bounds and export it to PDF; the interactive Panel
  dashboard is introduced for notebook use; the shown code is embedded
  via literalinclude from test-files/tutorial_visualization.py
- tutorial-parallel-reproducible.rst: one-line switch to the threads
  executor, then verify bitwise-identical final weights across backends
  with rng_mode per_client, and contrast the statistical-level global
  mode; embedded from test-files/tutorial_parallel_check.py
- tutorial_first_experiment.py: every run now takes a fresh model from
  the candidate-models property; the server trains the model it is
  given in place, so sharing one module across runs would warm-start
  every run after the first
- test/test_tutorial_scripts.py: two new behavioral smoke tests (curve
  merge and PDF export in a temporary working directory; bitwise
  sequential-vs-threads equality with per-client RNG)
- zh_CN translations for the new and updated pages
- howto-custom-algorithm: walk through the complete custom algorithm in
  test-files/custom_alg.py — config classes with validators, the server
  downlink/aggregation hooks, the client typed uplink contract and its
  parallel-safety rationale, named parameter exchange, registration, and
  the two layers (golden regression, hook contract) that protect
  registered algorithms; the legacy hook style is documented as
  sequential-only
- howto-custom-dataset: the full FedVisionDataset-based example plus a
  minimal NumPy-to-federated template, verified by execution; the
  template documents three easy-to-miss conventions (FedDataset has no
  constructor of its own, get_dataloader must handle client_idx=None,
  candidate models should be fl-sim models)
- howto-custom-optimizer: the optimizer registry, ProxSGD subclassing,
  name-based selection and its caveats
- test-files/custom_*.py: add literalinclude fragment markers (comments
  only; test_custom.py still passes)
- index.rst: new How-to guides toctree section; the CLI tutorial's
  next steps now link the how-tos instead of promising them
- zh_CN translations for the new and updated pages
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.79%. Comparing base (b31a5db) to head (99a5193).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   83.63%   83.79%   +0.15%     
==========================================
  Files          55       55              
  Lines        5640     5640              
==========================================
+ Hits         4717     4726       +9     
+ Misses        923      914       -9     

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Align the phrasing with the rest of the documentation: "research lives
in the variations" becomes a plain declarative opening, question
headings become noun phrases ("When do you need this?" -> "When is a
custom algorithm needed?"), and metaphorical wording is replaced ("How
your algorithm is kept honest" -> "Safeguards for registered
algorithms", "two things bundled together" -> "combines two
components", "look intimidating" -> "appear required", "the
lightest of the three how-tos" -> "the shortest of the three
guides"). The zh_CN translations are reworded to match. No technical
content changes.
@wenh06

wenh06 commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #62 (rebased to avoid merge conflicts with the squashed history of #59).

@wenh06 wenh06 closed this Oct 29, 2026
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.

1 participant