NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
486 stars 179 forks source link

The quick start installation guide does not work for zsh (and likely other shells) #2194

Open mitchdz opened 3 weeks ago

mitchdz commented 3 weeks ago

Required prerequisites

Describe the bug

The quick start installation guide says to install and use cuda-quantum like so:

sudo -E bash install_cuda_quantum.$(uname -m) --accept
. /etc/profile

This can cause issues if you are not using bash, as once install_cuda_quantum.$(uname -m) finishes running, you are returned to the calling shell. In my case, I am using zsh. The issues occurs because /opt/nvidia/cudaq/set_env.sh uses ${BASH_SOURCE[0]} which doesn't work well when using zsh.

Steps to reproduce the bug

Run a shell other than bash (such as zsh) and then attempt to source the environment file.

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ cat /etc/profile | tail -n 2
CUDAQ_INSTALL_PATH="/opt/nvidia/cudaq"
. "${CUDAQ_INSTALL_PATH}/set_env.sh"
$ . /etc/profile
$ echo $PATH
./bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Expected behavior

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ cat /etc/profile | tail -n 2
CUDAQ_INSTALL_PATH="/opt/nvidia/cudaq"
. "${CUDAQ_INSTALL_PATH}/set_env.sh"
$ . /etc/profile
$ echo $PATH
/opt/nvidia/cudaq/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment

Suggestions

This is honestly a pretty tricky situation to fix. Ideally you'd just insert a cheeky #!/bin/bash up top, but that does not work when you are sourcing a file.

For me, I fixed it by instead using

export CUDA_QUANTUM_PATH=`dirname "$(readlink -f "$0")"`

in my /opt/nvidia/cudaq/set_env.sh

Which works well for zsh, but not for bash.

To be the most portable, perhaps the documentation should just say to run the command in a bash shell and mention other shells might be problematic.