Skip to content

Commit

Permalink
Clean import
Browse files Browse the repository at this point in the history
  • Loading branch information
TApplencourt committed Aug 25, 2022
1 parent eb8fc38 commit 96de255
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
25 changes: 16 additions & 9 deletions qe/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@
from functools import partial, cached_property, cache
from collections import defaultdict
import numpy as np
from math import sqrt
import random

# Import mpi4py and utilities
from mpi4py import MPI # Note this initializes and finalizes MPI session automatically
import sys

from qe.fundamental_types import *
from qe.integral_indexing_utils import *
from qe.fundamental_types import (
Spin_determinant,
Determinant,
Psi_det,
OrbitalIdx,
Energy,
Psi_coef,
One_electron_integral,
Two_electron_integral,
Two_electron_integral_index_phase,
)
from typing import Iterator, Set, Tuple, List, Dict
from qe.integral_indexing_utils import compound_idx4_reverse, compound_idx4, canonical_idx4

# _____ _ _ _
# |_ _| | | | | | |
# | | _ __ | |_ ___ __ _ _ __ __ _| | | |_ _ _ _ __ ___ ___
Expand Down Expand Up @@ -69,6 +78,7 @@ def integral_category(i, j, k, l):
else:
return "G"


# _____ _ _ _ _
# | ___| (_) | | | (_)
# | |____ _____ _| |_ __ _| |_ _ ___ _ __
Expand Down Expand Up @@ -653,7 +663,6 @@ def category_A(idx, psi_i, det_to_index_j, spindet_a_occ_i, spindet_b_occ_i):
assert integral_category(i, j, k, l) == "A"

def do_diagonal_A(i, j, psi_i, det_to_index_j, spindet_occ_i, oppspindet_occ_i):
phase = 1
# Get indices of determinants occupied in ia and ib
det_indices = Hamiltonian_two_electrons_integral_driven.get_dets_occ_in_orbitals(
spindet_occ_i, oppspindet_occ_i, {"same": {i}, "opposite": {j}}, "all"
Expand Down Expand Up @@ -1710,7 +1719,7 @@ def distributed_davidson(
)

if all(converged): # Convergence check
self.print_master(f"All eigenvalues converged, exiting iteration")
self.print_master("All eigenvalues converged, exiting iteration")
break
for j in working_indices: # Iterate through non-converged eigenpairs
self.print_master(
Expand Down Expand Up @@ -1853,8 +1862,6 @@ def psi_external_local(self):
ceiling = floor + 1
# Save these distributions + offsets for some MPI communication later
self.external_distribution = [ceiling] * remainder + [floor] * (self.world_size - remainder)
# Local problem size (no. of local external determinants)
local_external_size = self.external_distribution[self.rank]
# Compute offsets (start of the local section) for all nodes
self.external_offsets = [0] + list(accumulate(self.external_distribution[:-1]))
# Distribute external dets
Expand Down
2 changes: 1 addition & 1 deletion qe/fundamental_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Tuple, Dict, NamedTuple, List, NewType

# Orbital index (0,1,2,...,n_orb-1)
OrbitalIdx = NewType("OrbitalIdx", int)
# Two-electron integral :
Expand Down Expand Up @@ -28,4 +29,3 @@ class Determinant(NamedTuple):
# The varitional Energy who correpond Psi_det
# The pt2 Energy who correnpond to the pertubative energy induce by each determinant connected to Psi_det
Energy = NewType("Energy", float)

2 changes: 1 addition & 1 deletion qe/integral_indexing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def compound_idx2_reverse(ij):
>>> compound_idx2_reverse(3)
(0, 2)
"""
assert( (1 + 8*ij) >= 0)
assert (1 + 8 * ij) >= 0
j = (math.isqrt(1 + 8 * ij) - 1) // 2
i = ij - (j * (j + 1) // 2)
return i, j
Expand Down
11 changes: 9 additions & 2 deletions qe/io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from qe.fundamental_types import Tuple, One_electron_integral, Two_electron_integral, Determinant, Energy, List
from qe.fundamental_types import (
Tuple,
One_electron_integral,
Two_electron_integral,
Determinant,
Energy,
List,
)
from collections import defaultdict
from qe.integral_indexing_utils import compound_idx4
import math
Expand Down Expand Up @@ -82,6 +89,7 @@ def load_integrals(

return n_orb, E0, d_one_e_integral, d_two_e_integral


def load_wf(path_wf) -> Tuple[List[float], List[Determinant]]:
"""Read the input file :
Representation of the Slater determinants (basis) and
Expand Down Expand Up @@ -169,4 +177,3 @@ def load_eref(path_ref) -> Energy:
import re

return float(re.search(r"E +=.+", data).group(0).strip().split()[-1])

28 changes: 26 additions & 2 deletions tests/test_everything_all_at_once.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@
import time
import sys
import os
import random

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from qe.drivers import *
from qe.io import *
from qe.integral_indexing_utils import (
compound_idx4_reverse,
compound_idx4,
canonical_idx4,
compound_idx2,
compound_idx2_reverse,
compound_idx4_reverse_all,
)
from qe.drivers import (
integral_category,
PhaseIdx,
Excitation,
Hamiltonian_two_electrons_integral_driven,
Hamiltonian_two_electrons_determinant_driven,
H_indices_generator,
Hamiltonian_generator,
Powerplant_manager,
selection_step,
)
from qe.io import load_eref, load_integrals, load_wf
from collections import defaultdict
from itertools import product
from qe.fundamental_types import Determinant
from mpi4py import MPI


class Timing:
def setUp(self):
Expand Down

0 comments on commit 96de255

Please sign in to comment.