Skip to content

docs: add custom ensemble example and fix Sphinx warnings - #1360

Open
joshb-code wants to merge 4 commits into
sunlabuiuc:masterfrom
joshb-code:docs/ensemble-snippet-and-sphinx-fixes
Open

joshb-code wants to merge 4 commits into
sunlabuiuc:masterfrom
joshb-code:docs/ensemble-snippet-and-sphinx-fixes

Conversation

@joshb-code

Copy link
Copy Markdown
Contributor

Contributor: Joshua Sebastian (joshb-code)

Contribution Type: Documentation

Description: Follow-up to #1341 (addresses the remaining review suggestion) and #324:

  • Adds a "Writing a custom strategy" section to the ensemble API page showing how to subclass BaseInterpreterEnsemble and implement _ensemble (autodoc hides private methods, so the signature and tensor shapes were not visible). I ran the example with three RandomBaseline experts; it returns the expected shapes.
  • Fixes two Sphinx errors from the docs build: |B| in the ComprehensivenessMetric and SufficiencyMetric docstrings was parsed as an undefined substitution reference; it is now escaped.
  • Lengthens the "Interpretability" heading underline in docs/api/interpret.rst (Sphinx "Title underline too short" warning).

I rebuilt the docs locally; these three warnings/errors no longer appear. Docstring changes are formula-line only (2 lines).

Files to Review:

  • docs/api/interpret/pyhealth.interpret.methods.ensemble.rst - new example section
  • docs/api/interpret.rst - heading underline
  • pyhealth/metrics/interpretability/comprehensiveness.py - escape |B|
  • pyhealth/metrics/interpretability/sufficiency.py - escape |B|

🤖 Generated with Claude Code

- Show how to subclass BaseInterpreterEnsemble and implement _ensemble on
  the ensemble page, since autodoc hides private methods.
- Escape |B| in the Comprehensiveness/Sufficiency docstrings, which Sphinx
  parsed as an undefined substitution reference.
- Lengthen the "Interpretability" heading underline in interpret.rst.

Follow-up to sunlabuiuc#1341; addresses sunlabuiuc#324

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Logiquo Logiquo added the status: automatic The PR will go through automatic review process. label Nov 1, 2026
@Logiquo

Logiquo commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/review

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 74.97% (21247 / 28339 lines)

Modified file Coverage Lines
pyhealth/metrics/interpretability/comprehensiveness.py 100.00% 6 / 6
pyhealth/metrics/interpretability/sufficiency.py 100.00% 7 / 7
pyhealth/models/__init__.py 100.00% 53 / 53
pyhealth/models/sequence_embedding.py 100.00% 148 / 148

Workflow run · 6adc3cd

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Previous review

Reviewed commit 757738f

github-actions[bot]
github-actions Bot previously approved these changes Nov 1, 2026

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Previous review

AI Review

suggestion: approve
decision: approve

Thank you for this contribution, Joshua. The new "Writing a custom strategy" section makes the _ensemble signature and tensor shapes visible, which autodoc hides. The Sphinx warning fixes are also useful.

The change looks ready to merge.

  • The example matches the base class contract: _ensemble takes (B, I, M) and returns (B, M).
  • Escaping |B| as \\|B\\| in the non-raw docstrings gives \|B\| in RST, which fixes the substitution-reference error. The existing \\ in the same docstrings confirms they are non-raw.
  • The heading underline now matches the title length.
  • Coverage: the two modified metric files are at 100%, and the repository total is 74.72%. Both are above the bar (80% per file, 60% overall). No new behavior is added, so no new tests are needed.

Optional suggestions:

  • The snippet uses model and batch without defining them. A one-line comment saying where they come from would help readers.
  • You said you ran the example with RandomBaseline experts, but the snippet uses IntegratedGradients, DeepLift and LimeExplainer. Consider making the two match, or noting that any experts work.

Reviewed commit 757738f

Address review feedback on sunlabuiuc#1360: state what `model` and `batch` are in the
custom ensemble example.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Logiquo

Logiquo commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed commit 8d428a6

github-actions[bot]
github-actions Bot previously approved these changes Nov 1, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI Review

suggestion: approve
decision: approve

Thank you for this contribution. The new "Writing a custom strategy" section makes the _ensemble signature and tensor shapes visible, which autodoc hides. The docs-warning fixes are also welcome. The change looks ready to merge.

Coverage: the whole repository is at 74.97%, above the 60% bar. The changed files under pyhealth/ are at 100%. Tests aren't expected for a docs-only change like this.

Optional suggestions:

  • In the two docstrings, the source now has \\\\|B\\\\|. In a non-raw string that produces two backslashes in the docstring text. Sphinx may then show a literal backslash in the rendered formula. Using \\|B\\| in the source would give a single backslash that escapes the | and renders as |B|. Please check the rendered HTML to confirm which you get.
  • The example comment says model is "a trained PyHealth model". DeepLift requires a model that implements Interpretable, so a short note about that would help readers.
  • You ran the example with RandomBaseline experts, not the IG, DeepLift and Lime experts it shows. Consider saying so, or checking it once with the real experts.

Reviewed commit 8d428a6

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

status: automatic The PR will go through automatic review process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants