fix: Handle Qlib Docker backtest failures gracefully (SECURITY FIX)

- Add _evaluate_factor_directly() to factor_runner.py
- When Qlib Docker returns None, try direct evaluation from result.h5
- Compute IC/Sharpe directly from factor values + forward returns
- Loop continues instead of hanging on Docker failures
- Fix MD5 security warning: usedforsecurity=False in cache_manager.py

Files changed:
- rdagent/scenarios/qlib/developer/factor_runner.py
- rdagent/app/qlib_rd_loop/quant.py
- rdagent/scenarios/qlib/local/cache_manager.py
This commit is contained in:
TPTBusiness
2026-04-05 09:21:33 +02:00
parent 84e3d1629f
commit c997d0daa6
2 changed files with 166 additions and 6 deletions
+12
View File
@@ -189,6 +189,18 @@ class QuantRDLoop(RDLoop):
if exp is None:
logger.error(f"Factor extraction failed.")
raise FactorEmptyError("Factor extraction failed.")
# Handle failed experiments gracefully (don't break the loop)
if getattr(exp, "failed", False):
reason = getattr(exp, "failure_reason", "unknown")
factor_name = "unknown"
if hasattr(exp, "hypothesis") and exp.hypothesis is not None:
factor_name = getattr(exp.hypothesis, "hypothesis", "unknown")
logger.warning(
f"Factor '{factor_name}' failed evaluation: {reason}. "
f"Continuing with next factor."
)
# Return exp anyway - loop will continue
elif prev_out["direct_exp_gen"]["propose"].action == "model":
exp = self.model_runner.develop(prev_out["coding"])
logger.log_object(exp, tag="runner result")