Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move docs from __init__ to right after class defiition #2692

Merged
merged 7 commits into from
Dec 8, 2023

Conversation

adam-narozniak
Copy link
Member

Issue

Some strategies have comprehensive docstrings in __ init__ but also short docstrings just after the class definition. That approach is not consistent with PEP 257 and it leads to documentation doubling.

Description

PEP 257 says that the class Docstrings should be (immediately following the class definition) - the most common option in our docs. The constructor (__init __) Docstrings is optional

Related PRs

#2644 describes the issue from the documentation POV.

Proposal

Move the docs from __ init__ to the right after the class def. This problem concerns Strategies (the rest of the code places the docstrings correctly).

Copy link
Member

@charlesbvll charlesbvll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of my comments are towards the old docstrings, but I feel like it's the right opportunity to make those fixes! Otherwise LGTM!

src/py/flwr/server/strategy/fedavg_android.py Outdated Show resolved Hide resolved
src/py/flwr/server/strategy/fedavgm.py Outdated Show resolved Hide resolved
src/py/flwr/server/strategy/fedtrimmedavg.py Outdated Show resolved Hide resolved
src/py/flwr/server/strategy/fedyogi.py Outdated Show resolved Hide resolved
src/py/flwr/server/strategy/fedyogi.py Outdated Show resolved Hide resolved
src/py/flwr/server/strategy/fedyogi.py Outdated Show resolved Hide resolved
src/py/flwr/server/strategy/krum.py Outdated Show resolved Hide resolved
src/py/flwr/server/strategy/fedavgm.py Outdated Show resolved Hide resolved
src/py/flwr/server/strategy/krum.py Outdated Show resolved Hide resolved
@adam-narozniak
Copy link
Member Author

@charlesbvll Thanks, good points. Let's make it consistent now.

What do you think about removing the "default from the docs"?

Re the links to the papers I think the best would be not to point directly to pdf but the arxiv.org/sth (there they can also see version etc). wdyt?

@charlesbvll
Copy link
Member

@charlesbvll Thanks, good points. Let's make it consistent now.

What do you think about removing the "default from the docs"?

Re the links to the papers I think the best would be not to point directly to pdf but the arxiv.org/sth (there they can also see version etc). wdyt?

@adam-narozniak Looking at our docs, it seems like Sphinx does not indicate the default value in all cases, which means that removing it from the docstring might remove some useful information from the docs. If we find a way to make it work consistently without using the docstring, I agree that it would be ideal. It's would be in another PR anyways.

For the links, they're all pointing to the abstract instead of the pdf (except the one I pointed out), so it should be good!

@adam-narozniak
Copy link
Member Author

Ok, so I'm gonna fix the defaults in the docs, but then I think it'd be good to get rid of them. Sphinx shows the defaults in the parameters (in the function/class signature). What's the example that does not have that?

adam-narozniak and others added 3 commits December 7, 2023 14:01
Co-authored-by: Charles Beauville <charles@flower.dev>
@adam-narozniak adam-narozniak self-assigned this Dec 7, 2023
charlesbvll
charlesbvll previously approved these changes Dec 7, 2023
@charlesbvll
Copy link
Member

Ok, so I'm gonna fix the defaults in the docs, but then I think it'd be good to get rid of them. Sphinx shows the defaults in the parameters (in the function/class signature). What's the example that does not have that?

It might be an issue with classes, here for instance the default for seed and shuffle are not shown (I took an example out of FDS because the goal is to migrate to the same tool). You can also see it on FedAvg or other strategies.

@adam-narozniak
Copy link
Member Author

adam-narozniak commented Dec 7, 2023

Got it. I think that it's not an issue if that's not present in the "parameter doc" (for the lack of a better term).
But it will be present in the signature in the case of a function/method and constructor is the case of a class, and it's present in the example you gave. By a constructor I mean

class FederatedDataset(*, dataset: str, subset: str | None = None, resplitter: Callable[[DatasetDict], DatasetDict] | Dict[str, Tuple[str, ...]] | None = None, partitioners: Dict[str, [Partitioner](https://flower.dev/docs/datasets/ref-api/flwr_datasets.partitioner.Partitioner.html#flwr_datasets.partitioner.Partitioner) | int], shuffle: bool = True, seed: int | None = 42)

so e.g. seed = 42
and it'll be the same in case of function/method (I don't think there's any function in public API in FDS; but for method), by signature I mean

load_partition(node_id: int, split: str | None = None)

the split = None is present.

So if we wanted the defaults in the "parameter docs" I would say it would be really worth it if there's some extension to do that. Because the cost of getting it wrong e.g. not changing manually when the change is in the code, outweighs the lack of having it in the parms docs because it's still in the signature/constructor. That's how I see it.

The issue of default values visibility should be alleviated/less prominent when we have constructor/signature docs such that there's one parameter per line or the types are stripped from the constructor/signature. The current formatting makes it hard to read. That's one of the problems I see with the current docs.

@danieljanes danieljanes enabled auto-merge (squash) December 8, 2023 20:03
@danieljanes danieljanes merged commit 1804a6a into main Dec 8, 2023
27 checks passed
@danieljanes danieljanes deleted the fix-init-double-documentation branch December 8, 2023 20:38
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.

3 participants