2 Set up guide for Anaconda virtual env
Masataro Asai edited this page 2022-03-23 14:58:54 -04:00

Preface

This document is written for people who want to ship Roswell-based environment with anaconda, a widely popular virtual-environment setup tool. While the tool is mainly targeting python audience, the tool can install non-python dependencies, such as compilers (e.g. Clang), C-based libraries, or CUDA libraries. It is a popular vessel for distributing reproducible environment in (computer) science community, mainly in Artificial Intelligence. This page would be thus useful for combining python-based deep-learning libraries with CL-based symbol processing.

While we are separately working on a conda package at https://github.com/roswell/conda-roswell that might (by chance?) become officially available in near future, this article describes a more manual installation. All files related to Roswell are installed under the virtual environment, never touching user's $HOME/.local directory or system-wide locations.

Dependencies

Setup under Anaconda : A sample environment.yml

Anaconda stores environment setup information in a yaml file typically named environment.yml. We provide a sample yml file and an installation script below. The script must be sourced, not executed --- Use it like source install.sh, rather than sh install.sh or ./install.sh.

environment.yml

name: myenv
dependencies:
  # Roswell dependencies
  - curl
  - libcurl
  - libzlib
  - compilers
  - automake

  # python dependencies
  - python=3.8
  - numpy
  - pip
  - pip:
      - tensorflow
      - ...

install.sh

#!/bin/bash

env="myenv"

# execute it in a subshell so that set -e stops on error, but does not exit the parent shell.
(
    set -e

    (conda activate >/dev/null 2>/dev/null)  || {
        echo "This script must be sourced, not executed. Run it like: source $0"
        exit 1
    }

    conda env create -f environment.yml || {
        echo "installation failed; cleaning up"
        conda env remove -n $env
        exit 1
    }

    conda activate $env

    ################################################################
    # reset my local variables so that they do not affect reproducibility

    echo "path variables that are set locally:"
    echo "-----------------"
    env | grep PATH | cut -d= -f1
    echo "-----------------"
    echo

    conda env config vars set LD_LIBRARY_PATH=
    conda env config vars set PYTHONPATH=
    conda env config vars set PKG_CONFIG_PATH=

    # these are required for building dependencies properly under conda
    conda env config vars set CPATH=${CONDA_PREFIX}/include:${CONDA_PREFIX}/x86_64-conda-linux-gnu/sysroot/usr/include:
    conda env config vars set ROSWELL_HOME=${CONDA_PREFIX}/var/roswell

    # note: "variables" field in yaml file introduced in conda 4.9 does not work because it does not expand shell variables

    # these are required for the variables to take effect
    conda deactivate ; conda activate $env

    echo $CPATH ; echo $ROSWELL_HOME

    conda env config vars list

    ################################################################
    # build Roswell
    (
        git clone -b release https://github.com/roswell/roswell.git
        cd roswell
        sh bootstrap
        ./configure --prefix=${CONDA_PREFIX}
        make
        make install
        ros setup
    )

) && {
    conda activate $env >/dev/null 2>/dev/null || echo "This script must be sourced, not executed. Run it like: source $0"
}