Unverified Commit 885b2adb authored by Bharath Ramsundar's avatar Bharath Ramsundar Committed by GitHub
Browse files

Merge pull request #2560 from VIGNESHinZONE/set

Setup for Jax dependency
parents cbab9678 32d52079
Loading
Loading
Loading
Loading
+137 −0
Original line number Diff line number Diff line
name: Test for DeepChem Jax
on:
  push: # ci work when pushing master branch
    branches:
      - master
  pull_request: # ci work when creating a PR to master branch
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.7]
    steps:
    - uses: actions/checkout@v2
    - name: Cache pip modules for Linux
      uses: actions/cache@v2
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ hashFiles('env.*.yml') }}
        restore-keys: |
          ${{ runner.os }}-pip-
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Build DeepChem
      run: |
        python -m pip install --upgrade pip
        pip install tensorflow==2.4
        pip install -e '.[jax]'
    - name: Import checking
      run: python -c "import deepchem; import jax;"

  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        python-version: [3.7]
        include:
          - os: ubuntu-latest
            python-version: 3.6
    env:
      OS: ${{ matrix.os }}
      PYTHON_VERSION: ${{ matrix.python-version }}
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    # https://github.com/galaxyproject/tools-iuc/blob/master/.github/workflows/pr.yaml
    # The range of commits to check for changes is:
    # - for events on the master branch we compare against the sha before the event
    #   (note that this does not work for feature branch events since we want all
    #   commits on the feature branch and not just the commits of the last event)
    # - for pull requests we compare against the 1st ancestor, given the current
    #   HEAD is the merge between the PR branch and the base branch
    - name: Set commit range (push to the master branch, e.g. merge)
      if: github.ref == 'refs/heads/master' && github.event_name == 'push'
      run: echo "COMMIT_RANGE=${{ github.event.before }}.." >> $GITHUB_ENV
    - name: Set commit range (pull request)
      if: github.event_name == 'pull_request'
      run: |
        git fetch origin master
        echo "COMMIT_RANGE=origin/master..." >> $GITHUB_ENV
    - name: Cache pip packages for Linux
      if: runner.os == 'Linux'
      uses: actions/cache@v2
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ hashFiles('env.*.yml') }}
        restore-keys: |
          ${{ runner.os }}-pip-
    - name: Cache pip packages for MacOS
      if: runner.os == 'macOS'
      uses: actions/cache@v2
      with:
        path: ~/Library/Caches/pip
        key: ${{ matrix.os }}-pip-${{ hashFiles('env.*.yml') }}
        restore-keys: |
          ${{ runner.os }}-pip-
    - name: Cache pip packages for Windows
      if: runner.os == 'Windows'
      uses: actions/cache@v2
      with:
        path: ~\AppData\Local\pip\Cache
        key: ${{ matrix.os }}-pip-${{ hashFiles('env.*.yml') }}
        restore-keys: |
          ${{ runner.os }}-pip-
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Create env.yml
      shell: bash
      run: |
        python -m pip install --upgrade pip;
        pip install conda-merge;
        if [ "$(uname)" == 'Darwin' ]; then
          conda-merge env_jax.yml env.test.yml > env.yml
        else
          conda-merge env_jax.yml env.test.yml > env.yml
        fi;
    - name: Install all dependencies
      uses: conda-incubator/setup-miniconda@v2
      with:
        miniconda-version: "latest"
        auto-update-conda: true
        activate-environment: deepchem
        channels: omnia,conda-forge,defaults
        python-version: ${{ matrix.python-version }}
        environment-file: env.yml
    - name: Install DeepChem
      id: install
      shell: bash -l {0}
      run: pip install -e '.[jax]'
    - name: Yapf (version 0.22.0)
      id: yapf
      # on Windows, yapf raise the strange error..., so ignore
      if: runner.os == 'Linux' || runner.os == 'macOS'
      shell: bash -l {0}
      run: |
        CHANGED_FILES=`git diff --name-only $COMMIT_RANGE | grep .py$ | grep -v contrib/ || true`
        if [ -n "$CHANGED_FILES" ]; then
          yapf -d $CHANGED_FILES
        fi
    - name: Flake8
      if: ${{ (success() || failure()) && (steps.install.outcome == 'failure' || steps.install.outcome == 'success') }}
      shell: bash -l {0}
      run: source scripts/flake8_for_ci.sh
    - name: PyTest
      if: ${{ (success() || failure()) && (steps.install.outcome == 'failure' || steps.install.outcome == 'success') }}
      shell: bash -l {0}
      run: pytest -v -m jax deepchem
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ jobs:
    - name: PyTest
      if: ${{ (success() || failure()) && (steps.install.outcome == 'failure' || steps.install.outcome == 'success') }}
      shell: bash -l {0}
      run: pytest -v -m "not slow" --cov=deepchem --cov-report=xml deepchem
      run: pytest -v -m "not slow and not jax" --cov=deepchem --cov-report=xml deepchem
    - name: Upload coverage to Codecov
      if: ${{ (success() || failure()) && (steps.install.outcome == 'failure' || steps.install.outcome == 'success') }}
      uses: codecov/codecov-action@v1
+8 −2
Original line number Diff line number Diff line
# Requirements - transformers, tokenizers
import os
import unittest
from unittest import TestCase
from deepchem.feat.smiles_tokenizer import SmilesTokenizer
try:
  from transformers import RobertaForMaskedLM
  from deepchem.feat.smiles_tokenizer import SmilesTokenizer
  has_transformers = True
except:
  has_transformers = False


class TestSmilesTokenizer(TestCase):
  """Tests the SmilesTokenizer to load the USPTO vocab file and a ChemBERTa Masked LM model with pre-trained weights.."""

  @unittest.skipIf(not has_transformers, 'transformers are not installed')
  def test_tokenize(self):
    current_dir = os.path.dirname(os.path.realpath(__file__))
    vocab_path = os.path.join(current_dir, 'data', 'vocab.txt')
+1 −1
Original line number Diff line number Diff line
@@ -5,13 +5,13 @@ import numpy as np

import deepchem as dc
from deepchem.feat import MolGraphConvFeaturizer
from deepchem.models import AttentiveFPModel
from deepchem.models.tests.test_graph_models import get_dataset

try:
  import dgl
  import dgllife
  import torch
  from deepchem.models import AttentiveFPModel
  has_torch_and_dgl = True
except:
  has_torch_and_dgl = False
+1 −1
Original line number Diff line number Diff line
@@ -7,11 +7,11 @@ import numpy as np
from deepchem.feat import CGCNNFeaturizer
from deepchem.molnet import load_perovskite, load_mp_metallicity
from deepchem.metrics import Metric, mae_score, roc_auc_score
from deepchem.models import CGCNNModel

try:
  import dgl  # noqa
  import torch  # noqa
  from deepchem.models import CGCNNModel
  has_pytorch_and_dgl = True
except:
  has_pytorch_and_dgl = False
Loading