Skip to content
Open
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
29 changes: 28 additions & 1 deletion SeQuant/core/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ bool operator==(const Context& ctx1, const Context& ctx2) {
ctx1.canonicalization_options() == ctx2.canonicalization_options() &&
ctx1.braket_typesetting() == ctx2.braket_typesetting() &&
ctx1.braket_slot_typesetting() == ctx2.braket_slot_typesetting() &&
ctx1.symmetry() == ctx2.symmetry() &&
ctx1.hermiticity() == ctx2.hermiticity() &&
ctx1.column_symmetry() == ctx2.column_symmetry() &&
*ctx1.index_space_registry() == *ctx2.index_space_registry();
}

Expand Down Expand Up @@ -132,7 +135,10 @@ Context::Context(Options options)
first_dummy_index_ordinal_(options.first_dummy_index_ordinal),
canonicalization_options_(options.canonicalization_options),
braket_typesetting_(options.braket_typesetting),
braket_slot_typesetting_(options.braket_slot_typesetting) {}
braket_slot_typesetting_(options.braket_slot_typesetting),
symmetry_(options.symmetry),
hermiticity_(options.hermiticity),
column_symmetry_(options.column_symmetry) {}

Context Context::clone() const {
Context ctx(*this);
Expand Down Expand Up @@ -176,6 +182,12 @@ BraKetSlotTypesetting Context::braket_slot_typesetting() const {
return braket_slot_typesetting_;
}

Symmetry Context::symmetry() const { return symmetry_; }

Hermiticity Context::hermiticity() const { return hermiticity_; }

ColumnSymmetry Context::column_symmetry() const { return column_symmetry_; }

Context& Context::set(Vacuum vacuum) {
vacuum_ = vacuum;
return *this;
Expand Down Expand Up @@ -229,6 +241,21 @@ Context& Context::set(BraKetSlotTypesetting bkst) {
return *this;
}

Context& Context::set(Symmetry symmetry) {
symmetry_ = symmetry;
return *this;
}

Context& Context::set(Hermiticity hermiticity) {
hermiticity_ = hermiticity;
return *this;
}

Context& Context::set(ColumnSymmetry column_symmetry) {
column_symmetry_ = column_symmetry;
return *this;
}

IndexSpace get_particle_space(const IndexSpace::QuantumNumbers& qn) {
return get_default_context().index_space_registry()->particle_space(qn);
}
Expand Down
42 changes: 42 additions & 0 deletions SeQuant/core/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ class Context {
constexpr static auto braket_typesetting = BraKetTypesetting::ContraSub;
constexpr static auto braket_slot_typesetting =
BraKetSlotTypesetting::TensorPackage;
// default symmetries used when *deserializing* a tensor whose symmetry is
// under-specified in the input; the library defaults are the *safest* (most
// general) possible, and applications can fine-tune them via Context for
// ergonomics (e.g. mbpt assumes particle-symmetric tensors). These do NOT
// affect the programmatic Tensor ctors, whose defaults are fixed and
// independent of the ambient Context. Note that there is no braket-symmetry
// default: braket symmetry is a *derived* property of a tensor (from its
// #Hermiticity and #base_field), so #hermiticity is the knob instead (cf.
// removal of Context::braket_symmetry).
constexpr static auto symmetry = Symmetry::Nonsymm;
constexpr static auto hermiticity = Hermiticity::NonHermitian;
constexpr static auto column_symmetry = ColumnSymmetry::Nonsymm;
};

/// helper for the named-parameter constructor of Context
Expand Down Expand Up @@ -86,6 +98,14 @@ class Context {
/// the BraKetSlotTypesetting object
BraKetSlotTypesetting braket_slot_typesetting =
Defaults::braket_slot_typesetting;
/// the default bra/ket permutational Symmetry for deserialized tensors
Symmetry symmetry = Defaults::symmetry;
/// the default Hermiticity for deserialized tensors; the braket symmetry
/// of a deserialized tensor is *derived* from this and its #base_field
Hermiticity hermiticity = Defaults::hermiticity;
/// the default ColumnSymmetry (particle-permutation symmetry) for
/// deserialized tensors
ColumnSymmetry column_symmetry = Defaults::column_symmetry;
};
static Options make_default_options() { return {}; }

Expand Down Expand Up @@ -155,6 +175,15 @@ class Context {
/// \return BraKetSlotTypesetting of this context; see BraKetSlotTypesetting
/// for the meaning of the possible values
BraKetSlotTypesetting braket_slot_typesetting() const;
/// \return the default bra/ket permutational Symmetry for deserialized tensors
Symmetry symmetry() const;
/// \return the default Hermiticity for deserialized tensors; the braket
/// symmetry of a deserialized tensor is *derived* from this and its
/// #base_field
Hermiticity hermiticity() const;
/// \return the default ColumnSymmetry (particle-permutation symmetry) for
/// deserialized tensors
ColumnSymmetry column_symmetry() const;

/// Sets the Vacuum for this context, convenient for chaining
/// \param vacuum Vacuum
Expand Down Expand Up @@ -195,6 +224,16 @@ class Context {
/// \param braket_slot_typeset BraKetSlotTypesetting
/// \return ref to `*this`, for chaining
Context& set(BraKetSlotTypesetting braket_slot_typeset);
/// Sets the default bra/ket permutational Symmetry for deserialized tensors
/// \return ref to `*this`, for chaining
Context& set(Symmetry symmetry);
/// Sets the default Hermiticity for deserialized tensors (the braket symmetry
/// of a deserialized tensor is derived from this and its base field)
/// \return ref to `*this`, for chaining
Context& set(Hermiticity hermiticity);
/// Sets the default ColumnSymmetry for deserialized tensors
/// \return ref to `*this`, for chaining
Context& set(ColumnSymmetry column_symmetry);

private:
std::shared_ptr<IndexSpaceRegistry> idx_space_reg_ = nullptr;
Expand All @@ -207,6 +246,9 @@ class Context {
BraKetTypesetting braket_typesetting_ = Defaults::braket_typesetting;
BraKetSlotTypesetting braket_slot_typesetting_ =
Defaults::braket_slot_typesetting;
Symmetry symmetry_ = Defaults::symmetry;
Hermiticity hermiticity_ = Defaults::hermiticity;
ColumnSymmetry column_symmetry_ = Defaults::column_symmetry;
};

/// Context object equality comparison
Expand Down
Loading
Loading