You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've covered how to install, remove, and list packages with Spack using the commands:
13
+
So far in this tutorial, we've covered the basic commands for managing individual packages:
14
14
15
-
* `spack install <https://spack.readthedocs.io/en/latest/basic_usage.html#cmd-spack-install>`_ to install packages;
16
-
* `spack uninstall <https://spack.readthedocs.io/en/latest/basic_usage.html#cmd-spack-uninstall>`_ to remove them; and
17
-
* `spack find <https://spack.readthedocs.io/en/latest/basic_usage.html#cmd-spack-find>`_ to look at and query what is installed.
15
+
* `spack install <https://spack.readthedocs.io/en/latest/basic_usage.html#cmd-spack-install>`_ to install packages
16
+
* `spack uninstall <https://spack.readthedocs.io/en/latest/basic_usage.html#cmd-spack-uninstall>`_ to remove them
17
+
* `spack find <https://spack.readthedocs.io/en/latest/basic_usage.html#cmd-spack-find>`_ to view and query installed packages
18
18
19
19
.. Customizing Spack's installation with configuration files, like
20
20
`packages.yaml <https://spack.readthedocs.io/en/latest/build_settings.html#build-settings>`_, was also discussed.
21
21
22
-
This section of the tutorial introduces **Spack Environments**, which allow you to work with independent groups of packages separately, in a reproducible way.
23
-
In some ways, Spack environments are similar to *virtual environments* in other systems (e.g., `Python venv <https://docs.python.org/3/library/venv.html>`_), but they are based around file formats (``spack.yaml`` and ``spack.lock``) that can be shared easily and re-used by others across systems.
22
+
Now we'll explore Spack Environments -- a powerful feature that let's us manage collections of packages together in a documented and reproducible way.
23
+
Spack environments are similar to *virtual environments* in other package managers (e.g., `Python venv <https://docs.python.org/3/library/venv.html>`_ or `nix-env <https://nix.dev/manual/nix/2.24/command-ref/nix-env>`_).
24
24
25
-
Administering properly configured software involving lots of packages and/or varying configuration requirements (e.g., different implementations of ``mpi``) for multiple projects and efforts can be overwhelming.
26
-
Spack environments allow you to readily:
25
+
-------------------------------
26
+
What Makes a Spack Environment?
27
+
-------------------------------
27
28
28
-
* establish standard software requirements for your project(s);
29
-
* set up run environments for users;
30
-
* support your usual development environment(s);
31
-
* set up packages for CI/CD;
32
-
* reproduce builds (approximately or exactly) on other machines; and
33
-
* much more.
29
+
Spack environments are based around two key files that can be easily shared and reused across different systems:
34
30
35
-
This tutorial introduces the basics of creating and using environments, then explains how to expand, configure, and build software in them.
36
-
We will start with the command line interface, then cover editing key environment files directly.
37
-
We will describe the difference between Spack-managed and independent environments, then finish with a section on reproducible builds.
31
+
* ``spack.yaml`` -- The main configuration file where we specify which packages to install, compilers to use, and other Spack settings.
32
+
33
+
* ``spack.lock`` -- A lockfile that captures the complete provenance of you environment, enabling reproduction of software environments.
34
+
35
+
---------------------
36
+
Why Use Environments?
37
+
---------------------
38
+
39
+
Managing complex software setups with multiple packages and varying configuration (like different MPI) can quickly become overwhelming.
40
+
Spack environments solve this by letting you:
41
+
42
+
* Establish standard software requirements for your project(s)
43
+
* Set up consistent runtime environments for your users
44
+
* Maintain reproducible development environments
45
+
* Configure packages for CI/CD pipelines
46
+
* Share and reproduce builds across different machines
47
+
* Document your software stack for collaboration
48
+
* And much more
49
+
50
+
----------------------
51
+
Goals of this Tutorial
52
+
----------------------
53
+
This tutorial will teach you the fundamentals of creating and using Spack environments.
54
+
We'll cover:
55
+
1. Command line basics -- Creating and managing environments with Spack commands.
56
+
2. Configuration files -- Editing ``spack.yaml`` and understanding ``spack.lock``.
57
+
3. Environment types -- Understanding Spack-managed vs independent environments.
58
+
4. Reproducible builds -- Sharing and recreating environments across systems.
38
59
39
60
-------------------
40
61
Environment Basics
@@ -46,108 +67,99 @@ Let's look at the output of ``spack find`` at this point in the tutorial.
46
67
:language: console
47
68
48
69
49
-
This is a complete, but cluttered list of the installed packages and their dependencies.
70
+
This is a complete, but cluttered list of all our installed packages and their dependencies.
50
71
It contains packages built with both ``openmpi`` and ``mpich``, as well as multiple variants of other packages, like ``hdf5`` and ``zlib-ng``.
51
-
The query mechanism we learned about with ``spack find`` can help, but it would be nice if we could start from a clean slate without losing what we've already installed.
72
+
The query mechanism we learned about with ``spack find`` can help, but it would be nice if we could see only the software that is relevant to our current project instead of seeing everything on the machine.
52
73
53
74
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54
-
Creating and activating environments
75
+
Creating and Activating Environments
55
76
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56
77
57
-
The ``spack env`` command can help.
58
-
Let's create a new environment called ``myproject``:
78
+
Let's create a new environment called ``myproject`` using the ``spack env create`` command:
The output from ``spack find`` is now *slightly* different.
101
-
It tells you that you're in the ``myproject`` environment, so there is no need to panic when you see that none of the previously installed packages are available.
109
+
.. note::
110
+
Although Spack doesn't show all installed software packages when
111
+
in an active environment, Spack will reuse packages across
112
+
environments to save disk space and reduce build times.
113
+
114
+
Additionally the output now tells us that we're in the ``myproject`` environment, so there is no need to panic when we no longer see our previously installed packages.
102
115
It also states that there are **no** *root specs*.
103
116
We'll get back to what that means later.
104
117
105
-
If you *only* want to check what environment you are in, you can use ``spack env status``:
118
+
While this detailed output is useful, if we *only* want to check what environment we're are in, we can use ``spack env status``:
Notice that we are no longer in an environment and all our packages are still installed.
120
-
121
131
^^^^^^^^^^^^^^^^^^^
122
132
Installing packages
123
133
^^^^^^^^^^^^^^^^^^^
124
134
125
-
Now that we understand how creation and activation work, let's go back to ``myproject`` and *install* a couple of packages, specifically, ``tcl`` and ``trilinos``.
135
+
Now that we understand how creation and activation work, let's go back to our ``myproject`` enviornment and *install* a couple of packages, specifically, ``tcl`` and ``trilinos``.
126
136
127
-
Try the usual install command first:
137
+
Let's try the usual install commands we learned earlier:
Environments are special in that you must *add* specs to them before installing. ``spack add`` allows us to queue up several specs to be installed together.
142
+
Environments are special in that we must *add* specs to the an environment before we can install them. This additional step helps prevent us from accidentally modifying a shared enviornment when installing new software.
143
+
144
+
``spack add`` allows us to queue up several specs to be installed together.
Now, ``tcl`` and ``trilinos`` have been registered as **root specs** in this environment.
139
-
That is because we explicitly asked for them to be installed, so they are the **roots** of the combined graph of all packages we'll install.
150
+
Now, ``tcl`` and ``trilinos`` have been registered as **root specs** in our environment. **Root specs** are packages that we've explicitly requested to be installed in an environment.
151
+
They're called **"roots"** because they sit at the top of the dependency graph—when Spack installs these packages, with their respective depenedency packages sitting below them.
We can see that Spack reused existing installations of ``tcl`` and the dependencies of ``trilinos`` that were already present on the system, rather than rebuilding them from scratch.
146
159
147
-
We see that ``tcl`` and the dependencies of ``trilinos`` are already installed, and that ``trilinos`` was newly installed.
148
-
We also see that the environment's view was updated to include the new installations.
160
+
Additionally, the environment's view was automatically updated to include the installations. This means all the software in this environment has been added to our PATH, making the installed packages readily accessible from the command line while we have the environment activated.
149
161
150
-
Now confirm the contents of the environment using ``spack find``:
162
+
Let's now confirm the contents of the environment using ``spack find``:
@@ -158,65 +170,60 @@ We can see that the roots and all their dependencies have been installed.
158
170
Creating an environment incrementally
159
171
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
160
172
161
-
As a short-hand, you can use the ``install --add`` flag to accomplish the same thing in one step:
162
-
163
-
.. code-block:: console
164
-
165
-
$ spack install --add tcl trilinos
166
-
167
-
This both adds the specs to the environment and installs them.
168
-
169
-
You can also add and install specs to an environment incrementally. For example:
173
+
We can also add and install specs to an environment incrementally. For example:
170
174
171
175
.. code-block:: console
172
176
173
177
$ spack install --add tcl
174
178
$ spack install --add trilinos
175
179
176
-
If you create environments incrementally, Spack ensures that already installed roots are not re-concretized.
180
+
If we create environments incrementally, Spack ensures that already installed roots are not re-concretized.
177
181
So, adding specs to an environment at a later point in time will not cause existing packages to rebuild.
178
182
179
-
Do note, however, that incrementally creating an environment can give you different package versions from an environment created all at once.
180
-
We will cover this after we've discussed different concretization strategies.
183
+
.. note::
184
+
185
+
Incrementally creating an environment may give us different package
186
+
versions from an environment created all at once.
187
+
We'll cover later in the tutorial this after we've discussed different
188
+
concretization strategies.
189
+
190
+
Further, there are two other advantages of concretizing and installing an
191
+
environment all at once:
181
192
182
-
Further, there are two other advantages of concretizing and installing an environment all at once:
183
193
184
-
* If you have a number of specs that can be installed together,
185
-
adding them first and installing them together enables them to
186
-
share dependencies and reduces total installation time.
194
+
* If you have a number of specs that can be installed together,
195
+
adding them first and installing them together enables them to
196
+
share dependencies and reduces total installation time.
187
197
188
-
* You can launch all builds in parallel by taking advantage of Spack's `install-level build parallelism <https://spack.readthedocs.io/en/latest/packaging_guide.html#install-level-build-parallelism>`_.
198
+
* You can launch all builds in parallel by taking advantage of Spack's
Environments provide a convenient way for using installed packages.
195
-
Running ``spack env activate`` gives you everything in the environment on your ``PATH``.
196
-
Otherwise, you would need to use `spack load <https://spack.readthedocs.io/en/latest/basic_usage.html#cmd-spack-load>`_ or `module load <https://spack.readthedocs.io/en/latest/module_file_support.html>`_ for each package in order to set up the environment for the package (and its dependencies).
206
+
When we run ``spack env activate`` Spack by default prepends packages in the environment to our ``PATH``, ``MANPATH``, and ``CMAKE_PREFIX_PATH`` environment variables.
197
207
198
-
When you install packages into an environment, they are, by default, linked into a single prefix, or *view*.
199
-
Activating the environment with ``spack env activate`` results in subdirectories from the view being added to ``PATH``, ``MANPATH``, ``CMAKE_PREFIX_PATH``, and other environment variables.
200
-
This makes the environment easier to use.
208
+
Let's try it out to get a better sense of how views are constructed and added to our shell environment.
201
209
202
-
Let's try it out.
203
210
We just installed ``tcl`` into our ``myproject`` environment. ``Tcl`` includes a shell-like application called ``tclsh``.
204
-
You can see the path to ``tclsh`` using ``which``:
211
+
To can see the path to ``tclsh`` let's use ``which``:
0 commit comments