seeding expansion
also: replace energy output with energy output density
This commit is contained in:
@@ -37,7 +37,7 @@ def walking():
|
||||
Dependency("environment", "ground_surface", "true", None, "requires"),
|
||||
Dependency("environment", "gravity", "true", None, "requires"),
|
||||
Dependency("physical", "mass_kg", "150", "kg", "range_max"),
|
||||
Dependency("force", "force_required_watts", "75", "watts", "range_min"),
|
||||
Dependency("force", "power_density_required_w_kg", "1", "W/kg", "range_min"),
|
||||
Dependency("environment", "medium", "ground", None, "requires"),
|
||||
],
|
||||
)
|
||||
@@ -53,7 +53,7 @@ def bicycle():
|
||||
Dependency("environment", "ground_surface", "true", None, "requires"),
|
||||
Dependency("environment", "gravity", "true", None, "requires"),
|
||||
Dependency("physical", "mass_kg", "30", "kg", "range_max"),
|
||||
Dependency("force", "force_required_watts", "75", "watts", "range_min"),
|
||||
Dependency("force", "power_density_required_w_kg", "1", "W/kg", "range_min"),
|
||||
Dependency("environment", "medium", "ground", None, "requires"),
|
||||
],
|
||||
)
|
||||
@@ -68,7 +68,7 @@ def spaceship():
|
||||
dependencies=[
|
||||
Dependency("environment", "atmosphere", "vacuum_or_thin", None, "requires"),
|
||||
Dependency("physical", "mass_kg", "5000", "kg", "range_min"),
|
||||
Dependency("force", "force_required_watts", "1000000", "watts", "range_min"),
|
||||
Dependency("force", "power_density_required_w_kg", "500", "W/kg", "range_min"),
|
||||
Dependency("environment", "medium", "space", None, "requires"),
|
||||
],
|
||||
)
|
||||
@@ -82,7 +82,7 @@ def solar_sail():
|
||||
description="Propulsion via radiation pressure",
|
||||
dependencies=[
|
||||
Dependency("environment", "atmosphere", "vacuum_or_thin", None, "requires"),
|
||||
Dependency("force", "force_output_watts", "1", "watts", "provides"),
|
||||
Dependency("force", "power_density_w_kg", "0.01", "W/kg", "provides"),
|
||||
Dependency("environment", "medium", "space", None, "requires"),
|
||||
],
|
||||
)
|
||||
@@ -95,7 +95,7 @@ def human_pedalling():
|
||||
dimension="power_source",
|
||||
description="Human-powered via pedalling",
|
||||
dependencies=[
|
||||
Dependency("force", "force_output_watts", "75", "watts", "provides"),
|
||||
Dependency("force", "power_density_w_kg", "1.5", "W/kg", "provides"),
|
||||
Dependency("physical", "mass_kg", "0", "kg", "range_min"),
|
||||
],
|
||||
)
|
||||
@@ -108,7 +108,7 @@ def nuclear_reactor():
|
||||
dimension="power_source",
|
||||
description="Small modular nuclear fission reactor",
|
||||
dependencies=[
|
||||
Dependency("force", "force_output_watts", "50000000", "watts", "provides"),
|
||||
Dependency("force", "power_density_w_kg", "50", "W/kg", "provides"),
|
||||
Dependency("physical", "mass_kg", "2000", "kg", "range_min"),
|
||||
],
|
||||
)
|
||||
@@ -121,7 +121,7 @@ def hydrogen_engine():
|
||||
dimension="power_source",
|
||||
description="Hydrogen fuel cell",
|
||||
dependencies=[
|
||||
Dependency("force", "force_output_watts", "80000", "watts", "provides"),
|
||||
Dependency("force", "power_density_w_kg", "1500", "W/kg", "provides"),
|
||||
Dependency("physical", "mass_kg", "30", "kg", "range_min"),
|
||||
],
|
||||
)
|
||||
@@ -134,7 +134,7 @@ def ice_engine():
|
||||
dimension="power_source",
|
||||
description="Gas-powered engine",
|
||||
dependencies=[
|
||||
Dependency("force", "force_output_watts", "100000", "watts", "provides"),
|
||||
Dependency("force", "power_density_w_kg", "1000", "W/kg", "provides"),
|
||||
Dependency("environment", "atmosphere", "standard", None, "requires"),
|
||||
Dependency("physical", "mass_kg", "50", "kg", "range_min"),
|
||||
],
|
||||
|
||||
48
tests/test_admin.py
Normal file
48
tests/test_admin.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Tests for admin panel — clear_all, reseed, and additive reseed."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from physcom.seed.transport_example import load_transport_seed
|
||||
|
||||
|
||||
def test_clear_all_wipes_data(seeded_repo):
|
||||
"""clear_all() should remove all rows from every table."""
|
||||
repo = seeded_repo
|
||||
assert len(repo.list_entities()) > 0
|
||||
assert len(repo.list_domains()) > 0
|
||||
|
||||
repo.clear_all()
|
||||
|
||||
assert len(repo.list_entities()) == 0
|
||||
assert len(repo.list_domains()) == 0
|
||||
assert len(repo.list_dimensions()) == 0
|
||||
assert sum(repo.count_combinations_by_status().values()) == 0
|
||||
assert len(repo.list_pipeline_runs()) == 0
|
||||
|
||||
|
||||
def test_reseed_after_clear_restores_data(seeded_repo):
|
||||
"""Wipe then reseed should restore entity/domain counts."""
|
||||
repo = seeded_repo
|
||||
original_entities = len(repo.list_entities())
|
||||
original_domains = len(repo.list_domains())
|
||||
|
||||
repo.clear_all()
|
||||
assert len(repo.list_entities()) == 0
|
||||
|
||||
counts = load_transport_seed(repo)
|
||||
assert len(repo.list_entities()) == original_entities
|
||||
assert len(repo.list_domains()) == original_domains
|
||||
assert counts["platforms"] + counts["power_sources"] == original_entities
|
||||
|
||||
|
||||
def test_additive_reseed_no_duplicates(seeded_repo):
|
||||
"""Running reseed on an already-seeded DB should not create duplicates."""
|
||||
repo = seeded_repo
|
||||
before = len(repo.list_entities())
|
||||
|
||||
counts = load_transport_seed(repo)
|
||||
|
||||
assert len(repo.list_entities()) == before
|
||||
assert counts["platforms"] == 0
|
||||
assert counts["power_sources"] == 0
|
||||
assert counts["domains"] == 0
|
||||
@@ -7,9 +7,11 @@ from physcom.models.entity import Entity
|
||||
|
||||
|
||||
def test_generates_cartesian_product(seeded_repo):
|
||||
from physcom.seed.transport_example import PLATFORMS, POWER_SOURCES
|
||||
|
||||
combos = generate_combinations(seeded_repo, ["platform", "power_source"])
|
||||
# 9 platforms x 9 power sources = 81
|
||||
assert len(combos) == 81
|
||||
expected = len(PLATFORMS) * len(POWER_SOURCES)
|
||||
assert len(combos) == expected
|
||||
|
||||
|
||||
def test_each_combo_has_one_per_dimension(seeded_repo):
|
||||
|
||||
@@ -41,39 +41,39 @@ def test_nuclear_reactor_blocks_with_bicycle(bicycle, nuclear_reactor):
|
||||
assert any("mass" in v.lower() for v in result.violations)
|
||||
|
||||
|
||||
def test_force_scale_mismatch_blocks():
|
||||
"""A platform needing 1MW and a power source providing 1W → force deficit block."""
|
||||
def test_power_density_mismatch_blocks():
|
||||
"""A platform needing 500 W/kg and a source providing 0.01 W/kg → block."""
|
||||
platform = Entity(
|
||||
name="HeavyPlatform", dimension="platform",
|
||||
dependencies=[
|
||||
Dependency("force", "force_required_watts", "1000000", "watts", "range_min"),
|
||||
Dependency("force", "power_density_required_w_kg", "500", "W/kg", "range_min"),
|
||||
],
|
||||
)
|
||||
power = Entity(
|
||||
name="TinyPower", dimension="power_source",
|
||||
dependencies=[
|
||||
Dependency("force", "force_output_watts", "1", "watts", "provides"),
|
||||
Dependency("force", "power_density_w_kg", "0.01", "W/kg", "provides"),
|
||||
],
|
||||
)
|
||||
resolver = ConstraintResolver()
|
||||
combo = Combination(entities=[platform, power])
|
||||
result = resolver.resolve(combo)
|
||||
assert result.status == "p1_fail"
|
||||
assert any("force deficit" in v for v in result.violations)
|
||||
assert any("power density deficit" in v for v in result.violations)
|
||||
|
||||
|
||||
def test_force_under_powered_warning():
|
||||
def test_power_density_under_powered_warning():
|
||||
"""Power source slightly below requirement → warning, not block."""
|
||||
platform = Entity(
|
||||
name="MedPlatform", dimension="platform",
|
||||
dependencies=[
|
||||
Dependency("force", "force_required_watts", "1000", "watts", "range_min"),
|
||||
Dependency("force", "power_density_required_w_kg", "100", "W/kg", "range_min"),
|
||||
],
|
||||
)
|
||||
power = Entity(
|
||||
name="WeakPower", dimension="power_source",
|
||||
dependencies=[
|
||||
Dependency("force", "force_output_watts", "500", "watts", "provides"),
|
||||
Dependency("force", "power_density_w_kg", "50", "W/kg", "provides"),
|
||||
],
|
||||
)
|
||||
resolver = ConstraintResolver()
|
||||
@@ -175,7 +175,7 @@ def test_energy_density_no_constraint_if_no_provider():
|
||||
power = Entity(
|
||||
name="Solar Sail", dimension="power_source",
|
||||
dependencies=[
|
||||
Dependency("force", "force_output_watts", "1", "watts", "provides"),
|
||||
Dependency("force", "power_density_w_kg", "0.01", "W/kg", "provides"),
|
||||
],
|
||||
)
|
||||
resolver = ConstraintResolver()
|
||||
|
||||
@@ -15,9 +15,11 @@ def test_pass1_filters_impossible_combos(seeded_repo):
|
||||
|
||||
result = pipeline.run(domain, ["platform", "power_source"], passes=[1])
|
||||
|
||||
assert result.total_generated == 81
|
||||
from physcom.seed.transport_example import PLATFORMS, POWER_SOURCES
|
||||
expected = len(PLATFORMS) * len(POWER_SOURCES)
|
||||
assert result.total_generated == expected
|
||||
assert result.pass1_failed > 0
|
||||
assert result.pass1_valid + result.pass1_conditional + result.pass1_failed == 81
|
||||
assert result.pass1_valid + result.pass1_conditional + result.pass1_failed == expected
|
||||
|
||||
|
||||
def test_pass123_produces_scored_results(seeded_repo):
|
||||
|
||||
@@ -21,9 +21,12 @@ def test_pipeline_run_lifecycle(seeded_repo):
|
||||
|
||||
pipeline.run(domain, ["platform", "power_source"], passes=[1, 2, 3], run_id=run_id)
|
||||
|
||||
from physcom.seed.transport_example import PLATFORMS, POWER_SOURCES
|
||||
expected = len(PLATFORMS) * len(POWER_SOURCES)
|
||||
|
||||
run = repo.get_pipeline_run(run_id)
|
||||
assert run["status"] == "completed"
|
||||
assert run["total_combos"] == 81
|
||||
assert run["total_combos"] == expected
|
||||
assert run["started_at"] is not None
|
||||
assert run["completed_at"] is not None
|
||||
|
||||
|
||||
@@ -79,10 +79,12 @@ def test_combination_save_and_dedup(repo):
|
||||
|
||||
|
||||
def test_seed_loads(seeded_repo):
|
||||
from physcom.seed.transport_example import PLATFORMS, POWER_SOURCES, ALL_DOMAINS
|
||||
|
||||
platforms = seeded_repo.list_entities(dimension="platform")
|
||||
power_sources = seeded_repo.list_entities(dimension="power_source")
|
||||
assert len(platforms) == 9
|
||||
assert len(power_sources) == 9
|
||||
assert len(platforms) == len(PLATFORMS)
|
||||
assert len(power_sources) == len(POWER_SOURCES)
|
||||
|
||||
domains = seeded_repo.list_domains()
|
||||
assert len(domains) == 2
|
||||
assert len(domains) == len(ALL_DOMAINS)
|
||||
|
||||
Reference in New Issue
Block a user