From a06a75b742446e29a486d6b393cd25454f916250 Mon Sep 17 00:00:00 2001 From: Oliver Backhouse Date: Tue, 6 Aug 2024 22:59:10 +0100 Subject: [PATCH 1/2] Use Namespace for EOM excitation amplitudes --- ebcc/cc/base.py | 65 +++++++++---------- ebcc/cc/gebcc.py | 46 ++++++-------- ebcc/cc/rebcc.py | 40 +++++------- ebcc/cc/uebcc.py | 48 ++++++-------- ebcc/codegen/GCCSD.py | 6 +- ebcc/codegen/UCCSD.py | 6 +- ebcc/eom/base.py | 36 +++++------ ebcc/eom/geom.py | 87 ++++++++++++++++++------- ebcc/eom/reom.py | 87 ++++++++++++++++++------- ebcc/eom/ueom.py | 144 +++++++++++++++++++++--------------------- 10 files changed, 303 insertions(+), 262 deletions(-) diff --git a/ebcc/cc/base.py b/ebcc/cc/base.py index c3e8ea41..b9ccc64a 100644 --- a/ebcc/cc/base.py +++ b/ebcc/cc/base.py @@ -475,6 +475,7 @@ def _load_function( eris: Optional[Union[ERIsInputType, Literal[False]]] = False, amplitudes: Optional[Union[Namespace[SpinArrayType], Literal[False]]] = False, lambdas: Optional[Union[Namespace[SpinArrayType], Literal[False]]] = False, + excitations: Optional[Namespace[SpinArrayType]] = None, **kwargs: Any, ) -> tuple[Callable[..., Any], dict[str, Any]]: """Load a function from the generated code, and return the arguments.""" @@ -497,6 +498,10 @@ def _load_function( else: dicts.append(dict(self._get_lams(lambdas=lambdas))) + # Get the excitation amplitudes: + if excitations: + dicts.append(dict(excitations)) + # Get the function: func = getattr(self._eqns, name, None) if func is None: @@ -791,15 +796,14 @@ def make_eb_coup_rdm( def hbar_matvec_ip( self, - *excitations: SpinArrayType, + excitations: Namespace[SpinArrayType], eris: Optional[ERIsInputType] = None, amplitudes: Optional[Namespace[SpinArrayType]] = None, - ) -> tuple[SpinArrayType, SpinArrayType]: + ) -> Namespace[SpinArrayType]: """Compute the product between a state vector and the IP-EOM Hamiltonian. Args: - r1: State vector (single excitations). - r2: State vector (double excitations). + excitations: State vector as a set of excitation amplitudes. eris: Electron repulsion integrals. amplitudes: Cluster amplitudes. @@ -807,28 +811,26 @@ def hbar_matvec_ip( Products between the state vectors and the IP-EOM Hamiltonian for the singles and doubles. """ - r1, r2 = excitations # FIXME func, kwargs = self._load_function( "hbar_matvec_ip", eris=eris, amplitudes=amplitudes, - r1=r1, - r2=r2, + excitations=excitations, ) - res: tuple[SpinArrayType, SpinArrayType] = func(**kwargs) + res: Namespace[SpinArrayType] = func(**kwargs) + res = util.Namespace(**{key.rstrip("new"): val for key, val in res.items()}) return res def hbar_matvec_ea( self, - *excitations: SpinArrayType, + excitations: Namespace[SpinArrayType], eris: Optional[ERIsInputType] = None, amplitudes: Optional[Namespace[SpinArrayType]] = None, - ) -> tuple[SpinArrayType, SpinArrayType]: + ) -> Namespace[SpinArrayType]: """Compute the product between a state vector and the EA-EOM Hamiltonian. Args: - r1: State vector (single excitations). - r2: State vector (double excitations). + excitations: State vector as a set of excitation amplitudes. eris: Electron repulsion integrals. amplitudes: Cluster amplitudes. @@ -836,28 +838,26 @@ def hbar_matvec_ea( Products between the state vectors and the EA-EOM Hamiltonian for the singles and doubles. """ - r1, r2 = excitations # FIXME func, kwargs = self._load_function( "hbar_matvec_ea", eris=eris, amplitudes=amplitudes, - r1=r1, - r2=r2, + excitations=excitations, ) - res: tuple[SpinArrayType, SpinArrayType] = func(**kwargs) + res: Namespace[SpinArrayType] = func(**kwargs) + res = util.Namespace(**{key.rstrip("new"): val for key, val in res.items()}) return res def hbar_matvec_ee( self, - *excitations: SpinArrayType, + excitations: Namespace[SpinArrayType], eris: Optional[ERIsInputType] = None, amplitudes: Optional[Namespace[SpinArrayType]] = None, - ) -> tuple[SpinArrayType, SpinArrayType]: + ) -> Namespace[SpinArrayType]: """Compute the product between a state vector and the EE-EOM Hamiltonian. Args: - r1: State vector (single excitations). - r2: State vector (double excitations). + excitations: State vector as a set of excitation amplitudes. eris: Electron repulsion integrals. amplitudes: Cluster amplitudes. @@ -865,15 +865,14 @@ def hbar_matvec_ee( Products between the state vectors and the EE-EOM Hamiltonian for the singles and doubles. """ - r1, r2 = excitations # FIXME func, kwargs = self._load_function( "hbar_matvec_ee", eris=eris, amplitudes=amplitudes, - r1=r1, - r2=r2, + excitations=excitations, ) - res: tuple[SpinArrayType, SpinArrayType] = func(**kwargs) + res: Namespace[SpinArrayType] = func(**kwargs) + res = util.Namespace(**{key.rstrip("new"): val for key, val in res.items()}) return res def make_ip_mom_bras( @@ -1089,7 +1088,7 @@ def vector_to_lambdas(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: pass @abstractmethod - def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ip(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the IP-EOM excitations. Args: @@ -1101,7 +1100,7 @@ def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> ND pass @abstractmethod - def excitations_to_vector_ea(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ea(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the EA-EOM excitations. Args: @@ -1113,7 +1112,7 @@ def excitations_to_vector_ea(self, *excitations: Namespace[SpinArrayType]) -> ND pass @abstractmethod - def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ee(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the EE-EOM excitations. Args: @@ -1125,9 +1124,7 @@ def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> ND pass @abstractmethod - def vector_to_excitations_ip( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ip(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of IP-EOM excitations from a vector. Args: @@ -1139,9 +1136,7 @@ def vector_to_excitations_ip( pass @abstractmethod - def vector_to_excitations_ea( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ea(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of EA-EOM excitations from a vector. Args: @@ -1153,9 +1148,7 @@ def vector_to_excitations_ea( pass @abstractmethod - def vector_to_excitations_ee( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ee(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of EE-EOM excitations from a vector. Args: diff --git a/ebcc/cc/gebcc.py b/ebcc/cc/gebcc.py index 3d96788b..de3368d4 100644 --- a/ebcc/cc/gebcc.py +++ b/ebcc/cc/gebcc.py @@ -815,7 +815,7 @@ def vector_to_lambdas(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: return lambdas - def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ip(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the IP-EOM excitations. Args: @@ -825,12 +825,10 @@ def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> ND IP-EOM excitations as a vector. """ vectors = [] - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[:-1] - vectors.append(util.compress_axes(key, excitations[m]).ravel()) - m += 1 + vectors.append(util.compress_axes(key, excitations[f"r{n}"]).ravel()) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -840,7 +838,7 @@ def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> ND return np.concatenate(vectors) - def excitations_to_vector_ea(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ea(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the EA-EOM excitations. Args: @@ -849,9 +847,9 @@ def excitations_to_vector_ea(self, *excitations: Namespace[SpinArrayType]) -> ND Returns: EA-EOM excitations as a vector. """ - return self.excitations_to_vector_ip(*excitations) + return self.excitations_to_vector_ip(excitations) - def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ee(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the EE-EOM excitations. Args: @@ -861,11 +859,9 @@ def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> ND EE-EOM excitations as a vector. """ vectors = [] - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): - vectors.append(util.compress_axes(key, excitations[m]).ravel()) - m += 1 + vectors.append(util.compress_axes(key, excitations[f"r{n}"]).ravel()) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -875,9 +871,7 @@ def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> ND return np.concatenate(vectors) - def vector_to_excitations_ip( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ip(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of IP-EOM excitations from a vector. Args: @@ -886,7 +880,7 @@ def vector_to_excitations_ip( Returns: IP-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): @@ -895,7 +889,7 @@ def vector_to_excitations_ip( shape = tuple(self.space.size(k) for k in key) vn_tril = vector[i0 : i0 + size] vn = util.decompress_axes(key, vn_tril, shape=shape) - excitations.append(vn) + excitations[f"r{n}"] = vn i0 += size for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): @@ -904,11 +898,9 @@ def vector_to_excitations_ip( for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return tuple(excitations) + return excitations - def vector_to_excitations_ea( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ea(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of EA-EOM excitations from a vector. Args: @@ -917,7 +909,7 @@ def vector_to_excitations_ea( Returns: EA-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): @@ -926,7 +918,7 @@ def vector_to_excitations_ea( shape = tuple(self.space.size(k) for k in key) vn_tril = vector[i0 : i0 + size] vn = util.decompress_axes(key, vn_tril, shape=shape) - excitations.append(vn) + excitations[f"r{n}"] = vn i0 += size for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): @@ -935,11 +927,9 @@ def vector_to_excitations_ea( for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return tuple(excitations) + return excitations - def vector_to_excitations_ee( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ee(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of EE-EOM excitations from a vector. Args: @@ -948,7 +938,7 @@ def vector_to_excitations_ee( Returns: EE-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): @@ -956,7 +946,7 @@ def vector_to_excitations_ee( shape = tuple(self.space.size(k) for k in key) vn_tril = vector[i0 : i0 + size] vn = util.decompress_axes(key, vn_tril, shape=shape) - excitations.append(vn) + excitations[f"r{n}"] = vn i0 += size for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): @@ -965,7 +955,7 @@ def vector_to_excitations_ee( for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return tuple(excitations) + return excitations def get_mean_field_G(self) -> NDArray[float]: """Get the mean-field boson non-conserving term. diff --git a/ebcc/cc/rebcc.py b/ebcc/cc/rebcc.py index 08623a1e..243cb0df 100644 --- a/ebcc/cc/rebcc.py +++ b/ebcc/cc/rebcc.py @@ -591,7 +591,7 @@ def vector_to_lambdas(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: return lambdas - def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ip(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the IP-EOM excitations. Args: @@ -601,11 +601,9 @@ def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> ND IP-EOM excitations as a vector. """ vectors = [] - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): - vectors.append(excitations[m].ravel()) - m += 1 + vectors.append(excitations[f"r{n}"].ravel()) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -626,7 +624,7 @@ def excitations_to_vector_ea(self, *excitations: Namespace[SpinArrayType]) -> ND """ return self.excitations_to_vector_ip(*excitations) - def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ee(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the EE-EOM excitations. Args: @@ -635,11 +633,9 @@ def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> ND Returns: EE-EOM excitations as a vector. """ - return self.excitations_to_vector_ip(*excitations) + return self.excitations_to_vector_ip(excitations) - def vector_to_excitations_ip( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ip(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of IP-EOM excitations from a vector. Args: @@ -648,14 +644,14 @@ def vector_to_excitations_ip( Returns: IP-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[:-1] shape = tuple(self.space.size(k) for k in key) size = np.prod(shape) - excitations.append(vector[i0 : i0 + size].reshape(shape)) + excitations[f"r{n}"] = vector[i0 : i0 + size].reshape(shape) i0 += size for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): @@ -664,11 +660,9 @@ def vector_to_excitations_ip( for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return tuple(excitations) + return excitations - def vector_to_excitations_ea( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ea(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of EA-EOM excitations from a vector. Args: @@ -677,14 +671,14 @@ def vector_to_excitations_ea( Returns: EA-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[n:] + key[: n - 1] shape = tuple(self.space.size(k) for k in key) size = np.prod(shape) - excitations.append(vector[i0 : i0 + size].reshape(shape)) + excitations[f"r{n}"] = vector[i0 : i0 + size].reshape(shape) i0 += size for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): @@ -693,11 +687,9 @@ def vector_to_excitations_ea( for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return tuple(excitations) + return excitations - def vector_to_excitations_ee( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ee(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of EE-EOM excitations from a vector. Args: @@ -706,13 +698,13 @@ def vector_to_excitations_ee( Returns: EE-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): shape = tuple(self.space.size(k) for k in key) size = np.prod(shape) - excitations.append(vector[i0 : i0 + size].reshape(shape)) + excitations[f"r{n}"] = vector[i0 : i0 + size].reshape(shape) i0 += size for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): @@ -721,7 +713,7 @@ def vector_to_excitations_ee( for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return tuple(excitations) + return excitations def get_mean_field_G(self) -> NDArray[float]: """Get the mean-field boson non-conserving term. diff --git a/ebcc/cc/uebcc.py b/ebcc/cc/uebcc.py index 66d6b1a1..d94f9b52 100644 --- a/ebcc/cc/uebcc.py +++ b/ebcc/cc/uebcc.py @@ -781,7 +781,7 @@ def vector_to_lambdas(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: return lambdas - def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ip(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the IP-EOM excitations. Args: @@ -791,14 +791,12 @@ def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> ND IP-EOM excitations as a vector. """ vectors = [] - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): for spin in util.generate_spin_combinations(n, excited=True, unique=True): - vn = excitations[m][spin] + vn = excitations[f"r{n}"][spin] subscript, _ = util.combine_subscripts(key[:-1], spin) vectors.append(util.compress_axes(subscript, vn).ravel()) - m += 1 for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -808,7 +806,7 @@ def excitations_to_vector_ip(self, *excitations: Namespace[SpinArrayType]) -> ND return np.concatenate(vectors) - def excitations_to_vector_ea(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ea(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the EA-EOM excitations. Args: @@ -818,15 +816,13 @@ def excitations_to_vector_ea(self, *excitations: Namespace[SpinArrayType]) -> ND EA-EOM excitations as a vector. """ vectors = [] - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[n:] + key[:n] for spin in util.generate_spin_combinations(n, excited=True, unique=True): - vn = excitations[m][spin] + vn = excitations[f"r{n}"][spin] subscript, _ = util.combine_subscripts(key[:-1], spin) vectors.append(util.compress_axes(subscript, vn).ravel()) - m += 1 for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -836,7 +832,7 @@ def excitations_to_vector_ea(self, *excitations: Namespace[SpinArrayType]) -> ND return np.concatenate(vectors) - def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> NDArray[float]: + def excitations_to_vector_ee(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the EE-EOM excitations. Args: @@ -846,14 +842,12 @@ def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> ND EE-EOM excitations as a vector. """ vectors = [] - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): for spin in util.generate_spin_combinations(n): - vn = excitations[m][spin] + vn = excitations[f"r{n}"][spin] subscript, _ = util.combine_subscripts(key, spin) vectors.append(util.compress_axes(subscript, vn).ravel()) - m += 1 for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -863,9 +857,7 @@ def excitations_to_vector_ee(self, *excitations: Namespace[SpinArrayType]) -> ND return np.concatenate(vectors) - def vector_to_excitations_ip( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ip(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of IP-EOM excitations from a vector. Args: @@ -874,7 +866,7 @@ def vector_to_excitations_ip( Returns: IP-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 sizes: dict[tuple[str, ...], int] = { (o, s): self.space[i].size(o) for o in "ovOVia" for i, s in enumerate("ab") @@ -895,7 +887,7 @@ def vector_to_excitations_ip( amp[spin] = vn i0 += size - excitations.append(amp) + excitations[f"r{n}"] = amp for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -905,11 +897,9 @@ def vector_to_excitations_ip( assert i0 == len(vector) - return tuple(excitations) + return excitations - def vector_to_excitations_ea( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ea(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of EA-EOM excitations from a vector. Args: @@ -918,7 +908,7 @@ def vector_to_excitations_ea( Returns: EA-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 sizes: dict[tuple[str, ...], int] = { (o, s): self.space[i].size(o) for o in "ovOVia" for i, s in enumerate("ab") @@ -939,7 +929,7 @@ def vector_to_excitations_ea( amp[spin] = vn i0 += size - excitations.append(amp) + excitations[f"r{n}"] = amp for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -949,11 +939,9 @@ def vector_to_excitations_ea( assert i0 == len(vector) - return tuple(excitations) + return excitations - def vector_to_excitations_ee( - self, vector: NDArray[float] - ) -> tuple[Namespace[SpinArrayType], ...]: + def vector_to_excitations_ee(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct a namespace of EE-EOM excitations from a vector. Args: @@ -962,7 +950,7 @@ def vector_to_excitations_ee( Returns: EE-EOM excitations. """ - excitations = [] + excitations: Namespace[SpinArrayType] = util.Namespace() i0 = 0 sizes: dict[tuple[str, ...], int] = { (o, s): self.space[i].size(o) for o in "ovOVia" for i, s in enumerate("ab") @@ -982,7 +970,7 @@ def vector_to_excitations_ee( amp[spin] = vn i0 += size - excitations.append(amp) + excitations[f"r{n}"] = amp for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -992,7 +980,7 @@ def vector_to_excitations_ee( assert i0 == len(vector) - return tuple(excitations) + return excitations def get_mean_field_G(self) -> NDArray[float]: """Get the mean-field boson non-conserving term. diff --git a/ebcc/codegen/GCCSD.py b/ebcc/codegen/GCCSD.py index 66ea8405..b4cbdbdd 100644 --- a/ebcc/codegen/GCCSD.py +++ b/ebcc/codegen/GCCSD.py @@ -1019,7 +1019,7 @@ def hbar_matvec_ip(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=No r1new -= einsum("i,ij->j", r1, f.oo) r2new += einsum("i,iajk->kja", r1, v.ovoo) - return r1new, r2new + return {"r1new": r1new, "r2new": r2new} def hbar_matvec_ea(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=None, l2=None, r1=None, r2=None, **kwargs): r2 = -r2 @@ -1247,7 +1247,7 @@ def hbar_matvec_ea(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=No r1new += einsum("a,ba->b", r1, f.vv) r2new += einsum("a,bcia->cbi", r1, v.vvov) - return r1new, r2new + return {"r1new": r1new, "r2new": r2new} def make_ee_mom_kets(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=None, l2=None, **kwargs): delta_oo = np.eye(nocc) @@ -1834,5 +1834,5 @@ def hbar_matvec_ee(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=No ree2new += einsum("ia,jb->jiab", r1, x125) del x125 - return ree1new, ree2new + return {"r1new": ree1new, "r2new": ree2new} diff --git a/ebcc/codegen/UCCSD.py b/ebcc/codegen/UCCSD.py index 559120b0..542a7ddf 100644 --- a/ebcc/codegen/UCCSD.py +++ b/ebcc/codegen/UCCSD.py @@ -4012,7 +4012,7 @@ def hbar_matvec_ip(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=No r1new = Namespace(a=r1new_a, b=r1new_b) r2new = Namespace(aaa=r2new_aaa, aba=r2new_aba, bab=r2new_bab, bbb=r2new_bbb) - return r1new, r2new + return {"r1new": r1new, "r2new": r2new} def hbar_matvec_ea(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=None, l2=None, r1=None, r2=None, **kwargs): x0 = np.zeros((nocc[0], nocc[1], nvir[1]), dtype=types[float]) @@ -4879,7 +4879,7 @@ def hbar_matvec_ea(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=No r2new.bab *= -1 r2new.bbb *= -1 - return r1new, r2new + return {"r1new": r1new, "r2new": r2new} def make_ee_mom_kets(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=None, l2=None, **kwargs): # pragma: no cover delta_oo = Namespace() @@ -7373,5 +7373,5 @@ def hbar_matvec_ee(f=None, v=None, nocc=None, nvir=None, t1=None, t2=None, l1=No ree1new = Namespace(aa=ree1new_aa, bb=ree1new_bb) ree2new = Namespace(aaaa=ree2new_aaaa, abab=ree2new_abab, baba=ree2new_baba, bbbb=ree2new_bbbb) - return ree1new, ree2new + return {"r1new": ree1new, "r2new": ree2new} diff --git a/ebcc/eom/base.py b/ebcc/eom/base.py index 263f2133..3e3b1d41 100644 --- a/ebcc/eom/base.py +++ b/ebcc/eom/base.py @@ -121,7 +121,7 @@ def name(self) -> str: return f"{self.excitation_type.upper()}-EOM-{self.spin_type}{self.ansatz.name}" @abstractmethod - def amplitudes_to_vector(self, *amplitudes: SpinArrayType) -> NDArray[float]: + def amplitudes_to_vector(self, amplitudes: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the amplitudes used in the given ansatz. Args: @@ -133,7 +133,7 @@ def amplitudes_to_vector(self, *amplitudes: SpinArrayType) -> NDArray[float]: pass @abstractmethod - def vector_to_amplitudes(self, vector: NDArray[float]) -> tuple[SpinArrayType, ...]: + def vector_to_amplitudes(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct amplitudes from a vector. Args: @@ -339,7 +339,7 @@ def davidson( f"{ANSI.B}{'Root':>4s} {'Energy':>16s} {'Weight':>13s} {'Conv.':>8s}{ANSI.R}" ) for n, (en, vn, cn) in enumerate(zip(e, v, converged)): - r1n = self.vector_to_amplitudes(vn)[0] + r1n = self.vector_to_amplitudes(vn)["r1"] qpwt = self._quasiparticle_weight(r1n) self.log.output( f"{n:>4d} {en:>16.10f} {qpwt:>13.5g} {[ANSI.r, ANSI.g][bool(cn)]}{cn!r:>8s}{ANSI.R}" @@ -398,7 +398,7 @@ def excitation_type(self) -> str: """Get the type of excitation.""" return "ip" - def amplitudes_to_vector(self, *amplitudes: SpinArrayType) -> NDArray[float]: + def amplitudes_to_vector(self, amplitudes: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the amplitudes used in the given ansatz. Args: @@ -407,9 +407,9 @@ def amplitudes_to_vector(self, *amplitudes: SpinArrayType) -> NDArray[float]: Returns: Cluster amplitudes as a vector. """ - return self.ebcc.excitations_to_vector_ip(*amplitudes) + return self.ebcc.excitations_to_vector_ip(amplitudes) - def vector_to_amplitudes(self, vector: NDArray[float]) -> tuple[SpinArrayType, ...]: + def vector_to_amplitudes(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct amplitudes from a vector. Args: @@ -433,8 +433,8 @@ def matvec( Resulting vector. """ amplitudes = self.vector_to_amplitudes(vector) - result = self.ebcc.hbar_matvec_ip(*amplitudes, eris=eris) - return self.amplitudes_to_vector(*result) + result = self.ebcc.hbar_matvec_ip(amplitudes, eris=eris) + return self.amplitudes_to_vector(result) class BaseEA_EOM(BaseEOM): @@ -445,7 +445,7 @@ def excitation_type(self) -> str: """Get the type of excitation.""" return "ea" - def amplitudes_to_vector(self, *amplitudes: SpinArrayType) -> NDArray[float]: + def amplitudes_to_vector(self, amplitudes: SpinArrayType) -> NDArray[float]: """Construct a vector containing all of the amplitudes used in the given ansatz. Args: @@ -454,9 +454,9 @@ def amplitudes_to_vector(self, *amplitudes: SpinArrayType) -> NDArray[float]: Returns: Cluster amplitudes as a vector. """ - return self.ebcc.excitations_to_vector_ea(*amplitudes) + return self.ebcc.excitations_to_vector_ea(amplitudes) - def vector_to_amplitudes(self, vector: NDArray[float]) -> tuple[SpinArrayType, ...]: + def vector_to_amplitudes(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct amplitudes from a vector. Args: @@ -480,8 +480,8 @@ def matvec( Resulting vector. """ amplitudes = self.vector_to_amplitudes(vector) - result = self.ebcc.hbar_matvec_ea(*amplitudes, eris=eris) - return self.amplitudes_to_vector(*result) + result = self.ebcc.hbar_matvec_ea(amplitudes, eris=eris) + return self.amplitudes_to_vector(result) class BaseEE_EOM(BaseEOM): @@ -492,7 +492,7 @@ def excitation_type(self) -> str: """Get the type of excitation.""" return "ee" - def amplitudes_to_vector(self, *amplitudes: SpinArrayType) -> NDArray[float]: + def amplitudes_to_vector(self, amplitudes: Namespace[SpinArrayType]) -> NDArray[float]: """Construct a vector containing all of the amplitudes used in the given ansatz. Args: @@ -501,9 +501,9 @@ def amplitudes_to_vector(self, *amplitudes: SpinArrayType) -> NDArray[float]: Returns: Cluster amplitudes as a vector. """ - return self.ebcc.excitations_to_vector_ee(*amplitudes) + return self.ebcc.excitations_to_vector_ee(amplitudes) - def vector_to_amplitudes(self, vector: NDArray[float]) -> tuple[SpinArrayType, ...]: + def vector_to_amplitudes(self, vector: NDArray[float]) -> Namespace[SpinArrayType]: """Construct amplitudes from a vector. Args: @@ -527,5 +527,5 @@ def matvec( Resulting vector. """ amplitudes = self.vector_to_amplitudes(vector) - result = self.ebcc.hbar_matvec_ee(*amplitudes, eris=eris) - return self.amplitudes_to_vector(*result) + result = self.ebcc.hbar_matvec_ee(amplitudes, eris=eris) + return self.amplitudes_to_vector(result) diff --git a/ebcc/eom/geom.py b/ebcc/eom/geom.py index 9faede45..9c69c551 100644 --- a/ebcc/eom/geom.py +++ b/ebcc/eom/geom.py @@ -33,7 +33,7 @@ class IP_GEOM(GEOM, BaseIP_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(np.abs(diag[: r1.size])) else: arg = np.argsort(np.abs(diag)) @@ -53,16 +53,16 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = util.Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[:-1] - parts.append(self.ebcc.energy_sum(key)) + parts[f"r{n}"] = self.ebcc.energy_sum(key) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. @@ -73,9 +73,16 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Bra vectors. """ - bras_raw = list(self.ebcc.make_ip_mom_bras(eris=eris)) + bras_raw = util.Namespace( + **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} + ) bras = np.array( - [self.amplitudes_to_vector(*[b[i] for b in bras_raw]) for i in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: b[i] for key, b in bras_raw.items()}) + ) + for i in range(self.nmo) + ] ) return bras @@ -88,9 +95,16 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Ket vectors. """ - kets_raw = list(self.ebcc.make_ip_mom_kets(eris=eris)) + kets_raw = util.Namespace( + **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} + ) kets = np.array( - [self.amplitudes_to_vector(*[k[..., i] for k in kets_raw]) for i in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: k[..., i] for key, k in kets_raw.items()}) + ) + for i in range(self.nmo) + ] ) return kets @@ -144,7 +158,7 @@ class EA_GEOM(GEOM, BaseEA_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(np.abs(diag[: r1.size])) else: arg = np.argsort(np.abs(diag)) @@ -164,16 +178,16 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = util.Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[n:] + key[: n - 1] - parts.append(-self.ebcc.energy_sum(key)) + parts[f"r{n}"] = -self.ebcc.energy_sum(key) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. @@ -184,9 +198,16 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Bra vectors. """ - bras_raw = list(self.ebcc.make_ea_mom_bras(eris=eris)) + bras_raw = util.Namespace( + **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} + ) bras = np.array( - [self.amplitudes_to_vector(*[b[i] for b in bras_raw]) for i in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: b[i] for key, b in bras_raw.items()}) + ) + for i in range(self.nmo) + ] ) return bras @@ -199,9 +220,16 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Ket vectors. """ - kets_raw = list(self.ebcc.make_ea_mom_kets(eris=eris)) + kets_raw = util.Namespace( + **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} + ) kets = np.array( - [self.amplitudes_to_vector(*[k[..., i] for k in kets_raw]) for i in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: k[..., i] for key, k in kets_raw.items()}) + ) + for i in range(self.nmo) + ] ) return kets @@ -255,7 +283,7 @@ class EE_GEOM(GEOM, BaseEE_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(diag[: r1.size]) else: arg = np.argsort(diag) @@ -275,15 +303,15 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = util.Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): - parts.append(-self.ebcc.energy_sum(key)) + parts[f"r{n}"] = -self.ebcc.energy_sum(key) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. @@ -294,10 +322,17 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Bra vectors. """ - bras_raw = list(self.ebcc.make_ee_mom_bras(eris=eris)) + bras_raw = util.Namespace( + **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ee_mom_bras(eris=eris))} + ) bras = np.array( [ - [self.amplitudes_to_vector(*[b[i, j] for b in bras_raw]) for j in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: b[i, j] for key, b in bras_raw.items()}) + ) + for j in range(self.nmo) + ] for i in range(self.nmo) ] ) @@ -312,11 +347,15 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Ket vectors. """ - kets_raw = list(self.ebcc.make_ee_mom_kets(eris=eris)) + kets_raw = util.Namespace( + **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ee_mom_kets(eris=eris))} + ) kets = np.array( [ [ - self.amplitudes_to_vector(*[k[..., i, j] for k in kets_raw]) + self.amplitudes_to_vector( + util.Namespace(**{key: k[..., i, j] for key, k in kets_raw.items()}) + ) for j in range(self.nmo) ] for i in range(self.nmo) diff --git a/ebcc/eom/reom.py b/ebcc/eom/reom.py index 8c179f05..54c0447d 100644 --- a/ebcc/eom/reom.py +++ b/ebcc/eom/reom.py @@ -33,7 +33,7 @@ class IP_REOM(REOM, BaseIP_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(np.abs(diag[: r1.size])) else: arg = np.argsort(np.abs(diag)) @@ -53,16 +53,16 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[:-1] - parts.append(self.ebcc.energy_sum(key)) + parts[f"r{n}"] = self.ebcc.energy_sum(key) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. @@ -73,9 +73,16 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Bra vectors. """ - bras_raw = list(self.ebcc.make_ip_mom_bras(eris=eris)) + bras_raw = util.Namespace( + **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} + ) bras = np.array( - [self.amplitudes_to_vector(*[b[i] for b in bras_raw]) for i in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: b[i] for key, b in bras_raw.items()}) + ) + for i in range(self.nmo) + ] ) return bras @@ -88,9 +95,16 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Ket vectors. """ - kets_raw = list(self.ebcc.make_ip_mom_kets(eris=eris)) + kets_raw = util.Namespace( + **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} + ) kets = np.array( - [self.amplitudes_to_vector(*[k[..., i] for k in kets_raw]) for i in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: k[..., i] for key, k in kets_raw.items()}) + ) + for i in range(self.nmo) + ] ) return kets @@ -144,7 +158,7 @@ class EA_REOM(REOM, BaseEA_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(np.abs(diag[: r1.size])) else: arg = np.argsort(np.abs(diag)) @@ -164,16 +178,16 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[n:] + key[: n - 1] - parts.append(-self.ebcc.energy_sum(key)) + parts[f"r{n}"] = self.ebcc.energy_sum(key) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. @@ -184,9 +198,16 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Bra vectors. """ - bras_raw = list(self.ebcc.make_ea_mom_bras(eris=eris)) + bras_raw = util.Namespace( + **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} + ) bras = np.array( - [self.amplitudes_to_vector(*[b[i] for b in bras_raw]) for i in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: b[i] for key, b in bras_raw.items()}) + ) + for i in range(self.nmo) + ] ) return bras @@ -199,9 +220,16 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Ket vectors. """ - kets_raw = list(self.ebcc.make_ea_mom_kets(eris=eris)) + kets_raw = util.Namespace( + **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} + ) kets = np.array( - [self.amplitudes_to_vector(*[k[..., i] for k in kets_raw]) for i in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: k[..., i] for key, k in kets_raw.items()}) + ) + for i in range(self.nmo) + ] ) return kets @@ -255,7 +283,7 @@ class EE_REOM(REOM, BaseEE_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(diag[: r1.size]) else: arg = np.argsort(diag) @@ -275,15 +303,15 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): - parts.append(-self.ebcc.energy_sum(key)) + parts[f"r{n}"] = -self.ebcc.energy_sum(key) for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. @@ -294,10 +322,17 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Bra vectors. """ - bras_raw = list(self.ebcc.make_ee_mom_bras(eris=eris)) + bras_raw = util.Namespace( + **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ee_mom_bras(eris=eris))} + ) bras = np.array( [ - [self.amplitudes_to_vector(*[b[i, j] for b in bras_raw]) for j in range(self.nmo)] + [ + self.amplitudes_to_vector( + util.Namespace(**{key: b[i, j] for key, b in bras_raw.items()}) + ) + for j in range(self.nmo) + ] for i in range(self.nmo) ] ) @@ -312,11 +347,15 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Ket vectors. """ - kets_raw = list(self.ebcc.make_ee_mom_kets(eris=eris)) + kets_raw = util.Namespace( + **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ee_mom_kets(eris=eris))} + ) kets = np.array( [ [ - self.amplitudes_to_vector(*[k[..., i, j] for k in kets_raw]) + self.amplitudes_to_vector( + util.Namespace(**{key: k[..., i, j] for key, k in kets_raw.items()}) + ) for j in range(self.nmo) ] for i in range(self.nmo) diff --git a/ebcc/eom/ueom.py b/ebcc/eom/ueom.py index 550cd66a..ff9dd076 100644 --- a/ebcc/eom/ueom.py +++ b/ebcc/eom/ueom.py @@ -32,7 +32,7 @@ class IP_UEOM(UEOM, BaseIP_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(np.abs(diag[: r1.a.size + r1.b.size])) else: arg = np.argsort(np.abs(diag)) @@ -52,19 +52,19 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = util.Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[:-1] spin_part: SpinArrayType = util.Namespace() for comb in util.generate_spin_combinations(n, excited=True): spin_part[comb] = self.ebcc.energy_sum(key, comb) - parts.append(spin_part) + parts[f"r{n}"] = spin_part for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. @@ -75,14 +75,15 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Bra vectors. """ - bras_raw = list(self.ebcc.make_ip_mom_bras(eris=eris)) + bras_raw = util.Namespace( + **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} + ) bras_tmp: Namespace[list[NDArray[float]]] = util.Namespace(a=[], b=[]) for i in range(self.nmo): - amps_a: list[SpinArrayType] = [] - amps_b: list[SpinArrayType] = [] + amps_a: Namespace[SpinArrayType] = util.Namespace() + amps_b: Namespace[SpinArrayType] = util.Namespace() - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): amp_a: SpinArrayType = util.Namespace() amp_b: SpinArrayType = util.Namespace() @@ -93,20 +94,19 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: setattr( amp_a, spin, - getattr(bras_raw[m], "a" + spin, {i: np.zeros(shape, dtype=types[float])})[ - i - ], + getattr( + bras_raw[f"r{n}"], "a" + spin, {i: np.zeros(shape, dtype=types[float])} + )[i], ) setattr( amp_b, spin, - getattr(bras_raw[m], "b" + spin, {i: np.zeros(shape, dtype=types[float])})[ - i - ], + getattr( + bras_raw[f"r{n}"], "b" + spin, {i: np.zeros(shape, dtype=types[float])} + )[i], ) - amps_a.append(amp_a) - amps_b.append(amp_b) - m += 1 + amps_a[f"r{n}"] = amp_a + amps_b[f"r{n}"] = amp_b for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -114,8 +114,8 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - bras_tmp.a.append(self.amplitudes_to_vector(*amps_a)) - bras_tmp.b.append(self.amplitudes_to_vector(*amps_b)) + bras_tmp.a.append(self.amplitudes_to_vector(amps_a)) + bras_tmp.b.append(self.amplitudes_to_vector(amps_b)) bras: Namespace[NDArray[float]] = util.Namespace( a=np.array(bras_tmp.a), b=np.array(bras_tmp.b) @@ -132,15 +132,16 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Ket vectors. """ - kets_raw = list(self.ebcc.make_ip_mom_kets(eris=eris)) + kets_raw = util.Namespace( + **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} + ) kets_tmp: Namespace[list[NDArray[float]]] = util.Namespace(a=[], b=[]) for i in range(self.nmo): j = (Ellipsis, i) - amps_a: list[SpinArrayType] = [] - amps_b: list[SpinArrayType] = [] + amps_a: Namespace[SpinArrayType] = util.Namespace() + amps_b: Namespace[SpinArrayType] = util.Namespace() - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): amp_a: SpinArrayType = util.Namespace() amp_b: SpinArrayType = util.Namespace() @@ -151,20 +152,19 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: setattr( amp_a, spin, - getattr(kets_raw[m], spin + "a", {j: np.zeros(shape, dtype=types[float])})[ - j - ], + getattr( + kets_raw[f"r{n}"], spin + "a", {j: np.zeros(shape, dtype=types[float])} + )[j], ) setattr( amp_b, spin, - getattr(kets_raw[m], spin + "b", {j: np.zeros(shape, dtype=types[float])})[ - j - ], + getattr( + kets_raw[f"r{n}"], spin + "b", {j: np.zeros(shape, dtype=types[float])} + )[j], ) - amps_a.append(amp_a) - amps_b.append(amp_b) - m += 1 + amps_a[f"r{n}"] = amp_a + amps_b[f"r{n}"] = amp_b for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -172,8 +172,8 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - kets_tmp.a.append(self.amplitudes_to_vector(*amps_a)) - kets_tmp.b.append(self.amplitudes_to_vector(*amps_b)) + kets_tmp.a.append(self.amplitudes_to_vector(amps_a)) + kets_tmp.b.append(self.amplitudes_to_vector(amps_b)) kets: Namespace[NDArray[float]] = util.Namespace( a=np.array(kets_tmp.a), b=np.array(kets_tmp.b) @@ -235,7 +235,7 @@ class EA_UEOM(UEOM, BaseEA_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(np.abs(diag[: r1.a.size + r1.b.size])) else: arg = np.argsort(np.abs(diag)) @@ -255,19 +255,19 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = util.Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): key = key[n:] + key[: n - 1] spin_part: SpinArrayType = util.Namespace() for comb in util.generate_spin_combinations(n, excited=True): spin_part[comb] = -self.ebcc.energy_sum(key, comb) - parts.append(spin_part) + parts[f"r{n}"] = spin_part for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. @@ -278,14 +278,15 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Bra vectors. """ - bras_raw = list(self.ebcc.make_ea_mom_bras(eris=eris)) + bras_raw = util.Namespace( + **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} + ) bras_tmp: Namespace[list[NDArray[float]]] = util.Namespace(a=[], b=[]) for i in range(self.nmo): - amps_a: list[SpinArrayType] = [] - amps_b: list[SpinArrayType] = [] + amps_a: Namespace[SpinArrayType] = util.Namespace() + amps_b: Namespace[SpinArrayType] = util.Namespace() - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): amp_a: SpinArrayType = util.Namespace() amp_b: SpinArrayType = util.Namespace() @@ -296,20 +297,19 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: setattr( amp_a, spin, - getattr(bras_raw[m], "a" + spin, {i: np.zeros(shape, dtype=types[float])})[ - i - ], + getattr( + bras_raw[f"r{n}"], "a" + spin, {i: np.zeros(shape, dtype=types[float])} + )[i], ) setattr( amp_b, spin, - getattr(bras_raw[m], "b" + spin, {i: np.zeros(shape, dtype=types[float])})[ - i - ], + getattr( + bras_raw[f"r{n}"], "b" + spin, {i: np.zeros(shape, dtype=types[float])} + )[i], ) - amps_a.append(amp_a) - amps_b.append(amp_b) - m += 1 + amps_a[f"r{n}"] = amp_a + amps_b[f"r{n}"] = amp_b for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -317,8 +317,8 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - bras_tmp.a.append(self.amplitudes_to_vector(*amps_a)) - bras_tmp.b.append(self.amplitudes_to_vector(*amps_b)) + bras_tmp.a.append(self.amplitudes_to_vector(amps_a)) + bras_tmp.b.append(self.amplitudes_to_vector(amps_b)) bras: Namespace[NDArray[float]] = util.Namespace( a=np.array(bras_tmp.a), b=np.array(bras_tmp.b) @@ -335,15 +335,16 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Returns: Ket vectors. """ - kets_raw = list(self.ebcc.make_ea_mom_kets(eris=eris)) + kets_raw = util.Namespace( + **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} + ) kets_tmp: Namespace[list[NDArray[float]]] = util.Namespace(a=[], b=[]) for i in range(self.nmo): j = (Ellipsis, i) - amps_a: list[SpinArrayType] = [] - amps_b: list[SpinArrayType] = [] + amps_a: Namespace[SpinArrayType] = util.Namespace() + amps_b: Namespace[SpinArrayType] = util.Namespace() - m = 0 for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): amp_a: SpinArrayType = util.Namespace() amp_b: SpinArrayType = util.Namespace() @@ -354,20 +355,19 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: setattr( amp_a, spin, - getattr(kets_raw[m], spin + "a", {j: np.zeros(shape, dtype=types[float])})[ - j - ], + getattr( + kets_raw[f"r{n}"], spin + "a", {j: np.zeros(shape, dtype=types[float])} + )[j], ) setattr( amp_b, spin, - getattr(kets_raw[m], spin + "b", {j: np.zeros(shape, dtype=types[float])})[ - j - ], + getattr( + kets_raw[f"r{n}"], spin + "b", {j: np.zeros(shape, dtype=types[float])} + )[j], ) - amps_a.append(amp_a) - amps_b.append(amp_b) - m += 1 + amps_a[f"r{n}"] = amp_a + amps_b[f"r{n}"] = amp_b for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented @@ -375,8 +375,8 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - kets_tmp.a.append(self.amplitudes_to_vector(*amps_a)) - kets_tmp.b.append(self.amplitudes_to_vector(*amps_b)) + kets_tmp.a.append(self.amplitudes_to_vector(amps_a)) + kets_tmp.b.append(self.amplitudes_to_vector(amps_b)) kets: Namespace[NDArray[float]] = util.Namespace( a=np.array(kets_tmp.a), b=np.array(kets_tmp.b) @@ -438,7 +438,7 @@ class EE_UEOM(UEOM, BaseEE_EOM): def _argsort_guesses(self, diag: NDArray[float]) -> NDArray[int]: """Sort the diagonal to inform the initial guesses.""" if self.options.koopmans: - r1 = self.vector_to_amplitudes(diag)[0] + r1 = self.vector_to_amplitudes(diag)["r1"] arg = np.argsort(diag[: r1.aa.size + r1.bb.size]) else: arg = np.argsort(diag) @@ -458,18 +458,18 @@ def diag(self, eris: Optional[ERIsInputType] = None) -> NDArray[float]: Returns: Diagonal of the Hamiltonian. """ - parts = [] + parts: Namespace[SpinArrayType] = util.Namespace() for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type): spin_part: SpinArrayType = util.Namespace() for comb in util.generate_spin_combinations(n): spin_part[comb] = self.ebcc.energy_sum(key, comb) - parts.append(spin_part) + parts[f"r{n}"] = spin_part for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type): raise util.ModelNotImplemented - return self.amplitudes_to_vector(*parts) + return self.amplitudes_to_vector(parts) def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: """Get the bra vectors. From 02ce9872bfd71052ef7cb54a06ff29dc33016108 Mon Sep 17 00:00:00 2001 From: Oliver Backhouse Date: Tue, 6 Aug 2024 23:13:11 +0100 Subject: [PATCH 2/2] flake8 --- ebcc/eom/geom.py | 12 ++++++------ ebcc/eom/reom.py | 12 ++++++------ ebcc/eom/ueom.py | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ebcc/eom/geom.py b/ebcc/eom/geom.py index 9c69c551..ae5266fe 100644 --- a/ebcc/eom/geom.py +++ b/ebcc/eom/geom.py @@ -74,7 +74,7 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Bra vectors. """ bras_raw = util.Namespace( - **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} + **{f"r{n + 1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} ) bras = np.array( [ @@ -96,7 +96,7 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Ket vectors. """ kets_raw = util.Namespace( - **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} + **{f"r{n + 1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} ) kets = np.array( [ @@ -199,7 +199,7 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Bra vectors. """ bras_raw = util.Namespace( - **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} + **{f"r{n + 1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} ) bras = np.array( [ @@ -221,7 +221,7 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Ket vectors. """ kets_raw = util.Namespace( - **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} + **{f"r{n + 1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} ) kets = np.array( [ @@ -323,7 +323,7 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Bra vectors. """ bras_raw = util.Namespace( - **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ee_mom_bras(eris=eris))} + **{f"r{n + 1}": b for n, b in enumerate(self.ebcc.make_ee_mom_bras(eris=eris))} ) bras = np.array( [ @@ -348,7 +348,7 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Ket vectors. """ kets_raw = util.Namespace( - **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ee_mom_kets(eris=eris))} + **{f"r{n + 1}": k for n, k in enumerate(self.ebcc.make_ee_mom_kets(eris=eris))} ) kets = np.array( [ diff --git a/ebcc/eom/reom.py b/ebcc/eom/reom.py index 54c0447d..4e893f88 100644 --- a/ebcc/eom/reom.py +++ b/ebcc/eom/reom.py @@ -74,7 +74,7 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Bra vectors. """ bras_raw = util.Namespace( - **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} + **{f"r{n + 1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} ) bras = np.array( [ @@ -96,7 +96,7 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Ket vectors. """ kets_raw = util.Namespace( - **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} + **{f"r{n + 1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} ) kets = np.array( [ @@ -199,7 +199,7 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Bra vectors. """ bras_raw = util.Namespace( - **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} + **{f"r{n + 1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} ) bras = np.array( [ @@ -221,7 +221,7 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Ket vectors. """ kets_raw = util.Namespace( - **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} + **{f"r{n + 1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} ) kets = np.array( [ @@ -323,7 +323,7 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Bra vectors. """ bras_raw = util.Namespace( - **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ee_mom_bras(eris=eris))} + **{f"r{n + 1}": b for n, b in enumerate(self.ebcc.make_ee_mom_bras(eris=eris))} ) bras = np.array( [ @@ -348,7 +348,7 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Ket vectors. """ kets_raw = util.Namespace( - **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ee_mom_kets(eris=eris))} + **{f"r{n + 1}": k for n, k in enumerate(self.ebcc.make_ee_mom_kets(eris=eris))} ) kets = np.array( [ diff --git a/ebcc/eom/ueom.py b/ebcc/eom/ueom.py index ff9dd076..814f504f 100644 --- a/ebcc/eom/ueom.py +++ b/ebcc/eom/ueom.py @@ -76,7 +76,7 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Bra vectors. """ bras_raw = util.Namespace( - **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} + **{f"r{n + 1}": b for n, b in enumerate(self.ebcc.make_ip_mom_bras(eris=eris))} ) bras_tmp: Namespace[list[NDArray[float]]] = util.Namespace(a=[], b=[]) @@ -133,7 +133,7 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Ket vectors. """ kets_raw = util.Namespace( - **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} + **{f"r{n + 1}": k for n, k in enumerate(self.ebcc.make_ip_mom_kets(eris=eris))} ) kets_tmp: Namespace[list[NDArray[float]]] = util.Namespace(a=[], b=[]) @@ -279,7 +279,7 @@ def bras(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Bra vectors. """ bras_raw = util.Namespace( - **{f"r{n+1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} + **{f"r{n + 1}": b for n, b in enumerate(self.ebcc.make_ea_mom_bras(eris=eris))} ) bras_tmp: Namespace[list[NDArray[float]]] = util.Namespace(a=[], b=[]) @@ -336,7 +336,7 @@ def kets(self, eris: Optional[ERIsInputType] = None) -> SpinArrayType: Ket vectors. """ kets_raw = util.Namespace( - **{f"r{n+1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} + **{f"r{n + 1}": k for n, k in enumerate(self.ebcc.make_ea_mom_kets(eris=eris))} ) kets_tmp: Namespace[list[NDArray[float]]] = util.Namespace(a=[], b=[])