Skip to content

fix(vectors): clear error for an out-of-range layer in normalize_alpha / dose#21

Merged
bamdadd merged 2 commits into
bamdadd:mainfrom
dchaudhari7177:fix/layer-range-error
Jul 20, 2026
Merged

fix(vectors): clear error for an out-of-range layer in normalize_alpha / dose#21
bamdadd merged 2 commits into
bamdadd:mainfrom
dchaudhari7177:fix/layer-range-error

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

Problem

Requesting a layer that is not in the vector raised a bare KeyError: 999, which doesn't tell the user which layers exist.

Fix

Guard at the top of normalize_alpha (which dose() also goes through):

ValueError: layer 999 not in steering vector; available layers: [3, 7]

Tests

  • normalize_alpha(vec, layer=999, ...) and dose(vec, layer=999, ...) both raise the new ValueError naming the layer and listing available layers (2-layer vector)
  • valid-layer behaviour pinned unchanged (norm-5 vector, alpha 2 → by_vector_norm 10)

python -m pytest tests/test_vectors.py passes.

Fixes #20

…_alpha

A layer missing from the steering vector raised a bare KeyError with no
hint of which layers exist. Guard in normalize_alpha (dose() reaches it
through the same path) and name both the bad layer and the available ones.

Fixes bamdadd#20
@bamdadd

bamdadd commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Thanks for this — the change itself is good. The out-of-range layer now raises a clear, typed ValueError that names the bad layer and lists the available ones, dose is covered through normalize_alpha, and the tests pin both. That's exactly what #20 asked for.

The only thing standing between this and a merge is formatting: CI's ruff format --check wants two files reformatted (src/steerbench/vectors.py and tests/test_vectors.py). Nothing wrong with the logic, it's just whitespace/wrapping the formatter is opinionated about. One step should turn CI green:

uv run ruff format .
git commit -am "style: ruff format"
git push

Push that and the checks should go green; I'll merge as soon as they do. Ping me if anything's unclear.

If steerbench is useful to you, a star helps others find it and Watch will keep you posted — glad to have you contributing.

@bamdadd
bamdadd merged commit 3b1ab2c into bamdadd:main Jul 20, 2026
1 check passed
@bamdadd

bamdadd commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Applied the one formatting step for you (ruff format on the two files) so you weren't blocked waiting on it — nothing else was needed. Your fix is solid: the out-of-range layer now raises a clear ValueError that names the bad layer and lists the available ones, dose is covered through normalize_alpha, and the tests pin both paths. Merged, and it closes #20.

Two clean contributions in a row now — really glad to have you here. If steerbench is useful to you, a star helps others find it and Watch keeps you posted on new issues; would love more contributions whenever you're up for it.

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.

Clear error for an out-of-range layer in normalize_alpha / dose

3 participants