Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupyter Continuous Integration #57

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions .github/workflows/jupyter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: jupyter

on:
push:
branches: [ master, shuklak13-patch-1 ]
pull_request:
branches: [ master, shuklak13-patch-1 ]
schedule:
- cron: '0 11 * * *'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]

steps:
- uses: actions/checkout@v2

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

- name: Install pip
run: |
python -m pip install --upgrade pip

- name: Install TensorFlow ecosystem
run: |
pip install tensorflow
pip install tensorflow_data_validation
pip install tensorflow_hub
pip install tensorflow-model-analysis

- name: Install test dependencies
run: |
pip install nbformat
pip install nbconvert

- name: Set up Jupyter
run: |
pip install jupyter
jupyter nbextension enable --py widgetsnbextension --sys-prefix
jupyter nbextension install --py --symlink tensorflow_model_analysis --sys-prefix
jupyter nbextension enable --py tensorflow_model_analysis --sys-prefix

- name: Test Jupyter Notebooks
run: python test_runner.py
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Fairness Indicators BETA

![](https://github.com/tensorflow/fairness-indicators/workflows/jupyter/badge.svg)

![Fairness_Indicators](https://raw.githubusercontent.com/tensorflow/fairness-indicators/master/fairness_indicators/images/fairnessIndicators.png)

Fairness Indicators is designed to support teams in evaluating, improving, and comparing models for fairness concerns in partnership with the broader Tensorflow toolkit.
Expand Down
34 changes: 34 additions & 0 deletions notebook_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import nbformat
import os

from nbconvert.preprocessors import ExecutePreprocessor


def run_notebook(notebook_path):
nb_name, _ = os.path.splitext(os.path.basename(notebook_path))
dirname = os.path.dirname(notebook_path)

with open(notebook_path) as f:
nb = nbformat.read(f, as_version=4)

proc = ExecutePreprocessor(timeout=None, kernel_name='python3')
proc.allow_errors = True

proc.preprocess(nb, {'metadata': {'path': '/'}})
output_path = os.path.join(dirname, '{}_all_output.ipynb'.format(nb_name))

with open(output_path, mode='wt') as f:
nbformat.write(nb, f)

errors = []
for cell in nb.cells:
if 'outputs' in cell:
for output in cell['outputs']:
if output.output_type == 'error':
errors.append(output)

print('ERRORS')
print(type(errors))
print(errors)

return errors
45 changes: 45 additions & 0 deletions test_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest

import notebook_runner


class TestNotebook(unittest.TestCase):

def test_example(self):
errors = notebook_runner.run_notebook(
'fairness_indicators/examples/Fairness_Indicators_Example_Colab.ipynb')
self.assertEmpty(errors)

def test_facessd(self):
errors = notebook_runner.run_notebook(
'fairness_indicators/examples/Facessd_Fairness_Indicators_Example_Colab.ipynb')
self.assertEmpty(errors)

def test_lineage(self):
errors = notebook_runner.run_notebook(
'fairness_indicators/examples/Fairness_Indicators_Lineage_Case_Study.ipynb')
self.assertEmpty(errors)

def test_tb(self):
errors = notebook_runner.run_notebook(
'fairness_indicators/examples/Fairness_Indicators_TensorBoard_Plugin_Example_Colab.ipynb')
self.assertEmpty(errors)

def test_tfco_celeba(self):
errors = notebook_runner.run_notebook(
'fairness_indicators/examples/Fairness_Indicators_TFCO_CelebA_Case_Study.ipynb')
self.assertEmpty(errors)

def test_tfco_wiki(self):
errors = notebook_runner.run_notebook(
'fairness_indicators/examples/Fairness_Indicators_TFCO_Wiki_Case_Study.ipynb')
self.assertEmpty(errors)

def test_tfhub(self):
errors = notebook_runner.run_notebook(
'fairness_indicators/examples/Fairness_Indicators_on_TF_Hub_Text_Embeddings.ipynb')
self.assertEmpty(errors)


if __name__ == '__main__':
unittest.main()