Skip to content

docs: clarify sampling raises#1214

Open
skyswordw wants to merge 2 commits into
generative-computing:mainfrom
skyswordw:docs-sampling-raises
Open

docs: clarify sampling raises#1214
skyswordw wants to merge 2 commits into
generative-computing:mainfrom
skyswordw:docs-sampling-raises

Conversation

@skyswordw

Copy link
Copy Markdown

Summary

  • clarify the AssertionError entry for BaseSamplingStrategy.sample() so it matches the current select_from_failure and generation-log assertions
  • document the concurrent subsample exception re-raise path when no subsample produces a result

Fixes #1213.

Checks

  • uv run ruff format --check mellea/stdlib/sampling/base.py
  • uv run ruff check mellea/stdlib/sampling/base.py
  • uv run pytest test/stdlib/sampling/test_sampling_base_unit.py -q
  • git diff --check

Assisted-by: Codex
Signed-off-by: skywalker <skywalkerwang98@gmail.com>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jun 5, 2026
@skyswordw skyswordw marked this pull request as ready for review June 6, 2026 02:08
@skyswordw skyswordw requested a review from a team as a code owner June 6, 2026 02:08
@skyswordw

Copy link
Copy Markdown
Author

Marking this ready for review.

Local checks completed before opening the PR:

  • uv run ruff format --check mellea/stdlib/sampling/base.py
  • uv run ruff check mellea/stdlib/sampling/base.py
  • uv run pytest test/stdlib/sampling/test_sampling_base_unit.py -q (16 passed)
  • git diff --check

GitHub checks visible on the PR are currently green.

@planetf1 planetf1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple of small consistency notes inline — nothing that should hold this up.

@planetf1 planetf1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple of small consistency notes inline — nothing that should hold this up.

Comment thread mellea/stdlib/sampling/base.py Outdated

Raises:
AssertionError: Asserts that all required components (repair, select_from_failure, validate, and generate) are provided before proceeding with the sampling.
AssertionError: If `select_from_failure` returns an index outside

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR — removing that stale assertion text is a good catch.

One small thing on the AssertionError description: "outside the generated samples" doesn't quite say what the assertion checks. The actual check is result_index < len(sample_generations), so "out-of-range index into sample_generations" is more direct. Same for the second part — "has no generation log to mark as final" is a roundabout way of saying "_generate_log is None".

The convention in this file is If \condition`with backtick code references — you can see it in theValueError` entry just below, and in the class docstring at line 131. Suggestion to bring it in line:

Suggested change
AssertionError: If `select_from_failure` returns an index outside
AssertionError: If `select_from_failure` returns an out-of-range index
into `sample_generations`, or if the selected result's
`_generate_log` is `None`.

Comment thread mellea/stdlib/sampling/base.py Outdated
the generated samples, or if the selected result has no
generation log to mark as final.
ValueError: If a `SAMPLING_LOOP_START` hook returns a non-positive `loop_budget`.
Exception: Re-raised from a concurrent subsample if all subsamples

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same convention note here — all the other entries in this block start with If <condition>, but this one starts with "Re-raised from…".

The condition is also slightly imprecise: the exception only fires when no subsample produced a usable result. A subsample can raise and the call still succeeds if any other subsample came through — so "all subsamples fail" undersells the specificity of the trigger:

Suggested change
Exception: Re-raised from a concurrent subsample if all subsamples
Exception: If all subsamples raise without producing a result,
the first non-cancellation exception is re-raised (e.g. a
backend error).

Signed-off-by: skywalker <skywalkerwang98@gmail.com>
@skyswordw skyswordw force-pushed the docs-sampling-raises branch from 02b1b0a to dabdbd4 Compare June 9, 2026 03:58
@skyswordw

Copy link
Copy Markdown
Author

Thanks, updated both docstring entries to match the suggested wording and the local If <condition> convention.

@planetf1 planetf1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the improvement. LGTM

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

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(docs): stale and incomplete Raises: entries in BaseSamplingStrategy.sample()

2 participants