You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix AstroPhot docstrings to explicit RST fields for Sphinx compatibility (#294)
Updates docstrings to RST for Sphinx/Jupyter Book compatibility, merges
docstrings across the MRO, and rebuilds the API docs structure with
autodoc pages and MathJax support.
## Changes Made
- Reworked `combine_docstrings` to merge parameters/options from the
full MRO into a single RST parameter list and add `[model param]` tags
to distinguish model parameters from options.
- Converted model and mixin docstrings from markdown to RST (including
`.. math::` blocks).
- Converted docstrings in the **image**, **fitting**, and **plotting**
sections to explicit RST field-list syntax using `:param:`, `:type:`,
`:returns:`, and `:rtype:` (replacing `Args:` / `Returns:` style
sections).
- Updated docstring terminology from `Tensor`/`tensor` to `Array` where
applicable, to reflect support for both PyTorch and JAX backends.
- Added `description` entries to every `_parameter_specs` parameter.
- Applied `combine_docstrings` to auto-generated classes in `radial.py`
and `radial_psf.py`.
- Removed `make_docs.py` and replaced the docstring notebook tree with
Sphinx autodoc RST pages.
## Documentation
- Added `docs/source/astrophotdocs/*.rst` autodoc pages and updated
`astrophotdocs/index.rst`.
- Enabled MathJax in the Jupyter Book/Sphinx configuration.
## Testing
- Targeted pytest runs for utility and parameter tests.
- Targeted pytest runs for updated sections: `tests/test_image.py`,
`tests/test_fit.py`, and `tests/test_plots.py`.
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Model docstrings need a rewrite</issue_title>
> <issue_description>As part of my latest update I tried to make the
model docstrings use markdown formatting, but this ultimately doesn't
seem to have worked. I would like to revert to a format that sphinx
autodoc can work with (I think this is RST). My main challenge is to get
it to work in a way that also compiles into the jupyter-book website
system with latex equations.
>
> Also, I think the `combine_docstrings` decorator should be smarter
about merging docstrings. It should find all of the "Parameters" and the
"Options" from each collected docstring and merge them into single lists
so that autodoc compiles them correctly.
>
> The combine_docstrings decorator also needs to be applied to all the
auto generated types in the `radial.py` and `radial_psf.py` files.
Further, they should be modified so that sphinx autodoc picks them up
when generating the documentation.
>
> My attempted giant jupyter notebook of docstrings didn't work so that
should be removed and instead the tree of autodoc results should be made
more human navigable.
>
> While doing this, it would be good to also check that all the
docstrings are up to date to match the actual coded implementations. And
the "Parameters" descriptions in the docstrings should be added as a
"description" key in all the `_parameter_specs` dictionaries associated
with each model.</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes#293
<!-- START COPILOT CODING AGENT TIPS -->
---
⌨️ Start Copilot coding agent tasks without leaving your editor —
available in [VS Code](https://gh.io/cca-vs-code-docs), [Visual
Studio](https://gh.io/cca-visual-studio-docs), [JetBrains
IDEs](https://gh.io/cca-jetbrains-docs) and
[Eclipse](https://gh.io/cca-eclipse-docs).
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Co-authored-by: Connor Stone <connorstone628@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- `mass_matrix_shape`: a dict that maps tuples of site names to the shape of
34
+
:param mass_matrix_shape: a dict that maps tuples of site names to the shape of
36
35
the corresponding mass matrix. Each tuple of site names corresponds to a block.
37
-
- `adapt_mass_matrix`: a flag to decide whether an adaptation scheme will be used.
38
-
- `options`: tensor options to construct the initial mass matrix.
36
+
:param adapt_mass_matrix: a flag to decide whether an adaptation scheme will be used.
37
+
:param options: Array options to construct the initial mass matrix.
39
38
"""
40
39
inverse_mass_matrix= {}
41
40
forsite_names, shapeinmass_matrix_shape.items():
@@ -70,16 +69,24 @@ class HMC(BaseOptimizer):
70
69
https://arxiv.org/abs/1701.02434, and
71
70
http://www.mcmchandbook.net/HandbookChapter5.pdf
72
71
73
-
**Args:**
74
-
- `max_iter` (int, optional): The number of sampling steps to perform. Defaults to 1000.
75
-
- `epsilon` (float, optional): The length of the integration step to perform for each leapfrog iteration. The momentum update will be of order epsilon * score. Defaults to 1e-5.
76
-
- `leapfrog_steps` (int, optional): Number of steps to perform with leapfrog integrator per sample of the HMC. Defaults to 10.
77
-
- `inv_mass` (float or array, optional): Inverse Mass matrix (covariance matrix) which can tune the behavior in each dimension to ensure better mixing when sampling. Defaults to the identity.
78
-
- `progress_bar` (bool, optional): Whether to display a progress bar during sampling. Defaults to True.
79
-
- `prior` (distribution, optional): Prior distribution for the parameters. Defaults to None.
80
-
- `warmup` (int, optional): Number of warmup steps before actual sampling begins. Defaults to 100.
81
-
- `hmc_kwargs` (dict, optional): Additional keyword arguments for the HMC sampler. Defaults to {}.
82
-
- `mcmc_kwargs` (dict, optional): Additional keyword arguments for the MCMC process. Defaults to {}.
72
+
:param max_iter: The number of sampling steps to perform. Defaults to 1000.
73
+
:type max_iter: int, optional
74
+
:param epsilon: The length of the integration step to perform for each leapfrog iteration. The momentum update will be of order epsilon * score. Defaults to 1e-5.
75
+
:type epsilon: float, optional
76
+
:param leapfrog_steps: Number of steps to perform with leapfrog integrator per sample of the HMC. Defaults to 10.
77
+
:type leapfrog_steps: int, optional
78
+
:param inv_mass: Inverse Mass matrix (covariance matrix) which can tune the behavior in each dimension to ensure better mixing when sampling. Defaults to the identity.
79
+
:type inv_mass: float or array, optional
80
+
:param progress_bar: Whether to display a progress bar during sampling. Defaults to True.
81
+
:type progress_bar: bool, optional
82
+
:param prior: Prior distribution for the parameters. Defaults to None.
83
+
:type prior: distribution, optional
84
+
:param warmup: Number of warmup steps before actual sampling begins. Defaults to 100.
85
+
:type warmup: int, optional
86
+
:param hmc_kwargs: Additional keyword arguments for the HMC sampler. Defaults to {}.
87
+
:type hmc_kwargs: dict, optional
88
+
:param mcmc_kwargs: Additional keyword arguments for the MCMC process. Defaults to {}.
89
+
:type mcmc_kwargs: dict, optional
83
90
84
91
"""
85
92
@@ -122,8 +129,8 @@ def fit(
122
129
123
130
Records the chain for later examination.
124
131
125
-
**Args:**
126
-
state (torch.Tensor, optional): Model parameters as a 1D tensor.
Copy file name to clipboardExpand all lines: astrophot/fit/scipy_fit.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -19,11 +19,10 @@ class ScipyFit(BaseOptimizer):
19
19
tasks. It supports a variety of methods, however only a subset allow users to
20
20
define boundaries for the parameters. This wrapper is only for those methods.
21
21
22
-
**Args:**
23
-
- `model`: The model to fit, which should be an instance of `Model`.
24
-
- `initial_state`: Initial guess for the model parameters as a 1D tensor.
25
-
- `method`: The optimization method to use. Default is "Nelder-Mead", but can be set to any of: "Nelder-Mead", "L-BFGS-B", "TNC", "SLSQP", "Powell", or "trust-constr".
26
-
- `ndf`: Optional number of degrees of freedom for the fit. If not provided, it is calculated as the number of data points minus the number of parameters.
22
+
:param model: The model to fit, which should be an instance of `Model`.
23
+
:param initial_state: Initial guess for the model parameters as a 1D Array.
24
+
:param method: The optimization method to use. Default is "Nelder-Mead", but can be set to any of: "Nelder-Mead", "L-BFGS-B", "TNC", "SLSQP", "Powell", or "trust-constr".
25
+
:param ndf: Optional number of degrees of freedom for the fit. If not provided, it is calculated as the number of data points minus the number of parameters.
0 commit comments