Spaces:
Build error
Build error
updated constraints
Browse files
src/__pycache__/data_prep.cpython-310.pyc
ADDED
|
Binary file (1.14 kB). View file
|
|
|
src/__pycache__/shared_features.cpython-310.pyc
ADDED
|
Binary file (7.08 kB). View file
|
|
|
src/evolution_optimized.py
CHANGED
|
@@ -22,7 +22,6 @@ SRC_DIR = PROJECT_ROOT / "src"
|
|
| 22 |
sys.path.append(str(PROJECT_ROOT))
|
| 23 |
|
| 24 |
|
| 25 |
-
|
| 26 |
class GenericPredictor:
|
| 27 |
"""Generic predictor that works for any property model."""
|
| 28 |
|
|
@@ -131,23 +130,16 @@ class GenericPredictor:
|
|
| 131 |
# Configuration: Use environment variable to switch between local and HF Hub
|
| 132 |
USE_LOCAL_MODELS = os.getenv('USE_LOCAL_MODELS', 'false').lower() == 'true'
|
| 133 |
|
| 134 |
-
# Hugging Face model repositories
|
| 135 |
HF_MODEL_REPOS = {
|
| 136 |
-
'cn': "SalZa2004/Cetane_Number_Predictor",
|
| 137 |
'ysi': "SalZa2004/YSI_Predictor",
|
| 138 |
'bp': "SalZa2004/Boiling_Point_Predictor",
|
| 139 |
'density': "SalZa2004/Density_Predictor",
|
| 140 |
'lhv': "SalZa2004/LHV_Predictor",
|
|
|
|
| 141 |
}
|
| 142 |
|
| 143 |
-
# Local predictor paths (only used if USE_LOCAL_MODELS=true)
|
| 144 |
-
LOCAL_PREDICTOR_PATHS = {
|
| 145 |
-
'cn': PROJECT_ROOT / "cn_predictor_model" / "cn_model",
|
| 146 |
-
'ysi': PROJECT_ROOT / "ysi_predictor_model" / "ysi_model",
|
| 147 |
-
'bp': PROJECT_ROOT / "bp_predictor_model" / "bp_model",
|
| 148 |
-
'density': PROJECT_ROOT / "density_predictor_model" / "density_model",
|
| 149 |
-
'lhv': PROJECT_ROOT / "lhv_predictor_model" / "lhv_model",
|
| 150 |
-
}
|
| 151 |
|
| 152 |
@dataclass
|
| 153 |
class EvolutionConfig:
|
|
@@ -155,18 +147,22 @@ class EvolutionConfig:
|
|
| 155 |
target_cn: float
|
| 156 |
minimize_ysi: bool = True
|
| 157 |
generations: int = 6
|
| 158 |
-
population_size: int =
|
| 159 |
mutations_per_parent: int = 5
|
| 160 |
-
survivor_fraction: float = 0.5
|
| 161 |
min_bp: float = 60
|
| 162 |
max_bp: float = 250
|
| 163 |
-
|
| 164 |
-
|
| 165 |
min_density: float = 720
|
|
|
|
| 166 |
use_bp_filter: bool = True
|
| 167 |
use_density_filter: bool = True
|
|
|
|
|
|
|
| 168 |
batch_size: int = 50
|
| 169 |
-
max_offspring_attempts: int = 10
|
|
|
|
| 170 |
|
| 171 |
@dataclass
|
| 172 |
class Molecule:
|
|
@@ -178,6 +174,7 @@ class Molecule:
|
|
| 178 |
ysi: Optional[float] = None
|
| 179 |
density: Optional[float] = None
|
| 180 |
lhv: Optional[float] = None
|
|
|
|
| 181 |
|
| 182 |
def dominates(self, other: 'Molecule') -> bool:
|
| 183 |
"""Check if this molecule Pareto-dominates another."""
|
|
@@ -203,14 +200,6 @@ class PropertyPredictor:
|
|
| 203 |
|
| 204 |
# Helper function to create predictor
|
| 205 |
def create_predictor(prop_name: str, display_name: str):
|
| 206 |
-
if USE_LOCAL_MODELS:
|
| 207 |
-
return GenericPredictor(
|
| 208 |
-
repo_id="", # Not used for local
|
| 209 |
-
property_name=display_name,
|
| 210 |
-
use_local=True,
|
| 211 |
-
local_dir=LOCAL_PREDICTOR_PATHS[prop_name]
|
| 212 |
-
)
|
| 213 |
-
else:
|
| 214 |
return GenericPredictor(
|
| 215 |
repo_id=HF_MODEL_REPOS[prop_name],
|
| 216 |
property_name=display_name,
|
|
@@ -232,12 +221,16 @@ class PropertyPredictor:
|
|
| 232 |
|
| 233 |
if config.use_lhv_filter:
|
| 234 |
self.predictors['lhv'] = create_predictor('lhv', 'Lower Heating Value')
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
# Define validation rules
|
| 237 |
self.validators = {
|
| 238 |
'bp': lambda v: self.config.min_bp <= v <= self.config.max_bp,
|
| 239 |
'density': lambda v: v > self.config.min_density,
|
| 240 |
'lhv': lambda v: v > self.config.min_lhv,
|
|
|
|
| 241 |
}
|
| 242 |
|
| 243 |
def _safe_predict(self, predictions: List) -> List[Optional[float]]:
|
|
@@ -264,7 +257,7 @@ class PropertyPredictor:
|
|
| 264 |
"""Predict all properties for a batch of SMILES."""
|
| 265 |
return {
|
| 266 |
prop: self._predict_batch(prop, smiles_list)
|
| 267 |
-
for prop in ['cn', 'ysi', 'bp', 'density', 'lhv'] #
|
| 268 |
if prop in self.predictors # Only predict if predictor exists
|
| 269 |
}
|
| 270 |
|
|
@@ -389,21 +382,22 @@ class MolecularEvolution:
|
|
| 389 |
# Validate required properties
|
| 390 |
if props['cn'] is None:
|
| 391 |
continue
|
| 392 |
-
if self.config.minimize_ysi and props
|
| 393 |
continue
|
| 394 |
|
| 395 |
-
# Validate filtered properties
|
| 396 |
-
if not all(self.predictor.is_valid(k, props
|
| 397 |
continue
|
| 398 |
|
| 399 |
molecules.append(Molecule(
|
| 400 |
smiles=smiles,
|
| 401 |
cn=props['cn'],
|
| 402 |
cn_error=abs(props['cn'] - self.config.target_cn),
|
| 403 |
-
bp=props
|
| 404 |
-
ysi=props
|
| 405 |
-
density=props
|
| 406 |
-
lhv=props
|
|
|
|
| 407 |
))
|
| 408 |
|
| 409 |
return molecules
|
|
@@ -575,22 +569,44 @@ def save_results(final_df: pd.DataFrame, pareto_df: pd.DataFrame, minimize_ysi:
|
|
| 575 |
|
| 576 |
def display_results(final_df: pd.DataFrame, pareto_df: pd.DataFrame, minimize_ysi: bool):
|
| 577 |
"""Display results to console."""
|
| 578 |
-
|
| 579 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
|
| 581 |
print("\n=== TOP 10 (sorted) ===")
|
| 582 |
print(final_df.head(10)[cols].to_string(index=False))
|
| 583 |
|
| 584 |
if minimize_ysi and not pareto_df.empty:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
print("\n=== PARETO FRONT (ranked) ===")
|
| 586 |
-
print(pareto_df[
|
| 587 |
-
.head(20).to_string(index=False))
|
| 588 |
|
| 589 |
|
| 590 |
def main():
|
| 591 |
"""Main execution function."""
|
| 592 |
config = get_user_config()
|
| 593 |
|
|
|
|
|
|
|
|
|
|
| 594 |
# Display and save results
|
| 595 |
display_results(final_df, pareto_df, config.minimize_ysi)
|
| 596 |
save_results(final_df, pareto_df, config.minimize_ysi)
|
|
|
|
| 22 |
sys.path.append(str(PROJECT_ROOT))
|
| 23 |
|
| 24 |
|
|
|
|
| 25 |
class GenericPredictor:
|
| 26 |
"""Generic predictor that works for any property model."""
|
| 27 |
|
|
|
|
| 130 |
# Configuration: Use environment variable to switch between local and HF Hub
|
| 131 |
USE_LOCAL_MODELS = os.getenv('USE_LOCAL_MODELS', 'false').lower() == 'true'
|
| 132 |
|
| 133 |
+
# Hugging Face model repositories
|
| 134 |
HF_MODEL_REPOS = {
|
| 135 |
+
'cn': "SalZa2004/Cetane_Number_Predictor",
|
| 136 |
'ysi': "SalZa2004/YSI_Predictor",
|
| 137 |
'bp': "SalZa2004/Boiling_Point_Predictor",
|
| 138 |
'density': "SalZa2004/Density_Predictor",
|
| 139 |
'lhv': "SalZa2004/LHV_Predictor",
|
| 140 |
+
'dynamic_viscosity': "SalZa2004/Dynamic_Viscosity_Predictor",
|
| 141 |
}
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
@dataclass
|
| 145 |
class EvolutionConfig:
|
|
|
|
| 147 |
target_cn: float
|
| 148 |
minimize_ysi: bool = True
|
| 149 |
generations: int = 6
|
| 150 |
+
population_size: int = 50
|
| 151 |
mutations_per_parent: int = 5
|
| 152 |
+
survivor_fraction: float = 0.5
|
| 153 |
min_bp: float = 60
|
| 154 |
max_bp: float = 250
|
| 155 |
+
min_dynamic_viscosity: float = 0.0
|
| 156 |
+
max_dynamic_viscosity: float = 2.0
|
| 157 |
min_density: float = 720
|
| 158 |
+
min_lhv: float = 30
|
| 159 |
use_bp_filter: bool = True
|
| 160 |
use_density_filter: bool = True
|
| 161 |
+
use_lhv_filter: bool = True
|
| 162 |
+
use_dynamic_viscosity_filter: bool = True
|
| 163 |
batch_size: int = 50
|
| 164 |
+
max_offspring_attempts: int = 10
|
| 165 |
+
|
| 166 |
|
| 167 |
@dataclass
|
| 168 |
class Molecule:
|
|
|
|
| 174 |
ysi: Optional[float] = None
|
| 175 |
density: Optional[float] = None
|
| 176 |
lhv: Optional[float] = None
|
| 177 |
+
dynamic_viscosity: Optional[float] = None
|
| 178 |
|
| 179 |
def dominates(self, other: 'Molecule') -> bool:
|
| 180 |
"""Check if this molecule Pareto-dominates another."""
|
|
|
|
| 200 |
|
| 201 |
# Helper function to create predictor
|
| 202 |
def create_predictor(prop_name: str, display_name: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
return GenericPredictor(
|
| 204 |
repo_id=HF_MODEL_REPOS[prop_name],
|
| 205 |
property_name=display_name,
|
|
|
|
| 221 |
|
| 222 |
if config.use_lhv_filter:
|
| 223 |
self.predictors['lhv'] = create_predictor('lhv', 'Lower Heating Value')
|
| 224 |
+
|
| 225 |
+
if config.use_dynamic_viscosity_filter:
|
| 226 |
+
self.predictors['dynamic_viscosity'] = create_predictor('dynamic_viscosity', 'Dynamic Viscosity')
|
| 227 |
|
| 228 |
# Define validation rules
|
| 229 |
self.validators = {
|
| 230 |
'bp': lambda v: self.config.min_bp <= v <= self.config.max_bp,
|
| 231 |
'density': lambda v: v > self.config.min_density,
|
| 232 |
'lhv': lambda v: v > self.config.min_lhv,
|
| 233 |
+
'dynamic_viscosity': lambda v: self.config.min_dynamic_viscosity <= v <= self.config.max_dynamic_viscosity
|
| 234 |
}
|
| 235 |
|
| 236 |
def _safe_predict(self, predictions: List) -> List[Optional[float]]:
|
|
|
|
| 257 |
"""Predict all properties for a batch of SMILES."""
|
| 258 |
return {
|
| 259 |
prop: self._predict_batch(prop, smiles_list)
|
| 260 |
+
for prop in ['cn', 'ysi', 'bp', 'density', 'lhv', 'dynamic_viscosity'] # ✅ FIXED: Added dynamic_viscosity
|
| 261 |
if prop in self.predictors # Only predict if predictor exists
|
| 262 |
}
|
| 263 |
|
|
|
|
| 382 |
# Validate required properties
|
| 383 |
if props['cn'] is None:
|
| 384 |
continue
|
| 385 |
+
if self.config.minimize_ysi and props.get('ysi') is None:
|
| 386 |
continue
|
| 387 |
|
| 388 |
+
# ✅ FIXED: Validate filtered properties including dynamic_viscosity
|
| 389 |
+
if not all(self.predictor.is_valid(k, props.get(k)) for k in ['bp', 'density', 'lhv', 'dynamic_viscosity']):
|
| 390 |
continue
|
| 391 |
|
| 392 |
molecules.append(Molecule(
|
| 393 |
smiles=smiles,
|
| 394 |
cn=props['cn'],
|
| 395 |
cn_error=abs(props['cn'] - self.config.target_cn),
|
| 396 |
+
bp=props.get('bp'),
|
| 397 |
+
ysi=props.get('ysi'),
|
| 398 |
+
density=props.get('density'),
|
| 399 |
+
lhv=props.get('lhv'),
|
| 400 |
+
dynamic_viscosity=props.get('dynamic_viscosity')
|
| 401 |
))
|
| 402 |
|
| 403 |
return molecules
|
|
|
|
| 569 |
|
| 570 |
def display_results(final_df: pd.DataFrame, pareto_df: pd.DataFrame, minimize_ysi: bool):
|
| 571 |
"""Display results to console."""
|
| 572 |
+
# ✅ FIXED: Added dynamic_viscosity to display columns
|
| 573 |
+
cols = ["rank", "smiles", "cn", "cn_error"]
|
| 574 |
+
if minimize_ysi and "ysi" in final_df.columns:
|
| 575 |
+
cols.append("ysi")
|
| 576 |
+
if "bp" in final_df.columns:
|
| 577 |
+
cols.append("bp")
|
| 578 |
+
if "density" in final_df.columns:
|
| 579 |
+
cols.append("density")
|
| 580 |
+
if "lhv" in final_df.columns:
|
| 581 |
+
cols.append("lhv")
|
| 582 |
+
if "dynamic_viscosity" in final_df.columns:
|
| 583 |
+
cols.append("dynamic_viscosity")
|
| 584 |
|
| 585 |
print("\n=== TOP 10 (sorted) ===")
|
| 586 |
print(final_df.head(10)[cols].to_string(index=False))
|
| 587 |
|
| 588 |
if minimize_ysi and not pareto_df.empty:
|
| 589 |
+
pareto_cols = ["rank", "smiles", "cn", "cn_error", "ysi"]
|
| 590 |
+
if "bp" in pareto_df.columns:
|
| 591 |
+
pareto_cols.append("bp")
|
| 592 |
+
if "density" in pareto_df.columns:
|
| 593 |
+
pareto_cols.append("density")
|
| 594 |
+
if "lhv" in pareto_df.columns:
|
| 595 |
+
pareto_cols.append("lhv")
|
| 596 |
+
if "dynamic_viscosity" in pareto_df.columns:
|
| 597 |
+
pareto_cols.append("dynamic_viscosity")
|
| 598 |
+
|
| 599 |
print("\n=== PARETO FRONT (ranked) ===")
|
| 600 |
+
print(pareto_df[pareto_cols].head(20).to_string(index=False))
|
|
|
|
| 601 |
|
| 602 |
|
| 603 |
def main():
|
| 604 |
"""Main execution function."""
|
| 605 |
config = get_user_config()
|
| 606 |
|
| 607 |
+
evolution = MolecularEvolution(config)
|
| 608 |
+
final_df, pareto_df = evolution.evolve()
|
| 609 |
+
|
| 610 |
# Display and save results
|
| 611 |
display_results(final_df, pareto_df, config.minimize_ysi)
|
| 612 |
save_results(final_df, pareto_df, config.minimize_ysi)
|
src/streamlit_app.py
CHANGED
|
@@ -37,6 +37,9 @@ DEFAULTS = {
|
|
| 37 |
"min_density": 720.0,
|
| 38 |
"use_lhv_filter": True,
|
| 39 |
"min_lhv": 30.0,
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
for k, v in DEFAULTS.items():
|
|
@@ -152,6 +155,7 @@ with st.container():
|
|
| 152 |
|
| 153 |
# === Property constraints ===
|
| 154 |
with st.expander("🔬 Property Constraints", expanded=False):
|
|
|
|
| 155 |
use_bp_filter = st.checkbox(
|
| 156 |
"Filter by Boiling Point",
|
| 157 |
value=st.session_state.use_bp_filter,
|
|
@@ -176,6 +180,7 @@ with st.container():
|
|
| 176 |
st.session_state.min_bp = min_bp
|
| 177 |
st.session_state.max_bp = max_bp
|
| 178 |
|
|
|
|
| 179 |
use_density_filter = st.checkbox(
|
| 180 |
"Filter by Density",
|
| 181 |
value=st.session_state.use_density_filter,
|
|
@@ -193,6 +198,7 @@ with st.container():
|
|
| 193 |
if not use_density_filter:
|
| 194 |
st.session_state.min_density = min_density
|
| 195 |
|
|
|
|
| 196 |
use_lhv_filter = st.checkbox(
|
| 197 |
"Filter by Lower Heating Value",
|
| 198 |
value=st.session_state.use_lhv_filter,
|
|
@@ -210,6 +216,32 @@ with st.container():
|
|
| 210 |
if not use_lhv_filter:
|
| 211 |
st.session_state.min_lhv = min_lhv
|
| 212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
# Run button
|
| 214 |
st.divider()
|
| 215 |
|
|
@@ -248,6 +280,10 @@ if run_optimization:
|
|
| 248 |
use_bp_filter=st.session_state.use_bp_filter,
|
| 249 |
use_density_filter=st.session_state.use_density_filter,
|
| 250 |
use_lhv_filter=st.session_state.use_lhv_filter,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
)
|
| 252 |
|
| 253 |
# Progress tracking
|
|
@@ -343,7 +379,7 @@ if st.session_state.results is not None and not st.session_state.results.empty:
|
|
| 343 |
with tab1:
|
| 344 |
st.subheader("Best Fuel Candidates")
|
| 345 |
|
| 346 |
-
# Prepare display columns
|
| 347 |
display_cols = ["rank", "smiles", "cn", "cn_error"]
|
| 348 |
if "ysi" in final_df.columns:
|
| 349 |
display_cols.append("ysi")
|
|
@@ -353,6 +389,8 @@ if st.session_state.results is not None and not st.session_state.results.empty:
|
|
| 353 |
display_cols.append("density")
|
| 354 |
if "lhv" in final_df.columns:
|
| 355 |
display_cols.append("lhv")
|
|
|
|
|
|
|
| 356 |
|
| 357 |
# Display with formatting
|
| 358 |
styled_df = (
|
|
@@ -383,6 +421,8 @@ if st.session_state.results is not None and not st.session_state.results.empty:
|
|
| 383 |
st.write(f"**Density:** {best['density']:.1f} kg/m³")
|
| 384 |
if "lhv" in best:
|
| 385 |
st.write(f"**LHV:** {best['lhv']:.2f} MJ/kg")
|
|
|
|
|
|
|
| 386 |
|
| 387 |
with tab2:
|
| 388 |
if config.minimize_ysi and pareto_df is not None and not pareto_df.empty:
|
|
@@ -391,6 +431,7 @@ if st.session_state.results is not None and not st.session_state.results.empty:
|
|
| 391 |
"These candidates represent the best trade-offs between CN accuracy and YSI."
|
| 392 |
)
|
| 393 |
|
|
|
|
| 394 |
display_cols_pareto = ["rank", "smiles", "cn", "cn_error", "ysi"]
|
| 395 |
if "bp" in pareto_df.columns:
|
| 396 |
display_cols_pareto.append("bp")
|
|
@@ -398,6 +439,8 @@ if st.session_state.results is not None and not st.session_state.results.empty:
|
|
| 398 |
display_cols_pareto.append("density")
|
| 399 |
if "lhv" in pareto_df.columns:
|
| 400 |
display_cols_pareto.append("lhv")
|
|
|
|
|
|
|
| 401 |
|
| 402 |
styled_pareto = pareto_df[display_cols_pareto].style.background_gradient(
|
| 403 |
subset=["cn_error", "ysi"], cmap="RdYlGn_r"
|
|
@@ -460,4 +503,4 @@ st.markdown(
|
|
| 460 |
</div>
|
| 461 |
""",
|
| 462 |
unsafe_allow_html=True,
|
| 463 |
-
)
|
|
|
|
| 37 |
"min_density": 720.0,
|
| 38 |
"use_lhv_filter": True,
|
| 39 |
"min_lhv": 30.0,
|
| 40 |
+
"use_dynamic_viscosity_filter": True, # ✅ ADDED
|
| 41 |
+
"min_dynamic_viscosity": 0.0, # ✅ ADDED
|
| 42 |
+
"max_dynamic_viscosity": 2.0, # ✅ ADDED
|
| 43 |
}
|
| 44 |
|
| 45 |
for k, v in DEFAULTS.items():
|
|
|
|
| 155 |
|
| 156 |
# === Property constraints ===
|
| 157 |
with st.expander("🔬 Property Constraints", expanded=False):
|
| 158 |
+
# Boiling Point
|
| 159 |
use_bp_filter = st.checkbox(
|
| 160 |
"Filter by Boiling Point",
|
| 161 |
value=st.session_state.use_bp_filter,
|
|
|
|
| 180 |
st.session_state.min_bp = min_bp
|
| 181 |
st.session_state.max_bp = max_bp
|
| 182 |
|
| 183 |
+
# Density
|
| 184 |
use_density_filter = st.checkbox(
|
| 185 |
"Filter by Density",
|
| 186 |
value=st.session_state.use_density_filter,
|
|
|
|
| 198 |
if not use_density_filter:
|
| 199 |
st.session_state.min_density = min_density
|
| 200 |
|
| 201 |
+
# LHV
|
| 202 |
use_lhv_filter = st.checkbox(
|
| 203 |
"Filter by Lower Heating Value",
|
| 204 |
value=st.session_state.use_lhv_filter,
|
|
|
|
| 216 |
if not use_lhv_filter:
|
| 217 |
st.session_state.min_lhv = min_lhv
|
| 218 |
|
| 219 |
+
# ✅ ADDED: Dynamic Viscosity Filter
|
| 220 |
+
use_dynamic_viscosity_filter = st.checkbox(
|
| 221 |
+
"Filter by Dynamic Viscosity",
|
| 222 |
+
value=st.session_state.use_dynamic_viscosity_filter,
|
| 223 |
+
key="use_dynamic_viscosity_filter",
|
| 224 |
+
)
|
| 225 |
+
if use_dynamic_viscosity_filter:
|
| 226 |
+
col1, col2 = st.columns(2)
|
| 227 |
+
with col1:
|
| 228 |
+
min_dynamic_viscosity = st.number_input(
|
| 229 |
+
"Min Viscosity (mPa·s)",
|
| 230 |
+
value=st.session_state.min_dynamic_viscosity,
|
| 231 |
+
key="min_dynamic_viscosity",
|
| 232 |
+
)
|
| 233 |
+
with col2:
|
| 234 |
+
max_dynamic_viscosity = st.number_input(
|
| 235 |
+
"Max Viscosity (mPa·s)",
|
| 236 |
+
value=st.session_state.max_dynamic_viscosity,
|
| 237 |
+
key="max_dynamic_viscosity",
|
| 238 |
+
)
|
| 239 |
+
else:
|
| 240 |
+
min_dynamic_viscosity = 0.0
|
| 241 |
+
max_dynamic_viscosity = 2.0
|
| 242 |
+
st.session_state.min_dynamic_viscosity = min_dynamic_viscosity
|
| 243 |
+
st.session_state.max_dynamic_viscosity = max_dynamic_viscosity
|
| 244 |
+
|
| 245 |
# Run button
|
| 246 |
st.divider()
|
| 247 |
|
|
|
|
| 280 |
use_bp_filter=st.session_state.use_bp_filter,
|
| 281 |
use_density_filter=st.session_state.use_density_filter,
|
| 282 |
use_lhv_filter=st.session_state.use_lhv_filter,
|
| 283 |
+
# ✅ ADDED: Dynamic viscosity parameters
|
| 284 |
+
use_dynamic_viscosity_filter=st.session_state.use_dynamic_viscosity_filter,
|
| 285 |
+
min_dynamic_viscosity=st.session_state.min_dynamic_viscosity,
|
| 286 |
+
max_dynamic_viscosity=st.session_state.max_dynamic_viscosity,
|
| 287 |
)
|
| 288 |
|
| 289 |
# Progress tracking
|
|
|
|
| 379 |
with tab1:
|
| 380 |
st.subheader("Best Fuel Candidates")
|
| 381 |
|
| 382 |
+
# ✅ FIXED: Prepare display columns including dynamic_viscosity
|
| 383 |
display_cols = ["rank", "smiles", "cn", "cn_error"]
|
| 384 |
if "ysi" in final_df.columns:
|
| 385 |
display_cols.append("ysi")
|
|
|
|
| 389 |
display_cols.append("density")
|
| 390 |
if "lhv" in final_df.columns:
|
| 391 |
display_cols.append("lhv")
|
| 392 |
+
if "dynamic_viscosity" in final_df.columns:
|
| 393 |
+
display_cols.append("dynamic_viscosity")
|
| 394 |
|
| 395 |
# Display with formatting
|
| 396 |
styled_df = (
|
|
|
|
| 421 |
st.write(f"**Density:** {best['density']:.1f} kg/m³")
|
| 422 |
if "lhv" in best:
|
| 423 |
st.write(f"**LHV:** {best['lhv']:.2f} MJ/kg")
|
| 424 |
+
if "dynamic_viscosity" in best:
|
| 425 |
+
st.write(f"**Viscosity:** {best['dynamic_viscosity']:.3f} mPa·s")
|
| 426 |
|
| 427 |
with tab2:
|
| 428 |
if config.minimize_ysi and pareto_df is not None and not pareto_df.empty:
|
|
|
|
| 431 |
"These candidates represent the best trade-offs between CN accuracy and YSI."
|
| 432 |
)
|
| 433 |
|
| 434 |
+
# ✅ FIXED: Add dynamic_viscosity to pareto display
|
| 435 |
display_cols_pareto = ["rank", "smiles", "cn", "cn_error", "ysi"]
|
| 436 |
if "bp" in pareto_df.columns:
|
| 437 |
display_cols_pareto.append("bp")
|
|
|
|
| 439 |
display_cols_pareto.append("density")
|
| 440 |
if "lhv" in pareto_df.columns:
|
| 441 |
display_cols_pareto.append("lhv")
|
| 442 |
+
if "dynamic_viscosity" in pareto_df.columns:
|
| 443 |
+
display_cols_pareto.append("dynamic_viscosity")
|
| 444 |
|
| 445 |
styled_pareto = pareto_df[display_cols_pareto].style.background_gradient(
|
| 446 |
subset=["cn_error", "ysi"], cmap="RdYlGn_r"
|
|
|
|
| 503 |
</div>
|
| 504 |
""",
|
| 505 |
unsafe_allow_html=True,
|
| 506 |
+
)
|