Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
4f144c5
Start external interface redesign
Krzmbrzl Jul 17, 2026
35036be
Provide forward_like without requiring C++23 yet
Krzmbrzl Jul 22, 2026
6751dd0
Fix compiler errors
Krzmbrzl Jul 22, 2026
9bafd3b
Switch to using variants for I/O types
Krzmbrzl Jul 22, 2026
c30f7b9
Apply consistent formatting
Krzmbrzl Jul 22, 2026
0e30564
Move ReadInputStep impl to dedicated file
Krzmbrzl Jul 23, 2026
ec4bce7
Implement latex output for ResultExpr
Krzmbrzl Jul 23, 2026
ff5fb46
Add OutputStep
Krzmbrzl Jul 23, 2026
ca49b1b
Switch to using ExecutionContext for data management
Krzmbrzl Jul 23, 2026
bd35e19
Generalize selectors and get_data functions
Krzmbrzl Jul 23, 2026
cfc96d3
assert -> SEQUANT_ASSERT
Krzmbrzl Jul 24, 2026
73dadcc
Remove unneeded processing_tree
Krzmbrzl Jul 24, 2026
e62a8ed
Fix has_more() function impl
Krzmbrzl Jul 24, 2026
de1f145
Move assertion to correct place
Krzmbrzl Jul 24, 2026
6eb3d4c
Add consistency assertion
Krzmbrzl Jul 24, 2026
ef820fa
Fix incorrect loop conditional
Krzmbrzl Jul 24, 2026
e848baf
Allow aliasing groups of IDs
Krzmbrzl Jul 24, 2026
a744769
Use alias grouping instead of data duplication
Krzmbrzl Jul 24, 2026
7420d74
Allow group alias output definitions
Krzmbrzl Jul 24, 2026
207a6e8
Drop alias containing '*'
Krzmbrzl Jul 24, 2026
f12e37a
Implement is_valid_id(…)
Krzmbrzl Jul 24, 2026
abb8189
num_outputs is not needed (atm)
Krzmbrzl Jul 24, 2026
81b86f1
Fix grammar in error msg
Krzmbrzl Jul 24, 2026
a0d5073
Implement ProcessingStepFactory
Krzmbrzl Jul 24, 2026
401236a
Move registrations to cpp file
Krzmbrzl Jul 24, 2026
6418811
Remove unused headers
Krzmbrzl Jul 24, 2026
7ff4eed
Implement Executor
Krzmbrzl Jul 24, 2026
76cb07b
Implement ValidateStep
Krzmbrzl Jul 24, 2026
a1a5495
Start assembling new NEVPT2 JSON driver more seriously
Krzmbrzl Jul 24, 2026
6ce2668
Add associated IDs to returned data object
Krzmbrzl Jul 27, 2026
3c5151c
Also add const conversion overload
Krzmbrzl Jul 27, 2026
09a54b7
Associate indices with alias (as intended)
Krzmbrzl Jul 27, 2026
a5489ea
Ensure specific partitioning of assicuated IDs
Krzmbrzl Jul 27, 2026
f786acf
Make use of new meta information in validate_step
Krzmbrzl Jul 27, 2026
eac0af2
Use more descriptive varname
Krzmbrzl Jul 27, 2026
fed4b18
Add option to specify default symmetry
Krzmbrzl Jul 27, 2026
467bc88
Modularize error messages
Krzmbrzl Jul 27, 2026
594253c
Started adding DF step
Krzmbrzl Jul 27, 2026
81f6d0d
Make default step IDs more easily understandable
Krzmbrzl Aug 4, 2026
2c500f1
Add ID validation
Krzmbrzl Aug 4, 2026
878367e
Avoid binding temporary string to string_view
Krzmbrzl Aug 4, 2026
3469ab8
Streamline creation of numeric data IDs
Krzmbrzl Aug 4, 2026
4db93ae
Provide default ProcessingStep wrapper
Krzmbrzl Aug 4, 2026
f4c1759
Implement missing function
Krzmbrzl Aug 4, 2026
5e88836
Register density_fitting step
Krzmbrzl Aug 4, 2026
9bdcf86
CMake: Include density_fitting_step in sources
Krzmbrzl Aug 4, 2026
9493f01
Make use of new ProcessingStep wrapper
Krzmbrzl Aug 4, 2026
943585e
Include DF step in NEVPT2 example
Krzmbrzl Aug 4, 2026
35543e7
Add optional forwarding aliases for unchanged input data
Krzmbrzl Aug 6, 2026
f4980fa
Rename OneToMany -> OneByOne
Krzmbrzl Aug 6, 2026
120dec7
Fixup includes
Krzmbrzl Aug 6, 2026
c64241e
Fix error message
Krzmbrzl Aug 6, 2026
575530a
Remove incorrect assertion
Krzmbrzl Aug 7, 2026
108dadf
Slightly improve code readability
Krzmbrzl Aug 7, 2026
6935ed3
Error on duplicate step ID
Krzmbrzl Aug 7, 2026
32c9b7c
Ensure function cleans up its own index tags
Krzmbrzl Aug 7, 2026
7b5c8e0
More minor readability improvements
Krzmbrzl Aug 7, 2026
3f3b088
Expand expression as first step in closed_shell_spintrace
Krzmbrzl Aug 7, 2026
b3f7681
Disable external index verification if those come from ResultExpr
Krzmbrzl Aug 7, 2026
5507803
Ensur rigorous spintrace also expands input as first step
Krzmbrzl Aug 7, 2026
21d16f9
Don't create empty symmetrization operator
Krzmbrzl Aug 7, 2026
73768a0
Use explicit sections
Krzmbrzl Aug 8, 2026
fa738a3
Allow SlotType to be used/combined as bitmasks
Krzmbrzl Aug 8, 2026
ce1b9ff
Allow restricting get_used_indices to specific slot types
Krzmbrzl Aug 8, 2026
0a99d13
Use common return code path
Krzmbrzl Aug 8, 2026
db39c36
Always simplify result of rigorous spintrace
Krzmbrzl Aug 8, 2026
2eec3b3
Ensure aux indices are ignored in spintracing
Krzmbrzl Aug 8, 2026
c685b4a
Add SpintracingStep
Krzmbrzl Aug 8, 2026
7192e85
Add CanonicalizeStep
Krzmbrzl Aug 8, 2026
abf8afc
Add SimplifyStep
Krzmbrzl Aug 8, 2026
e454503
Harden type detection
Krzmbrzl Aug 9, 2026
9045a14
Implement TreeIndex class
Krzmbrzl Aug 9, 2026
a7fa362
Fix typo
Krzmbrzl Aug 9, 2026
ce48ef0
Implement ProjectionStep
Krzmbrzl Aug 10, 2026
febb563
Remove symmetrizer for biorthogonalization
Krzmbrzl Aug 21, 2026
7bb8800
Simplify after projection
Krzmbrzl Aug 21, 2026
abfbf58
Make external interface serve old and new driver files
Krzmbrzl Aug 21, 2026
6d6332d
Remove redundant header
Krzmbrzl Aug 21, 2026
1f60d92
Fix ODR violation in unity builds
Krzmbrzl Aug 21, 2026
5823849
Reject empty IDs
Krzmbrzl Aug 21, 2026
72bf5b2
Add OptimizationStep
Krzmbrzl Aug 21, 2026
8a913e5
Add progress monitoring output
Krzmbrzl Aug 21, 2026
fbe21bd
Ensure we're not considering symm operators in optimization
Krzmbrzl Aug 21, 2026
7a030fd
Don't list headers as sources
Krzmbrzl Aug 21, 2026
2dd1187
Ensure alphabetic sorting
Krzmbrzl Aug 21, 2026
c511f98
Implement ToExportTreeStep
Krzmbrzl Aug 21, 2026
9540686
Fix convert_data not forwarding
Krzmbrzl Aug 21, 2026
870bf58
Fix to_latex not defined
Krzmbrzl Aug 21, 2026
c96c2e8
Start implementing ExportStep
Krzmbrzl Aug 21, 2026
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: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ set(SeQuant_symb_src
SeQuant/core/tensor_network/v2.hpp
SeQuant/core/tensor_network/v3.cpp
SeQuant/core/tensor_network/v3.hpp
SeQuant/core/tree_index.cpp
SeQuant/core/tree_index.hpp
SeQuant/core/utility/aggregate.hpp
SeQuant/core/utility/atomic.hpp
SeQuant/core/utility/context.hpp
Expand Down
36 changes: 32 additions & 4 deletions SeQuant/core/attr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cstdlib>
#include <ostream>
#include <string>
#include <type_traits>

namespace sequant {

Expand Down Expand Up @@ -130,10 +131,10 @@ enum class BraKetPos {
///
/// @note This does not include slot bundles, like braket, etc.
enum class SlotType {
Bra,
Ket,
Aux,
Proto,
Bra = 0b1,
Ket = 0b10,
Aux = 0b100,
Proto = 0b1000,
};

template <typename CharT, typename Traits>
Expand All @@ -156,6 +157,33 @@ std::basic_ostream<CharT, Traits>& operator<<(
return stream;
}

struct SlotTypes {
std::underlying_type_t<SlotType> active = 0;

constexpr SlotTypes(SlotType type)
: active(static_cast<decltype(active)>(type)) {}
constexpr SlotTypes(decltype(active) val) : active(val) {}

constexpr bool operator==(const SlotTypes&) const = default;
constexpr auto operator<=>(const SlotTypes&) const = default;

constexpr bool operator&(SlotType type) const {
return active & static_cast<decltype(active)>(type);
}

constexpr SlotTypes operator|(SlotType type) const {
return {active | static_cast<decltype(active)>(type)};
}
};

constexpr SlotTypes operator|(SlotType lhs, SlotType rhs) {
using IntType = std::underlying_type_t<SlotType>;
return {static_cast<IntType>(lhs) | static_cast<IntType>(rhs)};
}

static constexpr const SlotTypes AnySlotType =
SlotType::Bra | SlotType::Ket | SlotType::Aux | SlotType::Proto;

enum class Statistics {
FermiDirac,
BoseEinstein,
Expand Down
7 changes: 5 additions & 2 deletions SeQuant/core/export/export.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <SeQuant/core/export/expression_group.hpp>
#include <SeQuant/core/export/generator.hpp>
#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/io/latex/latex.hpp>
#include <SeQuant/core/logger.hpp>
#include <SeQuant/core/utility/macros.hpp>
#include <SeQuant/core/utility/tensor.hpp>
Expand Down Expand Up @@ -798,7 +799,8 @@ void preprocess_and_maybe_log(ExportNode<T> &tree, PreprocessResult &result,
std::cout << "Tree before preprocessing:\n"
<< tree.tikz(
[](const ExportNode<T> &node) {
return "$" + toUtf8(to_latex(node->expr())) + "$";
return "$" + toUtf8(io::latex::to_string(node->expr())) +
"$";
},
[](const ExportNode<T>) -> std::string { return ""; })
<< "\n";
Expand All @@ -811,7 +813,8 @@ void preprocess_and_maybe_log(ExportNode<T> &tree, PreprocessResult &result,
std::cout << "Tree after pre-processing:\n"
<< tree.tikz(
[](const ExportNode<T> &node) {
return "$" + toUtf8(to_latex(node->expr())) + "$";
return "$" + toUtf8(io::latex::to_string(node->expr())) +
"$";
},
[](const ExportNode<T>) -> std::string { return ""; })
<< "\n";
Expand Down
15 changes: 15 additions & 0 deletions SeQuant/core/expressions/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <SeQuant/core/tensor_canonicalizer.hpp>
#include <SeQuant/core/tensor_network.hpp>
#include <SeQuant/core/tensor_network/typedefs.hpp>
#include <SeQuant/core/tree_index.hpp>
#include <SeQuant/core/utility/macros.hpp>

#include <range/v3/algorithm/any_of.hpp>
Expand Down Expand Up @@ -65,6 +66,14 @@ const ExprPtr &Expr::operator[](std::size_t idx) const {
return begin()[idx];
}

ExprPtr &ExprPtr::operator[](const TreeIndex &idx) {
return idx.select_from(*this);
}

const ExprPtr &ExprPtr::operator[](const TreeIndex &idx) const {
return idx.select_from(*this);
}

ExprPtr &Expr::at(std::size_t idx) { return (*this)[idx]; }

const ExprPtr &Expr::at(std::size_t idx) const { return (*this)[idx]; }
Expand Down Expand Up @@ -183,6 +192,12 @@ Expr &Expr::operator+=(const Expr &) { throw not_implemented("operator+="); }

Expr &Expr::operator-=(const Expr &) { throw not_implemented("operator-="); }

Expr &Expr::operator[](const TreeIndex &idx) { return idx.select_from(*this); }

const Expr &Expr::operator[](const TreeIndex &idx) const {
return idx.select_from(*this);
}

ExprPtr adjoint(const ExprPtr &expr) {
auto result = expr->clone();
result->adjoint();
Expand Down
5 changes: 5 additions & 0 deletions SeQuant/core/expressions/expr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <SeQuant/core/expressions/expr_iterator.hpp>
#include <SeQuant/core/expressions/expr_ptr.hpp>
#include <SeQuant/core/options.hpp>
#include <SeQuant/core/tree_index.hpp>
#include <SeQuant/core/utility/macros.hpp>

#include <boost/core/demangle.hpp>
Expand Down Expand Up @@ -381,6 +382,10 @@ class Expr : public std::enable_shared_from_this<Expr> {
ExprPtr &operator[](std::size_t idx);
const ExprPtr &operator[](std::size_t idx) const;

/// @return The subexpression identified by the given index
Expr &operator[](const TreeIndex &idx);
const Expr &operator[](const TreeIndex &idx) const;

ExprPtr &at(std::size_t idx);
const ExprPtr &at(std::size_t idx) const;

Expand Down
5 changes: 5 additions & 0 deletions SeQuant/core/expressions/expr_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <SeQuant/core/container.hpp>
#include <SeQuant/core/expr_fwd.hpp>
#include <SeQuant/core/expressions/traits.hpp>
#include <SeQuant/core/tree_index.hpp>
#include <SeQuant/core/utility/macros.hpp>

#include <memory>
Expand Down Expand Up @@ -111,6 +112,10 @@ class ExprPtr : public std::shared_ptr<Expr> {
/// @return reference to @c *this
ExprPtr &operator*=(const ExprPtr &);

/// @return The subexpression identified by the given index
ExprPtr &operator[](const TreeIndex &idx);
const ExprPtr &operator[](const TreeIndex &idx) const;

/// @tparam T an Expr type
/// @return true if this object is of type @c T
template <typename T>
Expand Down
16 changes: 16 additions & 0 deletions SeQuant/core/io/latex/latex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
#include <SeQuant/core/container.hpp>
#include <SeQuant/core/expressions/constant.hpp>
#include <SeQuant/core/expressions/power.hpp>
#include <SeQuant/core/expressions/result_expr.hpp>
#include <SeQuant/core/io/latex/latex.hpp>
#include <SeQuant/core/rational.hpp>
#include <SeQuant/core/utility/string.hpp>

#include <map>
#include <optional>
#include <sstream>
#include <string>
#include <vector>

namespace sequant::io::latex {
Expand Down Expand Up @@ -64,6 +67,19 @@ std::wstring to_string(const Power& power) {
return result;
}

std::wstring to_string(const ResultExpr& expr) {
std::wstringstream stream;
if (expr.produces_tensor()) {
stream << to_string(expr.result_as_tensor());
} else {
stream << to_string(expr.result_as_variable());
}

stream << " = " << to_string(expr.expression());

return stream.str();
}

namespace detail {

template <typename Char, typename Traits, typename Alloc>
Expand Down
5 changes: 4 additions & 1 deletion SeQuant/core/io/latex/latex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

namespace sequant {
class Power;
}
class ResultExpr;
} // namespace sequant

namespace sequant::io::latex {

Expand Down Expand Up @@ -105,6 +106,8 @@ std::wstring to_string(const rational& num);

std::wstring to_string(const Power& power);

std::wstring to_string(const ResultExpr& expr);

namespace detail {

template <typename Char, typename Traits, typename Alloc>
Expand Down
22 changes: 22 additions & 0 deletions SeQuant/core/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <memory>
#include <ranges>
#include <type_traits>
#include <utility>

#include <range/v3/range/access.hpp>
#include <range/v3/range/traits.hpp>
Expand Down Expand Up @@ -570,6 +571,27 @@ static_assert(
std::same_as<mimic_constness_t<const int &, float &>, const float &>);
static_assert(std::same_as<mimic_constness_t<int &, const float &>, float &>);

#if defined(__cpp_lib_forward_like) && __cpp_lib_forward_like >= 202207L
using std::forward_like;
#else
template <class T, class U>
// Taken from cppreference https://en.cppreference.com/cpp/utility/forward_like
constexpr auto &&forward_like(U &&x) noexcept {
constexpr bool is_adding_const = std::is_const_v<std::remove_reference_t<T>>;
if constexpr (std::is_lvalue_reference_v<T &&>) {
if constexpr (is_adding_const)
return std::as_const(x);
else
return static_cast<U &>(x);
} else {
if constexpr (is_adding_const)
return std::move(std::as_const(x));
else
return std::move(x);
}
}
#endif

///
/// True if @p T is a range of rank @p Rank whose value type is convertible to
/// @p V.
Expand Down
71 changes: 71 additions & 0 deletions SeQuant/core/tree_index.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <SeQuant/core/container.hpp>
#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/tree_index.hpp>
#include <SeQuant/core/utility/exception.hpp>
#include <SeQuant/core/utility/macros.hpp>

#include <concepts>
#include <cstddef>
#include <initializer_list>
#include <ranges>
#include <string>
#include <type_traits>

namespace sequant {

TreeIndex::TreeIndex(container::svector<std::size_t> positions)
: positions_(std::move(positions)) {}

TreeIndex::TreeIndex(std::initializer_list<std::size_t> positions)
: TreeIndex(container::svector<std::size_t>(std::move(positions))) {}

template <typename ExprType>
ExprType &select_impl(ExprType &expr,
const container::svector<std::size_t> &positions) {
constexpr bool is_expr_ptr =
std::same_as<std::remove_cvref_t<ExprType>, ExprPtr>;

ExprType *selected = &expr;

for (std::size_t current : positions) {
if (current >= selected->size()) {
throw Exception("Position " + std::to_string(current) +
" is out of bounds for an expression of dimension " +
std::to_string(selected->size()));
}

using std::ranges::begin;

auto it = begin(*selected) + current;

if constexpr (is_expr_ptr) {
selected = &(*it);
} else {
selected = &(*(*it));
}
}

SEQUANT_ASSERT(selected);

return *selected;
}

ExprPtr &TreeIndex::select_from(ExprPtr &expr) const {
return select_impl(expr, positions_);
}

const ExprPtr &TreeIndex::select_from(const ExprPtr &expr) const {
return select_impl(expr, positions_);
}

Expr &TreeIndex::select_from(Expr &expr) const {
return select_impl(expr, positions_);
}

const Expr &TreeIndex::select_from(const Expr &expr) const {
return select_impl(expr, positions_);
}

std::size_t TreeIndex::depth() const { return positions_.size(); }

} // namespace sequant
Loading
Loading