Skip to content

Commit 4531794

Browse files
basis add sort_states
1 parent 16d5b01 commit 4531794

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/rydstate/basis/basis_base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ def filter_states(self, qn: str, value: float | tuple[float, float], *, delta: f
5757

5858
return self
5959

60+
def sort_states(self, *qns: str) -> Self:
61+
"""Sort the basis states according to the given quantum numbers.
62+
63+
The first quantum number given is the primary sorting key, the second quantum number
64+
is the secondary sorting key, and so on.
65+
"""
66+
values = np.array([self.calc_exp_qn(qn) for qn in qns])
67+
sorted_indices = np.lexsort(values[::-1])
68+
self.states = [self.states[i] for i in sorted_indices]
69+
return self
70+
6071
def calc_exp_qn(self, qn: str) -> list[float]:
6172
if is_angular_momentum_quantum_number(qn):
6273
return [state.angular.calc_exp_qn(qn) for state in self.states]

0 commit comments

Comments
 (0)