From 9ec41095d76d004fefa52c2607965b80af0d84fc Mon Sep 17 00:00:00 2001 From: Michael Harms Date: Fri, 20 Mar 2026 11:04:22 -0700 Subject: [PATCH 1/2] chasing down raxml-ng segfault --- dependencies/compile-raxml-ng.sh | 2 +- src/topiary/_private/interface.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dependencies/compile-raxml-ng.sh b/dependencies/compile-raxml-ng.sh index 7311686..c5cc958 100755 --- a/dependencies/compile-raxml-ng.sh +++ b/dependencies/compile-raxml-ng.sh @@ -21,7 +21,7 @@ git submodule update --init --recursive # Build binary mkdir build cd build -cmake -DTERRAPHAST_ARCH_NATIVE=OFF -DENABLE_RAXML_SIMD=OFF -DENABLE_PLLMOD_SIMD=OFF .. +cmake -DTERRAPHAST_ARCH_NATIVE=OFF -DENABLE_RAXML_SIMD=OFF -DENABLE_PLLMOD_SIMD=OFF -DENABLE_SSE=OFF -DENABLE_AVX=OFF -DENABLE_AVX2=OFF .. make -j 4 # Copy binary to final location diff --git a/src/topiary/_private/interface.py b/src/topiary/_private/interface.py index 607a73c..127a1ae 100644 --- a/src/topiary/_private/interface.py +++ b/src/topiary/_private/interface.py @@ -11,6 +11,11 @@ import multiprocessing as mp import functools +try: + import resource +except ImportError: + resource = None + from topiary._private.mpi import get_mpi_env class WrappedFunctionException(Exception): @@ -265,6 +270,15 @@ def launch(cmd, If the command terminates unexpectedly. """ + # Attempt to increase stack size for child processes to avoid segfaults + # on large calculations (consistent with RAxML-NG recommendations). + if resource is not None: + try: + soft, hard = resource.getrlimit(resource.RLIMIT_STACK) + resource.setrlimit(resource.RLIMIT_STACK, (hard, hard)) + except (resource.error, ValueError): + pass + # Go into working directory cwd = os.getcwd() os.chdir(run_directory) From 2aa8df4717156c5c7fe0d66580fb7e6b756cd868 Mon Sep 17 00:00:00 2001 From: Michael Harms Date: Fri, 20 Mar 2026 14:20:28 -0700 Subject: [PATCH 2/2] setting up install scripts for colab --- dependencies/compile-generax.sh | 19 +++++ dependencies/compile-raxml-ng.sh | 19 +++++ docs/badges/coverage-badge.svg | 2 +- docs/badges/ghwf.svg | 14 ++-- install.sh | 129 +++++++++++++++++++++---------- 5 files changed, 136 insertions(+), 47 deletions(-) diff --git a/dependencies/compile-generax.sh b/dependencies/compile-generax.sh index de3d00c..f4d0aee 100755 --- a/dependencies/compile-generax.sh +++ b/dependencies/compile-generax.sh @@ -27,6 +27,25 @@ if [ -z "$CONDA_PREFIX" ]; then exit 1 fi +KEEP_EXISTING=0 +while [[ $# -gt 0 ]]; do + case $1 in + --keep-existing) + KEEP_EXISTING=1 + shift ;; + *) + shift ;; + esac +done + +# Check if binary already exists in final location +if [ $KEEP_EXISTING -eq 1 ]; then + if [ -f "$CONDA_PREFIX/bin/generax" ]; then + echo "Using existing generax binary in \$CONDA_PREFIX/bin/ (skip compile)" + exit 0 + fi +fi + # Clean up environment rm -rf generax diff --git a/dependencies/compile-raxml-ng.sh b/dependencies/compile-raxml-ng.sh index c5cc958..286b1d1 100755 --- a/dependencies/compile-raxml-ng.sh +++ b/dependencies/compile-raxml-ng.sh @@ -10,6 +10,25 @@ if [ -z "$CONDA_PREFIX" ]; then exit 1 fi +KEEP_EXISTING=0 +while [[ $# -gt 0 ]]; do + case $1 in + --keep-existing) + KEEP_EXISTING=1 + shift ;; + *) + shift ;; + esac +done + +# Check if binary already exists in final location +if [ $KEEP_EXISTING -eq 1 ]; then + if [ -f "$CONDA_PREFIX/bin/raxml-ng" ]; then + echo "Using existing raxml-ng binary in \$CONDA_PREFIX/bin/ (skip compile)" + exit 0 + fi +fi + # Clean up environment rm -rf raxml-ng diff --git a/docs/badges/coverage-badge.svg b/docs/badges/coverage-badge.svg index 85e3f63..df4d225 100644 --- a/docs/badges/coverage-badge.svg +++ b/docs/badges/coverage-badge.svg @@ -1 +1 @@ -coverage: 93.42%coverage93.42% \ No newline at end of file +coverage: 93.41%coverage93.41% \ No newline at end of file diff --git a/docs/badges/ghwf.svg b/docs/badges/ghwf.svg index f8a69e1..632466a 100644 --- a/docs/badges/ghwf.svg +++ b/docs/badges/ghwf.svg @@ -1,13 +1,13 @@ - - topiary - no status + + topiary - passing - - + + @@ -21,12 +21,12 @@ - + - no status + passing diff --git a/install.sh b/install.sh index ca67513..dbd6004 100755 --- a/install.sh +++ b/install.sh @@ -7,62 +7,104 @@ if [ $? -ne 0 ]; then exit 1 fi -# Default environment name +# Default values ENV_NAME="topiary" +NCBI_KEY="" +is_cluster="n" +overwrite="ignore" +NON_INTERACTIVE=0 +KEEP_EXISTING=0 + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + -n|--name) + ENV_NAME="$2" + NON_INTERACTIVE=1 + shift; shift ;; + -k|--ncbi-key) + NCBI_KEY="$2" + NON_INTERACTIVE=1 + shift; shift ;; + --no-cluster) + is_cluster="n" + NON_INTERACTIVE=1 + shift ;; + -y|--yes) + overwrite="y" + NON_INTERACTIVE=1 + shift ;; + --keep-existing) + KEEP_EXISTING=1 + NON_INTERACTIVE=1 + shift ;; + *) + shift ;; + esac +done # 1. Ask for environment name -echo -read -p "Enter conda environment name [$ENV_NAME]: " input_env -if [ ! -z "$input_env" ]; then - ENV_NAME=$input_env +if [ $NON_INTERACTIVE -eq 0 ]; then + echo + read -p "Enter conda environment name [$ENV_NAME]: " input_env + if [ ! -z "$input_env" ]; then + ENV_NAME=$input_env + fi fi # Check if environment already exists +ENV_EXISTS=0 conda env list | grep -q "^$ENV_NAME " if [ $? -eq 0 ]; then - echo - read -p "Conda environment '$ENV_NAME' already exists. Overwrite? (y/N): " overwrite - if [[ ! "$overwrite" =~ ^[Yy]$ ]]; then - echo "Installation cancelled to avoid overwriting existing environment." - exit 0 + ENV_EXISTS=1 + if [ $NON_INTERACTIVE -eq 0 ]; then + echo + read -p "Conda environment '$ENV_NAME' already exists. Overwrite? (y/N): " input_overwrite + if [[ "$input_overwrite" =~ ^[Yy]$ ]]; then + overwrite="y" + fi fi -else - overwrite="ignore" fi # 2. Ask for NCBI API key -echo -echo "--------------------------------------------------------------------------------" -echo "An NCBI key allows users to make more requests against the NCBI servers" -echo "when running BLAST etc. Using one is highly recommended to prevent " -echo "throttling. You may obtain one for free from the NCBI website." -echo "https://ncbiinsights.ncbi.nlm.nih.gov/2017/11/02/new-api-keys-for-the-e-utilities/" -echo "--------------------------------------------------------------------------------" -read -p "Enter NCBI API key (optional, press Enter to skip): " NCBI_KEY - -# 3. Cluster installation prompt -echo -read -p "Are you installing on a cluster? (y/N): " is_cluster -if [[ "$is_cluster" =~ ^[Yy]$ ]]; then +if [ $NON_INTERACTIVE -eq 0 ]; then + echo echo "--------------------------------------------------------------------------------" - echo "To run topiary on a cluster, you need to make sure that the generax and raxml-ng" - echo "components are compiled using your cluster's compilers and MPI. You will need" - echo "to modify the 'dependencies/compile-generax.sh' script to do so. More details" - echo "are at the top of the script. If you have already modified this script, please" - echo "proceed with the installation." + echo "An NCBI key allows users to make more requests against the NCBI servers" + echo "when running BLAST etc. Using one is highly recommended to prevent " + echo "throttling. You may obtain one for free from the NCBI website." + echo "https://ncbiinsights.ncbi.nlm.nih.gov/2017/11/02/new-api-keys-for-the-e-utilities/" echo "--------------------------------------------------------------------------------" - read -p "Do you want to proceed with the installation? (Y/n): " is_cluster_proceed - if [[ "$is_cluster_proceed" =~ ^[Nn]$ ]]; then - echo "Installation cancelled." - exit 0 + read -p "Enter NCBI API key (optional, press Enter to skip): " NCBI_KEY +fi + +# 3. Cluster installation prompt +if [ $NON_INTERACTIVE -eq 0 ]; then + echo + read -p "Are you installing on a cluster? (y/N): " input_cluster + if [[ "$input_cluster" =~ ^[Yy]$ ]]; then + is_cluster="y" + echo "--------------------------------------------------------------------------------" + echo "To run topiary on a cluster, you need to make sure that the generax and raxml-ng" + echo "components are compiled using your cluster's compilers and MPI. You will need" + echo "to modify the 'dependencies/compile-generax.sh' script to do so. More details" + echo "are at the top of the script. If you have already modified this script, please" + echo "proceed with the installation." + echo "--------------------------------------------------------------------------------" + read -p "Do you want to proceed with the installation? (Y/n): " is_cluster_proceed + if [[ "$is_cluster_proceed" =~ ^[Nn]$ ]]; then + echo "Installation cancelled." + exit 0 + fi fi fi # Overwrite if we have to if [[ "$overwrite" =~ ^[Yy]$ ]]; then echo "Removing existing environment '$ENV_NAME'..." - conda deactivate + conda deactivate > /dev/null 2>&1 conda env remove -n $ENV_NAME -y + ENV_EXISTS=0 fi # wipe local builds @@ -72,8 +114,13 @@ for x in `find . -iname "__pycache__"`; do rm -rf $x; done # Nuke conda environment (now handled by overwrite check above if it exists) conda deactivate > /dev/null 2>&1 -# Create new conda environment -conda env create -f environment.yml -n $ENV_NAME -y +# Create/Update conda environment +if [ $ENV_EXISTS -eq 0 ]; then + conda env create -f environment.yml -n $ENV_NAME -y +else + echo "Updating existing environment '$ENV_NAME'..." + conda env update -f environment.yml -n $ENV_NAME --prune +fi # Set NCBI API key if provided if [ ! -z "$NCBI_KEY" ]; then @@ -86,8 +133,12 @@ conda run -n $ENV_NAME pip install coverage flake8 pytest genbadge[tests] pytest # compile raxml and generax cd dependencies -conda run -n $ENV_NAME bash compile-generax.sh -conda run -n $ENV_NAME bash compile-raxml-ng.sh +args="" +if [ $KEEP_EXISTING -eq 1 ]; then + args="--keep-existing" +fi +conda run -n $ENV_NAME bash compile-generax.sh $args +conda run -n $ENV_NAME bash compile-raxml-ng.sh $args #return to start cd ..