diff --git a/docs/source/changes.md b/docs/source/changes.md index 6d560354..e92eaa96 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -12,6 +12,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and `attributes` field on `PNode` and `PProvisionalNode` that will be mandatory on custom nodes in v0.6.0. - {pull}`662` adds the `.pixi` folder to be ignored by default during the collection. +- {pull}`671` enhances the documentation on complex repetitions. Closes {issue}`670`. ## 0.5.2 - 2024-12-19 diff --git a/docs/source/how_to_guides/bp_complex_task_repetitions.md b/docs/source/how_to_guides/bp_complex_task_repetitions.md index 46c0ff3b..6e83a9e4 100644 --- a/docs/source/how_to_guides/bp_complex_task_repetitions.md +++ b/docs/source/how_to_guides/bp_complex_task_repetitions.md @@ -74,6 +74,9 @@ caption: task_example.py As you see, we lost a level of indentation and we moved all the generations of names and paths to the dimensions and multi-dimensional objects. +Using a {class}`~pytask.PythonNode` allows us to hash the model and reexecute the task +if we define other model settings. + ## Adding another level Extending a dimension by another level is usually quickly done. For example, if we have diff --git a/docs_src/how_to_guides/bp_complex_task_repetitions/example_improved.py b/docs_src/how_to_guides/bp_complex_task_repetitions/example_improved.py index fd313479..d41360d2 100644 --- a/docs_src/how_to_guides/bp_complex_task_repetitions/example_improved.py +++ b/docs_src/how_to_guides/bp_complex_task_repetitions/example_improved.py @@ -1,14 +1,18 @@ +from pathlib import Path from typing import Annotated from typing import Any from myproject.config import EXPERIMENTS +from myproject.config import Model from myproject.config import data_catalog +from _pytask.nodes import PythonNode from pytask import task for experiment in EXPERIMENTS: @task(id=experiment.name) def task_fit_model( - path_to_data: experiment.dataset.path, + model: Annotated[Model, PythonNode(hash=True)] = experiment.model, + path_to_data: Path = experiment.dataset.path, ) -> Annotated[Any, data_catalog[experiment.fitted_model_name]]: ... diff --git a/docs_src/how_to_guides/bp_complex_task_repetitions/experiment.py b/docs_src/how_to_guides/bp_complex_task_repetitions/experiment.py deleted file mode 100644 index 002c669e..00000000 --- a/docs_src/how_to_guides/bp_complex_task_repetitions/experiment.py +++ /dev/null @@ -1,37 +0,0 @@ -from pathlib import Path -from typing import NamedTuple - -SRC = Path(__file__).parent -BLD = SRC / "bld" - - -class Dataset(NamedTuple): - name: str - - @property - def path(self) -> Path: - return SRC / f"{self.name}.pkl" - - -class Model(NamedTuple): - name: str - - -DATASETS = [Dataset("a"), Dataset("b"), Dataset("c")] -MODELS = [Model("ols"), Model("logit"), Model("linear_prob")] - - -class Experiment(NamedTuple): - dataset: Dataset - model: Model - - @property - def name(self) -> str: - return f"{self.model.name}-{self.dataset.name}" - - @property - def path(self) -> Path: - return BLD / f"{self.name}.pkl" - - -EXPERIMENTS = [Experiment(dataset, model) for dataset in DATASETS for model in MODELS]