diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..2599b5eaa --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,24 @@ +name: Install Environment and Run Tests + +on: + push: + branches: master + pull_request: + +jobs: + install-and-test: + permissions: + contents: read + runs-on: ubuntu-22.04 + defaults: + run: + working-directory: ./software + steps: + - name: Checkout the Squid repo + uses: actions/checkout@v4 + - name: Run the setup script for Ubuntu 22.04 + run: ./setup_22.04.sh + - name: Run the cuda setup script + run: ./setup_cuda_22.04.sh + - name: Run the tests + run: python3 -m pytest \ No newline at end of file diff --git a/software/README.md b/software/README.md index 4c31a84f8..cb2b08f9f 100644 --- a/software/README.md +++ b/software/README.md @@ -1,10 +1,18 @@ ## Setting up the environments Run the following script in terminal to clone the repo and set up the environment ``` -wget https://raw.githubusercontent.com/hongquanli/octopi-research/master/software/setup_22.04.sh +wget https://raw.githubusercontent.com/Cephla-Lab/Squid/master/software/setup_22.04.sh chmod +x setup_22.04.sh ./setup_22.04.sh ``` + +Then run this script to set up cuda +``` +wget https://raw.githubusercontent.com/Cephla-Lab/Squid/master/software/setup_cuda_22.04.sh +chmod +x setup_cuda_22.04.sh +./setup_cuda_22.04.sh +``` + Reboot the computer to finish the installation. ## Optional or Hardware-specific dependencies diff --git a/software/add_desktop_launcher_malaria.sh b/software/add_desktop_launcher_malaria.sh deleted file mode 100755 index 6b32f4f40..000000000 --- a/software/add_desktop_launcher_malaria.sh +++ /dev/null @@ -1,3 +0,0 @@ -cp octopi-research-malaria.desktop ~/.local/share/applications/ -chmod u+x ~/.local/share/applications/octopi-research-malaria.desktop -cp ~/.local/share/applications/octopi-research-malaria.desktop ~/Desktop/ \ No newline at end of file diff --git a/software/setup_22.04.sh b/software/setup_22.04.sh index b48894ab6..815624c4f 100755 --- a/software/setup_22.04.sh +++ b/software/setup_22.04.sh @@ -1,5 +1,19 @@ #!/bin/bash +set -eo pipefail +if [[ -n "$TRACE" ]]; then + echo "TRACE variable non-empty, turning on script tracing." + set -x +fi + +readonly SRC_ROOT="$HOME/Desktop" +mkdir -p "$SRC_ROOT" +readonly SQUID_REPO_HTTP="https://github.com/Cephla-Lab/Squid.git" +readonly SQUID_REPO_NAME="Squid" +readonly SQUID_SOFTWARE_ROOT="$SRC_ROOT/$SQUID_REPO_NAME/software" +readonly DAHENG_CAMERA_DRIVER_ROOT="$SQUID_SOFTWARE_ROOT/drivers and libraries/daheng camera/Galaxy_Linux-x86_Gige-U3_32bits-64bits_1.2.1911.9122" +readonly DAHENG_CAMERA_DRIVER_API_ROOT="$SQUID_SOFTWARE_ROOT/drivers and libraries/daheng camera/Galaxy_Linux_Python_1.0.1905.9081/api" +readonly TOUPCAM_UDEV_RULE_PATH="$SQUID_SOFTWARE_ROOT/drivers and libraries/toupcam/linux/udev/99-toupcam.rules" # update sudo apt update @@ -10,24 +24,24 @@ sudo apt install python3-pyqt5.qtsvg # clone the repo sudo apt-get install git -y -cd ~/Desktop -git clone https://github.com/hongquanli/octopi-research.git -cd octopi-research/software +cd "$SRC_ROOT" +git clone "$SQUID_REPO_HTTP" "$SQUID_REPO_NAME" +cd "$SQUID_SOFTWARE_ROOT" mkdir cache # install libraries pip3 install qtpy pyserial pandas imageio crc==1.3.0 lxml numpy tifffile scipy napari pip3 install opencv-python-headless opencv-contrib-python-headless -pip3 install napari[all] scikit-image dask_image ome_zarr aicsimageio basicpy +pip3 install napari[all] scikit-image dask_image ome_zarr aicsimageio basicpy pytest # install camera drivers -cd ~/Desktop/octopi-research/software/drivers\ and\ libraries/daheng\ camera/Galaxy_Linux-x86_Gige-U3_32bits-64bits_1.2.1911.9122 +cd "$DAHENG_CAMERA_DRIVER_ROOT" ./Galaxy_camera.run -cd ~/Desktop/octopi-research/software/drivers\ and\ libraries/daheng\ camera/Galaxy_Linux_Python_1.0.1905.9081/api +cd "$DAHENG_CAMERA_DRIVER_API_ROOT" python3 setup.py build sudo python3 setup.py install -cd ~/Desktop/octopi-research/software -sudo cp drivers\ and\ libraries/toupcam/linux/udev/99-toupcam.rules /etc/udev/rules.d +cd "$SQUID_SOFTWARE_ROOT" +sudo cp "$TOUPCAM_UDEV_RULE_PATH" /etc/udev/rules.d # enable access to serial ports without sudo sudo usermod -aG dialout $USER diff --git a/software/setup_cuda_22.04.sh b/software/setup_cuda_22.04.sh old mode 100644 new mode 100755 diff --git a/software/setup_octopi.sh b/software/setup_octopi.sh deleted file mode 100755 index b7bb293de..000000000 --- a/software/setup_octopi.sh +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/env bash -# Setup script for octopi-software environment -# ------------------------------------------------------- -# Usage -# ------------------------------------------------------- -# brew install git (MacOS) -# sudo apt-get install git (Linux) -# -# git clone git@github.com:sohamazing/octopi-software.git -# cd octopi-research/software -# chmod +x setup_octopi.sh -# ./setup_octopi.sh -# ./setup_octopi.sh --INSTALL_CUDA=True (optional) -# -# conda activate octopi -# python main.py --simulation -# ------------------------------------------------------- -set -eo pipefail - -if [[ -n "$TRACE" ]]; then - echo "TRACE variable non-empty, turning on script tracing." - set -x -fi - -# Detect Operating System -OS="$(uname -s)" -case "${OS}" in - Linux*) os=Linux;; - Darwin*) os=MacOS;; - *) os="UNKNOWN:${OS}" -esac - -# Function to compare version numbers -version() { - echo "$@" | awk -F. '{ printf("%d%03d%03d", $1,$2,$3); }' -} - -# Determines and installs the best NVIDIA driver, with checks for specific versions -install_best_nvidia_driver() { - if [ "${os}" == "Linux" ]; then - echo "Checking current NVIDIA driver version..." - local current_driver_version=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader | cut -d '.' -f1 || echo "0") - if [[ "$current_driver_version" -eq 550 || "$current_driver_version" -eq 535 || "$current_driver_version" -eq 545 ]]; then - echo "Compatible NVIDIA driver version $current_driver_version is already installed." - return - fi - - echo "No compatible NVIDIA driver version found. Determining the best driver for installation..." - # This example assumes ubuntu-drivers command is available and the system is Ubuntu - local recommended_driver=$(ubuntu-drivers devices | grep 'recommended' | grep 'nvidia-driver' | awk '{print $3}') - if [ -n "$recommended_driver" ]; then - echo "Purging existing NVIDIA drivers..." - sudo apt-get purge -y nvidia-* - echo "Installing recommended NVIDIA driver: $recommended_driver" - sudo apt-get install -y "$recommended_driver" - else - echo "No recommended NVIDIA driver found by `ubuntu-drivers devices`. Considering manual installation." - # Manual installation of a driver if needed - # sudo apt-get install -y nvidia-driver-550 ### uncomment to install version 550 manually - fi - else - echo "NVIDIA driver installation is not applicable on ${os}. Skipping..." - fi -} - -# Installs CUDA Toolkit if not already installed after ensuring the NVIDIA driver is correctly installed -install_cuda_toolkit() { - if [ "${os}" == "Linux" ]; then - if dpkg -l | grep -q cuda-12; then - echo "CUDA 12.x is already installed." - return - else - echo "Installing CUDA 12.x..." - if [ -f cuda-keyring_*.deb ]; then - echo "Removing existing CUDA keyring package..." - rm cuda-keyring_*.deb - fi - if dpkg -l | grep -q cuda-keyring; then - echo "Removing previously installed CUDA keyring..." - sudo dpkg --purge cuda-keyring - fi - wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb - sudo dpkg -i cuda-keyring_1.1-1_all.deb - rm cuda-keyring_1.1-1_all.deb - sudo apt-get install -y cuda-12 - echo "CUDA 12.x installation completed." - fi - else - echo "CUDA Toolkit installation is not applicable on ${os}. Skipping..." - fi -} - -# Combines the steps to install CUDA and NVIDIA drivers -install_cuda_nvidia_linux() { - if [ "${os}" == "Linux" ]; then - # Check for Ubuntu 22.04 or adapt for other distributions - if grep -q Ubuntu /etc/os-release; then - if grep -q "22.04" /etc/os-release; then - sudo apt-get update - install_best_nvidia_driver - install_cuda_toolkit - else - echo "This script is designed for Ubuntu 22.04. You are running a different version." - fi - else - echo "This script is designed for Ubuntu 22.04. Skipping CUDA and NVIDIA driver installation." - fi - else - echo "CUDA and NVIDIA driver installation is not applicable on ${os}. Skipping..." - fi -} - - -# Creates and activates a Conda environment if it doesn't already exist -create_conda_env() { - local env_name="octopi" - local python_version="3.10" - - if ! which conda; then - echo "No conda found, please install conda then re-run." - exit 1 - fi - - if conda info --envs | grep -qw "$env_name"; then - echo "Conda environment '$env_name' already exists. Activating it..." - else - echo "Creating conda environment '$env_name' with Python $python_version..." - conda create -y -n "$env_name" python="$python_version" - fi - eval "$(conda shell.bash hook)" - conda activate "$env_name" - echo "Conda environment '$env_name' activated." -} - -# Installs required Python packages excluding PyTorch -install_python_packages() { - echo "Installing Python packages..." - pip install -U pip setuptools wheel numpy pandas scikit-learn \ - PyQt5 pyqtgraph qtpy pyserial lxml==4.9.4 crc==1.3.0 \ - opencv-python-headless opencv-contrib-python-headless \ - dask_image imageio aicsimageio tifffile \ - napari[all] napari-ome-zarr basicpy pycparser -} - -# Installs PyTorch with CUDA support for Linux using Conda, updates JAX to a specific version based on the OS -install_conditional_packages() { - echo "Installing conditional packages..." - if [ "${os}" == "Linux" ]; then - pip install cuda-python cupy-cuda12x - conda install -y pytorch torchvision torchaudio cuda-version=12.1 -c pytorch -c nvidia - pip install 'jax[cuda12_pip]==0.4.23' --find-links https://storage.googleapis.com/jax-releases/jax_cuda_releases.html - elif [ "${os}" == "MacOS" ]; then - pip install torch torchvision torchaudio - pip install jax[cpu]==0.4.23 - fi -} - -# Installs the Galaxy Camera software -install_galaxy_camera() { - echo "Installing Galaxy Camera software..." - cd drivers\ and\ libraries/daheng\ camera/Galaxy_Linux-x86_Gige-U3_32bits-64bits_1.2.1911.9122/ - ./Galaxy_camera.run - cd ../Galaxy_Linux_Python_1.0.1905.9081/api - python3 setup.py build - python3 setup.py install -} - -# Main script execution -if [ ! -d "cache" ]; then - echo "Creating cache directory..." - mkdir cache -else - echo "Cache directory already exists." -fi -create_conda_env -if [ "$INSTALL_CUDA" == "True" ]; then - install_cuda_nvidia_linux # Check and install CUDA/NVIDIA drivers if necessary -fi -install_python_packages -install_conditional_packages # Install PyTorch, JAX, and related CUDA packages -install_galaxy_camera -echo "Installation completed successfully." \ No newline at end of file diff --git a/software/list_controllers.py b/software/tools/list_controllers.py similarity index 100% rename from software/list_controllers.py rename to software/tools/list_controllers.py