diff --git a/CMakeLists.txt b/CMakeLists.txt index 02df7cb732..11a020e53f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -388,7 +388,7 @@ set(SeQuant_src SeQuant/domain/mbpt/spin.cpp SeQuant/domain/mbpt/spin.hpp SeQuant/domain/mbpt/vac_av.hpp - SeQuant/domain/mbpt/vac_av.ipp + SeQuant/domain/mbpt/vac_av.cpp SeQuant/domain/mbpt/utils.hpp SeQuant/domain/mbpt/utils.cpp SeQuant/version.cpp diff --git a/SeQuant/domain/mbpt/models/cc.hpp b/SeQuant/domain/mbpt/models/cc.hpp index 0759d60f2b..5753428c88 100644 --- a/SeQuant/domain/mbpt/models/cc.hpp +++ b/SeQuant/domain/mbpt/models/cc.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/SeQuant/domain/mbpt/op.cpp b/SeQuant/domain/mbpt/op.cpp index b2f87195e9..adde256dc1 100644 --- a/SeQuant/domain/mbpt/op.cpp +++ b/SeQuant/domain/mbpt/op.cpp @@ -1236,13 +1236,11 @@ bool lowers_rank_to_vacuum(const ExprPtr& op_or_op_product, return can_change_qns(op_or_op_product, qns_t{}, excitation_type_qns(k)); } -#include - namespace tensor { -ExprPtr detail::expectation_value_impl( - ExprPtr expr, std::vector> nop_connections, - bool use_top, bool full_contractions) { +ExprPtr expectation_value_impl(ExprPtr expr, + std::vector> nop_connections, + bool use_top, bool full_contractions) { simplify(expr); auto isr = get_default_context().index_space_registry(); const auto spinor = get_default_context().spbasis() == SPBasis::Spinor; @@ -1466,38 +1464,17 @@ ExprPtr ref_av(ExprPtr expr, std::vector> nop_connections, const bool full_contractions = (isr->reference_occupied_space() == isr->vacuum_occupied_space()) ? true : false; - return detail::expectation_value_impl(expr, nop_connections, use_top, - full_contractions); + return expectation_value_impl(expr, nop_connections, use_top, + full_contractions); } ExprPtr vac_av(ExprPtr expr, std::vector> nop_connections, bool use_top) { - return detail::expectation_value_impl(expr, nop_connections, use_top, - /* full_contractions*/ true); + return expectation_value_impl(expr, nop_connections, use_top, + /* full_contractions*/ true); } } // namespace tensor } // namespace op -bool can_change_qns(const ExprPtr& op_or_op_product, const qns_t target_qns, - const qns_t source_qns = {}) { - qns_t qns = source_qns; - if (op_or_op_product.is()) { - const auto& op_product = op_or_op_product.as(); - for (auto& op_ptr : ranges::views::reverse(op_product.factors())) { - SEQUANT_ASSERT(op_ptr->template is()); - const auto& op = op_ptr->template as(); - qns = op(qns); - } - return qns.overlaps_with(target_qns); - } else if (op_or_op_product.is()) { - const auto& op = op_or_op_product.as(); - qns = op(qns); - return qns.overlaps_with(target_qns); - } else - throw std::invalid_argument( - "sequant::mbpt::sr::contains_rank(op_or_op_product): op_or_op_product " - "must be mbpt::sr::op_t or Product thereof"); -} - } // namespace sequant::mbpt diff --git a/SeQuant/domain/mbpt/op.hpp b/SeQuant/domain/mbpt/op.hpp index 64f597ddc2..f980e5f321 100644 --- a/SeQuant/domain/mbpt/op.hpp +++ b/SeQuant/domain/mbpt/op.hpp @@ -555,11 +555,9 @@ qns_t generic_deexcitation_qns(std::size_t particle_rank, std::size_t hole_rank, inline namespace op { namespace tensor { -namespace detail { ExprPtr expectation_value_impl(ExprPtr expr, std::vector> nop_connections, bool use_top, bool full_contractions); -} // namespace detail /// @brief computes the reference expectation value of a tensor-level expression /// @param expr input expression @@ -1304,7 +1302,6 @@ bool raises_vacuum_to_rank(const ExprPtr& op_or_op_product, bool lowers_rank_to_vacuum(const ExprPtr& op_or_op_product, const unsigned long k); -#include } // namespace op } // namespace mbpt } // namespace sequant diff --git a/SeQuant/domain/mbpt/vac_av.ipp b/SeQuant/domain/mbpt/vac_av.cpp similarity index 84% rename from SeQuant/domain/mbpt/vac_av.ipp rename to SeQuant/domain/mbpt/vac_av.cpp index 79cedd0e0c..f9aba37bf1 100644 --- a/SeQuant/domain/mbpt/vac_av.ipp +++ b/SeQuant/domain/mbpt/vac_av.cpp @@ -2,12 +2,24 @@ // Created by Eduard Valeyev on 8/2/23. // -// operator-level vac_av is same for SR and MR, to be included from {sr,mr}.cpp +#include -#ifndef SEQUANT_DOMAIN_MBPT_VAC_AV_IPP -#define SEQUANT_DOMAIN_MBPT_VAC_AV_IPP +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +namespace sequant { +namespace mbpt { +inline namespace op { -namespace detail { ExprPtr expectation_value_impl( ExprPtr expr, const OpConnections& op_connections, bool use_topology, bool screen, bool skip_clone, bool full_contractions) { @@ -90,8 +102,8 @@ ExprPtr expectation_value_impl( // compute expectation value // call the tensor-level impl function directly - auto vev = tensor::detail::expectation_value_impl( - product, connections, use_topology, full_contractions); + auto vev = tensor::expectation_value_impl(product, connections, + use_topology, full_contractions); // restore Variable types to the Product if (!variables.empty()) ranges::for_each(variables, [&vev](const auto& var) { vev *= var; }); @@ -128,9 +140,9 @@ ExprPtr expectation_value_impl( return expr; // vacuum is normalized } throw std::invalid_argument( - "mpbt::*::expectation_value_impl(expr): unknown expression type"); + "mbpt::op::detail::expectation_value_impl(expr): unknown expression " + "type"); } -} // namespace detail ExprPtr ref_av(ExprPtr expr, const OpConnections& op_connections, bool use_topology, bool screen, bool skip_clone) { @@ -138,8 +150,8 @@ ExprPtr ref_av(ExprPtr expr, const OpConnections& op_connections, const bool full_contractions = (isr->reference_occupied_space() == isr->vacuum_occupied_space()) ? true : false; - return detail::expectation_value_impl(expr, op_connections, use_topology, - screen, skip_clone, full_contractions); + return expectation_value_impl(expr, op_connections, use_topology, screen, + skip_clone, full_contractions); } ExprPtr ref_av(ExprPtr expr, const OpConnections& op_connections, @@ -150,9 +162,9 @@ ExprPtr ref_av(ExprPtr expr, const OpConnections& op_connections, ExprPtr vac_av(ExprPtr expr, const OpConnections& op_connections, bool use_topology, bool screen, bool skip_clone) { - return detail::expectation_value_impl(expr, op_connections, use_topology, - screen, skip_clone, - /* full_contractions*/ true); + return expectation_value_impl(expr, op_connections, use_topology, screen, + skip_clone, + /* full_contractions */ true); } ExprPtr vac_av(ExprPtr expr, const OpConnections& op_connections, @@ -161,4 +173,6 @@ ExprPtr vac_av(ExprPtr expr, const OpConnections& op_connections, screen, skip_clone); } -#endif // SEQUANT_DOMAIN_MBPT_VAC_AV_IPP +} // namespace op +} // namespace mbpt +} // namespace sequant diff --git a/SeQuant/domain/mbpt/vac_av.hpp b/SeQuant/domain/mbpt/vac_av.hpp index 99e70a666b..4830f219d6 100644 --- a/SeQuant/domain/mbpt/vac_av.hpp +++ b/SeQuant/domain/mbpt/vac_av.hpp @@ -2,6 +2,14 @@ // Created by Eduard Valeyev on 2023-10-30. // +#ifndef SEQUANT_DOMAIN_MBPT_VAC_AV_HPP +#define SEQUANT_DOMAIN_MBPT_VAC_AV_HPP + +#include + +namespace sequant::mbpt { +inline namespace op { + template using OpConnections = std::vector>; @@ -73,13 +81,10 @@ inline ExprPtr lower_to_tensor_form(const ExprPtr& expr_inp) { return expr; } -namespace detail { ExprPtr expectation_value_impl( ExprPtr expr, const OpConnections& op_connections, bool use_topology, bool screen, bool skip_clone, bool full_contractions); -} // namespace detail - // clang-format off /// @brief computes the reference expectation value /// @note equivalent to vac_av if the reference state is the Wick vacuum, @@ -165,3 +170,7 @@ ExprPtr vac_av(ExprPtr expr, default_op_connections(), bool use_topology = true, bool screen = true, bool skip_clone = false); + +} // namespace op +} // namespace sequant::mbpt +#endif // SEQUANT_DOMAIN_MBPT_VAC_AV_HPP diff --git a/doc/examples/synopsis/synopsis6.cpp b/doc/examples/synopsis/synopsis6.cpp index 2c1817ca5d..82a1b51101 100644 --- a/doc/examples/synopsis/synopsis6.cpp +++ b/doc/examples/synopsis/synopsis6.cpp @@ -3,6 +3,7 @@ #include #include #include +#include inline auto commutator(auto op1, auto op2) { return op1 * op2 - op2 * op1; } diff --git a/doc/examples/user/getting_started/ccd.cpp b/doc/examples/user/getting_started/ccd.cpp index e83bcb350b..ea65012454 100644 --- a/doc/examples/user/getting_started/ccd.cpp +++ b/doc/examples/user/getting_started/ccd.cpp @@ -3,6 +3,7 @@ #include #include #include +#include inline auto commutator(auto op1, auto op2) { return op1 * op2 - op2 * op1; } diff --git a/doc/examples/user/operator.cpp b/doc/examples/user/operator.cpp index 4c487d7945..ba7f952fdb 100644 --- a/doc/examples/user/operator.cpp +++ b/doc/examples/user/operator.cpp @@ -6,6 +6,7 @@ #include #include #include +#include int main() { // start-snippet-0 diff --git a/python/src/sequant/mbpt.h b/python/src/sequant/mbpt.h index a027c75e84..e326c78e9d 100644 --- a/python/src/sequant/mbpt.h +++ b/python/src/sequant/mbpt.h @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/tests/unit/test_mbpt.cpp b/tests/unit/test_mbpt.cpp index 828247c06b..abd260e615 100644 --- a/tests/unit/test_mbpt.cpp +++ b/tests/unit/test_mbpt.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include