recommenders/SETUP.md

155 строки
5.4 KiB
Markdown
Исходник Обычный вид История

2018-10-18 20:27:24 +03:00
# Setup guide
2018-10-18 17:55:45 +03:00
2018-10-18 20:27:24 +03:00
In this guide we show how to setup all the dependencies to run the notebooks of this repo.
2018-11-01 10:43:26 +03:00
Three environments are supported to run the notebooks in the repo:
* Python CPU
* Python GPU
* PySpark
2018-10-18 17:55:45 +03:00
## Requirements
- [Anaconda Python 3.6](https://conda.io/miniconda.html)
2018-11-01 10:43:26 +03:00
- The Python library dependencies can be found in this [script](scripts/generate_conda_file.sh).
- Machine with Spark (optional for Python environment but mandatory for PySpark environment).
- Machine with GPU (optional but desirable for computing acceleration).
2018-10-18 17:55:45 +03:00
## Conda environments
As a pre-requisite, we may want to make sure that Conda is up-to-date:
conda update conda
We provided a script to [generate a conda file](scripts/generate_conda_file.sh), depending of the environment we want to use.
2018-10-18 17:55:45 +03:00
2018-11-01 10:43:26 +03:00
To install each environment, first we need to generate a conda yml file and then install the environment. We can specify the environment name with the input `-n`. In the following examples, we provide a name example.
2018-10-18 17:55:45 +03:00
### Python CPU environment
2018-11-01 10:43:26 +03:00
Assuming the repo is cloned as `Recommenders` in the local system, to install the Python CPU environment:
2018-10-18 17:55:45 +03:00
2018-10-18 19:16:21 +03:00
cd Recommenders
2018-10-18 17:55:45 +03:00
./scripts/generate_conda_file.sh
conda env create -n reco_bare -f conda_bare.yaml
### Python GPU environment
Assuming that you have a GPU machine, to install the Python GPU environment, which by default installs the CPU environment:
2018-10-18 19:16:21 +03:00
cd Recommenders
2018-10-18 17:55:45 +03:00
./scripts/generate_conda_file.sh --gpu
conda env create -n reco_gpu -f conda_gpu.yaml
### PySpark environment
To install the PySpark environment, which by default installs the CPU environment:
2018-10-18 19:16:21 +03:00
cd Recommenders
2018-10-18 17:55:45 +03:00
./scripts/generate_conda_file.sh --pyspark
2018-10-30 12:31:51 +03:00
conda env create -n reco_pyspark -f conda_pyspark.yaml
2018-10-18 17:55:45 +03:00
2018-11-01 10:43:26 +03:00
**NOTE** for this environment, we need to set the environment variables `PYSPARK_PYTHON` and `PYSPARK_DRIVER_PYTHON` to point to the conda python executable.
For setting these variables every time the environment is activated, we can follow the steps of this [guide](https://conda.io/docs/user-guide/tasks/manage-environments.html#macos-and-linux). Assuming that we have installed the environment in `/anaconda/envs/reco_pyspark`, we create the file `/anaconda/envs/reco_pyspark/activate.d/env_vars.sh` and add:
```bash
#!/bin/sh
export PYSPARK_PYTHON=/anaconda/envs/reco_pyspark/bin/python
export PYSPARK_DRIVER_PYTHON=/anaconda/envs/reco_pyspark/bin/python
```
2018-10-24 20:14:25 +03:00
This will export the variables every time we do `source activate reco_pyspark`. To unset these variables when we deactivate the environment, we create the file `/anaconda/envs/reco_pyspark/deactivate.d/env_vars.sh` and add:
```bash
#!/bin/sh
unset PYSPARK_PYTHON
unset PYSPARK_DRIVER_PYTHON
```
2018-10-18 17:55:45 +03:00
### All environments
To install all three environments:
2018-10-18 19:16:21 +03:00
cd Recommenders
2018-10-18 17:55:45 +03:00
./scripts/generate_conda_file.sh --gpu --pyspark
conda env create -n reco_full -f conda_full.yaml
### Register the conda environment in Jupyter notebook
We can register our created conda environment to appear as a kernel in the Jupyter notebooks.
2018-10-18 19:16:21 +03:00
source activate my_env_name
python -m ipykernel install --user --name my_env_name --display-name "Python (my_env_name)"
2018-11-08 13:01:16 +03:00
## Tests
This project use unit, smoke and integration tests with Python files and notebooks. For more information, see a [quick introduction to unit, smoke and integration tests](https://miguelgfierro.com/blog/2018/a-beginners-guide-to-python-testing/).
### Unit tests
Unit tests ensure that each class or function behaves as it should. Every time a developer makes a pull request to staging or master branch, a battery of unit tests is executed. To manually execute the unit tests in the different environments, first **make sure you are in the correct environment**.
For executing the Python unit tests for the utilities:
pytest tests/unit -m "not notebooks and not spark and not gpu"
For executing the Python unit tests for the notebooks:
pytest tests/unit -m "notebooks and not spark and not gpu"
For executing the Python GPU unit tests for the utilities:
pytest tests/unit -m "not notebooks and not spark and gpu"
For executing the Python GPU unit tests for the notebooks:
pytest tests/unit -m "notebooks and not spark and gpu"
For executing the PySpark unit tests for the utilities:
pytest tests/unit -m "not notebooks and spark and not gpu"
For executing the PySpark unit tests for the notebooks:
pytest tests/unit -m "notebooks and spark and not gpu"
### Smoke tests
Smoke tests make sure that the system works and are executed just before the integration tests every night.
For executing the Python smoke tests:
pytest tests/smoke -m "smoke and not spark and not gpu"
For executing the Python GPU smoke tests:
pytest tests/smoke -m "smoke and not spark and gpu"
For executing the PySpark smoke tests:
pytest tests/smoke -m "smoke and spark and not gpu"
### Integration tests
Integration tests make sure that the program results are acceptable
For executing the Python integration tests:
pytest tests/integration -m "integration and not spark and not gpu"
For executing the Python GPU integration tests:
pytest tests/integration -m "integration and not spark and gpu"
For executing the PySpark integration tests:
pytest tests/integration -m "integration and spark and not gpu"
## Troubleshooting
* We found that there could be problems if the Spark version of the machine is not the same as the one in the conda file. You will have to adapt the conda file to your machine.