Skip to content

Using your environment

In a job script or interactive job

To use the binaries and libraries from your Spack environment, add the following two lines into your job script, (or run them within an interactive job):

module load spack/<version>
spack env activate /data/scratch/abc123/spack-environments/spack-only

The -p flag is not required in job scripts because the decorated prompt will not be observed within non-interactive jobs. The above command would make all of the applications we defined in the specs section of our spack.yaml environment file available at the same time. This is very powerful for workloads which require multiple applications to be available at the same time, for example Bioinformatics pipeline software. By using a Spack environment, the software required will have been compiled in a consistent way, ensuring better compatibility between applications. The pipeline can also be easily reproduced, as described in the next section.

Deactivating an environment

You may wish to deactivate an environment during an interactive session. To do so, simply run:

spack env deactivate

This will deactivate any activated environment, and (assuming you used the -p flag when initially activating the environment) remove the previously active environment's name from your prompt.

Sharing environments

Now that you have a working spack.yaml file for your environment, you could also share it with other Apocrita users, for example other members of your Research Group, and they would also be able to recreate your environment for themselves. This is essentially what we have done during this process - the ITSR support team created the spack.yaml file for this part of the tutorial in advance, and by following this tutorial, you will have replicated our Spack environment.

If you look inside the the top level of the environment directory, you should now also find a spack.lock file. This is a JSON-formatted file containing exact details about how everything in the environment was concretized. Using a spack.lock file is beyond the scope of this basic tutorial, but you can find more information about them in the official Spack documentation.