Skip to content

Latest commit

 

History

History
514 lines (409 loc) · 20.5 KB

README.md

File metadata and controls

514 lines (409 loc) · 20.5 KB

CDT-plusplus

Quantize spacetime on your laptop.

Linux Clang Linux GCC macOS Build status CodeQL codecov Quality Gate Status cpp-linter Whitespace Open Issues Join the chat at https://gitter.im/acgetchell/CDT-plusplus Gitpod Ready-to-Code

Small foliated Delaunay triangulation

Table of contents

Introduction

For an introduction to Causal Dynamical Triangulations, including the foundations and recent results, please see the wiki.

Causal Dynamical Triangulations in C++ uses the Computational Geometry Algorithms Library, Boost, TBB, and Eigen. Arbitrary-precision numbers and functions are by MPFR and GMP. Melissa E. O'Neill's Permuted Congruential Generators library provides high-quality RNGs that pass L'Ecuyer's TestU01 statistical tests. doctest provides BDD/TDD. vcpkg provides library management and building. Doxygen provides automated document generation. {fmt} provides a safe and fast alternative to iostream. spdlog provides fast, multithreaded logging. PVS-Studio and CodeQL provide commercial-grade static analysis and security checks. CometML provides machine learning for model building.

Roadmap

  • Cross-platform support on Linux, macOS (x64 & arm64), and Windows
  • Cross-compiler support on gcc, clang, and MSVC
  • Develop with literate programming using Doxygen
  • Efficient Pure Functional Programming in C++ Using Move Semantics
  • Test using CTest
  • Develop using Behavior-driven development (BDD) with doctest
  • Continuous integration by Travis-CI on macOS and Linux with gcc/Clang
  • Continuous integration by AppVeyor on Windows with MSVC
  • Continuous integration by Github Actions on the leading edge
  • 3D Simplex
  • 3D Spherical triangulation
  • 2+1 foliation
  • S3 Bulk action
  • 3D Ergodic moves
  • High-quality Random Number Generation with M.E. O'Neill's PCG library
  • Multithreading via TBB
  • Automated code analysis with [LGTM]
  • Build/debug with Visual Studio 2019
  • Use {fmt} library (instead of iostream)
  • Static code analysis with PVS-Studio
  • 3D Metropolis algorithm
  • Multithreaded logging with spdlog
  • Visualization with Qt
  • Output via HDF5
  • 4D Simplex
  • 4D Spherical triangulation
  • 3+1 foliation
  • S4 Bulk action
  • 4D Ergodic moves
  • Initialize two masses
  • The shortest path algorithm
  • Einstein tensor
  • Complete test coverage
  • Complete documentation
  • Quantize Spacetime!

Quickstart

Open in Gitpod

Setup

This project uses CMake+Ninja to build and vcpkg to manage C++ libraries. Using C++20 features, it successfully builds with AppleClang-14, gcc-12, clang-15, and Visual Studio 2019.

Short

If you use Docker:

docker pull acgetchell/cdt-plusplus
docker run -it --name cdt cdt-plusplus

Binaries will be in /CDT-plusplus/build/src. Proceed to Use.

Long

On macOS or Linux, you will first need to install some prerequisites using your favorite package manager (e.g. homebrew or apt):

  • build-essential (Linux only)
  • automake
  • autoconf
  • autoconf-archive
  • libtool (macOS) or libtool-bin (Linux)
  • pkg-config
  • texinfo
  • yasm
  • ninja (macOS) or ninja-build (Linux)
  • pkg-config (macOS)

Next, install vcpkg:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install

vcpkg is then invoked by CMake in vcpkg manifest mode and install the project dependencies listed in vcpkg.json into a local vcpkg_installed directory.

Proceed to Build.

Build

You'll need a reasonably modern compiler that supports C++20 features.

Clone the repo:

git clone https://github.com/acgetchell/CDT-plusplus.git

To get CMake and the build scripts to run correctly, you'll need to set $VCPKG_ROOT to wherever you cloned vcpkg, e.g.

export VCPKG_ROOT="$HOME/vcpkg"

This will set the CMAKE_TOOLCHAIN_FILE option for CMake.

You may also need to set VCPKG_DEFAULT_TRIPLET to your platform triplet, e.g.

export VCPKG_DEFAULT_TRIPLET="x64-linux"

You can optionally pre-build the project dependencies (100+ packages) by running at the top level of the project:

vcpkg install

At this point, you can build via the scripts in scripts, which will build the project and install the dependencies into vcpkg_installed.

Project Layout

The project is similar to PitchFork Layout, as follows:

  • .github - GitHub specific settings
  • build - Ephemeral out-of-source build directory
  • cmake - Cmake configurations
  • docs - Documentation
  • external - Includes submodules of external projects (none so far, all using vcpkg)
  • include - Header files
  • scripts - Build, test, and run scripts
  • src - Source files
  • tests - Unit tests

Run

Run one of the following in scripts, depending on your operating system and environment:

  • No unit tests, Release mode - fast-build.sh or fast-build.bat
  • Unit tests, RelWithDebInfo mode - build.sh or build.bat
  • On an HPC cluster with SLURM, modules, and spack - slurm.sh
  • Full debugging mode with asserts and tests, debug.sh (this will take some time, ~280 seconds on my current laptop)

This should result in the main program executable, cdt in build/src or build\Debug, along with several others.

  • cdt-opt is a simplified version with hard-coded inputs, mainly useful for debugging and scripting
  • cdt-viewer (macOS only) is a simple Qt-based viewer for the output of cdt
  • initialize is used by CometML to run parameter optimization

Usage

CDT-plusplus uses program_options to parse options from the help message, and so understands long or short argument formats, provided the short argument given is an unambiguous match to a longer one. The help message should be instructive:

./build/src/cdt --help
Causal Dynamical Triangulations in C++ using CGAL.

Copyright (c) 2013 Adam Getchell

A program that generates d-dimensional triangulated spacetimes
with a defined causal structure and evolves them according
to the Metropolis algorithm. Specify the number of passes to control
how much evolution is desired. Each pass attempts a number of ergodic
moves equal to the number of simplices in the simulation.

Usage:./cdt (--spherical | --toroidal) -n SIMPLICES -t TIMESLICES
            [-d DIM]
            [--init INITIAL RADIUS]
            [--foliate FOLIATION SPACING]
            -k K
            --alpha ALPHA
            --lambda LAMBDA
            [-p PASSES]
            [-c CHECKPOINT]

Optional arguments are in square brackets.

Examples:
./cdt --spherical -n 32000 -t 11 --alpha 0.6 -k 1.1 --lambda 0.1 --passes 1000
./cdt -s -n32000 -t11 -a.6 -k1.1 -l.1 -p1000

Options:
  -h [ --help ]                 Show this message
  -v [ --version ]              Show program version
  -s [ --spherical ]            Spherical topology
  -e [ --toroidal ]             Toroidal topology
  -n [ --simplices ] arg        Approximate number of simplices
  -t [ --timeslices ] arg       Number of timeslices
  -d [ --dimensions ] arg (=3)  Dimensionality
  -i [ --init ] arg (=1)        Initial radius
  -f [ --foliate ] arg (=1)     Foliation spacing
  -a [ --alpha ] arg            Negative squared geodesic length of 1-d
                                timelike edges
  -k [ --k ] arg                K = 1/(8*pi*G_newton)
  -l [ --lambda ] arg           K * Cosmological constant
  -p [ --passes ] arg (=100)    Number of passes
  -c [ --checkpoint ] arg (=10) Checkpoint every n passes

The dimensionality of the spacetime is such that each slice of spacetime is d-1-dimensional, so setting d=3 generates 2 spacelike dimensions and one timelike dimension, with a defined global time foliation. A d-dimensional simplex will have some d-1 sub-simplices that are purely spacelike (all on the same timeslice) as well as some that are timelike (span two timeslices). In CDT we actually care more about the timelike links (in 2+1 spacetime), and the timelike faces (in 3+1 spacetime).

Documentation

Online documentation is at https://adamgetchell.org/CDT-plusplus/.

If you have Doxygen installed you can generate the same information locally using the configuration file in docs\Doxyfile by simply typing at the top level directory (Doxygen will recursively search):

doxygen ./docs/Doxyfile

This will generate a docs/html/ directory containing documentation generated from CDT++ source files. USE_MATHJAX has been enabled in Doxyfile so that the LaTeX formulae can be rendered in the html documentation using MathJax. HAVE_DOT is set to YES which allows various graphs to be autogenerated by Doxygen using GraphViz. If you do not have GraphViz installed, set this option to NO (along with UML_LOOK).

Testing

In the scripts directory, run build.sh or build.bat depending on your operating system.

Unit tests run (in build/tests or build\tests\Debug) via CDT_unit_tests, the doctest executable:

./CDT_unit_tests

or (Windows):

CDT_unit_tests.exe

You can also run both CTest integration and doctest unit tests in the build directory with:

cmake --build . --target test

or (Windows):

ctest -C Debug

In addition to the command line output, you can see detailed results in the build/Testing directory which is generated thereby.

Deactivate Unit tests with -D ENABLE_TESTING:BOOL=FALSE, e.g. scripts/fast-build.sh.

Static Analysis

This project follows the CppCore Guidelines as enforced by ClangTidy, which you can install and then run using the clang-tidy.sh script:

sudo apt-get install clang-tidy
cd scripts
./clang-tidy.sh

(Or use your favorite linter plugin for your editor/IDE.)

The cppcheck.sh script runs a quick static analysis using cppcheck.

brew install cppcheck
cd scripts
./cppcheck-build.sh

Clang comes with scan-build which can run a much more thorough, but slower static analysis integrated with CMake and Ninja.

cd scripts
./scan.sh

PVS-Studio - static analyzer for C, C++, C#, and Java code.

cd scripts
./pvs-studio.sh

Sanitizers

AddressSanitizer + UndefinedBehaviorSanitizer, LeakSanitizer, MemorySanitizer, and ThreadSanitizer are run with scripts/asan.sh, scripts/lsan.sh, scripts/msan.sh, and scripts/tsan.sh. They are also checked by Travis-CI during commits.

Optimizing Parameters

CometML is used to record Experiments which conduct Model Optimization. The script to do this is optimize-initialize.py. In order for this to work, you must install the following into your Python virtual environment.

pip install tensorflow
pip install comet-ml

You can then run experiments and look at results on https://www.comet.ml!

Visualization

Qt is used to visualize 3D triangulations via cdt-viewer.

Contributing

Please see CONTRIBUTING.md and our CODE_OF_CONDUCT.md.

Your code should pass Continuous Integration:

Optional:

Issues