Skip to content

Commit

Permalink
Merge changes from branch master
Browse files Browse the repository at this point in the history
  • Loading branch information
obackhouse committed Aug 13, 2024
2 parents a70fad5 + 68edb21 commit 44d45f3
Show file tree
Hide file tree
Showing 12 changed files with 649 additions and 2,354 deletions.
234 changes: 0 additions & 234 deletions ebcc/cc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,168 +782,6 @@ def make_eb_coup_rdm(
"""
pass

def hbar_matvec_ip_intermediates(
self,
eris: Optional[ERIsInputType] = None,
amplitudes: Optional[Namespace[SpinArrayType]] = None,
) -> Namespace[NDArray[float]]:
"""Compute intermediates for the IP-EOM Hamiltonian.
Args:
eris: Electron repulsion integrals.
amplitudes: Cluster amplitudes.
Returns:
Intermediate products for the IP-EOM Hamiltonian.
"""
func, kwargs = self._load_function(
"hbar_matvec_ip_intermediates",
eris=eris,
amplitudes=amplitudes,
)
res: Namespace[NDArray[float]] = util.Namespace(**func(**kwargs))
return res

def hbar_matvec_ip(
self,
excitations: Namespace[SpinArrayType],
eris: Optional[ERIsInputType] = None,
amplitudes: Optional[Namespace[SpinArrayType]] = None,
ints: Optional[Namespace[NDArray[float]]] = None,
) -> Namespace[SpinArrayType]:
"""Compute the product between a state vector and the IP-EOM Hamiltonian.
Args:
excitations: State vector as a set of excitation amplitudes.
eris: Electron repulsion integrals.
amplitudes: Cluster amplitudes.
ints: Intermediate products.
Returns:
Products between the state vectors and the IP-EOM Hamiltonian for the singles and
doubles.
"""
if not ints:
ints = self.hbar_matvec_ip_intermediates(eris=eris, amplitudes=amplitudes)
func, kwargs = self._load_function(
"hbar_matvec_ip",
eris=eris,
amplitudes=amplitudes,
excitations=excitations,
ints=ints,
)
res: Namespace[SpinArrayType] = func(**kwargs)
res = util.Namespace(**{key.rstrip("new"): val for key, val in res.items()})
return res

def hbar_matvec_ea_intermediates(
self,
eris: Optional[ERIsInputType] = None,
amplitudes: Optional[Namespace[SpinArrayType]] = None,
) -> Namespace[NDArray[float]]:
"""Compute intermediates for the EA-EOM Hamiltonian.
Args:
eris: Electron repulsion integrals.
amplitudes: Cluster amplitudes.
Returns:
Intermediate products for the EA-EOM Hamiltonian.
"""
func, kwargs = self._load_function(
"hbar_matvec_ea_intermediates",
eris=eris,
amplitudes=amplitudes,
)
res: Namespace[NDArray[float]] = util.Namespace(**func(**kwargs))
return res

def hbar_matvec_ea(
self,
excitations: Namespace[SpinArrayType],
eris: Optional[ERIsInputType] = None,
amplitudes: Optional[Namespace[SpinArrayType]] = None,
ints: Optional[Namespace[NDArray[float]]] = None,
) -> Namespace[SpinArrayType]:
"""Compute the product between a state vector and the EA-EOM Hamiltonian.
Args:
excitations: State vector as a set of excitation amplitudes.
eris: Electron repulsion integrals.
amplitudes: Cluster amplitudes.
ints: Intermediate products.
Returns:
Products between the state vectors and the EA-EOM Hamiltonian for the singles and
doubles.
"""
if not ints:
ints = self.hbar_matvec_ea_intermediates(eris=eris, amplitudes=amplitudes)
func, kwargs = self._load_function(
"hbar_matvec_ea",
eris=eris,
amplitudes=amplitudes,
excitations=excitations,
ints=ints,
)
res: Namespace[SpinArrayType] = func(**kwargs)
res = util.Namespace(**{key.rstrip("new"): val for key, val in res.items()})
return res

def hbar_matvec_ee_intermediates(
self,
eris: Optional[ERIsInputType] = None,
amplitudes: Optional[Namespace[SpinArrayType]] = None,
) -> Namespace[NDArray[float]]:
"""Compute intermediates for the EE-EOM Hamiltonian.
Args:
eris: Electron repulsion integrals.
amplitudes: Cluster amplitudes.
Returns:
Intermediate products for the EE-EOM Hamiltonian.
"""
func, kwargs = self._load_function(
"hbar_matvec_ee_intermediates",
eris=eris,
amplitudes=amplitudes,
)
res: Namespace[NDArray[float]] = util.Namespace(**func(**kwargs))
return res

def hbar_matvec_ee(
self,
excitations: Namespace[SpinArrayType],
eris: Optional[ERIsInputType] = None,
amplitudes: Optional[Namespace[SpinArrayType]] = None,
ints: Optional[Namespace[NDArray[float]]] = None,
) -> Namespace[SpinArrayType]:
"""Compute the product between a state vector and the EE-EOM Hamiltonian.
Args:
excitations: State vector as a set of excitation amplitudes.
eris: Electron repulsion integrals.
amplitudes: Cluster amplitudes.
ints: Intermediate products.
Returns:
Products between the state vectors and the EE-EOM Hamiltonian for the singles and
doubles.
"""
if not ints:
ints = self.hbar_matvec_ee_intermediates(eris=eris, amplitudes=amplitudes)
func, kwargs = self._load_function(
"hbar_matvec_ee",
eris=eris,
amplitudes=amplitudes,
excitations=excitations,
ints=ints,
)
res: Namespace[SpinArrayType] = func(**kwargs)
res = util.Namespace(**{key.rstrip("new"): val for key, val in res.items()})
return res

@abstractmethod
def energy_sum(self, *args: str, signs_dict: Optional[dict[str, str]] = None) -> NDArray[float]:
"""Get a direct sum of energies.
Expand Down Expand Up @@ -1006,78 +844,6 @@ def vector_to_lambdas(self, vector: NDArray[float]) -> Namespace[SpinArrayType]:
"""
pass

@abstractmethod
def excitations_to_vector_ip(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]:
"""Construct a vector containing all of the IP-EOM excitations.
Args:
excitations: IP-EOM excitations.
Returns:
IP-EOM excitations as a vector.
"""
pass

@abstractmethod
def excitations_to_vector_ea(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]:
"""Construct a vector containing all of the EA-EOM excitations.
Args:
excitations: EA-EOM excitations.
Returns:
EA-EOM excitations as a vector.
"""
pass

@abstractmethod
def excitations_to_vector_ee(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]:
"""Construct a vector containing all of the EE-EOM excitations.
Args:
excitations: EE-EOM excitations.
Returns:
EE-EOM excitations as a vector.
"""
pass

@abstractmethod
def vector_to_excitations_ip(self, vector: NDArray[float]) -> Namespace[SpinArrayType]:
"""Construct a namespace of IP-EOM excitations from a vector.
Args:
vector: IP-EOM excitations as a vector.
Returns:
IP-EOM excitations.
"""
pass

@abstractmethod
def vector_to_excitations_ea(self, vector: NDArray[float]) -> Namespace[SpinArrayType]:
"""Construct a namespace of EA-EOM excitations from a vector.
Args:
vector: EA-EOM excitations as a vector.
Returns:
EA-EOM excitations.
"""
pass

@abstractmethod
def vector_to_excitations_ee(self, vector: NDArray[float]) -> Namespace[SpinArrayType]:
"""Construct a namespace of EE-EOM excitations from a vector.
Args:
vector: EE-EOM excitations as a vector.
Returns:
EE-EOM excitations.
"""
pass

@property
def fermion_ansatz(self) -> str:
"""Get a string representation of the fermion ansatz."""
Expand Down
142 changes: 0 additions & 142 deletions ebcc/cc/gebcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,148 +803,6 @@ def vector_to_lambdas(self, vector: NDArray[float]) -> Namespace[SpinArrayType]:

return lambdas

def excitations_to_vector_ip(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]:
"""Construct a vector containing all of the IP-EOM excitations.
Args:
excitations: IP-EOM excitations.
Returns:
IP-EOM excitations as a vector.
"""
vectors = []

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[f"r{n}"]).ravel())

for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

return np.concatenate(vectors)

def excitations_to_vector_ea(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]:
"""Construct a vector containing all of the EA-EOM excitations.
Args:
excitations: EA-EOM excitations.
Returns:
EA-EOM excitations as a vector.
"""
return self.excitations_to_vector_ip(excitations)

def excitations_to_vector_ee(self, excitations: Namespace[SpinArrayType]) -> NDArray[float]:
"""Construct a vector containing all of the EE-EOM excitations.
Args:
excitations: EE-EOM excitations.
Returns:
EE-EOM excitations as a vector.
"""
vectors = []

for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type):
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

for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

return np.concatenate(vectors)

def vector_to_excitations_ip(self, vector: NDArray[float]) -> Namespace[SpinArrayType]:
"""Construct a namespace of IP-EOM excitations from a vector.
Args:
vector: IP-EOM excitations as a vector.
Returns:
IP-EOM 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]
size = util.get_compressed_size(key, **{k: self.space.size(k) for k in set(key)})
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[f"r{n}"] = vn
i0 += size

for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

return excitations

def vector_to_excitations_ea(self, vector: NDArray[float]) -> Namespace[SpinArrayType]:
"""Construct a namespace of EA-EOM excitations from a vector.
Args:
vector: EA-EOM excitations as a vector.
Returns:
EA-EOM 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]
size = util.get_compressed_size(key, **{k: self.space.size(k) for k in set(key)})
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[f"r{n}"] = vn
i0 += size

for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

return excitations

def vector_to_excitations_ee(self, vector: NDArray[float]) -> Namespace[SpinArrayType]:
"""Construct a namespace of EE-EOM excitations from a vector.
Args:
vector: EE-EOM excitations as a vector.
Returns:
EE-EOM excitations.
"""
excitations: Namespace[SpinArrayType] = util.Namespace()
i0 = 0

for name, key, n in self.ansatz.fermionic_cluster_ranks(spin_type=self.spin_type):
size = util.get_compressed_size(key, **{k: self.space.size(k) for k in set(key)})
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[f"r{n}"] = vn
i0 += size

for name, key, n in self.ansatz.bosonic_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

for name, key, nf, nb in self.ansatz.coupling_cluster_ranks(spin_type=self.spin_type):
raise util.ModelNotImplemented

return excitations

def get_mean_field_G(self) -> NDArray[float]:
"""Get the mean-field boson non-conserving term.
Expand Down
Loading

0 comments on commit 44d45f3

Please sign in to comment.