{"id":13830823,"url":"https://github.com/Einsums/Einsums","last_synced_at":"2025-07-09T12:31:50.947Z","repository":{"id":38079667,"uuid":"447276816","full_name":"Einsums/Einsums","owner":"Einsums","description":"Provides compile-time contraction pattern analysis to determine optimal tensor operation to perform.","archived":false,"fork":false,"pushed_at":"2024-10-29T19:35:11.000Z","size":24752,"stargazers_count":46,"open_issues_count":8,"forks_count":7,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-29T21:38:49.343Z","etag":null,"topics":["cp-decomposition","cpp","cpp20","dense-matrices","einsum","linear-algebra","matrix","matrix-computations","matrix-library","scientific-computing","tensor","tensor-contraction","tensor-decomposition","tensors","tucker-decomposition"],"latest_commit_sha":null,"homepage":"https://einsums.github.io/Einsums/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Einsums.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-12T15:47:35.000Z","updated_at":"2024-10-29T19:33:42.000Z","dependencies_parsed_at":"2023-10-15T10:31:41.753Z","dependency_job_id":"b67624d6-d07b-4c84-a17f-c8704b0f398d","html_url":"https://github.com/Einsums/Einsums","commit_stats":null,"previous_names":["jturney/einsums","jturney/einsumsincpp"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Einsums%2FEinsums","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Einsums%2FEinsums/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Einsums%2FEinsums/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Einsums%2FEinsums/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Einsums","download_url":"https://codeload.github.com/Einsums/Einsums/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225539538,"owners_count":17485349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cp-decomposition","cpp","cpp20","dense-matrices","einsum","linear-algebra","matrix","matrix-computations","matrix-library","scientific-computing","tensor","tensor-contraction","tensor-decomposition","tensors","tucker-decomposition"],"created_at":"2024-08-04T10:01:09.598Z","updated_at":"2025-07-09T12:31:50.934Z","avatar_url":"https://github.com/Einsums.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# Einsums in C++\n\n|   |   |\n|---|---|\n| **Status** | [![codecov](https://codecov.io/github/Einsums/Einsums/graph/badge.svg?token=Z8WA6CEGQA)](https://codecov.io/github/Einsums/Einsums) ![GitHub branch check runs](https://img.shields.io/github/check-runs/Einsums/Einsums/main) |\n| **Release** | ![GitHub Release](https://img.shields.io/github/v/release/Einsums/Einsums) ![GitHub commits since latest release](https://img.shields.io/github/commits-since/Einsums/Einsums/latest) |\n| **Documentation** | [![Documentation](https://img.shields.io/badge/docs-latest-green?style=flat)](https://einsums.github.io/Einsums/) |\n| **Connect With Us** | [![Discord](https://img.shields.io/discord/1357368862512906360?logo=discord\u0026label=Discord)](https://discord.gg/8GvtkyWZUv) |\n\nProvides compile-time contraction pattern analysis to determine optimal operation to perform.\n\n## Requirements\nA C++ compiler with C++20 support.\n\nThe following libraries are required to build Einsums:\n\n* BLAS and LAPACK\n* HDF5\n\nThe following libraries are also required, but will be fetched if they can not be found.\n\n* fmtlib \u003e= 11\n* Catch2 \u003e= 3\n* Einsums/h5cpp\n* p-ranav/argparse\n* gabime/spdlog \u003e= 1\n\nOn my personal development machine, I use MKL for the above requirements. On GitHub Actions, stock BLAS, LAPACK, and FFTW3 are used.\n\nOptional requirements:\n\n* A Fast Fourier Transform library, either FFTW3 or DFT from MKL.\n* HIP for graphics card support. Uses hipBlas, hipSolver, and the HIP language. Does not yet support hipFFT.\n* cpptrace for backtraces.\n* LibreTT for GPU transposes.\n* pybind11 for the Python extension module.\n\n## Examples\nThis will optimize at compile-time to a BLAS dgemm call.\n```C++\n#include \"Einsums/TensorAlgebra.hpp\"\n\nusing einsums;  // Provides Tensor and create_random_tensor\nusing einsums::tensor_algebra;  // Provides einsum and Indices\nusing einsums::index;  // Provides i, j, k\n\nTensor\u003c2\u003e A = create_random_tensor(\"A\", 7, 7);\nTensor\u003c2\u003e B = create_random_tensor(\"B\", 7, 7);\nTensor\u003c2\u003e C{\"C\", 7, 7};\n\neinsum(Indices{i, j}, \u0026C, Indices{i, k}, A, Indices{k, j}, B);\n```\n\nTwo-Electron Contribution to the Fock Matrix\n```C++\n#include \"Einsums/TensorAlgebra.hpp\"\n\nusing namespace einsums;\n\nvoid build_Fock_2e_einsum(Tensor\u003c2\u003e *F,\n                          const Tensor\u003c4\u003e \u0026g,\n                          const Tensor\u003c2\u003e \u0026D) {\n    using namespace einsums::tensor_algebra;\n    using namespace einsums::index;\n\n    // Will compile-time optimize to BLAS gemv\n    einsum(1.0, Indices{p, q}, F,\n           2.0, Indices{p, q, r, s}, g, Indices{r, s}, D);\n\n    // As written cannot be optimized.\n    // A generic arbitrary contraction function will be used.\n    einsum(1.0, Indices{p, q}, F,\n          -1.0, Indices{p, r, q, s}, g, Indices{r, s}, D);\n}\n```\n\nHere are some comparisons between different methods of building the Hartree-Fock G matrix out of the two-electron integrals and the density matrix.\nThe code for this is similar to the sample above.\nThe first plot uses timings for 100 ortbitals using several methods: C for loops with compiler loop vectorization; C for loops with\nOpenMP loop vectorization and parallelization; Fortran do-concurrent loops; BLAS with a for loop for calculating the K matrix, gemv for the\nJ matrix, and axpy for the G matrix; BLAS with a for loop to permute the two-electron integrals, then gemv for the J and K matrices\nand axpy for the G matrix; Einsums without permuting the two-electron integrals, using the generic algorithm for the K matrix; and\nEinsums with a permutation of the two-electron integrals, using a selected algorithm for the K matrix.\n\n![einsum Performance](/docs/sphinx/_static/index-images/Performance.png)\n\nThe following shows the difference in overall performance as the number of orbitals increases.\n\n![einsums Growth](/docs/sphinx/_static/index-images/Performance_comp.png)\n\nThese timings were computed on a system with  an Intel Core i7-13700K with 32 GB of DDR5 RAM and an\nAMD Radeon 7900X graphics card running Debian 12, kernel version 6.1.\n\nW Intermediates in CCD\n```C++\nWmnij = g_oooo;\n// Compile-time optimizes to gemm\neinsum(1.0,  Indices{m, n, i, j}, \u0026Wmnij,\n       0.25, Indices{i, j, e, f}, t_oovv,\n             Indices{m, n, e, f}, g_oovv);\n\nWabef = g_vvvv;\n// Compile-time optimizes to gemm\neinsum(1.0,  Indices{a, b, e, f}, \u0026Wabef,\n       0.25, Indices{m, n, e, f}, g_oovv,\n             Indices{m, n, a, b}, t_oovv);\n\nWmbej = g_ovvo;\n// As written uses generic arbitrary contraction function\neinsum(1.0, Indices{m, b, e, j}, \u0026Wmbej,\n      -0.5, Indices{j, n, f, b}, t_oovv,\n            Indices{m, n, e, f}, g_oovv);\n```\n\nCCD Energy\n```C++\n/// Compile-time optimizes to a dot product\neinsum(0.0,  Indices{}, \u0026e_ccd,\n       0.25, Indices{i, j, a, b}, new_t_oovv,\n             Indices{i, j, a, b}, g_oovv);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEinsums%2FEinsums","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEinsums%2FEinsums","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEinsums%2FEinsums/lists"}