Skip to content

Commit c962143

Browse files
authored
Fix all docstrings for docs (#97)
1 parent c16afdb commit c962143

30 files changed

+241
-107
lines changed

.github/workflows/checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
run: poetry run pyright
5353
- name: Ruff lint
5454
run: poetry run ruff check . --output-format=github
55+
- name: Docstrings lint
56+
run: poetry run pydoclint .
5557
- name: Ruff format
5658
run: poetry run ruff format . --check
5759
- name: Pytest

.github/workflows/gh-pages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
cache: "poetry"
2828
- name: Install poe
2929
run: pip install poethepoet
30-
- name: Install mkdocs
31-
run: pip install mkdocs
3230
- name: Install dependencies
3331
run: poetry install --with docs
32+
- name: Generate docs
33+
run: poe gen-docs
3434
- name: Build Docs
3535
run: poe make-docs
3636
- name: Upload Docs Artifact

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"typecheck",
8888
"ultralow",
8989
"uncopyrighted",
90+
"ungraphed",
9091
"unsqueeze",
9192
"venv",
9293
"virtualenv",

docs/gen_ref_pages.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def is_source_file(file: Path) -> bool:
2222
"""Check if the provided file is a source file for Sparse Encoder.
2323
2424
Args:
25-
file (Path): The file path to check.
25+
file: The file path to check.
2626
2727
Returns:
2828
bool: True if the file is a source file, False otherwise.
@@ -34,11 +34,10 @@ def process_path(path: Path) -> tuple[Path, Path, Path]:
3434
"""Process the given path for documentation generation.
3535
3636
Args:
37-
path (Path): The file path to process.
37+
path: The file path to process.
3838
3939
Returns:
40-
tuple[Path, Path, Path]: A tuple containing module path, documentation path,
41-
and full documentation path.
40+
A tuple containing module path, documentation path, and full documentation path.
4241
"""
4342
module_path = path.relative_to(PROJECT_ROOT).with_suffix("")
4443
doc_path = path.relative_to(PROJECT_ROOT).with_suffix(".md")
@@ -56,9 +55,9 @@ def generate_documentation(path: Path, module_path: Path, full_doc_path: Path) -
5655
"""Generate documentation for the given source file.
5756
5857
Args:
59-
path (Path): The source file path.
60-
module_path (Path): The module path.
61-
full_doc_path (Path): The full documentation file path.
58+
path: The source file path.
59+
module_path: The module path.
60+
full_doc_path: The full documentation file path.
6261
"""
6362
if module_path.name == "__main__":
6463
return
@@ -77,8 +76,8 @@ def generate_nav_file(nav: mkdocs_gen_files.nav.Nav, reference_dir: Path) -> Non
7776
"""Generate the navigation file for the documentation.
7877
7978
Args:
80-
nav (mkdocs_gen_files.Nav): The navigation object.
81-
reference_dir (Path): The directory to write the navigation file.
79+
nav: The navigation object.
80+
reference_dir: The directory to write the navigation file.
8281
"""
8382
with mkdocs_gen_files.open(reference_dir / "SUMMARY.md", "w") as nav_file:
8483
nav_file.writelines(nav.build_literate_nav())

poetry.lock

Lines changed: 46 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
jupyter=">=1"
2121
plotly=">=5"
2222
poethepoet=">=0.24.2"
23-
pyright=">=1.1.334"
23+
pydoclint="^0.3.8"
24+
pyright=">=1.1.337"
2425
pytest=">=7"
2526
pytest-cov=">=4"
2627
pytest-timeout=">=2.2.0"
@@ -42,14 +43,14 @@
4243
mkdocs-section-index=">=0.3.8"
4344
mkdocstrings={extras=["python"], version=">=0.24.0"}
4445
mkdocstrings-python=">=1.7.3"
46+
mknotebooks="^0.8.0"
4547
pytkdocs-tweaks=">=0.0.7"
46-
mknotebooks = "^0.8.0"
4748

4849
[tool.poe.tasks]
4950
[tool.poe.tasks.check]
5051
help="All checks"
5152
ignore_fail=false
52-
sequence=["check-lock", "format", "lint", "test", "typecheck"]
53+
sequence=["check-lock", "docstring-lint", "format", "lint", "test", "typecheck"]
5354

5455
[tool.poe.tasks.format]
5556
cmd="ruff format ."
@@ -59,6 +60,10 @@
5960
cmd="ruff check . --fix"
6061
help="Lint (with autofix)"
6162

63+
[tool.poe.tasks.docstring-lint]
64+
cmd="pydoclint ."
65+
help="Lint docstrings"
66+
6267
[tool.poe.tasks.ruff]
6368
help=" [alias for lint && format]"
6469
ignore_fail=false
@@ -95,6 +100,7 @@
95100
[tool.poe.tasks.gen-docs]
96101
help="Cleans out the automatically generated docs."
97102
script="docs.gen_ref_pages:run"
103+
98104
[tool.poe.tasks.make-docs]
99105
cmd="mkdocs build"
100106
help="Generates our docs"
@@ -225,3 +231,11 @@
225231
strictListInference=true
226232
strictParameterNoneValue=true
227233
strictSetInference=true
234+
235+
[tool.pydoclint]
236+
allow-init-docstring=true
237+
arg-type-hints-in-docstring=false
238+
check-return-types=false
239+
check-yield-types=false
240+
exclude='\.venv'
241+
style="google"

sparse_autoencoder/activation_resampler/abstract_activation_resampler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@ def resample_dead_neurons(
6868
autoencoder: Sparse autoencoder model.
6969
loss_fn: Loss function.
7070
train_batch_size: Train batch size (also used for resampling).
71+
72+
Returns:
73+
Indices of dead neurons, and the updates for the encoder and decoder weights and biases.
7174
"""
72-
raise NotImplementedError

sparse_autoencoder/activation_resampler/activation_resampler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def compute_loss_and_get_activations(
9696
9797
Returns:
9898
A tuple containing the loss per item, and all input activations.
99+
100+
Raises:
101+
ValueError: If the number of items in the store is less than the number of inputs
99102
"""
100103
with torch.no_grad():
101104
loss_batches: list[TrainBatchStatistic] = []
@@ -274,6 +277,9 @@ def resample_dead_neurons(
274277
autoencoder: Sparse autoencoder model.
275278
loss_fn: Loss function.
276279
train_batch_size: Train batch size (also used for resampling).
280+
281+
Returns:
282+
Indices of dead neurons, and the updates for the encoder and decoder weights and biases.
277283
"""
278284
with torch.no_grad():
279285
dead_neuron_indices = self.get_dead_neuron_indices(neuron_activity)

sparse_autoencoder/activation_store/base_store.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,22 @@ class ActivationStore(Dataset[InputOutputActivationVector], ABC):
5151
@abstractmethod
5252
def append(self, item: InputOutputActivationVector) -> Future | None:
5353
"""Add a Single Item to the Store."""
54-
raise NotImplementedError
5554

5655
@abstractmethod
5756
def extend(self, batch: InputOutputActivationBatch) -> Future | None:
5857
"""Add a Batch to the Store."""
59-
raise NotImplementedError
6058

6159
@abstractmethod
6260
def empty(self) -> None:
6361
"""Empty the Store."""
64-
raise NotImplementedError
6562

6663
@abstractmethod
6764
def __len__(self) -> int:
6865
"""Get the Length of the Store."""
69-
raise NotImplementedError
7066

7167
@abstractmethod
7268
def __getitem__(self, index: int) -> InputOutputActivationVector:
7369
"""Get an Item from the Store."""
74-
raise NotImplementedError
7570

7671
def shuffle(self) -> None:
7772
"""Optional shuffle method."""

sparse_autoencoder/activation_store/disk_store.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,12 @@ def __len__(self) -> int:
251251
"""Length Dunder Method.
252252
253253
Example:
254-
>>> store = DiskActivationStore(max_cache_size=1, empty_dir=True)
255-
>>> print(len(store))
256-
0
254+
>>> store = DiskActivationStore(max_cache_size=1, empty_dir=True)
255+
>>> print(len(store))
256+
0
257+
258+
Returns:
259+
The number of activation vectors in the dataset.
257260
"""
258261
# Calculate the length if not cached
259262
if self._disk_n_activation_vectors.value == -1:

0 commit comments

Comments
 (0)