Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanFauvel committed Oct 21, 2022
0 parents commit 23e98e2
Show file tree
Hide file tree
Showing 12 changed files with 852 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
username=[email protected]
submission_name = 'TristanF_Submission_1'
password = "CWFKDLx33xwdnKtQRs"
project_id = "syn41016074"
SYNAPSE_AUTH_TOKEN ="eyJ0eXAiOiJKV1QiLCJraWQiOiJXN05OOldMSlQ6SjVSSzpMN1RMOlQ3TDc6M1ZYNjpKRU9VOjY0NFI6VTNJWDo1S1oyOjdaQ0s6RlBUSCIsImFsZyI6IlJTMjU2In0.eyJhY2Nlc3MiOnsic2NvcGUiOlsidmlldyIsImRvd25sb2FkIiwibW9kaWZ5Il0sIm9pZGNfY2xhaW1zIjp7fX0sInRva2VuX3R5cGUiOiJQRVJTT05BTF9BQ0NFU1NfVE9LRU4iLCJpc3MiOiJodHRwczovL3JlcG8tcHJvZC00MjYtMS5wcm9kLnNhZ2ViYXNlLm9yZy9hdXRoL3YxIiwiYXVkIjoiMCIsIm5iZiI6MTY2NjI2ODk0NSwiaWF0IjoxNjY2MjY4OTQ1LCJqdGkiOiIyMTU4Iiwic3ViIjoiMzQwMTIyMyJ9.Dv861iWmvJPbz85hrr0Tt67HixicgJG7gun5hrhhRsFabkR4auFRJuUSBaosuZqnQFzJcuLaAhbf-ZSIglss-TUcupRdM0zZQj8oDVvdLc0soUYznxttiUb5oigH0WsTmZT9Pab-Hqx8veEvKzIzKfxc_Xnlfqtxrq3Fg3xGGM-5TPxhgFTWycMmWtGci0wfuv1O0_LpsOlB7X5EKKOc6nEW3ijfrJXVIZjjDAgr1IVhusZIBY2pSTexXZW3RPW_tkAPl6tL8q7Vdhyb4p6hPopgp7A-4G-bqtAbudNihmd14PHBmtAXinCIOSBB8fMMUlhSWGmCvS5bA_c_A8dqyg"
root_folder = "/home/tristan/Desktop/DreamHF"
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env export-ignore
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.csv
*.odt
*.sif
.Rproj.user
R_baseline/
TODO.md
config.py
*.zip
*.mp4
References/
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
init:
pip install -r requirements.txt

test:
nosetests tests
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Template-Python-Singularity
## A template to build executable Singularity images in Python projects

### Objective

This repo contains a template to create a Python app that will run in an executable Singularity image. A Singularity containers can typically be used in data science projects to provide transparency and support of reproducibility.

### Content

* `singularity/`: singularity container
* singularity_test
* `utils/` : utility scripts (to make submissions, etc)

* `src/`: models
* `data/` : input data
* `output/` : where code output is stored

### Instruction to build the singularity container from the recipe.txt

To create an executable singularity container (which contains the code in /src), run :

```bash
./utils/build_container.sh
```

This will create a container container.sif in /singularity.
To test the executable singularity container, run :

```bash
./utils/test_container.sh
```

This will output the results in singularity/test_singularity/output.

### Instructions to run the model

The singularity container container.sif is executable, you can reproduce the results by running:

```bash
singularity run ./singularity/container.sif <Argument for input path>
```

Note: `<Argument for input path> ` is optional, default is ./


Note that container.sif should be in the same folder as /training and /test.
The prediction scores on test dataset are saved in `./output/scores.csv`.
### Instructions to run a custom model in the same environment

To run a model locally on synthetic data in the container environement, activate the singularity container in Terminal using:

```bash
singularity shell ./singularity/container.sif
```

This will allow you to have an environment (`Singularity>`) to run the model without installing any additional package.
In order to run the model, run the following command :

```bash
Singularity> python3 src/model.py <Argument for input path>
```

For example, on my computer, when my cwd is the DreamHF folder, I run :

```bash
Singularity> python3 src/model.py ./
```

This command can also be used to run the singularity without accessing the singularity shell:

```bash
singularity exec container.sif python3 src/model.py <Argument for input path>
```


### License

This software is distributed under the GNU GENERAL PUBLIC LICENSE. Please refer to the file LICENCE.txt included for details.
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
numpy==1.21.5
pandas==1.3.5
python-dotenv==0.21.0
scikit_learn==1.0.2
scikit_survival==0.17.2
scipy==1.7.3
synapseclient==2.7.0
40 changes: 40 additions & 0 deletions singularity/recipe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Bootstrap: docker
FROM: python:latest

%labels
Version v1.0

%help
Singularity image for DreamChallenge

%setup
mkdir -p ${SINGULARITY_ROOTFS}/src

%files
./src/* /src

%post
## Install the required python packages
pip install numpy==1.21.5
pip install pandas==1.3.5
pip install scikit_survival==0.17.2
pip install scipy==1.7.3
pip install python-dotenv==0.21.0
pip install synapseclient==2.7.0

%runscript
if [ $# -ne 1 ]; then
echo "No input directory provided, default is ./"
STR=$(pwd)
python3 ${SINGULARITY_ROOTFS}/src/model.py "${STR}"
else
python3 ${SINGULARITY_ROOTFS}/src/model.py $1
fi

# Update apt-get
#RUN apt-get update \
# && apt-get install -y --no-install-recommends apt-utils \
# && apt-get install -y --no-install-recommends \
# \
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/*
6 changes: 6 additions & 0 deletions singularity/test_singularity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Heart Failure Prediction : Microbiome
## FINRISK DREAM Challenge 2022

Author : Tristan Fauvel

### This folder contains the necessary tools to test the execution of the submitted singularity container.
6 changes: 6 additions & 0 deletions utils/.env -sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
username = "my_username"
submission_name = "my_submission_name"
password = "azerty123"
project_id = "syn1234"
SYNAPSE_AUTH_TOKEN ="TOKEN"
root_folder = "/home/tristan/Desktop/DreamHF/"
5 changes: 5 additions & 0 deletions utils/build_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/bash
echo "Building the singularity container ./singularity/container.sif from ./singularity/recipe.txt"
sudo singularity build --force ./singularity/container.sif ./singularity/recipe.txt
echo "Copying ./singularity/container.sif to ./singularity/test_singularity"
cp ./singularity/container.sif ./singularity/test_singularity
14 changes: 14 additions & 0 deletions utils/test_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash
echo "Run container.sif, check outputs in ./singularity/test_singularity/output"
singularity run ./singularity/test_singularity/container.sif ./singularity/test_singularity
read -p "Proceed to the second test? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
singularity run ./singularity/test_singularity/container.sif
fi





0 comments on commit 23e98e2

Please sign in to comment.