Skip to content

Commit b47d2ef

Browse files
Merge pull request #142 from rosswhitfield/update_nersc_docs
Simplify managing conda environments on NERSC docs
2 parents d6da2c3 + 9e81f0b commit b47d2ef

File tree

2 files changed

+52
-109
lines changed

2 files changed

+52
-109
lines changed

.github/workflows/workflows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
matrix:
3737
os: [ubuntu-latest, macos-latest]
3838
python-version: [3.6, 3.7, 3.8, 3.9]
39-
dask-version: ['2021.07.2']
39+
dask-version: ['2021.08.0']
4040
include:
4141
# same as NERSC Cori module python/3.7-anaconda-2019.10
4242
- os: ubuntu-latest
@@ -97,7 +97,7 @@ jobs:
9797
python3-pip
9898
python-is-python3
9999
- name: Install python testing dependencies
100-
run: python -m pip install pytest-cov pytest-timeout psutil dask==2021.07.2 distributed==2021.07.2
100+
run: python -m pip install pytest-cov pytest-timeout psutil dask==2021.08.0 distributed==2021.08.0
101101
- name: Install IPS (in develop mode)
102102
run: python -m pip install -e .
103103
- name: testing running IPS (--help)

doc/user_guides/nersc_conda.rst

Lines changed: 50 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,51 @@
22
Installing IPS on NERSC
33
=======================
44

5-
NERSC recommends the use of anaconda environments to mange python
5+
NERSC recommends the use of anaconda environments to manage python
66
installs, see `Brief introduction to Python at NERSC
7-
<https://docs.nersc.gov/development/languages/python/overview/>`_.
7+
<https://docs.nersc.gov/development/languages/python>`_.
88

99
There is a conda environment already constructed and maintained for
1010
the *atom* project created using the `shareable environment`_
11-
method. You can activate it by running ``source
12-
/global/common/software/atom/cori/ips-framework-new/bin/activate``.
11+
method. You can activate it and run IPS by:
12+
13+
.. code-block:: bash
14+
15+
module load python
16+
source activate /global/common/software/atom/cori/ips-framework-new
17+
ips.py --config=simulation.config --platform=platform.conf
1318
1419
Creating you own conda environment
1520
----------------------------------
1621

17-
This guide will go through creating a conda environment on NERSC
22+
This guide will go through creating a conda environment on NERSC and
1823
installing the IPS Framework using `Option 2: Module + source activate
1924
<https://docs.nersc.gov/development/languages/python/nersc-python/#option-2-module-source-activate>`_
2025

2126
First, you need to load the python module, then create and activate a
2227
new conda environment. This will create the conda environment in your
23-
home directory
28+
home directory (``$HOME/.conda/envs``):
2429

2530
.. code-block:: bash
2631
2732
module load python
2833
conda create --name my_ips_env python=3.8 # or any version of python >=3.6
2934
source activate my_ips_env
3035
31-
Next, get download the IPS Framework and install it into the conda
32-
environment
36+
If you would like the same packages and versions in your conda
37+
environment as found in the python modules on Cori, you can clone that
38+
environment. In this case using ``python/3.7-anaconda-2019.10``.
39+
40+
.. code-block:: bash
41+
42+
module load python/3.7-anaconda-2019.10
43+
conda create -n my_ips_env --clone base
44+
source activate my_ips_env
45+
46+
Next, install IPS-Framework into the conda environment
3347

3448
.. code-block:: bash
3549
36-
git clone https://github.com/HPC-SimTools/IPS-framework.git
37-
cd IPS-framework
3850
python -m pip install ipsframework
3951
4052
To leave your environment
@@ -43,9 +55,9 @@ To leave your environment
4355
4456
conda deactivate
4557
46-
The example below show how to select the newly create conda
47-
environment to run use, see `Running Python in a batch job
48-
<https://docs.nersc.gov/development/languages/python/overview/#running-python-in-a-batch-job>`_
58+
The example below shows how to select the newly create conda
59+
environment in a batch script, see `Running Python in a batch job
60+
<https://docs.nersc.gov/development/languages/python/#running-python-in-a-batch-job>`_
4961

5062
.. code-block:: bash
5163
@@ -63,29 +75,25 @@ environment to run use, see `Running Python in a batch job
6375
Creating a shareable environment on /global/common/software
6476
-----------------------------------------------------------
6577

66-
Creating an conda environment on /global/common/software is the
67-
recommend way to have one environment shared between many uses, this
68-
is covered by `Option 4a: Install your own Python without containers
69-
<https://docs.nersc.gov/development/languages/python/nersc-python/#option-4a-install-your-own-python-without-containers>`_.
70-
There may also be performance benefits to running from this location
71-
instead of your home directory.
78+
By default when you create a conda environment it will be created in
79+
``$HOME/.conda/envs``, to create one elsewhere that can be used by
80+
others you can use the ``--prefix`` option, see `Creating conda
81+
environments
82+
<https://docs.nersc.gov/development/languages/python/nersc-python/#creating-conda-environments>`_.
7283

73-
Following the instruction we do
84+
In this example we are cloning the conda environment from the
85+
``python/3.7-anaconda-2019.10`` module and install ``ipsframework``.
7486

7587
.. code-block:: bash
7688
77-
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
78-
bash Miniconda3-latest-Linux-x86_64.sh -b -p /global/common/software/myproject/env
79-
source /global/common/software/myproject/env/bin/activate
80-
81-
Then install IPS into the environment, from within the IPS-framework
82-
source directory::
83-
89+
module load python/3.7-anaconda-2019.10
90+
conda create --prefix /global/common/software/myproject/env --clone base
91+
source activate /global/common/software/myproject/env
8492
python -m pip install ipsframework
8593
86-
The example below show how to select the newly create conda
87-
environment to run use, see `Running Python in a batch job
88-
<https://docs.nersc.gov/development/languages/python/overview/#running-python-in-a-batch-job>`_
94+
The example below shows how to select the newly create conda
95+
environment in you batch script, see `Running Python in a batch job
96+
<https://docs.nersc.gov/development/languages/python/#running-python-in-a-batch-job>`_
8997

9098
.. code-block:: bash
9199
@@ -94,10 +102,10 @@ environment to run use, see `Running Python in a batch job
94102
#SBATCH --nodes=1
95103
#SBATCH --time=5
96104
97-
source /global/common/software/myproject/env/bin/activate
105+
module load python
106+
source activate /global/common/software/myproject/env
98107
ips.py --config=simulation.config --platform=platform.conf
99108
100-
101109
Installing dependencies
102110
~~~~~~~~~~~~~~~~~~~~~~~
103111

@@ -107,92 +115,27 @@ To see which packages are currently install in your environment run:
107115
108116
conda list
109117
110-
You can install just the dependencies you need by
111-
112-
.. code-block:: bash
113-
114-
conda install matplotlib netcdf4 ...
115-
116-
If you would like the same versions and dependencies in your conda
117-
environment as found in the python modules on Cori, you can export
118-
that environment and set your environment to be the same.
119-
120-
Export ``python/3.7-anaconda-2019.10`` to yml file.
121-
122-
.. code-block:: bash
123-
124-
module load python/3.7-anaconda-2019.10
125-
conda env export --name base > environment.yml
126-
127-
# remove mpi4py and buildtest from environment.yml as these should be installed manually
128-
sed -i '/mpi4py/d' environment.yml
129-
sed -i '/buildtest/d' environment.yml
130-
131-
Activate your conda environment and force it to match the
132-
``environment.yml`` file. ``mpi4py`` should be install separately
133-
`according to NERSC
134-
<https://docs.nersc.gov/development/languages/python/parallel-python/#mpi4py-in-your-custom-conda-environment>`_.
118+
You can install any other dependencies you need by
135119

136120
.. code-block:: bash
137121
138-
source activate my_ips_env
139-
conda env update -n my_ips_env --file environment.yml
140-
141-
# or
142-
143-
source /global/common/software/myproject/env/bin/activate # your environment
144-
# setup base environment
145-
conda env update -n base --file environment.yml
146-
147-
Install ``mpi4py`` if needed
148-
149-
.. code-block:: bash
150-
151-
MPICC="$(which cc) --shared" python -m pip install --no-binary mpi4py mpi4py
152-
153-
Alternatively you can start with the same Anaconda environment which
154-
will have almost everything you need already and then just install the
155-
few missing dependencies. As an example, this use the same Anaconda
156-
distribution as in the ``python/3.7-anaconda-2019.10`` module.
157-
158-
.. code-block:: bash
159-
160-
wget https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh
161-
bash Anaconda3-2019.10-Linux-x86_64.sh -b -p /global/common/software/myproject/env
162-
source /global/common/software/myproject/env
163-
conda install netcdf4
164-
MPICC="$(which cc) --shared" python -m pip install --no-binary mpi4py mpi4py
165-
python -m pip install dask-mpi
122+
conda install numpy matplotlib netcdf4 ...
166123
167124
User development
168125
~~~~~~~~~~~~~~~~
169126

170-
Miniconda or Anaconda can can be installed to your home directory for easy development of component wrappers.
171-
172-
.. code-block:: bash
173-
174-
wget https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh
175-
bash Anaconda3-2019.10-Linux-x86_64.sh -b -p $HOME/anaconda3
176-
source $HOME/anaconda3/bin/activate
177-
conda install netcdf4
178-
MPICC="$(which cc) --shared" python -m pip install --no-binary mpi4py mpi4py
179-
python -m pip install dask-mpi
180-
python -m pip install ipsframework
181-
182-
183-
After which you can switch between youy development and the production
184-
environment on atom project by
127+
You should keep your development environment separate from the
128+
production environment. If you do development in your ``my_ips_env``
129+
conda environment you can switch between that and the production
130+
environment on the atom project by
185131

186132
.. code-block:: bash
187133
188134
# switch to production environment
189-
source /global/common/software/atom/cori/ips-framework-new/bin/activate
135+
source activate /global/common/software/atom/cori/ips-framework-new
190136
191137
# switch bask to user development environment
192-
source $HOME/miniconda3/bin/activate
193-
194-
To see which environment you are currently in you can run
195-
196-
.. code-block:: bash
138+
source activate my_ips_env
197139
198-
conda env list
140+
Your bash prompt should be updated to reflect which environment you
141+
have active.

0 commit comments

Comments
 (0)