- ratio-log normalization (scale-invariant) replacing log1p - domain requirements (payload, trip_range) as hard mission constraints - platform payload_ratio, rotorcraft hover floor (min_specific_power) - maintenance_multiple + service_life folded into cost per metre - cruise speed searched between domain speed floor and build top speed - default-deny "domain" requires: Wind Sail / Gravity Coast need the domain to declare prevailing_wind / net_descent - LOGIC DOCS/004: cost per passenger and infrastructure cost, tabled Co-Authored-By: Claude <noreply@anthropic.com>
107 lines
4.6 KiB
Python
107 lines
4.6 KiB
Python
"""Tests for the multi-pass pipeline."""
|
|
|
|
from physcom.engine.constraint_resolver import ConstraintResolver
|
|
from physcom.engine.scorer import Scorer
|
|
from physcom.engine.pipeline import Pipeline
|
|
from physcom.llm.providers.mock import MockLLMProvider
|
|
|
|
|
|
def test_pass1_filters_impossible_combos(seeded_repo):
|
|
"""Pass 1 should block known-impossible combinations (e.g., solar sail + road vehicle)."""
|
|
domain = seeded_repo.get_domain("urban_commuting")
|
|
resolver = ConstraintResolver()
|
|
scorer = Scorer(domain)
|
|
pipeline = Pipeline(seeded_repo, resolver, scorer)
|
|
|
|
result = pipeline.run(domain, ["platform", "actuator", "energy_storage"], passes=[1])
|
|
|
|
from physcom.seed.transport_example import PLATFORMS, ACTUATORS, ENERGY_STORAGES
|
|
expected = len(PLATFORMS) * len(ACTUATORS) * len(ENERGY_STORAGES)
|
|
assert result.total_generated == expected
|
|
assert result.pass1_failed > 0
|
|
assert result.pass1_valid + result.pass1_conditional + result.pass1_failed == expected
|
|
|
|
|
|
def test_pass123_produces_scored_results(seeded_repo):
|
|
"""Passes 1-3 should produce a scored shortlist."""
|
|
domain = seeded_repo.get_domain("urban_commuting")
|
|
resolver = ConstraintResolver()
|
|
scorer = Scorer(domain)
|
|
pipeline = Pipeline(seeded_repo, resolver, scorer)
|
|
|
|
result = pipeline.run(
|
|
domain, ["platform", "actuator", "energy_storage"],
|
|
score_threshold=0.01, passes=[1, 2, 3, 5],
|
|
)
|
|
|
|
assert result.pass2_estimated > 0
|
|
assert result.pass3_above_threshold > 0
|
|
|
|
|
|
def test_pass4_with_mock_llm(seeded_repo):
|
|
"""Pass 4 should annotate with LLM review."""
|
|
domain = seeded_repo.get_domain("urban_commuting")
|
|
resolver = ConstraintResolver()
|
|
scorer = Scorer(domain)
|
|
mock_llm = MockLLMProvider()
|
|
pipeline = Pipeline(seeded_repo, resolver, scorer, llm=mock_llm)
|
|
|
|
result = pipeline.run(
|
|
domain, ["platform", "actuator", "energy_storage"],
|
|
score_threshold=0.01, passes=[1, 2, 3, 4, 5],
|
|
)
|
|
|
|
assert result.pass4_reviewed > 0
|
|
|
|
|
|
def test_blocked_combos_not_scored(seeded_repo):
|
|
"""Blocked combinations should not make it to scoring."""
|
|
domain = seeded_repo.get_domain("urban_commuting")
|
|
resolver = ConstraintResolver()
|
|
scorer = Scorer(domain)
|
|
pipeline = Pipeline(seeded_repo, resolver, scorer)
|
|
|
|
result = pipeline.run(
|
|
domain, ["platform", "actuator", "energy_storage"],
|
|
score_threshold=0.0, passes=[1, 2, 3, 5],
|
|
)
|
|
|
|
# Estimated count should be less than total (blocked ones filtered).
|
|
# Not necessarily equal to pass1_valid + pass1_conditional: a combo can
|
|
# pass pass 1's entity-declared-floor checks but still turn out
|
|
# structurally infeasible once pass 2 solves the domain-specific
|
|
# actuator/storage requirement (e.g. an engine too big to fit its own
|
|
# platform's declared mass ceiling) -- that's a legitimate per-domain
|
|
# block, not a bug (see Pipeline._decide_masses' `feasible` return).
|
|
assert result.pass2_estimated < result.total_generated
|
|
assert result.pass2_estimated <= result.pass1_valid + result.pass1_conditional
|
|
|
|
|
|
def test_hover_floor_and_mission_payload_are_hard(seeded_repo):
|
|
"""Rotorcraft must keep >= its min_specific_power at the build the
|
|
optimizer actually picks (payload included), and an actuator that can
|
|
never reach it is infeasible rather than silently floored."""
|
|
from physcom.models.combination import Combination
|
|
from physcom.engine.pipeline import _carried_payload
|
|
|
|
domain = seeded_repo.get_domain("urban_commuting")
|
|
assert domain.requirements == {"payload": 100.0, "trip_range": 50000.0}
|
|
bounds = {mb.metric_name: mb for mb in domain.metric_bounds}
|
|
units = {mb.metric_name: mb.unit for mb in domain.metric_bounds}
|
|
pipeline = Pipeline(seeded_repo, ConstraintResolver(), Scorer(domain))
|
|
rotor = seeded_repo.get_entity_by_name("platform", "Rotorcraft")
|
|
fuel = seeded_repo.get_entity_by_name("energy_storage", "Liquid Fuel")
|
|
|
|
piston = seeded_repo.get_entity_by_name("actuator", "Piston Engine")
|
|
ctx = pipeline._physics_context(Combination(entities=[rotor, piston, fuel]), bounds, domain.requirements)
|
|
a, s, p, feasible = pipeline._decide_masses(ctx, bounds, units)
|
|
gross = p + a + s + _carried_payload(ctx, a)
|
|
assert feasible
|
|
assert ctx.k_act * a / gross >= 140.0 - 1e-6
|
|
raw = pipeline._raw_physics_from_masses(ctx, a, s, bounds, units, platform_mass=p)
|
|
assert raw["range_fuel"] >= 50000.0
|
|
|
|
steam = seeded_repo.get_entity_by_name("actuator", "Steam Engine")
|
|
ctx = pipeline._physics_context(Combination(entities=[rotor, steam, fuel]), bounds, domain.requirements)
|
|
assert pipeline._decide_masses(ctx, bounds, units)[3] is False
|