refactor(config): migrate Config/QlibConfig to Pydantic BaseModel#2106
Open
Ayush10 wants to merge 1 commit intomicrosoft:mainfrom
Open
refactor(config): migrate Config/QlibConfig to Pydantic BaseModel#2106Ayush10 wants to merge 1 commit intomicrosoft:mainfrom
Ayush10 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Replace the raw dict wrapper in Config/QlibConfig with a typed Pydantic BaseModel (`QlibConfigModel`). All existing access patterns are preserved: - `C["key"]` dict-style access - `C.key` attribute access - `C.get(key, default)` safe access - `"key" in C` containment check - `C.update()`, `C.reset()` lifecycle methods - Pickle serialization - Nested dict mutation (logging_config, exp_manager, etc.) - Dynamic keys via `extra="allow"` (flask_server, region, etc.) The QlibConfigModel provides typed fields with defaults for all config keys, enabling IDE autocompletion, type checking, and future validation. No consumer files are changed in this PR. Add 39 tests covering all backward-compatible access patterns. Closes microsoft#1309
57c8473 to
3c7e319
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Config/QlibConfigwith a typed PydanticBaseModel(QlibConfigModel)Motivation
Issue #1309 requests refactoring the dict-based config management to use Pydantic for type safety, validation, and documentation. This PR is the first step: it introduces the Pydantic model internally while maintaining 100% backward compatibility.
What Changed
qlib/config.py: AddedQlibConfigModel(BaseModel)with typed fields for all config keys.Configclass now wraps aQlibConfigModelinstance instead of a raw dict. Usesextra="allow"so dynamic keys still work.tests/test_config_pydantic.py(new): 39 tests covering all backward-compatible access patternsWhat Did NOT Change
C["key"]andC.keyaccess patterns work identicallyTest plan
Closes #1309