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
The recommended way to create a new virtual environment is to use the [uv](https://docs.astral.sh/uv/) tool, which supports _relocatable_ virtual environments and asynchronous package downloads. The main benefit of a relocatable virtual environment is that it does not need to be created in the final path from where it will be used. This allows the use of shared memory to speed up the creation and initialization of the virtual environment and, since the virtual environment can be used from any location, the resulting squashfs image can be safely shared across projects.
40
+
41
+
```bash
42
+
# start the uenv
43
+
# in this case the "default" view of prgenv-gnu provides python, cray-mpich,
44
+
# and other useful tools
45
+
uenv start prgenv-gnu/24.11:v1 --view=default
46
+
47
+
# create and activate a new relocatable venv using uv
A new virtual environment can also be created using the standard `venv` module. However, virtual environments created by `venv` are not relocatable, and thus they need to be created and initialized in the path from where they will be used. This implies that the installation process can not be optimized for file system performance and will still be slow on Lustre filesystems.
66
+
67
+
```bash
68
+
# start the uenv
69
+
# in this case the "default" view of prgenv-gnu provides python, cray-mpich,
70
+
# and other useful tools
71
+
uenv start prgenv-gnu/24.11:v1 --view=default
72
+
73
+
# for the example create a working path on SCRATCH
`find` is used to list every path and file, and `stat` is called on each of these to get the inode, and then `sort` and `wc` are used to count the number of unique inodes.
66
96
67
97
In our "simple" pytorch example, I counted **22806 inodes**!
68
98
69
-
##### Alternative virtual environment creation using uv
70
99
71
-
The installation process described above is not optimized for file system performance and will still be slow on Lustre filesystems. An alternative way to create the virtual environment is to use the [uv](https://docs.astral.sh/uv/) tool, which supports _relocatable_ virtual environments and asynchronous package downloads. The main benefit of a relocatable virtual environment is that it does not need to be created in the final path from where it will be used. This allows the use of shared memory to speed up the creation and initialization of the virtual environment and, since the virtual environment can be used from any location, the resulting squashfs image can be safely shared across projects.
100
+
#### Step 2: make a squashfs image of the virtual environment
72
101
73
-
```bash
74
-
# activate the uenv as before
75
-
uenv start prgenv-gnu/24.11:v1 --view=default
102
+
The next step is to create a single squashfs file that contains the whole virtual environment folder (i.e. `/dev/shm/sqfs-demo/.venv` or `$SCRATCH/sqfs-demo/.venv`).
76
103
77
-
# create and activate a new relocatable venv using uv
Remember that virtual environments created by `uv` are relocatable only if the `--relocatable` option flag is passed to the `uv venv` command as mentioned in step 1. In that case, the generated environment is relocatable and thus it is possible to mount it in multiple locations without problems.
Note that the original virtual environment is still installed in `$SCRATCH/sqfs-demo/.pyenv`, however the squashfs image has been mounted on top of it, so the single squashfs file is being accessed instead of the many files in the original version.
167
+
Note that the original virtual environment is still installed in `$SCRATCH/sqfs-demo/.venv`, however the squashfs image has been mounted on top of it, so the single squashfs file is being accessed instead of the many files in the original version.
137
168
138
-
A benefit of this approach is that the squashfs file can be copied to a location that is not subject to the Scratch cleaning policy.
169
+
A benefit of this approach is that the squashfs file can be copied to a location that is not subject to the Scratch cleaning policy.
139
170
140
-
!!! warning
141
-
Virtual environments are not relocatable by default as they contain symlinks to absolute locations inside the virtual environment. This means that the squashfs file must be mounted in the exact same location where the virtual environment was created, unless it contains a virtual environment specifically created using a tool with support for relocatable virtual environments (e.g. `uv venv --relocatable` as mentioned in step 1), in which case it can be mounted in any location.
171
+
!!! warning
172
+
Virtual environments created by `venv` are not relocatable as they contain symlinks to absolute locations inside the virtual environment. This means that the squashfs file must be mounted in the exact same location where the virtual environment was created.
142
173
143
174
#### Step 4: (optional) regenerate the virtual environment
144
175
145
-
The squashfs file is immutable - it is not possible to modify the contents of `.pyenv` while it is mounted.
176
+
The squashfs file is immutable - it is not possible to modify the contents of `.venv` while it is mounted.
146
177
This means that it is not possible to `pip install` more packages in the virtual environment.
147
178
148
-
If you need to modify the virtual environment, run the original uenv without the squashfs file mounted, make changes, and run step 2 again to generate a new image.
179
+
If you need to modify the virtual environment, run the original uenv without the squashfs file mounted, make changes to the virtual environment, and run step 2 again to generate a new image.
149
180
150
181
!!! hint
151
182
If you save the updated copy in a different file, you can now "roll back" to the old version of the environment by mounting the old image.
0 commit comments