Skip to content

Commit

Permalink
Changed all non-array variables in smol/utils/cluster modules back in…
Browse files Browse the repository at this point in the history
…to int and double type in order to pass compilation.
  • Loading branch information
qchempku2017 committed Jan 2, 2025
1 parent 94adb8c commit ce6fe5a
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 97 deletions.
16 changes: 9 additions & 7 deletions smol/utils/cluster/container.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

__author__ = "Luis Barroso-Luque"

cimport numpy as np

import cython
from smol.utils.cluster.struct cimport (
FloatArray1D,
Expand All @@ -16,15 +18,15 @@ from smol.utils.cluster.struct cimport (

cdef class OrbitContainer:
cdef OrbitC* data
cdef readonly np.int32_t size
cdef readonly int size
cdef tuple _orbit_data

cpdef public void set_orbits(self, tuple orbit_data) except *

@staticmethod
cdef OrbitC create_struct(
np.int32_t orbit_id,
np.int32_t bit_id,
int orbit_id,
int bit_id,
np.float64_t[:, ::1] correlation_tensors,
np.int32_t[::1] tensor_indices,
)
Expand All @@ -33,7 +35,7 @@ cdef class OrbitContainer:
@cython.final
cdef class FloatArray2DContainer:
cdef FloatArray2D* data
cdef readonly np.int32_t size
cdef readonly int size
cdef tuple _arrays

cpdef public void set_arrays(self, tuple arrays) except *
Expand All @@ -45,7 +47,7 @@ cdef class FloatArray2DContainer:
@cython.final
cdef class FloatArray1DContainer:
cdef FloatArray1D* data
cdef readonly np.int32_t size
cdef readonly int size
cdef tuple _arrays

cpdef public void set_arrays(self, tuple arrays) except *
Expand All @@ -57,7 +59,7 @@ cdef class FloatArray1DContainer:
@cython.final
cdef class IntArray1DContainer:
cdef IntArray1D* data
cdef readonly np.int32_t size
cdef readonly int size
cdef tuple _arrays

cpdef public void set_arrays(self, tuple arrays) except *
Expand All @@ -69,7 +71,7 @@ cdef class IntArray1DContainer:
@cython.final
cdef class IntArray2DContainer:
cdef IntArray2D* data
cdef readonly np.int32_t size
cdef readonly int size
cdef tuple _arrays

cpdef public void set_arrays(self, tuple arrays) except *
Expand Down
18 changes: 9 additions & 9 deletions smol/utils/cluster/container.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ cdef class OrbitContainer:

cpdef public void set_orbits(self, tuple orbit_data) except *:
"""Populated data using a list of orbit data."""
cdef np.int32_t i
cdef int i

# check that dataypes are correct
for data in orbit_data:
if not isinstance(data[0], np.int32_t):
if not isinstance(data[0], int):
raise TypeError("id must be an integer.")
if not isinstance(data[1], np.int32_t):
if not isinstance(data[1], int):
raise TypeError("bit_id must be an integer.")
if not isinstance(data[2], np.ndarray):
raise TypeError("correlation_tensors must be a numpy array.")
Expand Down Expand Up @@ -83,8 +83,8 @@ cdef class OrbitContainer:

@staticmethod
cdef OrbitC create_struct(
np.int32_t orbit_id,
np.int32_t bit_id,
int orbit_id,
int bit_id,
np.float64_t[:, ::1] correlation_tensors,
np.int32_t[::1] tensor_indices,
):
Expand Down Expand Up @@ -131,7 +131,7 @@ cdef class FloatArray2DContainer:

cpdef public void set_arrays(self, tuple arrays) except *:
"""Populated data using a list of 2D arrays."""
cdef np.int32_t i
cdef int i

for array in arrays:
if array.ndim != 2:
Expand Down Expand Up @@ -190,7 +190,7 @@ cdef class FloatArray1DContainer:

cpdef public void set_arrays(self, tuple arrays) except *:
"""Populated data using a list of 1D arrays."""
cdef np.int32_t i
cdef int i

for array in arrays:
if array.ndim != 1:
Expand Down Expand Up @@ -247,7 +247,7 @@ cdef class IntArray1DContainer:

cpdef public void set_arrays(self, tuple arrays) except *:
"""Populated data using a list of 1D arrays."""
cdef np.int32_t i
cdef int i

for array in arrays:
if array.ndim != 1:
Expand Down Expand Up @@ -304,7 +304,7 @@ cdef class IntArray2DContainer:

cpdef public void set_arrays(self, tuple arrays) except *:
"""Populated data using a list of 2D arrays."""
cdef np.int32_t i
cdef int i

for array in arrays:
if array.ndim != 2:
Expand Down
64 changes: 32 additions & 32 deletions smol/utils/cluster/correlations.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ cimport numpy as np


cpdef corr_from_occupancy(const np.int32_t[::1] occu,
const np.int32_t num_corr_functions,
const int num_corr_functions,
list orbit_list):
"""Computes the correlation vector for a given encoded occupancy string.
Args:
occu (ndarray):
encoded occupancy array
num_corr_functions (np.int32_t):
num_corr_functions (int):
total number of bit orderings in expansion.
orbit_list:
Information of all orbits.
Expand All @@ -33,8 +33,8 @@ cpdef corr_from_occupancy(const np.int32_t[::1] occu,
Returns: array
correlation vector for given occupancy
"""
cdef np.int32_t i, j, n, m, I, J, M, index
cdef np.float64_t p
cdef int i, j, n, m, I, J, M, index
cdef double p
cdef const np.int32_t[:, ::1] indices
cdef const np.int32_t[::1] tensor_indices
cdef const np.int32_t[:, ::1] corr_tensors
Expand All @@ -60,7 +60,7 @@ cpdef corr_from_occupancy(const np.int32_t[::1] occu,

cpdef delta_corr_single_flip(const np.int32_t[::1] occu_f,
const np.int32_t[::1] occu_i,
const np.int32_t num_corr_functions,
const int num_corr_functions,
list site_orbit_list):
"""Computes the correlation difference between two occupancy arrays.
Expand All @@ -69,7 +69,7 @@ cpdef delta_corr_single_flip(const np.int32_t[::1] occu_f,
encoded occupancy array with flip
occu_i (ndarray):
encoded occupancy array without flip
num_corr_functions (np.int32_t):
num_corr_functions (int):
total number of bit orderings in expansion.
site_orbit_list:
Information of all orbits that include the flip site.
Expand All @@ -80,8 +80,8 @@ cpdef delta_corr_single_flip(const np.int32_t[::1] occu_f,
Returns:
ndarray: correlation vector difference
"""
cdef np.int32_t i, j, n, m, I, J, M, ind_i, ind_f
cdef np.float64_t p, ratio
cdef int i, j, n, m, I, J, M, ind_i, ind_f
cdef double p, ratio
cdef const np.int32_t[:, ::1] indices
cdef const np.int32_t[::1] tensor_indices
cdef const np.float64_t[:, ::1] corr_tensors
Expand All @@ -108,7 +108,7 @@ cpdef delta_corr_single_flip(const np.int32_t[::1] occu_f,
cpdef corr_distance_single_flip(const np.int32_t[::1] occu_f,
const np.int32_t[::1] occu_i,
const np.float64_t[::1] ref_corr_vector,
const np.int32_t num_corr_functions,
const int num_corr_functions,
list orbit_list):
"""Computes the absolute distance of two correlation vectors separated by a single
flip and a given correlation vector.
Expand All @@ -122,7 +122,7 @@ cpdef corr_distance_single_flip(const np.int32_t[::1] occu_f,
encoded occupancy array without flip
ref_corr_vector (ndarray):
reference correlation vector
num_corr_functions (np.int32_t):
num_corr_functions (int):
total number of bit orderings in expansion.
orbit_list:
Information of all orbits.
Expand All @@ -133,8 +133,8 @@ cpdef corr_distance_single_flip(const np.int32_t[::1] occu_f,
ndarray: 2D with correlation vector distances from reference for each of occu_i
and occu_f
"""
cdef np.int32_t i, j, n, m, I, J, M, ind_i, ind_f
cdef np.float64_t p_i, p_f
cdef int i, j, n, m, I, J, M, ind_i, ind_f
cdef double p_i, p_f
cdef const np.int32_t[:, ::1] indices
cdef const np.int32_t[::1] tensor_indices
cdef const np.float64_t[:, ::1] corr_tensors
Expand Down Expand Up @@ -162,17 +162,17 @@ cpdef corr_distance_single_flip(const np.int32_t[::1] occu_f,


cpdef interactions_from_occupancy(const np.int32_t[::1] occu,
const np.int32_t num_interactions,
const np.float64_t offset,
const int num_interactions,
const double offset,
list orbit_list):
"""Computes the cluster interaction vector for a given encoded occupancy string.
Args:
occu (ndarray):
encoded occupancy vector
num_interactions (np.int32_t):
num_interactions (int):
total number of cluster interactions (orbits in cluster subspace).
offset (np.float64_t):
offset (double):
eci value for the constant term.
orbit_list:
Information of all orbits.
Expand All @@ -181,8 +181,8 @@ cpdef interactions_from_occupancy(const np.int32_t[::1] occu,
Returns: array
cluster interaction vector for given occupancy
"""
cdef np.int32_t n, i, j, I, J, index
cdef np.float64_t p
cdef int n, i, j, I, J, index
cdef double p
cdef const np.int32_t[:, ::1] indices
cdef const np.int32_t[::1] tensor_indices
cdef const np.float64_t[::1] interaction_tensor
Expand All @@ -208,7 +208,7 @@ cpdef interactions_from_occupancy(const np.int32_t[::1] occu,

cpdef delta_interactions_single_flip(const np.int32_t[::1] occu_f,
const np.int32_t[::1] occu_i,
const np.int32_t num_interactions,
const int num_interactions,
list site_orbit_list):
"""Computes the cluster interaction vector difference between two occupancy
strings.
Expand All @@ -217,7 +217,7 @@ cpdef delta_interactions_single_flip(const np.int32_t[::1] occu_f,
encoded occupancy vector with flip
occu_i (ndarray):
encoded occupancy vector without flip
num_interactions (np.int32_t):
num_interactions (int):
total number of cluster interactions (orbits in cluster subspace).
site_orbit_list:
Information of all orbits that include the flip site.
Expand All @@ -227,8 +227,8 @@ cpdef delta_interactions_single_flip(const np.int32_t[::1] occu_f,
Returns:
ndarray: cluster interaction vector difference
"""
cdef np.int32_t i, j, n, I, J, ind_i, ind_f
cdef np.float64_t p, ratio
cdef int i, j, n, I, J, ind_i, ind_f
cdef double p, ratio
cdef const np.int32_t[:, ::1] indices
cdef const np.int32_t[::1] tensor_indices
cdef const np.float64_t[::1] interaction_tensor
Expand All @@ -252,7 +252,7 @@ cpdef delta_interactions_single_flip(const np.int32_t[::1] occu_f,
cpdef interaction_distance_single_flip(const np.int32_t[::1] occu_f,
const np.int32_t[::1] occu_i,
const np.float64_t[::1] ref_interaction_vector,
const np.int32_t num_interactions,
const int num_interactions,
list orbit_list):
"""Computes the absolute distance of two cluster interaction vectors separated by a
single flip and a given correlation vector.
Expand All @@ -266,7 +266,7 @@ cpdef interaction_distance_single_flip(const np.int32_t[::1] occu_f,
encoded occupancy array without flip
ref_interaction_vector (ndarray):
reference cluster interaction vector
num_interactions (np.int32_t):
num_interactions (int):
total number of cluster interactions (orbits in cluster subspace).
site_orbit_list:
Information of all orbits that include the flip site.
Expand All @@ -278,8 +278,8 @@ cpdef interaction_distance_single_flip(const np.int32_t[::1] occu_f,
ndarray: 2D with cluster interaction vector distances from reference for each of
occu_i and occu_f
"""
cdef np.int32_t n, i, j, I, J, ind_i, ind_f
cdef np.float64_t p_i, p_f
cdef int n, i, j, I, J, ind_i, ind_f
cdef double p_i, p_f
cdef const np.int32_t[:, ::1] indices
cdef const np.int32_t[::1] tensor_indices
cdef const np.float64_t[::1] interaction_tensor
Expand Down Expand Up @@ -309,7 +309,7 @@ cpdef delta_ewald_single_flip(const np.int32_t[::1] occu_f,
const np.int32_t[::1] occu_i,
const np.float64_t[:, ::1] ewald_matrix,
const np.int32_t[:, ::1] ewald_indices,
const np.int32_t site_ind):
const int site_ind):
"""Compute the change in electrostatic interaction energy from a flip.
Args:
Expand All @@ -322,16 +322,16 @@ cpdef delta_ewald_single_flip(const np.int32_t[::1] occu_f,
ewald_indices (ndarray):
2D array of indices corresponding to a specific site occupation
in the ewald matrix
site_ind (np.int32_t):
site_ind (int):
site index for site being flipped
Returns:
np.float64_t: electrostatic interaction energy difference
double: electrostatic interaction energy difference
"""
cdef np.int32_t i, j, k, add, sub
cdef int i, j, k, add, sub
cdef bint ok
cdef np.float64_t out = 0
cdef np.float64_t out_k
cdef double out = 0
cdef double out_k

# values of -1 are vacancies and hence don't have ewald indices
add = ewald_indices[site_ind, occu_f[site_ind]]
Expand Down
14 changes: 7 additions & 7 deletions smol/utils/cluster/evaluator.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ from smol.utils.cluster.container cimport (

@cython.final
cdef class ClusterSpaceEvaluator(OrbitContainer):
cdef np.int32_t num_corr # total number of correlation functions
cdef np.int32_t num_orbits # total number of orbits
cdef public np.float64_t offset # offset for the interaction tensor
cdef int num_corr # total number of correlation functions
cdef int num_orbits # total number of orbits
cdef public double offset # offset for the interaction tensor
cdef FloatArray1DContainer cluster_interactions
cdef public np.int32_t num_threads
cdef public int num_threads

cpdef public void reset_data(
self,
tuple orbit_data,
np.int32_t num_orbits,
np.int32_t num_corr_functions,
int num_orbits,
int num_corr_functions,
)

cpdef public void set_cluster_interactions(
self, tuple cluster_interaction_tensors, np.float64_t offset
self, tuple cluster_interaction_tensors, double offset
)

cpdef np.ndarray[np.float64_t, ndim=1] correlations_from_occupancy(
Expand Down
Loading

0 comments on commit ce6fe5a

Please sign in to comment.