Skip to content

Commit

Permalink
Merge pull request #18 from Bai-Chiang/micromamba
Browse files Browse the repository at this point in the history
Add micromamba support and various fix and improvements.
  • Loading branch information
Bai-Chiang authored Jan 29, 2024
2 parents 6724e5f + d472297 commit 79a2809
Show file tree
Hide file tree
Showing 22 changed files with 306 additions and 160 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tmpfs
log_*
toast_test_output
7 changes: 7 additions & 0 deletions config/binary/packages_conda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Adjust the default python version
python=3.10.*
#
jupyterlab
wurlitzer
plotly
plotly-resampler
Empty file.
17 changes: 17 additions & 0 deletions config/binary/packages_pip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pixell
quaternionarray
pysm3
# Uncomment here if installing wheel, and comment out
# line in packages_local.txt
posix-ipc
toast==3.0.0a20
pysqlite3-wheels
qpoint
so3g
#
# Latest tag
https://github.com/simonsobs/sotodlib/archive/master.tar.gz
#
# The mapsims package has hard-coded versions of pysm3 and
# pixell, which un-installs our versions of those packages.
#https://github.com/galsci/mapsims/archive/main.tar.gz
15 changes: 15 additions & 0 deletions config/binary/post_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This script is sourced in the main `soconda.sh` script.
# Any commands placed here will be executed within that shell
# and have access to all environment variables defined there.
# There are 2 variables defined here which control the optional
# creation of a modulefile to load the environment and also
# which create a small script that installs a jupyter kernel
# for the environment into a user's home directory.

# Install a module file?
install_module=yes

# Install jupyter kernel setup script?
install_jupyter_setup=yes

# Add any other shell commands here for this system...
1 change: 1 addition & 0 deletions config/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# and parse pip dependencies with pipgrip.
#
conda-build
conda-verify
compilers
setuptools
pip
Expand Down
2 changes: 1 addition & 1 deletion config/minimal/packages_conda.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Adjust the default python version
python=3.10.*
python=3.11.*
#
13 changes: 0 additions & 13 deletions config/minimal/packages_local.txt
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
# This config skips all the ACT tools and just installs
# binary packages for everything.
#qpoint
#pixell
#libactpol_deps
#libactpol
#moby2
# Remove next line once toast-3.0 is on conda-forge,
# and move to packages_conda.txt
#toast
# Uncomment next line to build so3g from source, and
# comment out line in packages_pip.txt.
#so3g
6 changes: 4 additions & 2 deletions config/minimal/packages_pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ quaternionarray
pysm3
# Uncomment here if installing wheel, and comment out
# line in packages_local.txt
pysqlite3-wheels
posix-ipc
toast==3.0.0a20
pysqlite3-wheels
qpoint
so3g
#
# Latest tag
https://github.com/simonsobs/sotodlib/archive/refs/master.tar.gz
https://github.com/simonsobs/sotodlib/archive/master.tar.gz
#
# The mapsims package has hard-coded versions of pysm3 and
# pixell, which un-installs our versions of those packages.
Expand Down
4 changes: 2 additions & 2 deletions config/minimal/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# for the environment into a user's home directory.

# Install a module file?
install_module=no
install_module=yes

# Install jupyter kernel setup script?
install_jupyter_setup=no
install_jupyter_setup=yes

# Add any other shell commands here for this system...
2 changes: 1 addition & 1 deletion config/perlmutter/packages_pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pysm3
#so3g
#
# Latest tag
https://github.com/simonsobs/sotodlib/archive/refs/master.tar.gz
https://github.com/simonsobs/sotodlib/archive/master.tar.gz
#
# The mapsims package has hard-coded versions of pysm3 and
# pixell, which un-installs our versions of those packages.
Expand Down
1 change: 1 addition & 0 deletions config/site/module_init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No module dependencies
6 changes: 6 additions & 0 deletions config/site/packages_conda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Adjust the default python version
python=3.10.*
#
wurlitzer
plotly
plotly-resampler
11 changes: 11 additions & 0 deletions config/site/packages_local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
qpoint
pixell
libactpol_deps
libactpol
moby2
# Remove next line once toast-3.0 is on conda-forge,
# and move to packages_conda.txt
toast
# Uncomment next line to build so3g from source, and
# comment out line in packages_pip.txt.
so3g
14 changes: 14 additions & 0 deletions config/site/packages_pip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
quaternionarray
pysm3
#
# Uncomment here if installing wheel, and comment out
# line in packages_local.txt
#pysqlite3-wheels
#so3g
#
# Latest tag
https://github.com/simonsobs/sotodlib/archive/master.tar.gz
#
# The mapsims package has hard-coded versions of pysm3 and
# pixell, which un-installs our versions of those packages.
#https://github.com/galsci/mapsims/archive/main.tar.gz
15 changes: 15 additions & 0 deletions config/site/post_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This script is sourced in the main `soconda.sh` script.
# Any commands placed here will be executed within that shell
# and have access to all environment variables defined there.
# There are 2 variables defined here which control the optional
# creation of a modulefile to load the environment and also
# which create a small script that installs a jupyter kernel
# for the environment into a user's home directory.

# Install a module file?
install_module=yes

# Install jupyter kernel setup script?
install_jupyter_setup=yes

# Add any other shell commands here for this system...
123 changes: 81 additions & 42 deletions docs/docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The install script takes options to specify the location of the base environment
to create. It also allows specifying a central location to install the
modulefile:

$> ./soconda.sh -h
./soconda.sh -h
Usage: ./soconda.sh
[-c <directory in config to use for options>]
[-e <environment, either name or full path>]
Expand All @@ -25,22 +25,20 @@ clutter.

## Base Conda Environment

If you already have a conda-forge base environment, then you can skip this
If you already have a conda-forge or micromamba base environment, then you can skip this
step. However, you should consider setting the "solver" in the base environment
to use libmamba. This will greatly speed up the dependency resolution
calculation. Once you decide on the install prefix for your overall conda
environment you can use the included bootstrap script. For this example, we
will use `/opt/conda` as the path to the conda base installation. Now run the
bootstrap script:
to use `libmamba`. To use `libmamba` solver see
[this](https://www.anaconda.com/blog/a-faster-conda-for-a-growing-community) article.
This will greatly speed up the dependency resolution
calculation.

$> ./tools/bootstrap_base "/opt/conda"
For new installation run following script to install miniforge

This bootstrap will install a base system with the conda-forge channel set to
the default and using the libmamba solver. You can now source the conda
initialization file and activate this base environment:
./tools/bootstrap_base "$HOME/miniforge3"

$> source /opt/conda/etc/profile.d/conda.sh
$> conda activate base
This will intall conda to `$HOME/miniforge3` directory.
It will set conda-forge as default channel and use `libmamba` as default solver.
After the installation you need to re-login or start a new terminal to initialize conda.

After installing an `soconda` environment below, you will not need this step
since it is done by the generated modulefile.
Expand All @@ -53,34 +51,69 @@ customized MPI compiler, then set the `MPICC` environment variable to the MPI C
compiler before running `soconda.sh`. That will cause the mpi4py package to
be built using your system MPI compiler.

## Example: Local System
## Install soconda
### Example: Local System
This installation could install `soconda` to your local computer and any cluster.

Starting from scratch, bootstrap a small conda-forge base environment in `~/conda`:
Clone soconda repo

$> ./tools/bootstrap_base.sh ~/conda
$> source ~/conda/etc/profile.d/conda.sh
$> conda activate base
git clone [email protected]:simonsobs/soconda.git
cd soconda

Create an `soconda` environment with default name and version. However, we
decide to put all the modulefiles into a central location in the root of the
base conda install:
Run the `soconda.sh` script

$> ./soconda.sh -b ~/conda -m ~/conda/modulefiles
export MAKEFLAGS='-j 4'
bash soconda.sh -e soconda -c default

Now we can load the module:
This will create a new environment `soconda_xxx.x.x` with version number as suffix
using `default` configuration. [More details on configuration.](#customizing-an-environment)
(The `MAKEFLAGS` doesn't seem to have any effect.)
If you want to specify a conda base directory add `-b "$HOME/miniforge3"` argument to `soconda.sh`.

$> module use ~/conda/modulefiles
$> module avail
$> module load soconda/XXXXXX
You could find out the name of new created environment with

## Example: NERSC
conda env list

Then you can now activate the environment with

conda activate soconda_xxx.x.x


If running on a Linux desktop that uses wayland, you also need to install the `qt-wayland` package

conda install qt-wayland


If running on server, start jupyterlab listening on port `12345` with command

cd /path/to/project
nohup jupyter-lab --no-browser --port=12345 &> jupyter.log &


To list current running jupyter server:

jupyter server list


To connect to jupyterlab running on server, start SSH tunnel from your laptop/desktop:

ssh -N -L 12345:localhost:12345 server_domain_or_ip

Then you can connect to jupyterlab with link provided by command `jupyter server list`.

To stop jupyterlab listenging on port 12345:

jupyter server stop 12345


### Example: NERSC

At NERSC, the default provided python is from Anaconda, and does not work well
for our needs. Instead, we have a conda-forge base system installed in our
project software directory:

$> source /global/common/software/sobs/perlmutter/conda/etc/profile.d/conda.sh
$> conda activate base
source /global/common/software/sobs/perlmutter/conda/etc/profile.d/conda.sh
conda activate base

Now we can either install a shared software environment or use this base
environment to build a conda environment in a personal directory. If you are
Expand All @@ -89,29 +122,29 @@ account and follow a specific naming convention which is beyond the scope of
this document. If you wanted to install these tools to your home directory you
could do:

$> mkdir -p ~/conda_envs
$> ./soconda.sh -e ~/conda_envs/soconda -m ~/conda_envs/modulefiles
mkdir -p ~/conda_envs
./soconda.sh -e ~/conda_envs/soconda -m ~/conda_envs/modulefiles

And then load the module:

$> module use ~/conda_envs/modulefiles
$> module avail
$> module load soconda/XXXXXX
module use ~/conda_envs/modulefiles
module avail
module load soconda/XXXXXX

## Running Tests

After loading an `soconda` environment, you can run some tests with:

$> ./run_tests.sh
./run_tests.sh

## Installing a Jupyter Kernel
## Installing a Jupyter Kernel for external Jupyter server

After loading an soconda module the first time, you can run (once) the included script:
After loading an soconda module or activate socond conda environment the first time, you can run (once) the included script:

$> soconda_jupyter.sh
soconda_jupyter.sh

This will install a kernel file so that jupyter knows how to launch a kernel
using this python stack.
This will install a kernel file to `~/.local/share/jupyter/kernels/soconda-xxxxx` so that external jupyter server
knows how to launch a kernel using this python stack.

## Customizing an Environment

Expand All @@ -127,9 +160,15 @@ Then install it as usual.
## Deleting an Environment

The `soconda` environments are self contained and you can delete them by
removing the path or (if using a name), removing the `<base dir>/envs/<name of
env>` directory. You can optionally delete the modulefile and the versioned pip
running command `conda remove --name envname --all` or `conda remove -p /base_dir/envs/name --all`.
Or directly removing the `<base dir>/envs/<name of env>` directory.
You can optionally delete the modulefile and the versioned pip
local directory in your home directory.
If you installed a jupyter kernel, remove kernel file in `~/.local/share/jupyter/kernels/`
with matching soconda version.
If you have multiple soconda environment and deleted wrong kernel file, you can always
[recreate it](#installing-a-jupyter-kernel).


## Advanced Details

Expand Down
2 changes: 1 addition & 1 deletion pkgs/so3g/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set version = "0.1.10" %}
{% set sha256 = "4cabc243acf6a18bb8b63572f468b303c3bc4cb4e0e901e3fbe222a8ff094e11" %}
{% set sha256 = "5367cdd24ac7eff70b482ede2c32df8e1acd16e582a24e489467ec2c4760c31b" %}

{% set build = 0 %}

Expand Down
6 changes: 3 additions & 3 deletions pkgs/toast/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{% set version = "3980cbb579de56a379df000df76e69a1c1ac73ae" %}
{% set sha256 = "e2713145f758631cd6bb24b89a87f2522322a72a29400f8ba51d5144e9afe54d" %}
{% set version = "3.0.0a20" %}
{% set sha256 = "4d5ad584bf0d2e851009beb17a4ec96677b36b9c9e18893910014581bc22bb4c" %}

{% set build = 0 %}

Expand All @@ -9,7 +9,7 @@ package:
version: {{ version }}

source:
url: https://github.com/hpc4cmb/toast/archive/{{ version }}.tar.gz
url: https://github.com/hpc4cmb/toast/archive/refs/tags/{{ version }}.tar.gz
sha256: {{ sha256 }}
# patches:
# - debug_lapack.patch
Expand Down
4 changes: 2 additions & 2 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

# Pixell Tests
OMP_NUM_THREADS=4 test_pixell.py
#OMP_NUM_THREADS=4 test_pixell.py

# Serial TOAST Tests
OMP_NUM_THREADS=4 MPI_DISABLED=1 python -c 'import toast.tests; toast.tests.run()'

# MPI-enabled tests
OMP_NUM_THREADS=2 mpirun -np 4 python -c 'import toast.tests; toast.tests.run()'
OMP_NUM_THREADS=2 mpirun -np 2 python -c 'import toast.tests; toast.tests.run()'
Loading

0 comments on commit 79a2809

Please sign in to comment.