Fix mypy error. #916
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
| name: Test | |
| on: | |
| push: | |
| branches: ["*"] | |
| paths: | |
| - "src/**" | |
| - "tests/**" | |
| - ".github/workflows/**" | |
| - "pyproject.toml" | |
| pull_request: | |
| branches: [main] | |
| paths: | |
| - "src/**" | |
| - "tests/**" | |
| - ".github/workflows/**" | |
| - "pyproject.toml" | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| task: | |
| type: choice | |
| options: [tests, release] | |
| default: tests | |
| description: Only run tests or release a new version to PyPI after tests pass. | |
| jobs: | |
| test: | |
| strategy: | |
| max-parallel: 20 | |
| matrix: | |
| config: | |
| - os: ubuntu-latest | |
| python: "3.13" | |
| optionals: "ops" | |
| - os: ubuntu-latest | |
| python: "3.13" | |
| optionals: "alchmtk" | |
| - os: ubuntu-latest | |
| python: "3.13" | |
| optionals: "jax" | |
| - os: ubuntu-latest | |
| python: "3.13" | |
| - os: macos-latest | |
| python: "3.11" | |
| runs-on: ${{ matrix.config.os }} | |
| env: | |
| PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: "python" | |
| PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: "uv.lock" | |
| python-version: ${{ matrix.config.python }} | |
| - name: Virtual env | |
| run: uv venv --python ${{ matrix.config.python }} --clear | |
| - name: Install dependencies | |
| run: | | |
| uv sync --upgrade | |
| uv pip install -e ".[${{ matrix.config.optionals }}]" | |
| uv pip install pytest pytest-cov | |
| - name: pytest | |
| run: | | |
| uv run python -c "import torch; print(torch.__version__)" | |
| uv run pytest --cov=matgl --cov-report=xml --cov-report=term tests --color=yes | |
| - name: Upload coverage artifacts | |
| if: matrix.config.optionals == 'ops' | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: coverage | |
| path: coverage.xml | |
| if-no-files-found: error | |
| test_grace_parity: | |
| # Numerical parity job for the GRACE model against the upstream | |
| # ``tensorpotential`` (TensorFlow) reference. Heavy install (TensorFlow | |
| # ~500 MB) so it lives in a dedicated job rather than under the main | |
| # test matrix. ``tensorpotential`` is intentionally NOT declared as a | |
| # project dependency or extras group; we install it manually here. | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python: ["3.11"] | |
| env: | |
| PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: "python" | |
| TF_CPP_MIN_LOG_LEVEL: "2" | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: "uv.lock" | |
| python-version: ${{ matrix.python }} | |
| - name: Virtual env | |
| run: uv venv --python ${{ matrix.python }} --clear | |
| - name: Install matgl | |
| run: | | |
| uv sync --upgrade | |
| uv pip install -e . | |
| uv pip install pytest | |
| - name: Install tensorpotential (parity reference) | |
| # Manual install — not added to pyproject.toml. We avoid pulling | |
| # ``tensorpotential``'s full dependency closure for two reasons: | |
| # | |
| # 1. On Linux, ``tensorpotential`` pins ``tensorflow[and-cuda]<2.20``, | |
| # whose ``nvidia-nccl-cu12`` extra clashes with torch's bundled | |
| # NCCL ABI (``undefined symbol: ncclCommWindowDeregister``). | |
| # 2. ``tensorpotential`` declares ``tf_keras`` as a dep, but the | |
| # Linux/Python 3.11 wheel resolved here ships with | |
| # ``saved_metadata.proto`` gencode 6.31.1 while ``tensorflow<2.20`` | |
| # constrains ``protobuf<6.0.0`` — TF 2.19 unconditionally imports | |
| # ``tf_keras.src.optimizers`` at startup and the gencode/runtime | |
| # check fails. The parity tests don't use Keras at all. | |
| # | |
| # We install ``tensorpotential`` itself with ``--no-deps`` and add | |
| # only the runtime deps the parity test actually exercises. | |
| run: | | |
| uv pip install --no-deps "tensorpotential>=0.5.9" | |
| uv pip install \ | |
| "tensorflow<2.20" \ | |
| "numpy<2" \ | |
| "scipy" \ | |
| "sympy" \ | |
| "matscipy" \ | |
| "pandas" \ | |
| "tqdm" \ | |
| "pyyaml" | |
| - name: parity pytest | |
| run: | | |
| uv run python -c "import tensorflow as tf, tensorpotential; print('tf', tf.__version__)" | |
| uv run pytest tests/models/test_grace_parity_tp.py tests/models/test_grace_training_parity.py -v --color=yes | |
| coverage: | |
| needs: [test] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Download coverage | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: coverage | |
| path: . | |
| merge-multiple: true | |
| - name: Upload coverage reports to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| files: coverage.xml | |
| fail_ci_if_error: false | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
| release: | |
| if: github.event_name == 'release' || inputs.task == 'release' | |
| needs: [test] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| # For pypi trusted publishing | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set up Python 3.12 | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.12" | |
| - name: Build | |
| run: | | |
| pip install build | |
| python -m build | |
| - name: Publish to PyPi | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| skip-existing: true | |
| verbose: true |