-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
🐛 Bug Description
During backtests that spawn joblib workers, fresh worker processes import Qlib and call config.register_from_C(g_config). That function checks C.registered before copying g_config. Because worker C._config lacks the key on first access, Config.getattr raises:
AttributeError: No such registered in self._config
Proposed fix
In qlib/config.py register_from_C:
Replace:
if C.registered and skip_register:
With:
if getattr(C, "registered", False) and skip_register:
After merging g_config into the worker:
self._config["registered"] = True
To Reproduce
qlib.backtest.report.PortfolioMetrics._cal_benchmark → qlib.utils.resam.get_higher_eq_freq_feature → D.features → DatasetD.dataset → dataset_processor → joblib.Parallel → qlib.data.data.inst_calculator → qlib.config.C.register_from_C
qlib/config.py: register_from_C:
if C.registered and skip_register: # raises AttributeError (key missing in worker)
Expected Behavior
Worker config should safely sync from the main process without assuming the key exists.
Environment
OS: Windows 11
Python: 3.10
Qlib: 0.9.7
Joblib: version bundled with Qlib deps
Backend: default process-based Parallel
Additional Notes
This avoids needing user-side hacks or thread-only backends. Defaulting the flag to False on first access is consistent with intent and prevents the worker crash.