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.
| ] | ||
| | 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.
kevinsung
left a comment
There was a problem hiding this comment.
Thank you! Just a few more minor changes.
c4d1e16 to
1e3131f
Compare
|
The current CI failures appear to be unrelated to this change. The failing jobs are invoking tox with environment names like env_list = For example, one failing job reports: So at least these failures are due to a workflow/tox environment naming mismatch @kevinsung |
CI was broken because of a change in tox 4.50.1. I've fixed this in #603 , please merge |
Hmmm still something wrong with tox. |
|
Just need to fix the sphinx warnings now. Unfortunately, I've never figured out a good way to debug those, besides tracking down the offending line through binary search. |
| *, | ||
| norb: int, | ||
| nocc: int, | ||
| c0_threshold: float = 1e-8, |
There was a problem hiding this comment.
| c0_threshold: float = 1e-8, | |
| c0_threshold: float = 1e-12, |
Let's make this smaller actually.
| cisd_vec: The CISD vector. This is a one-dimensional array storing the | ||
| reference coefficient :math:`c_0` in the first entry, followed by the | ||
| singles and then doubles coefficients. | ||
| norb: The number of spatial orbitals. | ||
| nocc: The number of occupied orbitals. | ||
| c0_threshold: Absolute value threshold for the reference coefficient. | ||
| An error is raised if the absolute value of the reference coefficient is | ||
| smaller than this threshold. | ||
| n_reps: The number of ansatz repetitions. |
There was a problem hiding this comment.
The indentation here doesn't match the other arguments, where lines after the first one are indented. Is this related to the Sphinx issues you were having?
|
Hmm the CI failure seems unrelated, I will look into it... |
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.