Reference system

The example Linux installation described below was done on the following system:
Machine: x86_64-based GNU/Linux cluster
Distribution: Ubuntu 4.4.0-210-generic
Processor: Intel Xeon E5-2670, 2300 MHz, 24 cores
RAM: 128 GB

STEP 1: Download L-Galaxies 2020

OPTION 1: Download zip file using browser:

  1. Go to https://github.com/LGalaxiesPublicRelease/LGalaxies2020_PublicRepository
  2. Click the green "Code" drop-down menu, and select "Download ZIP" [~42.2 MB]
  3. Move the downloaded file (master.zip) to a suitable base directory.
  4. In the terminal (or otherwise), navigate to that base directory, then unzip the file:
    • unzip ./master.zip
    This will create a new directory called /LGalaxies2020_PublicRepository-master, hereafter, the "project root directory".
  5. You can now delete the .zip file, if you wish:
    • rm ./master.zip
  6. Manually add an empty /output folder in the project root directory:
    • cd ./LGalaxies2020_PublicRepository-master
    • mkdir output


OPTION 2: Download zip file using wget:

  1. Navigate to a directory where you'd like L-Galaxies kept
  2. Download L-Galaxies 2020:
    • wget -P ./ https://github.com/LGalaxiesPublicRelease/LGalaxies2020_PublicRepository/archive/refs/heads/master.zip
  3. Unzip the file:
    • unzip ./master.zip
    This will create a new directory called/LGalaxies2020_PublicRepository-master, hereafter, the "project root directory".
  4. You can now delete the .zip file, if you wish:
    • rm ./master.zip
  5. Manually add an empty /output folder in the project root directory:
    • cd ./LGalaxies2020_PublicRepository-master
    • mkdir output


OPTION 3: Download as a local Git repository:
This option requires having a GitHub account and Git. Git is normally already installed on standard Linux systems. If it isn't on yours, download it following the instructions at: https://github.com/git-guides/install-git Once you have Git and a GitHub account, proceed as follows:

  1. Navigate to a directory where you'd like L-Galaxies kept
  2. Clone the repository:
    • git clone https://github.com/[GITHUB_USERNAME]/https://github.com/LGalaxiesPublicRelease/LGalaxies2020_PublicRepository


OPTION 4: Download as a local Git repository via the Eclipse IDE:
The L-Galaxies 2020 code can also be obtained from GitHub via the Eclipse IDE, which offers a more intuitive way of editing and debugging code using a Graphical User Interface (GUI). To install L-Galaxies 2020 this way, skip straight to STEP 8 below, where information on how to install Eclipse and synchronise it with L-Galaxies 2020 is provided.

STEP 2: Download spectrophotometric tables and treefiles

  1. Download the standard SpecPhotTables [~1.6 GB] [direct download]
  2. Move the downloaded .tar file (SpecPhotTables.tar) into the project root directory.
  3. In the terminal, navigate to the project root directory.
  4. Untar the file:
    • tar -xf ./SpecPhotTables.tar
    This will create a folder called /SpecPhotTables containing the downloaded spectrophotometic tables
  5. Download the treefiles (choose one of the following options):
  6. Millennium-I: Millennium-II:
  7. Move the downloaded .tar file into the /MergerTrees directory, which is in the project root directory.
  8. In the terminal, navigate to the /MergerTrees.
  9. Untar the treefiles:
    • tar -xf ./MR[II]_MergerTrees_[TREEFILE_NUMBERS]
    This will create a folder called either /MR/treedata, /MRII/treedata, or /MRII containing the downloaded treefiles.


NOTE: Because the full set of Millennium-I treefiles (MR_allMergerTrees.tar) are stored at an "http" address, rather than "https", some browsers may prevent it from being downloaded automatically. To get around this (at least in Chrome), right-click the download link above, select "Save link as..." and confirm a destination folder. Then, if the browser says that the file "can't be downloaded securely", click the up arrow next to the download and select "Keep".

STEP 3: Check your compiler and C libraries

L-Galaxies requires a C compiler (e.g. gcc), the make command, and the GNU Scientific Libraries (GSL) to run. Linux distributions typically come with all three of these installed as standard. You can check if gcc and make are installed on your system using the following commands, which return the directory in which they are stored (usually /usr/bin/gcc and /usr/bin/make):

GSL is typically installed in /usr/local/include/gsl (for the header files) and /usr/local/lib/ (for the libraries). If you can't find the explicit path yourself, you might be able to simply point L-Galaxies to the relevant environment variables, GSL_INCL = -I$(INCLUDE) and GSL_LIBS = -L$(LD_LIBRARY_PATH) (see STEP 4).

Note that if your Linux system runs with a modular environment, you may need to load the GSL libraries before they can be used:

You can check which packages are available as modules by running:
  • module avail

If your system doesn't have gcc and/or make, the simplest way to install them is probably via the "build-essential" package for either Ubuntu or Debian Linux:

Likewise, if your system doesn't have GSL, it should be installable as follows:
  • sudo apt-get install libgsl-dev libgsl-dbg
If all else fails, you can download the latest version of gcc (gcc-12.2.0) from here, following the installation instructions provided here. Likewise, the make tool can be downloaded from here. The latest version of GSL (gsl-2.7.1) can be downloaded from here, with installation instructions provided in the README and INSTALL files and general GSL documentation available here.

STEP 4: Check the compiler configuration

The L-Galaxies 2020 makefile needs to be told which C compiler to use and where the GSL libraries are stored. This information is provided by the user as a SYSTYPE configuration in the My_Makefile_compilers file, located in the project root directory.

By default, the SYSTYPE is set to "Linux", which should be suitable for most Linux installations. This configuration assumes the gcc compiler is to be used, and that the GSL header files and libraries are stored in their default locations: /usr/local/include and /usr/local/lib. If your GSL files are not stored in these locations, you will need to change the GSL_INCL and GSL_LIBS paths accordingly. As mentioned above, if you can't find the explicit path to GSL yourself, you might be able to simply point L-Galaxies to the relevant environment variables with something like GSL_INCL = -I$(INCLUDE) and GSL_LIBS = -L$(LD_LIBRARY_PATH).

By default, no compiler optimisation flags are added to this configuration. Feel free to add ones of your own, if you wish.

If L-Galaxies 2020 compiles without any errors when you run the make command described in STEP 5 below, you are probably good to go! If not, here are a few common compiler issues and our (unofficial) fixes for them:


Common compiler issues

  1. Running with an old C standard: If your distribution is quite old, it may not be running with the latest C standard. If so, you may need to inform the compiler of this in My_Makefile_compilers by adding the -std flag to the CC call. (e.g. CC = gcc -std=C99 for systems running with C99).

  2. Running with old C libraries: Likewise, an old distribution may not have a version of the GNU C libraries (glibc). If so, you may need to install and build new C libraries following the instructions provided here (which is compilcated!). Alternatively, a quick hack (if you do have a recent version of the GSL libraries, see above), is to replace the #include <math.h> statements at the top of each L-Galaxies code .c file with #include <gsl/gsl_math.h>

  3. Multiple tentative definitions: If a compilation crashes with an error stating that "multiple tenative definitions of a global variable in different compilation units" are not allowed, you may need to add the -fcommon flag to the CC call in My_Makefile_compilers. Note that this flag is set by default when running with SYSTYPE = "cygwin".

  4. Shared libraries: If your system has shared GSL libraries (i.e. .so files), rather than local archived ones (i.e. .a files), you may need to replace the default -static flag for GSL_LIBS in My_Makefile_compilers with a -shared flag. You may also find that the GSL libraries are stored in /usr/include and /usr/lib (rather than /usr/local/include and /usr/local/lib), so should update the paths in My_Makefile_compilers accordingly.

  5. Shared object errors: Similarly, if you are getting errors like: "Relocation R_X86_64_32 against undefined symbol '[LGALAXIES_PARAMETER]' can not be used when making a shared object", then you may need to add the -fPIC flag to the CC call in My_Makefile_compilers

STEP 5: Compile and run the code

Compiling and running L-Galaxies 2020 is done as follows:

  1. In the terminal, navigate to the project root directory
  2. Compile the code:
    • make
  3. Run the code:
    • ./L-Galaxies ./input/[INPUT FILE]


There are four standard input files to choose from (for info on which to use, see STEP 7):


Once L-Galaxies 2020 has finished running, the output file(s) generated will be stored in the /output folder. These can be read in to python for analysis as described in STEP 6.

Straight out of the box, L-Galaxies 2020 will run on treefile 5 of Millennium-I with only redshift 0 data outputted. However, various other standard set-ups are also possible (see STEP 7).

STEP 6: Reading-in L-Galaxies 2020 outputs in python

By default, L-Galaxies 2020 outputs are written as binary files. To be read, binary files require prior knowledge of the structure of the data in the file. This is why default L-Galaxies output structures (compatible for python) are provided in the /AuxCode/awk/output/python folder (see "Changing which properties are outputted" in STEP 7).


L-Galaxies 2020 also comes with a set of simple python scripts to read output files (according to the output structure), convert properties from code units to physical units, select sub-samples, plot a few key relations, etc. These python scripts can be found in /AuxCode/Python.


To run the python scripts on the default output produced by L-Galaxies 2020, simply execute the main_lgals.py file. This will generate a pickled version of the L-Glaxies 2020 output (.npy file) in the /output folder, as well as some plots of key galaxy population relations in the /figures folder. main_lgals.py also contains a number of switches which can be used to modify how/what data is read-in and plotted.


These python scripts use latex syntax for some of the axis labels in the plots. If your Linux installation does not have (la)tex capabilities, you may need to install (some) of the following packages:


For more information on how to use/modify these python scripts, feel free to drop me an email (r.yates3 -at- herts.ac.uk).

(For those who prefer to handle data in IDL, there are some IDL scripts available for reading-in/plotting L-Galaxies outputs. If you are interested in getting a copy of these, feel free to speak to me at the workshop, or drop me an email.)

STEP 7: Changing the model [OPTIONAL]

Default vs. Modified model
Input files (i.e. the .par files) are provided for the Default Model (DM) and Modified Model (MM) versions of L-Galaxies 2020 (see Yates+21a for details). In brief, the Default Model allows the majority of material released by supernovae and stellar winds to mix with the ambient ColdGas before some is blown out as galactic winds. The Modified Model allows the majority of this newly-released material to be directly ejected into the surrounding HotGas, without first mixing with the ColdGas. Depending on which model you want to use, the corresponding input file is one of the following:

Note that these input files are for runs on the Millenium-I merger trees. If you want to run on Millennium-II instead, see below.



Millennium-I vs. Millennium-II
By default, L-Galaxies 2020 will try to run on Millennium-I merger trees. To switch to Millennium-II, make sure you've downloaded some Millennium-II treefiles (see STEP 2), and then do the following:

  1. Open the My_Makefile_options file in the project root directory
  2. Uncomment the MRII switch
  3. Save and close My_Makefile_options
  4. Use the default model (DM) or modified model (MM) Millennium-II input files as the argument when running the code (see STEP 5 above):
    • input_MRII_W1_PLANCK_LGals2020_DM.par
    • input_MRII_W1_PLANCK_LGals2020_MM.par



Snapshot vs. Galaxytree mode
Snapshot mode (the default for L-Galaxies 2020) will only output data for a user-defined set of redshifts (i.e. snapshots). Galaxytree mode will instead output data from all snapshots, along with the IDs needed to link a given galaxy to its progenitors and descendents (note that this generates much larger output files).

To use/modify snapshot mode:

  1. Open desired_output_redshifts.txt in the /inputs folder
  2. Add the redshifts you wish to be outputted to the top of this file, one on each line, with an empty line at the end of your list (L-Galaxies will match these to their nearest snapshots automatically)
  3. Open the My_Makefile_options file in the project root directory
  4. Set the NOUT parameter to equal the number of redshifts you set to be outputted in desired_output_redshifts.txt
  5. Make sure that the GALAXYTREE switch is commented-out
  6. Save and close My_Makefile_options
  7. Compile and run L-Galaxies 2020 as described in STEP 5

To use galaxytree mode:
  1. Open the My_Makefile_options file in the project root directory
  2. Uncomment the GALAXYTREE switch
  3. Save and close My_Makefile_options
  4. Compile and run L-Galaxies 2020 as described in STEP 5



Changing the output file name

  1. Open the input file you wish to use (see above) in the /inputs folder
  2. Change FileNameGalaxies to an appropriate name. This will be the prefix in the name of the output file(s) that L-Galaxies generates.
  3. Save and close the input file
  4. Compile and run L-Galaxies 2020 as described in STEP 5



Changing the treefiles used

  1. Open the input file you wish to use (see above) in the /inputs folder
  2. Set FirstFile to the first treefile you wish to use
  3. Set LastFile to the last treefile you wish to use
  4. Save and close the input file
  5. Compile and run L-Galaxies 2020 as described in STEP 5

To run L-Galaxies 2020 on the full set of Millennium-I or II trees, set FirstFile to 0 and LastFile to 511. For testing purposes on Millennium-I, treefile 5 alone is normally sufficient. For quick but statistically-significant runs on Millennium-I, treefiles 0-9 are normally sufficient. For quick but statistically-significant runs on Millennium-II, treefiles 40-79 are normally sufficient.



Model switches
L-Galaxies 2020 comes with a series of pre-defined model options (or "switches") that change e.g. the physics models used, the treefiles used, which properties are tracked/outputted, etc. These switches are defined in the My_Makefile_options file in the project root directory. There meanings should be quite self explanatory, but if you are unsure, feel free to ask! You are also able to add your own switches to your version of the code. These should be defined in My_Makefile_options and then utilised in the necessary code files via "ifdef statements" (or equivalent). For example, to create a switch which prevents the property BulgeMassRings from being outputted:

  1. Open My_Makefile_options in the project root directory
  2. Add the following line:
    • OPT += -DNO_BULGEMASSRINGS_OUTPUT
  3. Save and close My_Makefile_options
  4. Put the following ifdef statement around the instances of BulgeMassRings in h_galaxy_output.h and save.c (see below for more details):
    • #ifndef NO_BULGEMASSRINGS_OUTPUT
    • ...
    • #endif //NO_BULGEMASSRINGS_OUTPUT
  5. Save and close the code files
  6. Open the output structure you are using (e.g. LGalaxy_snapshots.py, LGalaxy_galtree.py, or one you have created yourself)
  7. Remove BulgeMassRings by either setting it to "False" in the properties_used dictionary (at the bottom of the .py file), or directly commenting it out:
    • # ('BulgeMassRings',numpy.float32,12),



Changing which properties are outputted
By default (i.e. when in snapshot mode), L-Galaxies 2020 will output the properties listed in the Python-based "output structure" called LGalaxy_snapshots.py, which is in the /AuxCode/awk/output/python directory. The galaxytree equivalent of this, called LGalaxy_galtree.py, is also provided in the same directory. However, you are free to change which properties are actually outputted by L-Galaxies 2020. This is done as follows:

  1. Open h_galaxy_output.h in the /code folder
  2. In the GALAXY_OUTPUT structure, add/comment-out the property you wish to be outputted/not outputted
  3. For example, to remove BulgeMassRings, either put it in a newly-defined #ifndef (see above) or directly comment it out:
    • // float BulgeMassRings[RNUM];
  4. Save and close h_galaxy_output.h
  5. Open save.c in the /code folder
  6. In the prepare_galaxy_for_output() function, add/comment-out the property you wish to be outputted/not outputted
  7. For example, to remove BulgeMassRings, either put it in a newly-defined #ifndef (see above) or directly comment it out:
    • // o->BulgeMassRings[ll] = g->BulgeMassRings[ll];
  8. Save and close save.c
  9. Open the output structure you are using (e.g. LGalaxy_snapshots.py, LGalaxy_galtree.py, or one you have created yourself)
  10. In the LGalaxiesStruct structure, add/comment-out the property you wish to be outputted/not outputted
  11. For example, to remove BulgeMassRings, set it to "False" in the properties_used dictionary (at the bottom of the .py file), or directly comment it out:
    • # ('BulgeMassRings',numpy.float32,12),
    The property in question will now be included/removed from the output file generated by L-Galaxies 2020.
Note: The majority of errors occurring when trying to read-in L-Galaxies output binaries into a python script come from a mis-match between the actual output and the output structure. Therefore, make sure you keep your output structure up-to-date with your code!

STEP 8: Running L-Galaxies in the Eclipse IDE [OPTIONAL]

Although L-Galaxies 2020 can be used with any basic word processor and the command line, using an Interactive Development Environment (IDE) can make modifying, compiling, running, and debugging code significantly easier and more efficient. This can save a lot of time and energy in the long run. Therefore, we recommend an IDE (that is compatible with C makefile projects) is used when working with L-Galaxies. Below, we outline how to download, install, and synchronise the Java-based Eclipse IDE for L-Galaxies, which has already been extensively tried and tested with the code.


Check C compiler and libraries:

  1. If you haven't already, complete STEP 3 above to install the gcc compiler, make, and GSL.


Install jdk:
Eclipse is a java-based IDE, so it needs the Java Development Kit (JDK) to run. You can check if JDK is already installed on your system by running java -version in the command line. If this command returns information on a Java "Runtime Environment", you probably have a working version of JDK installed. If you don't have JDK, you can install the latest version as a private user as follows:

  1. Go to: https://www.oracle.com/java/technologies/downloads/#jdk19-linux
  2. Click the download link for the "x64 Compressed Archive" (if running on Debian/Ubuntu) or the "Arm 64 Compressed Archive" (if running on ARM CPU architecture)
  3. In the terminal, navigate to the directory where you want to install JDK, then move the downloaded .tar.gz file to that directory
  4. Unpack the tarball and install JDK:
    • tar zxvf jdk-19_linux-x64_bin.tar.gz
    • or
    • tar zxvf jdk-19_linux-aarch64_bin.tar.gz
    The JDK files will be installed to a directory called /jdk-19.
  5. Delete the .tar.gz file if you want to save disk space.


Install Eclipse IDE:

  1. Go to: https://www.eclipse.org/downloads/packages/installer
  2. Click the download link for the Eclipse 2022-09 R x86_64 Installer for Linux (probably the x86_64 version, unless you have AArch64 system architecture)
  3. Execute the installer (called eclipse-inst-jre-linux64.tar.gz)
  4. Once downloaded, in the terminal, navigate to the directory where you want to install the Eclipse IDE, then move the downloaded .tar.gz file to that directory
  5. Unpack the tarball:
    • tar zxvf eclipse-inst-jre-linux64.tar.gz
    • or
    • tar zxvf eclipse-inst-jre-linux-aarch64.tar.gz
  6. From the eclipse-installer sub-directory, install eclipse:
    • ./eclipse-inst
  7. When prompted, select: Eclipse IDE for C/C++ Developers
  8. Confirm that "Java 17+ VM:" is pointing to where JDK is installed, and confirm the default Installation Folder
  9. Click "install"
  10. Accept the user agreement
  11. Once it's installed, click "launch"
  12. Confirm the default Workspace and click "launch" again.


Clone L-Galaxies 2020 repository:

  1. In the Eclipse IDE, "Hide" the welcome screen (if still visible)
  2. Click the "Open Perspective" button in the top right corner (symbol of a GUI interface with a plus sign)
  3. Select "Git"
  4. Click "Clone a Git Repository" (left)
  5. Enter the L-Galaxies 2020 repository URI: https://github.com/LGalaxiesPublicRelease/LGalaxies2020_PublicRepository
  6. Click "Next"
  7. Make sure "master" is selected and click "Next"
  8. Confirm the destination directory (this will become your git-synchronised project root directory).
  9. Click "Finish"
  10. Eclipse will now clone a local version of the L-Galaxies 2020 repository (progress bar in the bottom right corner)
  11. Once cloned, right click / two-finger click the name of the project in the left-hand panel (LGalaxies2020_PublicRepository)
  12. Click "Import projects..."
  13. In the new window, click "Finish"
  14. The L-Galaxies 2020 code is now ready to be used in the standard "C/C++ Perspective" in Eclipse


Define as a makefile project:

  1. Click the "C/C++ Perspective" button in the top right corner (symbol of a GUI interface with a letter "C")
  2. Click on the project name in the left-hand panel (LGalaxies2020_PublicRepository), so that it's highlighted
  3. Press Ctrl+n on the keyboard
  4. Select: "Convert to C/C++ project (Adds C/C++ Nature)" and click "Next"
  5. Under "Convert to C or C++", select "C project"
  6. Under "Project Options", select "Makefile project" and the "Linux GCC" toolchain
  7. Click "Finish"


Set-up a run configuration:

  1. In the "C/C++ perspective", click the project name in the left-hand panel (LGalaxies2020_PublicRepository), so that it's highlighted
  2. From the top menu bar, select "Run" > "Run configurations..."
  3. In the new window (left-hand panel), click "C/C++ Allpication"
  4. Click the "New Launch configuration" button (symbol of a blank page with a plus sign)
  5. In the right-hand panel, set "Name" to: "LGalaxies2020_PublicRepository" (i.e. delete " Default")
  6. Set "C/C++ Application" to: "L-Galaxies"
  7. Click the "Arguments" tab (right-hand panel)
  8. Under "Program arguments", add the local path to your preferred input file (e.g. ./input/input_MR_W1_PLANCK_LGals2020_DM.par)
  9. Click "Apply", then click "Close"


Add an output folder:

  1. In the "C/C++ perspective", two-finger click the project name in the left-hand panel (LGalaxies2020_PublicRepository)
  2. Select "New" > "Folder"
  3. In the new window, set Folder name as "output"
  4. Click "Finish"


Download treefiles and specphot tables:

  1. If you haven't already, complete STEP 2 above for this cloned L-Galaxies 2020 repository


Check compiler configuration:

  1. Complete STEP 4 above to check the gcc compiler is configured correctly for L-Galaxies 2020 on your system
  2. For example, set the SYSTYPE to "Linux" in My_Makefile_compilers


Compile and run in Eclipse:

  1. In the "C/C++ perspective", click the project name in the left-hand panel (LGalaxies2020_PublicRepository), so that it's highlighted
  2. To compile: Click the "Build" button in the top left corner (symbol of a hammer)
  3. To run: Click the "Run" button in the top left corner (symbol of a green "play" sign)