Follow these steps to set up the qml-anomaly-detection
project using Poetry:
-
Install Poetry:
Linux, macOS, Windows (WSL)
curl -sSL https://install.python-poetry.org | python3 -
Windows Powershell:
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
Note: On Windows you must add the pypoetry Scripts path to your
PATH
environment variable. Poetry by default is installed at%APPDATA%\pypoetry
on Windows. -
Configure Poetry to use project directory for Virtual Environment
poetry config virtualenvs.in-project true
-
Install required python version using
pyenv
Install pyenv:
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev curl https://pyenv.run/ | bash
For Windows, refer to the installation here at https://github.com/pyenv-win/pyenv-win?tab=readme-ov-file#installation
Install python 3.10:
pyenv install 3.10
-
Clone the qml-anomaly-detection repository
git clone https://github.com/Manoj-E-S/qml-anomaly-detection.git
-
Set python-version as the local(default) version for the project
cd qml-anomaly-detection pyenv local 3.10
-
Install Dependencies under the python-version specified in pyproject.toml:
cd qml-anomaly-detection poetry env use 3.10 poetry install
-
Intall
torch
dependency-
If cuda is available:
-
Check cuda version on your device
nvcc --version
-
Add corresponding
torch
repository source inpyproject.toml
(Although this will not be useful in installing pytorch (as it will be installed outside of the dependency management), doing this will be helpful for documentation purposes)[[tool.poetry.source]] name = "pytorch-gpu-<PLACEHOLDER>" url = "https://download.pytorch.org/whl/<PLACEHOLDER>" priority = "explicit"
-
Install
torch
in the venv, without updating pyproject.tomlcd qml-anomaly-detection poetry run pip install "torch==2.4.1+<PLACEHOLDER>" --index-url "https://download.pytorch.org/whl/<PLACEHOLDER>"
-
Note: Replace PLACEHOLDER with cuda-appropriate repository. Ex: cu121 (for cuda 12.1), cu111 (for cuda 11.1), etc.
-
-
If cuda is not available:
cd qml-anomaly-detection poetry run pip install "torch==2.4.1+cpu" --index-url "https://download.pytorch.org/whl/cpu/torch_stable.html"
-
-
Download the datasets
Run the following to install the datasets:
poetry shell python datasets/dataset_install.py
If for whatever reason running the above script does not properly install the datasets, Manually download them from here and replace the contents in the
datasets
directory to form the following structure:
/datasets/
├── ccfraud/
├── diabetes/
├── KDD Cup 1999/
└── README.md -
Setup pre-commit to ensure consistency
pre-commit install
-
Run Your Project:
poetry shell python <your_script>.py
We are good to go!
-
Create a New Poetry Project:
poetry new <project-name> cd <project-name>
-
Add Dependencies:
poetry add <package-1-name> <package-2-name> ... poetry add "<package-name>@<version-specifier>" --source <custom-source-name>
-
Add Group Dependencies (dev-dependencies, test-dependencies, etc):
poetry add --group <group-name> <package-1-name> <package-2-name> ...
-
Add New Sources:
poetry source add --priority=<default|primary|supplemental|explicit> <custom-source-name> <source-url>
-
Bring poetry.lock up-to-date with pyproject.toml (without updating dependencies):
poetry lock --no-update
-
To run the tests:
poetry run pytest -s
Or to run a specific test file:
poetry run pytest -s test_file.py
-
Activate the Virtual Environment:
poetry shell
-
Deactivate the Virtual Environment:
exit
For more details, refer to the Poetry documentation.