Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
30d195b
Add placeholder FanCI Wfn (squash this commit)
msricher Aug 22, 2024
73ec79c
updated for AP1roGSDGeneralized_sen-o wavefunction
q-pratz-chem Nov 11, 2024
0bd7f86
renamed file for AP1roGSDGeneralized_sen-o
q-pratz-chem Nov 11, 2024
54c7e43
Add AP1roGeneralizedSenoObjective to pyci.h
q-pratz-chem Nov 11, 2024
78bb5e2
Declare & define Python class based on the AP1roGeneralizedSenoObject…
q-pratz-chem Nov 11, 2024
0a54be7
Generate GenCIwfn using FullCIwfn
q-pratz-chem Nov 12, 2024
b7400c6
Add Generalized_sen-o Singles to GenCI wfn
q-pratz-chem Nov 12, 2024
c69462d
Fix indexing error; update k increment from nword2 to nword
q-pratz-chem Nov 12, 2024
aa9a922
Add NonSingletCI class derived from GenCIWfn class
q-pratz-chem Nov 14, 2024
4137d19
Add NonSingletCI class derived from GenCIWfn class
q-pratz-chem Nov 14, 2024
42e7b9e
Add NonSingletCI class derived from GenCIWfn class
q-pratz-chem Nov 14, 2024
809a510
Add NonSingletCI class derived from GenCIWfn class
q-pratz-chem Nov 14, 2024
90c04a2
Add NonSingletCI class derived from GenCIWfn class
q-pratz-chem Nov 14, 2024
33582b0
Remove final keyword from GenCIWfn to allow inheritance for NonSingletCI
q-pratz-chem Nov 14, 2024
cd16c02
Add NonSingletCI class derived from GenCIWfn class
q-pratz-chem Nov 14, 2024
9a2e708
Add fill_hartreefock_det
q-pratz-chem Nov 15, 2024
519b071
Add function to excited dets
q-pratz-chem Nov 18, 2024
720337f
Include fill hartreefock det function
q-pratz-chem Nov 18, 2024
3624eb6
Add print statements for debug
q-pratz-chem Nov 19, 2024
cc7efdd
Remove unnecessary function forming orb pairs
q-pratz-chem Nov 20, 2024
211d945
Add function add_excited_dets & its Py binding
q-pratz-chem Nov 20, 2024
50e78d0
Add py_add_excited_dets
q-pratz-chem Nov 20, 2024
4f89318
Remove unnecessary file
q-pratz-chem Nov 21, 2024
15221d9
Add print statements in ap1rog.cpp 'init_overlap' & 'overlap' function
q-pratz-chem Nov 21, 2024
7bbc507
Fix typos
q-pratz-chem Nov 21, 2024
4165d9f
Correc the base class mention for AP1roGeneralizedSeno Objective
q-pratz-chem Nov 21, 2024
7550c22
Update the fill_hartreefock_det function
q-pratz-chem Nov 27, 2024
22b44ca
Update add_excited_dets for exc order >=2
q-pratz-chem Nov 27, 2024
5b56062
Update add_excited_dets exc_order >=2
q-pratz-chem Nov 27, 2024
218e1e2
Add methods to NonSingletCI Python binding for fill_hartreefock_det a…
q-pratz-chem Nov 26, 2024
37d3269
Change bit_index for alpha spins in fill_hartreefock_det
q-pratz-chem Nov 27, 2024
3f9bfce
Add print statements
q-pratz-chem Nov 27, 2024
3ad8e4f
Fix typo
q-pratz-chem Nov 27, 2024
40f139c
Fix bit_index for beta in fill_hartreefock_det
q-pratz-chem Nov 27, 2024
0b39487
add correct if conditions in add_excited_dets
q-pratz-chem Nov 27, 2024
b3a0497
check number of pairs in occ_pairs in add_excited_dets
q-pratz-chem Nov 27, 2024
3416769
Add avaialble_pairs variable in add_excited_dets exc>=2
q-pratz-chem Nov 27, 2024
3e06634
Print to check the if condition for s in add_excited_dets order >=2
q-pratz-chem Nov 27, 2024
6b03678
Updated a new algorithm for exc>=2 in add_excited_dets
q-pratz-chem Nov 27, 2024
28270dd
Fix typos
q-pratz-chem Nov 27, 2024
4bf0287
Add entry for generate_combinations function for NonSingletCI
q-pratz-chem Nov 27, 2024
34d1d46
fix typos { }
q-pratz-chem Nov 27, 2024
69d4457
Change type of pair_combinations in add_excited_dets
q-pratz-chem Nov 27, 2024
548602a
Fix det input in num_singles>0 case in add_excited_dets
q-pratz-chem Nov 27, 2024
dabfb0b
Fix the generate_combinations definition
q-pratz-chem Nov 27, 2024
74ba20b
Add Print statements
q-pratz-chem Nov 27, 2024
d3d187d
Add print statements
q-pratz-chem Nov 28, 2024
a43c8b1
Corrected the input det for add_det for S>0 case in add_excited_dets
q-pratz-chem Nov 28, 2024
5b343ab
Update S>0 case in add_excited_dets
q-pratz-chem Nov 28, 2024
89fc9b8
Update S>0 case in add_excited_dets
q-pratz-chem Nov 28, 2024
d838fe4
Update S>0 case in add_excited_dets
q-pratz-chem Nov 28, 2024
f25db31
Change base class from GenCIWfn to NonSingletCI
q-pratz-chem Nov 14, 2024
4bb2bf2
Change base class from GenCIWfn to NonSingletCI
q-pratz-chem Nov 14, 2024
04abc32
Change base class from GenCIWfn to NonSingletCI
q-pratz-chem Nov 14, 2024
a5df30c
update nparam value
q-pratz-chem Nov 21, 2024
f7f6922
Add explicit instantiation for Objective<NonSingletCI> template
q-pratz-chem Nov 21, 2024
edd8ff8
Add import nonsingletci_wfn
q-pratz-chem Nov 21, 2024
fcaa583
add print statement
q-pratz-chem Nov 21, 2024
fba094e
Add print statements
q-pratz-chem Nov 25, 2024
2fd9a1a
Add print statements
q-pratz-chem Nov 25, 2024
4b2f55e
Add function call for nonsingletci.add_excited_dets
q-pratz-chem Nov 25, 2024
aacd142
Add print statements
q-pratz-chem Nov 25, 2024
60b7d22
Revert "Add function call for nonsingletci.add_excited_dets"
q-pratz-chem Nov 26, 2024
c068a18
Revert "Revert "Add function call for nonsingletci.add_excited_dets""
q-pratz-chem Nov 28, 2024
bd4fe45
update the logic for s>0 in add_excited_dets
q-pratz-chem Nov 28, 2024
60ca2ad
fix typos
q-pratz-chem Nov 28, 2024
1888658
Revert to the orignial add_excitation calls in fill_wavefunction func…
q-pratz-chem Nov 28, 2024
16edbbd
Add print statements
q-pratz-chem Nov 28, 2024
79ec98c
Add print statements
q-pratz-chem Nov 28, 2024
778b25b
Try an input with *2 in occ_combinations for singles in add_excited_dets
q-pratz-chem Nov 28, 2024
86828d9
Add generate_cartesian_product function to form occ_pairs for sen-o s…
q-pratz-chem Nov 28, 2024
12f7213
Add print statements
q-pratz-chem Nov 28, 2024
bb5f1f0
fix typos
q-pratz-chem Nov 28, 2024
1abce91
Fix double excitation to consider all possible occ_pair to vir_pair c…
q-pratz-chem Nov 30, 2024
e0f1887
Cleanup the occs_up, _dn, virs_up, _dn vector code
q-pratz-chem Dec 2, 2024
78a01b7
Add is_hf_det bool flag, define and declare structure in pyci.h to st…
q-pratz-chem Dec 2, 2024
52b255e
Add print functions to avoid lengthy repetative lines
q-pratz-chem Dec 2, 2024
0917ac7
Change vector type to AlignedVector for remaining_occ_pairs , remaini…
q-pratz-chem Dec 2, 2024
d3444c5
Change vector type to AlignedVector for generate_cartesian_product
q-pratz-chem Dec 2, 2024
6b8301f
Store dets & indices for params corresponding to excitations in case …
q-pratz-chem Dec 2, 2024
6e0fa61
Add excitation details to the det_exc_param_indx vector
q-pratz-chem Dec 2, 2024
3c3a420
Correct variable type to size_t for variables with vector.size()
q-pratz-chem Dec 2, 2024
101d37c
Correction: excite singles from only doubly-occupied-orbital-pairs
q-pratz-chem Dec 3, 2024
952e5ce
Add check on combinations of occ and vir pairs
q-pratz-chem Dec 3, 2024
0aa9b17
Add det exc details entry at indx ndet everytime a new det is added i…
q-pratz-chem Dec 4, 2024
dd9e9b1
add nonsingletci entry in sparseop
q-pratz-chem Dec 4, 2024
a740485
comment line for pair inds in is_hf_block for e ==1 in add_excited_dets
q-pratz-chem Dec 4, 2024
d9fd120
Commenting det_exc_param_indx line in e==1_
q-pratz-chem Dec 4, 2024
9866706
Mark fill_hartreefock_det function as constant
q-pratz-chem Dec 4, 2024
a6b4f4b
Update the det_exc_param_indx size verification and fix indices for n…
q-pratz-chem Dec 4, 2024
e29f136
Ensure the container det size for every entry of the det_exc_param_indx
q-pratz-chem Dec 4, 2024
cb0d2bd
Add inline function to insure the struct size
q-pratz-chem Dec 4, 2024
d20e695
Update add_row function for NonSingletCI
q-pratz-chem Dec 6, 2024
3e7f0b3
Add entries for SparseOP NonSingletCI spefic functions
q-pratz-chem Dec 6, 2024
91652b5
Add update function in sparseop.cpp exclusively for NonSingletCI and …
q-pratz-chem Dec 7, 2024
c107970
Update definition and declaration for py_update function
q-pratz-chem Dec 8, 2024
2259d32
Add function to calculate indices of params corresponding to the exci…
q-pratz-chem Dec 8, 2024
5eb4a02
Update NonSingletCI declarations as per branch of ap1rogen
q-pratz-chem Dec 9, 2024
a149e0e
Mark calc_sindex and calc_pindex as const functions to suit it to ini…
q-pratz-chem Dec 9, 2024
f3066a2
Correct the sindex calculations
q-pratz-chem Dec 9, 2024
1b9b29c
Remove the det_exc_param_indx structure as a nonsingletci member
q-pratz-chem Dec 10, 2024
2e022cc
Add print statments
q-pratz-chem Dec 11, 2024
2043f73
change wfn.nvir to nvir in add_row
q-pratz-chem Dec 11, 2024
ecaf919
Modify init_overlap
q-pratz-chem Dec 3, 2024
60fb83d
Form pairs of occ and virs to get param indices for dets not stored i…
q-pratz-chem Dec 3, 2024
6871353
Add function to generate combintaitons of holes and particles
q-pratz-chem Dec 3, 2024
527ee37
Add function to generate partition of number of pairs and number of s…
q-pratz-chem Dec 3, 2024
79aaf20
Add generate excitations function for generate list of holes and part…
q-pratz-chem Dec 3, 2024
aa484ab
Add function to calculate permanet using Rysers algorithm given param…
q-pratz-chem Dec 3, 2024
5d9bc67
Update the overalp function
q-pratz-chem Dec 3, 2024
c39d15c
Add helper function compute_derivative
q-pratz-chem Dec 3, 2024
3409e74
Fix template definition for generation combinations function
q-pratz-chem Dec 3, 2024
f79eeb2
Fix typo
q-pratz-chem Dec 3, 2024
4d4a828
Add d_overlap function
q-pratz-chem Dec 3, 2024
5ab9833
Fix typos
q-pratz-chem Dec 3, 2024
91a35b1
Fix typos
q-pratz-chem Dec 3, 2024
984726d
Add det exc details entry at indx ndet everytime a new det is added i…
q-pratz-chem Dec 4, 2024
2d9997f
Recover the original definition of overlap and d_overlap function, d…
q-pratz-chem Dec 4, 2024
8e09435
Correct declaration of det_param_indx and init_overlap function for A…
q-pratz-chem Dec 4, 2024
794284d
Correct access to the det_exc_param_indx
q-pratz-chem Dec 4, 2024
0ea2f44
Add print statement
q-pratz-chem Dec 4, 2024
727057a
Add extra keyword wfntype for pyci.sparse_op call for nonsingletci ty…
q-pratz-chem Dec 8, 2024
d6ededc
Add condition for num_singles in generate partitions; restore det_exc…
q-pratz-chem Dec 8, 2024
8b5a870
Add input nbasis to generate combinations, add pairing condition in g…
q-pratz-chem Dec 9, 2024
ba37de2
Modify the generate_excitations function to accommodate unique combin…
q-pratz-chem Dec 9, 2024
ca32c14
fix function declarations
q-pratz-chem Dec 9, 2024
ef0e7a2
Update the generate combinations
q-pratz-chem Dec 9, 2024
3173a7d
add bool for vir_pairs in generate_partitions
q-pratz-chem Dec 9, 2024
42458d5
Update generate_exciations to consider appropriate pairs and singles
q-pratz-chem Dec 9, 2024
3b66550
Update sparse_op call for ci_op considering extra keyword for nonsing…
q-pratz-chem Dec 9, 2024
5fadc97
Add print statments in overlap
q-pratz-chem Dec 9, 2024
3030bde
Sort final indices of params before storing the data
q-pratz-chem Dec 10, 2024
6bd9501
Correct the pindex
q-pratz-chem Dec 10, 2024
a6f627a
Correct the overlap function and declare two vectors to store the per…
q-pratz-chem Dec 10, 2024
09dede2
Update checks for single_inds and pair_inds structure elements
q-pratz-chem Dec 10, 2024
fb78b62
Initialize det_exc_param_indx in init_overlap to store data for all d…
q-pratz-chem Dec 10, 2024
cc0cb8f
Add default value for stored param indices
q-pratz-chem Dec 11, 2024
6ae9477
Changing the default indices for params from default_value to -1.0
q-pratz-chem Dec 11, 2024
bef28f4
Fix input for fill_virs in add_row
q-pratz-chem Dec 11, 2024
8400b8e
Updated matrix elements terms in add_row
q-pratz-chem Dec 11, 2024
1261f7d
Update the matrix elements calculations and clean up the add_row func…
q-pratz-chem Dec 12, 2024
265dbe2
add temporary counter in the add_row function for NonSingletCI to cou…
q-pratz-chem Dec 12, 2024
2843ee8
Set default indices stored for dets to -1 long
q-pratz-chem Dec 12, 2024
f7aa442
Update permanent calculation algorithm, add extra structure Permanent…
q-pratz-chem Dec 12, 2024
e4b1514
Update the bool return for the overlap and corresponding helper funct…
q-pratz-chem Dec 12, 2024
b9fe6a9
update the varible type for max_pairs in generate_excitations
q-pratz-chem Dec 12, 2024
3dc6287
Fix the order of initialization in the constructor and declaration of…
q-pratz-chem Dec 12, 2024
5e8d9d0
fix the warning issues for the accessing the pairs
q-pratz-chem Dec 12, 2024
0534637
add temporary counter in the add_row function for NonSingletCI to cou…
q-pratz-chem Dec 12, 2024
32e72b5
Update the matrix elements calculations and clean up the add_row func…
q-pratz-chem Dec 12, 2024
c1ab6cd
Updated matrix elements terms in add_row
q-pratz-chem Dec 11, 2024
b05a6ea
Fix input for fill_virs in add_row
q-pratz-chem Dec 11, 2024
f777e4f
Correct the matrix elements for NonSingletCI in add_row: If matrix el…
q-pratz-chem Dec 12, 2024
d344701
Correct the matrix elements for NonSingletCI in add_row: If matrix el…
q-pratz-chem Dec 12, 2024
b494617
Correct the matrix elements for NonSingletCI in add_row: If matrix el…
q-pratz-chem Dec 12, 2024
a286acd
Initialize the permanent with 0.0 and ensure all inds are getting sto…
q-pratz-chem Dec 13, 2024
eb822df
Add_row function for NonSingletCI: correctly accesss the MOs, same in…
q-pratz-chem Dec 16, 2024
8b502de
Remove repeating generation of det using alpha beta --> beta alpha ex…
q-pratz-chem Dec 16, 2024
1d933cd
Fix compute_derivative to avoid invalid pointer error
q-pratz-chem Dec 17, 2024
cf04dd6
update function declarations for the compute_derivative and update th…
q-pratz-chem Dec 17, 2024
214b3ac
Restate the nparams
q-pratz-chem Dec 17, 2024
9bbb3c9
correct koffset in a loop in add_row, comment all elements =0
q-pratz-chem Dec 19, 2024
d5fa6cb
Remove matrix elements =0, remove print statements
q-pratz-chem Dec 20, 2024
6ce631e
Clean up the unnecessary code, comment print lines
q-pratz-chem Dec 20, 2024
88fb375
In compute_derivative: static cast iparam to long
q-pratz-chem Dec 20, 2024
a7c6cfa
Comment print statement
q-pratz-chem Dec 20, 2024
b17b1c6
Comment print statement
q-pratz-chem Dec 20, 2024
8ad558a
Comment print statements, remove the unnecessary is_hf_det bool block
q-pratz-chem Dec 20, 2024
0cea1ea
Remove print statements
q-pratz-chem Dec 20, 2024
e4be523
Remove print statements
q-pratz-chem Dec 20, 2024
cbbb122
Remove commit statement
q-pratz-chem Dec 20, 2024
6f21880
Remove print statement
q-pratz-chem Dec 20, 2024
fd41e5e
Remove print statement
q-pratz-chem Dec 20, 2024
8aa721f
Remove print statement
q-pratz-chem Dec 20, 2024
0f1995e
Remove print statements
q-pratz-chem Dec 20, 2024
c245c60
Remove print statements
q-pratz-chem Dec 20, 2024
d7c581f
Remove print statements
q-pratz-chem Dec 20, 2024
b5504e6
Remove print statements
q-pratz-chem Dec 20, 2024
2d71904
Remove the is_hf_det bool
q-pratz-chem Dec 20, 2024
1a3bf36
Update the compute_derivative helper function with modified Ryser's a…
q-pratz-chem Dec 23, 2024
94fcef2
correct the sign for alpha beta -> alpha beta matrix elements, correc…
q-pratz-chem Dec 23, 2024
0d975f9
Add code for testing the pCCD+ spin-preserving Singles
q-pratz-chem Jan 3, 2025
d30f961
Merge branch 'non-singletci-wfn' into nonsinglet-ap1rogen
q-pratz-chem Jan 3, 2025
e9ea704
add check for nproj to raise valueerror
q-pratz-chem Jan 7, 2025
2a78d90
Remove all print statements, remove the commented extra options for t…
q-pratz-chem Jan 7, 2025
dcfc762
Add a check for nocc, raise invalid_argument if it is odd. Add descri…
q-pratz-chem Jan 7, 2025
012c169
removed unused variables
q-pratz-chem Jan 9, 2025
53a17e5
comment print statements
q-pratz-chem Jan 9, 2025
485fdec
Fix the kk index to occ_up orbitals in the second alpha --> alpha exc…
q-pratz-chem Jan 14, 2025
27c3df7
Convert spatial to spin representation of ham, called those as one_ao…
q-pratz-chem Jan 14, 2025
6ab3bc9
Changed order of params by considering those corresponding to singles…
q-pratz-chem Jan 17, 2025
8b42198
added fanpy approach to calculate overlap
q-pratz-chem Feb 12, 2025
5fed888
Added deriv function for implementation approach same as fanpy
q-pratz-chem Feb 18, 2025
99f668c
update add row function for NonSingletCI
q-pratz-chem Feb 19, 2025
afc6c47
Clean up the commented extra optional codes
q-pratz-chem Feb 20, 2025
7e7cc71
Firstll configurations based on exc using FullCI base class
q-pratz-chem Feb 20, 2025
b46ac61
change nword2 to nword to fix the update issue in GenCI base class
q-pratz-chem Feb 20, 2025
048deea
update function declarations
q-pratz-chem Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .pyci import __version__, c_long, c_ulong, c_double, sparse_op

from .pyci import secondquant_op, wavefunction, one_spin_wfn, two_spin_wfn
from .pyci import doci_wfn, fullci_wfn, genci_wfn, sparse_op
from .pyci import doci_wfn, fullci_wfn, genci_wfn, nonsingletci_wfn, sparse_op
from .pyci import get_num_threads, set_num_threads, popcnt, ctz
from .pyci import compute_overlap, compute_rdms, compute_transition_rdms
from .pyci import add_hci, compute_enpt2
Expand All @@ -45,6 +45,7 @@
"doci_wfn",
"fullci_wfn",
"genci_wfn",
"nonsingletci_wfn",
"sparse_op",
"get_num_threads",
"set_num_threads",
Expand Down
2 changes: 2 additions & 0 deletions pyci/fanci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"AP1roG",
"DetRatio",
"pCCDS",
"AP1roGeneralizedSeno",
]


Expand All @@ -18,3 +19,4 @@
from .ap1rog import AP1roG
from .detratio import DetRatio
from .pccds import pCCDS
from .ap1rogen import AP1roGeneralizedSeno
195 changes: 195 additions & 0 deletions pyci/fanci/ap1rogen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
r"""
FanCI AP1roGeneralizedseno module for AP1roGSDGeneralized_sen-o wavefunction.

"""

from typing import Any, Union

import numpy as np

import pyci

from ..pyci import AP1roGeneralizedSenoObjective
from .fanci import FanCI
import pdb


__all___ = [
"AP1roGeneralizedSeno",
]


class AP1roGeneralizedSeno(FanCI):
r"""
DOC
"""

def __init__(
self,
ham: pyci.hamiltonian,
nocc: int,
nproj: int = None,
wfn: pyci.nonsingletci_wfn = None,
fill: str = 'excitation',
**kwargs: Any,
) -> None:
r"""
Initialize the FanCI problem.

Parameters
----------
ham : pyci.hamiltonian
PyCI Hamiltonian.
nocc : int
Number of occupied orbitals.
nproj : int, optional
Number of determinants in projection ("P") space.
wfn : pyci.nonsingletci_wfn
If specified, this PyCI wave function defines the projection ("P") space.
fill :
kwargs : Any, optional
Additional keyword arguments for base FanCI class.

"""
# SEE OTHER FANCI WFNS

if not isinstance(ham, pyci.hamiltonian):
raise TypeError(f"Invalid `ham` type `{type(ham)}`; must be `pyci.hamiltonian`")

nparam = nocc * (ham.nbasis - nocc) + (2 * nocc) * (2 * (ham.nbasis - nocc)) + 1 #less params considering we added singles as well
nproj = nparam if nproj is None else nproj

# if nproj > nparam:
# raise ValueError("nproj cannot be greater than the size of the space")

if wfn is None:
# wfn = pyci.doci_wfn(ham.nbasis, nocc, nocc)
# wfn.add_excited_dets(1) # add pair excited determinants
wfn = pyci.fullci_wfn(ham.nbasis, nocc, nocc)
# exc=0 ensures addint HF determinannt first
pyci.add_excitations(wfn,1,2,3,4)
print("Printing FCI wfn dets: ")
for i, sd in enumerate(wfn.to_occ_array()):
sd = np.array(sd)
print(wfn.to_det_array()[i],np.concatenate((sd[0],sd[1]+ham.nbasis)))

wfn = pyci.nonsingletci_wfn(wfn)

elif not isinstance(wfn, pyci.nonsingletci_wfn):
raise TypeError(f"Invalid `wfn` type `{type(wfn)}`; must be `pyci.nonsingletci_wfn`")
elif wfn.nocc != nocc:
raise ValueError(f"wfn.nocc does not match `nocc={nocc}` parameter")


# Initialize base class
FanCI.__init__(self, ham, wfn, nproj, nparam, **kwargs)
print("Nonsingletci nbasis: ",wfn.nbasis)
print("\n\nPrinting nonsingletci wfn dets: ")
for sd in (self._sspace):
print(sd)
# sd = np.array(sd)
# print(np.concatenate((sd[0],sd[1]+ham.nbasis)))
print("Done printing\n\n")

# Assign reference occupations
#ref_occs_up = np.arange(nocc_up, dtype=pyci.c_long)
#ref_occs_dn = np.arange(nocc_dn, dtype=pyci.c_long)

# Save sub-class-specific attributes
#self._ref_occs = [ref_occs_up, ref_occs_dn]

# Initiazlize C++ extension
try:
norm_det = kwargs["norm_det"]
idx_det_cons = np.asarray([elem[0] for elem in norm_det], dtype=int)
det_cons = np.asarray([elem[1] for elem in norm_det], dtype=int)
except KeyError:
idx_det_cons = None
det_cons = None

try:
norm_param = kwargs["norm_param"]
idx_param_cons = np.asarray([elem[0] for elem in norm_param], dtype=int)
param_cons = np.asarray([elem[1] for elem in norm_param], dtype=int)
except KeyError:
idx_param_cons = None
param_cons = None

self._cext = AP1roGeneralizedSenoObjective(
self._ci_op, self._wfn,
idx_det_cons=idx_det_cons, det_cons=det_cons,
idx_param_cons=idx_param_cons, param_cons=param_cons,
)

def compute_overlap(self, x: np.ndarray) -> np.ndarray:
r"""
Compute the FanCI overlap vector.

Parameters
----------
x : np.ndarray
Parameter array, [p_0, p_1, ..., p_n].

Returns
-------
ovlp : np.ndarray
Overlap array.

"""
return self._cext.overlap(x)

def compute_overlap_deriv(self, x: np.ndarray) -> np.ndarray:
r"""
Compute the FanCI overlap derivative matrix.

Parameters
----------
x : np.ndarray
Parameter array, [p_0, p_1, ..., p_n].

Returns
-------
ovlp : np.ndarray
Overlap derivative array.

"""
return self._cext.d_overlap(x)

def compute_objective(self, x: np.ndarray) -> np.ndarray:
r"""
Compute the FanCI objective function.

f : x[k] -> y[n]

Parameters
----------
x : np.ndarray
Parameter array, [p_0, p_1, ..., p_n, E].

Returns
-------
obj : np.ndarray
Objective vector.

"""
return self._cext.objective(self._ci_op, x)

def compute_jacobian(self, x: np.ndarray) -> np.ndarray:
r"""
Compute the Jacobian of the FanCI objective function.

j : x[k] -> y[n, k]

Parameters
----------
x : np.ndarray
Parameter array, [p_0, p_1, ..., p_n, E].

Returns
-------
jac : np.ndarray
Jacobian matrix.

"""
return self._cext.jacobian(self._ci_op, x)

25 changes: 24 additions & 1 deletion pyci/fanci/fanci.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from scipy.optimize import OptimizeResult, least_squares, root

from scipy.optimize import minimize

import pyci


Expand Down Expand Up @@ -200,11 +202,28 @@ def __init__(
wfn = fill_wavefunction(wfn, nproj, fill)

# Compute CI matrix operator with nproj rows and len(wfn) columns
ci_op = pyci.sparse_op(ham, wfn, nrow=nproj, ncol=len(wfn), symmetric=False)
if type(wfn).__name__ == "nonsingletci_wfn":
ci_op = pyci.sparse_op(ham, wfn, nrow=nproj, ncol=len(wfn), symmetric=False, wfntype="nonsingletci")
else:
ci_op = pyci.sparse_op(ham, wfn, nrow=nproj, ncol=len(wfn), symmetric=False)

# Compute arrays of occupations
sspace = wfn.to_occ_array()

# if type(wfn).__name__ == "nonsingletci_wfn":
# pspace = sspace[np.r_[0:13, 21:29, 37:45, 53:60, 66:72, 75:77, 81, 99:102, 104:108, 109:117, 126:129, 131:135,
# 136:144, 171:183, 189:195, 201:206, 209, 221:224, 225:231, 2316:239, 240:246, 261:267,
# 273:278, 282:286, 288, 300:302, 303:309, 314:316, 317:323, 337:344, 348:352, 356:359,
# 365:369, 371:375, 381:384, 388:391, 393:395, 400:403, 405:408, 413:416, 418:420, 422,
# 424:426, 427, 430]]
# # nproj = len(pspace)
# else:
pspace = sspace[:nproj]
print("len(sspace), len(pspace): ", len(sspace), len(pspace))
# dec_sspace = wfn.to_det_array()
# print("Printing sspace")
# for dec, bin in zip(dec_sspace, sspace):
# print("\n", dec, bin)

# Assign attributes to instance
self._nequation = nequation
Expand Down Expand Up @@ -271,6 +290,10 @@ def optimize(
elif mode == "root":
opt_args = f, x0
optimizer = root
# FIXME: For BFGS to work, objective function must return a scalar value
elif mode == "bfgs":
opt_args = f, x0
optimizer = minimize
else:
raise ValueError("invalid mode parameter")

Expand Down
Loading