Skip to content

Commit

Permalink
Updates for hls4ml 0.7.0 (#38)
Browse files Browse the repository at this point in the history
* remove modifying the saturation mode

* Update environment.yml

* update dockerfiles

* update

* update

* pre-commit

* contrib

* update env

* update widgets

* black

* Update _config.yml

* headings

* remove unneaded rounding/sat stuff, set trainging to true

* fix incompatibilities in deployment

* update docker

* update hls4ml to 0.7.0

* update

* clean up titles

* docker publish

* update docker images to tag

* updaet docker locations

---------

Co-authored-by: Javier Duarte <[email protected]>
  • Loading branch information
jmitrevs and jmduarte authored May 13, 2023
1 parent f9ab0c3 commit a7cbaaa
Show file tree
Hide file tree
Showing 27 changed files with 1,569 additions and 1,013 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
52 changes: 52 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: deploy-book

# Only run this when the master branch changes
on:
push:
branches:
- main
pull_request:
branches:
- main

# This job installs dependencies, build the book, and pushes it to `gh-pages`
jobs:
deploy-book:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

# Install dependencies
- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: hls4ml-tutorial
environment-file: environment.yml
python-version: 3.10.10
auto-activate-base: false

# Check dependencies
- name: Check Miniconda
shell: bash -l {0}
run: |
conda info
conda list
conda config --show-sources
conda config --show
printenv | sort
- name: Build the book
shell: bash -l {0}
run: |
jupyter contrib nbextension install --user
jupyter nbextension enable --py widgetsnbextension
jupyter-book build .
- name: GitHub Pages action
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: _build/html
force_orphan: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
35 changes: 35 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: docker-publish

on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v4
with:
push: ${{ github.event_name != 'pull_request' }}
file: docker/Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ github.repository }}/hls4ml-0.7.0:latest
ghcr.io/${{ github.repository }}/hls4ml-0.7.0:${{ github.sha }}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.ipynb_checkpoints
__pycache__
*~
*~
*.npy
_build
model_1
model_2
model_3
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ build:
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG --build-arg NB_USER=jovyan --build-arg NB_UID=1000
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
70 changes: 70 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
exclude: .*\.rpt$

repos:
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black-jupyter
language_version: python3
args: ['--line-length=125',
'--skip-string-normalization']

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", --line-length=125]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py36-plus"]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.2.0
hooks:
- id: setup-cfg-fmt

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
exclude: docs/conf.py
additional_dependencies: [flake8-bugbear, flake8-print]
args: ['--max-line-length=125', # github viewer width
'--extend-ignore=E203,T201'] # E203 is not PEP8 compliant

- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
hooks:
- id: check-manifest
stages: [manual]

- repo: https://github.com/jmduarte/p-clang-format
rev: "v1.0.4"
hooks:
- id: p-clang-format
types_or: [c++, c, cuda]
ci:
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit hooks'
autofix_prs: false # default is true
autoupdate_branch: 'main'
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: []
submodules: true
71 changes: 53 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
# hls4ml-tutorial
Tutorial notebooks for `hls4ml`
# hls4ml-tutorial: Tutorial notebooks for `hls4ml`


[![Jupyter Book Badge](https://jupyterbook.org/badge.svg)](https://fastmachinelearning.org/hls4ml-tutorial)
![deploy-book](https://github.com/fastmachinelearning/hls4ml-tutorial/actions/workflows/deploy.yml/badge.svg)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/fastmachinelearning/hls4ml-tutorial)


There are several ways to run the tutorial notebooks:
## Online
[![hls4ml](https://img.shields.io/badge/launch-hls4ml%20hub-%2359188e)](http://cern.ch/ssummers/hls4ml-tutorial)
[![badge](https://img.shields.io/badge/launch-CERN%20binder-E66581.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJXmsr1olJXmsrmZYH1olL1olKkfaPobXvviGabgadXmsqThKuofKHmZ4Dobnr1olJXmsr1olJXmspXmsr1olJXmsrfZ4TuhWn1olL1olJXmsqBi7X1olJXmspZmslbmMhbmsdemsVfl8ZgmsNim8Jpk8F0m7R4m7F5nLB6jbh7jbiDirOEibOGnKaMhq+PnaCVg6qWg6qegKaff6WhnpKofKGtnomxeZy3noG6dZi+n3vCcpPDcpPGn3bLb4/Mb47UbIrVa4rYoGjdaIbeaIXhoWHmZYHobXvpcHjqdHXreHLroVrsfG/uhGnuh2bwj2Hxk17yl1vzmljzm1j0nlX1olL3AJXWAAAAbXRSTlMAEBAQHx8gICAuLjAwMDw9PUBAQEpQUFBXV1hgYGBkcHBwcXl8gICAgoiIkJCQlJicnJ2goKCmqK+wsLC4usDAwMjP0NDQ1NbW3Nzg4ODi5+3v8PDw8/T09PX29vb39/f5+fr7+/z8/Pz9/v7+zczCxgAABC5JREFUeAHN1ul3k0U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aIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC)](https://binder.cern.ch/v2/gh/hls-fpga-machine-learning/hls4ml-tutorial/HEAD)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/hls-fpga-machine-learning/hls4ml-tutorial/HEAD)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/fastmachinelearning/hls4ml-tutorial)

## Conda
The Python environment used for the tutorials is specified in the `environment.yml` file. It can be setup like:
```
The Python environment used for the tutorials is specified in the `environment.yml` file.
It can be setup like:
```bash
conda env create -f environment.yml
conda activate hls4ml-tutorial
```

## Docker
Follow these steps to build a Docker image that can be used locally, or on a JupyterHub instance, e.g. as the [single user image](https://zero-to-jupyterhub.readthedocs.io/en/latest/customizing/user-environment.html#choose-and-use-an-existing-docker-image).
The Dockerfile was modified from one created using `repo2docker`.
You can build the image straight from the Github:
`docker build --build-arg NB_USER=jovyan --build-arg NB_UID=1000 https://github.com/hls-fpga-machine-learning/hls4ml-tutorial.git -f docker/Dockerfile`
Alternatively, you can clone the repository and build locally (you might want to do this to add Vivado installation, for example):
## Docker without Vivado
Pull the prebuilt image from the GitHub Container Registry:
```bash
docker pull ghcr.io/fastmachinlearning/hls4ml-tutorial/hls4ml-0.7.0:latest
```
git clone https://github.com/hls-fpga-machine-learning/hls4ml-tutorial.git

Follow these steps to build a Docker image that can be used locally, or on a JupyterHub instance.
You can build the image (without Vivado):
```bash
docker build https://github.com/fastmachinelearning/hls4ml-tutorial -f docker/Dockerfile
```
Alternatively, you can clone the repository and build locally:
```bash
git clone https://github.com/fastmachinelearning/hls4ml-tutorial
cd hls4ml-tutorial
# modify something
docker build --build-arg NB_USER=jovyan --build-arg NB_UID=1000 . -f docker/Dockerfile
docker build -f docker/Dockerfile -t ghcr.io/fastmachinlearning/hls4ml-tutorial/hls4ml-0.7.0:latest .
```
Then to start the container:
`docker run -p 8888:8888 <IMAGE ID>`
```bash
docker run -p 8888:8888 ghcr.io/fastmachinlearning/hls4ml-tutorial/hls4ml-0.7.0:latest
```
When the container starts, the Jupyter notebook server is started, and the link to open it in your browser is printed.
You can clone the repository inside the container and run the notebooks.

## Docker with Vivado
Pull the prebuilt image from the GitHub Container Registry:
```bash
docker pull ghcr.io/fastmachinlearning/hls4ml-tutorial/hls4ml-0.7.0-vivado-2019.2:latest
```

To build the image with Vivado, run (Warning: takes a long time and requires a lot of disk space):
```bash
docker build -f docker/Dockerfile.vivado -t ghcr.io/fastmachinlearning/hls4ml-tutorial:hls4ml-0.7.0-vivado-2019.2:latest .
```
Then to start the container:
```bash
docker run -p 8888:8888 ghcr.io/fastmachinlearning/hls4ml-tutorial/hls4ml-0.7.0-vivado-2019.2:latest
```

## Companion material
We have prepared a set of slides with some introduction and more details on each of the exercises. Please find them [here](https://docs.google.com/presentation/d/1c4LvEc6yMByx2HJs8zUP5oxLtY6ACSizQdKvw5cg5Ck/edit?usp=sharing).
We have prepared a set of slides with some introduction and more details on each of the exercises.
Please find them [here](https://docs.google.com/presentation/d/1c4LvEc6yMByx2HJs8zUP5oxLtY6ACSizQdKvw5cg5Ck/edit?usp=sharing).


## Notebooks
```{tableofcontents}
```
35 changes: 35 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Book settings
# Learn more at https://jupyterbook.org/customize/config.html

title: hls4ml tutorial
author: Fast ML team
logo: images/hls4ml_logo.svg
favicon: images/hls4ml_logo.svg

# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
execute:
execute_notebooks: force
timeout: -1

# Define the name of the latex output file for PDF builds
latex:
latex_documents:
targetname: book.tex

# Information about where the book exists on the web
repository:
url: https://github.com/fastmachinelearning/hls4ml-tutorial # Online location of your book
path_to_book: "" # Optional path to your book, relative to the repository root
branch: main # Which branch of the repository should be used when creating links (optional)

# Add GitHub buttons to your book
# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository
html:
use_issues_button: true
use_repository_button: true
baseurl: "https://fastmachinlearning.org/hls4ml-tutorial/" # The base URL where your book will be hosted. Used for creating image previews and social links. e.g.: https://mypage.com/mybook/

launch_buttons:
binderhub_url: "https://mybinder.org"
colab_url: "https://colab.research.google.com"
10 changes: 10 additions & 0 deletions _toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
format: jb-book
root: README.md
chapters:
- file: part1_getting_started.ipynb
- file: part2_advanced_config.ipynb
- file: part3_compression.ipynb
- file: part4_quantization.ipynb
- file: part5_bdt.ipynb
- file: part6_cnns.ipynb
- file: part7_deployment.ipynb
Loading

0 comments on commit a7cbaaa

Please sign in to comment.