import math import re import numpy import scipy.linalg from pyscf.lib import misc EINSUM_MAX_SIZE = getattr(misc.__config__, 'lib_einsum_max_size', 2000) try: # Import tblis before libnp_helper to avoid potential dl-loading conflicts from pyscf.lib import tblis_einsum FOUND_TBLIS = True except (ImportError, OSError): FOUND_TBLIS = False _np_helper = misc.load_library('libnp_helper') BLOCK_DIM = 192 PLAIN = 0 HERMITIAN = 1 ANTIHERMI = 2 SYMMETRIC = 3 LeviCivita = numpy.zeros((3,3,3)) LeviCivita[0,1,2] = LeviCivita[1,2,0] = LeviCivita[2,0,1] = 1 LeviCivita[0,2,1] = LeviCivita[2,1,0] = LeviCivita[1,0,2] = -1 PauliMatrices = numpy.array([[[0., 1.], [1., 0.]], # x [[0.,-1j], [1j, 0.]], # y
# Copyright 2014-2018 The PySCF Developers. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pyscf.lib import misc libnao = misc.load_library("libnao")
# Copyright 2014-2018 The PySCF Developers. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pyscf.lib import misc libnao = misc.load_library("libnao") try: libnao_gpu = misc.load_library("libnao_gpu") except: pass #print("Failed to import libnao_gpu") # Let's be silent, please!
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ''' A Python interface to mimic numpy.einsum ''' import sys import re import ctypes import numpy from pyscf.lib import misc libtblis = misc.load_library('libtblis') libtblis.as_einsum.restype = None libtblis.as_einsum.argtypes = (numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), ctypes.c_int, numpy.ctypeslib.ndpointer(),
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ''' A Python interface to mimic numpy.einsum ''' import re import ctypes import numpy from pyscf.lib import misc libtblis = misc.load_library('libtblis_einsum') libtblis.as_einsum.restype = None libtblis.as_einsum.argtypes = (numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), ctypes.c_int, numpy.ctypeslib.ndpointer(),
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pyscf.lib import misc from ctypes import POINTER, c_double, c_int, c_int64, c_float, c_int import scipy.sparse as sparse import numpy as np try: libspblas = misc.load_library("libsparse_blas") use_sparse_blas = True except: #raise UserWarning("Using scipy version") libspblas = None use_sparse_blas = False #def csrmm(alpha, csr, B, beta = 0.0, trans="N", colrow = "row"): # """ # Small wrapper to use the mkl_cspblas_?csrgemv routine # instead of the scipy.sparse mul operation. # Inputs: # ------- # csr: scipy csr matrix # x: 1D numpy array of size N # trans: string for trans csr, N or T
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ''' A Python interface to mimic numpy.einsum ''' import sys import re import ctypes import numpy from pyscf.lib import misc libtblis = misc.load_library('libtblis') libtblis.as_einsum.restype = None libtblis.as_einsum.argtypes = ( numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), numpy.ctypeslib.ndpointer(), ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char), ctypes.c_int, numpy.ctypeslib.ndpointer(), numpy.ctypeslib.ndpointer() )
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pyscf.lib import misc import numpy as np import scipy.sparse as sparse from ctypes import POINTER, c_double, c_int, c_int64, c_float, c_int libsparsetools = misc.load_library("libsparsetools") """ Wrapper to sparse matrix operations from scipy implemented with openmp """ def csr_matvec(csr, x): if not sparse.isspmatrix_csr(csr): raise Exception("Matrix must be in csr format") nrow, ncol = csr.shape nnz = csr.data.shape[0] if x.size != ncol: print(x.size, ncol) raise ValueError("wrong dimension!")
# Copyright 2014-2018 The PySCF Developers. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pyscf.lib import misc libnao = misc.load_library("libnao")
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pyscf.lib import misc from ctypes import POINTER, c_double, c_int, c_int64, c_float, c_int import scipy.sparse as sparse import numpy as np try: libspblas = misc.load_library("libsparse_blas") use_sparse_blas = True except: #raise UserWarning("Using scipy version") libspblas = None use_sparse_blas = False #def csrmm(alpha, csr, B, beta = 0.0, trans="N", colrow = "row"): # """ # Small wrapper to use the mkl_cspblas_?csrgemv routine # instead of the scipy.sparse mul operation. # Inputs: # ------- # csr: scipy csr matrix # x: 1D numpy array of size N
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import print_function, division import numpy as np from ctypes import POINTER, c_double, c_int, c_int64, c_float, c_int, c_long from scipy.linalg import blas from pyscf.nao.m_sparsetools import csr_matvec, csc_matvec, csc_matvecs import sys try: # to import gpu library from pyscf.lib import misc libnao_gpu = misc.load_library("libnao_gpu") GPU_import = True except: GPU_import = False class tddft_iter_gpu_c(): def __init__(self, GPU, X4, ksn2f, ksn2e, norbs, nfermi, nprod, vstart): """ Input Parameters: ----------------- GPU: variable to set up GPU calculations. It can take several forms * None : if GPU=None, no GPU will be use * True : if GPU is True, then calculation will be using GPUs with default setup * False : Identic to None
#!/usr/bin/env python # # Author: Qiming Sun <*****@*****.**> # import ctypes import numpy from pyscf.lib import misc """ Extension to numpy module """ _np_helper = misc.load_library("libnp_helper") BLOCK_DIM = 192 HERMITIAN = 1 ANTIHERMI = 2 # 2d -> 1d def pack_tril(mat): """flatten the lower triangular part of a matrix. Given mat, it returns mat[numpy.tril_indices(mat.shape[0])] Examples: >>> pack_tril(numpy.arange(9).reshape(3,3)) [0 3 4 6 7 8] """ mat = numpy.ascontiguousarray(mat)