Skip to content

Commit

Permalink
configure docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorStoneAstro committed Oct 21, 2024
1 parent 571b6d6 commit a97712b
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 68 deletions.
5 changes: 3 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version: 2

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
configuration: docs/source/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
Expand All @@ -29,14 +29,15 @@ build:
jobs:
pre_build:
# Generate the Sphinx configuration for this Jupyter Book so it builds.
- "jupyter-book config sphinx docs/"
- "jupyter-book config sphinx docs/source/"
# Create font cache ahead of jupyter book
- 'python -c "import matplotlib.pyplot as plt"'
# Get the API documentation dynamically
- "sphinx-apidoc -f -o docs/source/ src/caskade/"

python:
install:
- requirements: docs/requirements.txt # Path to your requirements.txt file
- requirements: requirements.txt # Path to your requirements.txt file
- method: pip
path: . # Install the package itself
19 changes: 19 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
5 changes: 5 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ipywidgets
jupyter-book
matplotlib
sphinx
sphinx_rtd_theme
2 changes: 1 addition & 1 deletion docs/_config.yml → docs/source/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ latex:
# Information about where the book exists on the web
repository:
url: https://github.com/ConnorStoneAstro/caskade # Online location of your book
path_to_book: docs # Optional path to your book, relative to the repository root
path_to_book: docs/source # Optional path to your book, relative to the repository root
branch: main # Which branch of the repository should be used when creating links (optional)

# Add GitHub buttons to your book
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 0 additions & 56 deletions src/caskade/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,59 +51,3 @@ def wrapped(self, *args, **kwargs):
return method(self, *args, **kwargs)

return wrapped


def apply_all_descendants(with_type=None):
"""
Decorator to apply a method to all descendants of the current node.
Parameters
----------
method: (Callable)
The method to be decorated.
Returns
-------
Callable
The decorated method.
"""

def _apply_all_descendants(method):
@functools.wraps(method)
def wrapped(self, *args, **kwargs):
method(self, *args, **kwargs)
for node in self.descendants(with_type):
if hasattr(node, method.__name__):
getattr(node, method.__name__)(*args, **kwargs)

return wrapped

return _apply_all_descendants


def apply_all_ancestors(with_type=None):
"""
Decorator to apply a method to all ancestors of the current node.
Parameters
----------
method: (Callable)
The method to be decorated.
Returns
-------
Callable
The decorated method.
"""

def _apply_all_ancestors(method):
@functools.wraps(method)
def wrapped(self, *args, **kwargs):
method(self, *args, **kwargs)
for node in self.ancestors(with_type):
if hasattr(node, method.__name__):
getattr(node, method.__name__)(*args, **kwargs)

return wrapped

return _apply_all_ancestors
2 changes: 1 addition & 1 deletion src/caskade/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def fill_params(self, params: Union[Tensor, Sequence, Mapping]):
f"Error filling params: {e}. Filling params with a list-by-children, rather than one element per dynamic parameter is tricky, consider using alternate format."
)
else:
raise ValueError(
raise AssertionError(
f"Input params length ({len(params)}) does not match dynamic params length ({len(self.dynamic_params)})"
)
elif isinstance(params, Mapping):
Expand Down
25 changes: 17 additions & 8 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,31 @@ def test_topological_ordering():
ordering = node1.topological_ordering()
assert ordering == (node1, node3, node6)

node1.unlink("subnode2")
node1.unlink(node3)
ordering = node1.topological_ordering()
assert ordering == (node1,)


def test_active():
@pytest.mark.parametrize("linkbyname": [True, False], "graphviz_order": [True, False])
def test_active(linkbyname, graphviz_order):
node1 = Node("node1")
node2 = Node("node2")
node3 = Node("node3")
node4 = Node("node4")
node5 = Node("node5")
node6 = Node("node6")

node1.link("subnode1", node2)
node1.link("subnode2", node3)
node2.link("subnode3", node4)
node2.link("subnode4", node5)
node3.link("subnode5", node6)
if linkbyname:
node1.link("subnode1", node2)
node1.link("subnode2", node3)
node2.link("subnode3", node4)
node2.link("subnode4", node5)
node3.link("subnode5", node6)
else:
node1.link(node2)
node1.link(node3)
node2.link(node4)
node2.link(node5)
node3.link(node6)

node1.active = True
assert node1.active == True
Expand All @@ -125,6 +132,8 @@ def test_active():
assert node5.active == False
assert node6.active == False

graph = node1.graphviz(graphviz_order)
assert graph is not None, "should return a graphviz object"

def test_test():
test()
4 changes: 4 additions & 0 deletions tests/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def __call__(self, d=None, e=None, live_c=None):
assert result.shape == (2, 2)
result = main1.testfun(1.0, params)
assert result.shape == (2, 2)
# Wrong number of params, too many
params = params + params + params
with pytest.raises(AssertionError):
result = main1.testfun(1.0, params=params)

# Tensor as params
params = torch.cat(tuple(p.flatten() for p in params))
Expand Down

0 comments on commit a97712b

Please sign in to comment.