Class TensorCanonicalizer

Inheritance Relationships

Derived Types

Class Documentation

class TensorCanonicalizer

Base class for Tensor canonicalizers To make custom canonicalizer make a derived class and register an instance of that class with TensorCanonicalizer::register_instance.

Subclassed by sequant::DefaultTensorCanonicalizer, sequant::NullTensorCanonicalizer

Public Types

using index_comparer_t = std::function<bool(const Index&, const Index&)>
using index_pair_t = std::pair<const Index, const Index>
using index_pair_comparer_t = std::function<bool(const index_pair_t&, const index_pair_t)>

Public Functions

virtual ~TensorCanonicalizer()
virtual ExprPtr apply(AbstractTensor&) const = 0
Returns:

a side effect of canonicalization (e.g. phase), or nullptr if none

Public Static Functions

static std::shared_ptr< TensorCanonicalizer > instance_ptr (std::wstring_view label=L"")
Returns:

ptr to the TensorCanonicalizer object, if any, that had been previously registered via TensorCanonicalizer::register_instance() with label , or to the default canonicalizer, if any

static std::shared_ptr<TensorCanonicalizer> nondefault_instance_ptr(std::wstring_view label)

See also

instance_ptr

Returns:

ptr to the TensorCanonicalizer object, if any, that had been previously registered via TensorCanonicalizer::register_instance() with label

static std::shared_ptr< TensorCanonicalizer > instance (std::wstring_view label=L"")
Throws:

std::runtime_error – if no canonicalizer has been registered

Returns:

a TensorCanonicalizer previously registered via TensorCanonicalizer::register_instance() with label or to the default canonicalizer

static void register_instance (std::shared_ptr< TensorCanonicalizer > canonicalizer, std::wstring_view label=L"")

registers canonicalizer to be applied to Tensor objects with label label ; leave the label empty if canonicalizer is to apply to Tensor objects with any label

Note

if a canonicalizer registered with label label exists, it is replaced

static bool try_register_instance (std::shared_ptr< TensorCanonicalizer > canonicalizer, std::wstring_view label=L"")

tries to register canonicalizer to be applied to Tensor objects with label label ; leave the label empty if canonicalizer is to apply to Tensor objects with any label

See also

regiter_instance

Returns:

false if there is already a canonicalizer registered with label

static void deregister_instance (std::wstring_view label=L"")

deregisters canonicalizer (if any) registered previously to be applied to tensors with label label

static inline const auto &cardinal_tensor_labels()
Returns:

a list of Tensor labels with lexicographic preference (in order)

static inline void set_cardinal_tensor_labels(const container::vector<std::wstring> &labels)
Parameters:

cardinal_tensor_labels – a list of Tensor labels with lexicographic preference (in order)

static const index_comparer_t &index_comparer()
Returns:

reference to the object used to compare Index objects

static void index_comparer(index_comparer_t comparer)
Parameters:

comparer – the compare object to be used by this

static const index_pair_comparer_t &index_pair_comparer()
Returns:

reference to the object used to compare Index objects

static void index_pair_comparer(index_pair_comparer_t comparer)
Parameters:

comparer – the compare object to be used by this

Protected Functions

inline auto bra_range(AbstractTensor &t) const
inline auto ket_range(AbstractTensor &t) const
inline auto aux_range(AbstractTensor &t) const

Protected Static Attributes

static index_comparer_t index_comparer_ = TensorIndexComparer{}

the object used to compare indices

static index_pair_comparer_t index_pair_comparer_ = TensorIndexComparer{}

the object used to compare pairs of indices