*It is recommended that you install a virtual machine in order to install LHAPDF. There is much software available to do this, but the most popular and simple software is Oracle VM Virtual Box, which can be found at this link. Instructions for how to install Oracle VM are found on their website, as well as on many other online resources. Make sure that the VM is set to Ubuntu 64 Bit. (Also make sure that enough RAM is allocated to the VM to ensure fast enough processing speed! At least 2GB is recommended)

**Also make sure to install Ubuntu and have it properly configured to run alongside your current OS so as to not lose any data after closing your Virtual Machine.

***If you are on a Linux OS, disregard all of the above.

****If you are running jobs via Rivanna, then there is no need to install any of the below unless you want to test code on your local machine before submitting a job of Rivanna - Rivanna is now equipped with LHAPDF and its required dependencies.



Setting up Ubuntu 22.04 with LHAPDF

  1. Install ubuntu using the bootable flash drive
  2. sudo apt update
  3. Additional Drivers (GUI) > Nvidia-driver-535 Note: this step can be done manually
  4. nvidia-smi : This should show a table with the GPU specs, it may also disply CUDA version if it was installed together with the driver in Step (3)
  5.  sudo apt install g++
  6.  sudo apt install -y python3-pip
  7.  pip3 install numpy
  8.  sudo ln -s /usr/bin/python3 /usr/bin/python (this is to force the  python path to python3.10)
  9.  sudo apt install -y build-essential libssl-dev libffi-dev python3-dev 
  10.  Download LHAPDF 6.5.4.tar.gz via https://lhapdf.hepforge.org/
  11.  Create a folder called "LHAPDF" inside the Home directory and move the LHAPDF 6.5.4.tar.gz and unzip.
  12.  Create a folder called "LHAPDF-install" inside the/home/LHAPDF directory. This is where we will install the LHAPDF software.
  13.  cd LHAPDF-6.5.4
  14.  Check the ~/.bashrc file and ensure you have the following there
     export PATH=$LHADIR/bin:$PATH
     export LHADIR=/home/username/LHAPDF/LHAPDF-install
     export LD_LIBRARY_PATH=$LHADIR/lib:$LD_LIBRARY_PATH
     alias python=python3
     alias Python=python3
     alias python='python3'
    then, source ~/.bashrc
  15.  ./configure - - prefix=/home/username/LHAPDF/LHAPDF-install (This will configure the LHAPDF, check the output to ensure no issues).
  16.  make
  17.  make install
  18.  Add the following line to the ~/.bashrc file.
     export PYTHONPATH=$LHADIR/local/lib/python3.10/dist-packages:$PYTHONPATH
     then, source ~/.bashrc
  19.  Type 'lha' and hit tab, it should auto-complete 'lhapdf' if everything went correctly. Then hit 'enter', and you will see some texts starting from "usage: lhapdf -h ......."
  20.  Next step is to run this PDFs_FFs_in_LHAPDF.py . For that you will need to download the relevant pdf drids. So, download this PDFs_FFs_in_LHAPDF.py  file, open and check which grids you need.
  21.  Download the relevant grids from https://lhapdf.hepforge.org/pdfsets.html page.
  22.  Copy those .tar.gz files to /LHAPDF-install/share/LHAPDF folder and unpack those using this command: tar -xvzf name.tar.gz
  23.  Add the following line to the ~/.bashrc
     export LHAPDF_DATA_PATH=/home/username/LHAPDF/LHAPDF-install/share/LHAPDF:$LHAPDF_DATA_PATH
     then, source ~/.bashrc
  24.  Run the  PDFs_FFs_in_LHAPDF.py, and check whether it generates two plots. (Note: you may comment out 'import pandas as pd' if you did not install pandas yet).





  1. Install Python3.8

Some versions of Linux may come pre-installed with Python, others may not, and those that do may not have an up-to-date version of Python. For the purposes of this guide, Python 3.8 will be used.

Open the terminal from the virtual machine. To install Python 3.8, type the following commands

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt-get update

sudo apt-get install python3.8

sudo apt install python3.8-distutils

sudo apt-get install python3-dev

In order to ensure that python3.8 is properly installed, go to your home directory. To make sure that you are in your home directory, type “cd” into the terminal and press Enter. Then, type

nano ~/.bashrc

This will open up your .bashrc file in a text editor. Your .bashrc file in Linux is essentially the script file that’s executed when a user logs in and contains a series of configurations for the terminal session.

At scroll down to the very end of the .bashrc file and input the following paths:

export PYTHONPATH=$LHADIR/lib/python3.8/site-packages:$PYTHONPATH

export PATH=$LHADIR/bin:$PATH

export LD_LIBRARY_PATH=$LHADIR/lib:$LD_LIBRARY_PATH

These paths are vital for letting LHAPDF know where to look for files. They’re being put there to avoid installation errors for when you have to install LHAPDF.


Note: to make sure that the python version is correctly selected.
On MacOS: use the following lines in the ~/.bash_profile and make sure to 'source' it. Also, it's better to do $ alias python=python3

export PYTHON=/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
export PYTHON_PATH=/Library/Frameworks/Python.framework/Versions/3.8/bin/python3

From this way, we can force the LHAPDF installation to use python3.8 instead of python2.7 (which is the usual default).
After the installation, check whether in LHAPDF-Install > lib has python3.8 folder.

             

          2. Installing LHAPDF

Assuming that Python3.8 is correctly installed, there are two ways to install LHAPDF:

  1. Download LHAPDF from https://lhapdf.hepforge.org/downloads
    1. If you decide to so this option, download the latest version then move that file into a new file in your home directory. Call that file “LHAPDF” for convenience.
  2. In the terminal from the home directory, type:


wget https://lhapdf.hepforge.org/downloads/?f=LHAPDF-6.X.Y.tar.gz -O LHAPDF-6.X.Y.tar.gz


Where the command says “LHAPDF-6.X.Y.tar.gz”, replace “X” and “Y” with the numbers associated with the version of LHAPDF you are using. At the time that I’m writing this manual, I’m using version LHAPDF-6.3.0, so I’d replace “X” and “Y” with “3” and “0”, respectively.

**It is recommended to do 1. as there is less of a chance of creating a directory error when trying to install LHAPDF.

To navigate to the LHAPDF file from your home directory from the terminal, type

cd LHAPDF

In this directory, type

tar xf LHAPDF-6.X.Y.tar.gz

This will extract the contents of the .tar.gz file into the LHAPDF directory. To check if this has occurred, type “ls” into the terminal and press Enter. You should see two files, one called “LHAPDF-6.3.0” and the other called “LHAPDF-6.3.0.tar.gz”. You’ll then want to move into make a new directory, let’s call it “LHAPDF_install” for convenience. To do this, type:

mkdir LHAPDF_install

To configure where the LHAPDF will be installed, you’ll want the exact path for how the VM should access your LHAPDF folder. To do this, simply type “pwd” and press Enter. You should get an address along the lines of

/home/VMusername/LHAPDF

Where “VMusername” is whatever you named your Virtual Machine. Copy this line and then type “cd” to go back all the way to your home directory.

At your home directory, reaccess your ~/.bashrc file by typing

nano ~/.bashrc

Scroll all the way down to the bottom of the file, where you inserted the previous paths when installing Python3.8. Above the first path you previously wrote, type:

export LHADIR=’/home/VMusername/LHAPDF/’

Then press Ctrl-X and then type ‘y’ to save the modifications. In the terminal type

source ~/.bashrc

You’ll then want to access the LHAPDF-6.3.0 directory. To do this, type:

cd LHAPDF/LHAPDF-6.3.0/

Hit Enter, then type:

./configure –prefix=/home/VMusername/LHAPDF/LHAPDF_install

And then hit Enter.

The address after the “=” sign could vary depending on how your setting up LHAPDF. Though, if you’ve followed the instructions of this guide exactly at detailed, the address should be akin to what’s shown. Whatever it is, you should paste exactly what the terminal printed after you typed “pwd” previously.

After that, type

make

And then hit Enter. Allow time for the data to process. After it finishes, type

make install

Then hit Enter.

Et voilà! You’ve successfully installed LHAPDF!


            3. Installing Data Sets

            To install PDF data sets, you have to LHAPDF website, the link to which is at the top of this manual. Navigate to the PDF sets section. You’ll see a very large list of PDF sets. All of these set contain different data that can be processed using LHAPDF. To download a set, click on “tarball”. You’ll be given the option of opening it or saving it; choose the latter option.

            Once you’ve downloaded a data set, navigate to where it downloaded in your files (in most cases, this should be in your downloads directory). Right click on the downloaded data set and select “move to”.

            The tricky part is finding where to put it. Normally, you want to go to the path of the LHAPDF installation. If you followed the steps of this manual, within your LHAPDF from your home directory there should be a folder called “LHAPDF_install”. Navigate to this. There may be another folder within it called “LHAPDF_install”, and if there is, also navigate to that. You should end up in a directory with folders entitled “bin”,”include”,”lib”, and “share”. You’ll want to move your data set to the “share” folder. If you’re in the “move to” menu, double click on the “share” folder and then select the “move here” option at the top-right hand corner of the window.

            You’ll then have to extract the file from the .tar.gz file type. To do this, right click anywhere in the “share” folder and open up the terminal. From here, type:

(for example of downloading NNPDF40_nlo_as_01180)

 wget https://lhapdf.hepforge.org/?f=NNPDF40_nlo_as_01180.tar.gz -O NNPDF40_nlo_as_01180.tar.gz

sudo tar -xvzf name.tar.gz

Where “name” would be replaced with whatever comes before the “.tar.gz” in the data set file name.

Alternatively, if you want to download/update all of the PDF sets available on the LHAPDF website, then in the "share" folder, open up the terminal and type

lhapdf list 

lhapdf install

lhapdf update

lhapdf upgrade

In order to call a dataset from within a script, LHAPDF will need to know the address to access it. Type “pwd” and copy the address that appears while you are in your share folder. Renavigate back to your ~/.bashrc file to add one more path. Go to your home directory in your terminal and type

nano ~/.bashrc

Scroll all the way to the bottom of the editor to where your input the paths from part 2. of manual. Below these, type

export LHAPDF_DATA_PATH=’destination path’

Where “destination path” is what you copied from your share folder. It should be something along the lines of

/home/VMusername/LHAPDF/LHAPDF_install/LHAPDF_install/share/LHAPDF

Ctrl+X and type y to save the changes. You’ll then need to source the bashrc file to compile these changes. Type

source ~/.bashrc

Then press enter. After that, you should be available to use the extracted file from within a python script simply by calling the filename.

The grids installed on Rivanna are located at "/project/apps_data/lhapdf/pdfset-6.x"


          4. Using LHAPDF

All input and outputs are defined in DOUBLE PRECISION

There are three options to make a single PDF dataset:

PDF * lhapdf.mkPDF(int lhaid)

Below is an example:

“variable name” = lhapdf.mkPDF(“filename”)

            Returns PDFs as vector<PDF*>

PDF * lhapdf.mkPDF(const std.string &setname, int member)

Ex: “variable name” = lhapdf.mkPDF(setname,imem)

 

PDF * lhapdf.mkPDF(const str.string &setname_nmen)

Where “variable name” is whatever name you want to give to the assigned variable.

For making whole PDF sets:

“variable name” = lhapdf.getPDFSet(‘filename’)

            lhapdf.getPDFSet() will allow you to use the raw data from a dataset.

                        à “Info” is a class of function. In this case, Info() is a default constructor.


       5. Using LHAPDF in a Rivanna Job

If you have a job script and code prepared that utilizes LHAPDF, then you'll need to follow some of these simple rules for executing the job.


  1. Make sure to write a slurm script for running our code (make sure the code is in the same directory as the slurm file).
  2. To make a slurm file:
    1. Create a new file and end it with " .sh " (without the quotation marks).
    2. Start you slurm file with the following


      #!/usr/bin/env bash

      #SBATCH -p standard

      #SBATCH --output=result_%a.out

      #SBATCH -c 1

      #SBATCH -t 16:30:00

      #SBATCH -A spinquest


                 The specifics of these lines are covered more on the UVA SLURM Job manager webpage (Here).

                                       ** I recommend not putting "#SBATCH --output=result_%a.out" in your slurm file. While it normally would print out the results of your job, with LHAPDF, and prints out the results but not before printing out all of the LHAPDF dataset file names first. So, any result should be saved directly to a file (.txt,.dat,.png.,.pdf,etc.). It is however a good idea to include it if you want to troubleshoot any problems you are having with running your code over Rivanna, as an error message will be written at the bottom of the output file. 

        3. Assuming you're using a python script to run your LHAPDF script, underneath all of what you previously wrote, type:

module purge

module load gcc/9.2.0 lhapdf

echo $LHAPDF_DATA_PATH

ls $LHAPDF_DATA_PATH

python -c "import lhapdf"

python -V

4. Underneath all of that, type in the run command to run your program as you would normally on a command line. In the case that you're using a python script, type:


python ./test_script.py


Where "test_script" is whatever the name of your file is. To then submit that job to Rivanna, from your directory, open the terminal and type


sbatch (your slurm file)

To use other libraries that aren't included within Rivanna, first make sure that it is already available on Rivanna by typing "module avail" into the terminal command line to see if it available. If you find it within the list, put within your slurm file underneath "module purge" as

module load (your module)

Practice Example for Running Jobs on Rivanna

Here is a .py and .slurm practice file which will produce two fragmentation functions if ran through Rivanna.

PDF.slurm

PDFs_FFs_in_LHAPDF.py 

Practice running this as a job over Rivanna with the above guide!

  • Using iminuit

You'll probably be using iminuit at some point to help fit data. Rivanna unfortuantely does not have iminuit pre-installed; however, you can install it to your local directory. To do this, from within your local directory, open the terminal and type

module load anaconda/2020.11-py3.8
source activate my_env # replace with env of interest
pip install iminuit 

Alternatively, this could be put inside your slurm file, but once you install iminuit once to your directory, it should stay there. 

 




                

  • No labels