Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into general-tensor-in…
Browse files Browse the repository at this point in the history
…dices
  • Loading branch information
Krzmbrzl committed May 16, 2024
2 parents 5403c14 + 5993ba5 commit 27cb596
Show file tree
Hide file tree
Showing 83 changed files with 1,185 additions and 18,719 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_UNITY_BUILD=${{ matrix.build_type == 'Debug' }}
-DMPIEXEC_PREFLAGS='--bind-to;none;--allow-run-as-root'
-DCMAKE_PREFIX_PATH='/usr/local/opt/boost@1.76'
-DCMAKE_PREFIX_PATH='/usr/local/opt/boost'
-DSEQUANT_EVAL_TESTS=ON
-DSEQUANT_USE_SYSTEM_BOOST_HASH=OFF
-DCMAKE_CXX_STANDARD=20
Expand All @@ -47,7 +47,7 @@ jobs:

- name: Install prerequisite MacOS packages
if: ${{ matrix.os == 'macos-latest' }}
run: brew install ninja gcc@10 boost@1.76 eigen open-mpi ccache
run: brew install ninja boost eigen open-mpi ccache catch2

- name: Install prerequisites Ubuntu packages
if: ${{ matrix.os == 'ubuntu-22.04' }}
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/formatting_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Formatting check

on: [push, pull_request]

jobs:
check:
name: "Check formatting"
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- uses: jidicula/[email protected]
with:
clang-format-version: "17"
exclude-regex: "/SeQuant\\/external/"

9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ include(FindOrFetchRangeV3)
# Boost will be added after defining SeQuant
include(external/boost.cmake)

# LibPerm
include(FindOrFetchLibPerm)

# embedded bliss-0.73
add_library(SeQuant-bliss
SeQuant/external/bliss/defs.cc
Expand Down Expand Up @@ -395,6 +398,9 @@ include(CTest)

if (BUILD_TESTING)

# need catch2
include(FindOrFetchCatch2)

set(utests_src
tests/unit/test_space.cpp
tests/unit/test_index.cpp
Expand Down Expand Up @@ -434,12 +440,11 @@ if (BUILD_TESTING)
tests/unit/test_eval_btas.cpp tests/unit/test_eval_ta.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif (TARGET tiledarray)

set(utests_deps SeQuant)
set(utests_deps SeQuant Catch2::Catch2)

set(unit_test_executable unit_tests-sequant)
add_executable(${unit_test_executable} EXCLUDE_FROM_ALL
tests/unit/test_main.cpp
tests/unit/catch.hpp
tests/unit/test_config.hpp
${utests_src})
target_link_libraries(${unit_test_executable} ${utests_deps})
Expand Down
4 changes: 2 additions & 2 deletions SeQuant/core/any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#define SEQUANT_HAS_CXX17_ANY
#endif // 10.14 or later
#endif // have macos version
//#else // libc++ on macos
//#define SEQUANT_HAS_CXX17_ANY
// #else // libc++ on macos
// #define SEQUANT_HAS_CXX17_ANY
#endif // libc++ on macos
#endif // c++17

Expand Down
8 changes: 4 additions & 4 deletions SeQuant/core/asy_cost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ AsyCost const &AsyCost::zero() {
return zero;
}

AsyCost& AsyCost::operator+=(AsyCost const& other) {
AsyCost &AsyCost::operator+=(AsyCost const &other) {
*this = *this + other;
return *this;
}

AsyCost& AsyCost::operator-=(AsyCost const& other) {
AsyCost &AsyCost::operator-=(AsyCost const &other) {
*this = *this - other;
return *this;
}
Expand Down Expand Up @@ -226,11 +226,11 @@ bool operator>(AsyCost const &lhs, AsyCost const &rhs) {
return !(lhs < rhs || lhs == rhs);
}

bool operator<=(AsyCost const& lhs, AsyCost const& rhs) {
bool operator<=(AsyCost const &lhs, AsyCost const &rhs) {
return lhs < rhs || lhs == rhs;
}

bool operator>=(AsyCost const& lhs, AsyCost const& rhs) {
bool operator>=(AsyCost const &lhs, AsyCost const &rhs) {
return lhs > rhs || lhs == rhs;
}

Expand Down
6 changes: 4 additions & 2 deletions SeQuant/core/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ struct Complex {
std::wstring result = L"{";
result += to_latex(this->real());
if (this->imag() > 0) {
result = L"\\bigl(" + result + L" + i " + to_latex(this->imag()) + L"\\bigr)";
result =
L"\\bigl(" + result + L" + i " + to_latex(this->imag()) + L"\\bigr)";
} else if (this->imag() < 0)
result = L"\\bigl(" + result + L" - i " + to_latex(-this->imag()) + L"\\bigr)";
result =
L"\\bigl(" + result + L" - i " + to_latex(-this->imag()) + L"\\bigr)";
result += L"}";
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion SeQuant/core/context.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <SeQuant/core/context.hpp>
#include <SeQuant/core/attr.hpp>
#include <SeQuant/core/context.hpp>
#include <SeQuant/core/utility/context.hpp>

namespace sequant {
Expand Down
92 changes: 48 additions & 44 deletions SeQuant/core/eval_expr.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <SeQuant/core/eval_expr.hpp>
#include <SeQuant/core/attr.hpp>
#include <SeQuant/core/complex.hpp>
#include <SeQuant/core/container.hpp>
#include <SeQuant/core/context.hpp>
#include <SeQuant/core/eval_expr.hpp>
#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/hash.hpp>
#include <SeQuant/core/index.hpp>
#include <SeQuant/core/tensor.hpp>
#include <SeQuant/core/wstring.hpp>
#include <SeQuant/core/utility/indices.hpp>
#include <SeQuant/core/wstring.hpp>

#include <range/v3/action.hpp>
#include <range/v3/algorithm.hpp>
Expand All @@ -18,14 +18,14 @@

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iterator>
#include <memory>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include <cmath>
#include <tuple>

namespace sequant {

Expand All @@ -45,29 +45,53 @@ std::wstring_view const var_label = L"Z";

} // namespace

template <
typename Iterable,
std::enable_if_t<!std::is_same_v<InnerOuterIndices, std::decay_t<Iterable>>,
bool> = true>
std::string indices_to_annot(Iterable const& indices) noexcept {
using ranges::views::intersperse;
using ranges::views::join;
using ranges::views::transform;
NestedTensorIndices::NestedTensorIndices(const sequant::Tensor& tnsr) {
auto push_ix = [this](Index const& ix) {
if (ix.has_proto_indices())
inner.push_back(ix);
else
outer.push_back(ix);
};

auto idx_label = [](Index const& idx) { return to_string(idx.label()); };
for (auto const& ix : tnsr.const_braket()) {
push_ix(ix);
for (auto const& ix_proto : ix.proto_indices()) push_ix(ix_proto);
}

return indices | transform(idx_label) | intersperse(",") | join |
ranges::to<std::string>;
if (!inner.empty()) {
ranges::actions::stable_sort(outer, Index::LabelCompare{});
ranges::actions::unique(outer, [](Index const& ix1, Index const& ix2) {
return ix1.label() == ix2.label();
});
}
}

std::string indices_to_annot(InnerOuterIndices const& inout) noexcept {
auto const& in = inout.inner;
auto const& out = inout.outer;
if (out.empty()) {
return indices_to_annot(in);
} else {
return indices_to_annot(in) + ";" + indices_to_annot(out);
}
std::string EvalExpr::braket_annot() const noexcept {
if (!is_tensor()) return {};

// given an iterable of sequant::Index objects, returns a string made
// of their full labels separated by comma
// eg. (a_1^{i_1,i_2},a_2^{i_2,i_3}) -> "a_1i_1i_2,a_2i_2i_3"
// eg. (i_1, i_2) -> "i_1,i_2"
auto annot = [](auto&& ixs) -> std::string {
using namespace ranges::views;

auto full_labels = ixs //
| transform(&Index::full_label) //
| transform([](auto&& fl) { //
return sequant::to_string(fl);
});
return full_labels //
| intersperse(std::string{","}) //
| join //
| ranges::to<std::string>;
};

auto nested = NestedTensorIndices{as_tensor()};

return nested.inner.empty() //
? annot(nested.outer)
: annot(nested.outer) + ";" + annot(nested.inner);
}

size_t EvalExpr::global_id_{};
Expand Down Expand Up @@ -145,29 +169,9 @@ Variable const& EvalExpr::as_variable() const noexcept {
return expr().as<Variable>();
}

InnerOuterIndices EvalExpr::inner_outer_indices() const noexcept {
if (is_scalar()) return {};

assert(is_tensor());
auto const& t = expr()->as<Tensor>();

container::svector<Index> inner;
container::svector<Index> outer;
for (auto const& idx : t.const_indices()) {
inner.emplace_back(idx);
for (auto const& pidx : idx.proto_indices()) outer.emplace_back(pidx);
}
ranges::stable_sort(outer, Index::LabelCompare{});
ranges::actions::unique(outer);
ranges::actions::remove_if(
inner, [&outer](Index const& i) { return ranges::contains(outer, i); });
return {std::move(inner), std::move(outer)};
}

std::string EvalExpr::label() const noexcept {
if (is_tensor())
return to_string(as_tensor().label()) + "(" +
indices_to_annot(inner_outer_indices()) + ")";
return to_string(as_tensor().label()) + "(" + braket_annot() + ")";
else if (is_constant()) {
auto const& c = as_constant();
auto real = Constant{c.value().real()}.value<double>();
Expand Down
43 changes: 16 additions & 27 deletions SeQuant/core/eval_expr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ enum class EvalOp {
enum class ResultType { Tensor, Scalar };

///
/// @see EvalExpr::inner_outer_indices
/// \brief Represents the outer indices and the inner indices of a nested
/// tensor.
///
struct InnerOuterIndices {
container::svector<Index> const inner;
container::svector<Index> const outer;
};

///
/// \param inout InnerOuterIndices object.
/// \return String of comma-separated labels of inner indices followed by the
/// labels of outer indices, separated by a semicolon.
/// \note The nested tensor is a concept that generalizes the sequant::Tensor
/// with and without proto indices. sequant::Tensors with proto indices have
/// outer and inner indices, whereas, those without proto indices only have
/// outer indices.
///
std::string indices_to_annot(InnerOuterIndices const& inout) noexcept;
struct NestedTensorIndices {
container::svector<Index> outer, inner;

explicit NestedTensorIndices(Tensor const&);
};

///
/// \brief The EvalExpr class represents the object that go into the nodes of
Expand Down Expand Up @@ -181,26 +181,15 @@ class EvalExpr {
[[nodiscard]] Variable const& as_variable() const noexcept;

///
/// \brief Separates indices of a tensor into inner and outer index groups.
///
/// \details - If the expression this object holds is a Constant, then the
/// resulting inner and outer indices are empty.
/// - The outer indices are empty if neither of the indices in the
/// tensor's braket have at least one proto-index.
/// - The proto-indices are collected, sorted using
/// Index::LabelCompare, and de-duplicated to form the outer
/// indices.
/// - The non-proto indices make up the inner indices if they are not
/// already in the outer indices.
///
/// \return InnerOuterIndices object.
/// \brief Get the label for this object useful for logging.
///
[[nodiscard]] InnerOuterIndices inner_outer_indices() const noexcept;
[[nodiscard]] std::string label() const noexcept;

///
/// \brief Get the label for this object useful for logging.
/// \return A string usable as TiledArray annotation if is_tensor() true,
/// empty string otherwise.
///
[[nodiscard]] std::string label() const noexcept;
[[nodiscard]] std::string braket_annot() const noexcept;

private:
EvalOp op_type_;
Expand Down
2 changes: 1 addition & 1 deletion SeQuant/core/eval_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <SeQuant/core/asy_cost.hpp>
#include <SeQuant/core/binary_node.hpp>
#include <SeQuant/core/eval_expr.hpp>
#include <SeQuant/core/tensor.hpp>
#include <SeQuant/core/math.hpp>
#include <SeQuant/core/tensor.hpp>

namespace sequant {

Expand Down
4 changes: 2 additions & 2 deletions SeQuant/core/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Created by Eduard Valeyev on 2019-02-06.
//

#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/abstract_tensor.hpp>
#include <SeQuant/core/algorithm.hpp>
#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/logger.hpp>
#include <SeQuant/core/tensor.hpp>
#include <SeQuant/core/tensor_network.hpp>
#include <SeQuant/core/tensor_canonicalizer.hpp>
#include <SeQuant/core/tensor_network.hpp>

#include <range/v3/all.hpp>

Expand Down
2 changes: 0 additions & 2 deletions SeQuant/core/expr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace sequant {

namespace {


template <typename T>
constexpr bool is_an_expr_v = meta::is_base_of_v<Expr, T>;
template <typename T>
Expand Down Expand Up @@ -1684,7 +1683,6 @@ T &ExprPtr::as() {

} // namespace sequant


#endif // SEQUANT_EXPR_HPP

#include "expr_operator.hpp"
Expand Down
2 changes: 1 addition & 1 deletion SeQuant/core/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Created by Eduard Valeyev on 4/30/20.
//

#include <SeQuant/core/index.hpp>
#include <SeQuant/core/context.hpp>
#include <SeQuant/core/index.hpp>
#include <SeQuant/core/latex.hpp>
#include <SeQuant/core/wstring.hpp>

Expand Down
Loading

0 comments on commit 27cb596

Please sign in to comment.