autoresearch-quantum/tests/test_scoring.py
saymrwulf e13a3268c2 Add teaching notebooks, widget-based quizzes, bug fixes, and expanded tests
- 8 Jupyter notebooks across 3 learning plans (A: bottom-up, B: spiral, C: parallel tracks)
- Teaching toolkit (src/autoresearch_quantum/teaching/) with ipywidgets-based
  quiz, predict_choice, reflect, and order widgets — visually distinct from code cells
- Fix spectator_z operator: was {1:'Z',2:'Z'} (IZZI, expectation=0), now {1:'Z',3:'Z'}
  (ZIZI, expectation=+1 for ideal T-state, commutes with logical operators)
- Fix u_magic seed: swap phase arguments to match h_p and ry_rz preparations
- Fix double-display bug: widgets rendered twice when function returned the box
- Fix CLI override parser for negative integers and missing '=' validation
- Fix stabilizer detection quiz: ZZZZ detects X errors, not Z errors
- Add ties parameter to order() for questions with interchangeable items
- Expand test suite from 21 to 107 tests
- Update README with notebook instructions and project tree
2026-04-07 17:14:37 +02:00

54 lines
1.8 KiB
Python

"""Tests for scoring module — edge cases and registry."""
from __future__ import annotations
import pytest
from autoresearch_quantum.models import EvaluationMetrics, QualityWeights, ScoreConfig
from autoresearch_quantum.scoring.score import (
SCORE_REGISTRY,
score_metrics,
weighted_acceptance_cost,
)
def test_score_all_zero_weights() -> None:
metrics = EvaluationMetrics(acceptance_rate=0.5, two_qubit_count=10, depth=20)
config = ScoreConfig(cheap_quality=QualityWeights()) # all zero weights
score, quality, cost = weighted_acceptance_cost(metrics, "cheap", config)
assert quality == 0.0
assert score == 0.0
def test_score_with_none_metrics() -> None:
metrics = EvaluationMetrics(acceptance_rate=0.8)
config = ScoreConfig(
cheap_quality=QualityWeights(
ideal_fidelity=1.0,
noisy_fidelity=1.0,
),
)
# ideal and noisy are None -> skipped
score, quality, cost = weighted_acceptance_cost(metrics, "cheap", config)
assert quality == 0.0
def test_score_expensive_tier_uses_expensive_weights() -> None:
metrics = EvaluationMetrics(
logical_magic_witness=0.9,
acceptance_rate=0.8,
)
config = ScoreConfig(
cheap_quality=QualityWeights(logical_witness=0.0), # zero weight
expensive_quality=QualityWeights(logical_witness=1.0), # full weight
)
score_cheap, _, _ = weighted_acceptance_cost(metrics, "cheap", config)
score_exp, _, _ = weighted_acceptance_cost(metrics, "expensive", config)
assert score_cheap == 0.0
assert score_exp > 0.0
def test_unknown_score_function_raises() -> None:
metrics = EvaluationMetrics()
config = ScoreConfig(name="nonexistent_scorer")
with pytest.raises(ValueError, match="Unknown score function"):
score_metrics(metrics, "cheap", config)