GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - HAWinther/FML: A C++ library for working with particles and grids in a parallel setting.

BranchesTags
Open more actions menu

Latest commit

 

History

938 Commits
938 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
Documentation
Documentation
 
 
FML
FML
 
 
LICENCE
LICENCE
 
 
README.md
README.md
 
 

Repository files navigation

FML

CI Nightly accuracy checks contributions welcome HitCount

This is FML 2.0. The library is constantly under construction. The changes since 1.0 are in the changelog; for the old version see Version 1.0. Development happens in the FMLDevelop branch.

FML is a C++17 library for large-scale-structure cosmology. It started as a set of general building blocks for working in parallel: grids that do FFTs, particle containers, mass assignment and PDE solvers, where the library takes care of the MPI and OpenMP parallelisation so that you can write an algorithm without thinking about how the data is split over tasks. On top of these it has grown to cover almost everything one needs in large-scale structure: the expansion history and the linear Einstein–Boltzmann equations, initial conditions and simulations, halo and void finding, clustering statistics, survey estimators and parameter inference. And not only for ΛCDM, but for any cosmological model you add.

The ideas behind FML

FML is built up from a domain decomposition, grids and particles on it, the algorithms that work on them, and the programs built from those

  • Parallel without having to think about it. The data structures know how they are distributed. A grid knows which part of the box it owns, exchanges its ghost cells and does distributed FFTs; a particle container sends particles to the task that owns them. Algorithms are written on top of these and run the same way in serial, with MPI, with OpenMP or with both. The one thing to keep in mind is that collective functions are called by all tasks.
  • Built up in layers: domain → grids and particles → algorithms → programs. A domain says which MPI task owns which part of the box: slabs (the default), pencils (x and y split, for up to N_mesh² tasks) or load-balanced ranges of a Peano–Hilbert curve. Grids (FFTWGrid on slabs, PencilGrid on pencils, the general MPIGrid and the adaptively refined AdaptiveMPIGrid) and particles (MPIParticles) live on a domain. The particles can be on the same domain as a grid or on another one, and the operations between them (mass assignment, interpolation) work across domains. The algorithms are written against a common grid interface, so most of the library, SimulationCode and SnapshotAnalyzer run on slabs or on pencils.
  • General through templates. Classes and algorithms are templated on the particle type and on the number of dimensions. Your own particle struct works as it is: it needs get_pos(), and the library detects at compile time which other members (velocity, mass, ID, ...) it has and uses them if it needs them. Most of the library is header-only.
  • Easy to extend. A module is a folder with its headers, a README, an example and tests. A new analysis method uses the grids and particles and gets the parallelisation from them.
  • Lightweight. You need a C++17 compiler and make. FFTW (Fourier transforms) and GSL (splines, ODEs) are used by most of the library; MPI, OpenMP, Lua, HDF5, CGAL and Python are optional and only needed by the modules that use them. There are no large dependencies such as Boost: the multigrid solvers, halo finders, KD-tree, FFTLog, samplers, the Boltzmann solver and so on are all part of the library. This now includes the Delaunay triangulation: ZOBOV and the ORIGAMI halos no longer need CGAL, and once the DTFE is ported (in progress) CGAL will be optional everywhere.
  • Any cosmological model. The physics is implemented once and shared: the same background and the same quasi-static gravity (μ and Σ) drive the Einstein–Boltzmann solver, the growth factors, LPT, the halo model and the simulations. A new model (dark energy, modified gravity, interacting dark sectors, ...) is a header and an entry in a registry for the Einstein–Boltzmann solver and everything built on its background, and the gravity models of SimulationCode use the same quasi-static definitions. Some twenty models are included.
  • Programs as examples. SimulationCode (formerly COLASolver), SnapshotAnalyzer, the Einstein–Boltzmann solver, CosmologyFitting, AMRCode and TreePMCode were written to show what can be done with the library. They have grown into codes that are useful in their own right, and they are also the most demanding tests of the building blocks.
  • Tested and validated. About 200 test programs compare with analytic results, manufactured solutions, conservation laws and external codes (CLASS, CAMB, CCL, FAST-PT, MG-PICOLA, ...). They run in CI on every push with 1 and 4 MPI tasks, and with longer accuracy checks every night. The module READMEs say what has been validated and over which range.

What's inside

Parallel building blocks

  • Grids for FFTs (FFTWGrid, real and complex) split in slabs, or in pencils for many tasks, behind one grid interface; a general distributed grid (MPIGrid); and an adaptively refined grid distributed along a Peano–Hilbert curve.
  • MPIParticles: a container for any particle type that sends particles to the task that owns them, with slab, pencil or Peano–Hilbert domains.
  • Particle–grid assignment and interpolation (B-splines from NGP to PQS, interlacing, window deconvolution), also for particles on any domain, and non-uniform FFTs.
  • Multigrid solvers for general (non-linear) PDEs, on uniform and on adaptive grids.
  • Smoothing and convolutions, random fields, splines and ODE solvers (GSL wrappers), FFTLog, a KD-tree, Lua parameter files, and reading and writing Gadget (binary and HDF5), RAMSES and ascii files.

Simulations

  • SimulationCode: a complete PM/COLA N-body code driven by a parameter file. Many cosmologies and theories of gravity (f(R), DGP, symmetron, dilaton, Jordan–Brans–Dicke, cubic Galileon, reduced Horndeski, coupled and interacting dark energy, the Fading Dark Sector, dark scattering, μ–Σ), screening solved exactly with multigrid or approximated, massive neutrinos, separate CDM and baryons, lightcones, and power spectra, bispectra, halos and more computed on the fly.
  • The pieces to build your own: Gaussian and non-Gaussian initial conditions (N-GenIC compatible), 1LPT–3LPT and arbitrary-order LPT, PM forces and time stepping (COLA, FastPM, also with a scale-dependent kick, and BullFrog, which can start from the Big Bang), initial conditions made by stepping from the Big Bang (StepFromBigBang: BullFrog, a new step exact to third-order LPT, and a scale-dependent hybrid for massive neutrinos and modified gravity), short-range forces for P3M/TreePM, and modified-gravity solvers.
  • Smaller, newer codes: an AMR N-body code (RAMSES-like), a TreePM N-body code (GADGET-like, individual time steps), wave dark matter (Schrödinger–Poisson), and gas dynamics with finite volumes and SPH. A moving-mesh (AREPO-style) solver is planned; its tessellation is done (below).

Analysing simulations and surveys

  • Power spectra, multipoles, bispectra and higher polyspectra; pair counting and 2- and 3-point correlation functions.
  • Surveys: power-spectrum multipoles with window functions, and BAO reconstruction.
  • Halos and structures: friends-of-friends (also relaxed FoF), spherical-overdensity masses, a phase-space halo and subhalo finder, merger histories, void finders (ZOBOV, voxel watershed, spherical), the DTFE, and cosmic-web classification.
  • FML's own Delaunay triangulation and periodic Voronoi tessellation (2D and 3D): exact predicates, MPI parallel for any distribution of the particles with results bitwise identical for any number of tasks, fast updates when the points move, no dependencies, and 1.5–4 times faster than CGAL. The DTFE, the watershed, ZOBOV and the ORIGAMI halos use it by default; CGAL's tessellation is an option.
  • Summary statistics: counts-in-cells, kNN distributions, density-split and marked statistics, Minkowski functionals, weak-lensing maps, and HOD mocks and baryonification.
  • SnapshotAnalyzer: all of this on Gadget snapshots from a parameter file.

Theory

  • An Einstein–Boltzmann solver (background, recombination, perturbations, CMB and matter spectra, lensing) for ΛCDM and many extensions, validated against CLASS.
  • Perturbation theory: one-loop SPT, Lagrangian and IR-resummed Eulerian PT for biased tracers in redshift space, TNS and EFTofLSS, and hybrid-bias spectra.
  • Nonlinear power spectra: Halofit, HMcode-2016/2020, a general halo model, ReACT (modified gravity, dark energy, massive neutrinos and coupled dark matter such as the Fading Dark Sector), EuclidEmulator2, and spherical collapse with screening.

Inference

  • MCMC (adaptive Metropolis–Hastings) and HMC samplers, a minimizer with profile likelihoods, and cosmological fits with supernovae (Pantheon+, DES-SN5YR, DES-Dovekie, Union3), BAO and RSD (DESI DR1/DR2, BOSS, eBOSS), DESI DR1 ShapeFit and full-shape power spectra, KiDS-1000 cosmic shear, BBN and the CMB (Planck 2018 plik_lite, low-ℓ and lensing, Planck PR4 CamSpec, ACT DR6 lensing), and trainable neural-network emulators.
  • Field-level inference with linear, LPT and particle-mesh forward models and their adjoints, on slabs or pencils, and joint sampling of the field, amplitude and bias with replica-exchange tempering.

The capability matrix lists every module with its scope, dependencies, parallel behaviour and tests, and the website explains the methods.

Example

The power spectrum of a particle catalogue, with your own particle type distributed over the MPI tasks (FML/QuickStart/example/pofk.cpp):

// Quick start 1: the power spectrum of a particle catalogue.
//
// Your own particle type, distributed over the MPI tasks, and P(k) with cloud-in-cell assignment and interlacing. The
// catalogue is uniformly random, so P(k) is the shot noise 1/n: we check that.
#include <FML/ComputePowerSpectra/ComputePowerSpectrum.h>
#include <FML/MPIParticles/MPIParticles.h>
#include <FML/RandomGenerator/RandomGenerator.h>

#include <cmath>
#include <iostream>

// Any type with get_pos() (positions in the box [0,1)) works as a particle: no base class needed
struct Particle {
    double x[3];
    double * get_pos() { return x; }
    constexpr int get_ndim() const { return 3; }
};

int main() {
    // The same random catalogue on every task (box units)
    const size_t Npart = 200000;
    std::vector<Particle> catalogue(Npart);
    FML::RANDOM::RandomGenerator rng(1234);
    for (auto & p : catalogue)
        for (auto & x : p.x)
            x = rng.generate_uniform();

    // Distribute it: every task keeps the particles in its part of the box
    FML::PARTICLE::MPIParticles<Particle> part;
    part.create(catalogue, 2 * Npart / FML::NTasks + 1000, FML::PARTICLE::Input::Replicated);

    // P(k) on a 64^3 grid, CIC with interlacing, without subtracting the shot noise
    const int Nmesh = 64;
    FML::CORRELATIONFUNCTIONS::PowerSpectrumBinning<3> pofk(Nmesh / 2);
    pofk.subtract_shotnoise = false;
    FML::CORRELATIONFUNCTIONS::compute_power_spectrum<3>(
        Nmesh, part.get_particles_ptr(), part.get_npart(), part.get_npart_total(), pofk, "CIC", true);

    // In a box of 1000 Mpc/h: k in h/Mpc, P in (Mpc/h)^3. The shot noise is V/N
    const double box = 1000.0, shotnoise = box * box * box / double(Npart);
    pofk.scale(box);
    double mean = 0.0;
    for (int i = 0; i < pofk.n; i++)
        mean += pofk.pofk[i] / shotnoise / pofk.n;
    if (FML::ThisTask == 0) {
        std::cout << "# k [h/Mpc]   P(k) [(Mpc/h)^3]   P / shot noise\n";
        for (int i = 0; i < pofk.n; i++)
            std::cout << pofk.kbin[i] << " " << pofk.pofk[i] << " " << pofk.pofk[i] / shotnoise << "\n";
        std::cout << "Mean P / shot noise = " << mean << " (expected 1)\n";
    }
    return std::abs(mean - 1.0) < 0.05 ? 0 : 1;
}

Compile it from the folder that contains FML/, linking FML/Global/Global.cpp:

c++ -std=c++17 -O3 -I. -DUSE_FFTW pofk.cpp FML/Global/Global.cpp -lfftw3 -o pofk
mpicxx -std=c++17 -O3 -I. -DUSE_MPI -DUSE_FFTW pofk.cpp FML/Global/Global.cpp -lfftw3_mpi -lfftw3 -o pofk  # with MPI

QuickStart has this and two more short programs: a particle-mesh N-body simulation in about 60 lines, and the same calculation with the particles on slabs, on pencils and on a Peano–Hilbert curve. Each module folder also has examples (example/) and a README with its conventions.

Building

You need a C++17 compiler and make. FFTW is needed for anything with Fourier transforms. MPI, OpenMP, GSL, Lua, HDF5, CGAL and Python are optional and only needed by the modules that use them (CGAL now only for the DTFE, which is being moved to FML's own triangulation). The tests also run in single precision (SINGLE_PRECISION_FFTW) every night. Set paths and compilers in FML/Makefile.local; the defaults are in Makefile.config.

git clone https://github.com/HAWinther/FML.git

make -C FML examples -j4                                  # build the examples
make -C FML test MPIRUN=mpirun NP_LIST="1 2 4"           # run the regression tests with 1, 2 and 4 MPI tasks
make -C FML/tests USE_MPI=false USE_OMP=false USE_FFTW=false USE_GSL=false USE_LUA=false test_core   # minimal serial test

The examples need no data files: they make their own input. The build guide explains the options and how to use FML from your own code. Clean the objects when you change the compiler, precision or feature flags.

Version 1.0

The previous version, FML 1.0, is the tag v1.0.0. To get it (with the TestData submodule its examples use):

git clone --branch v1.0.0 --depth 1 --recursive https://github.com/HAWinther/FML.git FML-1.0

Python

A small Python package has catalogue statistics: kNN distances and CDFs, and counts-in-spheres PDFs and moments, with NumPy results.

python -m pip install ./FML/PythonAnalysis
python FML/PythonAnalysis/examples/catalogue_statistics.py

There is also a SWIG wrapper tutorial and a pybind11 wrapper for the halo model; build them with make -C FML python.

Documentation

  • Capability matrix: every module, with its scope, dependencies, parallel behaviour and tests.
  • Build and API guide: compiling, linking, MPI and FFTW conventions.
  • References: the papers and external codes behind each module.
  • SimulationCode: the N-body code, its parameters and tests.
  • Changelog and development backlog.
  • Website and Doxygen reference; their sources are in Documentation, with the LaTeX source of the FML book.

The regression tests run in CI on every push. They compare against analytic results or reference codes where possible. The module READMEs describe what has been validated and over which range, so check them before relying on a method in a new regime.

Contributors

FML is developed by Hans A. Winther. Many people have helped improve it, among them Bartolomeo Fiorini, Guilherme Brando, Kazuya Koyama, Daniela Saadeh, Herman Sletmoen and Renate Mauland-Hus. The two main developers these days are Claude and Codex.

Licence

Except for third-party code carrying separate license notices, FML's original source code is licensed under the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version (GPL-3.0-or-later). See LICENCE for the full license text.

FML is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Third-party code retains its existing copyright and license notices. In particular, FML/Global/SystemMemory.h carries a CC BY 3.0 notice; this GPL statement does not relicense that file. Its compatibility or replacement must be resolved before distributing a combined GPL-covered work that includes it. FML/Emulator/EMantis is a port of e-MANTIS (GPL-3.0-or-later, its COPYING), and FML/Emulator/Bacco a port of baccoemu (MIT, its LICENSE, which must be kept with copies); the baccoemu networks are not distributed with FML (get_data.sh downloads them). Other bundled third-party components and external dependencies remain subject to their respective licenses. This statement covers source code and does not change the licensing of separately published documentation.

About

A C++ library for working with particles and grids in a parallel setting.

Resources

Readme
GPL-3.0 license
Activity

Stars

23 stars

Watchers

3 watching

Forks

19 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.