Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/pierre-guillou/pdiags_bench
13 February 2023, 11:53:21 UTC
  • Code
  • Branches (5)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/main
    • refs/heads/mesu
    • refs/heads/mesu_bench
    • refs/heads/saddle_pairs
    • refs/heads/zomo_variants
    No releases to show
  • 95e447f
  • /
  • build_software.py
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:367166979a1d9d6461c4b690bba20a93ecbd0f0d
origin badgedirectory badge Iframe embedding
swh:1:dir:95e447fd05b7bb9564fba216a8957d42fbdb26ff
origin badgerevision badge
swh:1:rev:8a2de479abf7bcbf2002b4f8f620c635217cc088
origin badgesnapshot badge
swh:1:snp:49df835a23e1f2a8e7b91973ed24143919372067
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 8a2de479abf7bcbf2002b4f8f620c635217cc088 authored by Julien J Tierny on 30 January 2023, 16:30:54 UTC
added reference to the arxiv repo
Tip revision: 8a2de47
build_software.py
import argparse
import os
import pathlib
import shutil
import subprocess
import time
import zipfile

from download_datasets import download_file


def create_dir(dirname):
    try:
        os.mkdir(dirname)
    except FileExistsError:
        pass


PERSEUS_URL = "https://people.maths.ox.ac.uk/nanda/source/perseus_4_beta.zip"
JAVAPLEX_URL = (
    "https://github.com/appliedtopology/javaplex"
    "/files/2196392/javaplex-processing-lib-4.3.4.zip"
)


def download_perseus(perseus_url=PERSEUS_URL):
    # download Perseus from project server
    perseus_zip = perseus_url.split("/")[-1]
    download_file(perseus_url, perseus_zip)
    create_dir("perseus")
    with zipfile.ZipFile(perseus_zip, "r") as src:
        src.extractall("backends_src/perseus")
    # remove zip
    os.remove(perseus_zip)


def download_javaplex(jplex_url=JAVAPLEX_URL):
    # download JAR from GitHub repository latest release
    jplex_zip = jplex_url.split("/")[-1]
    download_file(jplex_url, jplex_zip)
    create_dir("javaplex")
    with zipfile.ZipFile(jplex_zip, "r") as src:
        src.extract("javaplex/library/javaplex.jar")
    # move JAR to cwd
    os.replace("javaplex/library/javaplex.jar", "backends_src/javaplex.jar")
    os.removedirs("javaplex/library")
    # remove zip
    os.remove(jplex_zip)


def clean_env():
    env = dict(os.environ)
    env.pop("PYTHONPATH", None)
    env.pop("LD_LIBRARY_PATH", None)
    env.pop("PV_PLUGIN_PATH", None)
    env["CMAKE_PREFIX_PATH"] = ""
    return env


def build_paraview(prefix, vers, opts):
    pv = "backends_src/paraview-ttk"
    builddir = f"build_dirs/paraview_{vers}"
    create_dir(builddir)
    subprocess.run(["git", "checkout", vers], cwd=pv, check=True)
    subprocess.check_call(
        ["cmake"]
        + ["-S", pv]
        + ["-B", builddir]
        + ["-DCMAKE_BUILD_TYPE=Release", f"-DCMAKE_INSTALL_PREFIX={prefix}"]
        + opts,
        env=clean_env(),
    )
    # double configure needed here to prevent undefined reference errors
    subprocess.check_call(["cmake", builddir])
    subprocess.check_call(
        ["cmake", "--build", builddir, "--target", "install", "--parallel"]
    )


def main(subset=False):

    softs = [
        "dipha",
        "gudhi",
        "phat",
        "DiscreteMorseSandwich",
    ]

    extended_softs = [
        "CubicalRipser_2dim",
        "CubicalRipser_3dim",
        "diamorse",
        "Eirene.jl",
        "oineus",
        "ripser",
        "perseus",
        "JavaPlex",
        "PersistenceCycles",
    ]

    if not subset:
        softs += extended_softs
        pathlib.Path(".not_all_apps").unlink(missing_ok=True)
    else:
        # use a hidden file to mark that only a part of the benchmark
        # has been built
        pathlib.Path(".not_all_apps").touch()

    # 1. Fetch submodules
    subprocess.run(["git", "submodule", "update", "--init", "--recursive"], check=True)
    subprocess.run(
        ["git", "submodule", "foreach", "git", "checkout", "--", "."], check=True
    )

    # 2. Build each library
    create_dir("build_dirs")
    for soft in softs:
        print(f"Building {soft}...")
        soft_src = f"backends_src/{soft}"
        start = time.time()
        builddir = f"build_dirs/{soft}"
        if "CubicalRipser" in soft:
            # build CubicalRipser
            subprocess.run(["make"], cwd=soft_src, check=True)
        elif soft == "perseus":
            # download Perseus
            download_perseus()
            # build perseus
            try:
                shutil.copy2("patches/Makefile.perseus", f"{soft_src}/Makefile")
            except shutil.SameFileError:
                pass
            subprocess.run(["make"], cwd=soft_src, check=True)
        elif soft == "diamorse":
            # build diamorse
            try:
                subprocess.run(["git", "checkout", "."], cwd=soft_src, check=True)
                subprocess.run(
                    [
                        "git",
                        "apply",
                        "../../patches/diamorse_0001-Makefile-Target-Python2.patch",
                        "../../patches/diamorse_0002-persistence.py-Add-Gudhi-format-output.patch",
                    ],
                    cwd=soft_src,
                    check=True,
                )
                subprocess.run(["make", "all"], cwd=soft_src, check=True)
            except subprocess.CalledProcessError:
                print("Missing cython, python2-numpy to build diamorse")
        elif soft == "Eirene.jl":
            subprocess.run(["julia", "-e", 'using Pkg; Pkg.add("Eirene")'], check=True)
        elif soft == "JavaPlex":
            download_javaplex()
            subprocess.run(
                [
                    "javac",
                    "-classpath",
                    "backends_src/javaplex.jar",
                    "jplex_persistence.java",
                ],
                check=True,
            )
        elif soft == "gudhi":
            create_dir(builddir)
            subprocess.check_call(
                ["cmake"]
                + [
                    "-DWITH_GUDHI_TEST=OFF",
                    "-DWITH_GUDHI_UTILITIES=OFF",
                    "-DCMAKE_BUILD_TYPE=Release",
                ]
                + ["-S", soft_src]
                + ["-B", builddir]
            )
            subprocess.check_call(["cmake", "--build", builddir, "--parallel"])
        elif soft == "ripser":
            subprocess.run(["make"], cwd=soft_src, check=True)
        elif soft == "PersistenceCycles":
            # first build ParaView 5.6.1
            pv_ver = "v5.6.1"
            prefix = f"build_dirs/install_paraview_{pv_ver}"
            build_paraview(
                prefix,
                pv_ver,
                ["-DPARAVIEW_BUILD_QT_GUI=OFF", "-DVTK_Group_ParaViewRendering=OFF"],
            )
            # apply patch (to prevent segfaults)
            subprocess.run(["git", "checkout", "."], cwd=soft_src, check=True)
            subprocess.run(
                [
                    "git",
                    "apply",
                    "../../patches/PersistenceCycles_0001-Fix-Wreturn-type.patch",
                    "../../patches/PersistenceCycles_0003-Output-Diagram-in-Gudhi-format.patch",
                ],
                cwd=soft_src,
                check=True,
            )
            create_dir(builddir)
            env = clean_env()
            env["CMAKE_PREFIX_PATH"] = prefix
            subprocess.check_call(
                ["cmake"]
                + ["-S", f"{soft_src}/ttk-0.9.7"]
                + ["-B", builddir]
                + [
                    f"-DVTK_DIR={os.getcwd()}/{prefix}/lib/cmake/paraview-5.6",
                    "-DCMAKE_BUILD_TYPE=Release",
                    f"-DCMAKE_INSTALL_PREFIX={prefix}",
                    "-DTTK_ENABLE_KAMIKAZE=ON",
                ],
                env=env,
            )
            subprocess.check_call(
                ["cmake", "--build", builddir, "--target", "install", "--parallel"]
            )
        elif soft == "DiscreteMorseSandwich":
            # first build ParaView 5.10.1
            pv_ver = "v5.10.1"
            prefix = f"build_dirs/install_paraview_{pv_ver}"
            build_paraview(
                prefix,
                pv_ver,
                ["-DPARAVIEW_USE_QT=OFF", "-DVTK_Group_ENABLE_Rendering=NO"],
            )
            # apply DiscreteMorseSandwich patch
            subprocess.run(
                [
                    "git",
                    "apply",
                    "../../patches/DiscreteMorseSandwich_filters.patch",
                ],
                cwd=soft_src,
                check=True,
            )
            # prep env variable
            create_dir(builddir)
            env = clean_env()
            env["CMAKE_PREFIX_PATH"] = prefix
            # configure TTK build directory
            subprocess.check_call(
                ["cmake"]
                + ["-S", f"{soft_src}"]
                + ["-B", builddir]
                + [
                    f"-DVTK_DIR={os.getcwd()}/{prefix}/lib/cmake/paraview-5.10",
                    "-DCMAKE_BUILD_TYPE=Release",
                    f"-DCMAKE_INSTALL_PREFIX={prefix}",
                    "-DTTK_ENABLE_KAMIKAZE=ON",
                ],
                env=env,
            )
            # build & install TTK in ParaView install prefix
            subprocess.check_call(
                ["cmake", "--build", builddir, "--target", "install", "--parallel"]
            )
        else:
            if soft == "dipha":
                subprocess.run(
                    [
                        "git",
                        "apply",
                        "../../patches/Dipha_0001-Print-sum-of-ranks-memory-peaks.patch",
                    ],
                    cwd=soft_src,
                    check=True,
                )
            elif soft == "oineus":
                subprocess.run(
                    [
                        "git",
                        "apply",
                        "../../patches/oineus_0001-New-example-file-for-simplicial-complexes.patch",
                    ],
                    cwd=soft_src,
                    check=True,
                )
            create_dir(builddir)
            subprocess.check_call(
                ["cmake", "-S", soft_src, "-B", builddir, "-DCMAKE_BUILD_TYPE=Release"]
            )
            subprocess.check_call(["cmake", "--build", builddir, "--parallel"])

        end = time.time()
        print(f"Built {soft} in {int(end - start)} seconds\n")


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=("Build benchmark native software"))
    parser.add_argument(
        "-s",
        "--subset",
        help="Only build the most important benchmark applications",
        action="store_true",
    )
    args = parser.parse_args()
    main(args.subset)

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top