Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
23 changes: 0 additions & 23 deletions SeQuant/domain/mbpt/op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,6 @@ 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(
Expand Down Expand Up @@ -1479,25 +1477,4 @@ ExprPtr vac_av(ExprPtr expr, std::vector<std::pair<int, int>> nop_connections,
} // 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
1 change: 0 additions & 1 deletion SeQuant/domain/mbpt/op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,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
30 changes: 24 additions & 6 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,26 @@
// 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 @@ -128,8 +142,10 @@ 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,
Expand All @@ -152,7 +168,7 @@ 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);
/* full_contractions */ true);
}

ExprPtr vac_av(ExprPtr expr, const OpConnections<OpType>& op_connections,
Expand All @@ -161,4 +177,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