Skip to content

Commit

Permalink
defaults in the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gerkone committed Feb 26, 2024
1 parent 05162fa commit bfefdfe
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
# to get defaults.py in the documentation
"sphinx_exec_code",
]

numfig = True
Expand All @@ -62,6 +64,11 @@
}


# -- Options for sphinx-exec-code ---------------------------------------------

exec_code_working_dir = ".."


# drop the docstrings of undocumented the namedtuple attributes
def remove_namedtuple_attrib_docstring(app, what, name, obj, skip, options):
if type(obj) is collections._tuplegetter:
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Contents
.. toctree::
:maxdepth: 2

pages/defaults
pages/data
pages/case_setup
pages/models
Expand Down
45 changes: 45 additions & 0 deletions docs/pages/defaults.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Defaults
===================================



.. exec_code::
:hide_code:
:linenos_output:
:language_output: python
:caption: LagrangeBench default values


with open("lagrangebench/defaults.py", "r") as file:
defaults_full = file.read()

# parse defaults: remove imports, only keep the set_defaults function

defaults_full = defaults_full.split("\n")

# remove imports
defaults_full = [line for line in defaults_full if not line.startswith("import")]
defaults_full = [line for line in defaults_full if len(line.replace(" ", "")) > 0]

# remove other functions
keep = False
defaults = []
for i, line in enumerate(defaults_full):
if line.startswith("def"):
if "set_defaults" in line:
keep = True
else:
keep = False

if keep:
defaults.append(line)

# remove function declaration and return
defaults = defaults[2:-2]

# remove indent
defaults = [line[4:] for line in defaults]


print("\n".join(defaults))

1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ott-jax>=0.4.2
pyvista
PyYAML
sphinx==7.2.6
sphinx-exec-code
sphinx-rtd-theme==1.3.0
toml>=0.10.2
torch==2.1.0+cpu
Expand Down
1 change: 0 additions & 1 deletion lagrangebench/train/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def __init__(
input_seq_length: int = defaults.model.input_seq_length,
seed: int = defaults.seed,
):

if isinstance(cfg_train, Dict):
cfg_train = OmegaConf.create(cfg_train)

Check warning on line 131 in lagrangebench/train/trainer.py

View check run for this annotation

Codecov / codecov/patch

lagrangebench/train/trainer.py#L131

Added line #L131 was not covered by tests
if isinstance(cfg_eval, Dict):
Expand Down

0 comments on commit bfefdfe

Please sign in to comment.