Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
21 changes: 12 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,10 @@ set(SeQuant_src
SeQuant/core/index_space_registry.cpp
SeQuant/core/index_space_registry.hpp
SeQuant/core/interval.hpp
SeQuant/core/latex.cpp
SeQuant/core/latex.hpp
SeQuant/core/latex.ipp
SeQuant/core/io/concepts.hpp
SeQuant/core/io/shorthands.hpp
SeQuant/core/io/latex/latex.cpp
SeQuant/core/io/latex/latex.hpp
SeQuant/core/logger.hpp
SeQuant/core/math.hpp
SeQuant/core/meta.hpp
Expand All @@ -322,10 +323,14 @@ set(SeQuant_src
SeQuant/core/optimize/fusion.cpp
SeQuant/core/optimize/fusion.hpp
SeQuant/core/optimize/optimize.cpp
SeQuant/core/parse.hpp
SeQuant/core/parse/ast.cpp
SeQuant/core/parse/deparse.cpp
SeQuant/core/parse/parse.cpp
SeQuant/core/io/serialization/serialization.cpp
SeQuant/core/io/serialization/serialization.hpp
SeQuant/core/io/serialization/v1/ast.cpp
SeQuant/core/io/serialization/v1/ast.hpp
SeQuant/core/io/serialization/v1/ast_conversions.hpp
SeQuant/core/io/serialization/v1/deserialize.cpp
SeQuant/core/io/serialization/v1/semantic_actions.hpp
SeQuant/core/io/serialization/v1/serialize.cpp
SeQuant/core/ranges.hpp
SeQuant/core/rational.hpp
SeQuant/core/runtime.cpp
Expand Down Expand Up @@ -371,8 +376,6 @@ set(SeQuant_src
SeQuant/core/reserved.hpp
SeQuant/core/wick.hpp
SeQuant/core/wick.impl.hpp
SeQuant/core/wolfram.hpp
SeQuant/core/wstring.hpp
SeQuant/domain/mbpt/antisymmetrizer.cpp
SeQuant/domain/mbpt/antisymmetrizer.hpp
SeQuant/domain/mbpt/biorthogonalization.cpp
Expand Down
6 changes: 3 additions & 3 deletions SeQuant/core/asy_cost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <SeQuant/core/container.hpp>
#include <SeQuant/core/meta.hpp>
#include <SeQuant/core/rational.hpp>
#include <SeQuant/core/wstring.hpp>
#include <SeQuant/core/utility/string.hpp>

#include <boost/numeric/conversion/cast.hpp>

Expand Down Expand Up @@ -242,9 +242,9 @@ std::wstring AsyCost::to_latex() const {
//
// stream out in reverse so that more expensive terms appear first
auto rev = ranges::views::reverse(cost_);
oss << sequant::to_wstring(ranges::front(rev).to_latex());
oss << toUtf16(ranges::front(rev).to_latex());
for (auto &&c : ranges::views::tail(rev))
oss << L" + " << sequant::to_wstring(c.to_latex());
oss << L" + " << toUtf16(c.to_latex());
}
return oss.str();
}
Expand Down
30 changes: 0 additions & 30 deletions SeQuant/core/attr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@ enum class BraKetSymmetry { Symm, Conjugate, Nonsymm };
/// describes type of single-particle basis
enum class SPBasis { Spinor, Spinfree };

inline std::wstring to_wolfram(const Symmetry& symmetry) {
std::wstring result;
switch (symmetry) {
case Symmetry::Symm:
result = L"indexSymm[1]";
break;
case Symmetry::Antisymm:
result = L"indexSymm[-1]";
break;
case Symmetry::Nonsymm:
result = L"indexSymm[0]";
break;
}
return result;
}

inline std::wstring to_wstring(Symmetry sym) {
switch (sym) {
case Symmetry::Symm:
Expand All @@ -70,15 +54,6 @@ enum class BraKetPos {
Ket,
};

inline std::wstring to_wolfram(BraKetPos a) {
switch (a) {
case BraKetPos::Bra:
return L"indexType[bra]";
case BraKetPos::Ket:
return L"indexType[ket]";
}
}

enum class Statistics {
FermiDirac,
BoseEinstein,
Expand All @@ -92,11 +67,6 @@ inline Action adjoint(Action action) {
return action == Action::Create ? Action::Annihilate : Action::Create;
}

inline std::wstring to_wolfram(Action a) {
using namespace std::literals;
return L"indexType["s + (a == Action::Create ? L"cre" : L"ann") + L"]";
}

enum class Vacuum { Physical, SingleProduct, MultiProduct };

inline std::wstring to_string(Vacuum V) {
Expand Down
23 changes: 6 additions & 17 deletions SeQuant/core/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#include <string>

#include <SeQuant/core/hash.hpp>
#include <SeQuant/core/latex.hpp>
#include <SeQuant/core/io/latex/latex.hpp>
#include <SeQuant/core/rational.hpp>
#include <SeQuant/core/utility/macros.hpp>
#include <SeQuant/core/wolfram.hpp>

namespace sequant {

Expand Down Expand Up @@ -41,28 +40,18 @@ struct Complex {
constexpr bool is_identity() const { return real() == 1 && imag() == 0; }

std::wstring to_latex() const {
using ::sequant::to_latex;
std::wstring result = L"{";
result += to_latex(this->real());
result += io::latex::to_string(this->real());
if (this->imag() > 0) {
result =
L"\\bigl(" + result + L" + i " + to_latex(this->imag()) + L"\\bigr)";
result = L"\\bigl(" + result + L" + i " +
io::latex::to_string(this->imag()) + L"\\bigr)";
} else if (this->imag() < 0)
result =
L"\\bigl(" + result + L" - i " + to_latex(-this->imag()) + L"\\bigr)";
result = L"\\bigl(" + result + L" - i " +
io::latex::to_string(-this->imag()) + L"\\bigr)";
result += L"}";
return result;
}

std::wstring to_wolfram() const {
using ::sequant::to_wolfram;
if (this->imag() == 0)
return to_wolfram(this->real());
else
return std::wstring(L"Complex[") + to_wolfram(this->real()) + L"," +
to_wolfram(this->imag()) + L"]";
}

std::size_t hash_value() const {
auto v = hash::value(this->real());
hash::combine(v, this->imag());
Expand Down
5 changes: 3 additions & 2 deletions SeQuant/core/eval/eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <SeQuant/core/eval/eval_node.hpp>
#include <SeQuant/core/eval/result.hpp>
#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/io/serialization/serialization.hpp>
#include <SeQuant/core/logger.hpp>
#include <SeQuant/core/meta.hpp>
#include <SeQuant/core/parse.hpp>
#include <SeQuant/core/utility/macros.hpp>
#include <SeQuant/core/utility/string.hpp>

#include <chrono>
#include <range/v3/numeric.hpp>
Expand Down Expand Up @@ -354,7 +355,7 @@ ResultPtr evaluate(Node const& node, //

std::string xpr;
if constexpr (trace(EvalTrace)) {
xpr = to_string(deparse(to_expr(node)));
xpr = toUtf8(io::serialization::to_string(to_expr(node)));
log::term(log::TermMode::Begin, xpr);
}

Expand Down
13 changes: 6 additions & 7 deletions SeQuant/core/eval/eval_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/hash.hpp>
#include <SeQuant/core/index.hpp>
#include <SeQuant/core/parse.hpp>
#include <SeQuant/core/io/serialization/serialization.hpp>
#include <SeQuant/core/tensor_canonicalizer.hpp>
#include <SeQuant/core/tensor_network.hpp>
#include <SeQuant/core/utility/indices.hpp>
#include <SeQuant/core/utility/macros.hpp>
#include <SeQuant/core/wstring.hpp>
#include <SeQuant/external/bliss/graph.hh>

#include <range/v3/action.hpp>
Expand Down Expand Up @@ -98,9 +97,9 @@ std::string to_label_annotation(const Index& idx) {
using namespace ranges::views;
using ranges::to;

return sequant::to_string(idx.label()) +
return toUtf8(idx.label()) +
(idx.proto_indices() | transform(&Index::label) |
transform([](auto&& str) { return sequant::to_string(str); }) |
transform([](auto&& str) { return toUtf8(str); }) |
ranges::views::join | to<std::string>);
}

Expand Down Expand Up @@ -225,12 +224,12 @@ Variable const& EvalExpr::as_variable() const { return expr().as<Variable>(); }

std::string EvalExpr::label() const noexcept {
if (is_tensor())
return to_string(as_tensor().label()) + "(" + indices_annot() + ")";
return toUtf8(as_tensor().label()) + "(" + indices_annot() + ")";
else if (is_constant()) {
return sequant::to_string(sequant::deparse(as_constant()));
return toUtf8(io::serialization::to_string(as_constant()));
} else {
SEQUANT_ASSERT(is_variable());
return to_string(as_variable().label());
return toUtf8(as_variable().label());
}
}

Expand Down
1 change: 0 additions & 1 deletion SeQuant/core/export/generation_optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <SeQuant/core/container.hpp>
#include <SeQuant/core/export/generator.hpp>
#include <SeQuant/core/expr.hpp>
#include <SeQuant/core/parse.hpp>
#include <SeQuant/core/utility/macros.hpp>
#include <SeQuant/core/utility/tensor.hpp>

Expand Down
3 changes: 0 additions & 3 deletions SeQuant/core/export/itf.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef SEQUANT_CORE_EXPORT_ITF_HPP
#define SEQUANT_CORE_EXPORT_ITF_HPP

#include <SeQuant/core/parse.hpp>

#include <SeQuant/core/container.hpp>
#include <SeQuant/core/export/context.hpp>
#include <SeQuant/core/export/reordering_context.hpp>
Expand Down Expand Up @@ -408,7 +406,6 @@ class ItfGenerator : public Generator<Context> {
const Product &product = expr.as<Product>();

if (product.factors().size() > 2) {
std::wcerr << deparse(product) << std::endl;
throw std::runtime_error("ITF can only handle binary contractions");
}

Expand Down
59 changes: 28 additions & 31 deletions SeQuant/core/expressions/abstract_tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <SeQuant/core/container.hpp>
#include <SeQuant/core/expressions/expr_algorithms.hpp>
#include <SeQuant/core/index.hpp>
#include <SeQuant/core/latex.hpp>
#include <SeQuant/core/io/latex/latex.hpp>
#include <SeQuant/core/utility/macros.hpp>

#include <cstdlib>
Expand Down Expand Up @@ -415,7 +415,6 @@ inline auto column_symmetry(const AbstractTensor& t) {
inline auto color(const AbstractTensor& t) { return t._color(); }
inline auto is_cnumber(const AbstractTensor& t) { return t._is_cnumber(); }
inline auto label(const AbstractTensor& t) { return t._label(); }
inline auto to_latex(const AbstractTensor& t) { return t._to_latex(); }

/// produces LaTeX representation typeset using <a
/// href="https://ctan.org/pkg/tensor?lang=en">tensor package</a>
Expand Down Expand Up @@ -455,15 +454,15 @@ inline std::wstring to_latex_tensor(
unpaired_type == SlotType::Bra) ||
(bkt == BraKetTypesetting::KetSuper &&
unpaired_type == SlotType::Ket)) {
result += to_latex(unpaired_indices[col]);
result += io::latex::to_string(unpaired_indices[col]);
} else
result += L"{}";
result += L"_";
if ((bkt == BraKetTypesetting::BraSub &&
unpaired_type == SlotType::Bra) ||
(bkt == BraKetTypesetting::KetSub &&
unpaired_type == SlotType::Ket)) {
result += to_latex(unpaired_indices[col]);
result += io::latex::to_string(unpaired_indices[col]);
} else
result += L"{}";
}
Expand All @@ -477,11 +476,13 @@ inline std::wstring to_latex_tensor(
const auto paired_fence = col + num_paired;
for (; col != paired_fence; ++col, ++paired_bra, ++paired_ket) {
result += L"*^";
result += (bkt == BraKetTypesetting::BraSuper) ? to_latex(bra[paired_bra])
: to_latex(ket[paired_ket]);
result += (bkt == BraKetTypesetting::BraSuper)
? io::latex::to_string(bra[paired_bra])
: io::latex::to_string(ket[paired_ket]);
result += L"_";
result += (bkt == BraKetTypesetting::BraSub) ? to_latex(bra[paired_bra])
: to_latex(ket[paired_ket]);
result += (bkt == BraKetTypesetting::BraSub)
? io::latex::to_string(bra[paired_bra])
: io::latex::to_string(ket[paired_ket]);
}

// loop over right-aligned unpaired slots, if left_align==true
Expand All @@ -495,15 +496,15 @@ inline std::wstring to_latex_tensor(
unpaired_type == SlotType::Bra) ||
(bkt == BraKetTypesetting::KetSuper &&
unpaired_type == SlotType::Ket)) {
result += to_latex(unpaired_indices[col]);
result += io::latex::to_string(unpaired_indices[col]);
} else
result += L"{}";
result += L"_";
if ((bkt == BraKetTypesetting::BraSub &&
unpaired_type == SlotType::Bra) ||
(bkt == BraKetTypesetting::KetSub &&
unpaired_type == SlotType::Ket)) {
result += to_latex(unpaired_indices[col]);
result += io::latex::to_string(unpaired_indices[col]);
} else
result += L"{}";
}
Expand All @@ -515,7 +516,7 @@ inline std::wstring to_latex_tensor(
result += L"[";
const auto aux_rank = aux.size();
for (std::size_t i = 0; i < aux_rank; ++i) {
result += sequant::to_latex(aux[i]);
result += io::latex::to_string(aux[i]);
if (i + 1 < aux_rank) {
result += L",";
}
Expand Down Expand Up @@ -552,28 +553,24 @@ inline std::wstring to_latex_tensor(
/// colors are, for now, always assumed to commute)
/// - @c label(t) is a valid expression and its return is convertible to
/// a std::wstring;
/// - @c to_latex(t) is a valid expression and its return is convertible
/// to a std::wstring.
/// - @c io::latex::to_string(t) is a valid expression and its return is
/// convertible to a std::wstring.
template <typename T>
struct is_tensor
: std::bool_constant<
std::is_invocable_v<decltype(braket), T> &&
std::is_invocable_v<decltype(braketaux), T> &&
std::is_invocable_v<decltype(bra_rank), T> &&
std::is_invocable_v<decltype(ket_rank), T> &&
std::is_invocable_v<decltype(aux_rank), T> &&
std::is_invocable_v<decltype(symmetry), T> &&
std::is_invocable_v<decltype(braket_symmetry), T> &&
std::is_invocable_v<decltype(column_symmetry), T> &&
std::is_invocable_v<decltype(color), T> &&
std::is_invocable_v<decltype(is_cnumber), T> &&
std::is_invocable_v<decltype(label), T> &&
std::is_invocable_v<
decltype(static_cast<std::wstring (*)(const T&)>(to_latex)), T>> {
concept is_tensor = requires(const T& obj) {
{ braket(obj) } -> std::ranges::range;
{ braketaux(obj) } -> std::ranges::range;
{ bra_rank(obj) } -> std::convertible_to<std::size_t>;
{ ket_rank(obj) } -> std::convertible_to<std::size_t>;
{ aux_rank(obj) } -> std::convertible_to<std::size_t>;
{ symmetry(obj) } -> std::convertible_to<Symmetry>;
{ braket_symmetry(obj) } -> std::convertible_to<BraKetSymmetry>;
{ column_symmetry(obj) } -> std::convertible_to<ColumnSymmetry>;
{ color(obj) } -> std::convertible_to<std::size_t>;
{ is_cnumber(obj) } -> std::convertible_to<bool>;
{ label(obj) } -> std::constructible_from<std::wstring>;
{ io::latex::to_string(obj) } -> std::convertible_to<std::wstring>;
};
template <typename T>
constexpr bool is_tensor_v = is_tensor<T>::value;
static_assert(is_tensor_v<AbstractTensor>,
static_assert(is_tensor<AbstractTensor>,
"The AbstractTensor class does not fulfill the requirements of "
"the Tensor interface");

Expand Down
7 changes: 2 additions & 5 deletions SeQuant/core/expressions/constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <SeQuant/core/complex.hpp>
#include <SeQuant/core/expressions/expr.hpp>
#include <SeQuant/core/expressions/expr_ptr.hpp>
#include <SeQuant/core/io/latex/latex.hpp>
#include <SeQuant/core/rational.hpp>
#include <SeQuant/core/utility/macros.hpp>

Expand Down Expand Up @@ -66,11 +67,7 @@ class Constant : public Expr {
}

std::wstring to_latex() const override {
return L"{" + sequant::to_latex(value()) + L"}";
}

std::wstring to_wolfram() const override {
return sequant::to_wolfram(value());
return L"{" + io::latex::to_string(value()) + L"}";
}

type_id_type type_id() const override { return get_type_id<Constant>(); }
Expand Down
Loading