Skip to content

DM-55281: Add lsst-images-admin diagram subcommand for model layouts - #57

Merged
timj merged 13 commits into
mainfrom
tickets/DM-55281
Jun 26, 2026
Merged

DM-55281: Add lsst-images-admin diagram subcommand for model layouts#57
timj merged 13 commits into
mainfrom
tickets/DM-55281

Conversation

@timj

@timj timj commented Jun 24, 2026

Copy link
Copy Markdown
Member

Render the composition layout of lsst.images serialization models as Mermaid, Graphviz dot, or an ASCII tree. The core lives in a reusable lsst.images._diagram module (build_graph / build_instance_graph / graph_from_file / render) with a thin click wrapper.

Type mode walks a model's annotations (resolving PEP 695 aliases and Annotated wrappers); instance mode (--from-file) walks a file's reference tree and reports only what is stored, collapsing unions such as the PSF to the concrete type present. A curated policy collapses serialization-helper leaves by default, adjustable via --collapse/--expand/--expand-leaves, and scalar fields are hidden unless --attributes is given.

Example

$ lsst-images-admin diagram --from-file dp2-new.fits --hide-field data --collapse ButlerInfo --collapse Transform --hide-type TableModel --format dot --collapse Amplifier --collapse DetectorAttributes | dot -Tpng -o visit.png

Gives:

v

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.88337% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.36%. Comparing base (99e444f) to head (06066f7).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
python/lsst/images/diagram.py 97.59% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #57      +/-   ##
==========================================
+ Coverage   77.24%   78.36%   +1.12%     
==========================================
  Files         121      124       +3     
  Lines       14626    15426     +800     
==========================================
+ Hits        11298    12089     +791     
- Misses       3328     3337       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@timj
timj force-pushed the tickets/DM-55281 branch 3 times, most recently from 57782d1 to 5c7eda4 Compare June 25, 2026 18:58
Comment thread pyproject.toml Outdated
"SS05", # pydocstyle is better at finding infinitive verb.
"GL03", # ruff format of docstrings disagrees.
"PR04", # We use type annotations.
"PR01", # Not all parameters need to be documented.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TallJimbo I am thinking that we might want to re-enable this and fix the public methods that do not document parameters. It seems like disabling this can lead to public methods we really care about missing parameter docs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with turning this check back on. I turned it off because I got annoyed writing repetitive docstrings for single-argument functions, but I agree that we want this check in other cases, and the cost of those repetitive docstrings is not high.

timj and others added 7 commits June 25, 2026 15:45
Render the composition layout of lsst.images serialization models as
Mermaid, Graphviz dot, or an ASCII tree. The core lives in a reusable
lsst.images._diagram module (build_graph / build_instance_graph /
graph_from_file / render) with a thin click wrapper.

Type mode walks a model's annotations (resolving PEP 695 aliases and
Annotated wrappers); instance mode (--from-file) walks a file's reference
tree and reports only what is stored, collapsing unions such as the PSF to
the concrete type present. A curated policy collapses serialization-helper
leaves by default, adjustable via --collapse/--expand/--expand-leaves, and
scalar fields are hidden unless --attributes is given.

The --hide-type drops a type from the diagram entirely, removing every edge that points
at it, matching by public or serialization name. Unlike --collapse (which keeps the
type as a leaf), --hide-type removes the node and any reference left with no
remaining targets, in both type and instance modes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
class_for_schema resolves third-party lsst.images.schemas entry points
lazily by name, but --list only unioned the registry with the built-in
providers, so an entry-point-only schema worked when named explicitly yet
never appeared in the listing. Enumerate the entry point group by name
(without importing the providers) so the listing matches what can actually
be diagrammed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Handle optional containers of model types when classifying annotations so
those fields render as references instead of scalar attributes.

Merge observations from repeated instances of the same model class when
building concrete file diagrams, preserving all nested concrete union
members that appear in the file.

Co-authored-by: Codex 5.5 <codex@openai.com>
Reject files containing merge conflict markers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Run the full .pre-commit-config.yaml suite via prek on push to main and
on pull requests, covering hooks not exercised by the ruff-only
formatting workflow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@timj
timj force-pushed the tickets/DM-55281 branch from 5c7eda4 to 1cdcaa8 Compare June 25, 2026 22:45
@timj
timj requested a review from TallJimbo June 25, 2026 23:21
@timj

timj commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

@TallJimbo The new diagramming code was all added by Claude. I attached the work to the Jira ticket for me writing the talk (since I did this for the SPIE talk) -- I did not put the Jira ticket in review because I haven't quite finished the talk yet.

Not sure if you want to really look in detail at the diagrams.py (and especially the test code, which is comprehensive).

Probably best to focus on the public diagramming API and the command line interface.

Additionally I have:

  • Added numpydoc validation into pre-commit.
  • Fixed problems found by numpydoc validation.
  • Added a pre-commit GitHub action.

Main issue with the validation is whether to turn on PR01 (parameters must be documented for public methods) which I had to turn off since there are lots of internal methods that look like public methods but don't document much. I can try to fix those and I think not fixing them will lead to real public APIs potentially having problems.

@TallJimbo TallJimbo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I just skimmed the guts of the implementation.

I am a bit worried that overall we're accumulating a lot of code to maintain, between utilities like this and archive implementations we don't have concrete plans to utilize. But I also can't point to anything specific that I want to drop - this certainly looks useful for documentation! - and I think it's not clear yet whether AI helps enough with maintenance to offset how much it helps with feature-creation. So no action needed on this now, but it's a concern I wanted to share so we can both keep an eye on it.

Comment thread doc/lsst.images/model-diagrams.rst
# Per-backend array-payload pointers seen when diagramming a file.
"JsonRef",
"PointerModel",
"NdfPointerModel",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests that guard against forgetting to update this list when we add a new archive implementation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not something that can be automated. This is a list of the models that we don't want to expand by default. When you add a new model you can't automatically determine whether it is meant to be expanded or not so I think you end up doing a diagram and then getting annoyed that there is a lot of extra detail that you didn't want by default.

timj and others added 6 commits June 26, 2026 10:09
Remove PR01 from the numpydoc_validation ignore list so public methods
are required to document their parameters again, and add the parameter
docstrings that this surfaces across the package.

Parameters are documented without a type, since Sphinx picks up the type
from the annotation (PR04 remains disabled for the same reason).

Click command functions carry a `# numpydoc ignore=PR01` comment instead
of a Parameters section, because click embeds the docstring into its
--help output where a numpydoc Parameters block renders incorrectly; the
option help text lives in the click declarations.

Also fixes two pre-existing docstring issues uncovered by the check: a
wrong-axis summary on SkyFrame.standardize_y and the parameter order in
the CellField class docstring.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@timj
timj merged commit 1bed81f into main Jun 26, 2026
19 checks passed
@timj
timj deleted the tickets/DM-55281 branch June 26, 2026 20:30
@timj

timj commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

250 methods/functions had parameters added...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants