Skip to content

Manoj-E-S/qml-anomaly-detection

Repository files navigation

Project Setup

Follow these steps to set up the qml-anomaly-detection project using Poetry:

  1. 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.

  2. Configure Poetry to use project directory for Virtual Environment

    poetry config virtualenvs.in-project true
  3. 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
  4. Clone the qml-anomaly-detection repository

    git clone https://github.com/Manoj-E-S/qml-anomaly-detection.git
  5. Set python-version as the local(default) version for the project

    cd qml-anomaly-detection
    pyenv local 3.10
  6. Install Dependencies under the python-version specified in pyproject.toml:

    cd qml-anomaly-detection
    poetry env use 3.10
    poetry install
  7. Intall torch dependency

    1. If cuda is available:

      • Check cuda version on your device

        nvcc --version
      • Add corresponding torch repository source in pyproject.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.toml

        cd 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.

    2. 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"
  8. 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

  9. Setup pre-commit to ensure consistency

    pre-commit install
    
  10. Run Your Project:

    poetry shell
    python <your_script>.py

We are good to go!

Some useful Poetry Commands

  1. Create a New Poetry Project:

    poetry new <project-name>
    cd <project-name>
  2. Add Dependencies:

    poetry add <package-1-name> <package-2-name> ...
    poetry add "<package-name>@<version-specifier>" --source <custom-source-name>
  3. Add Group Dependencies (dev-dependencies, test-dependencies, etc):

    poetry add --group <group-name> <package-1-name> <package-2-name> ...
  4. Add New Sources:

    poetry source add --priority=<default|primary|supplemental|explicit> <custom-source-name> <source-url>
  5. Bring poetry.lock up-to-date with pyproject.toml (without updating dependencies):

    poetry lock --no-update
  6. To run the tests:

    poetry run pytest -s
    

    Or to run a specific test file:

    poetry run pytest -s test_file.py
    
  7. Activate the Virtual Environment:

    poetry shell
  8. Deactivate the Virtual Environment:

    exit

For more details, refer to the Poetry documentation.

About

Explore qiskit for quantum machine learning

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •