diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 29cd294..5cb60ff 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -19,6 +19,8 @@ Bug Fixes +++++++++ - Fix `convert_complex_to_dm` to properly return arrays with real dtype. +- Fix `Cell.kappa` and `Cell.eta` to properly introspect `q` when first edge on the graph + happens to not be dipole-allowed. Deprecations ++++++++++++ diff --git a/src/rydiqule/cell.py b/src/rydiqule/cell.py index 8b4a1ad..60ee907 100644 --- a/src/rydiqule/cell.py +++ b/src/rydiqule/cell.py @@ -390,7 +390,14 @@ def kappa(self) -> float: " = prior to running calculations" warnings.warn(msg) - q = self.couplings.edges[ground_manifold[0], excited_manifold[0]]["q"] + # extract q from coupling group, this ensures we find a dipole allowed edge with q defined + manifold_subgraph = self._coupling_subgraph(self.probe_tuple) + for (_, _, d) in manifold_subgraph.edges(data=True): + if 'q' in d: + q = d['q'] + break + else: + raise RydiquleError(f"No 'q' defined for coupling {self.probe_tuple}") omega_rad = self.atom.get_transition_frequency(probe_g_nlj, probe_e_nlj)*2*np.pi dipole_moment = self.atom.get_dipole_matrix_element(probe_g_nlj, probe_e_nlj, q=q)*a0*e @@ -481,7 +488,14 @@ def eta(self) -> float: " = prior to running calculations" warnings.warn(msg) - q = self.couplings.edges[ground_manifold[0], excited_manifold[0]]["q"] + # extract q from coupling group, this ensures we find a dipole allowed edge with q defined + manifold_subgraph = self._coupling_subgraph(self.probe_tuple) + for (_, _, d) in manifold_subgraph.edges(data=True): + if 'q' in d: + q = d['q'] + break + else: + raise RydiquleError(f"No 'q' defined for coupling {self.probe_tuple}") omega_rad = self.atom.get_transition_frequency(probe_g_nlj, probe_e_nlj)*2.0*np.pi dipole_moment = self.atom.get_dipole_matrix_element(probe_g_nlj, probe_e_nlj, q=q)*a0*e diff --git a/src/rydiqule/sensor.py b/src/rydiqule/sensor.py index 6923430..061b0c6 100644 --- a/src/rydiqule/sensor.py +++ b/src/rydiqule/sensor.py @@ -3066,6 +3066,29 @@ def states_with_spec(self, statespec: StateSpec) -> List[State]: """ return match_states(statespec, self.states) + + + def _coupling_subgraph(self, coupling: StateSpecs) -> nx.Graph: + """ + Returns a subgraph view of the couplings graph corresponding to `coupling`. + + Parameters + ---------- + coupling: StateSpecs + Coupling specification + + Returns + ------- + networkx.Graph + View of the corresponding subgraph + """ + + states1 = self.states_with_spec(coupling[0]) + states2 = self.states_with_spec(coupling[1]) + + subgraph = self.couplings.subgraph(states1 + states2) + + return subgraph def get_couplings(self) -> Dict[States, CouplingDict]: