Skip to content

Commit

Permalink
Initial commit of personalized algorithm template
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvanb committed Jul 26, 2024
0 parents commit 916e42a
Show file tree
Hide file tree
Showing 25 changed files with 869 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# DO NOT MODIFY THIS FILE MANUALLY.
# This file contains the answers to the questions asked by the
# v6-algorithm-template-creator (using the Copier package). The answers will
# be updated if you re-run the template creator. Also, the answers in this file
# may be used to submit your algorithm to a vantage6 algorithm store.
_commit: 4.3.4
_src_path: gh:vantage6/v6-algorithm-template.git
advanced: true
algorithm_description: Create a summary of the data (mean, range, variance, length,
...)
algorithm_name: v6-summary-py
author: B. van Beusekom, H. Alradhi, F.C. Martin
central_args:
- columns
- organizations_to_include
central_function_client: true
central_function_data: false
central_function_name: summary
copyright: IKNL, 2024
docker_image: harbor2.vantage6.ai/algorithms/v6-summary-py
docker_registry: harbor2.vantage6.ai
has_central_function: true
has_docs: true
has_gh_pipeline: true
has_partial_function: true
open_source_license: mit
partial_args:
- columns
partial_function_client: false
partial_function_data: true
partial_function_name: summary_per_data_station
partial_function_number_databases: 1
private_registry: true
project_name: v6-summary-py
use_vpn: false
28 changes: 28 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Create Release

on:
push:
branches:
- main

jobs:
create-docker-image:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Login to Docker registry
uses: docker/login-action@v3
with:
registry: harbor2.vantage6.ai
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Run Makefile Rule
run: docker build -t harbor2.vantage6.ai/algorithms/v6-summary-py .

- name: Push Docker image
run: |
docker push harbor2.vantage6.ai/algorithms/v6-summary-py
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.vscode/
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# basic python3 image as base
FROM harbor2.vantage6.ai/infrastructure/algorithm-base

# This is a placeholder that should be overloaded by invoking
# docker build with '--build-arg PKG_NAME=...'
ARG PKG_NAME="v6-summary-py"

# install federated algorithm
COPY . /app
RUN pip install /app


# Set environment variable to make name of the package available within the
# docker image.
ENV PKG_NAME=${PKG_NAME}

# Tell docker to execute `wrap_algorithm()` when the image is run. This function
# will ensure that the algorithm method is called properly.
CMD python -c "from vantage6.algorithm.tools.wrap import wrap_algorithm; wrap_algorithm()"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

# v6-summary-py

Create a summary of the data (mean, range, variance, length, ...)

This algorithm is designed to be run with the [vantage6](https://vantage6.ai)
infrastructure for distributed analysis and learning.

The base code for this algorithm has been created via the
[v6-algorithm-template](https://github.com/vantage6/v6-algorithm-template)
template generator.

### Checklist

Note that the template generator does not create a completely ready-to-use
algorithm yet. There are still a number of things you have to do yourself.
Please ensure to execute the following steps. The steps are also indicated with
TODO statements in the generated code - so you can also simply search the
code for TODO instead of following the checklist below.

- [ ] Include a URL to your code repository in setup.py.
- [ ] Implement your algorithm functions.
- [ ] You are free to add more arguments to the functions. Be sure to add them
*after* the `client` and dataframe arguments.
- [ ] When adding new arguments, if you run the `test/test.py` script, be sure
to include values for these arguments in the `client.task.create()` calls
that are available there.
- [ ] If you are using Python packages that are not in the standard library, add
them to the `requirements.txt` and `setup.py` file.
- [ ] Fill in the documentation template. This will help others to understand your
algorithm, be able to use it safely, and to contribute to it.
- [ ] If you want to submit your algorithm to a vantage6 algorithm store, be sure
to fill in everything in ``algorithm_store.json`` (and be sure to update
it if you change function names, arguments, etc.).
- [ ] Create a ``DOCKER_USER`` and ``DOCKER_PASSWORD`` secret in the GitHub repository
settings. This will be used to push the Docker image to the registry in the github
pipeline.
- [ ] Finally, remove this checklist section to keep the README clean.

### Dockerizing your algorithm

To finally run your algorithm on the vantage6 infrastructure, you need to
create a Docker image of your algorithm.

#### Automatically

The easiest way to create a Docker image is to use the GitHub Actions pipeline to
automatically build and push the Docker image. All that you need to do is push a
commit to the ``main`` branch.

#### Manually

A Docker image can be created by executing the following command in the root of your
algorithm directory:

```bash
docker build -t [my_docker_image_name] .
```

where you should provide a sensible value for the Docker image name. The
`docker build` command will create a Docker image that contains your algorithm.
You can create an additional tag for it by running

```bash
docker tag [my_docker_image_name] [another_image_name]
```

This way, you can e.g. do
`docker tag local_average_algorithm harbor2.vantage6.ai/algorithms/average` to
make the algorithm available on a remote Docker registry (in this case
`harbor2.vantage6.ai`).

Finally, you need to push the image to the Docker registry. This can be done
by running

```bash
docker push [my_docker_image_name]
```

Note that you need to be logged in to the Docker registry before you can push
the image. You can do this by running `docker login` and providing your
credentials. Check [this page](https://docs.docker.com/get-started/04_sharing_app/)
For more details on sharing images on Docker Hub. If you are using a different
Docker registry, check the documentation of that registry and be sure that you
have sufficient permissions.
43 changes: 43 additions & 0 deletions algorithm_store.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "v6-summary-py",
"image": "harbor2.vantage6.ai/algorithms/v6-summary-py",
"vantage6_version": "4.3",
"partitioning": "horizontal",
"functions": [
{
"name": "summary",
"description": "Create a summary of the data (mean, range, variance, length, ...)",
"type": "central",
"databases": [],
"arguments": [
{
"name": "columns",
"type": "",
"description": ""
},
{
"name": "organizations_to_include",
"type": "",
"description": ""
}
]
},
{
"name": "summary_per_data_station",
"description": "",
"type": "federated",
"databases": [
{
"name": "Database 1"
}
],
"arguments": [
{
"name": "columns",
"type": "",
"description": ""
}
]
}
]
}
23 changes: 23 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

livehtml:
sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
19 changes: 19 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Documentation of v6-summary-py

### How to run this documentation locally

```bash

# Install the required packages
pip install -r requirements.txt

# Build the documentation
make html

# Run a local service to view the documentation that updates when you make changes
make livehtml
```

### How to publish the documentation

View the instructions from [Sphinx](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/read-the-docs.html)
Loading

0 comments on commit 916e42a

Please sign in to comment.