Spaces:
Sleeping
Sleeping
| """Baseline validation matrix: sweep configs x pressures x speeds.""" | |
| from typing import List, Optional | |
| import pandas as pd | |
| from cryosim import predict | |
| CONFIGS = ["old_icv", "new_icv"] | |
| PRESSURES = [50.0, 100.0, 200.0, 350.0, 500.0, 700.0, 900.0] | |
| SPEEDS = [0.65, 0.8, 1.0] | |
| def run_validation_matrix( | |
| configs: Optional[List[str]] = None, | |
| pressures: Optional[List[float]] = None, | |
| speeds: Optional[List[float]] = None, | |
| flash_eff: float = 0.0, | |
| ) -> pd.DataFrame: | |
| """Run the engine across a grid of conditions. | |
| Returns DataFrame with one row per (config, pressure, speed) combination. | |
| """ | |
| configs = configs or CONFIGS | |
| pressures = pressures or PRESSURES | |
| speeds = speeds or SPEEDS | |
| rows = [] | |
| for cfg_name in configs: | |
| for Pexit in pressures: | |
| for speed in speeds: | |
| try: | |
| r = predict( | |
| hardware=cfg_name, | |
| Pexit=Pexit, | |
| speed=speed, | |
| flash_eff=flash_eff, | |
| ) | |
| rows.append({ | |
| "config": cfg_name, | |
| "Pexit": Pexit, | |
| "speed": speed, | |
| "mdot_kgpm": r.mdot_kgpm, | |
| "mass_eff": r.mass_eff, | |
| "Tc_peak_K": r.Tc_peak_K, | |
| "pc_peak_barg": r.pc_peak_barg, | |
| "DCV_ct_s": r.DCV_ct_s, | |
| "ICV_open_frac": r.ICV_open_frac, | |
| "kWh_extend": r.kWh_extend, | |
| "cpu_s": r.cpu_s, | |
| "steps": r.steps, | |
| "error": None, | |
| }) | |
| except Exception as e: | |
| rows.append({ | |
| "config": cfg_name, | |
| "Pexit": Pexit, | |
| "speed": speed, | |
| "mdot_kgpm": None, | |
| "mass_eff": None, | |
| "Tc_peak_K": None, | |
| "pc_peak_barg": None, | |
| "DCV_ct_s": None, | |
| "ICV_open_frac": None, | |
| "kWh_extend": None, | |
| "cpu_s": None, | |
| "steps": None, | |
| "error": str(e), | |
| }) | |
| return pd.DataFrame(rows) | |
| def save_matrix(df: pd.DataFrame, path: str = "validation_matrix.csv"): | |
| """Save validation matrix results to CSV.""" | |
| df.to_csv(path, index=False) | |
| print(f"Saved {len(df)} results to {path}") | |
| if __name__ == "__main__": | |
| import time | |
| print("Running full validation matrix...") | |
| print(f" Configs: {CONFIGS}") | |
| print(f" Pressures: {PRESSURES}") | |
| print(f" Speeds: {SPEEDS}") | |
| print(f" Total cases: {len(CONFIGS) * len(PRESSURES) * len(SPEEDS)}") | |
| print() | |
| t0 = time.time() | |
| df = run_validation_matrix() | |
| elapsed = time.time() - t0 | |
| print(f"\nCompleted in {elapsed:.1f}s") | |
| print(f"Failures: {df['error'].notna().sum()}") | |
| print() | |
| print(df[["config", "Pexit", "speed", "mdot_kgpm", "mass_eff", "cpu_s"]].to_string(index=False)) | |
| save_matrix(df) | |