Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ValeevGroup/SeQuant into …
Browse files Browse the repository at this point in the history
…general-tensor-indices
  • Loading branch information
Krzmbrzl committed Feb 15, 2024
2 parents 7e195c8 + 4b5cc99 commit 64d7af3
Show file tree
Hide file tree
Showing 6 changed files with 883 additions and 922 deletions.
9 changes: 5 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ prerequisites:
* mandatory:
* CMake 3.15 or later
* a C++17 compiler
* [Boost](https://www.boost.org/), version 1.67 or higher (N.B. critical bugs make the following versions unusable: 1.70, 1.77, 1.78); the following non-header-only Boost libraries are required:
* [Boost](https://www.boost.org/), version 1.81 or higher (N.B. older compilers _may_ work with older Boost releases). *SeQuant can download and build Boost if configured with `Boost_FETCH_IF_MISSING=ON`, but this is not recommended.* The following non-header-only Boost libraries are required, hence Boost must be configured/built:
- [Boost.Regex](https://www.boost.org/doc/libs/master/libs/regex/doc/html/index.html)
- [Boost.Locale](https://www.boost.org/doc/libs/master/libs/locale/doc/html/index.html)
* [Range-V3](https://github.com/ericniebler/range-v3.git), tag 0.12.0, *if not found, SeQuant will download and build Range-V3*
Expand All @@ -20,8 +20,9 @@ for the impatient (from the top of the SeQuant source directory):
* `cmake --build build --target check-sequant`

useful CMake variables:
* `BUILD_TESTING` --- enables unit tests targets, e.g. `check-sequant` [default=ON]
* `CMAKE_CXX_COMPILER` --- specifies the C++ compiler to use
* `CMAKE_PREFIX_PATH` --- this semicolon-separated list specifies search paths for dependencies (Boost, Range-V3, etc.)
* [`BUILD_TESTING`](https://cmake.org/cmake/help/latest/module/CTest.html) --- enables unit tests targets, e.g. `check-sequant` [default=ON]
* [`CMAKE_CXX_COMPILER`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html#variable:CMAKE_%3CLANG%3E_COMPILER) --- specifies the C++ compiler to use
* [`CMAKE_PREFIX_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html) --- this semicolon-separated list specifies search paths for dependencies (Boost, Range-V3, etc.)
* `SEQUANT_MIMALLOC` --- use [mimalloc](https://github.com/microsoft/mimalloc) for fast memory allocation
* `SEQUANT_EVAL_TRACE` --- enables tracing of expression interpretation; especially useful in combination with TiledArray's memory tracing mechanism (configure TiledArray with `TA_TENSOR_MEM_PROFILE=ON` to enable that)
* `Boost_FETCH_IF_MISSING` --- if set to `ON`, SeQuant will download and build Boost if it is not found by `find_package(Boost ...)`; this is not recommended. [default=OFF]
54 changes: 5 additions & 49 deletions SeQuant/core/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace sequant_boost = boost;
#include <SeQuant/external/boost/container_hash/hash.hpp>
#endif

#if SEQUANT_BOOST_VERSION < 108100
#error "SeQuant requires Boost 1.81 or later for hashing"
#endif

#include "meta.hpp"

namespace sequant {
Expand All @@ -27,17 +31,7 @@ enum class Impl { BoostPre181 = 1, Boost181OrLater = 2 };

/// @return the version of hashing used by SeQuant, depends on the version of
/// Boost
constexpr hash::Impl hash_version() {
#ifdef SEQUANT_USE_SYSTEM_BOOST_HASH
#if SEQUANT_BOOST_VERSION < 108100
return hash::Impl::BoostPre181;
#else
return hash::Impl::Boost181OrLater;
#endif
#else
return hash::Impl::Boost181OrLater;
#endif
}
constexpr hash::Impl hash_version() { return hash::Impl::Boost181OrLater; }

namespace detail {
template <typename T, typename Enabler = void>
Expand Down Expand Up @@ -116,45 +110,7 @@ template <class T>
inline void combine(std::size_t& seed, T const& v) {
_<T> hasher;

#ifdef SEQUANT_USE_SYSTEM_BOOST_HASH
#if SEQUANT_BOOST_VERSION >= 108100
boost::hash_combine(seed, hasher(v));
#else // older boost workarounds
// in boost 1.78 hash_combine_impl implementation changed
// https://github.com/boostorg/container_hash/commit/21f2b5e1db1a118c83a3690055c110d0f5637da3
// probably no longer need these acrobatics
if constexpr (sizeof(std::size_t) == sizeof(boost::uint32_t) &&
sizeof(decltype(hasher(v))) == sizeof(boost::uint32_t)) {
const boost::uint32_t value = hasher(v);
#if SEQUANT_BOOST_VERSION >= 107800
seed = boost::hash_detail::hash_combine_impl<32>::fn(
static_cast<boost::uint32_t>(seed), value);
#else
// N.B. seed passed by reference
boost::hash_detail::hash_combine_impl(
reinterpret_cast<boost::uint32_t&>(seed), value);
#endif
return;
} else if constexpr (sizeof(std::size_t) == sizeof(boost::uint64_t) &&
sizeof(decltype(hasher(v))) == sizeof(boost::uint64_t)) {
const boost::uint64_t value = hasher(v);

#if SEQUANT_BOOST_VERSION >= 107800
seed = boost::hash_detail::hash_combine_impl<64>::fn(
static_cast<boost::uint64_t>(seed), value);
#else
// N.B. seed passed by reference
boost::hash_detail::hash_combine_impl(
reinterpret_cast<boost::uint64_t&>(seed), value);
#endif
return;
} else {
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
#endif // older boost workarounds
#else // !defined(SEQUANT_USE_SYSTEM_BOOST_HASH)
sequant_boost::hash_combine(seed, hasher(v));
#endif

// assert(seed == seed_ref);
}
Expand Down
4 changes: 2 additions & 2 deletions SeQuant/domain/eval/eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void log_eval(Args const&... args) noexcept {
#endif
}

void log_cache_access(size_t key, CacheManager const& cm) {
[[maybe_unused]] void log_cache_access(size_t key, CacheManager const& cm) {
#ifdef SEQUANT_EVAL_TRACE
auto& l = Logger::get_instance();
if (l.log_level_eval > 0) {
Expand All @@ -50,7 +50,7 @@ void log_cache_access(size_t key, CacheManager const& cm) {
#endif
}

void log_cache_store(size_t key, CacheManager const& cm) {
[[maybe_unused]] void log_cache_store(size_t key, CacheManager const& cm) {
#ifdef SEQUANT_EVAL_TRACE
auto& l = Logger::get_instance();
if (l.log_level_eval > 0) {
Expand Down
2 changes: 1 addition & 1 deletion SeQuant/domain/eval/eval_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ inline void log_constant(Args const&... args) noexcept {
void log_ta_tensor_host_memory_use(madness::World& world,
std::string_view label = "");

struct EvalResult;
class EvalResult;

using ERPtr = std::shared_ptr<EvalResult>;

Expand Down
36 changes: 12 additions & 24 deletions tests/unit/test_mbpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,18 @@ TEST_CASE("NBodyOp", "[mbpt]") {

auto t = t1 + t2;

if constexpr (hash_version() == hash::Impl::BoostPre181) {
REQUIRE(
to_latex(simplify(f * t * t)) ==
to_latex(f * t1 * t1 + f * t2 * t2 + ex<Constant>(2) * f * t1 * t2));
} else {
// std::wcout << "to_latex(simplify(f * t * t)): "
// << to_latex(simplify(f * t * t)) << std::endl;
REQUIRE(
to_latex(simplify(f * t * t)) ==
to_latex(ex<Constant>(2) * f * t1 * t2 + f * t2 * t2 + f * t1 * t1));
}

if constexpr (hash_version() == hash::Impl::BoostPre181) {
REQUIRE(to_latex(simplify(f * t * t * t)) ==
to_latex(ex<Constant>(3) * f * t1 * t2 * t2 + f * t2 * t2 * t2 +
ex<Constant>(3) * f * t1 * t1 * t2 + f * t1 * t1 * t1));
} else {
// std::wcout << "to_latex(simplify(f * t * t * t): "
// << to_latex(simplify(f * t * t * t)) << std::endl;
REQUIRE(to_latex(simplify(f * t * t * t)) ==
to_latex(f * t2 * t2 * t2 + f * t1 * t1 * t1 +
ex<Constant>(3) * f * t1 * t1 * t2 +
ex<Constant>(3) * f * t1 * t2 * t2));
}
// std::wcout << "to_latex(simplify(f * t * t)): "
// << to_latex(simplify(f * t * t)) << std::endl;
REQUIRE(
to_latex(simplify(f * t * t)) ==
to_latex(ex<Constant>(2) * f * t1 * t2 + f * t2 * t2 + f * t1 * t1));

// std::wcout << "to_latex(simplify(f * t * t * t): "
// << to_latex(simplify(f * t * t * t)) << std::endl;
REQUIRE(to_latex(simplify(f * t * t * t)) ==
to_latex(f * t2 * t2 * t2 + f * t1 * t1 * t1 +
ex<Constant>(3) * f * t1 * t1 * t2 +
ex<Constant>(3) * f * t1 * t2 * t2));

} // SECTION("canonicalize")

Expand Down
Loading

0 comments on commit 64d7af3

Please sign in to comment.