Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# CI compatibility baseline

The three Python workflows share `constraints.txt` via a job-level, absolute
`PIP_CONSTRAINT` path. It applies to every pip invocation, including installs
inside `make ci-install`, later notebook/tool installs, and the released `pyqlib`
package. A bound in this checkout's `pyproject.toml` alone does not constrain a
package installed from PyPI. Keep the compatibility bounds in both files in
sync; `tests/test_ci_configuration.py` checks this.

This is a set of known compatibility bounds, not a fully reproducible Python
lockfile. The workflows run `pip check` and always print installed versions for
future diagnosis. They retain all 25 OS/Python combinations per workflow and
disable matrix fail-fast so that one failure does not hide the others.

## Why these bounds exist

| Dependency | Constraint | Failure addressed |
| --- | --- | --- |
| MLflow | `<3.13` | Qlib uses the filesystem tracking backend, disabled by default in newer versions. |
| filelock | `>=3.16.0,<3.30` | Fork-safety checks conflict with DataQueue's producer thread and multiprocessing workers. |
| fastjsonschema | `<2.22` on Python 3.8/3.9 | Python 3.10 union annotations are evaluated on older interpreters. |
| Plotly | `<7` | Qlib still imports `figure_factory.create_distplot`. |
| lxml | `<6.1.3` | The Windows job falls back to a source distribution without libxml2 headers. |
| OSQP | `==1.0.5` on Windows/Python 3.8 | Native imports crash with 1.1.3 and also with 0.6.7.post3. |
| Black | `<26.1` | Use one compatible formatter for both Python and notebooks. |

OSQP 1.0.5 is the wheel used by the successful full Windows/Python 3.8 job in
[PR #2308](https://github.com/microsoft/qlib/actions/runs/30225522618/job/89854962742).
It is selected during dependency resolution, not installed as a downgrade after
an incompatible environment has already been built. All three workflows smoke
test native solver imports rather than excluding Windows/Python 3.8.

`MLFLOW_ALLOW_FILE_STORE=true` retains the original PR's explicit file-backend
opt-in. The upper bound also protects source installs outside CI. Migrating
Qlib's tracking backend is a separate change.

## Install only each test job's dependencies

CI calls `make ci-install` with an explicit `CI_EXTRAS` profile. The existing
`make dev` target still installs the complete developer environment.

| Source job | Extras |
| --- | --- |
| Regular, Windows/macOS | `dev,test,analysis,lint` |
| Regular, Ubuntu 24.04 | `dev,test,analysis,lint,rl` |
| Regular, Ubuntu 22.04 | `dev,test,analysis,lint,rl,docs` |
| Slow, Windows/macOS | `dev,test,analysis` |
| Slow, Linux | `dev,test,analysis,rl` |

All source jobs additionally install `test-requirements.txt`: PyTorch is
required for the neural-network tests even without the RL extra. NumPy/SciPy
retain the compatibility bounds previously inherited from the RL/docs extras.
Ubuntu jobs select CPU PyTorch wheels. torchvision/torchaudio are not used by
the test suite and are no longer installed explicitly. No test job needs the
package-building extra; docs dependencies are installed only where `docs-gen`
runs. Lint checks stay in the existing regular source matrix.

`tests/conftest.py` already excludes RL tests on non-Linux platforms. Installing
RL extras there used to pull in `tianshou -> tensorboard -> grpcio`, requiring
expensive source builds to work around incorrect macOS wheel metadata and an
Xcode 16.4 bundled-zlib build failure. Those jobs no longer install this unused
dependency chain, so the grpcio source-build workaround has been removed.
Linux retains the RL extra and the same RL tests. The PyPI workflow is unchanged.

Explicit imports of PyTorch, Qlib's PyTorch model registry, GeneralPTNN, and
both dataset classes prevent missing dependencies from silently bypassing
neural-network tests. On macOS, prepare LightGBM and its `libomp` runtime before
these checks: importing the model package also eagerly imports LightGBM. The
preparation step verifies the LightGBM native import before checking the model
registry. A non-Linux footprint check rejects accidental
reintroduction of tianshou/TensorBoard/grpcio, followed by the unchanged
`pip check`. If a future test genuinely needs these dependencies on macOS,
update this policy and validate native wheel metadata/imports rather than
disabling the checks. This change does not reduce the matrix, alter test
selection, add caches, or reduce test data sizes.

## Network and workflow retries

Dataset commands have at most three attempts, with a 15-minute timeout per
attempt. `--delete_old False` makes retries noninteractive in these fresh CI
directories, including when an earlier attempt already extracted one dataset.
Bash command blocks use `set -euo pipefail`, so an earlier failure cannot be
hidden by a later successful command. Exhausted retries still fail the job.

The configuration-driven workflow has at most three 30-minute attempts. This
is a bounded mitigation for the observed MLflow file-store error
`Metric 'IC' is malformed. No data found.`, not a fix for a suspected
read/write race. A deterministic error must still fail all attempts; do not
introduce `continue-on-error` or silently skip assertions. Fixing file-store
consistency should be handled separately, with a reproducer.

The MLflow client performance test initializes the tracking store before
timing repeated client construction, uses a monotonic performance clock, and
retains the original 10ms (Linux) / 20ms (other platforms) thresholds. Cold
plugin/store initialization is not a client-construction regression.

The PyPI workflow runs outside the checkout (`RUNNER_TEMP`) and passes the
example YAML by absolute path, so imports test the installed distribution.

## Title lint and maintenance

Checkout, Python setup, Node setup, and retry actions use Node 24-based releases
(`checkout@v6`, `setup-python@v6`, `setup-node@v6`, `retry@v4`). The action
runtime is separate from the Python and Node versions installed for tests.

Node 22 satisfies commitlint's Node >=22.12 requirement. The root `package.json`
and `package-lock.json` pin the title tooling and its transitive dependencies;
CI uses `npm ci --ignore-scripts` and `npx --no-install`.

When updating a bound, update the package metadata and constraints together,
run the offline policy checks, and verify the full matrix, including PyPI:

```sh
python -m unittest discover -s tests -p test_ci_configuration.py
npm ci --ignore-scripts --no-audit --no-fund
printf '%s\n' 'ci: update compatibility baseline' | npx --no-install commitlint --config .commitlintrc.js
```

For local pip installs, set `PIP_CONSTRAINT` to the absolute path of this
directory's `constraints.txt`. Do not infer Windows/macOS runtime correctness
from a Linux resolver check. Remove individual bounds only after reproducing
and verifying the upstream fix on the affected environment.
19 changes: 19 additions & 0 deletions .github/ci/constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Shared by source and PyPI jobs through an absolute PIP_CONSTRAINT path.
# This is a compatibility baseline, not a complete lock of every dependency.
# Keep runtime bounds aligned with pyproject.toml; see README.md in this folder.

# Qlib still uses MLflow's filesystem tracking backend.
mlflow<3.13
# New fork-safety checks race with the threaded DataQueue producer.
filelock>=3.16.0,<3.30
# 2.22 uses Python 3.10 union syntax on older interpreters.
fastjsonschema<2.22; python_version < "3.10"
# Qlib imports figure_factory.create_distplot, removed in Plotly 7.
plotly<7
# 6.1.3 falls back to a source build on Windows without libxml2 headers.
lxml<6.1.3
# This exact Windows/Python 3.8 wheel passed the full matrix in PR #2308.
# Both 1.1.3 and a subsequent downgrade to 0.6.7.post3 crashed on import.
osqp==1.0.5; sys_platform == "win32" and python_version == "3.8"
# Use the same formatter for Python files and notebooks.
black<26.1
7 changes: 7 additions & 0 deletions .github/ci/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Runtime required by both source test workflows, including non-Linux jobs
# which do not run tests/rl. Do not rely on the RL extra to bring in PyTorch.
torch
# Preserve the numerical dependency bounds previously inherited from the RL
# and docs extras while changing which optional tools are installed.
numpy<2.0.0
scipy<=1.15.3
10 changes: 5 additions & 5 deletions .github/workflows/lint_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ jobs:
steps:
# This step is necessary because the lint title uses the .commitlintrc.js file in the project root directory.
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: '16'
node-version: '22'

- name: Install commitlint
run: npm install --save-dev @commitlint/{config-conventional,cli}
run: npm ci --ignore-scripts --no-audit --no-fund

- name: Validate PR Title with commitlint
env:
BODY: ${{ github.event.pull_request.title }}
run: |
echo "$BODY" | npx commitlint --config .commitlintrc.js
printf '%s\n' "$BODY" | npx --no-install commitlint --config .commitlintrc.js
45 changes: 37 additions & 8 deletions .github/workflows/test_qlib_from_pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ on:
jobs:
build:
timeout-minutes: 120
env:
MLFLOW_ALLOW_FILE_STORE: "true"
PIP_CONSTRAINT: ${{ github.workspace }}/.github/ci/constraints.txt

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-24.04, ubuntu-22.04, macos-14, macos-15]
# In github action, using python 3.7, pip install will not match the latest version of the package.
Expand All @@ -25,12 +29,12 @@ jobs:

steps:
- name: Test qlib from pip
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -42,6 +46,13 @@ jobs:
run: |
python -m pip install pyqlib

- name: Verify dependency consistency
run: python -m pip check

- name: Verify native solvers on Windows Python 3.8
if: ${{ matrix.os == 'windows-latest' && matrix.python-version == '3.8' }}
run: python -c "import cvxpy, osqp; print('CVXPY', cvxpy.__version__, 'OSQP', osqp.__version__)"

- name: Install Lightgbm for MacOS
if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }}
run: |
Expand All @@ -50,11 +61,29 @@ jobs:
python -m pip install --no-binary=:all: lightgbm

- name: Downloads dependencies data
run: |
cd ..
python -m qlib.cli.data qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn
cd qlib
uses: nick-fields/retry@v4
with:
timeout_minutes: 15
max_attempts: 3
retry_wait_seconds: 10
shell: bash
command: |
set -euo pipefail
cd "$RUNNER_TEMP"
python -m qlib.cli.data qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn --delete_old False

- name: Test workflow by config
run: |
qrun examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
uses: nick-fields/retry@v4
with:
timeout_minutes: 30
max_attempts: 3
shell: bash
command: |
set -euo pipefail
cd "$RUNNER_TEMP"
python -c "import os, pathlib, qlib; print('Testing installed Qlib:', qlib.__file__); assert pathlib.Path(os.environ['GITHUB_WORKSPACE']).resolve() not in pathlib.Path(qlib.__file__).resolve().parents"
qrun "$GITHUB_WORKSPACE/examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml"

- name: Report installed dependencies
if: always()
run: python -m pip freeze
Loading
Loading