Initialize UCJ from CISD#595
Conversation
| def from_cisd( | ||
| cisd, | ||
| *, | ||
| civec: np.ndarray | None = None, |
There was a problem hiding this comment.
Instead of accepting cisd, only accept civec, and rename it to cisd_vec. Also, rename the method to from_cisd_vec.
| "or use a converged PySCF CISD object with a `ci` attribute." | ||
| ) | ||
|
|
||
| c0, c1, c2 = cisd.cisdvec_to_amplitudes(civec, copy=False) |
There was a problem hiding this comment.
Use pyscf.ci.cisd.cisdvec_to_amplitudes instead, since you won't have the cisd object anymore.
| "UCJOpSpinBalanced.from_cisd requires amplitudes from a restricted " | ||
| "closed-shell CISD calculation." | ||
| ) | ||
| if np.isclose(c0, 0.0): |
There was a problem hiding this comment.
Add a keyword-only argument c0_tol: float = 1e-8 to use for the absolute tolerance here. Also, this is a nit but prefer math.isclose to np.isclose when comparing numbers because it avoids numpy function dispatch overhead.
|
|
||
| @staticmethod | ||
| def from_cisd_vec( | ||
| cisd_vec, |
| def from_cisd_vec( | ||
| cisd_vec, | ||
| *, | ||
| nmo: int, |
There was a problem hiding this comment.
Rename this to norb to match with the rest of ffsim.
| ] | ||
| | None = None, | ||
| tol: float = 1e-8, | ||
| c0_tol: float = 1e-8, |
There was a problem hiding this comment.
Let's put c0_tol after nocc and before n_reps.
| :meth:`from_t_amplitudes`. | ||
|
|
||
| Args: | ||
| civec: CISD coefficient vector. |
There was a problem hiding this comment.
Need to update this to cisd_vec and also add document norb, nocc, and c0_tol.
| if cisd_vec is None: | ||
| raise ValueError("CISD coefficient vector `cisd_vec` cannot be None.") | ||
|
|
There was a problem hiding this comment.
This check is unnecessary.
| cisd_vec, nmo, nocc, copy=False | ||
| ) | ||
|
|
||
| if math.isclose(c0, 0.0, rel_tol=0.0, abs_tol=c0_tol): |
There was a problem hiding this comment.
Since we're comparing to zero, it's actually unnecessary to specify rel_tol.
| f"CISD reference coefficient c0={c0} is too close to zero " | ||
| f"(abs_tol={c0_tol})." |
There was a problem hiding this comment.
| f"CISD reference coefficient c0={c0} is too close to zero " | |
| f"(abs_tol={c0_tol})." | |
| f"CISD reference coefficient c0={c0} is smaller than the specified threshold, c0_tol={c0_tol}." |
| t2 = c2 / c0 - 0.5 * np.einsum("ia,jb->ijab", t1, t1) | ||
|
|
||
| operator = ffsim.UCJOpSpinBalanced.from_cisd_vec( | ||
| cisd.ci, nmo=cisd.nmo, nocc=cisd.nocc |
There was a problem hiding this comment.
You should also test that cisd.ci was not modified, since you chose to pass copy=False in cisdvec_to_amplitudes.
Initialization of UCJ from CISD as described in https://arxiv.org/pdf/2511.22476
Added as a method
from.cisd()in UCJOpSpinBalanced, and any necessary tests. Closes issue #592.