Tips & Tricks#
Key generation for SSH#
If you do not like to keep having to enter your password, have a look at generating an ssh key here and here.
Generate a key with the command
ssh-keygen
. You can choose to leave the password empty.Add the SSH key to the
ssh-agent
and create a corresponding public key with the commands:
eval $(ssh-agent -s); ssh-add ~/.ssh/id_rsa
Copy the public key to the server using:
ssh-copy-id -i ~/.ssh/id_rsa <your user name>@lxslc7.ihep.ac.cn
You will be asked for your IHEP account password.Try to log in to the server with:
ssh -Y <your user name>@lxslc7.ihep.ac.cn
If all went correctly, you don’t have to enter your password anymore.
Installing ROOT#
The BOSS Starter Kit comes with a
handy bash script
to download and install CERN ROOT6 on a Ubuntu platform. It requires you to have sudo
(admin) rights. The script can be run in one go using:
wget https://raw.githubusercontent.com/redeboer/BOSS_StarterKit/master/utilities/InstallCernRoot.sh
sudo bash InstallCernRoot.sh
For more information, see the official pages:
Warning
You will download around 1 GB of source code.
Visual Studio Code#
Visual Studio Code (VSCode) is a popular IDE that
is regularly updated, is configurable with easy-to-access json
files, and offers a
growing number of user-developed extensions. In recent years, it is has become
the most widely used editor
on the market.
Remote SSH#
For working with VSCode on lxslc
, you can use the
Remote - SSH
extension. This lets you with VSCode work on the server with full functionality, such as
using the Source Control Manager and language navigation from any other VSCode
extensions you installed. See
here for a
tutorial on how to connect to a remote SSH server.
There is one thing you need to change in your VSCode settings. Following these instructions, set the following option:
"remote.SSH.useLocalServer": false,
In addition, you may need to set the remote platform to "linux"
:
"remote.SSH.remotePlatform": {
"lxslc7.ihep.ac.cn": "linux"
},
where "lxslc7.ihep.ac.cn"
is the name of the host in your
SSH Config file.
Tip
VSCode Remote SSH installs some files into your home directory on the server, in a
folder called .vscode-server
. This will not work if you experience this (rather
common) problem: I lost read-write access in my afs home folder. It is therefore recommended that you move the
.vscode-server
folder to a directory where you always have read-write access and then
create a symbolic link to that folder in your actual home folder. Do this as follows:
cd ~
mkdir /besfs5/users/$USER/.vscode-server
ln -s /besfs5/users/$USER/.vscode-server
cd ~
mv -f .vscode-server /besfs5/users/$USER/
ln -s /besfs5/users/$USER/.vscode-server
Another major advantage of this set-up is that you won’t have problems with
data quota when the
.vscode-server
grows over time.
Conda#
The lxslc
server has a very outdated version of Python. If you do want to use Python
3, you can work with Conda, which is available on the server. Just add the following
script:
__conda_setup="$(
'/cvmfs/mlgpu.ihep.ac.cn/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null
)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/cvmfs/mlgpu.ihep.ac.cn/anaconda3/etc/profile.d/conda.sh" ]; then
. "/cvmfs/mlgpu.ihep.ac.cn/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/cvmfs/mlgpu.ihep.ac.cn/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
You can then source it through whatever means you prefer, like creating an alias
alias condaenv="source <path_to_script>/conda_env.sh"
in your .bashrc
.
Next, just run conda activate tensorflow-gpu
and you have python3
, ipython
and
even import tensorflow
available! (At the time of writing, TensorFlow is version
1.13.1 though.)
Unfortunately, you don’t have the rights to conda create
new environments. To see
which other environments are available, use conda info --envs
.
Note
If you don’t want to go through this whole hassle (it’s quite slow indeed), and
just want to use python3
, you could also just add
/cvmfs/mlgpu.ihep.ac.cn/anaconda3/envs/tensorflow/bin
to your
PATH
. But keep in mind that you may run into trouble with certain
Python libraries!
Compiling#
For compiling outside ROOT (that is, not using the ROOT interpreter), you will need to
use a compiler like g++
. The compiler needs to be told where the libraries for
included ROOT header files are located. You can do this using flags that ROOT set during
its installation. In case of g++
, use:
g++ YourCode.C -I$(root-config --incdir) $(root-config --libs --evelibs
--glibs) -o YourBinaryOutput.o
Pro bash
tip: You might like to create an easy command for this. You can do this by
adding the following lines to your ~/.bashrc
.
function rtcompile () {
g++ "$1"
-I$(root-config --incdir) \
$(root-config --libs --evelibs --glibs) \
-lRooFit -lRooFitCore -lRooStats -lMinuit -o "${1/._/.o}"
}
function rtcompilerun () {
rtcompile "$1"
if [ $? -eq 0 ]; then
./${1/._/.o}
fi
}
function rtdebugcompile () {
g++ "$1"
-I$(root-config --incdir) \
$(root-config --libs --evelibs --glibs) \
-lRooFit -lRooFitCore -lRooStats -lMinuit -fsanitize=address -g -o "${1/.\*/}"
}
export -f rtcompile
export -f rtcompilerun
export -f rtdebugcompile
Note the flags added through root-config
: there are includes (preceded by option -I
)
and linked libraries (following that option, and preceding output option -o
). Note
also that flags have been added for RooFit
. For more information about ROOT flags, see
this page.
Here, we give three examples of commands, one for compiling only (rtcompile
), one for
compiling and executing if successful (rtcompilerun
), and one for compiling with
fsanitize
activated
(rtdebugcompile). The
latter is useful if you want to look for memory leaks etc — only use if you are
interested in this, because it will decrease run-time. In addition, there are many
issues in root (like TString
) that are identified by fsanitize
.
Compiling on Windows 10#
Although it is highly recommended to on a Linux OS such as Ubuntu or CentOS, there are still -certain advantages of working on Windows. As a developer, that brings problems, however, if you want to start compiling your code.
Since Windows 10, there exists an easy solution: Windows Subsystem for Linux (WSL). In the newest versions can be easily installed from the Windows Store (search for “Ubuntu”). After installing, search for “Ubuntu” in the start menu. This is a bash terminal that has full access to your windows system, but entirely through bash commands.
As such, you have access to convenient commands like apt install
, vi
, and g++
.
Best of all is that you can use this to
install ROOT. If you are having trouble
installing ROOT through bash, have a look
at this script
(ROOT6).