Skip to content

Commit

Permalink
Move constant orbital limits to fqe.settings
Browse files Browse the repository at this point in the history
  • Loading branch information
awhite862 committed Aug 26, 2023
1 parent 9232d3d commit b941a5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/fqe/bitstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from fqe.lib.bitstring import _lexicographic_bitstring_generator, _count_bits, \
_get_occupation
import fqe.settings
from fqe.settings import use_accelerated_code, c_string_max_norb


def gbit_index(str0: int) -> Generator[int, None, None]:
Expand Down Expand Up @@ -68,7 +68,7 @@ def integer_index(string: int) -> 'Nparray':
Nparray: a list of integers indicating the index of each occupied \
orbital
"""
if fqe.settings.use_accelerated_code:
if use_accelerated_code:
return _get_occupation(string)
else:
return numpy.array(list(gbit_index(int(string)))).astype(numpy.int32)
Expand Down Expand Up @@ -107,7 +107,7 @@ def lexicographic_bitstring_generator(nele: int, norb: int) -> 'Nparray':
if nele > norb:
raise ValueError("nele cannot be larger than norb")

if fqe.settings.use_accelerated_code and norb < 64:
if use_accelerated_code and norb <= c_string_max_norb:
out = numpy.zeros((int(special.comb(norb, nele)),), dtype=numpy.uint64)
_lexicographic_bitstring_generator(out, norb, nele)
return out
Expand All @@ -127,7 +127,7 @@ def count_bits(string: int) -> int:
Returns:
int: the number of bits equal to 1
"""
if fqe.settings.use_accelerated_code:
if use_accelerated_code:
return _count_bits(string)
else:
return bin(int(string)).count('1')
Expand Down
14 changes: 7 additions & 7 deletions src/fqe/fci_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
_calculate_string_address, \
_c_map_to_deexc_alpha_icol, \
_make_mapping_each, _calculate_Z_matrix
import fqe.settings
from fqe.settings import use_accelerated_code, c_string_max_norb

Spinmap = Dict[Tuple[int, ...], Nparray]

Expand All @@ -54,7 +54,7 @@ def map_to_deexc(mappings: Spinmap, states: int, norbs: int,
index = numpy.zeros((states,), dtype=numpy.uint32)
for (i, j), values in mappings.items():
idx = i * norbs + j
if fqe.settings.use_accelerated_code and norbs < 64:
if use_accelerated_code and norbs <= c_string_max_norb:
_map_deexc(dexc, values, index, idx)
else:
for state, target, parity in values:
Expand Down Expand Up @@ -82,7 +82,7 @@ def _get_Z_matrix(norb: int, nele: int) -> Nparray:
if Z.size == 0:
return Z

if fqe.settings.use_accelerated_code and norb < 64:
if use_accelerated_code and norb <= c_string_max_norb:
_calculate_Z_matrix(Z, norb, nele)
else:
for k in range(1, nele):
Expand Down Expand Up @@ -217,7 +217,7 @@ def _build_mapping(self, strings: Nparray, nele: int,
"""
norb = self._norb

if fqe.settings.use_accelerated_code and norb < 64:
if use_accelerated_code and norb <= c_string_max_norb:
return _build_mapping_strings(strings, _get_Z_matrix(norb, nele),
nele, norb)
else:
Expand Down Expand Up @@ -315,7 +315,7 @@ def _build_strings(self, nele: int,
norb = self._norb
blist = lexicographic_bitstring_generator(nele, norb)

if fqe.settings.use_accelerated_code and norb < 64:
if use_accelerated_code and norb <= c_string_max_norb:
Z = _get_Z_matrix(norb, nele)
string_list = _calculate_string_address(Z, nele, norb, blist)
else:
Expand Down Expand Up @@ -470,7 +470,7 @@ def _map_to_deexc_alpha_icol(self):
length2,
), dtype=numpy.int32)
astrings = self.string_alpha_all()
if fqe.settings.use_accelerated_code and norb < 64:
if use_accelerated_code and norb <= c_string_max_norb:
_c_map_to_deexc_alpha_icol(exc, diag, index, astrings, norb,
self._alpha_map)
else:
Expand Down Expand Up @@ -538,7 +538,7 @@ def make_mapping_each(self, result: 'Nparray', alpha: bool, dag: List[int],
strings = self.string_beta_all()
length = self.lenb()

if fqe.settings.use_accelerated_code:
if use_accelerated_code:
count = _make_mapping_each(result, strings, length,
numpy.array(dag, dtype=numpy.int32),
numpy.array(undag, dtype=numpy.int32))
Expand Down
6 changes: 3 additions & 3 deletions src/fqe/fci_graph_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import scipy
from scipy import special

import fqe.settings
from fqe.settings import use_accelerated_code, c_string_max_norb
from fqe.fci_graph import FciGraph
from fqe.util import alpha_beta_electrons
from fqe.bitstring import integer_index, count_bits_between
Expand Down Expand Up @@ -171,7 +171,7 @@ def _postprocess(spinmap, dnv, index0, index1):

if dna != 0:
(iasec, jasec) = (isec, jsec) if dna < 0 else (jsec, isec)
if fqe.settings.use_accelerated_code and norb < 64:
if use_accelerated_code and norb <= c_string_max_norb:
ndowna, nupa = _make_mapping_each_set(iasec.string_alpha_all(),
abs(dna), norb,
iasec.nalpha())
Expand All @@ -192,7 +192,7 @@ def _postprocess(spinmap, dnv, index0, index1):

if dnb != 0:
(ibsec, jbsec) = (isec, jsec) if dnb < 0 else (jsec, isec)
if fqe.settings.use_accelerated_code and norb < 64:
if use_accelerated_code and norb <= c_string_max_norb:
ndownb, nupb = _make_mapping_each_set(ibsec.string_beta_all(),
abs(dnb), norb,
ibsec.nbeta())
Expand Down
11 changes: 11 additions & 0 deletions src/fqe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ class CodePath(Flag):
"""
A switch to check if accelerated code is used. Default is true if accelerated code is available
"""

global_max_norb = 64
"""
The global maximum number of orbitals that can be handled by FQE.
"""

c_string_max_norb = 63
"""
The max number of orbitals correctly handled by the C codepath
for generating determinant strings.
"""

0 comments on commit b941a5d

Please sign in to comment.