mirror of
https://github.com/microsoft/qlib.git
synced 2026-11-12 05:50:57 +08:00
* security: harden artifact serialization and loading * ci: restore dependency and title lint compatibility * fix: address artifact test and lint failures * ci: handle current MLflow and Windows OSQP changes * ci: use lxml release with cross-platform wheels * fix: defer optional CVXPY solver imports * docs: mark notebook model artifacts as trusted * docs: mark position artifacts as trusted * style: document intentional lazy import * ci: skip broken released OSQP on Windows Python 3.8 * fix: mark online model artifacts as trusted * test: make MLflow client timing check robust * ci: retry nondeterministic benchmark smoke test * fix: cap filelock before fork safety regression * fix: use filelock release compatible with multiprocessing * fix: preserve artifact loading compatibility after hardening * fix(security): validate derived artifact paths and extend regressions * fix(security): preserve extended data artifact round trips * fix(security): retain legacy NumPy and pandas artifact classes Allow the exact MaskedArray and SparseDtype module paths emitted by the older dependency versions in CI. Preserve restricted loading and cover both old and new paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(data): avoid unused trading calendar lookup in PIT normalization PIT normalization uses report dates and calendar-day offsets, so do not request an unused Baostock calendar. Cover annual and quarterly normalization without online calendar access. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(security): require explicit trust in artifact workflows Expose default-off artifact trust at online, delayed-training and meta-workflow entry points. Keep data loading restricted, preserve legacy default recorder calls and restored workflow defaults, and document migration and trust boundaries. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test(workflow): cover complete DDG-DA and HIST artifact flows Exercise real training, cache and recorder restoration, saved-task replay, signals and portfolio backtests. Fix the cache trust, grouping, relative-path, LightGBM early-stopping and HIST CPU blockers exposed by full execution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(security)!: unify artifact trust and publish upgrade guidance Use trusted consistently across public APIs and CLI options. Migrate pre-release saved consent only at serialization boundaries, reject invalid or conflicting settings, and preserve restricted data reads. Add a canonical upgrade guide with README, installation, changelog and runtime-error entry points. BREAKING CHANGE: executable artifact restoration requires explicit trusted=True. HIST mappings use JSON and high-frequency cache paths must remain within artifact_root. See docs/start/artifact_migration.rst for upgrading existing workflows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(security): remove trial-only trust compatibility Target upgrades from pre-PR Qlib rather than artifacts generated by intermediate PR revisions. Retain restricted defaults for saved objects without consent, unify current APIs, and remove state/keyword migration branches and documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: avoid failed dataset probes and space download retries Download the same existing v2 archives used by successful jobs without probing nonexistent package-version assets. Allow five download attempts 60 seconds apart; preserve the full matrix, datasets, noninteractive setup and failure propagation. Cover the exact archives and retry policy in offline CI tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs: add practical artifact migration examples Show explicit consent for restored online components while preserving the original manager, schema-aware Arrow conversions, timezone-preserving ZoneInfo migration, and restricted round trips into a separate recorder. Explain shared-component scope, staging artifacts and trusted-source prerequisites. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(workflow): preserve fresh artifact workflows with scoped trust Keep immutable cache references intact at open rolling tails. Add explicit per-load record-template consent and per-artifact collector loading options without widening other reads. Restore the original template class after parent-load failures, and support audited business-frequency and NumPy record representations through exact pickle globals. Document the scoped APIs and cover fresh trained-model reads, cache generation, numerical round trips and refusal paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
164 lines
6.2 KiB
YAML
164 lines
6.2 KiB
YAML
name: Test qlib from source
|
|
|
|
concurrency:
|
|
cancel-in-progress: true
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
build:
|
|
timeout-minutes: 180
|
|
env:
|
|
MLFLOW_ALLOW_FILE_STORE: "true"
|
|
PIP_CONSTRAINT: ${{ github.workspace }}/.github/ci/constraints.txt
|
|
# we may retry for 3 times for `Unit tests with Pytest`
|
|
|
|
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.
|
|
# Also, python 3.7 is no longer supported from macos-14, and will be phased out from macos-13 in the near future.
|
|
# All things considered, we have removed python 3.7.
|
|
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
|
|
|
steps:
|
|
- name: Test qlib from source
|
|
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Update pip to the latest version
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
|
|
- name: Installing pytorch for ubuntu
|
|
if: ${{ matrix.os == 'ubuntu-24.04' || matrix.os == 'ubuntu-22.04' }}
|
|
run: |
|
|
python -m pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
|
|
|
|
- name: Set up Python tools
|
|
env:
|
|
# RL tests are Linux-only; only ubuntu-22.04 builds the docs below.
|
|
CI_EXTRAS: dev,test,analysis,lint${{ runner.os == 'Linux' && ',rl' || '' }}${{ matrix.os == 'ubuntu-22.04' && ',docs' || '' }}
|
|
run: |
|
|
make ci-install
|
|
|
|
# Importing Qlib's model registry also loads LightGBM and its OpenMP runtime.
|
|
- name: Install Lightgbm for MacOS
|
|
if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }}
|
|
run: |
|
|
brew update
|
|
brew install libomp || brew reinstall libomp
|
|
python -m pip install --no-binary=:all: lightgbm
|
|
python -c "import lightgbm; print('LightGBM', lightgbm.__version__, 'native import passed')"
|
|
|
|
- name: Verify neural network test dependencies
|
|
run: python -c "import torch; from qlib.contrib.model import pytorch_classes; from qlib.contrib.model.pytorch_general_nn import GeneralPTNN; from qlib.data.dataset import DatasetH, TSDatasetH; assert pytorch_classes; print('PyTorch', torch.__version__, 'model imports passed')"
|
|
|
|
- name: Verify non-Linux dependency footprint
|
|
if: ${{ runner.os != 'Linux' }}
|
|
run: python -c "from importlib.metadata import distributions; unexpected = {'tianshou', 'tensorboard', 'grpcio'} & {d.metadata['Name'].lower() for d in distributions()}; assert not unexpected, unexpected"
|
|
|
|
- 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: Lint with Black
|
|
run: |
|
|
make black
|
|
|
|
- name: Make html with sphinx
|
|
# Since read the docs builds on ubuntu 22.04, we only need to test that the build passes on ubuntu 22.04.
|
|
if: ${{ matrix.os == 'ubuntu-22.04' }}
|
|
run: |
|
|
make docs-gen
|
|
|
|
- name: Check Qlib with pylint
|
|
run: |
|
|
make pylint
|
|
|
|
- name: Check Qlib with flake8
|
|
run: |
|
|
make flake8
|
|
|
|
- name: Check Qlib with mypy
|
|
run: |
|
|
make mypy
|
|
|
|
- name: Check Qlib ipynb with nbqa
|
|
run: |
|
|
make nbqa
|
|
|
|
- name: Test data downloads
|
|
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4
|
|
with:
|
|
timeout_minutes: 15
|
|
max_attempts: 5
|
|
retry_wait_seconds: 60
|
|
shell: bash
|
|
command: |
|
|
set -euo pipefail
|
|
python scripts/get_data.py download_data --file_name v2/qlib_data_simple_cn_1d_latest.zip --target_dir ~/.qlib/qlib_data/cn_data --delete_old False
|
|
python scripts/get_data.py download_data --file_name rl_data.zip --target_dir tests/.data/rl --delete_old False
|
|
|
|
- name: Check Qlib ipynb with nbconvert
|
|
run: |
|
|
make nbconvert
|
|
|
|
- name: Test workflow by config (install from source)
|
|
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4
|
|
with:
|
|
timeout_minutes: 30
|
|
max_attempts: 3
|
|
shell: bash
|
|
command: |
|
|
set -euo pipefail
|
|
python -m pip install numba
|
|
python -m pip check
|
|
python qlib/cli/run.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
|
|
|
|
- name: Unit tests with Pytest (MacOS)
|
|
if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }}
|
|
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4
|
|
with:
|
|
timeout_minutes: 60
|
|
max_attempts: 3
|
|
command: |
|
|
# Limit the number of threads in various libraries to prevent Segmentation faults caused by OpenMP multithreading conflicts under macOS.
|
|
export OMP_NUM_THREADS=1 # Limit the number of OpenMP threads
|
|
export MKL_NUM_THREADS=1 # Limit the number of Intel MKL threads
|
|
export NUMEXPR_NUM_THREADS=1 # Limit the number of NumExpr threads
|
|
export OPENBLAS_NUM_THREADS=1 # Limit the number of OpenBLAS threads
|
|
export VECLIB_MAXIMUM_THREADS=1 # Limit the number of macOS Accelerate/vecLib threads
|
|
cd tests
|
|
python -m pytest . -m "not slow" --durations=0
|
|
|
|
- name: Unit tests with Pytest (Ubuntu and Windows)
|
|
if: ${{ matrix.os != 'macos-13' && matrix.os != 'macos-14' && matrix.os != 'macos-15' }}
|
|
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4
|
|
with:
|
|
timeout_minutes: 60
|
|
max_attempts: 3
|
|
command: |
|
|
cd tests
|
|
python -m pytest . -m "not slow" --durations=0
|
|
|
|
- name: Report installed dependencies
|
|
if: always()
|
|
run: python -m pip freeze
|