Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
local_space.hpp
Go to the documentation of this file.
1
7#pragma once
8
11
12#include <concepts>
13#include <cstddef>
14#include <initializer_list>
15#include <ranges>
16#include <span>
17#include <stdexcept>
18#include <string>
19#include <utility>
20#include <vector>
21
22namespace uni20
23{
24
29 public:
33 explicit LocalSpace(Symmetry sym, std::string label = {}) : sym_(sym), label_(std::move(label))
34 {
35 this->verify_symmetry();
36 }
37
42 LocalSpace(Symmetry sym, std::initializer_list<QNum> qnums, std::string label = {})
43 : LocalSpace(sym, std::move(label))
44 {
45 this->append_qnums(qnums);
46 }
47
53 template <std::ranges::input_range QNums>
54 requires std::constructible_from<QNum, std::ranges::range_reference_t<QNums>>
55 LocalSpace(Symmetry sym, QNums&& qnums, std::string label = {}) : LocalSpace(sym, std::move(label))
56 {
57 this->append_qnums(std::forward<QNums>(qnums));
58 }
59
63 explicit LocalSpace(QNumList const& qnums, std::string label = {}) : LocalSpace(qnums.symmetry(), std::move(label))
64 {
65 this->append_qnums(qnums);
66 }
67
70 auto symmetry() const -> Symmetry { return sym_; }
71
74 auto size() const -> std::size_t { return qnums_.size(); }
75
78 auto empty() const -> bool { return qnums_.empty(); }
79
83 auto operator[](std::size_t index) const -> QNum const& { return qnums_[index]; }
84
87 auto qnums() const -> std::span<QNum const> { return qnums_; }
88
91 auto begin() const { return qnums_.begin(); }
92
95 auto end() const { return qnums_.end(); }
96
99 auto label() const -> std::string const& { return label_; }
100
103 void set_label(std::string label) { label_ = std::move(label); }
104
108 auto operator==(LocalSpace const& other) const -> bool = default;
109
110 private:
112 void verify_symmetry() const
113 {
114 if (!sym_.valid())
115 {
116 throw std::invalid_argument("LocalSpace requires a valid symmetry");
117 }
118 }
119
123 template <std::ranges::input_range QNums> void append_qnums(QNums&& qnums)
124 {
125 for (auto&& input : qnums)
126 {
127 QNum q(std::forward<decltype(input)>(input));
128 if (!q.valid() || q.symmetry() != sym_)
129 {
130 throw std::invalid_argument("LocalSpace state has the wrong symmetry");
131 }
132 qnums_.push_back(std::move(q));
133 }
134 }
135
136 Symmetry sym_;
137 std::vector<QNum> qnums_;
138 std::string label_;
139};
140
141static_assert(SymmetrySpace<LocalSpace>);
142
143} // namespace uni20
Ordered local-state space whose quantum numbers may repeat.
Definition local_space.hpp:28
auto operator==(LocalSpace const &other) const -> bool=default
Compare symmetry, ordered local states, and label.
auto label() const -> std::string const &
Return the semantic leg label.
Definition local_space.hpp:99
LocalSpace(Symmetry sym, QNums &&qnums, std::string label={})
Construct a local space from an input range.
Definition local_space.hpp:55
auto size() const -> std::size_t
Return the number of explicit local states.
Definition local_space.hpp:74
auto begin() const
Return an iterator to the first local state.
Definition local_space.hpp:91
LocalSpace(QNumList const &qnums, std::string label={})
Construct an immutable local space from a QNumList.
Definition local_space.hpp:63
LocalSpace(Symmetry sym, std::initializer_list< QNum > qnums, std::string label={})
Construct a local space from an initializer list.
Definition local_space.hpp:42
void set_label(std::string label)
Replace the semantic leg label without changing the space structure.
Definition local_space.hpp:103
auto symmetry() const -> Symmetry
Return the symmetry shared by every local state.
Definition local_space.hpp:70
auto operator[](std::size_t index) const -> QNum const &
Return indexed local-state access.
Definition local_space.hpp:83
auto qnums() const -> std::span< QNum const >
Return the ordered local-state quantum numbers.
Definition local_space.hpp:87
LocalSpace(Symmetry sym, std::string label={})
Construct an empty local space in an explicit symmetry.
Definition local_space.hpp:33
auto empty() const -> bool
Return whether the local space has no states.
Definition local_space.hpp:78
auto end() const
Return an iterator past the last local state.
Definition local_space.hpp:95
Explicit sparse tensor space represented as quantum numbers with one shared symmetry.
Definition qnum.hpp:102
One irrep label together with the symmetry context needed to interpret it.
Definition qnum.hpp:29
Public handle to a canonicalized direct-product symmetry specification.
Definition symmetry.hpp:24
auto valid() const -> bool
Return whether this handle refers to a valid symmetry.
Definition symmetry.hpp:44
Definition qnum.hpp:403
Definition async/async.hpp:26
std::size_t span
Definition presentation.cpp:2017
Defines packed quantum numbers and same-symmetry quantum-number containers.
Defines the common tensor-space concepts.