Skip to content

Commit c8b40de

Browse files
add rydberg base
1 parent 43adf3f commit c8b40de

2 files changed

Lines changed: 46 additions & 11 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
3+
import logging
4+
from abc import ABC, abstractmethod
5+
from typing import TYPE_CHECKING, Any
6+
7+
if TYPE_CHECKING:
8+
from rydstate.angular import AngularState
9+
from rydstate.angular.angular_ket import AngularKetBase
10+
from rydstate.units import MatrixElementOperator, PintFloat
11+
12+
logger = logging.getLogger(__name__)
13+
14+
15+
class RydbergStateBase(ABC):
16+
@property
17+
@abstractmethod
18+
def angular(self) -> AngularState[Any] | AngularKetBase: ...
19+
20+
@abstractmethod
21+
def calc_reduced_overlap(self, other: RydbergStateBase) -> float: ...
22+
23+
@abstractmethod
24+
def calc_reduced_matrix_element(
25+
self, other: RydbergStateBase, operator: MatrixElementOperator, unit: str | None = None
26+
) -> PintFloat | float: ...

src/rydstate/rydberg/rydberg_sqdt.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99

1010
from rydstate.angular.angular_ket import quantum_numbers_to_angular_ket
1111
from rydstate.radial import RadialKet
12+
from rydstate.rydberg.rydberg_base import RydbergStateBase
1213
from rydstate.species import SpeciesObject
1314
from rydstate.species.utils import calc_energy_from_nu
1415
from rydstate.units import BaseQuantities, MatrixElementOperatorRanks, ureg
1516

1617
if TYPE_CHECKING:
17-
from typing_extensions import Self
18-
1918
from rydstate.angular.angular_ket import AngularKetBase, AngularKetJJ, AngularKetLS
2019
from rydstate.units import MatrixElementOperator, PintFloat
2120

2221

2322
logger = logging.getLogger(__name__)
2423

2524

26-
class RydbergStateSQDT:
25+
class RydbergStateSQDT(RydbergStateBase):
2726
species: SpeciesObject
2827

2928
def __init__(
@@ -154,22 +153,27 @@ def get_energy(self, unit: str | None = None) -> PintFloat | float:
154153
return energy
155154
return energy.to(unit, "spectroscopy").magnitude
156155

157-
def calc_reduced_overlap(self, other: RydbergStateSQDT) -> float:
156+
def calc_reduced_overlap(self, other: RydbergStateBase) -> float:
158157
"""Calculate the reduced overlap <self|other> (ignoring the magnetic quantum number m)."""
158+
if not isinstance(other, RydbergStateSQDT):
159+
raise NotImplementedError("Reduced overlap only implemented between RydbergStateSQDT states.")
160+
159161
radial_overlap = self.radial.calc_overlap(other.radial)
160162
angular_overlap = self.angular.calc_reduced_overlap(other.angular)
161163
return radial_overlap * angular_overlap
162164

163-
@overload
165+
@overload # type: ignore [override]
164166
def calc_reduced_matrix_element(
165-
self, other: Self, operator: MatrixElementOperator, unit: None = None
167+
self, other: RydbergStateBase, operator: MatrixElementOperator, unit: None = None
166168
) -> PintFloat: ...
167169

168170
@overload
169-
def calc_reduced_matrix_element(self, other: Self, operator: MatrixElementOperator, unit: str) -> float: ...
171+
def calc_reduced_matrix_element(
172+
self, other: RydbergStateBase, operator: MatrixElementOperator, unit: str
173+
) -> float: ...
170174

171175
def calc_reduced_matrix_element(
172-
self, other: Self, operator: MatrixElementOperator, unit: str | None = None
176+
self, other: RydbergStateBase, operator: MatrixElementOperator, unit: str | None = None
173177
) -> PintFloat | float:
174178
r"""Calculate the reduced matrix element.
175179
@@ -192,6 +196,9 @@ def calc_reduced_matrix_element(
192196
The reduced matrix element for the given operator.
193197
194198
"""
199+
if not isinstance(other, RydbergStateSQDT):
200+
raise NotImplementedError("Reduced matrix element only implemented between RydbergStateSQDT states.")
201+
195202
if operator not in MatrixElementOperatorRanks:
196203
raise ValueError(
197204
f"Operator {operator} not supported, must be one of {list(MatrixElementOperatorRanks.keys())}."
@@ -234,13 +241,15 @@ def calc_reduced_matrix_element(
234241
return matrix_element.to(unit).magnitude
235242

236243
@overload
237-
def calc_matrix_element(self, other: Self, operator: MatrixElementOperator, q: int) -> PintFloat: ...
244+
def calc_matrix_element(self, other: RydbergStateSQDT, operator: MatrixElementOperator, q: int) -> PintFloat: ...
238245

239246
@overload
240-
def calc_matrix_element(self, other: Self, operator: MatrixElementOperator, q: int, unit: str) -> float: ...
247+
def calc_matrix_element(
248+
self, other: RydbergStateSQDT, operator: MatrixElementOperator, q: int, unit: str
249+
) -> float: ...
241250

242251
def calc_matrix_element(
243-
self, other: Self, operator: MatrixElementOperator, q: int, unit: str | None = None
252+
self, other: RydbergStateSQDT, operator: MatrixElementOperator, q: int, unit: str | None = None
244253
) -> PintFloat | float:
245254
r"""Calculate the matrix element.
246255

0 commit comments

Comments
 (0)