Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions SeQuant/domain/mbpt/models/cc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <SeQuant/core/op.hpp>
#include <SeQuant/domain/mbpt/op.hpp>
#include <SeQuant/domain/mbpt/vac_av.hpp>

#include <cstddef>
#include <limits>
Expand Down
37 changes: 7 additions & 30 deletions SeQuant/domain/mbpt/op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SeQuant/domain/mbpt/vac_av.ipp>

namespace tensor {

ExprPtr detail::expectation_value_impl(
ExprPtr expr, std::vector<std::pair<int, int>> nop_connections,
bool use_top, bool full_contractions) {
ExprPtr expectation_value_impl(ExprPtr expr,
std::vector<std::pair<int, int>> 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;
Expand Down Expand Up @@ -1466,38 +1464,17 @@ ExprPtr ref_av(ExprPtr expr, std::vector<std::pair<int, int>> 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<std::pair<int, int>> 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<Product>()) {
const auto& op_product = op_or_op_product.as<Product>();
for (auto& op_ptr : ranges::views::reverse(op_product.factors())) {
SEQUANT_ASSERT(op_ptr->template is<op_t>());
const auto& op = op_ptr->template as<op_t>();
qns = op(qns);
}
return qns.overlaps_with(target_qns);
} else if (op_or_op_product.is<op_t>()) {
const auto& op = op_or_op_product.as<op_t>();
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
3 changes: 0 additions & 3 deletions SeQuant/domain/mbpt/op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<int, int>> 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
Expand Down Expand Up @@ -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 <SeQuant/domain/mbpt/vac_av.hpp>
} // namespace op
} // namespace mbpt
} // namespace sequant
Expand Down
42 changes: 28 additions & 14 deletions SeQuant/domain/mbpt/vac_av.ipp → SeQuant/domain/mbpt/vac_av.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SeQuant/domain/mbpt/vac_av.hpp>

#ifndef SEQUANT_DOMAIN_MBPT_VAC_AV_IPP
#define SEQUANT_DOMAIN_MBPT_VAC_AV_IPP
#include <SeQuant/core/context.hpp>
#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/op.hpp>
#include <SeQuant/core/utility/macros.hpp>

#include <range/v3/algorithm/any_of.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/filter.hpp>

#include <vector>

namespace sequant {
namespace mbpt {
inline namespace op {

namespace detail {
ExprPtr expectation_value_impl(
ExprPtr expr, const OpConnections<std::wstring>& op_connections,
bool use_topology, bool screen, bool skip_clone, bool full_contractions) {
Expand Down Expand Up @@ -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; });
Expand Down Expand Up @@ -128,18 +140,18 @@ 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<std::wstring>& op_connections,
bool use_topology, bool screen, bool skip_clone) {
auto isr = get_default_context().index_space_registry();
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<OpType>& op_connections,
Expand All @@ -150,9 +162,9 @@ ExprPtr ref_av(ExprPtr expr, const OpConnections<OpType>& op_connections,

ExprPtr vac_av(ExprPtr expr, const OpConnections<std::wstring>& 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<OpType>& op_connections,
Expand All @@ -161,4 +173,6 @@ ExprPtr vac_av(ExprPtr expr, const OpConnections<OpType>& op_connections,
screen, skip_clone);
}

#endif // SEQUANT_DOMAIN_MBPT_VAC_AV_IPP
} // namespace op
} // namespace mbpt
} // namespace sequant
15 changes: 12 additions & 3 deletions SeQuant/domain/mbpt/vac_av.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SeQuant/domain/mbpt/op.hpp>

namespace sequant::mbpt {
inline namespace op {

template <typename T>
using OpConnections = std::vector<std::pair<T, T>>;

Expand Down Expand Up @@ -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<std::wstring>& 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,
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions doc/examples/synopsis/synopsis6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <SeQuant/core/op.hpp>
#include <SeQuant/domain/mbpt/convention.hpp>
#include <SeQuant/domain/mbpt/op.hpp>
#include <SeQuant/domain/mbpt/vac_av.hpp>

inline auto commutator(auto op1, auto op2) { return op1 * op2 - op2 * op1; }

Expand Down
1 change: 1 addition & 0 deletions doc/examples/user/getting_started/ccd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <SeQuant/core/op.hpp>
#include <SeQuant/domain/mbpt/convention.hpp>
#include <SeQuant/domain/mbpt/op.hpp>
#include <SeQuant/domain/mbpt/vac_av.hpp>

inline auto commutator(auto op1, auto op2) { return op1 * op2 - op2 * op1; }

Expand Down
1 change: 1 addition & 0 deletions doc/examples/user/operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <SeQuant/core/expr.hpp>
#include <SeQuant/domain/mbpt/convention.hpp>
#include <SeQuant/domain/mbpt/op.hpp>
#include <SeQuant/domain/mbpt/vac_av.hpp>

int main() {
// start-snippet-0
Expand Down
1 change: 1 addition & 0 deletions python/src/sequant/mbpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <SeQuant/domain/mbpt/convention.hpp>
#include <SeQuant/domain/mbpt/op.hpp>
#include <SeQuant/domain/mbpt/vac_av.hpp>

#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/tensor_canonicalizer.hpp>
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_mbpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <SeQuant/domain/mbpt/rules/df.hpp>
#include <SeQuant/domain/mbpt/rules/thc.hpp>
#include <SeQuant/domain/mbpt/utils.hpp>
#include <SeQuant/domain/mbpt/vac_av.hpp>

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
Expand Down