src/qlib_platform/: canonical provider-neutral Python package. Package root is reserved for cross-domain composition/core surfaces such as CLI, settings, lineage, bootstrap, workflow contracts, and project audit.src/qlib_platform/data/: market-data ingestion, normalization, quality, PIT data preparation, symbol/universe handling, and provider adapters; concrete vendor/transport integrations belong underdata/sources/.src/qlib_platform/datasets/: DatasetVersion manifests/registry/resolution, lakehouse freezing, verification, Qlib export, and layout/data migration.src/qlib_platform/backtesting/: portfolio/strategy policies, Qlib strategy integration, prediction backtests, execution/strategy audits, and backtest reporting.src/qlib_platform/artifacts/: artifact contracts, prediction/live artifacts, resolvers, institutional artifacts, and research bundle export.src/qlib_platform/research/: research orchestration, feature store, train/select, walk-forward, diagnostics, Phase 1/2/3 governance, and acceptance logic.src/qlib_platform/models/: model adapters, runtime resolution, bundles, registry, and production refit.src/qlib_platform/runtime/: live inference, daily signal orchestration, health/monitoring, runtime safety/resources, and scheduler rendering.src/qlib_platform/ops/: operational state, delivery ledger, LEAN/platform integration, and operational CLI surfaces.src/qlib_platform/releases/,platform_adapter/,feedback/,auth/, andnotifier/: explicit bounded supporting domains.tests/: pytest test suites (test_*.py).scripts/: utility entry scripts.configs/: pipeline and workflow YAML files.docs/: operational runbooks and API documentation..github/workflows/: CI definitions;constraints/: CI dependency constraints.data/: generated/raw/curated output datasets (large artifacts, keep untracked).mlruns/: experiment metadata/artifacts from training runs.README.md: operational command reference.
- Run commands from the repository root and use only the repository-local interpreter: Windows PowerShell
.\.venv\Scripts\python.exe; macOS/Linux.venv/bin/python. Do not use systempython,py, globally installed Python, or baretq/qruncommands. If this interpreter is absent, stop and recreate the local environment before proceeding. - In PowerShell, define
$RepoPython = '.\.venv\Scripts\python.exe'; in macOS/Linux shells, defineRepoPython=.venv/bin/python. Invoke pipeline commands as<repo-python> -m qlib_platform --config configs/pipeline.standalone.yaml <command>unless a governed workflow names another profile.python -m qlib_platformis the canonical module entry point. - Install core development dependencies:
<repo-python> -m pip install -c constraints/ci.txt -e ".[dev]". - Install operational data dependencies when needed:
<repo-python> -m pip install -e ".[data]"; thedataextra currently contains the supported Tushare Pro and MySQL adapter dependencies. Install all operational dependencies with<repo-python> -m pip install -e ".[all,dev]"; PyTorch model work:<repo-python> -m pip install -c constraints/ci.txt -e ".[dev,pytorch]". - Pipeline example:
<repo-python> -m qlib_platform --config configs/pipeline.yaml init-metadata; use explicit, validated--start YYYYMMDD --end YYYYMMDDwindows for backfills. - Qlib workflow run: use the venv-local
qrunlauncher (.\.venv\Scripts\qrun.exeon Windows;.venv/bin/qrunon macOS/Linux) withconfigs/workflow_lightgbm.yaml(requiresQLIB_DATA_URI). - Tests:
<repo-python> -m pytest(discoverstests/test_*.py). - Lint/type check:
<repo-python> -m ruff check src tests,<repo-python> -m ruff format --check src tests, and<repo-python> -m mypy src. - Do not use Makefile targets locally until they are parameterized to use
$RepoPython; they currently resolve Python tools fromPATH.
- Python 3.10+.
- Use 4-space indentation and keep line length near 110.
- Naming:
snake_casefor functions/modules,PascalCasefor classes,UPPER_SNAKE_CASEfor constants. - Prefer small, composable functions for extraction/normalize/stage steps.
- Store credentials in environment variables, never in code.
- Do not encode a market-data vendor in core package, domain, or canonical storage-path names. Provider SDKs, credentials, rate limits, endpoint translations, and transport-specific behavior belong behind
qlib_platform.data.sourcesadapters. - Do not add flat implementation modules at
src/qlib_platform/when a domain package owns the concern. The root is a composition boundary, not a compatibility dumping ground. - The historical
src/tushare_qlibnamespace has been removed. Do not recreate it or add import hooks that silently resurrect it; downstream code must migrate to the canonicalqlib_platformdomain path.
- Test framework:
pytest(declared in optional dev dependencies; invoke it through the repository-local interpreter). - Keep tests deterministic and lightweight; avoid live vendor/API calls in tests.
- Add/extend tests under
tests/with file names liketest_<feature>.py. - Data-source adapters require contract/registry tests and must be testable without live credentials.
- Storage-layout migrations must preserve legacy source bytes and fail closed on ambiguous source layouts; never rewrite DatasetVersion/PIT identity merely to normalize a directory name.
- Run targeted tests with
<repo-python> -m pytest tests/test_normalize.pybefore broad runs. - Before a PR, run the local equivalents of CI quality gates: ruff, mypy,
validate-qrun-contract,pytest --cov=src/qlib_platform --cov-report=term-missing --cov-fail-under=60, andproject-audit --root . --output <temporary-path>. - For execution-boundary updates, update
docs/architecture_boundary.md,docs/qmt_gateway.md, and boundary tests together.
- Use
mainplus short-lived task branches. A branch represents one task, never one computer. - Before starting work on either computer, synchronize
mainwith:git switch maingit fetch origingit pull --ff-only
- Configure
git config --global pull.ff onlyon each development computer. Do not create merge commits merely to synchronize local and remotemain. - Direct commits to
mainare allowed only for low-risk changes such as README/comments, spelling, log wording, or a tiny deterministic fix. Run the relevant local checks before pushing. - Create a short-lived branch and PR for normal features and for all changes involving:
- research, labels, alpha/features, model selection, or walk-forward logic;
- data cleaning, point-in-time correctness, calendars, or survivorship handling;
- backtests, costs, portfolios, strategies, gates, or promotion;
- production/trading execution;
- database schemas, CI, dependencies, large refactors, or experimental work once mature.
- Use task-oriented branch names such as
feat/walk-forward-v2,fix/qlib-calendar,refactor/data-layer,chore/update-qlib, ordocs/research-guide. - To continue the same task on another computer, push the task branch and track that same remote branch. Do not restart the task from
mainor create computer-specific branches. - Keep feature branches current with
git fetch originfollowed bygit rebase origin/main; do not mergeorigin/maininto a feature branch. If the rebased branch was already published, update it withgit push --force-with-lease, never plain--force. - A feature branch may contain several focused commits. Use
type(scope): concise summarycommit messages, for examplefeat(research): add walk-forward runner. - Open a PR as the change-set boundary. Before merge:
- ensure CI passes ruff, mypy, Qlib workflow-contract validation, coverage, project audit, and pytest;
- review the complete diff, especially correctness and point-in-time effects;
- document changed stages, commands/test status, config changes, and validation evidence when data or accuracy behavior changes.
- Prefer Squash and merge so
mainreceives one clean commit per PR. After merge, delete the remote task branch, update localmainwithgit pull --ff-only, delete the local branch, and rungit fetch --prune. - Do not force-push or delete
main. Repository protection should require PR status checks for critical changes without requiring a self-approval review. - Agents working in this repository must follow these rules: use a task branch and PR for functional or critical-path changes, and treat direct-to-
mainwork as the documented low-risk exception.
- Never commit secrets (
TUSHARE_TOKEN,.env, raw API credentials). - Execution-state modules for broker/order state are intentionally out-of-repo: do not add order submission, cancellation, replacement, ledger, or broker-state writes here.
- Validate date windows before running full rebuilds; production jobs should run idempotent checks and data-completeness guards.
- Treat
backfill,stage-*,dump-*,daily-sync,production-*,model-deploy,model-rollback, and scheduled-task installation/removal as state-changing operations. Run them only with explicit user authorization and report affected outputs.
qlib-platformis a Research / Alpha Factory. It consumes immutableDataReleaseinputs, performs research, and publishes research artifacts through Artifact Contract v2.- Keep the cross-repository boundary explicit: the sole handoff is a content-addressed
TARGET_PORTFOLIObound to exactly oneDataRelease. - Do not introduce broker order submission, cancellation, replacement, broker-state writes, OMS ownership, execution ledgers, hard-risk enforcement, or authoritative LEAN execution semantics. Those belong to
platform. - Preserve point-in-time causality, immutable artifact identities, per-fold fitted-state isolation, ordered non-overlapping OOS stitching, deterministic lineage/hashes, final-holdout isolation, and fail-closed validation.
- The certified infrastructure baseline is the default explanation for weak research results. Do not alter certified infrastructure behavior merely because a model, alpha, or portfolio result is weak; see
docs/research_infrastructure_certification.md. - The active governed program is Phase 3-D. It is diagnostics only: formal candidates, model selection, P2-R01 through P2-R03, final-holdout access, and publishing remain disallowed. Use the
research-diagnosticsSkill and its Phase 3-D profile before Phase 3 work.