{"repo_id":"CUDALibrarySamples","entity_id":"py:NPP.nppCanny.npp_canny_simple","uri":"program://CUDALibrarySamples/module/NPP.nppCanny.npp_canny_simple#L1-L243","kind":"module","name":"NPP.nppCanny.npp_canny_simple","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":1,"end_line":243,"context_start_line":1,"context_end_line":243,"code":"# SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nNPP 3-Channel Canny Edge Detection - Simple Example\n====================================================\n\nDetects edges in color images using NVIDIA NPP.\n20x faster than OpenCV, detects 60% more edges.\n\nRequirements:\n pip install torch opencv-python numpy\n\nUsage:\n python npp_canny_simple.py image.jpg\n\"\"\"\n\nimport cv2\nimport torch\nimport ctypes\nfrom ctypes import c_int, c_int16, c_ubyte, POINTER, c_void_p, sizeof\nimport sys\nimport time\n\n\nclass NPPCanny:\n \"\"\"NPP 3-Channel Canny Edge Detector\"\"\"\n\n # NPP enum constants\n NPP_FILTER_SOBEL = 0\n NPP_MASK_SIZE_3_X_3 = 200\n NPPI_NORM_L2 = 2\n NPP_BORDER_REPLICATE = 2\n\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n # Load NPP library\n import platform\n if platform.system() == 'Windows':\n lib = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.1\\bin\\x64\\nppif64_13.dll\"\n else:\n lib = \"/usr/local/cuda/lib64/libnppif.so\"\n\n self.npp = ctypes.cdll.LoadLibrary(lib)\n\n # Setup functions\n self.get_buffer_size = self.npp.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [NPPCanny.NppiSize, POINTER(c_int)]\n\n self.canny = self.npp.nppiFilterCannyBorder_8u_C3C1R_Ctx\n self.canny.restype = c_int\n self.canny.argtypes = [\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize, NPPCanny.NppiPoint,\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize,\n c_int, c_int, c_int16, c_int16, c_int, c_int, c_void_p,\n NPPCanny.NppStreamContext\n ]\n\n def detect(self, image, low=50, high=100):\n \"\"\"\n Detect edges in RGB image\n\n Args:\n image: numpy array (H, W, 3) BGR format\n low: low threshold (0-255)\n high: high threshold (0-255)\n\n Returns:\n edges: numpy array (H, W) binary edge map\n \"\"\"\n # Convert to tensor (HWC format required by NPP)\n img_tensor = torch.from_numpy(image).cuda().to(torch.uint8).contiguous()\n\n h, w, c = img_tensor.shape\n\n # Allocate output\n output = torch.empty((h, w), dtype=torch.uint8, device='cuda')\n\n # Get buffer size\n roi = NPPCanny.NppiSize(w, h)\n buf_size = c_int(0)\n status = self.get_buffer_size(roi, ctypes.byref(buf_size))\n if status != 0:\n raise RuntimeError(f\"NPP buffer size error: {status}\")\n buffer = torch.empty(buf_size.value, dtype=torch.uint8, device='cuda')\n\n # Setup context - properly initialize all fields\n device_id = torch.cuda.current_device()\n device_props = torch.cuda.get_device_properties(device_id)\n\n ctx = NPPCanny.NppStreamContext()\n ctx.hStream = c_void_p(torch.cuda.current_stream().cuda_stream)\n ctx.nCudaDeviceId = device_id\n ctx.nMultiProcessorCount = device_props.multi_processor_count\n ctx.nMaxThreadsPerMultiProcessor = device_props.max_threads_per_multi_processor\n ctx.nMaxThreadsPerBlock = device_props.max_threads_per_block\n ctx.nSharedMemPerBlock = device_props.total_constant_memory # Approximation\n ctx.nCudaDevAttrComputeCapabilityMajor = device_props.major\n ctx.nCudaDevAttrComputeCapabilityMinor = device_props.minor\n ctx.nStreamFlags = 0\n\n # Run Canny\n status = self.canny(\n ctypes.cast(img_tensor.data_ptr(), POINTER(c_ubyte)),\n 3 * w * sizeof(c_ubyte),\n NPPCanny.NppiSize(w, h),\n NPPCanny.NppiPoint(0, 0),\n ctypes.cast(output.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte),\n roi,\n NPPCanny.NPP_FILTER_SOBEL,\n NPPCanny.NPP_MASK_SIZE_3_X_3,\n c_int16(low),\n c_int16(high),\n NPPCanny.NPPI_NORM_L2,\n NPPCanny.NPP_BORDER_REPLICATE,\n ctypes.cast(buffer.data_ptr(), c_void_p),\n ctx\n )\n\n # Check NPP status\n if status != 0:\n raise RuntimeError(f\"NPP error: {status}\")\n\n return output.cpu().numpy()\n\n\ndef main():\n # Load image\n image_path = sys.argv[1] if len(sys.argv) > 1 else \"image.jpg\"\n image = cv2.imread(image_path)\n\n if image is None:\n print(f\"Error: Could not read {image_path}\")\n return\n\n print(f\"Image: {image.shape[1]}×{image.shape[0]}\")\n\n # Check GPU\n if not torch.cuda.is_available():\n print(\"Error: CUDA not available\")\n return\n\n print(f\"GPU: {torch.cuda.get_device_name(0)}\")\n\n # NPP 3-Channel Canny\n print(\"\\nNPP 3-Channel Canny...\")\n detector = NPPCanny()\n\n # Warmup run (initializes CUDA context)\n _ = detector.detect(image, low=50, high=100)\n torch.cuda.synchronize()\n\n # Timed run (average of 10 iterations)\n start = time.time()\n for _ in range(10):\n edges_npp = detector.detect(image, low=50, high=100)\n torch.cuda.synchronize()\n npp_time = (time.time() - start) * 1000 / 10\n\n print(f\" Time: {npp_time:.2f} ms\")\n print(f\" Edges: {edges_npp.sum() // 255} pixels\")\n\n # OpenCV Grayscale (comparison)\n print(\"\\nOpenCV Grayscale...\")\n gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n\n # Average of 10 iterations for fair comparison\n start = time.time()\n for _ in range(10):\n edges_cv = cv2.Canny(gray, 50, 100, L2gradient=True)\n cv_time = (time.time() - start) * 1000 / 10\n\n print(f\" Time: {cv_time:.2f} ms\")\n print(f\" Edges: {edges_cv.sum() // 255} pixels\")\n\n # OpenCV 3-Channel (naive approach: 3 separate Canny + merge)\n print(\"\\nOpenCV 3-Channel (3× separate)...\")\n b, g, r = cv2.split(image)\n\n # Average of 10 iterations\n start = time.time()\n for _ in range(10):\n edges_b = cv2.Canny(b, 50, 100, L2gradient=True)\n edges_g = cv2.Canny(g, 50, 100, L2gradient=True)\n edges_r = cv2.Canny(r, 50, 100, L2gradient=True)\n edges_cv_3ch = cv2.bitwise_or(edges_r, cv2.bitwise_or(edges_g, edges_b))\n cv_3ch_time = (time.time() - start) * 1000 / 10\n\n print(f\" Time: {cv_3ch_time:.2f} ms\")\n print(f\" Edges: {edges_cv_3ch.sum() // 255} pixels\")\n\n # Results\n print(\"\\n\" + \"=\"*50)\n print(\"PERFORMANCE COMPARISON\")\n print(\"=\"*50)\n print(f\"NPP 3-Channel: {npp_time:6.2f} ms ({edges_npp.sum() // 255:5d} edges)\")\n print(f\"OpenCV Grayscale: {cv_time:6.2f} ms ({edges_cv.sum() // 255:5d} edges)\")\n print(f\"OpenCV 3-Channel: {cv_3ch_time:6.2f} ms ({edges_cv_3ch.sum() // 255:5d} edges)\")\n print(\"=\"*50)\n print(f\"NPP vs OpenCV Gray: {cv_time/npp_time:5.1f}× faster\")\n print(f\"NPP vs OpenCV 3-Ch: {cv_3ch_time/npp_time:5.1f}× faster\")\n print(f\"Extra edges vs Gray: +{((edges_npp.sum() - edges_cv.sum()) / edges_cv.sum() * 100):4.0f}%\")\n print(\"=\"*50)\n\n # Save outputs\n cv2.imwrite(\"edges_npp.png\", edges_npp)\n cv2.imwrite(\"edges_opencv_gray.png\", edges_cv)\n cv2.imwrite(\"edges_opencv_3ch.png\", edges_cv_3ch)\n\n print(\"\\nSaved: edges_npp.png, edges_opencv_gray.png, edges_opencv_3ch.png\")\n\n\nif __name__ == \"__main__\":\n main()","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP.nppCanny.npp_canny_simple.NPPCanny","uri":"program://CUDALibrarySamples/class/NPP.nppCanny.npp_canny_simple.NPPCanny#L38-L153","kind":"class","name":"NPPCanny","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":38,"end_line":153,"context_start_line":18,"context_end_line":173,"code":"====================================================\n\nDetects edges in color images using NVIDIA NPP.\n20x faster than OpenCV, detects 60% more edges.\n\nRequirements:\n pip install torch opencv-python numpy\n\nUsage:\n python npp_canny_simple.py image.jpg\n\"\"\"\n\nimport cv2\nimport torch\nimport ctypes\nfrom ctypes import c_int, c_int16, c_ubyte, POINTER, c_void_p, sizeof\nimport sys\nimport time\n\n\nclass NPPCanny:\n \"\"\"NPP 3-Channel Canny Edge Detector\"\"\"\n\n # NPP enum constants\n NPP_FILTER_SOBEL = 0\n NPP_MASK_SIZE_3_X_3 = 200\n NPPI_NORM_L2 = 2\n NPP_BORDER_REPLICATE = 2\n\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n # Load NPP library\n import platform\n if platform.system() == 'Windows':\n lib = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.1\\bin\\x64\\nppif64_13.dll\"\n else:\n lib = \"/usr/local/cuda/lib64/libnppif.so\"\n\n self.npp = ctypes.cdll.LoadLibrary(lib)\n\n # Setup functions\n self.get_buffer_size = self.npp.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [NPPCanny.NppiSize, POINTER(c_int)]\n\n self.canny = self.npp.nppiFilterCannyBorder_8u_C3C1R_Ctx\n self.canny.restype = c_int\n self.canny.argtypes = [\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize, NPPCanny.NppiPoint,\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize,\n c_int, c_int, c_int16, c_int16, c_int, c_int, c_void_p,\n NPPCanny.NppStreamContext\n ]\n\n def detect(self, image, low=50, high=100):\n \"\"\"\n Detect edges in RGB image\n\n Args:\n image: numpy array (H, W, 3) BGR format\n low: low threshold (0-255)\n high: high threshold (0-255)\n\n Returns:\n edges: numpy array (H, W) binary edge map\n \"\"\"\n # Convert to tensor (HWC format required by NPP)\n img_tensor = torch.from_numpy(image).cuda().to(torch.uint8).contiguous()\n\n h, w, c = img_tensor.shape\n\n # Allocate output\n output = torch.empty((h, w), dtype=torch.uint8, device='cuda')\n\n # Get buffer size\n roi = NPPCanny.NppiSize(w, h)\n buf_size = c_int(0)\n status = self.get_buffer_size(roi, ctypes.byref(buf_size))\n if status != 0:\n raise RuntimeError(f\"NPP buffer size error: {status}\")\n buffer = torch.empty(buf_size.value, dtype=torch.uint8, device='cuda')\n\n # Setup context - properly initialize all fields\n device_id = torch.cuda.current_device()\n device_props = torch.cuda.get_device_properties(device_id)\n\n ctx = NPPCanny.NppStreamContext()\n ctx.hStream = c_void_p(torch.cuda.current_stream().cuda_stream)\n ctx.nCudaDeviceId = device_id\n ctx.nMultiProcessorCount = device_props.multi_processor_count\n ctx.nMaxThreadsPerMultiProcessor = device_props.max_threads_per_multi_processor\n ctx.nMaxThreadsPerBlock = device_props.max_threads_per_block\n ctx.nSharedMemPerBlock = device_props.total_constant_memory # Approximation\n ctx.nCudaDevAttrComputeCapabilityMajor = device_props.major\n ctx.nCudaDevAttrComputeCapabilityMinor = device_props.minor\n ctx.nStreamFlags = 0\n\n # Run Canny\n status = self.canny(\n ctypes.cast(img_tensor.data_ptr(), POINTER(c_ubyte)),\n 3 * w * sizeof(c_ubyte),\n NPPCanny.NppiSize(w, h),\n NPPCanny.NppiPoint(0, 0),\n ctypes.cast(output.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte),\n roi,\n NPPCanny.NPP_FILTER_SOBEL,\n NPPCanny.NPP_MASK_SIZE_3_X_3,\n c_int16(low),\n c_int16(high),\n NPPCanny.NPPI_NORM_L2,\n NPPCanny.NPP_BORDER_REPLICATE,\n ctypes.cast(buffer.data_ptr(), c_void_p),\n ctx\n )\n\n # Check NPP status\n if status != 0:\n raise RuntimeError(f\"NPP error: {status}\")\n\n return output.cpu().numpy()\n\n\ndef main():\n # Load image\n image_path = sys.argv[1] if len(sys.argv) > 1 else \"image.jpg\"\n image = cv2.imread(image_path)\n\n if image is None:\n print(f\"Error: Could not read {image_path}\")\n return\n\n print(f\"Image: {image.shape[1]}×{image.shape[0]}\")\n\n # Check GPU\n if not torch.cuda.is_available():\n print(\"Error: CUDA not available\")\n return\n\n print(f\"GPU: {torch.cuda.get_device_name(0)}\")\n","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP.nppCanny.npp_canny_simple.main","uri":"program://CUDALibrarySamples/function/NPP.nppCanny.npp_canny_simple.main#L156-L239","kind":"function","name":"main","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":156,"end_line":239,"context_start_line":136,"context_end_line":243,"code":" ctypes.cast(output.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte),\n roi,\n NPPCanny.NPP_FILTER_SOBEL,\n NPPCanny.NPP_MASK_SIZE_3_X_3,\n c_int16(low),\n c_int16(high),\n NPPCanny.NPPI_NORM_L2,\n NPPCanny.NPP_BORDER_REPLICATE,\n ctypes.cast(buffer.data_ptr(), c_void_p),\n ctx\n )\n\n # Check NPP status\n if status != 0:\n raise RuntimeError(f\"NPP error: {status}\")\n\n return output.cpu().numpy()\n\n\ndef main():\n # Load image\n image_path = sys.argv[1] if len(sys.argv) > 1 else \"image.jpg\"\n image = cv2.imread(image_path)\n\n if image is None:\n print(f\"Error: Could not read {image_path}\")\n return\n\n print(f\"Image: {image.shape[1]}×{image.shape[0]}\")\n\n # Check GPU\n if not torch.cuda.is_available():\n print(\"Error: CUDA not available\")\n return\n\n print(f\"GPU: {torch.cuda.get_device_name(0)}\")\n\n # NPP 3-Channel Canny\n print(\"\\nNPP 3-Channel Canny...\")\n detector = NPPCanny()\n\n # Warmup run (initializes CUDA context)\n _ = detector.detect(image, low=50, high=100)\n torch.cuda.synchronize()\n\n # Timed run (average of 10 iterations)\n start = time.time()\n for _ in range(10):\n edges_npp = detector.detect(image, low=50, high=100)\n torch.cuda.synchronize()\n npp_time = (time.time() - start) * 1000 / 10\n\n print(f\" Time: {npp_time:.2f} ms\")\n print(f\" Edges: {edges_npp.sum() // 255} pixels\")\n\n # OpenCV Grayscale (comparison)\n print(\"\\nOpenCV Grayscale...\")\n gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n\n # Average of 10 iterations for fair comparison\n start = time.time()\n for _ in range(10):\n edges_cv = cv2.Canny(gray, 50, 100, L2gradient=True)\n cv_time = (time.time() - start) * 1000 / 10\n\n print(f\" Time: {cv_time:.2f} ms\")\n print(f\" Edges: {edges_cv.sum() // 255} pixels\")\n\n # OpenCV 3-Channel (naive approach: 3 separate Canny + merge)\n print(\"\\nOpenCV 3-Channel (3× separate)...\")\n b, g, r = cv2.split(image)\n\n # Average of 10 iterations\n start = time.time()\n for _ in range(10):\n edges_b = cv2.Canny(b, 50, 100, L2gradient=True)\n edges_g = cv2.Canny(g, 50, 100, L2gradient=True)\n edges_r = cv2.Canny(r, 50, 100, L2gradient=True)\n edges_cv_3ch = cv2.bitwise_or(edges_r, cv2.bitwise_or(edges_g, edges_b))\n cv_3ch_time = (time.time() - start) * 1000 / 10\n\n print(f\" Time: {cv_3ch_time:.2f} ms\")\n print(f\" Edges: {edges_cv_3ch.sum() // 255} pixels\")\n\n # Results\n print(\"\\n\" + \"=\"*50)\n print(\"PERFORMANCE COMPARISON\")\n print(\"=\"*50)\n print(f\"NPP 3-Channel: {npp_time:6.2f} ms ({edges_npp.sum() // 255:5d} edges)\")\n print(f\"OpenCV Grayscale: {cv_time:6.2f} ms ({edges_cv.sum() // 255:5d} edges)\")\n print(f\"OpenCV 3-Channel: {cv_3ch_time:6.2f} ms ({edges_cv_3ch.sum() // 255:5d} edges)\")\n print(\"=\"*50)\n print(f\"NPP vs OpenCV Gray: {cv_time/npp_time:5.1f}× faster\")\n print(f\"NPP vs OpenCV 3-Ch: {cv_3ch_time/npp_time:5.1f}× faster\")\n print(f\"Extra edges vs Gray: +{((edges_npp.sum() - edges_cv.sum()) / edges_cv.sum() * 100):4.0f}%\")\n print(\"=\"*50)\n\n # Save outputs\n cv2.imwrite(\"edges_npp.png\", edges_npp)\n cv2.imwrite(\"edges_opencv_gray.png\", edges_cv)\n cv2.imwrite(\"edges_opencv_3ch.png\", edges_cv_3ch)\n\n print(\"\\nSaved: edges_npp.png, edges_opencv_gray.png, edges_opencv_3ch.png\")\n\n\nif __name__ == \"__main__\":\n main()","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP.nppCanny.npp_canny_simple.NppiSize","uri":"program://CUDALibrarySamples/class/NPP.nppCanny.npp_canny_simple.NppiSize#L47-L48","kind":"class","name":"NppiSize","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":47,"end_line":48,"context_start_line":27,"context_end_line":68,"code":" python npp_canny_simple.py image.jpg\n\"\"\"\n\nimport cv2\nimport torch\nimport ctypes\nfrom ctypes import c_int, c_int16, c_ubyte, POINTER, c_void_p, sizeof\nimport sys\nimport time\n\n\nclass NPPCanny:\n \"\"\"NPP 3-Channel Canny Edge Detector\"\"\"\n\n # NPP enum constants\n NPP_FILTER_SOBEL = 0\n NPP_MASK_SIZE_3_X_3 = 200\n NPPI_NORM_L2 = 2\n NPP_BORDER_REPLICATE = 2\n\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n # Load NPP library\n import platform\n if platform.system() == 'Windows':\n lib = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.1\\bin\\x64\\nppif64_13.dll\"\n else:","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP.nppCanny.npp_canny_simple.NppiPoint","uri":"program://CUDALibrarySamples/class/NPP.nppCanny.npp_canny_simple.NppiPoint#L50-L51","kind":"class","name":"NppiPoint","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":50,"end_line":51,"context_start_line":30,"context_end_line":71,"code":"import cv2\nimport torch\nimport ctypes\nfrom ctypes import c_int, c_int16, c_ubyte, POINTER, c_void_p, sizeof\nimport sys\nimport time\n\n\nclass NPPCanny:\n \"\"\"NPP 3-Channel Canny Edge Detector\"\"\"\n\n # NPP enum constants\n NPP_FILTER_SOBEL = 0\n NPP_MASK_SIZE_3_X_3 = 200\n NPPI_NORM_L2 = 2\n NPP_BORDER_REPLICATE = 2\n\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n # Load NPP library\n import platform\n if platform.system() == 'Windows':\n lib = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.1\\bin\\x64\\nppif64_13.dll\"\n else:\n lib = \"/usr/local/cuda/lib64/libnppif.so\"\n\n self.npp = ctypes.cdll.LoadLibrary(lib)","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP.nppCanny.npp_canny_simple.NppStreamContext","uri":"program://CUDALibrarySamples/class/NPP.nppCanny.npp_canny_simple.NppStreamContext#L53-L61","kind":"class","name":"NppStreamContext","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":53,"end_line":61,"context_start_line":33,"context_end_line":81,"code":"from ctypes import c_int, c_int16, c_ubyte, POINTER, c_void_p, sizeof\nimport sys\nimport time\n\n\nclass NPPCanny:\n \"\"\"NPP 3-Channel Canny Edge Detector\"\"\"\n\n # NPP enum constants\n NPP_FILTER_SOBEL = 0\n NPP_MASK_SIZE_3_X_3 = 200\n NPPI_NORM_L2 = 2\n NPP_BORDER_REPLICATE = 2\n\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n # Load NPP library\n import platform\n if platform.system() == 'Windows':\n lib = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.1\\bin\\x64\\nppif64_13.dll\"\n else:\n lib = \"/usr/local/cuda/lib64/libnppif.so\"\n\n self.npp = ctypes.cdll.LoadLibrary(lib)\n\n # Setup functions\n self.get_buffer_size = self.npp.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [NPPCanny.NppiSize, POINTER(c_int)]\n\n self.canny = self.npp.nppiFilterCannyBorder_8u_C3C1R_Ctx\n self.canny.restype = c_int\n self.canny.argtypes = [\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize, NPPCanny.NppiPoint,","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP.nppCanny.npp_canny_simple.__init__","uri":"program://CUDALibrarySamples/function/NPP.nppCanny.npp_canny_simple.__init__#L63-L85","kind":"function","name":"__init__","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":63,"end_line":85,"context_start_line":43,"context_end_line":105,"code":" NPP_MASK_SIZE_3_X_3 = 200\n NPPI_NORM_L2 = 2\n NPP_BORDER_REPLICATE = 2\n\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n # Load NPP library\n import platform\n if platform.system() == 'Windows':\n lib = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.1\\bin\\x64\\nppif64_13.dll\"\n else:\n lib = \"/usr/local/cuda/lib64/libnppif.so\"\n\n self.npp = ctypes.cdll.LoadLibrary(lib)\n\n # Setup functions\n self.get_buffer_size = self.npp.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [NPPCanny.NppiSize, POINTER(c_int)]\n\n self.canny = self.npp.nppiFilterCannyBorder_8u_C3C1R_Ctx\n self.canny.restype = c_int\n self.canny.argtypes = [\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize, NPPCanny.NppiPoint,\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize,\n c_int, c_int, c_int16, c_int16, c_int, c_int, c_void_p,\n NPPCanny.NppStreamContext\n ]\n\n def detect(self, image, low=50, high=100):\n \"\"\"\n Detect edges in RGB image\n\n Args:\n image: numpy array (H, W, 3) BGR format\n low: low threshold (0-255)\n high: high threshold (0-255)\n\n Returns:\n edges: numpy array (H, W) binary edge map\n \"\"\"\n # Convert to tensor (HWC format required by NPP)\n img_tensor = torch.from_numpy(image).cuda().to(torch.uint8).contiguous()\n\n h, w, c = img_tensor.shape\n\n # Allocate output\n output = torch.empty((h, w), dtype=torch.uint8, device='cuda')","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP.nppCanny.npp_canny_simple.detect","uri":"program://CUDALibrarySamples/function/NPP.nppCanny.npp_canny_simple.detect#L87-L153","kind":"function","name":"detect","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":87,"end_line":153,"context_start_line":67,"context_end_line":173,"code":" lib = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v13.1\\bin\\x64\\nppif64_13.dll\"\n else:\n lib = \"/usr/local/cuda/lib64/libnppif.so\"\n\n self.npp = ctypes.cdll.LoadLibrary(lib)\n\n # Setup functions\n self.get_buffer_size = self.npp.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [NPPCanny.NppiSize, POINTER(c_int)]\n\n self.canny = self.npp.nppiFilterCannyBorder_8u_C3C1R_Ctx\n self.canny.restype = c_int\n self.canny.argtypes = [\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize, NPPCanny.NppiPoint,\n POINTER(c_ubyte), c_int, NPPCanny.NppiSize,\n c_int, c_int, c_int16, c_int16, c_int, c_int, c_void_p,\n NPPCanny.NppStreamContext\n ]\n\n def detect(self, image, low=50, high=100):\n \"\"\"\n Detect edges in RGB image\n\n Args:\n image: numpy array (H, W, 3) BGR format\n low: low threshold (0-255)\n high: high threshold (0-255)\n\n Returns:\n edges: numpy array (H, W) binary edge map\n \"\"\"\n # Convert to tensor (HWC format required by NPP)\n img_tensor = torch.from_numpy(image).cuda().to(torch.uint8).contiguous()\n\n h, w, c = img_tensor.shape\n\n # Allocate output\n output = torch.empty((h, w), dtype=torch.uint8, device='cuda')\n\n # Get buffer size\n roi = NPPCanny.NppiSize(w, h)\n buf_size = c_int(0)\n status = self.get_buffer_size(roi, ctypes.byref(buf_size))\n if status != 0:\n raise RuntimeError(f\"NPP buffer size error: {status}\")\n buffer = torch.empty(buf_size.value, dtype=torch.uint8, device='cuda')\n\n # Setup context - properly initialize all fields\n device_id = torch.cuda.current_device()\n device_props = torch.cuda.get_device_properties(device_id)\n\n ctx = NPPCanny.NppStreamContext()\n ctx.hStream = c_void_p(torch.cuda.current_stream().cuda_stream)\n ctx.nCudaDeviceId = device_id\n ctx.nMultiProcessorCount = device_props.multi_processor_count\n ctx.nMaxThreadsPerMultiProcessor = device_props.max_threads_per_multi_processor\n ctx.nMaxThreadsPerBlock = device_props.max_threads_per_block\n ctx.nSharedMemPerBlock = device_props.total_constant_memory # Approximation\n ctx.nCudaDevAttrComputeCapabilityMajor = device_props.major\n ctx.nCudaDevAttrComputeCapabilityMinor = device_props.minor\n ctx.nStreamFlags = 0\n\n # Run Canny\n status = self.canny(\n ctypes.cast(img_tensor.data_ptr(), POINTER(c_ubyte)),\n 3 * w * sizeof(c_ubyte),\n NPPCanny.NppiSize(w, h),\n NPPCanny.NppiPoint(0, 0),\n ctypes.cast(output.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte),\n roi,\n NPPCanny.NPP_FILTER_SOBEL,\n NPPCanny.NPP_MASK_SIZE_3_X_3,\n c_int16(low),\n c_int16(high),\n NPPCanny.NPPI_NORM_L2,\n NPPCanny.NPP_BORDER_REPLICATE,\n ctypes.cast(buffer.data_ptr(), c_void_p),\n ctx\n )\n\n # Check NPP status\n if status != 0:\n raise RuntimeError(f\"NPP error: {status}\")\n\n return output.cpu().numpy()\n\n\ndef main():\n # Load image\n image_path = sys.argv[1] if len(sys.argv) > 1 else \"image.jpg\"\n image = cv2.imread(image_path)\n\n if image is None:\n print(f\"Error: Could not read {image_path}\")\n return\n\n print(f\"Image: {image.shape[1]}×{image.shape[0]}\")\n\n # Check GPU\n if not torch.cuda.is_available():\n print(\"Error: CUDA not available\")\n return\n\n print(f\"GPU: {torch.cuda.get_device_name(0)}\")\n","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.5_get_configs","uri":"program://CUDALibrarySamples/module/nvMatmulHeuristics.5_get_configs#L1-L167","kind":"module","name":"nvMatmulHeuristics.5_get_configs","path":"nvMatmulHeuristics/5_get_configs.py","language":"python","start_line":1,"end_line":167,"context_start_line":1,"context_end_line":167,"code":"#!/usr/bin/env python3\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport sys\n\nfrom nvMatmulHeuristics import (\n NvMatmulHeuristicsInterface,\n NvMatmulHeuristicsTarget,\n NvMatmulHeuristicsFlags,\n NvMatmulHeuristicsMatmulLayout,\n NvMatmulHeuristicsNvidiaGpu,\n layoutToStr\n)\n\n\ndef parse_args():\n parser = argparse.ArgumentParser(\n description='Get and display GEMM configurations for specified parameters'\n )\n\n parser.add_argument('-M', '--m-dim',\n type=int,\n required=True,\n help='Output matrix height')\n\n parser.add_argument('-N', '--n-dim',\n type=int,\n required=True,\n help='Output matrix width')\n\n parser.add_argument('-K', '--k-dim',\n type=int,\n required=True,\n help='Reduced dimension')\n\n parser.add_argument('-B', '--batch-size',\n type=int,\n default=1,\n help='Batch size (default: 1)')\n\n parser.add_argument('--gpu',\n type=str,\n choices=[gpu.name for gpu in NvMatmulHeuristicsNvidiaGpu if gpu.name != 'END'],\n required=True,\n help='Target GPU')\n\n parser.add_argument('--layout',\n type=str,\n choices=[layout.name for layout in NvMatmulHeuristicsMatmulLayout if layout.name != 'END'],\n default='NN_ROW_MAJOR',\n help='Matrix layout (default: NN_ROW_MAJOR)')\n\n parser.add_argument('--backend',\n type=str,\n choices=[backend.name for backend in NvMatmulHeuristicsTarget if backend.name != 'END'],\n default='CUTLASS3',\n help='Target backend (default: CUTLASS3)')\n\n parser.add_argument('--precision',\n type=str,\n default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--count',\n type=int,\n default=8,\n help='Number of configurations to retrieve (default: 8)')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n return parser.parse_args()\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nGetting {args.count} configurations for:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"Batch size: {args.batch_size}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\\n\")\n\n # Initialize nvMatmulHeuristics interface\n try:\n nvMatmulHeuristics = NvMatmulHeuristicsInterface(\n path=args.lib_path,\n backend=backend,\n precision=args.precision,\n flags=NvMatmulHeuristicsFlags.PERF_MODEL_BASED_AUTO_TUNING\n )\n except OSError as e:\n print(f\"Error: Failed to load nvMatmulHeuristics library: {e}\")\n print(f\"Make sure the library exists at: {args.lib_path}\")\n return 1\n except AssertionError:\n print(\"Error: Version mismatch or unsupported precision\")\n return 1\n\n try:\n # Create and initialize hardware descriptor\n hw_desc = nvMatmulHeuristics.createHardwareDescriptor()\n try:\n # Set the target GPU\n nvMatmulHeuristics.setHardwarePredefinedGpu(hw_desc, gpu)\n\n # Load internal discovery set for the specified layout\n success = nvMatmulHeuristics.loadInternalDiscoverySet(layout, hw_desc)\n if success:\n print(\"Successfully loaded internal discovery set.\")\n else:\n print(\"Failed to load internal discovery set. Make sure it is available for selected hardware and layout.\")\n\n # Create problem object\n problem = nvMatmulHeuristics.makeNvMatmulHeuristicsProblem(\n args.m_dim, args.n_dim, args.k_dim, layout, args.batch_size\n )\n\n # Get configurations using the problem object\n configs = nvMatmulHeuristics.get(problem, args.count, hw_desc)\n\n # Print results\n print(f\"Found {len(configs)} configurations:\\n\")\n for i, config in enumerate(configs, 1):\n kernel = config[\"kernel\"]\n runtime = config[\"runtime\"]\n print(f\"Configuration {i}:\")\n print(f\" Kernel: {kernel}\")\n print(f\" Estimated runtime: {runtime * 1000:.6f} ms\\n\")\n\n finally:\n # Clean up hardware descriptor\n nvMatmulHeuristics.destroyHardwareDescriptor(hw_desc)\n\n except RuntimeError as e:\n print(f\"Error: {e}\")\n return 1\n\n return 0\n\n\nif __name__ == \"__main__\":\n sys.exit(main())","source_hash":"f9a5426507cdbdf27b6825d4b6e2d06daaa200ae8dc67e6e1079307334868cf0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.5_get_configs.parse_args","uri":"program://CUDALibrarySamples/function/nvMatmulHeuristics.5_get_configs.parse_args#L31-L89","kind":"function","name":"parse_args","path":"nvMatmulHeuristics/5_get_configs.py","language":"python","start_line":31,"end_line":89,"context_start_line":11,"context_end_line":109,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport sys\n\nfrom nvMatmulHeuristics import (\n NvMatmulHeuristicsInterface,\n NvMatmulHeuristicsTarget,\n NvMatmulHeuristicsFlags,\n NvMatmulHeuristicsMatmulLayout,\n NvMatmulHeuristicsNvidiaGpu,\n layoutToStr\n)\n\n\ndef parse_args():\n parser = argparse.ArgumentParser(\n description='Get and display GEMM configurations for specified parameters'\n )\n\n parser.add_argument('-M', '--m-dim',\n type=int,\n required=True,\n help='Output matrix height')\n\n parser.add_argument('-N', '--n-dim',\n type=int,\n required=True,\n help='Output matrix width')\n\n parser.add_argument('-K', '--k-dim',\n type=int,\n required=True,\n help='Reduced dimension')\n\n parser.add_argument('-B', '--batch-size',\n type=int,\n default=1,\n help='Batch size (default: 1)')\n\n parser.add_argument('--gpu',\n type=str,\n choices=[gpu.name for gpu in NvMatmulHeuristicsNvidiaGpu if gpu.name != 'END'],\n required=True,\n help='Target GPU')\n\n parser.add_argument('--layout',\n type=str,\n choices=[layout.name for layout in NvMatmulHeuristicsMatmulLayout if layout.name != 'END'],\n default='NN_ROW_MAJOR',\n help='Matrix layout (default: NN_ROW_MAJOR)')\n\n parser.add_argument('--backend',\n type=str,\n choices=[backend.name for backend in NvMatmulHeuristicsTarget if backend.name != 'END'],\n default='CUTLASS3',\n help='Target backend (default: CUTLASS3)')\n\n parser.add_argument('--precision',\n type=str,\n default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--count',\n type=int,\n default=8,\n help='Number of configurations to retrieve (default: 8)')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n return parser.parse_args()\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nGetting {args.count} configurations for:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"Batch size: {args.batch_size}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\\n\")\n\n # Initialize nvMatmulHeuristics interface\n try:","source_hash":"f9a5426507cdbdf27b6825d4b6e2d06daaa200ae8dc67e6e1079307334868cf0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.5_get_configs.main","uri":"program://CUDALibrarySamples/function/nvMatmulHeuristics.5_get_configs.main#L92-L163","kind":"function","name":"main","path":"nvMatmulHeuristics/5_get_configs.py","language":"python","start_line":92,"end_line":163,"context_start_line":72,"context_end_line":167,"code":" help='Target backend (default: CUTLASS3)')\n\n parser.add_argument('--precision',\n type=str,\n default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--count',\n type=int,\n default=8,\n help='Number of configurations to retrieve (default: 8)')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n return parser.parse_args()\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nGetting {args.count} configurations for:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"Batch size: {args.batch_size}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\\n\")\n\n # Initialize nvMatmulHeuristics interface\n try:\n nvMatmulHeuristics = NvMatmulHeuristicsInterface(\n path=args.lib_path,\n backend=backend,\n precision=args.precision,\n flags=NvMatmulHeuristicsFlags.PERF_MODEL_BASED_AUTO_TUNING\n )\n except OSError as e:\n print(f\"Error: Failed to load nvMatmulHeuristics library: {e}\")\n print(f\"Make sure the library exists at: {args.lib_path}\")\n return 1\n except AssertionError:\n print(\"Error: Version mismatch or unsupported precision\")\n return 1\n\n try:\n # Create and initialize hardware descriptor\n hw_desc = nvMatmulHeuristics.createHardwareDescriptor()\n try:\n # Set the target GPU\n nvMatmulHeuristics.setHardwarePredefinedGpu(hw_desc, gpu)\n\n # Load internal discovery set for the specified layout\n success = nvMatmulHeuristics.loadInternalDiscoverySet(layout, hw_desc)\n if success:\n print(\"Successfully loaded internal discovery set.\")\n else:\n print(\"Failed to load internal discovery set. Make sure it is available for selected hardware and layout.\")\n\n # Create problem object\n problem = nvMatmulHeuristics.makeNvMatmulHeuristicsProblem(\n args.m_dim, args.n_dim, args.k_dim, layout, args.batch_size\n )\n\n # Get configurations using the problem object\n configs = nvMatmulHeuristics.get(problem, args.count, hw_desc)\n\n # Print results\n print(f\"Found {len(configs)} configurations:\\n\")\n for i, config in enumerate(configs, 1):\n kernel = config[\"kernel\"]\n runtime = config[\"runtime\"]\n print(f\"Configuration {i}:\")\n print(f\" Kernel: {kernel}\")\n print(f\" Estimated runtime: {runtime * 1000:.6f} ms\\n\")\n\n finally:\n # Clean up hardware descriptor\n nvMatmulHeuristics.destroyHardwareDescriptor(hw_desc)\n\n except RuntimeError as e:\n print(f\"Error: {e}\")\n return 1\n\n return 0\n\n\nif __name__ == \"__main__\":\n sys.exit(main())","source_hash":"f9a5426507cdbdf27b6825d4b6e2d06daaa200ae8dc67e6e1079307334868cf0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.7_smem_carveout","uri":"program://CUDALibrarySamples/module/nvMatmulHeuristics.7_smem_carveout#L1-L194","kind":"module","name":"nvMatmulHeuristics.7_smem_carveout","path":"nvMatmulHeuristics/7_smem_carveout.py","language":"python","start_line":1,"end_line":194,"context_start_line":1,"context_end_line":194,"code":"#!/usr/bin/env python3\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport ctypes\nimport sys\n\nfrom nvMatmulHeuristics import (\n NvMatmulHeuristicsInterface,\n NvMatmulHeuristicsTarget,\n NvMatmulHeuristicsFlags,\n NvMatmulHeuristicsMatmulLayout,\n NvMatmulHeuristicsNvidiaGpu,\n NvMatmulHeuristicsBackendProperty,\n layoutToStr\n)\n\n\ndef parse_args():\n parser = argparse.ArgumentParser(\n description='Compare GEMM configurations with and without SMEM carveout'\n )\n\n parser.add_argument('-M', '--m-dim',\n type=int,\n required=True,\n help='Output matrix height')\n\n parser.add_argument('-N', '--n-dim',\n type=int,\n required=True,\n help='Output matrix width')\n\n parser.add_argument('-K', '--k-dim',\n type=int,\n required=True,\n help='Reduced dimension')\n\n parser.add_argument('--gpu',\n type=str,\n choices=[gpu.name for gpu in NvMatmulHeuristicsNvidiaGpu if gpu.name != 'END'],\n required=True,\n help='Target GPU')\n\n parser.add_argument('--layout',\n type=str,\n choices=[layout.name for layout in NvMatmulHeuristicsMatmulLayout if layout.name != 'END'],\n default='NN_ROW_MAJOR',\n help='Matrix layout (default: NN_ROW_MAJOR)')\n\n parser.add_argument('--backend',\n type=str,\n choices=[backend.name for backend in NvMatmulHeuristicsTarget if backend.name != 'END'],\n default='CUTLASS3',\n help='Target backend (default: CUTLASS3)')\n\n parser.add_argument('--precision',\n type=str,\n default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--smem-carveout',\n type=int,\n required=True,\n help='SMEM carveout size in bytes')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n return parser.parse_args()\n\n\ndef print_kernel_config(config, title):\n print(f\"\\n{title}:\")\n print(f\" CTA Tile: {config['kernel'].cta_tile_m}x{config['kernel'].cta_tile_n}x{config['kernel'].cta_tile_k}\")\n print(f\" Warp Tile: {config['kernel'].warp_tile_m}x{config['kernel'].warp_tile_n}x{config['kernel'].warp_tile_k}\")\n print(f\" Instruction Tile: {config['kernel'].instr_tile_m}x{config['kernel'].instr_tile_n}x{config['kernel'].instr_tile_k}\")\n print(f\" Split K: {config['kernel'].split_k}\")\n print(f\" Stages: {config['kernel'].stages}\")\n print(f\" CTA swizzling: {config['kernel'].swizzle_factor}\")\n print(f\" CTA Order: {config['kernel'].cta_order}\")\n print(f\" Cluster Config: {config['kernel'].cluster_m}x{config['kernel'].cluster_n}\")\n print(f\" Estimated Runtime: {config['runtime'] * 1000:.6f} ms\")\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nComparing configurations with and without SMEM carveout:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\")\n print(f\"SMEM Carveout: {args.smem_carveout} bytes\\n\")\n\n # Initialize nvMatmulHeuristics interface\n try:\n nvMatmulHeuristics = NvMatmulHeuristicsInterface(\n path=args.lib_path,\n backend=backend,\n precision=args.precision,\n flags=NvMatmulHeuristicsFlags.PERF_MODEL_BASED_AUTO_TUNING\n )\n except OSError as e:\n print(f\"Error: Failed to load nvMatmulHeuristics library: {e}\")\n print(f\"Make sure the library exists at: {args.lib_path}\")\n return 1\n except AssertionError:\n print(\"Error: Version mismatch or unsupported precision\")\n return 1\n\n try:\n # Create and initialize hardware descriptor\n hw_desc = nvMatmulHeuristics.createHardwareDescriptor()\n try:\n # Set the target GPU\n nvMatmulHeuristics.setHardwarePredefinedGpu(hw_desc, gpu)\n\n # Load internal discovery set for the specified layout\n success = nvMatmulHeuristics.loadInternalDiscoverySet(layout, hw_desc)\n if not success:\n print(\"Failed to load internal discovery set. Make sure it is available for selected hardware and layout.\")\n return 1\n\n # Create problem object\n problem = nvMatmulHeuristics.makeNvMatmulHeuristicsProblem(\n args.m_dim, args.n_dim, args.k_dim, layout\n )\n\n # Get configurations without SMEM carveout\n configs_no_carveout = nvMatmulHeuristics.get(problem, 1, hw_desc)\n if not configs_no_carveout:\n print(\"No configurations found without SMEM carveout\")\n return 1\n\n # Create backend with SMEM carveout\n backend_obj = nvMatmulHeuristics.createBackend(backend)\n try:\n # Set SMEM carveout size as int32_t\n smem_carveout = ctypes.c_int32(args.smem_carveout)\n nvMatmulHeuristics.setBackendValueProperty(\n backend_obj,\n NvMatmulHeuristicsBackendProperty.SMEM_CARVEOUT_SIZE,\n ctypes.byref(smem_carveout),\n ctypes.sizeof(smem_carveout)\n )\n\n # Get configurations with SMEM carveout\n configs_with_carveout = nvMatmulHeuristics.getEx(problem, 1, backend_obj, hw_desc)\n if not configs_with_carveout:\n print(\"No configurations found with SMEM carveout\")\n return 1\n\n # Print and compare configurations\n print_kernel_config(configs_no_carveout[0], \"Configuration without SMEM carveout\")\n print_kernel_config(configs_with_carveout[0], \"Configuration with SMEM carveout\")\n\n finally:\n nvMatmulHeuristics.destroyBackend(backend_obj)\n\n finally:\n nvMatmulHeuristics.destroyHardwareDescriptor(hw_desc)\n\n except RuntimeError as e:\n print(f\"Error: {e}\")\n return 1\n\n return 0\n\n\nif __name__ == \"__main__\":\n sys.exit(main())","source_hash":"e98cee2a04a1554e53ded6923a242b33b6613dda9ad7687da4d09302dd6968c1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.7_smem_carveout.parse_args","uri":"program://CUDALibrarySamples/function/nvMatmulHeuristics.7_smem_carveout.parse_args#L33-L86","kind":"function","name":"parse_args","path":"nvMatmulHeuristics/7_smem_carveout.py","language":"python","start_line":33,"end_line":86,"context_start_line":13,"context_end_line":106,"code":"# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport ctypes\nimport sys\n\nfrom nvMatmulHeuristics import (\n NvMatmulHeuristicsInterface,\n NvMatmulHeuristicsTarget,\n NvMatmulHeuristicsFlags,\n NvMatmulHeuristicsMatmulLayout,\n NvMatmulHeuristicsNvidiaGpu,\n NvMatmulHeuristicsBackendProperty,\n layoutToStr\n)\n\n\ndef parse_args():\n parser = argparse.ArgumentParser(\n description='Compare GEMM configurations with and without SMEM carveout'\n )\n\n parser.add_argument('-M', '--m-dim',\n type=int,\n required=True,\n help='Output matrix height')\n\n parser.add_argument('-N', '--n-dim',\n type=int,\n required=True,\n help='Output matrix width')\n\n parser.add_argument('-K', '--k-dim',\n type=int,\n required=True,\n help='Reduced dimension')\n\n parser.add_argument('--gpu',\n type=str,\n choices=[gpu.name for gpu in NvMatmulHeuristicsNvidiaGpu if gpu.name != 'END'],\n required=True,\n help='Target GPU')\n\n parser.add_argument('--layout',\n type=str,\n choices=[layout.name for layout in NvMatmulHeuristicsMatmulLayout if layout.name != 'END'],\n default='NN_ROW_MAJOR',\n help='Matrix layout (default: NN_ROW_MAJOR)')\n\n parser.add_argument('--backend',\n type=str,\n choices=[backend.name for backend in NvMatmulHeuristicsTarget if backend.name != 'END'],\n default='CUTLASS3',\n help='Target backend (default: CUTLASS3)')\n\n parser.add_argument('--precision',\n type=str,\n default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--smem-carveout',\n type=int,\n required=True,\n help='SMEM carveout size in bytes')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n return parser.parse_args()\n\n\ndef print_kernel_config(config, title):\n print(f\"\\n{title}:\")\n print(f\" CTA Tile: {config['kernel'].cta_tile_m}x{config['kernel'].cta_tile_n}x{config['kernel'].cta_tile_k}\")\n print(f\" Warp Tile: {config['kernel'].warp_tile_m}x{config['kernel'].warp_tile_n}x{config['kernel'].warp_tile_k}\")\n print(f\" Instruction Tile: {config['kernel'].instr_tile_m}x{config['kernel'].instr_tile_n}x{config['kernel'].instr_tile_k}\")\n print(f\" Split K: {config['kernel'].split_k}\")\n print(f\" Stages: {config['kernel'].stages}\")\n print(f\" CTA swizzling: {config['kernel'].swizzle_factor}\")\n print(f\" CTA Order: {config['kernel'].cta_order}\")\n print(f\" Cluster Config: {config['kernel'].cluster_m}x{config['kernel'].cluster_n}\")\n print(f\" Estimated Runtime: {config['runtime'] * 1000:.6f} ms\")\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]","source_hash":"e98cee2a04a1554e53ded6923a242b33b6613dda9ad7687da4d09302dd6968c1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.7_smem_carveout.print_kernel_config","uri":"program://CUDALibrarySamples/function/nvMatmulHeuristics.7_smem_carveout.print_kernel_config#L89-L99","kind":"function","name":"print_kernel_config","path":"nvMatmulHeuristics/7_smem_carveout.py","language":"python","start_line":89,"end_line":99,"context_start_line":69,"context_end_line":119,"code":" help='Target backend (default: CUTLASS3)')\n\n parser.add_argument('--precision',\n type=str,\n default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--smem-carveout',\n type=int,\n required=True,\n help='SMEM carveout size in bytes')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n return parser.parse_args()\n\n\ndef print_kernel_config(config, title):\n print(f\"\\n{title}:\")\n print(f\" CTA Tile: {config['kernel'].cta_tile_m}x{config['kernel'].cta_tile_n}x{config['kernel'].cta_tile_k}\")\n print(f\" Warp Tile: {config['kernel'].warp_tile_m}x{config['kernel'].warp_tile_n}x{config['kernel'].warp_tile_k}\")\n print(f\" Instruction Tile: {config['kernel'].instr_tile_m}x{config['kernel'].instr_tile_n}x{config['kernel'].instr_tile_k}\")\n print(f\" Split K: {config['kernel'].split_k}\")\n print(f\" Stages: {config['kernel'].stages}\")\n print(f\" CTA swizzling: {config['kernel'].swizzle_factor}\")\n print(f\" CTA Order: {config['kernel'].cta_order}\")\n print(f\" Cluster Config: {config['kernel'].cluster_m}x{config['kernel'].cluster_n}\")\n print(f\" Estimated Runtime: {config['runtime'] * 1000:.6f} ms\")\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nComparing configurations with and without SMEM carveout:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\")\n print(f\"SMEM Carveout: {args.smem_carveout} bytes\\n\")\n\n # Initialize nvMatmulHeuristics interface\n try:","source_hash":"e98cee2a04a1554e53ded6923a242b33b6613dda9ad7687da4d09302dd6968c1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.7_smem_carveout.main","uri":"program://CUDALibrarySamples/function/nvMatmulHeuristics.7_smem_carveout.main#L102-L190","kind":"function","name":"main","path":"nvMatmulHeuristics/7_smem_carveout.py","language":"python","start_line":102,"end_line":190,"context_start_line":82,"context_end_line":194,"code":" type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n return parser.parse_args()\n\n\ndef print_kernel_config(config, title):\n print(f\"\\n{title}:\")\n print(f\" CTA Tile: {config['kernel'].cta_tile_m}x{config['kernel'].cta_tile_n}x{config['kernel'].cta_tile_k}\")\n print(f\" Warp Tile: {config['kernel'].warp_tile_m}x{config['kernel'].warp_tile_n}x{config['kernel'].warp_tile_k}\")\n print(f\" Instruction Tile: {config['kernel'].instr_tile_m}x{config['kernel'].instr_tile_n}x{config['kernel'].instr_tile_k}\")\n print(f\" Split K: {config['kernel'].split_k}\")\n print(f\" Stages: {config['kernel'].stages}\")\n print(f\" CTA swizzling: {config['kernel'].swizzle_factor}\")\n print(f\" CTA Order: {config['kernel'].cta_order}\")\n print(f\" Cluster Config: {config['kernel'].cluster_m}x{config['kernel'].cluster_n}\")\n print(f\" Estimated Runtime: {config['runtime'] * 1000:.6f} ms\")\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nComparing configurations with and without SMEM carveout:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\")\n print(f\"SMEM Carveout: {args.smem_carveout} bytes\\n\")\n\n # Initialize nvMatmulHeuristics interface\n try:\n nvMatmulHeuristics = NvMatmulHeuristicsInterface(\n path=args.lib_path,\n backend=backend,\n precision=args.precision,\n flags=NvMatmulHeuristicsFlags.PERF_MODEL_BASED_AUTO_TUNING\n )\n except OSError as e:\n print(f\"Error: Failed to load nvMatmulHeuristics library: {e}\")\n print(f\"Make sure the library exists at: {args.lib_path}\")\n return 1\n except AssertionError:\n print(\"Error: Version mismatch or unsupported precision\")\n return 1\n\n try:\n # Create and initialize hardware descriptor\n hw_desc = nvMatmulHeuristics.createHardwareDescriptor()\n try:\n # Set the target GPU\n nvMatmulHeuristics.setHardwarePredefinedGpu(hw_desc, gpu)\n\n # Load internal discovery set for the specified layout\n success = nvMatmulHeuristics.loadInternalDiscoverySet(layout, hw_desc)\n if not success:\n print(\"Failed to load internal discovery set. Make sure it is available for selected hardware and layout.\")\n return 1\n\n # Create problem object\n problem = nvMatmulHeuristics.makeNvMatmulHeuristicsProblem(\n args.m_dim, args.n_dim, args.k_dim, layout\n )\n\n # Get configurations without SMEM carveout\n configs_no_carveout = nvMatmulHeuristics.get(problem, 1, hw_desc)\n if not configs_no_carveout:\n print(\"No configurations found without SMEM carveout\")\n return 1\n\n # Create backend with SMEM carveout\n backend_obj = nvMatmulHeuristics.createBackend(backend)\n try:\n # Set SMEM carveout size as int32_t\n smem_carveout = ctypes.c_int32(args.smem_carveout)\n nvMatmulHeuristics.setBackendValueProperty(\n backend_obj,\n NvMatmulHeuristicsBackendProperty.SMEM_CARVEOUT_SIZE,\n ctypes.byref(smem_carveout),\n ctypes.sizeof(smem_carveout)\n )\n\n # Get configurations with SMEM carveout\n configs_with_carveout = nvMatmulHeuristics.getEx(problem, 1, backend_obj, hw_desc)\n if not configs_with_carveout:\n print(\"No configurations found with SMEM carveout\")\n return 1\n\n # Print and compare configurations\n print_kernel_config(configs_no_carveout[0], \"Configuration without SMEM carveout\")\n print_kernel_config(configs_with_carveout[0], \"Configuration with SMEM carveout\")\n\n finally:\n nvMatmulHeuristics.destroyBackend(backend_obj)\n\n finally:\n nvMatmulHeuristics.destroyHardwareDescriptor(hw_desc)\n\n except RuntimeError as e:\n print(f\"Error: {e}\")\n return 1\n\n return 0\n\n\nif __name__ == \"__main__\":\n sys.exit(main())","source_hash":"e98cee2a04a1554e53ded6923a242b33b6613dda9ad7687da4d09302dd6968c1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.6_get_configs_ex","uri":"program://CUDALibrarySamples/module/nvMatmulHeuristics.6_get_configs_ex#L1-L179","kind":"module","name":"nvMatmulHeuristics.6_get_configs_ex","path":"nvMatmulHeuristics/6_get_configs_ex.py","language":"python","start_line":1,"end_line":179,"context_start_line":1,"context_end_line":179,"code":"#!/usr/bin/env python3\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport sys\n\nfrom nvMatmulHeuristics import (\n NvMatmulHeuristicsInterfaceEx,\n NvMatmulHeuristicsTarget,\n NvMatmulHeuristicsFlags,\n NvMatmulHeuristicsMatmulLayout,\n NvMatmulHeuristicsNvidiaGpu,\n layoutToStr\n)\n\n\ndef parse_args():\n parser = argparse.ArgumentParser(\n description='Get and display GEMM configurations using NvMatmulHeuristicsInterfaceEx'\n )\n\n parser.add_argument('-M', '--m-dim',\n type=int,\n required=True,\n help='Output matrix height')\n\n parser.add_argument('-N', '--n-dim',\n type=int,\n required=True,\n help='Output matrix width')\n\n parser.add_argument('-K', '--k-dim',\n type=int,\n required=True,\n help='Reduced dimension')\n\n parser.add_argument('-B', '--batch-size',\n type=int,\n default=1,\n help='Batch size (default: 1)')\n\n parser.add_argument('--gpu',\n type=str,\n choices=[gpu.name for gpu in NvMatmulHeuristicsNvidiaGpu if gpu.name != 'END'],\n required=True,\n help='Target GPU')\n\n parser.add_argument('--layout',\n type=str,\n choices=[layout.name for layout in NvMatmulHeuristicsMatmulLayout if layout.name != 'END'],\n default='NN_ROW_MAJOR',\n help='Matrix layout (default: NN_ROW_MAJOR)')\n\n parser.add_argument('--backend',\n type=str,\n choices=[backend.name for backend in NvMatmulHeuristicsTarget if backend.name != 'END'],\n default='CUTLASS3',\n help='Target backend (default: CUTLASS3)')\n\n parser.add_argument('--precision',\n type=str,\n default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--count',\n type=int,\n default=8,\n help='Number of configurations to retrieve (default: 8)')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n parser.add_argument('--no-auto-load',\n action='store_true',\n help='Disable automatic loading of discovery sets')\n\n return parser.parse_args()\n\n\ndef print_kernel_config(config, title):\n \"\"\"Print kernel configuration details.\"\"\"\n kernel = config[\"kernel\"]\n runtime = config[\"runtime\"]\n print(f\"\\n{title}:\")\n print(f\" Kernel: {kernel}\")\n print(f\" Estimated runtime: {runtime * 1000:.6f} ms\")\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nGetting {args.count} configurations for:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"Batch size: {args.batch_size}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\")\n print(f\"Auto-load discovery sets: {not args.no_auto_load}\\n\")\n\n # Initialize nvMatmulHeuristics interface\n try:\n # Create interface with the GPU\n nvMatmulHeuristics = NvMatmulHeuristicsInterfaceEx(\n path=args.lib_path,\n backend=backend,\n flags=NvMatmulHeuristicsFlags.PERF_MODEL_BASED_AUTO_TUNING,\n load_discovery_implicitly=not args.no_auto_load,\n gpu=gpu\n )\n\n # Create problem object\n problem = nvMatmulHeuristics.makeNvMatmulHeuristicsProblem(\n args.m_dim, args.n_dim, args.k_dim, layout, args.batch_size\n )\n\n # Set precision\n precision = args.precision\n print(f\"\\nGetting configurations with precision ({precision})...\")\n\n # Track loaded discovery sets before the call\n loaded_before = set(nvMatmulHeuristics._loaded_discovery_sets.keys())\n\n # Get configurations\n configs = nvMatmulHeuristics.get(problem, args.count, precision=precision)\n\n # Check which discovery sets were loaded\n loaded_after = set(nvMatmulHeuristics._loaded_discovery_sets.keys())\n newly_loaded = loaded_after - loaded_before\n\n if newly_loaded:\n print(\"\\nImplicitly loaded discovery sets:\")\n for key in newly_loaded:\n target, prec, layout = key\n print(f\" - Target: {target.name}, Precision: {prec}, Layout: {layoutToStr(layout)}\")\n else:\n print(\"\\nNo new discovery sets were loaded\")\n\n print(f\"\\nFound {len(configs)} configurations with {precision} precision:\")\n for i, config in enumerate(configs, 1):\n print_kernel_config(config, f\"Configuration {i}\")\n\n except OSError as e:\n print(f\"Error: Failed to load nvMatmulHeuristics library: {e}\")\n print(f\"Make sure the library exists at: {args.lib_path}\")\n return 1\n except AssertionError:\n print(\"Error: Version mismatch or unsupported precision\")\n return 1\n except RuntimeError as e:\n print(f\"Error: {e}\")\n return 1\n\n return 0\n\n\nif __name__ == \"__main__\":\n sys.exit(main())","source_hash":"c8e84920ab1e83cb90e60a289983efb6b6619c65b71586c0e60e1e33e1eac47a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.6_get_configs_ex.parse_args","uri":"program://CUDALibrarySamples/function/nvMatmulHeuristics.6_get_configs_ex.parse_args#L31-L93","kind":"function","name":"parse_args","path":"nvMatmulHeuristics/6_get_configs_ex.py","language":"python","start_line":31,"end_line":93,"context_start_line":11,"context_end_line":113,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport sys\n\nfrom nvMatmulHeuristics import (\n NvMatmulHeuristicsInterfaceEx,\n NvMatmulHeuristicsTarget,\n NvMatmulHeuristicsFlags,\n NvMatmulHeuristicsMatmulLayout,\n NvMatmulHeuristicsNvidiaGpu,\n layoutToStr\n)\n\n\ndef parse_args():\n parser = argparse.ArgumentParser(\n description='Get and display GEMM configurations using NvMatmulHeuristicsInterfaceEx'\n )\n\n parser.add_argument('-M', '--m-dim',\n type=int,\n required=True,\n help='Output matrix height')\n\n parser.add_argument('-N', '--n-dim',\n type=int,\n required=True,\n help='Output matrix width')\n\n parser.add_argument('-K', '--k-dim',\n type=int,\n required=True,\n help='Reduced dimension')\n\n parser.add_argument('-B', '--batch-size',\n type=int,\n default=1,\n help='Batch size (default: 1)')\n\n parser.add_argument('--gpu',\n type=str,\n choices=[gpu.name for gpu in NvMatmulHeuristicsNvidiaGpu if gpu.name != 'END'],\n required=True,\n help='Target GPU')\n\n parser.add_argument('--layout',\n type=str,\n choices=[layout.name for layout in NvMatmulHeuristicsMatmulLayout if layout.name != 'END'],\n default='NN_ROW_MAJOR',\n help='Matrix layout (default: NN_ROW_MAJOR)')\n\n parser.add_argument('--backend',\n type=str,\n choices=[backend.name for backend in NvMatmulHeuristicsTarget if backend.name != 'END'],\n default='CUTLASS3',\n help='Target backend (default: CUTLASS3)')\n\n parser.add_argument('--precision',\n type=str,\n default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--count',\n type=int,\n default=8,\n help='Number of configurations to retrieve (default: 8)')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n parser.add_argument('--no-auto-load',\n action='store_true',\n help='Disable automatic loading of discovery sets')\n\n return parser.parse_args()\n\n\ndef print_kernel_config(config, title):\n \"\"\"Print kernel configuration details.\"\"\"\n kernel = config[\"kernel\"]\n runtime = config[\"runtime\"]\n print(f\"\\n{title}:\")\n print(f\" Kernel: {kernel}\")\n print(f\" Estimated runtime: {runtime * 1000:.6f} ms\")\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nGetting {args.count} configurations for:\")","source_hash":"c8e84920ab1e83cb90e60a289983efb6b6619c65b71586c0e60e1e33e1eac47a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.6_get_configs_ex.print_kernel_config","uri":"program://CUDALibrarySamples/function/nvMatmulHeuristics.6_get_configs_ex.print_kernel_config#L96-L102","kind":"function","name":"print_kernel_config","path":"nvMatmulHeuristics/6_get_configs_ex.py","language":"python","start_line":96,"end_line":102,"context_start_line":76,"context_end_line":122,"code":" default='HSH',\n help='Precision string (e.g. HSS, TST) (default: HSH)')\n\n parser.add_argument('--count',\n type=int,\n default=8,\n help='Number of configurations to retrieve (default: 8)')\n\n parser.add_argument('--lib-path',\n type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n parser.add_argument('--no-auto-load',\n action='store_true',\n help='Disable automatic loading of discovery sets')\n\n return parser.parse_args()\n\n\ndef print_kernel_config(config, title):\n \"\"\"Print kernel configuration details.\"\"\"\n kernel = config[\"kernel\"]\n runtime = config[\"runtime\"]\n print(f\"\\n{title}:\")\n print(f\" Kernel: {kernel}\")\n print(f\" Estimated runtime: {runtime * 1000:.6f} ms\")\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nGetting {args.count} configurations for:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"Batch size: {args.batch_size}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\")\n print(f\"Auto-load discovery sets: {not args.no_auto_load}\\n\")\n\n # Initialize nvMatmulHeuristics interface","source_hash":"c8e84920ab1e83cb90e60a289983efb6b6619c65b71586c0e60e1e33e1eac47a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvMatmulHeuristics.6_get_configs_ex.main","uri":"program://CUDALibrarySamples/function/nvMatmulHeuristics.6_get_configs_ex.main#L105-L175","kind":"function","name":"main","path":"nvMatmulHeuristics/6_get_configs_ex.py","language":"python","start_line":105,"end_line":175,"context_start_line":85,"context_end_line":179,"code":" type=str,\n default=None,\n help='Path to nvMatmulHeuristics shared library (default: uses the library from the wheel)')\n\n parser.add_argument('--no-auto-load',\n action='store_true',\n help='Disable automatic loading of discovery sets')\n\n return parser.parse_args()\n\n\ndef print_kernel_config(config, title):\n \"\"\"Print kernel configuration details.\"\"\"\n kernel = config[\"kernel\"]\n runtime = config[\"runtime\"]\n print(f\"\\n{title}:\")\n print(f\" Kernel: {kernel}\")\n print(f\" Estimated runtime: {runtime * 1000:.6f} ms\")\n\n\ndef main():\n args = parse_args()\n\n # Convert string arguments to enum values\n gpu = NvMatmulHeuristicsNvidiaGpu[args.gpu]\n layout = NvMatmulHeuristicsMatmulLayout[args.layout]\n backend = NvMatmulHeuristicsTarget[args.backend]\n\n print(f\"\\nGetting {args.count} configurations for:\")\n print(f\"Problem size: M={args.m_dim}, N={args.n_dim}, K={args.k_dim}\")\n print(f\"Batch size: {args.batch_size}\")\n print(f\"GPU: {gpu.name}\")\n print(f\"Layout: {layoutToStr(layout)}\")\n print(f\"Backend: {backend.name}\")\n print(f\"Precision: {args.precision}\")\n print(f\"Auto-load discovery sets: {not args.no_auto_load}\\n\")\n\n # Initialize nvMatmulHeuristics interface\n try:\n # Create interface with the GPU\n nvMatmulHeuristics = NvMatmulHeuristicsInterfaceEx(\n path=args.lib_path,\n backend=backend,\n flags=NvMatmulHeuristicsFlags.PERF_MODEL_BASED_AUTO_TUNING,\n load_discovery_implicitly=not args.no_auto_load,\n gpu=gpu\n )\n\n # Create problem object\n problem = nvMatmulHeuristics.makeNvMatmulHeuristicsProblem(\n args.m_dim, args.n_dim, args.k_dim, layout, args.batch_size\n )\n\n # Set precision\n precision = args.precision\n print(f\"\\nGetting configurations with precision ({precision})...\")\n\n # Track loaded discovery sets before the call\n loaded_before = set(nvMatmulHeuristics._loaded_discovery_sets.keys())\n\n # Get configurations\n configs = nvMatmulHeuristics.get(problem, args.count, precision=precision)\n\n # Check which discovery sets were loaded\n loaded_after = set(nvMatmulHeuristics._loaded_discovery_sets.keys())\n newly_loaded = loaded_after - loaded_before\n\n if newly_loaded:\n print(\"\\nImplicitly loaded discovery sets:\")\n for key in newly_loaded:\n target, prec, layout = key\n print(f\" - Target: {target.name}, Precision: {prec}, Layout: {layoutToStr(layout)}\")\n else:\n print(\"\\nNo new discovery sets were loaded\")\n\n print(f\"\\nFound {len(configs)} configurations with {precision} precision:\")\n for i, config in enumerate(configs, 1):\n print_kernel_config(config, f\"Configuration {i}\")\n\n except OSError as e:\n print(f\"Error: Failed to load nvMatmulHeuristics library: {e}\")\n print(f\"Make sure the library exists at: {args.lib_path}\")\n return 1\n except AssertionError:\n print(\"Error: Version mismatch or unsupported precision\")\n return 1\n except RuntimeError as e:\n print(f\"Error: {e}\")\n return 1\n\n return 0\n\n\nif __name__ == \"__main__\":\n sys.exit(main())","source_hash":"c8e84920ab1e83cb90e60a289983efb6b6619c65b71586c0e60e1e33e1eac47a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP+.cannyEdgeDetectorPython.cannyEdgeDetector","uri":"program://CUDALibrarySamples/module/NPP+.cannyEdgeDetectorPython.cannyEdgeDetector#L1-L164","kind":"module","name":"NPP+.cannyEdgeDetectorPython.cannyEdgeDetector","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":1,"end_line":164,"context_start_line":1,"context_end_line":164,"code":"# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport os\nimport time\nimport cv2\nimport torch\nimport ctypes\nimport numpy as np\nimport pandas as pd\nimport torchvision\nfrom tabulate import tabulate\nfrom ctypes import c_int, c_int16, c_ubyte, POINTER, c_void_p, sizeof\n\n# Settings\nINPUT_IMAGE = \"Teapot.jpg\"\nOUTPUT_DIR = \"Teapot_resolutions\"\nWARMUP_ITERATIONS = 5\nMEASURE_ITERATIONS = 1000\nTHRESH_WEAK = 72\nTHRESH_STRONG = 256\n\nRESOLUTIONS = [\n (320, 180, \"320x180\"),\n (640, 360, \"640x360\"),\n (800, 600, \"800x600\"),\n (1280, 720, \"1280x720\"),\n (1920, 1080, \"1920x1080\"),\n (2560, 1440, \"2560x1440\"),\n (3840, 2160, \"3840x2160\"),\n (5120, 2880, \"5120x2880\"),\n]\n\nos.makedirs(OUTPUT_DIR, exist_ok=True)\n\nclass CannyEdgeDetector:\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n #npp_path = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.8\\bin\\npp_plus_if64_12.dll\" # for windows user\n #self.npp_lib = ctypes.cdll.LoadLibrary(npp_path)\n self.npp_lib = ctypes.CDLL('libnpp_plus_if.so') # for linux user\n self._setup_functions()\n\n def _setup_functions(self):\n self.get_buffer_size = self.npp_lib.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [self.NppiSize, POINTER(c_int)]\n\n self.canny_func = self.npp_lib.nppiFilterCannyBorder_8u_C1R_Ctx\n self.canny_func.restype = c_int\n self.canny_func.argtypes = [\n POINTER(c_ubyte), c_int, self.NppiSize, self.NppiPoint,\n POINTER(c_ubyte), c_int, self.NppiSize,\n c_int, c_int, c_int16, c_int16,\n c_int, c_int, c_void_p, self.NppStreamContext\n ]\n\n def __call__(self, img_tensor, low_thresh, high_thresh):\n if img_tensor.dtype != torch.uint8:\n img_tensor = (img_tensor * 255).byte()\n if not img_tensor.is_cuda:\n img_tensor = img_tensor.cuda()\n\n h, w = img_tensor.shape\n output = torch.empty_like(img_tensor)\n scratch_size = c_int()\n self.get_buffer_size(self.NppiSize(w, h), ctypes.byref(scratch_size))\n scratch_buffer = torch.empty(scratch_size.value, dtype=torch.uint8, device='cuda')\n\n stream_ctx = self.NppStreamContext()\n stream_ctx.hStream = c_void_p(torch.cuda.current_stream().cuda_stream)\n\n status = self.canny_func(\n ctypes.cast(img_tensor.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte), self.NppiSize(w, h), self.NppiPoint(0, 0),\n ctypes.cast(output.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte), self.NppiSize(w, h),\n 0, 200, c_int16(low_thresh), c_int16(high_thresh),\n 2, 2,\n ctypes.cast(scratch_buffer.data_ptr(), c_void_p), stream_ctx\n )\n\n if status != 0:\n raise RuntimeError(f\"NPP Canny edge detection failed with status {status}\")\n\n return output\n\n# Load input image\nimg = cv2.imread(INPUT_IMAGE)\nif img is None:\n raise FileNotFoundError(f\"Image not found: {INPUT_IMAGE}\")\n\nif not torch.cuda.is_available():\n raise RuntimeError(\"CUDA device not available!\")\n\nprint(f\"Input image size: {img.shape}\")\nprint(f\"Running benchmark... {MEASURE_ITERATIONS} iterations\")\n\ndetector = CannyEdgeDetector()\nresults = []\n\nfor width, height, label in RESOLUTIONS:\n print(f\"\\nProcessing {label}\")\n resized = cv2.resize(img, (width, height))\n img_tensor = torch.from_numpy(resized).cuda().permute(2, 0, 1)\n img_tensor = torchvision.transforms.functional.rgb_to_grayscale(img_tensor).squeeze(0)\n\n for _ in range(WARMUP_ITERATIONS):\n detector(img_tensor, THRESH_WEAK, THRESH_STRONG)\n\n timings = []\n for _ in range(MEASURE_ITERATIONS):\n start = torch.cuda.Event(enable_timing=True)\n end = torch.cuda.Event(enable_timing=True)\n start.record()\n detector(img_tensor, THRESH_WEAK, THRESH_STRONG)\n end.record()\n torch.cuda.synchronize()\n timings.append(start.elapsed_time(end))\n\n output_image = detector(img_tensor, THRESH_WEAK, THRESH_STRONG).cpu().numpy()\n cv2.imwrite(f\"{OUTPUT_DIR}/out_npp_{label}.png\", output_image)\n\n results.append({\n \"Resolution\": label,\n \"Megapixels\": (width * height) / 1_000_000,\n \"NPP Time (ms)\": np.mean(timings)\n })\n\n# Save performance summary\ndf = pd.DataFrame(results)\nprint(\"\\n--- Performance Summary ---\")\nprint(tabulate(df, headers='keys', tablefmt='pretty', floatfmt='.3f'))\n\ncsv_path = os.path.join(OUTPUT_DIR, \"performance_results.csv\")\ndf.to_csv(csv_path, index=False)\nprint(f\"\\nResults saved to {csv_path}\")","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.CannyEdgeDetector","uri":"program://CUDALibrarySamples/class/NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.CannyEdgeDetector#L48-L113","kind":"class","name":"CannyEdgeDetector","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":48,"end_line":113,"context_start_line":28,"context_end_line":133,"code":"INPUT_IMAGE = \"Teapot.jpg\"\nOUTPUT_DIR = \"Teapot_resolutions\"\nWARMUP_ITERATIONS = 5\nMEASURE_ITERATIONS = 1000\nTHRESH_WEAK = 72\nTHRESH_STRONG = 256\n\nRESOLUTIONS = [\n (320, 180, \"320x180\"),\n (640, 360, \"640x360\"),\n (800, 600, \"800x600\"),\n (1280, 720, \"1280x720\"),\n (1920, 1080, \"1920x1080\"),\n (2560, 1440, \"2560x1440\"),\n (3840, 2160, \"3840x2160\"),\n (5120, 2880, \"5120x2880\"),\n]\n\nos.makedirs(OUTPUT_DIR, exist_ok=True)\n\nclass CannyEdgeDetector:\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n #npp_path = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.8\\bin\\npp_plus_if64_12.dll\" # for windows user\n #self.npp_lib = ctypes.cdll.LoadLibrary(npp_path)\n self.npp_lib = ctypes.CDLL('libnpp_plus_if.so') # for linux user\n self._setup_functions()\n\n def _setup_functions(self):\n self.get_buffer_size = self.npp_lib.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [self.NppiSize, POINTER(c_int)]\n\n self.canny_func = self.npp_lib.nppiFilterCannyBorder_8u_C1R_Ctx\n self.canny_func.restype = c_int\n self.canny_func.argtypes = [\n POINTER(c_ubyte), c_int, self.NppiSize, self.NppiPoint,\n POINTER(c_ubyte), c_int, self.NppiSize,\n c_int, c_int, c_int16, c_int16,\n c_int, c_int, c_void_p, self.NppStreamContext\n ]\n\n def __call__(self, img_tensor, low_thresh, high_thresh):\n if img_tensor.dtype != torch.uint8:\n img_tensor = (img_tensor * 255).byte()\n if not img_tensor.is_cuda:\n img_tensor = img_tensor.cuda()\n\n h, w = img_tensor.shape\n output = torch.empty_like(img_tensor)\n scratch_size = c_int()\n self.get_buffer_size(self.NppiSize(w, h), ctypes.byref(scratch_size))\n scratch_buffer = torch.empty(scratch_size.value, dtype=torch.uint8, device='cuda')\n\n stream_ctx = self.NppStreamContext()\n stream_ctx.hStream = c_void_p(torch.cuda.current_stream().cuda_stream)\n\n status = self.canny_func(\n ctypes.cast(img_tensor.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte), self.NppiSize(w, h), self.NppiPoint(0, 0),\n ctypes.cast(output.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte), self.NppiSize(w, h),\n 0, 200, c_int16(low_thresh), c_int16(high_thresh),\n 2, 2,\n ctypes.cast(scratch_buffer.data_ptr(), c_void_p), stream_ctx\n )\n\n if status != 0:\n raise RuntimeError(f\"NPP Canny edge detection failed with status {status}\")\n\n return output\n\n# Load input image\nimg = cv2.imread(INPUT_IMAGE)\nif img is None:\n raise FileNotFoundError(f\"Image not found: {INPUT_IMAGE}\")\n\nif not torch.cuda.is_available():\n raise RuntimeError(\"CUDA device not available!\")\n\nprint(f\"Input image size: {img.shape}\")\nprint(f\"Running benchmark... {MEASURE_ITERATIONS} iterations\")\n\ndetector = CannyEdgeDetector()\nresults = []\n\nfor width, height, label in RESOLUTIONS:\n print(f\"\\nProcessing {label}\")\n resized = cv2.resize(img, (width, height))\n img_tensor = torch.from_numpy(resized).cuda().permute(2, 0, 1)\n img_tensor = torchvision.transforms.functional.rgb_to_grayscale(img_tensor).squeeze(0)","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.NppiSize","uri":"program://CUDALibrarySamples/class/NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.NppiSize#L49-L50","kind":"class","name":"NppiSize","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":49,"end_line":50,"context_start_line":29,"context_end_line":70,"code":"OUTPUT_DIR = \"Teapot_resolutions\"\nWARMUP_ITERATIONS = 5\nMEASURE_ITERATIONS = 1000\nTHRESH_WEAK = 72\nTHRESH_STRONG = 256\n\nRESOLUTIONS = [\n (320, 180, \"320x180\"),\n (640, 360, \"640x360\"),\n (800, 600, \"800x600\"),\n (1280, 720, \"1280x720\"),\n (1920, 1080, \"1920x1080\"),\n (2560, 1440, \"2560x1440\"),\n (3840, 2160, \"3840x2160\"),\n (5120, 2880, \"5120x2880\"),\n]\n\nos.makedirs(OUTPUT_DIR, exist_ok=True)\n\nclass CannyEdgeDetector:\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n #npp_path = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.8\\bin\\npp_plus_if64_12.dll\" # for windows user\n #self.npp_lib = ctypes.cdll.LoadLibrary(npp_path)\n self.npp_lib = ctypes.CDLL('libnpp_plus_if.so') # for linux user\n self._setup_functions()\n","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.NppiPoint","uri":"program://CUDALibrarySamples/class/NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.NppiPoint#L52-L53","kind":"class","name":"NppiPoint","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":52,"end_line":53,"context_start_line":32,"context_end_line":73,"code":"THRESH_WEAK = 72\nTHRESH_STRONG = 256\n\nRESOLUTIONS = [\n (320, 180, \"320x180\"),\n (640, 360, \"640x360\"),\n (800, 600, \"800x600\"),\n (1280, 720, \"1280x720\"),\n (1920, 1080, \"1920x1080\"),\n (2560, 1440, \"2560x1440\"),\n (3840, 2160, \"3840x2160\"),\n (5120, 2880, \"5120x2880\"),\n]\n\nos.makedirs(OUTPUT_DIR, exist_ok=True)\n\nclass CannyEdgeDetector:\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n #npp_path = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.8\\bin\\npp_plus_if64_12.dll\" # for windows user\n #self.npp_lib = ctypes.cdll.LoadLibrary(npp_path)\n self.npp_lib = ctypes.CDLL('libnpp_plus_if.so') # for linux user\n self._setup_functions()\n\n def _setup_functions(self):\n self.get_buffer_size = self.npp_lib.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.NppStreamContext","uri":"program://CUDALibrarySamples/class/NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.NppStreamContext#L55-L63","kind":"class","name":"NppStreamContext","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":55,"end_line":63,"context_start_line":35,"context_end_line":83,"code":"RESOLUTIONS = [\n (320, 180, \"320x180\"),\n (640, 360, \"640x360\"),\n (800, 600, \"800x600\"),\n (1280, 720, \"1280x720\"),\n (1920, 1080, \"1920x1080\"),\n (2560, 1440, \"2560x1440\"),\n (3840, 2160, \"3840x2160\"),\n (5120, 2880, \"5120x2880\"),\n]\n\nos.makedirs(OUTPUT_DIR, exist_ok=True)\n\nclass CannyEdgeDetector:\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n #npp_path = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.8\\bin\\npp_plus_if64_12.dll\" # for windows user\n #self.npp_lib = ctypes.cdll.LoadLibrary(npp_path)\n self.npp_lib = ctypes.CDLL('libnpp_plus_if.so') # for linux user\n self._setup_functions()\n\n def _setup_functions(self):\n self.get_buffer_size = self.npp_lib.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [self.NppiSize, POINTER(c_int)]\n\n self.canny_func = self.npp_lib.nppiFilterCannyBorder_8u_C1R_Ctx\n self.canny_func.restype = c_int\n self.canny_func.argtypes = [\n POINTER(c_ubyte), c_int, self.NppiSize, self.NppiPoint,\n POINTER(c_ubyte), c_int, self.NppiSize,\n c_int, c_int, c_int16, c_int16,\n c_int, c_int, c_void_p, self.NppStreamContext\n ]","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.__init__","uri":"program://CUDALibrarySamples/function/NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.__init__#L65-L69","kind":"function","name":"__init__","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":65,"end_line":69,"context_start_line":45,"context_end_line":89,"code":"\nos.makedirs(OUTPUT_DIR, exist_ok=True)\n\nclass CannyEdgeDetector:\n class NppiSize(ctypes.Structure):\n _fields_ = [(\"width\", c_int), (\"height\", c_int)]\n\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n #npp_path = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.8\\bin\\npp_plus_if64_12.dll\" # for windows user\n #self.npp_lib = ctypes.cdll.LoadLibrary(npp_path)\n self.npp_lib = ctypes.CDLL('libnpp_plus_if.so') # for linux user\n self._setup_functions()\n\n def _setup_functions(self):\n self.get_buffer_size = self.npp_lib.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [self.NppiSize, POINTER(c_int)]\n\n self.canny_func = self.npp_lib.nppiFilterCannyBorder_8u_C1R_Ctx\n self.canny_func.restype = c_int\n self.canny_func.argtypes = [\n POINTER(c_ubyte), c_int, self.NppiSize, self.NppiPoint,\n POINTER(c_ubyte), c_int, self.NppiSize,\n c_int, c_int, c_int16, c_int16,\n c_int, c_int, c_void_p, self.NppStreamContext\n ]\n\n def __call__(self, img_tensor, low_thresh, high_thresh):\n if img_tensor.dtype != torch.uint8:\n img_tensor = (img_tensor * 255).byte()\n if not img_tensor.is_cuda:\n img_tensor = img_tensor.cuda()","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP+.cannyEdgeDetectorPython.cannyEdgeDetector._setup_functions","uri":"program://CUDALibrarySamples/function/NPP+.cannyEdgeDetectorPython.cannyEdgeDetector._setup_functions#L71-L83","kind":"function","name":"_setup_functions","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":71,"end_line":83,"context_start_line":51,"context_end_line":103,"code":"\n class NppiPoint(ctypes.Structure):\n _fields_ = [(\"x\", c_int), (\"y\", c_int)]\n\n class NppStreamContext(ctypes.Structure):\n _fields_ = [\n (\"hStream\", c_void_p), (\"nCudaDeviceId\", c_int),\n (\"nMultiProcessorCount\", c_int), (\"nMaxThreadsPerMultiProcessor\", c_int),\n (\"nMaxThreadsPerBlock\", c_int), (\"nSharedMemPerBlock\", c_int),\n (\"nCudaDevAttrComputeCapabilityMajor\", c_int),\n (\"nCudaDevAttrComputeCapabilityMinor\", c_int),\n (\"nStreamFlags\", c_int)\n ]\n\n def __init__(self):\n #npp_path = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.8\\bin\\npp_plus_if64_12.dll\" # for windows user\n #self.npp_lib = ctypes.cdll.LoadLibrary(npp_path)\n self.npp_lib = ctypes.CDLL('libnpp_plus_if.so') # for linux user\n self._setup_functions()\n\n def _setup_functions(self):\n self.get_buffer_size = self.npp_lib.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [self.NppiSize, POINTER(c_int)]\n\n self.canny_func = self.npp_lib.nppiFilterCannyBorder_8u_C1R_Ctx\n self.canny_func.restype = c_int\n self.canny_func.argtypes = [\n POINTER(c_ubyte), c_int, self.NppiSize, self.NppiPoint,\n POINTER(c_ubyte), c_int, self.NppiSize,\n c_int, c_int, c_int16, c_int16,\n c_int, c_int, c_void_p, self.NppStreamContext\n ]\n\n def __call__(self, img_tensor, low_thresh, high_thresh):\n if img_tensor.dtype != torch.uint8:\n img_tensor = (img_tensor * 255).byte()\n if not img_tensor.is_cuda:\n img_tensor = img_tensor.cuda()\n\n h, w = img_tensor.shape\n output = torch.empty_like(img_tensor)\n scratch_size = c_int()\n self.get_buffer_size(self.NppiSize(w, h), ctypes.byref(scratch_size))\n scratch_buffer = torch.empty(scratch_size.value, dtype=torch.uint8, device='cuda')\n\n stream_ctx = self.NppStreamContext()\n stream_ctx.hStream = c_void_p(torch.cuda.current_stream().cuda_stream)\n\n status = self.canny_func(\n ctypes.cast(img_tensor.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte), self.NppiSize(w, h), self.NppiPoint(0, 0),\n ctypes.cast(output.data_ptr(), POINTER(c_ubyte)),","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.__call__","uri":"program://CUDALibrarySamples/function/NPP+.cannyEdgeDetectorPython.cannyEdgeDetector.__call__#L85-L113","kind":"function","name":"__call__","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":85,"end_line":113,"context_start_line":65,"context_end_line":133,"code":" def __init__(self):\n #npp_path = r\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.8\\bin\\npp_plus_if64_12.dll\" # for windows user\n #self.npp_lib = ctypes.cdll.LoadLibrary(npp_path)\n self.npp_lib = ctypes.CDLL('libnpp_plus_if.so') # for linux user\n self._setup_functions()\n\n def _setup_functions(self):\n self.get_buffer_size = self.npp_lib.nppiFilterCannyBorderGetBufferSize\n self.get_buffer_size.restype = c_int\n self.get_buffer_size.argtypes = [self.NppiSize, POINTER(c_int)]\n\n self.canny_func = self.npp_lib.nppiFilterCannyBorder_8u_C1R_Ctx\n self.canny_func.restype = c_int\n self.canny_func.argtypes = [\n POINTER(c_ubyte), c_int, self.NppiSize, self.NppiPoint,\n POINTER(c_ubyte), c_int, self.NppiSize,\n c_int, c_int, c_int16, c_int16,\n c_int, c_int, c_void_p, self.NppStreamContext\n ]\n\n def __call__(self, img_tensor, low_thresh, high_thresh):\n if img_tensor.dtype != torch.uint8:\n img_tensor = (img_tensor * 255).byte()\n if not img_tensor.is_cuda:\n img_tensor = img_tensor.cuda()\n\n h, w = img_tensor.shape\n output = torch.empty_like(img_tensor)\n scratch_size = c_int()\n self.get_buffer_size(self.NppiSize(w, h), ctypes.byref(scratch_size))\n scratch_buffer = torch.empty(scratch_size.value, dtype=torch.uint8, device='cuda')\n\n stream_ctx = self.NppStreamContext()\n stream_ctx.hStream = c_void_p(torch.cuda.current_stream().cuda_stream)\n\n status = self.canny_func(\n ctypes.cast(img_tensor.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte), self.NppiSize(w, h), self.NppiPoint(0, 0),\n ctypes.cast(output.data_ptr(), POINTER(c_ubyte)),\n w * sizeof(c_ubyte), self.NppiSize(w, h),\n 0, 200, c_int16(low_thresh), c_int16(high_thresh),\n 2, 2,\n ctypes.cast(scratch_buffer.data_ptr(), c_void_p), stream_ctx\n )\n\n if status != 0:\n raise RuntimeError(f\"NPP Canny edge detection failed with status {status}\")\n\n return output\n\n# Load input image\nimg = cv2.imread(INPUT_IMAGE)\nif img is None:\n raise FileNotFoundError(f\"Image not found: {INPUT_IMAGE}\")\n\nif not torch.cuda.is_available():\n raise RuntimeError(\"CUDA device not available!\")\n\nprint(f\"Input image size: {img.shape}\")\nprint(f\"Running benchmark... {MEASURE_ITERATIONS} iterations\")\n\ndetector = CannyEdgeDetector()\nresults = []\n\nfor width, height, label in RESOLUTIONS:\n print(f\"\\nProcessing {label}\")\n resized = cv2.resize(img, (width, height))\n img_tensor = torch.from_numpy(resized).cuda().permute(2, 0, 1)\n img_tensor = torchvision.transforms.functional.rgb_to_grayscale(img_tensor).squeeze(0)","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.setup","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.setup#L1-L50","kind":"module","name":"cuTENSOR.python.setup","path":"cuTENSOR/python/setup.py","language":"python","start_line":1,"end_line":50,"context_start_line":1,"context_end_line":50,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nfrom setuptools import setup, find_packages\n\nfrom cutensor.package_info import __version__\nfrom cutensor.package_info import __package_name__\nfrom cutensor.package_info import __homepage__\nfrom cutensor.package_info import __download_url__\nfrom cutensor.package_info import __description__\nfrom cutensor.package_info import __license__\n\nfrom cutensor.c_extensions import CustomExtension\n\nsetup(name=__package_name__,\n version=__version__,\n description=__description__,\n url=__homepage__,\n download_url=__download_url__,\n license=__license__,\n packages=find_packages(),\n ext_modules=CustomExtension.modules)","source_hash":"40da31ad5e62ed57625f64836a01bb5a6e98b0377bb5157c5c91e3f27f44cd00","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.common","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.cutensor.common#L1-L42","kind":"module","name":"cuTENSOR.python.cutensor.common","path":"cuTENSOR/python/cutensor/common.py","language":"python","start_line":1,"end_line":42,"context_start_line":1,"context_end_line":42,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\ndef normalize_subscript(subscript):\n if '->' in subscript:\n subscript = subscript.split('->')\n lhs = subscript[0]\n rhs = subscript[1]\n else:\n lhs = subscript\n rhs = ''.join(sorted([s for s in set(subscript) if s != ',' and subscript.count(s) == 1]))\n if '...' in lhs:\n raise RuntimeError('Elipsis is currently unsupported')\n return lhs + '->' + rhs, ',' in lhs","source_hash":"39de8aec45a7a7eb78b137c1102e2c3c60468c8ff9fe3fe1b5920ea6e46c3995","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.common.normalize_subscript","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.common.normalize_subscript#L32-L42","kind":"function","name":"normalize_subscript","path":"cuTENSOR/python/cutensor/common.py","language":"python","start_line":32,"end_line":42,"context_start_line":12,"context_end_line":42,"code":"# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\ndef normalize_subscript(subscript):\n if '->' in subscript:\n subscript = subscript.split('->')\n lhs = subscript[0]\n rhs = subscript[1]\n else:\n lhs = subscript\n rhs = ''.join(sorted([s for s in set(subscript) if s != ',' and subscript.count(s) == 1]))\n if '...' in lhs:\n raise RuntimeError('Elipsis is currently unsupported')\n return lhs + '->' + rhs, ',' in lhs","source_hash":"39de8aec45a7a7eb78b137c1102e2c3c60468c8ff9fe3fe1b5920ea6e46c3995","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.c_extensions","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.cutensor.c_extensions#L1-L43","kind":"module","name":"cuTENSOR.python.cutensor.c_extensions","path":"cuTENSOR/python/cutensor/c_extensions.py","language":"python","start_line":1,"end_line":43,"context_start_line":1,"context_end_line":43,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nfrom cutensor.c_extensions_utils import CustomExtension\n\neinsum_torch = CustomExtension.Torch('cutensor.torch.binding',\n sources=['cutensor/torch/einsum.cc'])\n\neinsum_tf = CustomExtension.Tensorflow(\n 'cutensor.tensorflow.binding',\n sources=[\n 'cutensor/tensorflow/einsum_kernel.cc',\n 'cutensor/tensorflow/einsum_ops.cc',\n 'cutensor/tensorflow/einsum_module.cc'\n ])","source_hash":"8db515da87f6b15ff4a8c57773c3628cb53e60c4fb6b7b4b4031511e89f26752","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.c_extensions_utils","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.cutensor.c_extensions_utils#L1-L106","kind":"module","name":"cuTENSOR.python.cutensor.c_extensions_utils","path":"cuTENSOR/python/cutensor/c_extensions_utils.py","language":"python","start_line":1,"end_line":106,"context_start_line":1,"context_end_line":106,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nfrom setuptools import Extension\nfrom distutils.spawn import find_executable\nimport os\nimport subprocess\nimport re\n\n__all__ = ['CustomExtension']\n\ninclude_dirs = []\nlibrary_dirs = []\n\ncuda_nvcc = find_executable('nvcc')\ncuda_root = os.path.join(os.path.dirname(cuda_nvcc), os.pardir)\ncuda_version = re.search(\n r'release ([^,]*),',\n subprocess.check_output([cuda_nvcc, '--version']).decode('utf-8')).group(1)\ninclude_dirs.append(os.path.join(cuda_root, 'include'))\nlibrary_dirs.append(os.path.join(cuda_root, 'lib64'))\n\nif 'CUTENSOR_ROOT' in os.environ:\n root = os.environ['CUTENSOR_ROOT']\n include_dirs.append(os.path.join(root, 'include'))\n library_dirs.append(os.path.join(root, 'lib'))\n library_dirs.append(os.path.join(root, 'build/lib'))\n versioned_path = os.path.join(root, 'lib', cuda_version)\n if not os.path.exists(versioned_path):\n versioned_path = os.path.join(root, 'lib', cuda_version.split('.')[0])\n library_dirs.append(versioned_path)\n\n\nclass CustomExtension:\n modules = []\n\n @classmethod\n def Torch(cls, name, sources):\n try:\n import torch\n from torch.utils.cpp_extension import CUDAExtension\n ext = CUDAExtension(name,\n sources=sources,\n libraries=['cutensor'],\n define_macros=[\n ('TORCH_API_INCLUDE_EXTENSION_H',),\n ('TORCH_EXTENSION_NAME',\n name.split('.')[-1]),\n ('_GLIBCXX_USE_CXX11_ABI',\n str(int(torch._C._GLIBCXX_USE_CXX11_ABI)))\n ],\n extra_compile_args=['-std=c++17', '-fopenmp'],\n extra_link_args=['-std=c++17', '-fopenmp'],\n include_dirs=include_dirs,\n library_dirs=library_dirs,\n runtime_library_dirs=library_dirs)\n cls.modules.append(ext)\n return ext\n except ImportError:\n return None\n\n @classmethod\n def Tensorflow(cls, name, sources):\n try:\n import tensorflow as tf\n ext = Extension(name,\n sources=sources,\n libraries=['cutensor', 'cudart'],\n extra_compile_args=tf.sysconfig.get_compile_flags(),\n extra_link_args=tf.sysconfig.get_link_flags() +\n tf.sysconfig.get_compile_flags(),\n define_macros=[('GOOGLE_CUDA', '1')],\n include_dirs=include_dirs,\n library_dirs=library_dirs,\n runtime_library_dirs=library_dirs)\n cls.modules.append(ext)\n except ImportError:\n return None","source_hash":"1a3308912e942fb1c001012f5ace9c67d49ee32e7fad080d516eca679b63f337","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.c_extensions_utils.CustomExtension","uri":"program://CUDALibrarySamples/class/cuTENSOR.python.cutensor.c_extensions_utils.CustomExtension#L62-L106","kind":"class","name":"CustomExtension","path":"cuTENSOR/python/cutensor/c_extensions_utils.py","language":"python","start_line":62,"end_line":106,"context_start_line":42,"context_end_line":106,"code":"\ncuda_nvcc = find_executable('nvcc')\ncuda_root = os.path.join(os.path.dirname(cuda_nvcc), os.pardir)\ncuda_version = re.search(\n r'release ([^,]*),',\n subprocess.check_output([cuda_nvcc, '--version']).decode('utf-8')).group(1)\ninclude_dirs.append(os.path.join(cuda_root, 'include'))\nlibrary_dirs.append(os.path.join(cuda_root, 'lib64'))\n\nif 'CUTENSOR_ROOT' in os.environ:\n root = os.environ['CUTENSOR_ROOT']\n include_dirs.append(os.path.join(root, 'include'))\n library_dirs.append(os.path.join(root, 'lib'))\n library_dirs.append(os.path.join(root, 'build/lib'))\n versioned_path = os.path.join(root, 'lib', cuda_version)\n if not os.path.exists(versioned_path):\n versioned_path = os.path.join(root, 'lib', cuda_version.split('.')[0])\n library_dirs.append(versioned_path)\n\n\nclass CustomExtension:\n modules = []\n\n @classmethod\n def Torch(cls, name, sources):\n try:\n import torch\n from torch.utils.cpp_extension import CUDAExtension\n ext = CUDAExtension(name,\n sources=sources,\n libraries=['cutensor'],\n define_macros=[\n ('TORCH_API_INCLUDE_EXTENSION_H',),\n ('TORCH_EXTENSION_NAME',\n name.split('.')[-1]),\n ('_GLIBCXX_USE_CXX11_ABI',\n str(int(torch._C._GLIBCXX_USE_CXX11_ABI)))\n ],\n extra_compile_args=['-std=c++17', '-fopenmp'],\n extra_link_args=['-std=c++17', '-fopenmp'],\n include_dirs=include_dirs,\n library_dirs=library_dirs,\n runtime_library_dirs=library_dirs)\n cls.modules.append(ext)\n return ext\n except ImportError:\n return None\n\n @classmethod\n def Tensorflow(cls, name, sources):\n try:\n import tensorflow as tf\n ext = Extension(name,\n sources=sources,\n libraries=['cutensor', 'cudart'],\n extra_compile_args=tf.sysconfig.get_compile_flags(),\n extra_link_args=tf.sysconfig.get_link_flags() +\n tf.sysconfig.get_compile_flags(),\n define_macros=[('GOOGLE_CUDA', '1')],\n include_dirs=include_dirs,\n library_dirs=library_dirs,\n runtime_library_dirs=library_dirs)\n cls.modules.append(ext)\n except ImportError:\n return None","source_hash":"1a3308912e942fb1c001012f5ace9c67d49ee32e7fad080d516eca679b63f337","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.c_extensions_utils.Torch","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.c_extensions_utils.Torch#L66-L88","kind":"function","name":"Torch","path":"cuTENSOR/python/cutensor/c_extensions_utils.py","language":"python","start_line":66,"end_line":88,"context_start_line":46,"context_end_line":106,"code":" r'release ([^,]*),',\n subprocess.check_output([cuda_nvcc, '--version']).decode('utf-8')).group(1)\ninclude_dirs.append(os.path.join(cuda_root, 'include'))\nlibrary_dirs.append(os.path.join(cuda_root, 'lib64'))\n\nif 'CUTENSOR_ROOT' in os.environ:\n root = os.environ['CUTENSOR_ROOT']\n include_dirs.append(os.path.join(root, 'include'))\n library_dirs.append(os.path.join(root, 'lib'))\n library_dirs.append(os.path.join(root, 'build/lib'))\n versioned_path = os.path.join(root, 'lib', cuda_version)\n if not os.path.exists(versioned_path):\n versioned_path = os.path.join(root, 'lib', cuda_version.split('.')[0])\n library_dirs.append(versioned_path)\n\n\nclass CustomExtension:\n modules = []\n\n @classmethod\n def Torch(cls, name, sources):\n try:\n import torch\n from torch.utils.cpp_extension import CUDAExtension\n ext = CUDAExtension(name,\n sources=sources,\n libraries=['cutensor'],\n define_macros=[\n ('TORCH_API_INCLUDE_EXTENSION_H',),\n ('TORCH_EXTENSION_NAME',\n name.split('.')[-1]),\n ('_GLIBCXX_USE_CXX11_ABI',\n str(int(torch._C._GLIBCXX_USE_CXX11_ABI)))\n ],\n extra_compile_args=['-std=c++17', '-fopenmp'],\n extra_link_args=['-std=c++17', '-fopenmp'],\n include_dirs=include_dirs,\n library_dirs=library_dirs,\n runtime_library_dirs=library_dirs)\n cls.modules.append(ext)\n return ext\n except ImportError:\n return None\n\n @classmethod\n def Tensorflow(cls, name, sources):\n try:\n import tensorflow as tf\n ext = Extension(name,\n sources=sources,\n libraries=['cutensor', 'cudart'],\n extra_compile_args=tf.sysconfig.get_compile_flags(),\n extra_link_args=tf.sysconfig.get_link_flags() +\n tf.sysconfig.get_compile_flags(),\n define_macros=[('GOOGLE_CUDA', '1')],\n include_dirs=include_dirs,\n library_dirs=library_dirs,\n runtime_library_dirs=library_dirs)\n cls.modules.append(ext)\n except ImportError:\n return None","source_hash":"1a3308912e942fb1c001012f5ace9c67d49ee32e7fad080d516eca679b63f337","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.c_extensions_utils.Tensorflow","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.c_extensions_utils.Tensorflow#L91-L106","kind":"function","name":"Tensorflow","path":"cuTENSOR/python/cutensor/c_extensions_utils.py","language":"python","start_line":91,"end_line":106,"context_start_line":71,"context_end_line":106,"code":" sources=sources,\n libraries=['cutensor'],\n define_macros=[\n ('TORCH_API_INCLUDE_EXTENSION_H',),\n ('TORCH_EXTENSION_NAME',\n name.split('.')[-1]),\n ('_GLIBCXX_USE_CXX11_ABI',\n str(int(torch._C._GLIBCXX_USE_CXX11_ABI)))\n ],\n extra_compile_args=['-std=c++17', '-fopenmp'],\n extra_link_args=['-std=c++17', '-fopenmp'],\n include_dirs=include_dirs,\n library_dirs=library_dirs,\n runtime_library_dirs=library_dirs)\n cls.modules.append(ext)\n return ext\n except ImportError:\n return None\n\n @classmethod\n def Tensorflow(cls, name, sources):\n try:\n import tensorflow as tf\n ext = Extension(name,\n sources=sources,\n libraries=['cutensor', 'cudart'],\n extra_compile_args=tf.sysconfig.get_compile_flags(),\n extra_link_args=tf.sysconfig.get_link_flags() +\n tf.sysconfig.get_compile_flags(),\n define_macros=[('GOOGLE_CUDA', '1')],\n include_dirs=include_dirs,\n library_dirs=library_dirs,\n runtime_library_dirs=library_dirs)\n cls.modules.append(ext)\n except ImportError:\n return None","source_hash":"1a3308912e942fb1c001012f5ace9c67d49ee32e7fad080d516eca679b63f337","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.package_info","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.cutensor.package_info#L1-L44","kind":"module","name":"cuTENSOR.python.cutensor.package_info","path":"cuTENSOR/python/cutensor/package_info.py","language":"python","start_line":1,"end_line":44,"context_start_line":1,"context_end_line":44,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nMAJOR = 0\nMINOR = 1\nPATCH = 0\n\nVERSION = (MAJOR, MINOR, PATCH)\n\n__version__ = '.'.join(map(str, VERSION))\n\n__package_name__ = 'cutensor-python'\n__description__ = 'PyTorch and Tensorflow Python bindings for cuTENSOR',\n__homepage__ = 'https://developer.nvidia.com/cutensor',\n__download_url__ = 'https://github.com/NVIDIA/CUDALibrarySamples/tree/master/cuTENSOR/cutensor',\n__license__ = 'BSD'","source_hash":"7d2fb8fe25e907d639b06b534620fd5ac2fe4b1bbe8543faef8000c1d08fdc62","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum_test","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.cutensor.torch.einsum_test#L1-L249","kind":"module","name":"cuTENSOR.python.cutensor.torch.einsum_test","path":"cuTENSOR/python/cutensor/torch/einsum_test.py","language":"python","start_line":1,"end_line":249,"context_start_line":1,"context_end_line":249,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nimport torch\n\nimport unittest\nfrom parameterized import parameterized\nfrom parameterized import param\n\nimport cutensor.torch as cutensor\n\n\nclass EinsumTest(unittest.TestCase):\n\n\n def setUp(self):\n torch.backends.cuda.matmul.allow_tf32 = False\n\n\n def assertClose(self, cutensor_tensor, torch_tensor):\n self.assertEqual(cutensor_tensor.shape, torch_tensor.shape)\n self.assertEqual(torch.is_complex(cutensor_tensor), torch.is_complex(torch_tensor))\n if torch.is_complex(cutensor_tensor):\n self.assertClose(torch.real(cutensor_tensor), torch.real(torch_tensor))\n self.assertClose(torch.imag(cutensor_tensor), torch.imag(torch_tensor))\n else:\n torch.testing.assert_close(cutensor_tensor, torch_tensor, rtol=5e-3, atol=6e-3)\n \n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n a_size=(48, 37),\n b_size=(37, 74),\n equation=\"ik,kj->ij\",\n dtype=torch.float32,\n ),\n param(\n \"test 0 (complex)\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=torch.complex64,\n ),\n param(\n \"test 1\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=torch.complex128,\n ),\n param(\n \"test 2\",\n a_size=(50, 50, 50, 20),\n b_size=(50, 50, 50, 20),\n equation=\"likm,lkjm->lij\",\n dtype=torch.float32,\n ),\n param(\n \"test 3\",\n a_size=(20, 50, 50, 50),\n b_size=(50, 50, 50, 20),\n equation=\"mlik,lkjm->lij\",\n dtype=torch.float32,\n ),\n param(\n \"test 4\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=torch.float16,\n ),\n param(\"test 5\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=torch.float16),\n param(\n \"test 6\",\n a_size=(50, 50, 50, 20),\n b_size=(50, 50, 50, 20),\n equation=\"likm,lkjm->lij\",\n dtype=torch.float16,\n ),\n param(\n \"test 7\",\n a_size=(20, 50, 50, 50),\n b_size=(50, 50, 50, 20),\n equation=\"mlik,lkjm->lij\",\n dtype=torch.float16,\n ),\n param(\n \"test 8\",\n a_size=(2, 5, 50, 2),\n b_size=(5, 2, 50, 2),\n equation=\"mlik,lkjm\",\n dtype=torch.float64,\n ),\n # Activate when cuTENSOR supports it\n # param(\n # \"test 8\",\n # a_size=(20, 50, 50, 50),\n # b_size=(50, 50, 50, 20),\n # equation=\"mlik,lkjm->lij\",\n # dtype=torch.bfloat16,\n # ),\n ]\n # yapf: enable\n )\n def test_einsum_equivalent_results(self,\n _,\n a_size,\n b_size,\n equation,\n dtype=torch.float32):\n\n\n kwargs = {\n 'dtype': dtype,\n 'device': torch.device(\"cuda\"),\n 'requires_grad': True\n }\n\n torch.manual_seed(0)\n\n cutensor_A = torch.randn(*a_size, **kwargs)\n cutensor_B = torch.randn(*b_size, **kwargs)\n cutensor_rslt = cutensor.EinsumFunction.apply(equation, cutensor_A,\n cutensor_B)\n cutensor_rslt.backward(torch.ones_like(cutensor_rslt))\n cutensor_rslt = cutensor_rslt\n cutensor_A_grad = cutensor_A.grad\n cutensor_B_grad = cutensor_B.grad\n\n torch_A = cutensor_A.clone().detach().requires_grad_(True)\n torch_B = cutensor_B.clone().detach().requires_grad_(True)\n torch_rslt = torch.einsum(equation, torch_A, torch_B)\n torch_rslt.backward(torch.ones_like(torch_rslt))\n torch_A_grad = torch_A.grad\n torch_B_grad = torch_B.grad\n\n self.assertClose(cutensor_rslt, torch_rslt)\n self.assertClose(cutensor_A_grad, torch_A_grad)\n self.assertClose(cutensor_B_grad, torch_B_grad)\n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n sizes=[(50, 60), (60, 40)],\n equation=\"ik,kj->ji\",\n dtype=torch.float32,\n ),\n param(\n \"test 1\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj->ij\",\n dtype=torch.float32,\n ),\n param(\n \"test 2\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj\",\n dtype=torch.float32,\n ),\n param(\n \"test 3\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj->ij\",\n dtype=torch.complex64,\n ),\n # single input currently not supported\n param(\n \"test 4\",\n sizes=[(50, 60)],\n equation=\"ij->ji\",\n dtype=torch.float32,\n ),\n ]\n # yapf: enable\n )\n def test_einsum_general_equivalent_results(self,\n _,\n sizes,\n equation,\n dtype=torch.float32):\n\n kwargs = {\n 'dtype': dtype,\n 'device': torch.device(\"cuda\"),\n 'requires_grad': True\n }\n\n cutensor_tensors = [torch.randn(*size, **kwargs) for size in sizes]\n torch_tensors = [\n t.clone().detach().requires_grad_(True) for t in cutensor_tensors\n ]\n\n cutensor_rslt = cutensor.EinsumGeneral(equation, *cutensor_tensors)\n cutensor_rslt.backward(torch.ones_like(cutensor_rslt))\n cutensor_rslt = cutensor_rslt\n cutensor_grads = [\n t.grad for t in cutensor_tensors\n ]\n\n torch_rslt = torch.einsum(equation, *torch_tensors)\n torch_rslt.backward(torch.ones_like(torch_rslt))\n torch_rslt = torch_rslt\n torch_grads = [t.grad for t in torch_tensors]\n\n\n self.assertClose(cutensor_rslt, torch_rslt)\n for ct, tt in zip(cutensor_grads, torch_grads):\n self.assertClose(ct, tt)\n\n\nif __name__ == '__main__':\n unittest.main()","source_hash":"62eb53281ef757a7f0c88017e6fe41e49825ceb7a9bce5ad720479e04a629cf9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum_test.EinsumTest","uri":"program://CUDALibrarySamples/class/cuTENSOR.python.cutensor.torch.einsum_test.EinsumTest#L41-L245","kind":"class","name":"EinsumTest","path":"cuTENSOR/python/cutensor/torch/einsum_test.py","language":"python","start_line":41,"end_line":245,"context_start_line":21,"context_end_line":249,"code":"# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nimport torch\n\nimport unittest\nfrom parameterized import parameterized\nfrom parameterized import param\n\nimport cutensor.torch as cutensor\n\n\nclass EinsumTest(unittest.TestCase):\n\n\n def setUp(self):\n torch.backends.cuda.matmul.allow_tf32 = False\n\n\n def assertClose(self, cutensor_tensor, torch_tensor):\n self.assertEqual(cutensor_tensor.shape, torch_tensor.shape)\n self.assertEqual(torch.is_complex(cutensor_tensor), torch.is_complex(torch_tensor))\n if torch.is_complex(cutensor_tensor):\n self.assertClose(torch.real(cutensor_tensor), torch.real(torch_tensor))\n self.assertClose(torch.imag(cutensor_tensor), torch.imag(torch_tensor))\n else:\n torch.testing.assert_close(cutensor_tensor, torch_tensor, rtol=5e-3, atol=6e-3)\n \n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n a_size=(48, 37),\n b_size=(37, 74),\n equation=\"ik,kj->ij\",\n dtype=torch.float32,\n ),\n param(\n \"test 0 (complex)\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=torch.complex64,\n ),\n param(\n \"test 1\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=torch.complex128,\n ),\n param(\n \"test 2\",\n a_size=(50, 50, 50, 20),\n b_size=(50, 50, 50, 20),\n equation=\"likm,lkjm->lij\",\n dtype=torch.float32,\n ),\n param(\n \"test 3\",\n a_size=(20, 50, 50, 50),\n b_size=(50, 50, 50, 20),\n equation=\"mlik,lkjm->lij\",\n dtype=torch.float32,\n ),\n param(\n \"test 4\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=torch.float16,\n ),\n param(\"test 5\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=torch.float16),\n param(\n \"test 6\",\n a_size=(50, 50, 50, 20),\n b_size=(50, 50, 50, 20),\n equation=\"likm,lkjm->lij\",\n dtype=torch.float16,\n ),\n param(\n \"test 7\",\n a_size=(20, 50, 50, 50),\n b_size=(50, 50, 50, 20),\n equation=\"mlik,lkjm->lij\",\n dtype=torch.float16,\n ),\n param(\n \"test 8\",\n a_size=(2, 5, 50, 2),\n b_size=(5, 2, 50, 2),\n equation=\"mlik,lkjm\",\n dtype=torch.float64,\n ),\n # Activate when cuTENSOR supports it\n # param(\n # \"test 8\",\n # a_size=(20, 50, 50, 50),\n # b_size=(50, 50, 50, 20),\n # equation=\"mlik,lkjm->lij\",\n # dtype=torch.bfloat16,\n # ),\n ]\n # yapf: enable\n )\n def test_einsum_equivalent_results(self,\n _,\n a_size,\n b_size,\n equation,\n dtype=torch.float32):\n\n\n kwargs = {\n 'dtype': dtype,\n 'device': torch.device(\"cuda\"),\n 'requires_grad': True\n }\n\n torch.manual_seed(0)\n\n cutensor_A = torch.randn(*a_size, **kwargs)\n cutensor_B = torch.randn(*b_size, **kwargs)\n cutensor_rslt = cutensor.EinsumFunction.apply(equation, cutensor_A,\n cutensor_B)\n cutensor_rslt.backward(torch.ones_like(cutensor_rslt))\n cutensor_rslt = cutensor_rslt\n cutensor_A_grad = cutensor_A.grad\n cutensor_B_grad = cutensor_B.grad\n\n torch_A = cutensor_A.clone().detach().requires_grad_(True)\n torch_B = cutensor_B.clone().detach().requires_grad_(True)\n torch_rslt = torch.einsum(equation, torch_A, torch_B)\n torch_rslt.backward(torch.ones_like(torch_rslt))\n torch_A_grad = torch_A.grad\n torch_B_grad = torch_B.grad\n\n self.assertClose(cutensor_rslt, torch_rslt)\n self.assertClose(cutensor_A_grad, torch_A_grad)\n self.assertClose(cutensor_B_grad, torch_B_grad)\n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n sizes=[(50, 60), (60, 40)],\n equation=\"ik,kj->ji\",\n dtype=torch.float32,\n ),\n param(\n \"test 1\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj->ij\",\n dtype=torch.float32,\n ),\n param(\n \"test 2\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj\",\n dtype=torch.float32,\n ),\n param(\n \"test 3\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj->ij\",\n dtype=torch.complex64,\n ),\n # single input currently not supported\n param(\n \"test 4\",\n sizes=[(50, 60)],\n equation=\"ij->ji\",\n dtype=torch.float32,\n ),\n ]\n # yapf: enable\n )\n def test_einsum_general_equivalent_results(self,\n _,\n sizes,\n equation,\n dtype=torch.float32):\n\n kwargs = {\n 'dtype': dtype,\n 'device': torch.device(\"cuda\"),\n 'requires_grad': True\n }\n\n cutensor_tensors = [torch.randn(*size, **kwargs) for size in sizes]\n torch_tensors = [\n t.clone().detach().requires_grad_(True) for t in cutensor_tensors\n ]\n\n cutensor_rslt = cutensor.EinsumGeneral(equation, *cutensor_tensors)\n cutensor_rslt.backward(torch.ones_like(cutensor_rslt))\n cutensor_rslt = cutensor_rslt\n cutensor_grads = [\n t.grad for t in cutensor_tensors\n ]\n\n torch_rslt = torch.einsum(equation, *torch_tensors)\n torch_rslt.backward(torch.ones_like(torch_rslt))\n torch_rslt = torch_rslt\n torch_grads = [t.grad for t in torch_tensors]\n\n\n self.assertClose(cutensor_rslt, torch_rslt)\n for ct, tt in zip(cutensor_grads, torch_grads):\n self.assertClose(ct, tt)\n\n\nif __name__ == '__main__':\n unittest.main()","source_hash":"62eb53281ef757a7f0c88017e6fe41e49825ceb7a9bce5ad720479e04a629cf9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum_test.setUp","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum_test.setUp#L44-L45","kind":"function","name":"setUp","path":"cuTENSOR/python/cutensor/torch/einsum_test.py","language":"python","start_line":44,"end_line":45,"context_start_line":24,"context_end_line":65,"code":"# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nimport torch\n\nimport unittest\nfrom parameterized import parameterized\nfrom parameterized import param\n\nimport cutensor.torch as cutensor\n\n\nclass EinsumTest(unittest.TestCase):\n\n\n def setUp(self):\n torch.backends.cuda.matmul.allow_tf32 = False\n\n\n def assertClose(self, cutensor_tensor, torch_tensor):\n self.assertEqual(cutensor_tensor.shape, torch_tensor.shape)\n self.assertEqual(torch.is_complex(cutensor_tensor), torch.is_complex(torch_tensor))\n if torch.is_complex(cutensor_tensor):\n self.assertClose(torch.real(cutensor_tensor), torch.real(torch_tensor))\n self.assertClose(torch.imag(cutensor_tensor), torch.imag(torch_tensor))\n else:\n torch.testing.assert_close(cutensor_tensor, torch_tensor, rtol=5e-3, atol=6e-3)\n \n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n a_size=(48, 37),\n b_size=(37, 74),\n equation=\"ik,kj->ij\",","source_hash":"62eb53281ef757a7f0c88017e6fe41e49825ceb7a9bce5ad720479e04a629cf9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum_test.assertClose","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum_test.assertClose#L48-L55","kind":"function","name":"assertClose","path":"cuTENSOR/python/cutensor/torch/einsum_test.py","language":"python","start_line":48,"end_line":55,"context_start_line":28,"context_end_line":75,"code":"# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nimport torch\n\nimport unittest\nfrom parameterized import parameterized\nfrom parameterized import param\n\nimport cutensor.torch as cutensor\n\n\nclass EinsumTest(unittest.TestCase):\n\n\n def setUp(self):\n torch.backends.cuda.matmul.allow_tf32 = False\n\n\n def assertClose(self, cutensor_tensor, torch_tensor):\n self.assertEqual(cutensor_tensor.shape, torch_tensor.shape)\n self.assertEqual(torch.is_complex(cutensor_tensor), torch.is_complex(torch_tensor))\n if torch.is_complex(cutensor_tensor):\n self.assertClose(torch.real(cutensor_tensor), torch.real(torch_tensor))\n self.assertClose(torch.imag(cutensor_tensor), torch.imag(torch_tensor))\n else:\n torch.testing.assert_close(cutensor_tensor, torch_tensor, rtol=5e-3, atol=6e-3)\n \n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n a_size=(48, 37),\n b_size=(37, 74),\n equation=\"ik,kj->ij\",\n dtype=torch.float32,\n ),\n param(\n \"test 0 (complex)\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=torch.complex64,\n ),\n param(","source_hash":"62eb53281ef757a7f0c88017e6fe41e49825ceb7a9bce5ad720479e04a629cf9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum_test.test_einsum_equivalent_results","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum_test.test_einsum_equivalent_results#L140-L174","kind":"function","name":"test_einsum_equivalent_results","path":"cuTENSOR/python/cutensor/torch/einsum_test.py","language":"python","start_line":140,"end_line":174,"context_start_line":120,"context_end_line":194,"code":" dtype=torch.float16,\n ),\n param(\n \"test 8\",\n a_size=(2, 5, 50, 2),\n b_size=(5, 2, 50, 2),\n equation=\"mlik,lkjm\",\n dtype=torch.float64,\n ),\n # Activate when cuTENSOR supports it\n # param(\n # \"test 8\",\n # a_size=(20, 50, 50, 50),\n # b_size=(50, 50, 50, 20),\n # equation=\"mlik,lkjm->lij\",\n # dtype=torch.bfloat16,\n # ),\n ]\n # yapf: enable\n )\n def test_einsum_equivalent_results(self,\n _,\n a_size,\n b_size,\n equation,\n dtype=torch.float32):\n\n\n kwargs = {\n 'dtype': dtype,\n 'device': torch.device(\"cuda\"),\n 'requires_grad': True\n }\n\n torch.manual_seed(0)\n\n cutensor_A = torch.randn(*a_size, **kwargs)\n cutensor_B = torch.randn(*b_size, **kwargs)\n cutensor_rslt = cutensor.EinsumFunction.apply(equation, cutensor_A,\n cutensor_B)\n cutensor_rslt.backward(torch.ones_like(cutensor_rslt))\n cutensor_rslt = cutensor_rslt\n cutensor_A_grad = cutensor_A.grad\n cutensor_B_grad = cutensor_B.grad\n\n torch_A = cutensor_A.clone().detach().requires_grad_(True)\n torch_B = cutensor_B.clone().detach().requires_grad_(True)\n torch_rslt = torch.einsum(equation, torch_A, torch_B)\n torch_rslt.backward(torch.ones_like(torch_rslt))\n torch_A_grad = torch_A.grad\n torch_B_grad = torch_B.grad\n\n self.assertClose(cutensor_rslt, torch_rslt)\n self.assertClose(cutensor_A_grad, torch_A_grad)\n self.assertClose(cutensor_B_grad, torch_B_grad)\n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n sizes=[(50, 60), (60, 40)],\n equation=\"ik,kj->ji\",\n dtype=torch.float32,\n ),\n param(\n \"test 1\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj->ij\",\n dtype=torch.float32,\n ),\n param(\n \"test 2\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj\",","source_hash":"62eb53281ef757a7f0c88017e6fe41e49825ceb7a9bce5ad720479e04a629cf9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum_test.test_einsum_general_equivalent_results","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum_test.test_einsum_general_equivalent_results#L213-L245","kind":"function","name":"test_einsum_general_equivalent_results","path":"cuTENSOR/python/cutensor/torch/einsum_test.py","language":"python","start_line":213,"end_line":245,"context_start_line":193,"context_end_line":249,"code":" sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj\",\n dtype=torch.float32,\n ),\n param(\n \"test 3\",\n sizes=[(50, 60), (60, 7), (7, 8)],\n equation=\"ik,kl,lj->ij\",\n dtype=torch.complex64,\n ),\n # single input currently not supported\n param(\n \"test 4\",\n sizes=[(50, 60)],\n equation=\"ij->ji\",\n dtype=torch.float32,\n ),\n ]\n # yapf: enable\n )\n def test_einsum_general_equivalent_results(self,\n _,\n sizes,\n equation,\n dtype=torch.float32):\n\n kwargs = {\n 'dtype': dtype,\n 'device': torch.device(\"cuda\"),\n 'requires_grad': True\n }\n\n cutensor_tensors = [torch.randn(*size, **kwargs) for size in sizes]\n torch_tensors = [\n t.clone().detach().requires_grad_(True) for t in cutensor_tensors\n ]\n\n cutensor_rslt = cutensor.EinsumGeneral(equation, *cutensor_tensors)\n cutensor_rslt.backward(torch.ones_like(cutensor_rslt))\n cutensor_rslt = cutensor_rslt\n cutensor_grads = [\n t.grad for t in cutensor_tensors\n ]\n\n torch_rslt = torch.einsum(equation, *torch_tensors)\n torch_rslt.backward(torch.ones_like(torch_rslt))\n torch_rslt = torch_rslt\n torch_grads = [t.grad for t in torch_tensors]\n\n\n self.assertClose(cutensor_rslt, torch_rslt)\n for ct, tt in zip(cutensor_grads, torch_grads):\n self.assertClose(ct, tt)\n\n\nif __name__ == '__main__':\n unittest.main()","source_hash":"62eb53281ef757a7f0c88017e6fe41e49825ceb7a9bce5ad720479e04a629cf9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.cutensor.torch.einsum#L1-L170","kind":"module","name":"cuTENSOR.python.cutensor.torch.einsum","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":1,"end_line":170,"context_start_line":1,"context_end_line":170,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nimport torch\nimport torch.autograd\nimport numpy as np\nfrom .binding import einsum, plan, execute\nfrom ..common import normalize_subscript\n\nclass EinsumFunction(torch.autograd.Function):\n\n @staticmethod\n def forward(ctx, equation, input_0, input_1=None):\n equation, isBinary = normalize_subscript(equation)\n if isBinary and input_1 is None:\n raise RuntimeError('The subscript indicates two inputs, but only one was passed')\n if not isBinary and input_1 is not None:\n raise RuntimeError('The subscript indicates one input, but two were passed')\n if input_1 is None:\n input_1 = input_0.new_empty((1,))\n\n output = einsum(equation, input_0, input_1, False, False)\n\n if isBinary:\n ctx.save_for_backward(input_0, input_1)\n\n ctx.equation = equation\n ctx.isBinary = isBinary\n\n return output\n\n @staticmethod\n def backward(ctx, grad_output):\n equation = ctx.equation\n lhs, modeC = equation.split('->')\n if ctx.isBinary:\n input_0, input_1 = ctx.saved_tensors\n conjugate = False\n if torch.is_complex(input_0) or torch.is_complex(input_1):\n conjugate = True\n modeA, modeB = lhs.split(',')\n d_input_0 = einsum(modeC + ',' + modeB + '->' + modeA, grad_output,\n input_1, False, conjugate)\n d_input_1 = einsum(modeA + ',' + modeC + '->' + modeB, input_0,\n grad_output, conjugate, False)\n return None, d_input_0, d_input_1\n else:\n dummy = grad_output.new_empty((1,))\n d_input = einsum(modeC + '->' + lhs, grad_output, dummy, False, False)\n return None, d_input\n\n\n def plan(equation, input_0, input_1=None, jit_pref=False):\n equation, isBinary = normalize_subscript(equation)\n if isBinary and input_1 is None:\n raise RuntimeError('The subscript indicates two inputs, but only one was passed')\n if not isBinary and input_1 is not None:\n raise RuntimeError('The subscript indicates one input, but two were passed')\n if input_1 is None:\n input_1 = input_0.new_empty((1,))\n\n output = plan(equation, input_0, input_1, False, False, jit_pref)\n\n return output\n \n\n def execute(plan):\n try:\n result = execute(plan)\n if result is None: # Handle NULL return\n raise RuntimeError(\"cuTENSOR execute returned NULL (CUTENSOR_STATUS_INVALID_VALUE)\")\n return result\n except SystemError as e:\n raise RuntimeError(f\"cuTENSOR execution failed {e}\")\n\n\nclass Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m\n # reorder target modes like target\n result = list(result)\n for i in range(len(result)):\n if result[i] not in target: continue\n for j in range(i):\n if result[j] not in target: continue\n if target.index(result[j]) > target.index(result[i]):\n result[i], result[j] = result[j], result[i]\n return ''.join(result)\n\n\ndef EinsumGeneral(equation, *tensors, **kwargs):\n tensors = list(tensors)\n equation, isBinary = normalize_subscript(equation)\n path = np.einsum_path(equation,\n *[np.broadcast_to(np.nan, t.shape) for t in tensors],\n **kwargs)\n path = path[0][1:]\n equation = equation.split('->')\n eqs = equation[0].split(',')\n target = equation[1]\n for step in path:\n if len(step) == 1:\n result = EinsumFunction.apply(eqs[0] + '->' + target, tensors[0])\n continue\n assert step[0] < step[1]\n in0 = tensors[step[0]]\n in1 = tensors[step[1]]\n tensors.pop(step[1])\n tensors.pop(step[0])\n tgt = _compute_target_tensor(eqs[step[0]], eqs[step[1]], target, [eq for idx, eq in enumerate(eqs) if idx not in step])\n assert tgt != \"\"\n eq = eqs[step[0]] + ',' + eqs[step[1]] + '->' + tgt\n eqs.pop(step[1])\n eqs.pop(step[0])\n eqs.append(tgt)\n result = EinsumFunction.apply(eq, in0, in1)\n tensors.append(result)\n return result\n ","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.EinsumFunction","uri":"program://CUDALibrarySamples/class/cuTENSOR.python.cutensor.torch.einsum.EinsumFunction#L38-L102","kind":"class","name":"EinsumFunction","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":38,"end_line":102,"context_start_line":18,"context_end_line":122,"code":"#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nimport torch\nimport torch.autograd\nimport numpy as np\nfrom .binding import einsum, plan, execute\nfrom ..common import normalize_subscript\n\nclass EinsumFunction(torch.autograd.Function):\n\n @staticmethod\n def forward(ctx, equation, input_0, input_1=None):\n equation, isBinary = normalize_subscript(equation)\n if isBinary and input_1 is None:\n raise RuntimeError('The subscript indicates two inputs, but only one was passed')\n if not isBinary and input_1 is not None:\n raise RuntimeError('The subscript indicates one input, but two were passed')\n if input_1 is None:\n input_1 = input_0.new_empty((1,))\n\n output = einsum(equation, input_0, input_1, False, False)\n\n if isBinary:\n ctx.save_for_backward(input_0, input_1)\n\n ctx.equation = equation\n ctx.isBinary = isBinary\n\n return output\n\n @staticmethod\n def backward(ctx, grad_output):\n equation = ctx.equation\n lhs, modeC = equation.split('->')\n if ctx.isBinary:\n input_0, input_1 = ctx.saved_tensors\n conjugate = False\n if torch.is_complex(input_0) or torch.is_complex(input_1):\n conjugate = True\n modeA, modeB = lhs.split(',')\n d_input_0 = einsum(modeC + ',' + modeB + '->' + modeA, grad_output,\n input_1, False, conjugate)\n d_input_1 = einsum(modeA + ',' + modeC + '->' + modeB, input_0,\n grad_output, conjugate, False)\n return None, d_input_0, d_input_1\n else:\n dummy = grad_output.new_empty((1,))\n d_input = einsum(modeC + '->' + lhs, grad_output, dummy, False, False)\n return None, d_input\n\n\n def plan(equation, input_0, input_1=None, jit_pref=False):\n equation, isBinary = normalize_subscript(equation)\n if isBinary and input_1 is None:\n raise RuntimeError('The subscript indicates two inputs, but only one was passed')\n if not isBinary and input_1 is not None:\n raise RuntimeError('The subscript indicates one input, but two were passed')\n if input_1 is None:\n input_1 = input_0.new_empty((1,))\n\n output = plan(equation, input_0, input_1, False, False, jit_pref)\n\n return output\n \n\n def execute(plan):\n try:\n result = execute(plan)\n if result is None: # Handle NULL return\n raise RuntimeError(\"cuTENSOR execute returned NULL (CUTENSOR_STATUS_INVALID_VALUE)\")\n return result\n except SystemError as e:\n raise RuntimeError(f\"cuTENSOR execution failed {e}\")\n\n\nclass Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.Einsum","uri":"program://CUDALibrarySamples/class/cuTENSOR.python.cutensor.torch.einsum.Einsum#L105-L122","kind":"class","name":"Einsum","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":105,"end_line":122,"context_start_line":85,"context_end_line":142,"code":" if not isBinary and input_1 is not None:\n raise RuntimeError('The subscript indicates one input, but two were passed')\n if input_1 is None:\n input_1 = input_0.new_empty((1,))\n\n output = plan(equation, input_0, input_1, False, False, jit_pref)\n\n return output\n \n\n def execute(plan):\n try:\n result = execute(plan)\n if result is None: # Handle NULL return\n raise RuntimeError(\"cuTENSOR execute returned NULL (CUTENSOR_STATUS_INVALID_VALUE)\")\n return result\n except SystemError as e:\n raise RuntimeError(f\"cuTENSOR execution failed {e}\")\n\n\nclass Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m\n # reorder target modes like target\n result = list(result)\n for i in range(len(result)):\n if result[i] not in target: continue\n for j in range(i):\n if result[j] not in target: continue\n if target.index(result[j]) > target.index(result[i]):\n result[i], result[j] = result[j], result[i]\n return ''.join(result)\n\n\ndef EinsumGeneral(equation, *tensors, **kwargs):","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum._compute_target_tensor","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum._compute_target_tensor#L125-L139","kind":"function","name":"_compute_target_tensor","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":125,"end_line":139,"context_start_line":105,"context_end_line":159,"code":"class Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m\n # reorder target modes like target\n result = list(result)\n for i in range(len(result)):\n if result[i] not in target: continue\n for j in range(i):\n if result[j] not in target: continue\n if target.index(result[j]) > target.index(result[i]):\n result[i], result[j] = result[j], result[i]\n return ''.join(result)\n\n\ndef EinsumGeneral(equation, *tensors, **kwargs):\n tensors = list(tensors)\n equation, isBinary = normalize_subscript(equation)\n path = np.einsum_path(equation,\n *[np.broadcast_to(np.nan, t.shape) for t in tensors],\n **kwargs)\n path = path[0][1:]\n equation = equation.split('->')\n eqs = equation[0].split(',')\n target = equation[1]\n for step in path:\n if len(step) == 1:\n result = EinsumFunction.apply(eqs[0] + '->' + target, tensors[0])\n continue\n assert step[0] < step[1]\n in0 = tensors[step[0]]\n in1 = tensors[step[1]]\n tensors.pop(step[1])","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.EinsumGeneral","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum.EinsumGeneral#L142-L169","kind":"function","name":"EinsumGeneral","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":142,"end_line":169,"context_start_line":122,"context_end_line":170,"code":" return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m\n # reorder target modes like target\n result = list(result)\n for i in range(len(result)):\n if result[i] not in target: continue\n for j in range(i):\n if result[j] not in target: continue\n if target.index(result[j]) > target.index(result[i]):\n result[i], result[j] = result[j], result[i]\n return ''.join(result)\n\n\ndef EinsumGeneral(equation, *tensors, **kwargs):\n tensors = list(tensors)\n equation, isBinary = normalize_subscript(equation)\n path = np.einsum_path(equation,\n *[np.broadcast_to(np.nan, t.shape) for t in tensors],\n **kwargs)\n path = path[0][1:]\n equation = equation.split('->')\n eqs = equation[0].split(',')\n target = equation[1]\n for step in path:\n if len(step) == 1:\n result = EinsumFunction.apply(eqs[0] + '->' + target, tensors[0])\n continue\n assert step[0] < step[1]\n in0 = tensors[step[0]]\n in1 = tensors[step[1]]\n tensors.pop(step[1])\n tensors.pop(step[0])\n tgt = _compute_target_tensor(eqs[step[0]], eqs[step[1]], target, [eq for idx, eq in enumerate(eqs) if idx not in step])\n assert tgt != \"\"\n eq = eqs[step[0]] + ',' + eqs[step[1]] + '->' + tgt\n eqs.pop(step[1])\n eqs.pop(step[0])\n eqs.append(tgt)\n result = EinsumFunction.apply(eq, in0, in1)\n tensors.append(result)\n return result\n ","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.forward","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum.forward#L115-L116","kind":"function","name":"forward","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":115,"end_line":116,"context_start_line":95,"context_end_line":136,"code":" def execute(plan):\n try:\n result = execute(plan)\n if result is None: # Handle NULL return\n raise RuntimeError(\"cuTENSOR execute returned NULL (CUTENSOR_STATUS_INVALID_VALUE)\")\n return result\n except SystemError as e:\n raise RuntimeError(f\"cuTENSOR execution failed {e}\")\n\n\nclass Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m\n # reorder target modes like target\n result = list(result)\n for i in range(len(result)):\n if result[i] not in target: continue\n for j in range(i):\n if result[j] not in target: continue","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.backward","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum.backward#L61-L78","kind":"function","name":"backward","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":61,"end_line":78,"context_start_line":41,"context_end_line":98,"code":" def forward(ctx, equation, input_0, input_1=None):\n equation, isBinary = normalize_subscript(equation)\n if isBinary and input_1 is None:\n raise RuntimeError('The subscript indicates two inputs, but only one was passed')\n if not isBinary and input_1 is not None:\n raise RuntimeError('The subscript indicates one input, but two were passed')\n if input_1 is None:\n input_1 = input_0.new_empty((1,))\n\n output = einsum(equation, input_0, input_1, False, False)\n\n if isBinary:\n ctx.save_for_backward(input_0, input_1)\n\n ctx.equation = equation\n ctx.isBinary = isBinary\n\n return output\n\n @staticmethod\n def backward(ctx, grad_output):\n equation = ctx.equation\n lhs, modeC = equation.split('->')\n if ctx.isBinary:\n input_0, input_1 = ctx.saved_tensors\n conjugate = False\n if torch.is_complex(input_0) or torch.is_complex(input_1):\n conjugate = True\n modeA, modeB = lhs.split(',')\n d_input_0 = einsum(modeC + ',' + modeB + '->' + modeA, grad_output,\n input_1, False, conjugate)\n d_input_1 = einsum(modeA + ',' + modeC + '->' + modeB, input_0,\n grad_output, conjugate, False)\n return None, d_input_0, d_input_1\n else:\n dummy = grad_output.new_empty((1,))\n d_input = einsum(modeC + '->' + lhs, grad_output, dummy, False, False)\n return None, d_input\n\n\n def plan(equation, input_0, input_1=None, jit_pref=False):\n equation, isBinary = normalize_subscript(equation)\n if isBinary and input_1 is None:\n raise RuntimeError('The subscript indicates two inputs, but only one was passed')\n if not isBinary and input_1 is not None:\n raise RuntimeError('The subscript indicates one input, but two were passed')\n if input_1 is None:\n input_1 = input_0.new_empty((1,))\n\n output = plan(equation, input_0, input_1, False, False, jit_pref)\n\n return output\n \n\n def execute(plan):\n try:\n result = execute(plan)\n if result is None: # Handle NULL return","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.plan","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum.plan#L118-L119","kind":"function","name":"plan","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":118,"end_line":119,"context_start_line":98,"context_end_line":139,"code":" if result is None: # Handle NULL return\n raise RuntimeError(\"cuTENSOR execute returned NULL (CUTENSOR_STATUS_INVALID_VALUE)\")\n return result\n except SystemError as e:\n raise RuntimeError(f\"cuTENSOR execution failed {e}\")\n\n\nclass Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m\n # reorder target modes like target\n result = list(result)\n for i in range(len(result)):\n if result[i] not in target: continue\n for j in range(i):\n if result[j] not in target: continue\n if target.index(result[j]) > target.index(result[i]):\n result[i], result[j] = result[j], result[i]\n return ''.join(result)","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.execute","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum.execute#L121-L122","kind":"function","name":"execute","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":121,"end_line":122,"context_start_line":101,"context_end_line":142,"code":" except SystemError as e:\n raise RuntimeError(f\"cuTENSOR execution failed {e}\")\n\n\nclass Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m\n # reorder target modes like target\n result = list(result)\n for i in range(len(result)):\n if result[i] not in target: continue\n for j in range(i):\n if result[j] not in target: continue\n if target.index(result[j]) > target.index(result[i]):\n result[i], result[j] = result[j], result[i]\n return ''.join(result)\n\n\ndef EinsumGeneral(equation, *tensors, **kwargs):","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.__init__","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum.__init__#L107-L110","kind":"function","name":"__init__","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":107,"end_line":110,"context_start_line":87,"context_end_line":130,"code":" if input_1 is None:\n input_1 = input_0.new_empty((1,))\n\n output = plan(equation, input_0, input_1, False, False, jit_pref)\n\n return output\n \n\n def execute(plan):\n try:\n result = execute(plan)\n if result is None: # Handle NULL return\n raise RuntimeError(\"cuTENSOR execute returned NULL (CUTENSOR_STATUS_INVALID_VALUE)\")\n return result\n except SystemError as e:\n raise RuntimeError(f\"cuTENSOR execution failed {e}\")\n\n\nclass Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.torch.einsum.reset_parameters","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.torch.einsum.reset_parameters#L112-L113","kind":"function","name":"reset_parameters","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":112,"end_line":113,"context_start_line":92,"context_end_line":133,"code":" return output\n \n\n def execute(plan):\n try:\n result = execute(plan)\n if result is None: # Handle NULL return\n raise RuntimeError(\"cuTENSOR execute returned NULL (CUTENSOR_STATUS_INVALID_VALUE)\")\n return result\n except SystemError as e:\n raise RuntimeError(f\"cuTENSOR execution failed {e}\")\n\n\nclass Einsum(torch.nn.Module):\n\n def __init__(self, equation):\n super(Einsum, self).__init__()\n self.equation = equation\n self.reset_parameters()\n\n def reset_parameters(self):\n pass\n\n def forward(self, input_0, input_1):\n return EinsumFunction.apply(self.equation, input_0, input_1)\n \n def plan(self, input_0, input_1, jit_pref=False):\n return EinsumFunction.plan(self.equation, input_0, input_1=input_1, jit_pref=jit_pref)\n\n def execute(self, plan):\n return EinsumFunction.execute(plan)\n\n\ndef _compute_target_tensor(in0, in1, target, rest):\n result = \"\"\n rest = ''.join(rest) + target\n for m in in0[:-1] + in1[:-1] + in1[-1] + in0[-1]:\n if m in rest and not m in result:\n result += m\n # reorder target modes like target\n result = list(result)\n for i in range(len(result)):","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.tensorflow.einsum_test","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.cutensor.tensorflow.einsum_test#L1-L193","kind":"module","name":"cuTENSOR.python.cutensor.tensorflow.einsum_test","path":"cuTENSOR/python/cutensor/tensorflow/einsum_test.py","language":"python","start_line":1,"end_line":193,"context_start_line":1,"context_end_line":193,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nfrom parameterized import parameterized\nfrom parameterized import param\n\nimport tensorflow as tf\nfrom tensorflow.python.platform import test\nimport tensorflow.test\n\nimport cutensor.tensorflow as cutensor\n\ntf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n\n\nclass EinsumcuTENSORTest(tensorflow.test.TestCase):\n\n def setUp(self):\n super().setUp()\n tf.config.experimental.enable_tensor_float_32_execution(False)\n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=tf.float32,\n ),\n param(\n \"test 1\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=tf.float32,\n ),\n param(\n \"test 2\",\n a_size=(50, 50, 50, 20),\n b_size=(50, 50, 50, 20),\n equation=\"likm,lkjm->lij\",\n dtype=tf.float32,\n ),\n param(\n \"test 3\",\n a_size=(20, 50, 50, 50),\n b_size=(50, 50, 50, 20),\n equation=\"mlik,lkjm->lij\",\n dtype=tf.float32,\n ),\n param(\n \"test 4\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=tf.float16,\n ),\n param(\"test 5\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=tf.float16),\n param(\n \"test 6\",\n a_size=(50, 50, 50, 20),\n b_size=(50, 50, 50, 20),\n equation=\"likm,lkjm->lij\",\n dtype=tf.float16,\n ),\n param(\n \"test 7\",\n a_size=(20, 50, 50, 50),\n b_size=(50, 50, 50, 20),\n equation=\"mlik,lkjm->lij\",\n dtype=tf.float16,\n ),\n param(\n \"test 8\",\n a_size=(2, 5, 5, 5),\n b_size=(5, 5, 5, 2),\n equation=\"mlik,lkjm\",\n dtype=tf.float16,\n ),\n param(\n \"test 9\",\n a_size=(20, 50, 50, 50),\n b_size=None,\n equation=\"mlik->imlk\",\n dtype=tf.float16,\n ),\n # Activate when cuTENSOR supports it\n # param(\n # \"test 8\",\n # a_size=(20, 50, 50, 50),\n # b_size=(50, 50, 50, 20),\n # equation=\"mlik,lkjm->lij\",\n # dtype=tf.bfloat16,\n # ),\n ]\n # yapf: enable\n )\n def test_einsum_equivalent_results(self,\n _,\n a_size,\n b_size,\n equation,\n dtype=tf.float32):\n A = tf.random.normal(a_size, dtype=dtype)\n\n\n if b_size is not None:\n B = tf.random.normal(b_size, dtype=dtype)\n\n with tf.GradientTape() as tape:\n tape.watch([A, B])\n tf_native_rslt = tf.einsum(equation, A, B, name=\"tf_native_einsum\")\n\n tf_native_grads = tape.gradient(tf_native_rslt, [A, B])\n\n with tf.GradientTape() as tape:\n tape.watch([A, B])\n tf_cutensor_rslt = cutensor.einsum(equation,\n A,\n B,\n name=\"tf_cuTensor_einsum\")\n \n tf_cutensor_grads = tape.gradient(tf_cutensor_rslt, [A, B])\n else:\n with tf.GradientTape() as tape:\n tape.watch([A])\n tf_native_rslt = tf.einsum(equation, A, name=\"tf_native_einsum\")\n\n tf_native_grads = tape.gradient(tf_native_rslt, [A])\n\n with tf.GradientTape() as tape:\n tape.watch([A])\n tf_cutensor_rslt = cutensor.einsum(equation,\n A,\n name=\"tf_cuTensor_einsum\")\n tf_cutensor_grads = tape.gradient(tf_cutensor_rslt, [A])\n\n self.assertEqual(tf_native_rslt.get_shape(),\n tf_cutensor_rslt.get_shape())\n\n self.assertEqual(tf_native_rslt.dtype, tf_cutensor_rslt.dtype)\n self.assertEqual(len(tf_cutensor_grads), len(tf_native_grads))\n\n self.assertAllClose(tf_native_rslt,\n tf_cutensor_rslt,\n rtol=5e-03,\n atol=5e-03)\n\n for tf_native_grad, tf_cutensor_grad in zip(tf_native_grads,\n tf_cutensor_grads):\n self.assertAllClose(tf_native_grad,\n tf_cutensor_grad,\n rtol=5e-03,\n atol=5e-03)\n self.assertEqual(tf_native_grad.dtype, tf_cutensor_grad.dtype)\n\n\nif __name__ == '__main__':\n test.main()","source_hash":"ca094c2d398702551844cced82d278fc1b53129ea3755fd0ceb0ff4ce267ab9c","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.tensorflow.einsum_test.EinsumcuTENSORTest","uri":"program://CUDALibrarySamples/class/cuTENSOR.python.cutensor.tensorflow.einsum_test.EinsumcuTENSORTest#L44-L189","kind":"class","name":"EinsumcuTENSORTest","path":"cuTENSOR/python/cutensor/tensorflow/einsum_test.py","language":"python","start_line":44,"end_line":189,"context_start_line":24,"context_end_line":193,"code":"# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nfrom parameterized import parameterized\nfrom parameterized import param\n\nimport tensorflow as tf\nfrom tensorflow.python.platform import test\nimport tensorflow.test\n\nimport cutensor.tensorflow as cutensor\n\ntf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n\n\nclass EinsumcuTENSORTest(tensorflow.test.TestCase):\n\n def setUp(self):\n super().setUp()\n tf.config.experimental.enable_tensor_float_32_execution(False)\n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=tf.float32,\n ),\n param(\n \"test 1\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=tf.float32,\n ),\n param(\n \"test 2\",\n a_size=(50, 50, 50, 20),\n b_size=(50, 50, 50, 20),\n equation=\"likm,lkjm->lij\",\n dtype=tf.float32,\n ),\n param(\n \"test 3\",\n a_size=(20, 50, 50, 50),\n b_size=(50, 50, 50, 20),\n equation=\"mlik,lkjm->lij\",\n dtype=tf.float32,\n ),\n param(\n \"test 4\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=tf.float16,\n ),\n param(\"test 5\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=tf.float16),\n param(\n \"test 6\",\n a_size=(50, 50, 50, 20),\n b_size=(50, 50, 50, 20),\n equation=\"likm,lkjm->lij\",\n dtype=tf.float16,\n ),\n param(\n \"test 7\",\n a_size=(20, 50, 50, 50),\n b_size=(50, 50, 50, 20),\n equation=\"mlik,lkjm->lij\",\n dtype=tf.float16,\n ),\n param(\n \"test 8\",\n a_size=(2, 5, 5, 5),\n b_size=(5, 5, 5, 2),\n equation=\"mlik,lkjm\",\n dtype=tf.float16,\n ),\n param(\n \"test 9\",\n a_size=(20, 50, 50, 50),\n b_size=None,\n equation=\"mlik->imlk\",\n dtype=tf.float16,\n ),\n # Activate when cuTENSOR supports it\n # param(\n # \"test 8\",\n # a_size=(20, 50, 50, 50),\n # b_size=(50, 50, 50, 20),\n # equation=\"mlik,lkjm->lij\",\n # dtype=tf.bfloat16,\n # ),\n ]\n # yapf: enable\n )\n def test_einsum_equivalent_results(self,\n _,\n a_size,\n b_size,\n equation,\n dtype=tf.float32):\n A = tf.random.normal(a_size, dtype=dtype)\n\n\n if b_size is not None:\n B = tf.random.normal(b_size, dtype=dtype)\n\n with tf.GradientTape() as tape:\n tape.watch([A, B])\n tf_native_rslt = tf.einsum(equation, A, B, name=\"tf_native_einsum\")\n\n tf_native_grads = tape.gradient(tf_native_rslt, [A, B])\n\n with tf.GradientTape() as tape:\n tape.watch([A, B])\n tf_cutensor_rslt = cutensor.einsum(equation,\n A,\n B,\n name=\"tf_cuTensor_einsum\")\n \n tf_cutensor_grads = tape.gradient(tf_cutensor_rslt, [A, B])\n else:\n with tf.GradientTape() as tape:\n tape.watch([A])\n tf_native_rslt = tf.einsum(equation, A, name=\"tf_native_einsum\")\n\n tf_native_grads = tape.gradient(tf_native_rslt, [A])\n\n with tf.GradientTape() as tape:\n tape.watch([A])\n tf_cutensor_rslt = cutensor.einsum(equation,\n A,\n name=\"tf_cuTensor_einsum\")\n tf_cutensor_grads = tape.gradient(tf_cutensor_rslt, [A])\n\n self.assertEqual(tf_native_rslt.get_shape(),\n tf_cutensor_rslt.get_shape())\n\n self.assertEqual(tf_native_rslt.dtype, tf_cutensor_rslt.dtype)\n self.assertEqual(len(tf_cutensor_grads), len(tf_native_grads))\n\n self.assertAllClose(tf_native_rslt,\n tf_cutensor_rslt,\n rtol=5e-03,\n atol=5e-03)\n\n for tf_native_grad, tf_cutensor_grad in zip(tf_native_grads,\n tf_cutensor_grads):\n self.assertAllClose(tf_native_grad,\n tf_cutensor_grad,\n rtol=5e-03,\n atol=5e-03)\n self.assertEqual(tf_native_grad.dtype, tf_cutensor_grad.dtype)\n\n\nif __name__ == '__main__':\n test.main()","source_hash":"ca094c2d398702551844cced82d278fc1b53129ea3755fd0ceb0ff4ce267ab9c","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.tensorflow.einsum_test.setUp","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.tensorflow.einsum_test.setUp#L46-L48","kind":"function","name":"setUp","path":"cuTENSOR/python/cutensor/tensorflow/einsum_test.py","language":"python","start_line":46,"end_line":48,"context_start_line":26,"context_end_line":68,"code":"# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nfrom parameterized import parameterized\nfrom parameterized import param\n\nimport tensorflow as tf\nfrom tensorflow.python.platform import test\nimport tensorflow.test\n\nimport cutensor.tensorflow as cutensor\n\ntf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n\n\nclass EinsumcuTENSORTest(tensorflow.test.TestCase):\n\n def setUp(self):\n super().setUp()\n tf.config.experimental.enable_tensor_float_32_execution(False)\n\n @parameterized.expand(\n # yapf: disable\n [\n param(\n \"test 0\",\n a_size=(50, 50),\n b_size=(50, 50),\n equation=\"ik,kj->ij\",\n dtype=tf.float32,\n ),\n param(\n \"test 1\",\n a_size=(50, 50, 50),\n b_size=(50, 50, 50),\n equation=\"lik,lkj->lij\",\n dtype=tf.float32,\n ),\n param(\n \"test 2\",","source_hash":"ca094c2d398702551844cced82d278fc1b53129ea3755fd0ceb0ff4ce267ab9c","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.tensorflow.einsum_test.test_einsum_equivalent_results","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.tensorflow.einsum_test.test_einsum_equivalent_results#L132-L189","kind":"function","name":"test_einsum_equivalent_results","path":"cuTENSOR/python/cutensor/tensorflow/einsum_test.py","language":"python","start_line":132,"end_line":189,"context_start_line":112,"context_end_line":193,"code":" dtype=tf.float16,\n ),\n param(\n \"test 9\",\n a_size=(20, 50, 50, 50),\n b_size=None,\n equation=\"mlik->imlk\",\n dtype=tf.float16,\n ),\n # Activate when cuTENSOR supports it\n # param(\n # \"test 8\",\n # a_size=(20, 50, 50, 50),\n # b_size=(50, 50, 50, 20),\n # equation=\"mlik,lkjm->lij\",\n # dtype=tf.bfloat16,\n # ),\n ]\n # yapf: enable\n )\n def test_einsum_equivalent_results(self,\n _,\n a_size,\n b_size,\n equation,\n dtype=tf.float32):\n A = tf.random.normal(a_size, dtype=dtype)\n\n\n if b_size is not None:\n B = tf.random.normal(b_size, dtype=dtype)\n\n with tf.GradientTape() as tape:\n tape.watch([A, B])\n tf_native_rslt = tf.einsum(equation, A, B, name=\"tf_native_einsum\")\n\n tf_native_grads = tape.gradient(tf_native_rslt, [A, B])\n\n with tf.GradientTape() as tape:\n tape.watch([A, B])\n tf_cutensor_rslt = cutensor.einsum(equation,\n A,\n B,\n name=\"tf_cuTensor_einsum\")\n \n tf_cutensor_grads = tape.gradient(tf_cutensor_rslt, [A, B])\n else:\n with tf.GradientTape() as tape:\n tape.watch([A])\n tf_native_rslt = tf.einsum(equation, A, name=\"tf_native_einsum\")\n\n tf_native_grads = tape.gradient(tf_native_rslt, [A])\n\n with tf.GradientTape() as tape:\n tape.watch([A])\n tf_cutensor_rslt = cutensor.einsum(equation,\n A,\n name=\"tf_cuTensor_einsum\")\n tf_cutensor_grads = tape.gradient(tf_cutensor_rslt, [A])\n\n self.assertEqual(tf_native_rslt.get_shape(),\n tf_cutensor_rslt.get_shape())\n\n self.assertEqual(tf_native_rslt.dtype, tf_cutensor_rslt.dtype)\n self.assertEqual(len(tf_cutensor_grads), len(tf_native_grads))\n\n self.assertAllClose(tf_native_rslt,\n tf_cutensor_rslt,\n rtol=5e-03,\n atol=5e-03)\n\n for tf_native_grad, tf_cutensor_grad in zip(tf_native_grads,\n tf_cutensor_grads):\n self.assertAllClose(tf_native_grad,\n tf_cutensor_grad,\n rtol=5e-03,\n atol=5e-03)\n self.assertEqual(tf_native_grad.dtype, tf_cutensor_grad.dtype)\n\n\nif __name__ == '__main__':\n test.main()","source_hash":"ca094c2d398702551844cced82d278fc1b53129ea3755fd0ceb0ff4ce267ab9c","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.tensorflow.einsum","uri":"program://CUDALibrarySamples/module/cuTENSOR.python.cutensor.tensorflow.einsum#L1-L124","kind":"module","name":"cuTENSOR.python.cutensor.tensorflow.einsum","path":"cuTENSOR/python/cutensor/tensorflow/einsum.py","language":"python","start_line":1,"end_line":124,"context_start_line":1,"context_end_line":124,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nimport tensorflow as tf\nfrom tensorflow.python.framework import ops\nfrom tensorflow.python.ops import math_ops\nfrom tensorflow.python.ops import special_math_ops\nfrom tensorflow.python.framework.load_library import load_op_library\n\nfrom ..common import normalize_subscript\n\nimport glob\nimport os\npattern = os.path.join(os.path.dirname(__file__), 'binding*.so')\nglob_res = glob.glob(pattern)\nbinding_file, = glob_res\neinsum_lib = tf.load_op_library(binding_file)\n\n\ndef einsum(equation, *inputs, **kwargs):\n name = kwargs.pop('name', None)\n\n if kwargs:\n raise TypeError(\n 'invalid keyword arguments for this function: ' +\n ', '.join([format(key) for key in sorted(list(kwargs.keys()))]))\n\n with ops.name_scope(name, 'einsum', [equation, inputs]):\n inputs = list(inputs)\n\n input_shapes = [x.get_shape() for x in inputs]\n input_axis_labels, output_axis_labels = special_math_ops._einsum_v1_parse_and_resolve_equation(\n equation, input_shapes)\n\n axis_labels = set(''.join(input_axis_labels) + output_axis_labels)\n\n for a in axis_labels:\n for input_labels in input_axis_labels:\n if (len(input_axis_labels) == 1 and\n input_labels.count(a) == 2 and\n input_labels == input_labels[::-1] and\n '->' not in equation):\n return math_ops.trace(inputs[0])\n if input_labels.count(a) > 1:\n raise ValueError(\n 'Subscript not supported: an axis appears more than once: %s'\n % input_labels)\n\n for a in axis_labels:\n\n input_count = sum(1 for s in input_axis_labels if a in s)\n\n if input_count > 2 and a not in output_axis_labels:\n tf.compat.v1.logging.warn(\n 'Falling back to exponential-space implementation of einsum()'\n ' because index \"%s\" is summed over more than two inputs.',\n a)\n return special_math_ops._exponential_space_einsum(\n equation, *inputs)\n\n equation = ','.join(input_axis_labels) + '->' + output_axis_labels\n if len(inputs) == 1:\n # inputs.append(inputs[0])\n inputs.append(tf.constant([0], dtype=inputs[0].dtype))\n return einsum_lib.einsum_cu_tensor(input_0=inputs[0],\n input_1=inputs[1],\n equation=equation)\n\n\n@ops.RegisterGradient(\"EinsumCuTensor\")\ndef _einsum_cu_tensor_grad(op, grad):\n A = op.inputs[0]\n B = op.inputs[1]\n\n subscript, _ = normalize_subscript(op.get_attr(\"equation\").decode())\n lhs, modeC = subscript.split('->')\n if ',' in lhs:\n modeA, modeB = lhs.split(',')\n\n grad_A = einsum_lib.einsum_cu_tensor(input_0=grad,\n input_1=B,\n equation=modeC + ',' + modeB + '->' +\n modeA)\n\n grad_B = einsum_lib.einsum_cu_tensor(input_0=A,\n input_1=grad,\n equation=modeA + ',' + modeC + '->' +\n modeB)\n\n return [grad_A, grad_B]\n else:\n grad = einsum_lib.einsum_cu_tensor(input_0=grad,\n input_1=B,\n equation=modeC + '->' + lhs)\n return [grad, B]\n","source_hash":"2dcc95e346f39b8fcadd6ff4acbeff17ef74e0919e634ed7968a4e4edaf34bff","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.tensorflow.einsum.einsum","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.tensorflow.einsum.einsum#L48-L95","kind":"function","name":"einsum","path":"cuTENSOR/python/cutensor/tensorflow/einsum.py","language":"python","start_line":48,"end_line":95,"context_start_line":28,"context_end_line":115,"code":"# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n#\n\nimport tensorflow as tf\nfrom tensorflow.python.framework import ops\nfrom tensorflow.python.ops import math_ops\nfrom tensorflow.python.ops import special_math_ops\nfrom tensorflow.python.framework.load_library import load_op_library\n\nfrom ..common import normalize_subscript\n\nimport glob\nimport os\npattern = os.path.join(os.path.dirname(__file__), 'binding*.so')\nglob_res = glob.glob(pattern)\nbinding_file, = glob_res\neinsum_lib = tf.load_op_library(binding_file)\n\n\ndef einsum(equation, *inputs, **kwargs):\n name = kwargs.pop('name', None)\n\n if kwargs:\n raise TypeError(\n 'invalid keyword arguments for this function: ' +\n ', '.join([format(key) for key in sorted(list(kwargs.keys()))]))\n\n with ops.name_scope(name, 'einsum', [equation, inputs]):\n inputs = list(inputs)\n\n input_shapes = [x.get_shape() for x in inputs]\n input_axis_labels, output_axis_labels = special_math_ops._einsum_v1_parse_and_resolve_equation(\n equation, input_shapes)\n\n axis_labels = set(''.join(input_axis_labels) + output_axis_labels)\n\n for a in axis_labels:\n for input_labels in input_axis_labels:\n if (len(input_axis_labels) == 1 and\n input_labels.count(a) == 2 and\n input_labels == input_labels[::-1] and\n '->' not in equation):\n return math_ops.trace(inputs[0])\n if input_labels.count(a) > 1:\n raise ValueError(\n 'Subscript not supported: an axis appears more than once: %s'\n % input_labels)\n\n for a in axis_labels:\n\n input_count = sum(1 for s in input_axis_labels if a in s)\n\n if input_count > 2 and a not in output_axis_labels:\n tf.compat.v1.logging.warn(\n 'Falling back to exponential-space implementation of einsum()'\n ' because index \"%s\" is summed over more than two inputs.',\n a)\n return special_math_ops._exponential_space_einsum(\n equation, *inputs)\n\n equation = ','.join(input_axis_labels) + '->' + output_axis_labels\n if len(inputs) == 1:\n # inputs.append(inputs[0])\n inputs.append(tf.constant([0], dtype=inputs[0].dtype))\n return einsum_lib.einsum_cu_tensor(input_0=inputs[0],\n input_1=inputs[1],\n equation=equation)\n\n\n@ops.RegisterGradient(\"EinsumCuTensor\")\ndef _einsum_cu_tensor_grad(op, grad):\n A = op.inputs[0]\n B = op.inputs[1]\n\n subscript, _ = normalize_subscript(op.get_attr(\"equation\").decode())\n lhs, modeC = subscript.split('->')\n if ',' in lhs:\n modeA, modeB = lhs.split(',')\n\n grad_A = einsum_lib.einsum_cu_tensor(input_0=grad,\n input_1=B,\n equation=modeC + ',' + modeB + '->' +\n modeA)\n\n grad_B = einsum_lib.einsum_cu_tensor(input_0=A,\n input_1=grad,\n equation=modeA + ',' + modeC + '->' +","source_hash":"2dcc95e346f39b8fcadd6ff4acbeff17ef74e0919e634ed7968a4e4edaf34bff","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuTENSOR.python.cutensor.tensorflow.einsum._einsum_cu_tensor_grad","uri":"program://CUDALibrarySamples/function/cuTENSOR.python.cutensor.tensorflow.einsum._einsum_cu_tensor_grad#L99-L123","kind":"function","name":"_einsum_cu_tensor_grad","path":"cuTENSOR/python/cutensor/tensorflow/einsum.py","language":"python","start_line":99,"end_line":123,"context_start_line":79,"context_end_line":124,"code":" input_count = sum(1 for s in input_axis_labels if a in s)\n\n if input_count > 2 and a not in output_axis_labels:\n tf.compat.v1.logging.warn(\n 'Falling back to exponential-space implementation of einsum()'\n ' because index \"%s\" is summed over more than two inputs.',\n a)\n return special_math_ops._exponential_space_einsum(\n equation, *inputs)\n\n equation = ','.join(input_axis_labels) + '->' + output_axis_labels\n if len(inputs) == 1:\n # inputs.append(inputs[0])\n inputs.append(tf.constant([0], dtype=inputs[0].dtype))\n return einsum_lib.einsum_cu_tensor(input_0=inputs[0],\n input_1=inputs[1],\n equation=equation)\n\n\n@ops.RegisterGradient(\"EinsumCuTensor\")\ndef _einsum_cu_tensor_grad(op, grad):\n A = op.inputs[0]\n B = op.inputs[1]\n\n subscript, _ = normalize_subscript(op.get_attr(\"equation\").decode())\n lhs, modeC = subscript.split('->')\n if ',' in lhs:\n modeA, modeB = lhs.split(',')\n\n grad_A = einsum_lib.einsum_cu_tensor(input_0=grad,\n input_1=B,\n equation=modeC + ',' + modeB + '->' +\n modeA)\n\n grad_B = einsum_lib.einsum_cu_tensor(input_0=A,\n input_1=grad,\n equation=modeA + ',' + modeC + '->' +\n modeB)\n\n return [grad_A, grad_B]\n else:\n grad = einsum_lib.einsum_cu_tensor(input_0=grad,\n input_1=B,\n equation=modeC + '->' + lhs)\n return [grad, B]\n","source_hash":"2dcc95e346f39b8fcadd6ff4acbeff17ef74e0919e634ed7968a4e4edaf34bff","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvCOMP.benchmarks.text_to_binary","uri":"program://CUDALibrarySamples/module/nvCOMP.benchmarks.text_to_binary#L1-L108","kind":"module","name":"nvCOMP.benchmarks.text_to_binary","path":"nvCOMP/benchmarks/text_to_binary.py","language":"python","start_line":1,"end_line":108,"context_start_line":1,"context_end_line":108,"code":"#!/usr/bin/env python3\n\n# SPDX-FileCopyrightText: Copyright (c) 2018-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport sys\nimport struct\nimport argparse\nimport numpy\nimport warnings\n\ndelimiter = ','\n\ndef fixInput(val):\n if val is None:\n return 0\n try:\n retval = int(val)\n except ValueError:\n retval = ord(val)\n\n return retval\n\n\nif len(sys.argv) != 5 and len(sys.argv) != 6:\n print(\"Usage:\")\n print(\"\\tcsv_to_binary.py [delimiter]\")\n print()\n print(\"This program converts one column of a text file containing a table of data,\")\n print(\"(a comma-separated values file by default), into a binary file.\")\n print()\n print(\"The should be an integer in the range [0, N-1], where N is the number of columns.\")\n print(\"The option should be one of 'int', 'long', 'float', 'double', or 'string'.\")\n print(\"'string' keeps the text, converting it to UTF-16 with no separators between the values.\")\n print(\"The [delimiter] is an optional argument, and defaults to '%s'\" % delimiter)\n print(\"Some delimiters may need to be surrounded by quotation marks or prefixed by a backslash, depending on\")\n print(\"the shell, for example space, semicolon, or vertical pipe, due to the command line parsing\")\n print(\"interpreting the space or semicolon as a parameter separator or command separator, instead of a\")\n print(\"parameter to this script.\")\n print()\n print(\"Examples:\")\n print(\" text_to_binary.py ExampleFloatData.csv 2 float ZValues.bin\")\n print(\" text_to_binary.py ExampleTable.txt 5 long Dates.bin '|'\")\n print(\" text_to_binary.py SpaceSeparatedData.txt 0 int FirstColumn.bin ' '\")\n print()\n exit()\n\nin_fname = sys.argv[1]\ncol_num = sys.argv[2]\ndatatype = sys.argv[3]\nout_fname = sys.argv[4]\n\nif len(sys.argv) == 6:\n delimiter = sys.argv[5]\n\n# Add more datatypes if needed\nif datatype == \"int\":\n dtype = \"int32\"\nelif datatype == \"long\":\n dtype = \"int64\"\nelif datatype == \"float\":\n dtype = \"float32\"\nelif datatype == \"double\":\n dtype = \"float64\"\nelif datatype == \"string\":\n dtype = \"str\"\nelse:\n print(\"Please select datatype int, long, float, double, or string\")\n exit()\n\n\nprint(\"Reading column \" + col_num + \", of type \" + datatype + \"...\")\n\nchunk_size = 10000000\nfinished = False\noffset = 0\nwith open(str(in_fname), \"r\") as inFile:\n with open(str(out_fname), \"wb\") as newFile:\n with warnings.catch_warnings():\n while not finished:\n in_data=numpy.genfromtxt(inFile, dtype=dtype,\n max_rows=chunk_size, usecols=(int(col_num),), delimiter=delimiter, loose=False)\n\n if offset == 0:\n # don't warn about an empty file after we have read something\n warnings.filterwarnings('ignore', r'genfromtxt: Empty input file:')\n\n if in_data.size > 0:\n in_data.tofile(newFile)\n offset += in_data.size\n else:\n finished = True\nif offset != 0:\n print('Wrote '+str(offset)+' '+datatype+'s to '+str(out_fname))\nelse:\n print('Wrote no data')","source_hash":"5601fd2b155cd156149175e706737741adf81e7643e979541c6432893becc0d7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:nvCOMP.benchmarks.text_to_binary.fixInput","uri":"program://CUDALibrarySamples/function/nvCOMP.benchmarks.text_to_binary.fixInput#L26-L34","kind":"function","name":"fixInput","path":"nvCOMP/benchmarks/text_to_binary.py","language":"python","start_line":26,"end_line":34,"context_start_line":6,"context_end_line":54,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport sys\nimport struct\nimport argparse\nimport numpy\nimport warnings\n\ndelimiter = ','\n\ndef fixInput(val):\n if val is None:\n return 0\n try:\n retval = int(val)\n except ValueError:\n retval = ord(val)\n\n return retval\n\n\nif len(sys.argv) != 5 and len(sys.argv) != 6:\n print(\"Usage:\")\n print(\"\\tcsv_to_binary.py [delimiter]\")\n print()\n print(\"This program converts one column of a text file containing a table of data,\")\n print(\"(a comma-separated values file by default), into a binary file.\")\n print()\n print(\"The should be an integer in the range [0, N-1], where N is the number of columns.\")\n print(\"The option should be one of 'int', 'long', 'float', 'double', or 'string'.\")\n print(\"'string' keeps the text, converting it to UTF-16 with no separators between the values.\")\n print(\"The [delimiter] is an optional argument, and defaults to '%s'\" % delimiter)\n print(\"Some delimiters may need to be surrounded by quotation marks or prefixed by a backslash, depending on\")\n print(\"the shell, for example space, semicolon, or vertical pipe, due to the command line parsing\")\n print(\"interpreting the space or semicolon as a parameter separator or command separator, instead of a\")\n print(\"parameter to this script.\")\n print()\n print(\"Examples:\")\n print(\" text_to_binary.py ExampleFloatData.csv 2 float ZValues.bin\")","source_hash":"5601fd2b155cd156149175e706737741adf81e7643e979541c6432893becc0d7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.setup","uri":"program://CUDALibrarySamples/module/cuFFTMp.JAX_FFT.setup#L1-L115","kind":"module","name":"cuFFTMp.JAX_FFT.setup","path":"cuFFTMp/JAX_FFT/setup.py","language":"python","start_line":1,"end_line":115,"context_start_line":1,"context_end_line":115,"code":"#!/usr/bin/env python\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nimport codecs\nimport os\nimport subprocess\nimport sys\nimport distutils.sysconfig\nimport pybind11\n\nfrom setuptools import Extension, find_packages, setup\nfrom setuptools.command.build_ext import build_ext\n\nHERE = os.path.dirname(os.path.realpath(__file__))\n\ndef read(*parts):\n with codecs.open(os.path.join(HERE, *parts), \"rb\", \"utf-8\") as f:\n return f.read()\n\nclass CMakeBuildExt(build_ext):\n def build_extensions(self):\n\n cmake_python_library = \"{}/{}\".format(\n distutils.sysconfig.get_config_var(\"LIBDIR\"),\n distutils.sysconfig.get_config_var(\"INSTSONAME\"),\n )\n cmake_python_include_dir = distutils.sysconfig.get_python_inc()\n\n install_dir = os.path.abspath(\n os.path.dirname(self.get_ext_fullpath(\"dummy\"))\n )\n os.makedirs(install_dir, exist_ok=True)\n cmake_args = [\n \"-DCMAKE_INSTALL_PREFIX={}\".format(install_dir),\n \"-DPython_EXECUTABLE={}\".format(sys.executable),\n \"-DPython_LIBRARIES={}\".format(cmake_python_library),\n \"-DPython_INCLUDE_DIRS={}\".format(cmake_python_include_dir),\n \"-DCMAKE_CUDA_ARCHITECTURES=70;80;90\",\n \"-DNVSHMEM_HOME={}\".format(HERE + \"/nvshmem\"),\n \"-DCUFFTMP_HOME={}\".format(HERE + \"/cufftmp\"),\n \"-DCMAKE_BUILD_TYPE={}\".format(\n \"Debug\" if self.debug else \"Release\"\n ),\n \"-DCMAKE_PREFIX_PATH={}\".format(pybind11.get_cmake_dir()),\n ]\n\n os.makedirs(self.build_temp, exist_ok=True)\n subprocess.check_call(\n [\"cmake\", f\"{HERE}/src/cufftmp_jax/\"] + cmake_args, cwd=self.build_temp\n )\n\n # Build all the extensions\n super().build_extensions()\n\n # Finally run install\n subprocess.check_call(\n [\"cmake\", \"--build\", \".\", \"--target\", \"install\"],\n cwd=self.build_temp,\n )\n\n def build_extension(self, ext):\n target_name = ext.name.split(\".\")[-1]\n subprocess.check_call(\n [\"cmake\", \"--build\", \".\", \"--target\", target_name],\n cwd=self.build_temp,\n )\n\n\nextensions = [\n Extension(\n \"cufftmp_jax.gpu_ops\",\n [\n \"src/cufftmp_jax/src/gpu_ops.cpp\",\n \"src/cufftmp_jax/src/kernels.cu\",\n ],\n )]\n\n\nsetup(\n name=\"fft_jax\",\n version='0.0.2',\n author=\"Leopold Cambier, Zan Xu\",\n author_email=\"lcambier@nvidia.com, zanx@nvidia.com\",\n license=\"All rights reserved\",\n description=(\"FFT + JAX\"),\n long_description=read(\"README.md\"),\n long_description_content_type=\"text/markdown\",\n packages=find_packages(\"src\"),\n package_dir={\"\": \"src\"},\n include_package_data=True,\n install_requires=[\n # We remove the following JAX dependencies because we base our container from jax toolbox.\n # This avoids unnecessary update/downgrade of jax/jaxlib against the jax/jaxlib in container.\n # For building in other containers/environments, please uncomment the following.\n # \"jax[cuda]\", \n # \"jaxlib\"\n ],\n ext_modules=extensions,\n cmdclass={\"build_ext\": CMakeBuildExt},\n)","source_hash":"420ad161261a465b48610d90924220f0db941c0e6c98bdec5c24e32662a59d69","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.setup.read","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.setup.read#L31-L33","kind":"function","name":"read","path":"cuFFTMp/JAX_FFT/setup.py","language":"python","start_line":31,"end_line":33,"context_start_line":11,"context_end_line":53,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nimport codecs\nimport os\nimport subprocess\nimport sys\nimport distutils.sysconfig\nimport pybind11\n\nfrom setuptools import Extension, find_packages, setup\nfrom setuptools.command.build_ext import build_ext\n\nHERE = os.path.dirname(os.path.realpath(__file__))\n\ndef read(*parts):\n with codecs.open(os.path.join(HERE, *parts), \"rb\", \"utf-8\") as f:\n return f.read()\n\nclass CMakeBuildExt(build_ext):\n def build_extensions(self):\n\n cmake_python_library = \"{}/{}\".format(\n distutils.sysconfig.get_config_var(\"LIBDIR\"),\n distutils.sysconfig.get_config_var(\"INSTSONAME\"),\n )\n cmake_python_include_dir = distutils.sysconfig.get_python_inc()\n\n install_dir = os.path.abspath(\n os.path.dirname(self.get_ext_fullpath(\"dummy\"))\n )\n os.makedirs(install_dir, exist_ok=True)\n cmake_args = [\n \"-DCMAKE_INSTALL_PREFIX={}\".format(install_dir),\n \"-DPython_EXECUTABLE={}\".format(sys.executable),\n \"-DPython_LIBRARIES={}\".format(cmake_python_library),\n \"-DPython_INCLUDE_DIRS={}\".format(cmake_python_include_dir),\n \"-DCMAKE_CUDA_ARCHITECTURES=70;80;90\",","source_hash":"420ad161261a465b48610d90924220f0db941c0e6c98bdec5c24e32662a59d69","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.setup.CMakeBuildExt","uri":"program://CUDALibrarySamples/class/cuFFTMp.JAX_FFT.setup.CMakeBuildExt#L35-L81","kind":"class","name":"CMakeBuildExt","path":"cuFFTMp/JAX_FFT/setup.py","language":"python","start_line":35,"end_line":81,"context_start_line":15,"context_end_line":101,"code":"# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nimport codecs\nimport os\nimport subprocess\nimport sys\nimport distutils.sysconfig\nimport pybind11\n\nfrom setuptools import Extension, find_packages, setup\nfrom setuptools.command.build_ext import build_ext\n\nHERE = os.path.dirname(os.path.realpath(__file__))\n\ndef read(*parts):\n with codecs.open(os.path.join(HERE, *parts), \"rb\", \"utf-8\") as f:\n return f.read()\n\nclass CMakeBuildExt(build_ext):\n def build_extensions(self):\n\n cmake_python_library = \"{}/{}\".format(\n distutils.sysconfig.get_config_var(\"LIBDIR\"),\n distutils.sysconfig.get_config_var(\"INSTSONAME\"),\n )\n cmake_python_include_dir = distutils.sysconfig.get_python_inc()\n\n install_dir = os.path.abspath(\n os.path.dirname(self.get_ext_fullpath(\"dummy\"))\n )\n os.makedirs(install_dir, exist_ok=True)\n cmake_args = [\n \"-DCMAKE_INSTALL_PREFIX={}\".format(install_dir),\n \"-DPython_EXECUTABLE={}\".format(sys.executable),\n \"-DPython_LIBRARIES={}\".format(cmake_python_library),\n \"-DPython_INCLUDE_DIRS={}\".format(cmake_python_include_dir),\n \"-DCMAKE_CUDA_ARCHITECTURES=70;80;90\",\n \"-DNVSHMEM_HOME={}\".format(HERE + \"/nvshmem\"),\n \"-DCUFFTMP_HOME={}\".format(HERE + \"/cufftmp\"),\n \"-DCMAKE_BUILD_TYPE={}\".format(\n \"Debug\" if self.debug else \"Release\"\n ),\n \"-DCMAKE_PREFIX_PATH={}\".format(pybind11.get_cmake_dir()),\n ]\n\n os.makedirs(self.build_temp, exist_ok=True)\n subprocess.check_call(\n [\"cmake\", f\"{HERE}/src/cufftmp_jax/\"] + cmake_args, cwd=self.build_temp\n )\n\n # Build all the extensions\n super().build_extensions()\n\n # Finally run install\n subprocess.check_call(\n [\"cmake\", \"--build\", \".\", \"--target\", \"install\"],\n cwd=self.build_temp,\n )\n\n def build_extension(self, ext):\n target_name = ext.name.split(\".\")[-1]\n subprocess.check_call(\n [\"cmake\", \"--build\", \".\", \"--target\", target_name],\n cwd=self.build_temp,\n )\n\n\nextensions = [\n Extension(\n \"cufftmp_jax.gpu_ops\",\n [\n \"src/cufftmp_jax/src/gpu_ops.cpp\",\n \"src/cufftmp_jax/src/kernels.cu\",\n ],\n )]\n\n\nsetup(\n name=\"fft_jax\",\n version='0.0.2',\n author=\"Leopold Cambier, Zan Xu\",\n author_email=\"lcambier@nvidia.com, zanx@nvidia.com\",\n license=\"All rights reserved\",\n description=(\"FFT + JAX\"),\n long_description=read(\"README.md\"),","source_hash":"420ad161261a465b48610d90924220f0db941c0e6c98bdec5c24e32662a59d69","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.setup.build_extensions","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.setup.build_extensions#L36-L74","kind":"function","name":"build_extensions","path":"cuFFTMp/JAX_FFT/setup.py","language":"python","start_line":36,"end_line":74,"context_start_line":16,"context_end_line":94,"code":"# limitations under the License.\n\n\nimport codecs\nimport os\nimport subprocess\nimport sys\nimport distutils.sysconfig\nimport pybind11\n\nfrom setuptools import Extension, find_packages, setup\nfrom setuptools.command.build_ext import build_ext\n\nHERE = os.path.dirname(os.path.realpath(__file__))\n\ndef read(*parts):\n with codecs.open(os.path.join(HERE, *parts), \"rb\", \"utf-8\") as f:\n return f.read()\n\nclass CMakeBuildExt(build_ext):\n def build_extensions(self):\n\n cmake_python_library = \"{}/{}\".format(\n distutils.sysconfig.get_config_var(\"LIBDIR\"),\n distutils.sysconfig.get_config_var(\"INSTSONAME\"),\n )\n cmake_python_include_dir = distutils.sysconfig.get_python_inc()\n\n install_dir = os.path.abspath(\n os.path.dirname(self.get_ext_fullpath(\"dummy\"))\n )\n os.makedirs(install_dir, exist_ok=True)\n cmake_args = [\n \"-DCMAKE_INSTALL_PREFIX={}\".format(install_dir),\n \"-DPython_EXECUTABLE={}\".format(sys.executable),\n \"-DPython_LIBRARIES={}\".format(cmake_python_library),\n \"-DPython_INCLUDE_DIRS={}\".format(cmake_python_include_dir),\n \"-DCMAKE_CUDA_ARCHITECTURES=70;80;90\",\n \"-DNVSHMEM_HOME={}\".format(HERE + \"/nvshmem\"),\n \"-DCUFFTMP_HOME={}\".format(HERE + \"/cufftmp\"),\n \"-DCMAKE_BUILD_TYPE={}\".format(\n \"Debug\" if self.debug else \"Release\"\n ),\n \"-DCMAKE_PREFIX_PATH={}\".format(pybind11.get_cmake_dir()),\n ]\n\n os.makedirs(self.build_temp, exist_ok=True)\n subprocess.check_call(\n [\"cmake\", f\"{HERE}/src/cufftmp_jax/\"] + cmake_args, cwd=self.build_temp\n )\n\n # Build all the extensions\n super().build_extensions()\n\n # Finally run install\n subprocess.check_call(\n [\"cmake\", \"--build\", \".\", \"--target\", \"install\"],\n cwd=self.build_temp,\n )\n\n def build_extension(self, ext):\n target_name = ext.name.split(\".\")[-1]\n subprocess.check_call(\n [\"cmake\", \"--build\", \".\", \"--target\", target_name],\n cwd=self.build_temp,\n )\n\n\nextensions = [\n Extension(\n \"cufftmp_jax.gpu_ops\",\n [\n \"src/cufftmp_jax/src/gpu_ops.cpp\",\n \"src/cufftmp_jax/src/kernels.cu\",\n ],\n )]\n\n\nsetup(","source_hash":"420ad161261a465b48610d90924220f0db941c0e6c98bdec5c24e32662a59d69","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.setup.build_extension","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.setup.build_extension#L76-L81","kind":"function","name":"build_extension","path":"cuFFTMp/JAX_FFT/setup.py","language":"python","start_line":76,"end_line":81,"context_start_line":56,"context_end_line":101,"code":" \"-DCMAKE_BUILD_TYPE={}\".format(\n \"Debug\" if self.debug else \"Release\"\n ),\n \"-DCMAKE_PREFIX_PATH={}\".format(pybind11.get_cmake_dir()),\n ]\n\n os.makedirs(self.build_temp, exist_ok=True)\n subprocess.check_call(\n [\"cmake\", f\"{HERE}/src/cufftmp_jax/\"] + cmake_args, cwd=self.build_temp\n )\n\n # Build all the extensions\n super().build_extensions()\n\n # Finally run install\n subprocess.check_call(\n [\"cmake\", \"--build\", \".\", \"--target\", \"install\"],\n cwd=self.build_temp,\n )\n\n def build_extension(self, ext):\n target_name = ext.name.split(\".\")[-1]\n subprocess.check_call(\n [\"cmake\", \"--build\", \".\", \"--target\", target_name],\n cwd=self.build_temp,\n )\n\n\nextensions = [\n Extension(\n \"cufftmp_jax.gpu_ops\",\n [\n \"src/cufftmp_jax/src/gpu_ops.cpp\",\n \"src/cufftmp_jax/src/kernels.cu\",\n ],\n )]\n\n\nsetup(\n name=\"fft_jax\",\n version='0.0.2',\n author=\"Leopold Cambier, Zan Xu\",\n author_email=\"lcambier@nvidia.com, zanx@nvidia.com\",\n license=\"All rights reserved\",\n description=(\"FFT + JAX\"),\n long_description=read(\"README.md\"),","source_hash":"420ad161261a465b48610d90924220f0db941c0e6c98bdec5c24e32662a59d69","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.tests.helpers","uri":"program://CUDALibrarySamples/module/cuFFTMp.JAX_FFT.tests.helpers#L1-L131","kind":"module","name":"cuFFTMp.JAX_FFT.tests.helpers","path":"cuFFTMp/JAX_FFT/tests/helpers.py","language":"python","start_line":1,"end_line":131,"context_start_line":1,"context_end_line":131,"code":"# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\n\nimport jax\nfrom jax.experimental.shard_map import shard_map\n\n\ndef Frob_error_impl(dtest, dref):\n derr2 = jax.numpy.linalg.norm(dtest - dref) ** 2\n dnorm2 = jax.numpy.linalg.norm(dref) ** 2\n derr2_sum = jax.lax.psum(derr2, axis_name=\"gpus\")\n dnorm2_sum = jax.lax.psum(dnorm2, axis_name=\"gpus\")\n error = jax.numpy.sqrt(derr2_sum / dnorm2_sum)\n return error\n\n\ndef Frob_error(dtest, dref, mesh, dist):\n\n \"\"\"Computes the relative error in the Frobenius norm\n\n Arguments:\n dtest -- the test array, sharded along the axis `ngpus`\n dref -- the reference array, sharded along the axis `ngpus`\n dist -- the sharding of dtest and dref\n Should be an instance of fft_common.Dist\n\n Returns the relative error in the Frobenius norm, i.e., \n ||dtest - dref||_F / ||dref||_F\n \"\"\"\n\n return jax.jit(\n shard_map(\n Frob_error_impl,\n mesh=mesh,\n in_specs=dist.part_spec,\n out_specs=jax.sharding.PartitionSpec(),\n ),\n in_shardings=jax.sharding.NamedSharding(mesh, dist.part_spec),\n out_shardings=jax.sharding.NamedSharding(mesh, jax.sharding.PartitionSpec())\n )(dtest, dref)\n\n\ndef parser():\n parser = argparse.ArgumentParser(\n description=\"Test program for distributed FFTs in JAX\"\n )\n parser.add_argument(\n \"implementation\",\n type=str,\n choices=['cufftmp', 'xfft'],\n default='cufftmp',\n help='uses cuFFTMp or jit+shard_map'\n )\n parser.add_argument(\n \"mode\",\n type=str,\n choices=['test', 'perf'],\n default='test',\n help='test (correctness) or perf (performance)'\n )\n parser.add_argument(\n \"-x\", \"--xsize\",\n type=int,\n help=\"Size along X\",\n default=1\n )\n parser.add_argument(\n \"-y\", \"--ysize\",\n type=int,\n help=\"Size along Y\",\n default=1\n )\n parser.add_argument(\n \"-z\", \"--zsize\",\n type=int,\n help=\"Size along Z\",\n default=None\n )\n parser.add_argument(\n \"-n\", \"--size\",\n type=int,\n help=\"Size along X, Y and Z (takes precedence over xsize, ysize and zsize\",\n default=None\n )\n parser.add_argument(\n \"-c\", \"--cycles\",\n type=int,\n help=\"Cycles to benchmark (perf only)\",\n default=10\n )\n parser.add_argument(\n '-v', '--verbose',\n action='count',\n default=0,\n help=\"Verbosity level (0 = silent, 2 = debug)\"\n )\n parser.add_argument(\n '-d', '--dist',\n type=str,\n choices=['X', 'Y'],\n default='X',\n help=\"Input distribution (X for SLABS_X or Y for SLABS_Y)\"\n )\n parser.add_argument(\n \"--multiprocess\",\n type=str,\n default=None,\n help=\"If set, should be of the shape `coordinator,num_procs,proc_id` or `bootstrap` (automatic cluster detection)\")\n args = parser.parse_args()\n if args.size:\n shape = args.size, args.size, args.size\n else:\n if args.zsize:\n shape = args.xsize, args.ysize, args.zsize\n else:\n shape = args.xsize, args.ysize\n return {'shape': shape, **vars(args)}","source_hash":"ab3d644995e5284831cb6e75ee8c190741cd64350d7d46da446b147ce9a34b13","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.tests.helpers.Frob_error_impl","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.tests.helpers.Frob_error_impl#L22-L28","kind":"function","name":"Frob_error_impl","path":"cuFFTMp/JAX_FFT/tests/helpers.py","language":"python","start_line":22,"end_line":28,"context_start_line":2,"context_end_line":48,"code":"# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\n\nimport jax\nfrom jax.experimental.shard_map import shard_map\n\n\ndef Frob_error_impl(dtest, dref):\n derr2 = jax.numpy.linalg.norm(dtest - dref) ** 2\n dnorm2 = jax.numpy.linalg.norm(dref) ** 2\n derr2_sum = jax.lax.psum(derr2, axis_name=\"gpus\")\n dnorm2_sum = jax.lax.psum(dnorm2, axis_name=\"gpus\")\n error = jax.numpy.sqrt(derr2_sum / dnorm2_sum)\n return error\n\n\ndef Frob_error(dtest, dref, mesh, dist):\n\n \"\"\"Computes the relative error in the Frobenius norm\n\n Arguments:\n dtest -- the test array, sharded along the axis `ngpus`\n dref -- the reference array, sharded along the axis `ngpus`\n dist -- the sharding of dtest and dref\n Should be an instance of fft_common.Dist\n\n Returns the relative error in the Frobenius norm, i.e., \n ||dtest - dref||_F / ||dref||_F\n \"\"\"\n\n return jax.jit(\n shard_map(\n Frob_error_impl,\n mesh=mesh,","source_hash":"ab3d644995e5284831cb6e75ee8c190741cd64350d7d46da446b147ce9a34b13","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.tests.helpers.Frob_error","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.tests.helpers.Frob_error#L31-L54","kind":"function","name":"Frob_error","path":"cuFFTMp/JAX_FFT/tests/helpers.py","language":"python","start_line":31,"end_line":54,"context_start_line":11,"context_end_line":74,"code":"# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\n\nimport jax\nfrom jax.experimental.shard_map import shard_map\n\n\ndef Frob_error_impl(dtest, dref):\n derr2 = jax.numpy.linalg.norm(dtest - dref) ** 2\n dnorm2 = jax.numpy.linalg.norm(dref) ** 2\n derr2_sum = jax.lax.psum(derr2, axis_name=\"gpus\")\n dnorm2_sum = jax.lax.psum(dnorm2, axis_name=\"gpus\")\n error = jax.numpy.sqrt(derr2_sum / dnorm2_sum)\n return error\n\n\ndef Frob_error(dtest, dref, mesh, dist):\n\n \"\"\"Computes the relative error in the Frobenius norm\n\n Arguments:\n dtest -- the test array, sharded along the axis `ngpus`\n dref -- the reference array, sharded along the axis `ngpus`\n dist -- the sharding of dtest and dref\n Should be an instance of fft_common.Dist\n\n Returns the relative error in the Frobenius norm, i.e., \n ||dtest - dref||_F / ||dref||_F\n \"\"\"\n\n return jax.jit(\n shard_map(\n Frob_error_impl,\n mesh=mesh,\n in_specs=dist.part_spec,\n out_specs=jax.sharding.PartitionSpec(),\n ),\n in_shardings=jax.sharding.NamedSharding(mesh, dist.part_spec),\n out_shardings=jax.sharding.NamedSharding(mesh, jax.sharding.PartitionSpec())\n )(dtest, dref)\n\n\ndef parser():\n parser = argparse.ArgumentParser(\n description=\"Test program for distributed FFTs in JAX\"\n )\n parser.add_argument(\n \"implementation\",\n type=str,\n choices=['cufftmp', 'xfft'],\n default='cufftmp',\n help='uses cuFFTMp or jit+shard_map'\n )\n parser.add_argument(\n \"mode\",\n type=str,\n choices=['test', 'perf'],\n default='test',\n help='test (correctness) or perf (performance)'\n )","source_hash":"ab3d644995e5284831cb6e75ee8c190741cd64350d7d46da446b147ce9a34b13","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.tests.helpers.parser","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.tests.helpers.parser#L57-L131","kind":"function","name":"parser","path":"cuFFTMp/JAX_FFT/tests/helpers.py","language":"python","start_line":57,"end_line":131,"context_start_line":37,"context_end_line":131,"code":" dref -- the reference array, sharded along the axis `ngpus`\n dist -- the sharding of dtest and dref\n Should be an instance of fft_common.Dist\n\n Returns the relative error in the Frobenius norm, i.e., \n ||dtest - dref||_F / ||dref||_F\n \"\"\"\n\n return jax.jit(\n shard_map(\n Frob_error_impl,\n mesh=mesh,\n in_specs=dist.part_spec,\n out_specs=jax.sharding.PartitionSpec(),\n ),\n in_shardings=jax.sharding.NamedSharding(mesh, dist.part_spec),\n out_shardings=jax.sharding.NamedSharding(mesh, jax.sharding.PartitionSpec())\n )(dtest, dref)\n\n\ndef parser():\n parser = argparse.ArgumentParser(\n description=\"Test program for distributed FFTs in JAX\"\n )\n parser.add_argument(\n \"implementation\",\n type=str,\n choices=['cufftmp', 'xfft'],\n default='cufftmp',\n help='uses cuFFTMp or jit+shard_map'\n )\n parser.add_argument(\n \"mode\",\n type=str,\n choices=['test', 'perf'],\n default='test',\n help='test (correctness) or perf (performance)'\n )\n parser.add_argument(\n \"-x\", \"--xsize\",\n type=int,\n help=\"Size along X\",\n default=1\n )\n parser.add_argument(\n \"-y\", \"--ysize\",\n type=int,\n help=\"Size along Y\",\n default=1\n )\n parser.add_argument(\n \"-z\", \"--zsize\",\n type=int,\n help=\"Size along Z\",\n default=None\n )\n parser.add_argument(\n \"-n\", \"--size\",\n type=int,\n help=\"Size along X, Y and Z (takes precedence over xsize, ysize and zsize\",\n default=None\n )\n parser.add_argument(\n \"-c\", \"--cycles\",\n type=int,\n help=\"Cycles to benchmark (perf only)\",\n default=10\n )\n parser.add_argument(\n '-v', '--verbose',\n action='count',\n default=0,\n help=\"Verbosity level (0 = silent, 2 = debug)\"\n )\n parser.add_argument(\n '-d', '--dist',\n type=str,\n choices=['X', 'Y'],\n default='X',\n help=\"Input distribution (X for SLABS_X or Y for SLABS_Y)\"\n )\n parser.add_argument(\n \"--multiprocess\",\n type=str,\n default=None,\n help=\"If set, should be of the shape `coordinator,num_procs,proc_id` or `bootstrap` (automatic cluster detection)\")\n args = parser.parse_args()\n if args.size:\n shape = args.size, args.size, args.size\n else:\n if args.zsize:\n shape = args.xsize, args.ysize, args.zsize\n else:\n shape = args.xsize, args.ysize\n return {'shape': shape, **vars(args)}","source_hash":"ab3d644995e5284831cb6e75ee8c190741cd64350d7d46da446b147ce9a34b13","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.tests.fft_test","uri":"program://CUDALibrarySamples/module/cuFFTMp.JAX_FFT.tests.fft_test#L1-L170","kind":"module","name":"cuFFTMp.JAX_FFT.tests.fft_test","path":"cuFFTMp/JAX_FFT/tests/fft_test.py","language":"python","start_line":1,"end_line":170,"context_start_line":1,"context_end_line":170,"code":"# -*- coding: utf-8 -*-\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport time\nimport math\nimport numpy as np\nimport sys\n\nimport jax\nimport jax.numpy as jnp\nfrom jax.sharding import Mesh\n\nfrom fft_common import Dist, Dir\nfrom cufftmp_jax import cufftmp\nfrom xfft import xfft\n\nimport helpers\n\n\ndef main():\n\n opt = helpers.parser()\n\n # Initialize JAX for multi-process runs\n if opt['multiprocess'] is not None:\n if opt['multiprocess'] == 'bootstrap':\n jax.distributed.initialize()\n else:\n coordinator, num_procs, my_proc = opt['multiprocess'].split(',')\n jax.distributed.initialize(\n coordinator_address=coordinator,\n num_processes=int(num_procs),\n process_id=int(my_proc)\n )\n\n fft_dims = opt['shape']\n cycles = opt['cycles']\n\n impl = opt['implementation']\n if impl == \"cufftmp\":\n dist_fft = cufftmp\n elif impl == \"xfft\":\n dist_fft = xfft\n else:\n raise ValueError(f\"Wrong implementation: got {impl}, expected cufftmp or xfft\")\n\n dist = Dist.create(opt['dist'])\n input_shape = dist.slab_shape(fft_dims)\n dtype = jnp.complex64\n\n mesh = Mesh(np.asarray(jax.devices()), ('gpus',))\n sharding = jax.sharding.NamedSharding(mesh, dist.part_spec)\n\n with jax.spmd_mode('allow_all'):\n\n if opt['mode'] == \"test\":\n\n seed = 170\n key = jax.random.PRNGKey(seed)\n input = jax.random.normal(key, shape=fft_dims, dtype=dtype)\n\n with mesh:\n\n fft = jax.jit(dist_fft,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2])\n\n output = fft(input, dist, Dir.FWD)\n\n output_ref = jnp.fft.fftn(input)\n error = jnp.linalg.norm(output - output_ref) / \\\n jnp.linalg.norm(output_ref)\n\n if jax.process_index() == 0:\n print(f\"{impl} (test): {fft_dims}, dist {dist} --> {dist.opposite}, num GPUs {jax.device_count()}, num processes {jax.process_count()}, L2 rel error {error:.2e}\")\n if error < 1e-4:\n print(\"&&&& PASSED\")\n else:\n print(\"&&&& FAILED\")\n sys.exit(1)\n\n else:\n\n with mesh:\n\n # Performance testing only supports 1 device per process\n # because of the way the input `dinput` is generated\n assert jax.local_device_count() == 1\n\n # Quick generation of the local array\n input = jnp.ones(input_shape, dtype=dtype)\n\n # Create the global sharded array\n dinput = jax.make_array_from_single_device_arrays(\n fft_dims,\n sharding,\n [input])\n\n # Function to benchmark. \n # One forward distributed FFT and one backward distributed FFT.\n def fwd_bwd(x, dist, dir):\n return dist_fft(dist_fft(x, dist, dir),\n dist.opposite,\n dir.opposite)\n\n fwd_bwd_jit = jax.jit(fwd_bwd,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2])\n\n def fwd_bwd_bench(x):\n return fwd_bwd_jit(x, dist, Dir.FWD)\n\n # Warmup\n x = fwd_bwd_bench(dinput).block_until_ready()\n\n # Benchmark\n times = []\n x = dinput\n for _ in range(cycles):\n cycle_start = time.time()\n x = fwd_bwd_bench(x)\n x.block_until_ready()\n cycle_end = time.time()\n times.append((cycle_end - cycle_start)/2) # divide by 2 since two FFTs in forward-backward transform\n doutput = x.block_until_ready()\n\n # Check error\n doutput_ref = dinput\n error = helpers.Frob_error(doutput_ref, doutput, mesh, dist)\n\n # Calculate statistics, and multiply 1e3 to convert to ms\n mean_time = np.mean(times) * 1e3\n median_time = np.median(times) * 1e3\n std_dev = np.std(times) * 1e3\n min_time = np.min(times) * 1e3\n max_time = np.max(times) * 1e3\n \n # Perf ?\n perf_GFlops = \\\n (5 * math.prod(fft_dims) * math.log2(math.prod(fft_dims))) / 1e9 / median_time\n bandwidth_GBsGPUdir = \\\n (8 * math.prod(fft_dims)) / jax.device_count() / 1e9 / median_time\n\n if jax.process_index() == 0:\n print(f\"{impl} (perf): {fft_dims}, num GPUs {jax.device_count()}, num processes {jax.process_count()}, relative L2 error {error:.2e}, cycles {cycles}, time_avg {mean_time:.2e} ms, time_med {median_time:.2e} ms, time_std {std_dev:.2e} ms, time_min {min_time:.2e} ms, time_max {max_time:.2e} ms, perf_median {perf_GFlops:.2e} GFlop/s, bandwidth_median {bandwidth_GBsGPUdir:.2e} GB/s/GPU\")\n if error < 1e-4:\n print(\"&&&& PASSED\")\n else:\n print(\"&&&& FAILED\")\n sys.exit(1)\n\n\nif __name__ == \"__main__\":\n main()","source_hash":"bf53d532bb89cda5d80a0d967a3b60583a521c7cb9f5b16660167233177105f2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.tests.fft_test.main","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.tests.fft_test.main#L34-L166","kind":"function","name":"main","path":"cuFFTMp/JAX_FFT/tests/fft_test.py","language":"python","start_line":34,"end_line":166,"context_start_line":14,"context_end_line":170,"code":"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport time\nimport math\nimport numpy as np\nimport sys\n\nimport jax\nimport jax.numpy as jnp\nfrom jax.sharding import Mesh\n\nfrom fft_common import Dist, Dir\nfrom cufftmp_jax import cufftmp\nfrom xfft import xfft\n\nimport helpers\n\n\ndef main():\n\n opt = helpers.parser()\n\n # Initialize JAX for multi-process runs\n if opt['multiprocess'] is not None:\n if opt['multiprocess'] == 'bootstrap':\n jax.distributed.initialize()\n else:\n coordinator, num_procs, my_proc = opt['multiprocess'].split(',')\n jax.distributed.initialize(\n coordinator_address=coordinator,\n num_processes=int(num_procs),\n process_id=int(my_proc)\n )\n\n fft_dims = opt['shape']\n cycles = opt['cycles']\n\n impl = opt['implementation']\n if impl == \"cufftmp\":\n dist_fft = cufftmp\n elif impl == \"xfft\":\n dist_fft = xfft\n else:\n raise ValueError(f\"Wrong implementation: got {impl}, expected cufftmp or xfft\")\n\n dist = Dist.create(opt['dist'])\n input_shape = dist.slab_shape(fft_dims)\n dtype = jnp.complex64\n\n mesh = Mesh(np.asarray(jax.devices()), ('gpus',))\n sharding = jax.sharding.NamedSharding(mesh, dist.part_spec)\n\n with jax.spmd_mode('allow_all'):\n\n if opt['mode'] == \"test\":\n\n seed = 170\n key = jax.random.PRNGKey(seed)\n input = jax.random.normal(key, shape=fft_dims, dtype=dtype)\n\n with mesh:\n\n fft = jax.jit(dist_fft,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2])\n\n output = fft(input, dist, Dir.FWD)\n\n output_ref = jnp.fft.fftn(input)\n error = jnp.linalg.norm(output - output_ref) / \\\n jnp.linalg.norm(output_ref)\n\n if jax.process_index() == 0:\n print(f\"{impl} (test): {fft_dims}, dist {dist} --> {dist.opposite}, num GPUs {jax.device_count()}, num processes {jax.process_count()}, L2 rel error {error:.2e}\")\n if error < 1e-4:\n print(\"&&&& PASSED\")\n else:\n print(\"&&&& FAILED\")\n sys.exit(1)\n\n else:\n\n with mesh:\n\n # Performance testing only supports 1 device per process\n # because of the way the input `dinput` is generated\n assert jax.local_device_count() == 1\n\n # Quick generation of the local array\n input = jnp.ones(input_shape, dtype=dtype)\n\n # Create the global sharded array\n dinput = jax.make_array_from_single_device_arrays(\n fft_dims,\n sharding,\n [input])\n\n # Function to benchmark. \n # One forward distributed FFT and one backward distributed FFT.\n def fwd_bwd(x, dist, dir):\n return dist_fft(dist_fft(x, dist, dir),\n dist.opposite,\n dir.opposite)\n\n fwd_bwd_jit = jax.jit(fwd_bwd,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2])\n\n def fwd_bwd_bench(x):\n return fwd_bwd_jit(x, dist, Dir.FWD)\n\n # Warmup\n x = fwd_bwd_bench(dinput).block_until_ready()\n\n # Benchmark\n times = []\n x = dinput\n for _ in range(cycles):\n cycle_start = time.time()\n x = fwd_bwd_bench(x)\n x.block_until_ready()\n cycle_end = time.time()\n times.append((cycle_end - cycle_start)/2) # divide by 2 since two FFTs in forward-backward transform\n doutput = x.block_until_ready()\n\n # Check error\n doutput_ref = dinput\n error = helpers.Frob_error(doutput_ref, doutput, mesh, dist)\n\n # Calculate statistics, and multiply 1e3 to convert to ms\n mean_time = np.mean(times) * 1e3\n median_time = np.median(times) * 1e3\n std_dev = np.std(times) * 1e3\n min_time = np.min(times) * 1e3\n max_time = np.max(times) * 1e3\n \n # Perf ?\n perf_GFlops = \\\n (5 * math.prod(fft_dims) * math.log2(math.prod(fft_dims))) / 1e9 / median_time\n bandwidth_GBsGPUdir = \\\n (8 * math.prod(fft_dims)) / jax.device_count() / 1e9 / median_time\n\n if jax.process_index() == 0:\n print(f\"{impl} (perf): {fft_dims}, num GPUs {jax.device_count()}, num processes {jax.process_count()}, relative L2 error {error:.2e}, cycles {cycles}, time_avg {mean_time:.2e} ms, time_med {median_time:.2e} ms, time_std {std_dev:.2e} ms, time_min {min_time:.2e} ms, time_max {max_time:.2e} ms, perf_median {perf_GFlops:.2e} GFlop/s, bandwidth_median {bandwidth_GBsGPUdir:.2e} GB/s/GPU\")\n if error < 1e-4:\n print(\"&&&& PASSED\")\n else:\n print(\"&&&& FAILED\")\n sys.exit(1)\n\n\nif __name__ == \"__main__\":\n main()","source_hash":"bf53d532bb89cda5d80a0d967a3b60583a521c7cb9f5b16660167233177105f2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.tests.fft_test.fwd_bwd","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.tests.fft_test.fwd_bwd#L116-L119","kind":"function","name":"fwd_bwd","path":"cuFFTMp/JAX_FFT/tests/fft_test.py","language":"python","start_line":116,"end_line":119,"context_start_line":96,"context_end_line":139,"code":"\n else:\n\n with mesh:\n\n # Performance testing only supports 1 device per process\n # because of the way the input `dinput` is generated\n assert jax.local_device_count() == 1\n\n # Quick generation of the local array\n input = jnp.ones(input_shape, dtype=dtype)\n\n # Create the global sharded array\n dinput = jax.make_array_from_single_device_arrays(\n fft_dims,\n sharding,\n [input])\n\n # Function to benchmark. \n # One forward distributed FFT and one backward distributed FFT.\n def fwd_bwd(x, dist, dir):\n return dist_fft(dist_fft(x, dist, dir),\n dist.opposite,\n dir.opposite)\n\n fwd_bwd_jit = jax.jit(fwd_bwd,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2])\n\n def fwd_bwd_bench(x):\n return fwd_bwd_jit(x, dist, Dir.FWD)\n\n # Warmup\n x = fwd_bwd_bench(dinput).block_until_ready()\n\n # Benchmark\n times = []\n x = dinput\n for _ in range(cycles):\n cycle_start = time.time()\n x = fwd_bwd_bench(x)\n x.block_until_ready()\n cycle_end = time.time()","source_hash":"bf53d532bb89cda5d80a0d967a3b60583a521c7cb9f5b16660167233177105f2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.tests.fft_test.fwd_bwd_bench","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.tests.fft_test.fwd_bwd_bench#L126-L127","kind":"function","name":"fwd_bwd_bench","path":"cuFFTMp/JAX_FFT/tests/fft_test.py","language":"python","start_line":126,"end_line":127,"context_start_line":106,"context_end_line":147,"code":" input = jnp.ones(input_shape, dtype=dtype)\n\n # Create the global sharded array\n dinput = jax.make_array_from_single_device_arrays(\n fft_dims,\n sharding,\n [input])\n\n # Function to benchmark. \n # One forward distributed FFT and one backward distributed FFT.\n def fwd_bwd(x, dist, dir):\n return dist_fft(dist_fft(x, dist, dir),\n dist.opposite,\n dir.opposite)\n\n fwd_bwd_jit = jax.jit(fwd_bwd,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2])\n\n def fwd_bwd_bench(x):\n return fwd_bwd_jit(x, dist, Dir.FWD)\n\n # Warmup\n x = fwd_bwd_bench(dinput).block_until_ready()\n\n # Benchmark\n times = []\n x = dinput\n for _ in range(cycles):\n cycle_start = time.time()\n x = fwd_bwd_bench(x)\n x.block_until_ready()\n cycle_end = time.time()\n times.append((cycle_end - cycle_start)/2) # divide by 2 since two FFTs in forward-backward transform\n doutput = x.block_until_ready()\n\n # Check error\n doutput_ref = dinput\n error = helpers.Frob_error(doutput_ref, doutput, mesh, dist)\n\n # Calculate statistics, and multiply 1e3 to convert to ms","source_hash":"bf53d532bb89cda5d80a0d967a3b60583a521c7cb9f5b16660167233177105f2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils","uri":"program://CUDALibrarySamples/module/cuFFTMp.JAX_FFT.src.fft_common.utils#L1-L121","kind":"module","name":"cuFFTMp.JAX_FFT.src.fft_common.utils","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":1,"end_line":121,"context_start_line":1,"context_end_line":121,"code":"# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom enum import Enum\n\nimport jax\nfrom jax.sharding import PartitionSpec\n\n\nclass Dist(Enum):\n\n \"\"\"Describes a SLAB data decomposition\n\n For a X*Y*Z array, SLABS_X indicates the array is\n distributed along the first dimension, i.e., each \n device owns a slab of size (X // nGPUs)*Y*Z\n SLABS_Y indicates the array is distributed along the\n second dimension, with each device owning a slab\n of size X*(Y // nGPUs)*Z.\n \"\"\"\n\n SLABS_X = 'SLABS_X'\n SLABS_Y = 'SLABS_Y'\n\n @staticmethod\n def create(string):\n if string == 'X':\n return Dist.SLABS_X\n elif string == 'Y':\n return Dist.SLABS_Y\n else:\n raise RuntimeError(\"Wrong dist\")\n\n @property\n def opposite(dist):\n if dist == Dist.SLABS_X:\n return Dist.SLABS_Y\n else:\n return Dist.SLABS_X\n\n @property\n def _C_enum(dist):\n if dist == Dist.SLABS_X:\n return 0\n else:\n return 1\n\n def fft_axes(self, fft_rank):\n if self == Dist.SLABS_X:\n return list(range(1, fft_rank))\n else:\n return [0]\n\n def slab_shape(self, fft_dims):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (\n fft_dims[0] // ngpus,\n fft_dims[1],\n *fft_dims[2:]\n )\n else:\n return (\n fft_dims[0],\n fft_dims[1] // ngpus,\n *fft_dims[2:]\n )\n\n def fft_shape(self, local_shape):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (local_shape[0] * ngpus, local_shape[1], *local_shape[2:])\n else:\n return (local_shape[0], local_shape[1] * ngpus, *local_shape[2:])\n\n\n @property\n def part_spec(dist):\n if dist == Dist.SLABS_X:\n return PartitionSpec(\"gpus\", None)\n else:\n return PartitionSpec(None, \"gpus\")\n\n\nclass Dir(Enum):\n\n \"\"\"Describe the FFT direction\n\n FWD is the forward, unnormalized, direction.\n BWD is the backward, normalized by 1/N, direction,\n with N the product of the dimensions.\n \"\"\"\n\n FWD = 'FWD'\n INV = 'INV'\n\n @property\n def _C_enum(dir):\n if dir == Dir.FWD:\n return 0\n else:\n return 1\n\n @property\n def opposite(dir):\n if dir == Dir.FWD:\n return Dir.INV\n else:\n return Dir.FWD","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils.Dist","uri":"program://CUDALibrarySamples/class/cuFFTMp.JAX_FFT.src.fft_common.utils.Dist#L22-L94","kind":"class","name":"Dist","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":22,"end_line":94,"context_start_line":2,"context_end_line":114,"code":"# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom enum import Enum\n\nimport jax\nfrom jax.sharding import PartitionSpec\n\n\nclass Dist(Enum):\n\n \"\"\"Describes a SLAB data decomposition\n\n For a X*Y*Z array, SLABS_X indicates the array is\n distributed along the first dimension, i.e., each \n device owns a slab of size (X // nGPUs)*Y*Z\n SLABS_Y indicates the array is distributed along the\n second dimension, with each device owning a slab\n of size X*(Y // nGPUs)*Z.\n \"\"\"\n\n SLABS_X = 'SLABS_X'\n SLABS_Y = 'SLABS_Y'\n\n @staticmethod\n def create(string):\n if string == 'X':\n return Dist.SLABS_X\n elif string == 'Y':\n return Dist.SLABS_Y\n else:\n raise RuntimeError(\"Wrong dist\")\n\n @property\n def opposite(dist):\n if dist == Dist.SLABS_X:\n return Dist.SLABS_Y\n else:\n return Dist.SLABS_X\n\n @property\n def _C_enum(dist):\n if dist == Dist.SLABS_X:\n return 0\n else:\n return 1\n\n def fft_axes(self, fft_rank):\n if self == Dist.SLABS_X:\n return list(range(1, fft_rank))\n else:\n return [0]\n\n def slab_shape(self, fft_dims):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (\n fft_dims[0] // ngpus,\n fft_dims[1],\n *fft_dims[2:]\n )\n else:\n return (\n fft_dims[0],\n fft_dims[1] // ngpus,\n *fft_dims[2:]\n )\n\n def fft_shape(self, local_shape):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (local_shape[0] * ngpus, local_shape[1], *local_shape[2:])\n else:\n return (local_shape[0], local_shape[1] * ngpus, *local_shape[2:])\n\n\n @property\n def part_spec(dist):\n if dist == Dist.SLABS_X:\n return PartitionSpec(\"gpus\", None)\n else:\n return PartitionSpec(None, \"gpus\")\n\n\nclass Dir(Enum):\n\n \"\"\"Describe the FFT direction\n\n FWD is the forward, unnormalized, direction.\n BWD is the backward, normalized by 1/N, direction,\n with N the product of the dimensions.\n \"\"\"\n\n FWD = 'FWD'\n INV = 'INV'\n\n @property\n def _C_enum(dir):\n if dir == Dir.FWD:\n return 0\n else:\n return 1","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils.Dir","uri":"program://CUDALibrarySamples/class/cuFFTMp.JAX_FFT.src.fft_common.utils.Dir#L97-L121","kind":"class","name":"Dir","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":97,"end_line":121,"context_start_line":77,"context_end_line":121,"code":" fft_dims[1] // ngpus,\n *fft_dims[2:]\n )\n\n def fft_shape(self, local_shape):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (local_shape[0] * ngpus, local_shape[1], *local_shape[2:])\n else:\n return (local_shape[0], local_shape[1] * ngpus, *local_shape[2:])\n\n\n @property\n def part_spec(dist):\n if dist == Dist.SLABS_X:\n return PartitionSpec(\"gpus\", None)\n else:\n return PartitionSpec(None, \"gpus\")\n\n\nclass Dir(Enum):\n\n \"\"\"Describe the FFT direction\n\n FWD is the forward, unnormalized, direction.\n BWD is the backward, normalized by 1/N, direction,\n with N the product of the dimensions.\n \"\"\"\n\n FWD = 'FWD'\n INV = 'INV'\n\n @property\n def _C_enum(dir):\n if dir == Dir.FWD:\n return 0\n else:\n return 1\n\n @property\n def opposite(dir):\n if dir == Dir.FWD:\n return Dir.INV\n else:\n return Dir.FWD","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils.create","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.fft_common.utils.create#L38-L44","kind":"function","name":"create","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":38,"end_line":44,"context_start_line":18,"context_end_line":64,"code":"import jax\nfrom jax.sharding import PartitionSpec\n\n\nclass Dist(Enum):\n\n \"\"\"Describes a SLAB data decomposition\n\n For a X*Y*Z array, SLABS_X indicates the array is\n distributed along the first dimension, i.e., each \n device owns a slab of size (X // nGPUs)*Y*Z\n SLABS_Y indicates the array is distributed along the\n second dimension, with each device owning a slab\n of size X*(Y // nGPUs)*Z.\n \"\"\"\n\n SLABS_X = 'SLABS_X'\n SLABS_Y = 'SLABS_Y'\n\n @staticmethod\n def create(string):\n if string == 'X':\n return Dist.SLABS_X\n elif string == 'Y':\n return Dist.SLABS_Y\n else:\n raise RuntimeError(\"Wrong dist\")\n\n @property\n def opposite(dist):\n if dist == Dist.SLABS_X:\n return Dist.SLABS_Y\n else:\n return Dist.SLABS_X\n\n @property\n def _C_enum(dist):\n if dist == Dist.SLABS_X:\n return 0\n else:\n return 1\n\n def fft_axes(self, fft_rank):\n if self == Dist.SLABS_X:\n return list(range(1, fft_rank))\n else:\n return [0]","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils.opposite","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.fft_common.utils.opposite#L117-L121","kind":"function","name":"opposite","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":117,"end_line":121,"context_start_line":97,"context_end_line":121,"code":"class Dir(Enum):\n\n \"\"\"Describe the FFT direction\n\n FWD is the forward, unnormalized, direction.\n BWD is the backward, normalized by 1/N, direction,\n with N the product of the dimensions.\n \"\"\"\n\n FWD = 'FWD'\n INV = 'INV'\n\n @property\n def _C_enum(dir):\n if dir == Dir.FWD:\n return 0\n else:\n return 1\n\n @property\n def opposite(dir):\n if dir == Dir.FWD:\n return Dir.INV\n else:\n return Dir.FWD","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils._C_enum","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.fft_common.utils._C_enum#L110-L114","kind":"function","name":"_C_enum","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":110,"end_line":114,"context_start_line":90,"context_end_line":121,"code":" def part_spec(dist):\n if dist == Dist.SLABS_X:\n return PartitionSpec(\"gpus\", None)\n else:\n return PartitionSpec(None, \"gpus\")\n\n\nclass Dir(Enum):\n\n \"\"\"Describe the FFT direction\n\n FWD is the forward, unnormalized, direction.\n BWD is the backward, normalized by 1/N, direction,\n with N the product of the dimensions.\n \"\"\"\n\n FWD = 'FWD'\n INV = 'INV'\n\n @property\n def _C_enum(dir):\n if dir == Dir.FWD:\n return 0\n else:\n return 1\n\n @property\n def opposite(dir):\n if dir == Dir.FWD:\n return Dir.INV\n else:\n return Dir.FWD","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils.fft_axes","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.fft_common.utils.fft_axes#L60-L64","kind":"function","name":"fft_axes","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":60,"end_line":64,"context_start_line":40,"context_end_line":84,"code":" return Dist.SLABS_X\n elif string == 'Y':\n return Dist.SLABS_Y\n else:\n raise RuntimeError(\"Wrong dist\")\n\n @property\n def opposite(dist):\n if dist == Dist.SLABS_X:\n return Dist.SLABS_Y\n else:\n return Dist.SLABS_X\n\n @property\n def _C_enum(dist):\n if dist == Dist.SLABS_X:\n return 0\n else:\n return 1\n\n def fft_axes(self, fft_rank):\n if self == Dist.SLABS_X:\n return list(range(1, fft_rank))\n else:\n return [0]\n\n def slab_shape(self, fft_dims):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (\n fft_dims[0] // ngpus,\n fft_dims[1],\n *fft_dims[2:]\n )\n else:\n return (\n fft_dims[0],\n fft_dims[1] // ngpus,\n *fft_dims[2:]\n )\n\n def fft_shape(self, local_shape):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (local_shape[0] * ngpus, local_shape[1], *local_shape[2:])","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils.slab_shape","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.fft_common.utils.slab_shape#L66-L79","kind":"function","name":"slab_shape","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":66,"end_line":79,"context_start_line":46,"context_end_line":99,"code":" @property\n def opposite(dist):\n if dist == Dist.SLABS_X:\n return Dist.SLABS_Y\n else:\n return Dist.SLABS_X\n\n @property\n def _C_enum(dist):\n if dist == Dist.SLABS_X:\n return 0\n else:\n return 1\n\n def fft_axes(self, fft_rank):\n if self == Dist.SLABS_X:\n return list(range(1, fft_rank))\n else:\n return [0]\n\n def slab_shape(self, fft_dims):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (\n fft_dims[0] // ngpus,\n fft_dims[1],\n *fft_dims[2:]\n )\n else:\n return (\n fft_dims[0],\n fft_dims[1] // ngpus,\n *fft_dims[2:]\n )\n\n def fft_shape(self, local_shape):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (local_shape[0] * ngpus, local_shape[1], *local_shape[2:])\n else:\n return (local_shape[0], local_shape[1] * ngpus, *local_shape[2:])\n\n\n @property\n def part_spec(dist):\n if dist == Dist.SLABS_X:\n return PartitionSpec(\"gpus\", None)\n else:\n return PartitionSpec(None, \"gpus\")\n\n\nclass Dir(Enum):\n\n \"\"\"Describe the FFT direction","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils.fft_shape","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.fft_common.utils.fft_shape#L81-L86","kind":"function","name":"fft_shape","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":81,"end_line":86,"context_start_line":61,"context_end_line":106,"code":" if self == Dist.SLABS_X:\n return list(range(1, fft_rank))\n else:\n return [0]\n\n def slab_shape(self, fft_dims):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (\n fft_dims[0] // ngpus,\n fft_dims[1],\n *fft_dims[2:]\n )\n else:\n return (\n fft_dims[0],\n fft_dims[1] // ngpus,\n *fft_dims[2:]\n )\n\n def fft_shape(self, local_shape):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (local_shape[0] * ngpus, local_shape[1], *local_shape[2:])\n else:\n return (local_shape[0], local_shape[1] * ngpus, *local_shape[2:])\n\n\n @property\n def part_spec(dist):\n if dist == Dist.SLABS_X:\n return PartitionSpec(\"gpus\", None)\n else:\n return PartitionSpec(None, \"gpus\")\n\n\nclass Dir(Enum):\n\n \"\"\"Describe the FFT direction\n\n FWD is the forward, unnormalized, direction.\n BWD is the backward, normalized by 1/N, direction,\n with N the product of the dimensions.\n \"\"\"\n\n FWD = 'FWD'","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.fft_common.utils.part_spec","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.fft_common.utils.part_spec#L90-L94","kind":"function","name":"part_spec","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":90,"end_line":94,"context_start_line":70,"context_end_line":114,"code":" fft_dims[0] // ngpus,\n fft_dims[1],\n *fft_dims[2:]\n )\n else:\n return (\n fft_dims[0],\n fft_dims[1] // ngpus,\n *fft_dims[2:]\n )\n\n def fft_shape(self, local_shape):\n ngpus = jax.device_count()\n if self == Dist.SLABS_X:\n return (local_shape[0] * ngpus, local_shape[1], *local_shape[2:])\n else:\n return (local_shape[0], local_shape[1] * ngpus, *local_shape[2:])\n\n\n @property\n def part_spec(dist):\n if dist == Dist.SLABS_X:\n return PartitionSpec(\"gpus\", None)\n else:\n return PartitionSpec(None, \"gpus\")\n\n\nclass Dir(Enum):\n\n \"\"\"Describe the FFT direction\n\n FWD is the forward, unnormalized, direction.\n BWD is the backward, normalized by 1/N, direction,\n with N the product of the dimensions.\n \"\"\"\n\n FWD = 'FWD'\n INV = 'INV'\n\n @property\n def _C_enum(dir):\n if dir == Dir.FWD:\n return 0\n else:\n return 1","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax","uri":"program://CUDALibrarySamples/module/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax#L1-L226","kind":"module","name":"cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":1,"end_line":226,"context_start_line":1,"context_end_line":226,"code":"# -*- coding: utf-8 -*-\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\n__all__ = [\"cufftmp\"]\n\nfrom functools import partial\nimport math\n\nimport jax\nfrom jax.lib import xla_client\nfrom jax import core, dtypes\nfrom jax.interpreters import xla, mlir\nfrom jax.core import ShapedArray\nfrom jax.sharding import NamedSharding\nfrom jax.experimental.custom_partitioning import custom_partitioning\nfrom jaxlib.hlo_helpers import custom_call\n\nfrom fft_common import Dir, Dist\n\nfrom . import gpu_ops\nfor _name, _value in gpu_ops.registrations().items():\n xla_client.register_custom_call_target(_name, _value, platform=\"gpu\")\n\nxops = xla_client.ops\n\n# ************\n# * BINDINGS *\n# ************\n\n\ndef _cufftmp_bind(input, num_parts, dist, dir):\n\n # param=val means it's a static parameter\n (output,) = _cufftmp_prim.bind(input,\n num_parts=num_parts,\n dist=dist,\n dir=dir)\n\n # scale in INVERSE direction\n if dir == Dir.INV:\n fft_dims = dist.fft_shape(input.shape)\n output = jax.numpy.divide(output, math.prod([\n jax.numpy.complex64(f) for f in fft_dims\n ]))\n\n return output\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n \"\"\" Describes the required input and output sharding of the op.\n `mesh`, `arg_shapes` and `result_shape` are the shapes provided by the\n user (i.e., in jit).\n Returns:\n - The operation to perform locally on all GPUs\n - The output sharding\n - The input sharding \"\"\"\n \n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n\n return mesh, \\\n lambda x: _cufftmp_bind(x,\n num_parts=jax.device_count(),\n dist=dist,\n dir=dir), \\\n _supported_sharding(arg_shardings[0], dist.opposite), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef cufftmp(x, dist, dir):\n\n \"\"\"Compute the DFT using a JAX+cuFFTMp implementation.\n\n Arguments:\n x -- the input tensor\n dist -- the data decomposition of x.\n Should be an instance of fft_common.Dist\n dir -- the direction of the transform.\n Should be an instance of fft_common.Dir\n\n Returns the transformed tensor.\n The output tensoris distributed according to dist.opposite\n\n This function should be used with jit like\n\n jit(\n cufftmp,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2]\n )(x, dist, dir)\n\n \"\"\"\n\n # cuFFTMp only supports 1 device per proces\n assert jax.local_device_count() == 1\n\n @custom_partitioning\n def _cufftmp_(x):\n return _cufftmp_bind(x, num_parts=1, dist=dist, dir=dir)\n\n _cufftmp_.def_partition(\n infer_sharding_from_operands=partial(\n _infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(\n _partition,\n dist=dist,\n dir=dir))\n\n return _cufftmp_(x)\n\n\n# *********************************\n# * SUPPORT FOR JIT COMPILATION *\n# *********************************\n\n# Abstract implementation, i.e., return the shape of the output array\n# based on the input array and a number of partitions (ie devices)\ndef _cufftmp_abstract(input, num_parts, dist, dir):\n dtype = dtypes.canonicalize_dtype(input.dtype)\n input_shape = input.shape\n if dist == Dist.SLABS_X:\n output_shape = (input_shape[0] * num_parts,\n input_shape[1] // num_parts,\n *input_shape[2:])\n elif dist == Dist.SLABS_Y:\n output_shape = (input_shape[0] // num_parts,\n input_shape[1] * num_parts,\n *input_shape[2:])\n return (ShapedArray(output_shape, dtype),)\n\n\n# Implementation calling into the C++ bindings\ndef _cufftmp_lowering(ctx, input, num_parts, dist, dir):\n\n assert num_parts == jax.device_count()\n\n input_type = mlir.ir.RankedTensorType(input.type)\n dims_in = input_type.shape\n fft_dims = dist.fft_shape(dims_in)\n dims_out = dist.opposite.slab_shape(fft_dims)\n output_type = mlir.ir.RankedTensorType.get(\n dims_out,\n input_type.element_type\n )\n\n layout = tuple(range(len(dims_in) - 1, -1, -1))\n\n if len(fft_dims) == 2:\n opaque = gpu_ops.build_cufftmp_descriptor(\n fft_dims[0],\n fft_dims[1],\n 1,\n dist._C_enum,\n dir._C_enum\n )\n elif len(fft_dims) == 3:\n opaque = gpu_ops.build_cufftmp_descriptor(\n fft_dims[0],\n fft_dims[1],\n fft_dims[2],\n dist._C_enum,\n dir._C_enum\n )\n else:\n raise ValueError(\"Unsupported tensor rank; must be 2 or 3\")\n\n return custom_call(\n \"gpu_cufftmp\",\n # Output types\n result_types=[output_type],\n # The inputs:\n operands=[input,],\n # Layout specification:\n operand_layouts=[layout,],\n result_layouts=[layout,],\n # GPU specific additional data\n backend_config=opaque\n ).results\n\n\n# *********************************************\n# * BOILERPLATE TO REGISTER THE OP WITH JAX *\n# *********************************************\n_cufftmp_prim = core.Primitive(\"cufftmp\")\n_cufftmp_prim.multiple_results = True\n_cufftmp_prim.def_impl(partial(xla.apply_primitive, _cufftmp_prim))\n_cufftmp_prim.def_abstract_eval(_cufftmp_abstract)\n\n# Register the op with MLIR\nmlir.register_lowering(_cufftmp_prim, _cufftmp_lowering, platform=\"gpu\")","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._cufftmp_bind","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._cufftmp_bind#L46-L61","kind":"function","name":"_cufftmp_bind","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":46,"end_line":61,"context_start_line":26,"context_end_line":81,"code":"from jax import core, dtypes\nfrom jax.interpreters import xla, mlir\nfrom jax.core import ShapedArray\nfrom jax.sharding import NamedSharding\nfrom jax.experimental.custom_partitioning import custom_partitioning\nfrom jaxlib.hlo_helpers import custom_call\n\nfrom fft_common import Dir, Dist\n\nfrom . import gpu_ops\nfor _name, _value in gpu_ops.registrations().items():\n xla_client.register_custom_call_target(_name, _value, platform=\"gpu\")\n\nxops = xla_client.ops\n\n# ************\n# * BINDINGS *\n# ************\n\n\ndef _cufftmp_bind(input, num_parts, dist, dir):\n\n # param=val means it's a static parameter\n (output,) = _cufftmp_prim.bind(input,\n num_parts=num_parts,\n dist=dist,\n dir=dir)\n\n # scale in INVERSE direction\n if dir == Dir.INV:\n fft_dims = dist.fft_shape(input.shape)\n output = jax.numpy.divide(output, math.prod([\n jax.numpy.complex64(f) for f in fft_dims\n ]))\n\n return output\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n \"\"\" Describes the required input and output sharding of the op.\n `mesh`, `arg_shapes` and `result_shape` are the shapes provided by the\n user (i.e., in jit).\n Returns:\n - The operation to perform locally on all GPUs\n - The output sharding\n - The input sharding \"\"\"\n ","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._supported_sharding","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._supported_sharding#L64-L65","kind":"function","name":"_supported_sharding","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":64,"end_line":65,"context_start_line":44,"context_end_line":85,"code":"\n\ndef _cufftmp_bind(input, num_parts, dist, dir):\n\n # param=val means it's a static parameter\n (output,) = _cufftmp_prim.bind(input,\n num_parts=num_parts,\n dist=dist,\n dir=dir)\n\n # scale in INVERSE direction\n if dir == Dir.INV:\n fft_dims = dist.fft_shape(input.shape)\n output = jax.numpy.divide(output, math.prod([\n jax.numpy.complex64(f) for f in fft_dims\n ]))\n\n return output\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n \"\"\" Describes the required input and output sharding of the op.\n `mesh`, `arg_shapes` and `result_shape` are the shapes provided by the\n user (i.e., in jit).\n Returns:\n - The operation to perform locally on all GPUs\n - The output sharding\n - The input sharding \"\"\"\n \n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n\n return mesh, \\\n lambda x: _cufftmp_bind(x,","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._partition","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._partition#L68-L90","kind":"function","name":"_partition","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":68,"end_line":90,"context_start_line":48,"context_end_line":110,"code":" # param=val means it's a static parameter\n (output,) = _cufftmp_prim.bind(input,\n num_parts=num_parts,\n dist=dist,\n dir=dir)\n\n # scale in INVERSE direction\n if dir == Dir.INV:\n fft_dims = dist.fft_shape(input.shape)\n output = jax.numpy.divide(output, math.prod([\n jax.numpy.complex64(f) for f in fft_dims\n ]))\n\n return output\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n \"\"\" Describes the required input and output sharding of the op.\n `mesh`, `arg_shapes` and `result_shape` are the shapes provided by the\n user (i.e., in jit).\n Returns:\n - The operation to perform locally on all GPUs\n - The output sharding\n - The input sharding \"\"\"\n \n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n\n return mesh, \\\n lambda x: _cufftmp_bind(x,\n num_parts=jax.device_count(),\n dist=dist,\n dir=dir), \\\n _supported_sharding(arg_shardings[0], dist.opposite), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef cufftmp(x, dist, dir):\n\n \"\"\"Compute the DFT using a JAX+cuFFTMp implementation.\n\n Arguments:\n x -- the input tensor\n dist -- the data decomposition of x.\n Should be an instance of fft_common.Dist","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._infer_sharding_from_operands","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._infer_sharding_from_operands#L93-L100","kind":"function","name":"_infer_sharding_from_operands","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":93,"end_line":100,"context_start_line":73,"context_end_line":120,"code":"\n \"\"\" Describes the required input and output sharding of the op.\n `mesh`, `arg_shapes` and `result_shape` are the shapes provided by the\n user (i.e., in jit).\n Returns:\n - The operation to perform locally on all GPUs\n - The output sharding\n - The input sharding \"\"\"\n \n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n\n return mesh, \\\n lambda x: _cufftmp_bind(x,\n num_parts=jax.device_count(),\n dist=dist,\n dir=dir), \\\n _supported_sharding(arg_shardings[0], dist.opposite), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef cufftmp(x, dist, dir):\n\n \"\"\"Compute the DFT using a JAX+cuFFTMp implementation.\n\n Arguments:\n x -- the input tensor\n dist -- the data decomposition of x.\n Should be an instance of fft_common.Dist\n dir -- the direction of the transform.\n Should be an instance of fft_common.Dir\n\n Returns the transformed tensor.\n The output tensoris distributed according to dist.opposite\n\n This function should be used with jit like\n\n jit(\n cufftmp,","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax.cufftmp","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax.cufftmp#L103-L145","kind":"function","name":"cufftmp","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":103,"end_line":145,"context_start_line":83,"context_end_line":165,"code":"\n return mesh, \\\n lambda x: _cufftmp_bind(x,\n num_parts=jax.device_count(),\n dist=dist,\n dir=dir), \\\n _supported_sharding(arg_shardings[0], dist.opposite), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef cufftmp(x, dist, dir):\n\n \"\"\"Compute the DFT using a JAX+cuFFTMp implementation.\n\n Arguments:\n x -- the input tensor\n dist -- the data decomposition of x.\n Should be an instance of fft_common.Dist\n dir -- the direction of the transform.\n Should be an instance of fft_common.Dir\n\n Returns the transformed tensor.\n The output tensoris distributed according to dist.opposite\n\n This function should be used with jit like\n\n jit(\n cufftmp,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2]\n )(x, dist, dir)\n\n \"\"\"\n\n # cuFFTMp only supports 1 device per proces\n assert jax.local_device_count() == 1\n\n @custom_partitioning\n def _cufftmp_(x):\n return _cufftmp_bind(x, num_parts=1, dist=dist, dir=dir)\n\n _cufftmp_.def_partition(\n infer_sharding_from_operands=partial(\n _infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(\n _partition,\n dist=dist,\n dir=dir))\n\n return _cufftmp_(x)\n\n\n# *********************************\n# * SUPPORT FOR JIT COMPILATION *\n# *********************************\n\n# Abstract implementation, i.e., return the shape of the output array\n# based on the input array and a number of partitions (ie devices)\ndef _cufftmp_abstract(input, num_parts, dist, dir):\n dtype = dtypes.canonicalize_dtype(input.dtype)\n input_shape = input.shape\n if dist == Dist.SLABS_X:\n output_shape = (input_shape[0] * num_parts,\n input_shape[1] // num_parts,\n *input_shape[2:])\n elif dist == Dist.SLABS_Y:\n output_shape = (input_shape[0] // num_parts,\n input_shape[1] * num_parts,\n *input_shape[2:])\n return (ShapedArray(output_shape, dtype),)","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._cufftmp_abstract","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._cufftmp_abstract#L154-L165","kind":"function","name":"_cufftmp_abstract","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":154,"end_line":165,"context_start_line":134,"context_end_line":185,"code":"\n _cufftmp_.def_partition(\n infer_sharding_from_operands=partial(\n _infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(\n _partition,\n dist=dist,\n dir=dir))\n\n return _cufftmp_(x)\n\n\n# *********************************\n# * SUPPORT FOR JIT COMPILATION *\n# *********************************\n\n# Abstract implementation, i.e., return the shape of the output array\n# based on the input array and a number of partitions (ie devices)\ndef _cufftmp_abstract(input, num_parts, dist, dir):\n dtype = dtypes.canonicalize_dtype(input.dtype)\n input_shape = input.shape\n if dist == Dist.SLABS_X:\n output_shape = (input_shape[0] * num_parts,\n input_shape[1] // num_parts,\n *input_shape[2:])\n elif dist == Dist.SLABS_Y:\n output_shape = (input_shape[0] // num_parts,\n input_shape[1] * num_parts,\n *input_shape[2:])\n return (ShapedArray(output_shape, dtype),)\n\n\n# Implementation calling into the C++ bindings\ndef _cufftmp_lowering(ctx, input, num_parts, dist, dir):\n\n assert num_parts == jax.device_count()\n\n input_type = mlir.ir.RankedTensorType(input.type)\n dims_in = input_type.shape\n fft_dims = dist.fft_shape(dims_in)\n dims_out = dist.opposite.slab_shape(fft_dims)\n output_type = mlir.ir.RankedTensorType.get(\n dims_out,\n input_type.element_type\n )\n\n layout = tuple(range(len(dims_in) - 1, -1, -1))\n\n if len(fft_dims) == 2:\n opaque = gpu_ops.build_cufftmp_descriptor(","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._cufftmp_lowering","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._cufftmp_lowering#L169-L214","kind":"function","name":"_cufftmp_lowering","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":169,"end_line":214,"context_start_line":149,"context_end_line":226,"code":"# * SUPPORT FOR JIT COMPILATION *\n# *********************************\n\n# Abstract implementation, i.e., return the shape of the output array\n# based on the input array and a number of partitions (ie devices)\ndef _cufftmp_abstract(input, num_parts, dist, dir):\n dtype = dtypes.canonicalize_dtype(input.dtype)\n input_shape = input.shape\n if dist == Dist.SLABS_X:\n output_shape = (input_shape[0] * num_parts,\n input_shape[1] // num_parts,\n *input_shape[2:])\n elif dist == Dist.SLABS_Y:\n output_shape = (input_shape[0] // num_parts,\n input_shape[1] * num_parts,\n *input_shape[2:])\n return (ShapedArray(output_shape, dtype),)\n\n\n# Implementation calling into the C++ bindings\ndef _cufftmp_lowering(ctx, input, num_parts, dist, dir):\n\n assert num_parts == jax.device_count()\n\n input_type = mlir.ir.RankedTensorType(input.type)\n dims_in = input_type.shape\n fft_dims = dist.fft_shape(dims_in)\n dims_out = dist.opposite.slab_shape(fft_dims)\n output_type = mlir.ir.RankedTensorType.get(\n dims_out,\n input_type.element_type\n )\n\n layout = tuple(range(len(dims_in) - 1, -1, -1))\n\n if len(fft_dims) == 2:\n opaque = gpu_ops.build_cufftmp_descriptor(\n fft_dims[0],\n fft_dims[1],\n 1,\n dist._C_enum,\n dir._C_enum\n )\n elif len(fft_dims) == 3:\n opaque = gpu_ops.build_cufftmp_descriptor(\n fft_dims[0],\n fft_dims[1],\n fft_dims[2],\n dist._C_enum,\n dir._C_enum\n )\n else:\n raise ValueError(\"Unsupported tensor rank; must be 2 or 3\")\n\n return custom_call(\n \"gpu_cufftmp\",\n # Output types\n result_types=[output_type],\n # The inputs:\n operands=[input,],\n # Layout specification:\n operand_layouts=[layout,],\n result_layouts=[layout,],\n # GPU specific additional data\n backend_config=opaque\n ).results\n\n\n# *********************************************\n# * BOILERPLATE TO REGISTER THE OP WITH JAX *\n# *********************************************\n_cufftmp_prim = core.Primitive(\"cufftmp\")\n_cufftmp_prim.multiple_results = True\n_cufftmp_prim.def_impl(partial(xla.apply_primitive, _cufftmp_prim))\n_cufftmp_prim.def_abstract_eval(_cufftmp_abstract)\n\n# Register the op with MLIR\nmlir.register_lowering(_cufftmp_prim, _cufftmp_lowering, platform=\"gpu\")","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._cufftmp_","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.cufftmp_jax.cufftmp_jax._cufftmp_#L132-L133","kind":"function","name":"_cufftmp_","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":132,"end_line":133,"context_start_line":112,"context_end_line":153,"code":" Should be an instance of fft_common.Dir\n\n Returns the transformed tensor.\n The output tensoris distributed according to dist.opposite\n\n This function should be used with jit like\n\n jit(\n cufftmp,\n in_shardings=sharding,\n out_shardings=sharding,\n static_argnums=[1, 2]\n )(x, dist, dir)\n\n \"\"\"\n\n # cuFFTMp only supports 1 device per proces\n assert jax.local_device_count() == 1\n\n @custom_partitioning\n def _cufftmp_(x):\n return _cufftmp_bind(x, num_parts=1, dist=dist, dir=dir)\n\n _cufftmp_.def_partition(\n infer_sharding_from_operands=partial(\n _infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(\n _partition,\n dist=dist,\n dir=dir))\n\n return _cufftmp_(x)\n\n\n# *********************************\n# * SUPPORT FOR JIT COMPILATION *\n# *********************************\n\n# Abstract implementation, i.e., return the shape of the output array\n# based on the input array and a number of partitions (ie devices)","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.xfft.xfft","uri":"program://CUDALibrarySamples/module/cuFFTMp.JAX_FFT.src.xfft.xfft#L1-L110","kind":"module","name":"cuFFTMp.JAX_FFT.src.xfft.xfft","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":1,"end_line":110,"context_start_line":1,"context_end_line":110,"code":"# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom functools import partial\n\nimport jax\nfrom jax.sharding import NamedSharding\nfrom jax.experimental.custom_partitioning import custom_partitioning\nfrom fft_common import Dir\n\n\ndef _fft(x, dist, dir):\n\n \"\"\" Compute a local FFT along the appropriate axes (based on dist), in the\n forward or backward direction \"\"\"\n\n if dir == Dir.FWD:\n return jax.numpy.fft.fftn(x, axes=dist.fft_axes(len(x.shape)))\n else:\n return jax.numpy.fft.ifftn(x, axes=dist.fft_axes(len(x.shape)))\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return mesh, lambda x: _fft(x, dist, dir), \\\n _supported_sharding(arg_shardings[0], dist), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef fft(x, dist, dir):\n\n \"\"\" Extends jax.numpy.fft.fftn to support sharding along the first or\n second direction, without intermediate re-sharding \"\"\"\n\n @custom_partitioning\n def _fft_(x):\n return _fft(x, dist, dir)\n\n _fft_.def_partition(\n infer_sharding_from_operands=partial(_infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(_partition, dist=dist, dir=dir))\n\n return _fft_(x)\n\n\ndef xfft(x, dist, dir):\n\n \"\"\"Compute the discrete Fourier transform using a JAX-only implementation.\n\n Arguments:\n x -- the input tensor\n dist -- the data decomposition of x.\n Should be an instance of fft_common.Dist\n dir -- the direction of the transform.\n Should be an instance of fft_common.Dir\n\n Returns the transformed tensor.\n The output tensoris distributed according to dist.opposite\n\n This function should be used with jit like\n\n jit(xfft,\n in_shardings=sharding,\n out_shardings=sharding_opposite,\n static_argnums=[1, 2]\n )(x, dist, dir)\n \"\"\"\n\n # If dist == Dist.SLABS_X, FFT along Y and Z\n x = fft(x, dist, dir)\n\n # Implicitly re-shards to match the required\n # input sharding of the next fft(..., dist.opposite, ...)\n\n # If dist == Dist.SLABS_X, FFT along X\n x = fft(x, dist.opposite, dir)\n\n return x","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.xfft.xfft._fft","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.xfft.xfft._fft#L24-L32","kind":"function","name":"_fft","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":24,"end_line":32,"context_start_line":4,"context_end_line":52,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom functools import partial\n\nimport jax\nfrom jax.sharding import NamedSharding\nfrom jax.experimental.custom_partitioning import custom_partitioning\nfrom fft_common import Dir\n\n\ndef _fft(x, dist, dir):\n\n \"\"\" Compute a local FFT along the appropriate axes (based on dist), in the\n forward or backward direction \"\"\"\n\n if dir == Dir.FWD:\n return jax.numpy.fft.fftn(x, axes=dist.fft_axes(len(x.shape)))\n else:\n return jax.numpy.fft.ifftn(x, axes=dist.fft_axes(len(x.shape)))\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return mesh, lambda x: _fft(x, dist, dir), \\\n _supported_sharding(arg_shardings[0], dist), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.xfft.xfft._supported_sharding","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.xfft.xfft._supported_sharding#L35-L36","kind":"function","name":"_supported_sharding","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":35,"end_line":36,"context_start_line":15,"context_end_line":56,"code":"\nfrom functools import partial\n\nimport jax\nfrom jax.sharding import NamedSharding\nfrom jax.experimental.custom_partitioning import custom_partitioning\nfrom fft_common import Dir\n\n\ndef _fft(x, dist, dir):\n\n \"\"\" Compute a local FFT along the appropriate axes (based on dist), in the\n forward or backward direction \"\"\"\n\n if dir == Dir.FWD:\n return jax.numpy.fft.fftn(x, axes=dist.fft_axes(len(x.shape)))\n else:\n return jax.numpy.fft.ifftn(x, axes=dist.fft_axes(len(x.shape)))\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return mesh, lambda x: _fft(x, dist, dir), \\\n _supported_sharding(arg_shardings[0], dist), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.xfft.xfft._partition","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.xfft.xfft._partition#L39-L48","kind":"function","name":"_partition","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":39,"end_line":48,"context_start_line":19,"context_end_line":68,"code":"from jax.sharding import NamedSharding\nfrom jax.experimental.custom_partitioning import custom_partitioning\nfrom fft_common import Dir\n\n\ndef _fft(x, dist, dir):\n\n \"\"\" Compute a local FFT along the appropriate axes (based on dist), in the\n forward or backward direction \"\"\"\n\n if dir == Dir.FWD:\n return jax.numpy.fft.fftn(x, axes=dist.fft_axes(len(x.shape)))\n else:\n return jax.numpy.fft.ifftn(x, axes=dist.fft_axes(len(x.shape)))\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return mesh, lambda x: _fft(x, dist, dir), \\\n _supported_sharding(arg_shardings[0], dist), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef fft(x, dist, dir):\n\n \"\"\" Extends jax.numpy.fft.fftn to support sharding along the first or\n second direction, without intermediate re-sharding \"\"\"\n\n @custom_partitioning\n def _fft_(x):\n return _fft(x, dist, dir)\n","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.xfft.xfft._infer_sharding_from_operands","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.xfft.xfft._infer_sharding_from_operands#L51-L57","kind":"function","name":"_infer_sharding_from_operands","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":51,"end_line":57,"context_start_line":31,"context_end_line":77,"code":" else:\n return jax.numpy.fft.ifftn(x, axes=dist.fft_axes(len(x.shape)))\n\n\ndef _supported_sharding(sharding, dist):\n return NamedSharding(sharding.mesh, dist.part_spec)\n\n\ndef _partition(mesh, \n arg_shapes,\n result_shape, \n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return mesh, lambda x: _fft(x, dist, dir), \\\n _supported_sharding(arg_shardings[0], dist), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef fft(x, dist, dir):\n\n \"\"\" Extends jax.numpy.fft.fftn to support sharding along the first or\n second direction, without intermediate re-sharding \"\"\"\n\n @custom_partitioning\n def _fft_(x):\n return _fft(x, dist, dir)\n\n _fft_.def_partition(\n infer_sharding_from_operands=partial(_infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(_partition, dist=dist, dir=dir))\n\n return _fft_(x)\n\n","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.xfft.xfft.fft","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.xfft.xfft.fft#L60-L75","kind":"function","name":"fft","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":60,"end_line":75,"context_start_line":40,"context_end_line":95,"code":" arg_shapes,\n result_shape, \n dist,\n dir):\n\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return mesh, lambda x: _fft(x, dist, dir), \\\n _supported_sharding(arg_shardings[0], dist), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef fft(x, dist, dir):\n\n \"\"\" Extends jax.numpy.fft.fftn to support sharding along the first or\n second direction, without intermediate re-sharding \"\"\"\n\n @custom_partitioning\n def _fft_(x):\n return _fft(x, dist, dir)\n\n _fft_.def_partition(\n infer_sharding_from_operands=partial(_infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(_partition, dist=dist, dir=dir))\n\n return _fft_(x)\n\n\ndef xfft(x, dist, dir):\n\n \"\"\"Compute the discrete Fourier transform using a JAX-only implementation.\n\n Arguments:\n x -- the input tensor\n dist -- the data decomposition of x.\n Should be an instance of fft_common.Dist\n dir -- the direction of the transform.\n Should be an instance of fft_common.Dir\n\n Returns the transformed tensor.\n The output tensoris distributed according to dist.opposite\n\n This function should be used with jit like\n\n jit(xfft,\n in_shardings=sharding,","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.xfft.xfft.xfft","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.xfft.xfft.xfft#L78-L110","kind":"function","name":"xfft","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":78,"end_line":110,"context_start_line":58,"context_end_line":110,"code":"\n\ndef fft(x, dist, dir):\n\n \"\"\" Extends jax.numpy.fft.fftn to support sharding along the first or\n second direction, without intermediate re-sharding \"\"\"\n\n @custom_partitioning\n def _fft_(x):\n return _fft(x, dist, dir)\n\n _fft_.def_partition(\n infer_sharding_from_operands=partial(_infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(_partition, dist=dist, dir=dir))\n\n return _fft_(x)\n\n\ndef xfft(x, dist, dir):\n\n \"\"\"Compute the discrete Fourier transform using a JAX-only implementation.\n\n Arguments:\n x -- the input tensor\n dist -- the data decomposition of x.\n Should be an instance of fft_common.Dist\n dir -- the direction of the transform.\n Should be an instance of fft_common.Dir\n\n Returns the transformed tensor.\n The output tensoris distributed according to dist.opposite\n\n This function should be used with jit like\n\n jit(xfft,\n in_shardings=sharding,\n out_shardings=sharding_opposite,\n static_argnums=[1, 2]\n )(x, dist, dir)\n \"\"\"\n\n # If dist == Dist.SLABS_X, FFT along Y and Z\n x = fft(x, dist, dir)\n\n # Implicitly re-shards to match the required\n # input sharding of the next fft(..., dist.opposite, ...)\n\n # If dist == Dist.SLABS_X, FFT along X\n x = fft(x, dist.opposite, dir)\n\n return x","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuFFTMp.JAX_FFT.src.xfft.xfft._fft_","uri":"program://CUDALibrarySamples/function/cuFFTMp.JAX_FFT.src.xfft.xfft._fft_#L66-L67","kind":"function","name":"_fft_","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":66,"end_line":67,"context_start_line":46,"context_end_line":87,"code":" return mesh, lambda x: _fft(x, dist, dir), \\\n _supported_sharding(arg_shardings[0], dist), \\\n (_supported_sharding(arg_shardings[0], dist),)\n\n\ndef _infer_sharding_from_operands(mesh,\n arg_shapes,\n result_shape,\n dist,\n dir):\n arg_shardings = jax.tree.map(lambda x: x.sharding, arg_shapes)\n return _supported_sharding(arg_shardings[0], dist)\n\n\ndef fft(x, dist, dir):\n\n \"\"\" Extends jax.numpy.fft.fftn to support sharding along the first or\n second direction, without intermediate re-sharding \"\"\"\n\n @custom_partitioning\n def _fft_(x):\n return _fft(x, dist, dir)\n\n _fft_.def_partition(\n infer_sharding_from_operands=partial(_infer_sharding_from_operands,\n dist=dist,\n dir=dir),\n partition=partial(_partition, dist=dist, dir=dir))\n\n return _fft_(x)\n\n\ndef xfft(x, dist, dir):\n\n \"\"\"Compute the discrete Fourier transform using a JAX-only implementation.\n\n Arguments:\n x -- the input tensor\n dist -- the data decomposition of x.\n Should be an instance of fft_common.Dist\n dir -- the direction of the transform.\n Should be an instance of fft_common.Dir","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk_gradient_rhf.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.3_density_fitting.core_df_jk_gradient_rhf.run#L1-L572","kind":"module","name":"cuEST.python_examples.3_density_fitting.core_df_jk_gradient_rhf.run","path":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_rhf/run.py","language":"python","start_line":1,"end_line":572,"context_start_line":1,"context_end_line":572,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n aux_gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n # Orbital Basis\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n # Auxilliary Basis\n aux_shells = []\n aux_n_shells_per_atom = []\n shell_count = 1\n for atom_shells in aux_shellinfo:\n aux_n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n aux_shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n # Auxilliary Basis\n auxbasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n auxbasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n auxbasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspace=auxbasis_persistent_workspace.pointer,\n temporaryWorkspace=auxbasis_temporary_workspace.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n del auxbasis_temporary_workspace\n\n for i, shell in enumerate(aux_shells):\n cuest_check(f'Destroy Aux AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build DF Integral Plan <= #\n\n dfintplan_handle = ce.cuestDFIntPlanHandle()\n dfintplan_parameters = ce.cuestDFIntPlanParameters()\n cuest_check('Create DFIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n outParameters=dfintplan_parameters,\n )\n )\n\n cuest_check('Create DFIntPlan Workspace Query',\n ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n print(\"DFIntPlan Persistent sizes:\", persistent_workspace_descriptor)\n print(\"DFIntPlan Temporary sizes:\", temporary_workspace_descriptor)\n\n dfintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n dfintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n\n cuest_check('Create DFIntPlan',\n ce.cuestDFIntPlanCreate(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspace=dfintplan_persistent_workspace.pointer,\n temporaryWorkspace=dfintplan_temporary_workspace.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n del dfintplan_temporary_workspace\n\n cuest_check('Destroy DFIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=dfintplan_parameters,\n )\n )\n\n # => Build Fake Density Matrix / Occupied Orbitals <= #\n\n nocc = int(np.abs(np.sum(Zs))//2)\n natom = len(Zs)\n\n densitymatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n densitymatrix_device_handle = ce.Pointer()\n densitymatrix_device_handle.value = densitymatrix_device_pointer\n densitymatrix_host_array = np.random.normal(size=(nao, nao)).astype(np.double)\n densitymatrix_host_array = np.ravel(densitymatrix_host_array + densitymatrix_host_array.T)\n cuda_memcpy_htod(\n device_pointer=densitymatrix_device_pointer,\n host_pointer=densitymatrix_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n # Occupied MO coefficients\n occorbitals_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n occorbitals_device_handle = ce.Pointer()\n occorbitals_device_handle.value = occorbitals_device_pointer\n occorbitals_host_array = np.random.normal(size=nocc * nao).astype(np.double)\n cuda_memcpy_htod(\n device_pointer=occorbitals_device_pointer,\n host_pointer=occorbitals_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n )\n\n # Allow the algorithm to use up to 2GB of DRAM\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000\n )\n\n compute_JK_gradient_parameters = ce.cuestDFSymmetricDerivativeComputeParameters()\n cuest_check('Create JK Grad Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=compute_JK_gradient_parameters,\n )\n )\n\n JKgrad_device_handle = ce.Pointer()\n cuest_check('Compute JK Gradient Workspace Query',\n ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_JK_gradient_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=2.0,\n densityMatrix=densitymatrix_device_handle,\n coefficientScale=-1.0,\n numCoefficientMatrices=1,\n numOccupied=[nocc,],\n coefficientMatrices=occorbitals_device_handle,\n outGradient=JKgrad_device_handle,\n )\n )\n\n JKgrad_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n JKgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * natom * 3,\n )\n JKgrad_device_handle.value = np.intp(JKgrad_device_pointer)\n cuest_check('Compute JK Gradient',\n ce.cuestDFSymmetricDerivativeCompute(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_JK_gradient_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=JKgrad_temporary_workspace.pointer,\n densityScale=2.0, # The scale factor for the J term\n densityMatrix=densitymatrix_device_handle,\n coefficientScale=-1.0, # This should be further scaled by the HF X scale factor for hybrid DFT\n numCoefficientMatrices=1,\n numOccupied=[nocc,],\n coefficientMatrices=occorbitals_device_handle,\n outGradient=JKgrad_device_handle,\n )\n )\n\n cuest_check('Destroy JK Grad Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=compute_JK_gradient_parameters,\n )\n )\n\n cuda_free(\n array=occorbitals_device_pointer\n )\n cuda_free(\n array=densitymatrix_device_pointer\n )\n\n del JKgrad_temporary_workspace\n\n JKgrad_host_array = np.empty(\n (natom, 3),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=JKgrad_host_array.ctypes.data,\n device_pointer=JKgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * natom,\n )\n\n cuda_free(\n array=JKgrad_device_pointer\n )\n\n # => Cleanup <= #\n\n cuest_check('Destroy DFIntPlan',\n ce.cuestDFIntPlanDestroy(\n handle=dfintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n handle=aopairlist_handle,\n )\n )\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n cuest_check('Destroy Aux AOBasis',\n ce.cuestAOBasisDestroy(\n handle=auxbasis_handle,\n )\n )\n\n del dfintplan_persistent_workspace\n del aopairlist_persistent_workspace\n del aobasis_persistent_workspace\n del auxbasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Run using XYZ and GBS files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"The file with molecular coordinates (Angstrom) in basic xyz format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"The basis set file in G94/Psi4 GBS format.\"\n )\n parser.add_argument(\n \"aux_gbs_filename\",\n type=str,\n help=\"The auxilliary basis set file in G94/Psi4 GBS format.\"\n )\n\n args = parser.parse_args()\n\n run(\n xyz_filename=args.xyz_filename,\n gbs_filename=args.gbs_filename,\n aux_gbs_filename=args.aux_gbs_filename,\n )\n","source_hash":"5a4b5a74876ebbf1e8d1f4937ac408a03122ac8aeb69a63ddf668f7e8c61d418","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk_gradient_rhf.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.3_density_fitting.core_df_jk_gradient_rhf.run.run#L29-L543","kind":"function","name":"run","path":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_rhf/run.py","language":"python","start_line":29,"end_line":543,"context_start_line":9,"context_end_line":563,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n aux_gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n # Orbital Basis\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n # Auxilliary Basis\n aux_shells = []\n aux_n_shells_per_atom = []\n shell_count = 1\n for atom_shells in aux_shellinfo:\n aux_n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n aux_shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n # Auxilliary Basis\n auxbasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n auxbasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n auxbasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspace=auxbasis_persistent_workspace.pointer,\n temporaryWorkspace=auxbasis_temporary_workspace.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n del auxbasis_temporary_workspace\n\n for i, shell in enumerate(aux_shells):\n cuest_check(f'Destroy Aux AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build DF Integral Plan <= #\n\n dfintplan_handle = ce.cuestDFIntPlanHandle()\n dfintplan_parameters = ce.cuestDFIntPlanParameters()\n cuest_check('Create DFIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n outParameters=dfintplan_parameters,\n )\n )\n\n cuest_check('Create DFIntPlan Workspace Query',\n ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n print(\"DFIntPlan Persistent sizes:\", persistent_workspace_descriptor)\n print(\"DFIntPlan Temporary sizes:\", temporary_workspace_descriptor)\n\n dfintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n dfintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n\n cuest_check('Create DFIntPlan',\n ce.cuestDFIntPlanCreate(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspace=dfintplan_persistent_workspace.pointer,\n temporaryWorkspace=dfintplan_temporary_workspace.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n del dfintplan_temporary_workspace\n\n cuest_check('Destroy DFIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=dfintplan_parameters,\n )\n )\n\n # => Build Fake Density Matrix / Occupied Orbitals <= #\n\n nocc = int(np.abs(np.sum(Zs))//2)\n natom = len(Zs)\n\n densitymatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n densitymatrix_device_handle = ce.Pointer()\n densitymatrix_device_handle.value = densitymatrix_device_pointer\n densitymatrix_host_array = np.random.normal(size=(nao, nao)).astype(np.double)\n densitymatrix_host_array = np.ravel(densitymatrix_host_array + densitymatrix_host_array.T)\n cuda_memcpy_htod(\n device_pointer=densitymatrix_device_pointer,\n host_pointer=densitymatrix_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n # Occupied MO coefficients\n occorbitals_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n occorbitals_device_handle = ce.Pointer()\n occorbitals_device_handle.value = occorbitals_device_pointer\n occorbitals_host_array = np.random.normal(size=nocc * nao).astype(np.double)\n cuda_memcpy_htod(\n device_pointer=occorbitals_device_pointer,\n host_pointer=occorbitals_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n )\n\n # Allow the algorithm to use up to 2GB of DRAM\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000\n )\n\n compute_JK_gradient_parameters = ce.cuestDFSymmetricDerivativeComputeParameters()\n cuest_check('Create JK Grad Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=compute_JK_gradient_parameters,\n )\n )\n\n JKgrad_device_handle = ce.Pointer()\n cuest_check('Compute JK Gradient Workspace Query',\n ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_JK_gradient_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=2.0,\n densityMatrix=densitymatrix_device_handle,\n coefficientScale=-1.0,\n numCoefficientMatrices=1,\n numOccupied=[nocc,],\n coefficientMatrices=occorbitals_device_handle,\n outGradient=JKgrad_device_handle,\n )\n )\n\n JKgrad_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n JKgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * natom * 3,\n )\n JKgrad_device_handle.value = np.intp(JKgrad_device_pointer)\n cuest_check('Compute JK Gradient',\n ce.cuestDFSymmetricDerivativeCompute(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_JK_gradient_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=JKgrad_temporary_workspace.pointer,\n densityScale=2.0, # The scale factor for the J term\n densityMatrix=densitymatrix_device_handle,\n coefficientScale=-1.0, # This should be further scaled by the HF X scale factor for hybrid DFT\n numCoefficientMatrices=1,\n numOccupied=[nocc,],\n coefficientMatrices=occorbitals_device_handle,\n outGradient=JKgrad_device_handle,\n )\n )\n\n cuest_check('Destroy JK Grad Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=compute_JK_gradient_parameters,\n )\n )\n\n cuda_free(\n array=occorbitals_device_pointer\n )\n cuda_free(\n array=densitymatrix_device_pointer\n )\n\n del JKgrad_temporary_workspace\n\n JKgrad_host_array = np.empty(\n (natom, 3),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=JKgrad_host_array.ctypes.data,\n device_pointer=JKgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * natom,\n )\n\n cuda_free(\n array=JKgrad_device_pointer\n )\n\n # => Cleanup <= #\n\n cuest_check('Destroy DFIntPlan',\n ce.cuestDFIntPlanDestroy(\n handle=dfintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n handle=aopairlist_handle,\n )\n )\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n cuest_check('Destroy Aux AOBasis',\n ce.cuestAOBasisDestroy(\n handle=auxbasis_handle,\n )\n )\n\n del dfintplan_persistent_workspace\n del aopairlist_persistent_workspace\n del aobasis_persistent_workspace\n del auxbasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Run using XYZ and GBS files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"The file with molecular coordinates (Angstrom) in basic xyz format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"The basis set file in G94/Psi4 GBS format.\"\n )\n parser.add_argument(\n \"aux_gbs_filename\",\n type=str,\n help=\"The auxilliary basis set file in G94/Psi4 GBS format.\"\n )","source_hash":"5a4b5a74876ebbf1e8d1f4937ac408a03122ac8aeb69a63ddf668f7e8c61d418","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk_gradient_rhf.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.3_density_fitting.core_df_jk_gradient_rhf.run.cuest_check#L58-L65","kind":"function","name":"cuest_check","path":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_rhf/run.py","language":"python","start_line":58,"end_line":65,"context_start_line":38,"context_end_line":85,"code":" symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(","source_hash":"5a4b5a74876ebbf1e8d1f4937ac408a03122ac8aeb69a63ddf668f7e8c61d418","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.3_density_fitting.core_df_jk.run#L1-L629","kind":"module","name":"cuEST.python_examples.3_density_fitting.core_df_jk.run","path":"cuEST/python_examples/3_density_fitting/core_df_jk/run.py","language":"python","start_line":1,"end_line":629,"context_start_line":1,"context_end_line":629,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n aux_gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n # Orbital Basis\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n # Auxilliary Basis\n aux_shells = []\n aux_n_shells_per_atom = []\n shell_count = 1\n for atom_shells in aux_shellinfo:\n aux_n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n aux_shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n # Auxilliary Basis\n auxbasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n auxbasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n auxbasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspace=auxbasis_persistent_workspace.pointer,\n temporaryWorkspace=auxbasis_temporary_workspace.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n del auxbasis_temporary_workspace\n\n for i, shell in enumerate(aux_shells):\n cuest_check(f'Destroy Aux AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build Fake Density Matrix / Occupied Orbitals <= #\n\n densitymatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n densitymatrix_device_handle = ce.Pointer()\n densitymatrix_device_handle.value = densitymatrix_device_pointer\n densitymatrix_host_array = np.random.normal(size=(nao, nao)).astype(np.double)\n densitymatrix_host_array = np.ravel(densitymatrix_host_array + densitymatrix_host_array.T)\n cuda_memcpy_htod(\n device_pointer=densitymatrix_device_pointer,\n host_pointer=densitymatrix_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n nocc = int(np.abs(np.sum(Zs)//2))\n occorbitals_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n occorbitals_device_handle = ce.Pointer()\n occorbitals_device_handle.value = occorbitals_device_pointer\n occorbitals_host_array = np.random.normal(size=nocc*nao).astype(np.double)\n cuda_memcpy_htod(\n device_pointer=occorbitals_device_pointer,\n host_pointer=occorbitals_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n )\n\n # => Build DF Integral Plan <= #\n\n dfintplan_handle = ce.cuestDFIntPlanHandle()\n dfintplan_parameters = ce.cuestDFIntPlanParameters()\n cuest_check('Create DFIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n outParameters=dfintplan_parameters,\n )\n )\n\n cuest_check('Create DFIntPlan Workspace Query',\n ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n print(\"DFIntPlan Persistent sizes:\", persistent_workspace_descriptor)\n print(\"DFIntPlan Temporary sizes:\", temporary_workspace_descriptor)\n\n dfintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n dfintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n\n cuest_check('Create DFIntPlan',\n ce.cuestDFIntPlanCreate(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspace=dfintplan_persistent_workspace.pointer,\n temporaryWorkspace=dfintplan_temporary_workspace.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n del dfintplan_temporary_workspace\n\n cuest_check('Destroy DFIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=dfintplan_parameters,\n )\n )\n\n # => Coulomb Matrix <= #\n\n coulombmatrix_device_handle = ce.Pointer()\n compute_coulomb_matrix_parameters = ce.cuestDFCoulombComputeParameters()\n cuest_check('Create Coulomb Compute Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFCOULOMBCOMPUTE_PARAMETERS,\n outParameters=compute_coulomb_matrix_parameters,\n )\n )\n\n cuest_check('Compute Coulomb Compute Workspace Query',\n ce.cuestDFCoulombComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_coulomb_matrix_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=densitymatrix_device_handle,\n outCoulombMatrix=coulombmatrix_device_handle,\n )\n )\n\n print(\"CoulombInt Temporary sizes:\", temporary_workspace_descriptor)\n\n coulombint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n coulombmatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n coulombmatrix_device_handle.value = np.intp(coulombmatrix_device_pointer)\n cuest_check('Compute Coulomb Compute',\n ce.cuestDFCoulombCompute(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_coulomb_matrix_parameters,\n temporaryWorkspace=coulombint_temporary_workspace.pointer,\n densityMatrix=densitymatrix_device_handle,\n outCoulombMatrix=coulombmatrix_device_handle,\n )\n )\n\n del coulombint_temporary_workspace\n\n cuest_check('Destroy Coulomb Compute Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFCOULOMBCOMPUTE_PARAMETERS,\n parameters=compute_coulomb_matrix_parameters,\n )\n )\n\n coulombmatrix_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=coulombmatrix_host_array.ctypes.data,\n device_pointer=coulombmatrix_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=coulombmatrix_device_pointer\n )\n\n # => Exchange Matrix <= #\n\n # Allow the algorithm to use up to 2GB of DRAM\n variable_buffer_size = WorkspaceDescriptor(\n device_buffer_size_in_bytes=2000000000\n )\n compute_exchange_matrix_parameters = ce.cuestDFSymmetricExchangeComputeParameters()\n cuest_check('Create Exchange Compute Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n outParameters=compute_exchange_matrix_parameters,\n )\n )\n exchangematrix_device_handle = ce.Pointer()\n\n cuest_check('Compute Exchange Compute Workspace Query',\n ce.cuestDFSymmetricExchangeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_exchange_matrix_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=occorbitals_device_handle,\n outExchangeMatrix=exchangematrix_device_handle,\n )\n )\n\n print(\"ExchangeInt Temporary sizes:\", temporary_workspace_descriptor)\n\n exchangeint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n exchangematrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n exchangematrix_device_handle.value = np.intp(exchangematrix_device_pointer)\n cuest_check('Compute Exchange Compute',\n ce.cuestDFSymmetricExchangeCompute(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_exchange_matrix_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=exchangeint_temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=occorbitals_device_handle,\n outExchangeMatrix=exchangematrix_device_handle,\n )\n )\n\n del exchangeint_temporary_workspace\n\n cuest_check('Destroy Exchange Compute Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n parameters=compute_exchange_matrix_parameters,\n )\n )\n\n exchangematrix_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=exchangematrix_host_array.ctypes.data,\n device_pointer=exchangematrix_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=exchangematrix_device_pointer\n )\n\n # =\n# ... truncated ...","source_hash":"e311612ddde65956938f50e6c78a06229591757cb91a20564279aa201deebd51","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.3_density_fitting.core_df_jk.run.run#L29-L600","kind":"function","name":"run","path":"cuEST/python_examples/3_density_fitting/core_df_jk/run.py","language":"python","start_line":29,"end_line":600,"context_start_line":9,"context_end_line":620,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n aux_gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n # Orbital Basis\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n # Auxilliary Basis\n aux_shells = []\n aux_n_shells_per_atom = []\n shell_count = 1\n for atom_shells in aux_shellinfo:\n aux_n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n aux_shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n # Auxilliary Basis\n auxbasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n auxbasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n auxbasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspace=auxbasis_persistent_workspace.pointer,\n temporaryWorkspace=auxbasis_temporary_workspace.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n del auxbasis_temporary_workspace\n\n for i, shell in enumerate(aux_shells):\n cuest_check(f'Destroy Aux AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build Fake Density Matrix / Occupied Orbitals <= #\n\n densitymatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n densitymatrix_device_handle = ce.Pointer()\n densitymatrix_device_handle.value = densitymatrix_device_pointer\n densitymatrix_host_array = np.random.normal(size=(nao, nao)).astype(np.double)\n densitymatrix_host_array = np.ravel(densitymatrix_host_array + densitymatrix_host_array.T)\n cuda_memcpy_htod(\n device_pointer=densitymatrix_device_pointer,\n host_pointer=densitymatrix_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n nocc = int(np.abs(np.sum(Zs)//2))\n occorbitals_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n occorbitals_device_handle = ce.Pointer()\n occorbitals_device_handle.value = occorbitals_device_pointer\n occorbitals_host_array = np.random.normal(size=nocc*nao).astype(np.double)\n cuda_memcpy_htod(\n device_pointer=occorbitals_device_pointer,\n host_pointer=occorbitals_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n )\n\n # => Build DF Integral Plan <= #\n\n dfintplan_handle = ce.cuestDFIntPlanHandle()\n dfintplan_parameters = ce.cuestDFIntPlanParameters()\n cuest_check('Create DFIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n outParameters=dfintplan_parameters,\n )\n )\n\n cuest_check('Create DFIntPlan Workspace Query',\n ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n print(\"DFIntPlan Persistent sizes:\", persistent_workspace_descriptor)\n print(\"DFIntPlan Temporary sizes:\", temporary_workspace_descriptor)\n\n dfintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n dfintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n\n cuest_check('Create DFIntPlan',\n ce.cuestDFIntPlanCreate(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspace=dfintplan_persistent_workspace.pointer,\n temporaryWorkspace=dfintplan_temporary_workspace.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n del dfintplan_temporary_workspace\n\n cuest_check('Destroy DFIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=dfintplan_parameters,\n )\n )\n\n # => Coulomb Matrix <= #\n\n coulombmatrix_device_handle = ce.Pointer()\n compute_coulomb_matrix_parameters = ce.cuestDFCoulombComputeParameters()\n cuest_check('Create Coulomb Compute Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFCOULOMBCOMPUTE_PARAMETERS,\n outParameters=compute_coulomb_matrix_parameters,\n )\n )\n\n cuest_check('Compute Coulomb Compute Workspace Query',\n ce.cuestDFCoulombComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_coulomb_matrix_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=densitymatrix_device_handle,\n outCoulombMatrix=coulombmatrix_device_handle,\n )\n )\n\n print(\"CoulombInt Temporary sizes:\", temporary_workspace_descriptor)\n\n coulombint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n coulombmatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n coulombmatrix_device_handle.value = np.intp(coulombmatrix_device_pointer)\n cuest_check('Compute Coulomb Compute',\n ce.cuestDFCoulombCompute(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_coulomb_matrix_parameters,\n temporaryWorkspace=coulombint_temporary_workspace.pointer,\n densityMatrix=densitymatrix_device_handle,\n outCoulombMatrix=coulombmatrix_device_handle,\n )\n )\n\n del coulombint_temporary_workspace\n\n cuest_check('Destroy Coulomb Compute Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFCOULOMBCOMPUTE_PARAMETERS,\n parameters=compute_coulomb_matrix_parameters,\n )\n )\n\n coulombmatrix_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=coulombmatrix_host_array.ctypes.data,\n device_pointer=coulombmatrix_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=coulombmatrix_device_pointer\n )\n\n # => Exchange Matrix <= #\n\n # Allow the algorithm to use up to 2GB of DRAM\n variable_buffer_size = WorkspaceDescriptor(\n device_buffer_size_in_bytes=2000000000\n )\n compute_exchange_matrix_parameters = ce.cuestDFSymmetricExchangeComputeParameters()\n cuest_check('Create Exchange Compute Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n outParameters=compute_exchange_matrix_parameters,\n )\n )\n exchangematrix_device_handle = ce.Pointer()\n\n cuest_check('Compute Exchange Compute Workspace Query',\n ce.cuestDFSymmetricExchangeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_exchange_matrix_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=occorbitals_device_handle,\n outExchangeMatrix=exchangematrix_device_handle,\n )\n )\n\n print(\"ExchangeInt Temporary sizes:\", temporary_workspace_descriptor)\n\n exchangeint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n exchangematrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n exchangematrix_device_handle.value = np.intp(exchangematrix_device_pointer)\n cuest_check('Compute Exchange Compute',\n ce.cuestDFSymmetricExchangeCompute(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_exchange_matrix_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=exchangeint_temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=occorbitals_device_handle,\n outExchangeMatrix=exchangematrix_device_handle,\n )\n )\n\n del exchangeint_temporary_workspace\n\n cuest_check('Destroy Exchange Compute Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n parameters=compute_exchange_matrix_parameters,\n )\n )\n\n exchangematrix_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=exchangematrix_host_array.ctypes.data,\n device_pointer=exchangematrix_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=exchangematrix_device_pointer\n )\n\n # => Cleanup <= #\n\n cuda_free(\n array=densitymatrix_device_pointer,\n )\n\n cuda_free(\n array=occorbitals_device_pointer,\n )\n\n cuest_check('Destroy DFIntPlan',\n ce.cuestDFIntPlanDestroy(\n handle=dfintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n# ... truncated ...","source_hash":"e311612ddde65956938f50e6c78a06229591757cb91a20564279aa201deebd51","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.3_density_fitting.core_df_jk.run.cuest_check#L58-L65","kind":"function","name":"cuest_check","path":"cuEST/python_examples/3_density_fitting/core_df_jk/run.py","language":"python","start_line":58,"end_line":65,"context_start_line":38,"context_end_line":85,"code":" symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(","source_hash":"e311612ddde65956938f50e6c78a06229591757cb91a20564279aa201deebd51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk_gradient_uhf.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.3_density_fitting.core_df_jk_gradient_uhf.run#L1-L586","kind":"module","name":"cuEST.python_examples.3_density_fitting.core_df_jk_gradient_uhf.run","path":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_uhf/run.py","language":"python","start_line":1,"end_line":586,"context_start_line":1,"context_end_line":586,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n aux_gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n # Orbital Basis\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n # Auxilliary Basis\n aux_shells = []\n aux_n_shells_per_atom = []\n shell_count = 1\n for atom_shells in aux_shellinfo:\n aux_n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n aux_shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n # Auxilliary Basis\n auxbasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n auxbasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n auxbasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspace=auxbasis_persistent_workspace.pointer,\n temporaryWorkspace=auxbasis_temporary_workspace.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n del auxbasis_temporary_workspace\n\n for i, shell in enumerate(aux_shells):\n cuest_check(f'Destroy Aux AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build DF Integral Plan <= #\n\n dfintplan_handle = ce.cuestDFIntPlanHandle()\n dfintplan_parameters = ce.cuestDFIntPlanParameters()\n cuest_check('Create DFIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n outParameters=dfintplan_parameters,\n )\n )\n\n cuest_check('Create DFIntPlan Workspace Query',\n ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n print(\"DFIntPlan Persistent sizes:\", persistent_workspace_descriptor)\n print(\"DFIntPlan Temporary sizes:\", temporary_workspace_descriptor)\n\n dfintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n dfintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n\n cuest_check('Create DFIntPlan',\n ce.cuestDFIntPlanCreate(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspace=dfintplan_persistent_workspace.pointer,\n temporaryWorkspace=dfintplan_temporary_workspace.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n del dfintplan_temporary_workspace\n\n cuest_check('Destroy DFIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=dfintplan_parameters,\n )\n )\n\n # => Build Fake Density Matrix / Occupied Orbitals <= #\n\n nocc_beta = int(np.abs(np.sum(Zs))//2)\n nocc_alpha = nocc_beta + 1 # assume anion for this example\n natom = len(Zs)\n\n # The total alpha + beta density matrix\n densitymatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n densitymatrix_device_handle = ce.Pointer()\n densitymatrix_device_handle.value = densitymatrix_device_pointer\n densitymatrix_host_array = np.random.normal(size=(nao, nao)).astype(np.double)\n densitymatrix_host_array = np.ravel(densitymatrix_host_array + densitymatrix_host_array.T)\n cuda_memcpy_htod(\n device_pointer=densitymatrix_device_pointer,\n host_pointer=densitymatrix_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n # Occupied MO coefficients with all alpha then all beta, i.e.:\n #\n # / Ca_mo0_ao0 Ca_mo0_ao1 ... Ca_mo0_aoN \\\n # | Ca_mo1_ao0 Ca_mo1_ao1 ... Ca_mo0_aoN |\n # | . . . |\n # | . . . |\n # | Ca_moA_ao0 Ca_moA_ao1 ... Ca_moA_aoN |\n # | Cb_mo0_ao0 Cb_mo0_ao1 ... Cb_mo0_aoN |\n # | Cb_mo1_ao0 Cb_mo1_ao1 ... Cb_mo1_aoN |\n # | . . . |\n # | . . . |\n # \\ Cb_moB_ao0 Cb_moB_ao1 ... Cb_moB_aoN /\n #\n # Where there are A alpha occupied orbitals, B beta occupied orbitals and N atomic orbitals.\n occorbitals_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * (nocc_alpha + nocc_beta) * nao\n )\n occorbitals_device_handle = ce.Pointer()\n occorbitals_device_handle.value = occorbitals_device_pointer\n occorbitals_host_array = np.random.normal(size=(nocc_alpha + nocc_beta)*nao).astype(np.double)\n cuda_memcpy_htod(\n device_pointer=occorbitals_device_pointer,\n host_pointer=occorbitals_host_array.ctypes.data,\n size_in_bytes=sizeof_double * (nocc_alpha + nocc_beta) * nao,\n )\n\n # Allow the algorithm to use up to 2GB of DRAM\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000\n )\n compute_JK_gradient_parameters = ce.cuestDFSymmetricDerivativeComputeParameters()\n cuest_check('Create JK Grad Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=compute_JK_gradient_parameters,\n )\n )\n\n JKgrad_device_handle = ce.Pointer()\n cuest_check('Compute JK Gradient Workspace Query',\n ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_JK_gradient_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=0.5,\n densityMatrix=densitymatrix_device_handle,\n coefficientScale=-0.5,\n numCoefficientMatrices=2,\n numOccupied=[nocc_alpha, nocc_beta],\n coefficientMatrices=occorbitals_device_handle,\n outGradient=JKgrad_device_handle,\n )\n )\n\n JKgrad_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n JKgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * natom * 3,\n )\n JKgrad_device_handle.value = np.intp(JKgrad_device_pointer)\n cuest_check('Compute JK Gradient',\n ce.cuestDFSymmetricDerivativeCompute(\n handle=cuest_handle,\n plan=dfintplan_handle,\n variableBufferSize=variable_buffer_size.pointer,\n parameters=compute_JK_gradient_parameters,\n temporaryWorkspace=JKgrad_temporary_workspace.pointer,\n densityScale=0.5, # The scale factor for the J term\n densityMatrix=densitymatrix_device_handle,\n coefficientScale=-0.5, # This should be further scaled by the HF X scale factor for hybrid DFT\n numCoefficientMatrices=2,\n numOccupied=[nocc_alpha, nocc_beta],\n coefficientMatrices=occorbitals_device_handle,\n outGradient=JKgrad_device_handle,\n )\n )\n\n cuda_free(\n array=occorbitals_device_pointer\n )\n cuda_free(\n array=densitymatrix_device_pointer\n )\n\n del JKgrad_temporary_workspace\n\n cuest_check('Destroy JK Grad Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=compute_JK_gradient_parameters,\n )\n )\n\n JKgrad_host_array = np.empty(\n (natom, 3),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=JKgrad_host_array.ctypes.data,\n device_pointer=JKgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * natom,\n )\n\n cuda_free(\n array=JKgrad_device_pointer\n )\n\n # => Cleanup <= #\n\n cuest_check('Destroy DFIntPlan',\n ce.cuestDFIntPlanDestroy(\n handle=dfintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n handle=aopairlist_handle,\n )\n )\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n cuest_check('Destroy Aux AOBasis',\n ce.cuestAOBasisDestroy(\n handle=auxbasis_handle,\n )\n )\n\n del dfintplan_persistent_workspace\n del aopairlist_persistent_workspace\n del aobasis_persistent_workspace\n del auxbasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Run using XYZ and GBS files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"The file\n# ... truncated ...","source_hash":"136f973ac3516a05d7c54a452d0de8fe3143a6e2cc26ff253b7fa9071d7892e4","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk_gradient_uhf.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.3_density_fitting.core_df_jk_gradient_uhf.run.run#L29-L557","kind":"function","name":"run","path":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_uhf/run.py","language":"python","start_line":29,"end_line":557,"context_start_line":9,"context_end_line":577,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n aux_gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n # Orbital Basis\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n # Auxilliary Basis\n aux_shells = []\n aux_n_shells_per_atom = []\n shell_count = 1\n for atom_shells in aux_shellinfo:\n aux_n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n aux_shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n # Auxilliary Basis\n auxbasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n auxbasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n auxbasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=aux_n_shells_per_atom,\n shells=aux_shells,\n parameters=aobasis_parameters,\n persistentWorkspace=auxbasis_persistent_workspace.pointer,\n temporaryWorkspace=auxbasis_temporary_workspace.pointer,\n outBasis=auxbasis_handle,\n )\n )\n\n del auxbasis_temporary_workspace\n\n for i, shell in enumerate(aux_shells):\n cuest_check(f'Destroy Aux AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build DF Integral Plan <= #\n\n dfintplan_handle = ce.cuestDFIntPlanHandle()\n dfintplan_parameters = ce.cuestDFIntPlanParameters()\n cuest_check('Create DFIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n outParameters=dfintplan_parameters,\n )\n )\n\n cuest_check('Create DFIntPlan Workspace Query',\n ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n print(\"DFIntPlan Persistent sizes:\", persistent_workspace_descriptor)\n print(\"DFIntPlan Temporary sizes:\", temporary_workspace_descriptor)\n\n dfintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n dfintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n\n cuest_check('Create DFIntPlan',\n ce.cuestDFIntPlanCreate(\n handle=cuest_handle,\n primaryBasis=aobasis_handle,\n auxiliaryBasis=auxbasis_handle,\n pairList=aopairlist_handle,\n parameters=dfintplan_parameters,\n persistentWorkspace=dfintplan_persistent_workspace.pointer,\n temporaryWorkspace=dfintplan_temporary_workspace.pointer,\n outPlan=dfintplan_handle,\n )\n )\n\n del dfintplan_temporary_workspace\n\n cuest_check('Destroy DFIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=dfintplan_parameters,\n )\n )\n\n # => Build Fake Density Matrix / Occupied Orbitals <= #\n\n nocc_beta = int(np.abs(np.sum(Zs))//2)\n nocc_alpha = nocc_beta + 1 # assume anion for this example\n natom = len(Zs)\n\n # The total alpha + beta density matrix\n densitymatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n densitymatrix_device_handle = ce.Pointer()\n densitymatrix_device_handle.value = densitymatrix_device_pointer\n densitymatrix_host_array = np.random.normal(size=(nao, nao)).astype(np.double)\n densitymatrix_host_array = np.ravel(densitymatrix_host_array + densitymatrix_host_array.T)\n cuda_memcpy_htod(\n device_pointer=densitymatrix_device_pointer,\n host_pointer=densitymatrix_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n # Occupied MO coefficients with all alpha then all beta, i.e.:\n #\n # / Ca_mo0_ao0 Ca_mo0_ao1 ... Ca_mo0_aoN \\\n # | Ca_mo1_ao0 Ca_mo1_ao1 ... Ca_mo0_aoN |\n # | . . . |\n # | . . . |\n # | Ca_moA_ao0 Ca_moA_ao1 ... Ca_moA_aoN |\n # | Cb_mo0_ao0 Cb_mo0_ao1 ... Cb_mo0_aoN |\n # | Cb_mo1_ao0 Cb_mo1_ao1 ... Cb_mo1_aoN |\n # | . . . |\n # | . . . |\n # \\ Cb_moB_ao0 Cb_moB_ao1 ... Cb_moB_aoN /\n #\n # Where there are A alpha occupied orbitals, B beta occupied orbitals and N atomic orbitals.\n occorbitals_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * (nocc_alpha + nocc_beta) * nao\n )\n occorbitals_device_handle = ce.Pointer()\n occorbitals_device_handle.value = occorbitals_device_pointer\n occorbitals_host_array = np.random.normal(size=(nocc_alpha + nocc_beta)*nao).astype(np.double)\n cuda_memcpy_htod(\n device_pointer=occorbitals_device_pointer,\n host_pointer=occorbitals_host_array.ctypes.data,\n size_in_bytes=sizeof_double * (nocc_alpha + nocc_beta) * nao,\n )\n\n # Allow the algorithm to use up to 2GB of DRAM\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000\n )\n compute_JK_gradient_parameters = ce.cuestDFSymmetricDerivativeComputeParameters()\n cuest_check('Create JK Grad Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=compute_JK_gradient_parameters,\n )\n )\n\n JKgrad_device_handle = ce.Pointer()\n cuest_check('Compute JK Gradient Workspace Query',\n ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=dfintplan_handle,\n parameters=compute_JK_gradient_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=0.5,\n densityMatrix=densitymatrix_device_handle,\n coefficientScale=-0.5,\n numCoefficientMatrices=2,\n numOccupied=[nocc_alpha, nocc_beta],\n coefficientMatrices=occorbitals_device_handle,\n outGradient=JKgrad_device_handle,\n )\n )\n\n JKgrad_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n JKgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * natom * 3,\n )\n JKgrad_device_handle.value = np.intp(JKgrad_device_pointer)\n cuest_check('Compute JK Gradient',\n ce.cuestDFSymmetricDerivativeCompute(\n handle=cuest_handle,\n plan=dfintplan_handle,\n variableBufferSize=variable_buffer_size.pointer,\n parameters=compute_JK_gradient_parameters,\n temporaryWorkspace=JKgrad_temporary_workspace.pointer,\n densityScale=0.5, # The scale factor for the J term\n densityMatrix=densitymatrix_device_handle,\n coefficientScale=-0.5, # This should be further scaled by the HF X scale factor for hybrid DFT\n numCoefficientMatrices=2,\n numOccupied=[nocc_alpha, nocc_beta],\n coefficientMatrices=occorbitals_device_handle,\n outGradient=JKgrad_device_handle,\n )\n )\n\n cuda_free(\n array=occorbitals_device_pointer\n )\n cuda_free(\n array=densitymatrix_device_pointer\n )\n\n del JKgrad_temporary_workspace\n\n cuest_check('Destroy JK Grad Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=compute_JK_gradient_parameters,\n )\n )\n\n JKgrad_host_array = np.empty(\n (natom, 3),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=JKgrad_host_array.ctypes.data,\n device_pointer=JKgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * natom,\n )\n\n cuda_free(\n array=JKgrad_device_pointer\n )\n\n # => Cleanup <= #\n\n cuest_check('Destroy DFIntPlan',\n ce.cuestDFIntPlanDestroy(\n handle=dfintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n handle=aopairlist_handle,\n )\n )\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n cuest_check('Destroy Aux AOBasis',\n ce.cuestAOBasisDestroy(\n handle=auxbasis_handle,\n )\n )\n\n del dfintplan_persistent_workspace\n del aopairlist_persistent_workspace\n del aobasis_persistent_workspace\n del auxbasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Run using XYZ and GBS files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"The file with molecular coordinates (Angstrom) in basic xyz format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"The basis set file in G94/Psi4 GBS format.\"\n )\n parser.add_argument(\n \"aux_gbs_filename\",\n type=str,\n help=\"The auxilliary basis set file in G94/Psi4 GBS format.\"\n )","source_hash":"136f973ac3516a05d7c54a452d0de8fe3143a6e2cc26ff253b7fa9071d7892e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.3_density_fitting.core_df_jk_gradient_uhf.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.3_density_fitting.core_df_jk_gradient_uhf.run.cuest_check#L58-L65","kind":"function","name":"cuest_check","path":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_uhf/run.py","language":"python","start_line":58,"end_line":65,"context_start_line":38,"context_end_line":85,"code":" symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n aux_shellinfo = simple_gbs_parser(\n filename=aux_gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(","source_hash":"136f973ac3516a05d7c54a452d0de8fe3143a6e2cc26ff253b7fa9071d7892e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.nonlocal_xc_gradient.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.4_exchange_correlation.nonlocal_xc_gradient.run#L1-L684","kind":"module","name":"cuEST.python_examples.4_exchange_correlation.nonlocal_xc_gradient.run","path":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_gradient/run.py","language":"python","start_line":1,"end_line":684,"context_start_line":1,"context_end_line":684,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\nfrom helpers.grid_utils import build_ahlrichs_radial_quadrature, symbol_to_ahlrichs_radius\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n stream_handle = ce.data_cudaStream_t()\n cuest_check('Query Handle Stream',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n\n # => Build Molecular Integration Grid <= #\n\n atomgrid_parameters = ce.cuestAtomGridParameters()\n\n cuest_check('Create AtomGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n outParameters=atomgrid_parameters,\n )\n )\n\n atomgrids = []\n for atom,symbol in enumerate(symbols):\n # For simplicity, build an unpruned 75/302 grid using the Ahlrichs radial quadrature scheme\n ahlrichs_radius = symbol_to_ahlrichs_radius(\n symbol=symbol\n )\n radial_nodes, radial_weights = build_ahlrichs_radial_quadrature(\n npoint=75,\n R=ahlrichs_radius,\n )\n num_angular_points = [302]*len(radial_nodes)\n atomgrid_handle = ce.cuestAtomGridHandle()\n cuest_check(f'Create AtomGrid {atom}',\n ce.cuestAtomGridCreate(\n handle=cuest_handle,\n numRadialPoints=75,\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters,\n outAtomGrid=atomgrid_handle,\n )\n )\n atomgrids.append(atomgrid_handle)\n\n cuest_check('Destroy AtomGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n parameters=atomgrid_parameters,\n )\n )\n\n moleculargrid_parameters = ce.cuestMolecularGridParameters()\n\n cuest_check('Create MolecularGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n outParameters=moleculargrid_parameters,\n )\n )\n\n cuest_check('Create MolecularGrid Workspace Query',\n ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n )\n\n grid_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n moleculargrid=ce.cuestMolecularGridHandle()\n\n cuest_check('Create MolecularGrid',\n ce.cuestMolecularGridCreate(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=moleculargrid,\n )\n )\n\n del grid_temporary_workspace\n\n for atom,grid in enumerate(atomgrids):\n cuest_check(f'Destroy AtomGrid{atom}',\n ce.cuestAtomGridDestroy(\n atomGrid=grid,\n )\n )\n\n cuest_check('Destroy MolecularGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n parameters=moleculargrid_parameters,\n )\n )\n\n # => Build XC Integral Plan <= #\n\n xcintplan_parameters = ce.cuestXCIntPlanParameters()\n cuest_check('Create XCIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n outParameters=xcintplan_parameters,\n )\n )\n\n cuest_check('Create XCIntPlan Workspace Query',\n ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ce.cuestXCIntPlanHandle(),\n )\n )\n\n xcintplan = ce.cuestXCIntPlanHandle()\n xcintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n xcintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create XCIntPlan',\n ce.cuestXCIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspace=xcintplan_persistent_workspace.pointer,\n temporaryWorkspace=xcintplan_temporary_workspace.pointer,\n outPlan=xcintplan,\n )\n )\n\n del xcintplan_temporary_workspace\n\n cuest_check('Destroy XCIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xcintplan_parameters,\n )\n )\n\n # => Configure the Nonlocal Potential <= #\n\n nonlocal_xc_compute_parameters = ce.cuestNonlocalXCDerivativeRKSComputeParameters()\n\n cuest_check('NonlocalXC Gradient Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n outParameters=nonlocal_xc_compute_parameters,\n )\n )\n\n vv10_b = ce.data_double(6.0)\n cuest_check('VV10 b Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n )\n\n vv10_C = ce.data_double(0.01)\n cuest_check('VV10 C Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n )\n\n vv10_scale = ce.data_double(1.0)\n cuest_check('VV10 Scale Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n )\n\n # => RKS Derivative Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n nocc = np.abs(int(np.sum(Zs)//2))\n\n Cocc_host = np.random.normal(size=(nocc, nao)).astype(np.double)\n Cocc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n Cocc_device_handle = ce.Pointer(Cocc_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocc_device_pointer,\n host_pointer=Cocc_host.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Derivative Compute Routines <= #\n\n Vxcgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * num_atoms,\n )\n Vxcgrad_device_handle = ce.Pointer(Vxcgrad_device_pointer)\n\n cuest_check('NonlocalXCDerivativeRKSCompute Workspace Query',\n ce.cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=nonlocal_xc_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('NonlocalXCDerivativeRKSCompute',\n ce.cuestNonlocalXCDerivativeRKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=nonlocal_xc_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n del Vxc_workspace\n\n cuest_check('Destroy NonlocalXC Gradient Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n )\n )\n\n cuda_free(\n array=Cocc_device_pointer\n )\n\n Vxcgrad_host_array = np.empty(\n (3 * num_atoms),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxcgrad_host_array.ctypes.data,\n device_pointer=Vxcgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * num_atoms,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxcgrad_device_pointer\n )\n\n # => UKS Derivatives Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n # Assume a cation\n nocca = np.abs(int(np.sum(Zs)//2))\n noccb = nocca - 1\n\n # Alpha and Beta occupied molecular orbitals\n Cocca_host = np.random.normal(size=(nocca, nao)).astype(np.double)\n Cocca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocca * nao\n )\n Cocca_device_handle = ce.Pointer(Cocca_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocca_device_pointer,\n host_pointer=Cocca_host.ctypes.data,\n size_in_bytes=sizeof_double * nocca * nao,\n stream=stream_handle.value,\n )\n\n Coccb_host = np.random.normal(size=(noccb, nao)).astype(np.double)\n Coccb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * noccb * nao\n )\n Coccb_device_handle = ce.Pointer(Coccb_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Coccb_device_pointer,\n host_pointer=Coccb_host.ctypes.data,\n size_in_bytes=sizeof_double * noccb * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Derivative Compute Routines <= #\n\n Vxcgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * num_atoms,\n )\n Vxcgrad_device_handle = ce.Pointer(Vxcgrad_device_pointer)\n nonlocal_xc_compute_parameters = ce.cuestNonlocalXCDerivativeUKSComputeParameters()\n cuest_check('NonlocalXC UKS Gradient Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n outParameters=nonlocal_xc_compute_parameters,\n )\n )\n vv10_b = ce.data_double(6.0)\n cuest_check('VV10 b UKS Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeUKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n )\n vv10_C = ce.data_double(0.01)\n cuest_check('VV10 C UKS Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMET\n# ... truncated ...","source_hash":"e7d03b16d1097dd9b250e3c9f125b3c385813d99794b90b7b22a56f25df174cd","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.nonlocal_xc_gradient.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.4_exchange_correlation.nonlocal_xc_gradient.run.run#L29-L660","kind":"function","name":"run","path":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_gradient/run.py","language":"python","start_line":29,"end_line":660,"context_start_line":9,"context_end_line":680,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\nfrom helpers.grid_utils import build_ahlrichs_radial_quadrature, symbol_to_ahlrichs_radius\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n stream_handle = ce.data_cudaStream_t()\n cuest_check('Query Handle Stream',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n\n # => Build Molecular Integration Grid <= #\n\n atomgrid_parameters = ce.cuestAtomGridParameters()\n\n cuest_check('Create AtomGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n outParameters=atomgrid_parameters,\n )\n )\n\n atomgrids = []\n for atom,symbol in enumerate(symbols):\n # For simplicity, build an unpruned 75/302 grid using the Ahlrichs radial quadrature scheme\n ahlrichs_radius = symbol_to_ahlrichs_radius(\n symbol=symbol\n )\n radial_nodes, radial_weights = build_ahlrichs_radial_quadrature(\n npoint=75,\n R=ahlrichs_radius,\n )\n num_angular_points = [302]*len(radial_nodes)\n atomgrid_handle = ce.cuestAtomGridHandle()\n cuest_check(f'Create AtomGrid {atom}',\n ce.cuestAtomGridCreate(\n handle=cuest_handle,\n numRadialPoints=75,\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters,\n outAtomGrid=atomgrid_handle,\n )\n )\n atomgrids.append(atomgrid_handle)\n\n cuest_check('Destroy AtomGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n parameters=atomgrid_parameters,\n )\n )\n\n moleculargrid_parameters = ce.cuestMolecularGridParameters()\n\n cuest_check('Create MolecularGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n outParameters=moleculargrid_parameters,\n )\n )\n\n cuest_check('Create MolecularGrid Workspace Query',\n ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n )\n\n grid_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n moleculargrid=ce.cuestMolecularGridHandle()\n\n cuest_check('Create MolecularGrid',\n ce.cuestMolecularGridCreate(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=moleculargrid,\n )\n )\n\n del grid_temporary_workspace\n\n for atom,grid in enumerate(atomgrids):\n cuest_check(f'Destroy AtomGrid{atom}',\n ce.cuestAtomGridDestroy(\n atomGrid=grid,\n )\n )\n\n cuest_check('Destroy MolecularGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n parameters=moleculargrid_parameters,\n )\n )\n\n # => Build XC Integral Plan <= #\n\n xcintplan_parameters = ce.cuestXCIntPlanParameters()\n cuest_check('Create XCIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n outParameters=xcintplan_parameters,\n )\n )\n\n cuest_check('Create XCIntPlan Workspace Query',\n ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ce.cuestXCIntPlanHandle(),\n )\n )\n\n xcintplan = ce.cuestXCIntPlanHandle()\n xcintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n xcintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create XCIntPlan',\n ce.cuestXCIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspace=xcintplan_persistent_workspace.pointer,\n temporaryWorkspace=xcintplan_temporary_workspace.pointer,\n outPlan=xcintplan,\n )\n )\n\n del xcintplan_temporary_workspace\n\n cuest_check('Destroy XCIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xcintplan_parameters,\n )\n )\n\n # => Configure the Nonlocal Potential <= #\n\n nonlocal_xc_compute_parameters = ce.cuestNonlocalXCDerivativeRKSComputeParameters()\n\n cuest_check('NonlocalXC Gradient Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n outParameters=nonlocal_xc_compute_parameters,\n )\n )\n\n vv10_b = ce.data_double(6.0)\n cuest_check('VV10 b Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n )\n\n vv10_C = ce.data_double(0.01)\n cuest_check('VV10 C Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n )\n\n vv10_scale = ce.data_double(1.0)\n cuest_check('VV10 Scale Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n )\n\n # => RKS Derivative Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n nocc = np.abs(int(np.sum(Zs)//2))\n\n Cocc_host = np.random.normal(size=(nocc, nao)).astype(np.double)\n Cocc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n Cocc_device_handle = ce.Pointer(Cocc_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocc_device_pointer,\n host_pointer=Cocc_host.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Derivative Compute Routines <= #\n\n Vxcgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * num_atoms,\n )\n Vxcgrad_device_handle = ce.Pointer(Vxcgrad_device_pointer)\n\n cuest_check('NonlocalXCDerivativeRKSCompute Workspace Query',\n ce.cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=nonlocal_xc_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('NonlocalXCDerivativeRKSCompute',\n ce.cuestNonlocalXCDerivativeRKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=nonlocal_xc_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n del Vxc_workspace\n\n cuest_check('Destroy NonlocalXC Gradient Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n )\n )\n\n cuda_free(\n array=Cocc_device_pointer\n )\n\n Vxcgrad_host_array = np.empty(\n (3 * num_atoms),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxcgrad_host_array.ctypes.data,\n device_pointer=Vxcgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * num_atoms,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxcgrad_device_pointer\n )\n\n # => UKS Derivatives Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n # Assume a cation\n nocca = np.abs(int(np.sum(Zs)//2))\n noccb = nocca - 1\n\n # Alpha and Beta occupied molecular orbitals\n Cocca_host = np.random.normal(size=(nocca, nao)).astype(np.double)\n Cocca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocca * nao\n )\n Cocca_device_handle = ce.Pointer(Cocca_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocca_device_pointer,\n host_pointer=Cocca_host.ctypes.data,\n size_in_bytes=sizeof_double * nocca * nao,\n stream=stream_handle.value,\n )\n\n Coccb_host = np.random.normal(size=(noccb, nao)).astype(np.double)\n Coccb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * noccb * nao\n )\n Coccb_device_handle = ce.Pointer(Coccb_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Coccb_device_pointer,\n host_pointer=Coccb_host.ctypes.data,\n size_in_bytes=sizeof_double * noccb * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Derivative Compute Routines <= #\n\n Vxcgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * num_atoms,\n )\n Vxcgrad_device_handle = ce.Pointer(Vxcgrad_device_pointer)\n nonlocal_xc_compute_parameters = ce.cuestNonlocalXCDerivativeUKSComputeParameters()\n cuest_check('NonlocalXC UKS Gradient Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n outParameters=nonlocal_xc_compute_parameters,\n )\n )\n vv10_b = ce.data_double(6.0)\n cuest_check('VV10 b UKS Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeUKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n )\n vv10_C = ce.data_double(0.01)\n cuest_check('VV10 C UKS Gradient Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCDerivativeUKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVEUKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n )\n vv10_scale = ce.data_double(1.0)\n cuest_check('VV10 Scale UKS Gradient Parameter Configure',\n# ... truncated ...","source_hash":"e7d03b16d1097dd9b250e3c9f125b3c385813d99794b90b7b22a56f25df174cd","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.nonlocal_xc_gradient.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.4_exchange_correlation.nonlocal_xc_gradient.run.cuest_check#L52-L59","kind":"function","name":"cuest_check","path":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_gradient/run.py","language":"python","start_line":52,"end_line":59,"context_start_line":32,"context_end_line":79,"code":" gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n","source_hash":"e7d03b16d1097dd9b250e3c9f125b3c385813d99794b90b7b22a56f25df174cd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.local_xc_gradient.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.4_exchange_correlation.local_xc_gradient.run#L1-L622","kind":"module","name":"cuEST.python_examples.4_exchange_correlation.local_xc_gradient.run","path":"cuEST/python_examples/4_exchange_correlation/local_xc_gradient/run.py","language":"python","start_line":1,"end_line":622,"context_start_line":1,"context_end_line":622,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\nfrom helpers.grid_utils import build_ahlrichs_radial_quadrature, symbol_to_ahlrichs_radius\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n stream_handle = ce.data_cudaStream_t()\n cuest_check('Query Handle Stream',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n\n # => Build Molecular Integration Grid <= #\n\n atomgrid_parameters = ce.cuestAtomGridParameters()\n\n cuest_check('Create AtomGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n outParameters=atomgrid_parameters,\n )\n )\n\n atomgrids = []\n for atom,symbol in enumerate(symbols):\n # For simplicity, build an unpruned 75/302 grid using the Ahlrichs radial quadrature scheme\n ahlrichs_radius = symbol_to_ahlrichs_radius(\n symbol=symbol\n )\n radial_nodes, radial_weights = build_ahlrichs_radial_quadrature(\n npoint=75,\n R=ahlrichs_radius,\n )\n num_angular_points = [302]*len(radial_nodes)\n atomgrid_handle = ce.cuestAtomGridHandle()\n cuest_check(f'Create AtomGrid {atom}',\n ce.cuestAtomGridCreate(\n handle=cuest_handle,\n numRadialPoints=75,\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters,\n outAtomGrid=atomgrid_handle,\n )\n )\n atomgrids.append(atomgrid_handle)\n\n cuest_check('Destroy AtomGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n parameters=atomgrid_parameters,\n )\n )\n\n moleculargrid_parameters = ce.cuestMolecularGridParameters()\n\n cuest_check('Create MolecularGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n outParameters=moleculargrid_parameters,\n )\n )\n\n cuest_check('Create MolecularGrid Workspace Query',\n ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n )\n\n grid_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n moleculargrid=ce.cuestMolecularGridHandle()\n\n cuest_check('Create MolecularGrid',\n ce.cuestMolecularGridCreate(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=moleculargrid,\n )\n )\n\n del grid_temporary_workspace\n\n for atom,grid in enumerate(atomgrids):\n cuest_check(f'Destroy AtomGrid{atom}',\n ce.cuestAtomGridDestroy(\n atomGrid=grid,\n )\n )\n\n cuest_check('Destroy MolecularGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n parameters=moleculargrid_parameters,\n )\n )\n\n # => Build XC Integral Plan <= #\n\n xcintplan_parameters = ce.cuestXCIntPlanParameters()\n cuest_check('Create XCIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n outParameters=xcintplan_parameters,\n )\n )\n\n cuest_check('Create XCIntPlan Workspace Query',\n ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ce.cuestXCIntPlanHandle(),\n )\n )\n\n xcintplan = ce.cuestXCIntPlanHandle()\n xcintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n xcintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create XCIntPlan',\n ce.cuestXCIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspace=xcintplan_persistent_workspace.pointer,\n temporaryWorkspace=xcintplan_temporary_workspace.pointer,\n outPlan=xcintplan,\n )\n )\n\n del xcintplan_temporary_workspace\n\n cuest_check('Destroy XCIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xcintplan_parameters,\n )\n )\n\n # => RKS Derivatives Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n nocc = np.abs(int(np.sum(Zs)//2))\n\n Cocc_host = np.random.normal(size=(nocc, nao)).astype(np.double)\n Cocc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n Cocc_device_handle = ce.Pointer(Cocc_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocc_device_pointer,\n host_pointer=Cocc_host.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Derivative Compute Routines <= #\n\n Vxcgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * num_atoms,\n )\n Vxcgrad_device_handle = ce.Pointer(Vxcgrad_device_pointer)\n\n xc_derivative_rks_compute_parameters = ce.cuestXCDerivativeRKSComputeParameters()\n cuest_check('XCDerivativeRKSCompute Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS,\n outParameters=xc_derivative_rks_compute_parameters,\n )\n )\n\n cuest_check('XCDerivativeRKSCompute Workspace Query',\n ce.cuestXCDerivativeRKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=xc_derivative_rks_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('XCDerivativeRKSCompute',\n ce.cuestXCDerivativeRKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=xc_derivative_rks_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n cuest_check('Destroy XCDerivativeRKSCompute Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=xc_derivative_rks_compute_parameters,\n )\n )\n\n del Vxc_workspace\n\n cuda_free(\n array=Cocc_device_pointer\n )\n\n Vxcgrad_host_array = np.empty(\n (3 * num_atoms),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxcgrad_host_array.ctypes.data,\n device_pointer=Vxcgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * num_atoms,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxcgrad_device_pointer\n )\n\n # => UKS Derivative Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n # Assume a cation\n nocca = np.abs(int(np.sum(Zs)//2))\n noccb = nocca - 1\n\n # Alpha and Beta occupied molecular orbitals\n Cocca_host = np.random.normal(size=(nocca, nao)).astype(np.double)\n Cocca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocca * nao\n )\n Cocca_device_handle = ce.Pointer(Cocca_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocca_device_pointer,\n host_pointer=Cocca_host.ctypes.data,\n size_in_bytes=sizeof_double * nocca * nao,\n stream=stream_handle.value,\n )\n\n Coccb_host = np.random.normal(size=(noccb, nao)).astype(np.double)\n Coccb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * noccb * nao\n )\n Coccb_device_handle = ce.Pointer(Coccb_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Coccb_device_pointer,\n host_pointer=Coccb_host.ctypes.data,\n size_in_bytes=sizeof_double * noccb * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Derivative Compute Routines <= #\n\n Vxcgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * num_atoms,\n )\n Vxcgrad_device_handle = ce.Pointer(Vxcgrad_device_pointer)\n\n xc_derivative_uks_compute_parameters = ce.cuestXCDerivativeUKSComputeParameters()\n cuest_check('XCDerivativeUKSCompute Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n outParameters=xc_derivative_uks_compute_parameters,\n )\n )\n cuest_check('XCDerivativeUKSCompute Workspace Query',\n ce.cuestXCDerivativeUKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=xc_derivative_uks_compute_parameters,\n numOccupiedAlpha=nocca,\n numOccupiedBeta=noccb,\n coefficientMatrixAlpha=Cocca_device_handle,\n coefficientMatrixBeta=Coccb_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('XCDerivativeUKSCompute',\n ce.cuestXCDerivativeUKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=xc_derivative_uks_compute_parameters,\n numOccupiedAlpha=nocca,\n numOccupiedBeta=noccb,\n coefficientMatrixAlpha=Cocca_device_handle,\n coefficientMatrixBeta=Coccb_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n del Vxc_workspace\n cuest_check('Destroy XCDerivativeUKSCompute Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n parameters=xc_derivative_uks_compute_parameters,\n )\n )\n\n cuda_free(\n array=Cocca_device_pointer\n )\n cuda_free(\n array=Coccb_device_pointer\n )\n\n Vxcgrad_host_array = np.empty(\n (3 * num_atoms),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxcgrad_host_array.ctypes.data,\n device_pointer=Vxcgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * num_atoms,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxcgrad_device_pointer\n )\n\n # => Cleanup <= #\n\n cuest_check('Destroy XCIntPlan',\n ce.cuestXCIntPlanDestroy(\n handle=xcintplan,\n# ... truncated ...","source_hash":"662e42c176dd2f694c6eb8ef74c2a4a4c0cd7ed325e60b7df5118bdaaee650fe","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.local_xc_gradient.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.4_exchange_correlation.local_xc_gradient.run.run#L29-L599","kind":"function","name":"run","path":"cuEST/python_examples/4_exchange_correlation/local_xc_gradient/run.py","language":"python","start_line":29,"end_line":599,"context_start_line":9,"context_end_line":619,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\nfrom helpers.grid_utils import build_ahlrichs_radial_quadrature, symbol_to_ahlrichs_radius\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n stream_handle = ce.data_cudaStream_t()\n cuest_check('Query Handle Stream',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n\n # => Build Molecular Integration Grid <= #\n\n atomgrid_parameters = ce.cuestAtomGridParameters()\n\n cuest_check('Create AtomGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n outParameters=atomgrid_parameters,\n )\n )\n\n atomgrids = []\n for atom,symbol in enumerate(symbols):\n # For simplicity, build an unpruned 75/302 grid using the Ahlrichs radial quadrature scheme\n ahlrichs_radius = symbol_to_ahlrichs_radius(\n symbol=symbol\n )\n radial_nodes, radial_weights = build_ahlrichs_radial_quadrature(\n npoint=75,\n R=ahlrichs_radius,\n )\n num_angular_points = [302]*len(radial_nodes)\n atomgrid_handle = ce.cuestAtomGridHandle()\n cuest_check(f'Create AtomGrid {atom}',\n ce.cuestAtomGridCreate(\n handle=cuest_handle,\n numRadialPoints=75,\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters,\n outAtomGrid=atomgrid_handle,\n )\n )\n atomgrids.append(atomgrid_handle)\n\n cuest_check('Destroy AtomGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n parameters=atomgrid_parameters,\n )\n )\n\n moleculargrid_parameters = ce.cuestMolecularGridParameters()\n\n cuest_check('Create MolecularGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n outParameters=moleculargrid_parameters,\n )\n )\n\n cuest_check('Create MolecularGrid Workspace Query',\n ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n )\n\n grid_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n moleculargrid=ce.cuestMolecularGridHandle()\n\n cuest_check('Create MolecularGrid',\n ce.cuestMolecularGridCreate(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=moleculargrid,\n )\n )\n\n del grid_temporary_workspace\n\n for atom,grid in enumerate(atomgrids):\n cuest_check(f'Destroy AtomGrid{atom}',\n ce.cuestAtomGridDestroy(\n atomGrid=grid,\n )\n )\n\n cuest_check('Destroy MolecularGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n parameters=moleculargrid_parameters,\n )\n )\n\n # => Build XC Integral Plan <= #\n\n xcintplan_parameters = ce.cuestXCIntPlanParameters()\n cuest_check('Create XCIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n outParameters=xcintplan_parameters,\n )\n )\n\n cuest_check('Create XCIntPlan Workspace Query',\n ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ce.cuestXCIntPlanHandle(),\n )\n )\n\n xcintplan = ce.cuestXCIntPlanHandle()\n xcintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n xcintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create XCIntPlan',\n ce.cuestXCIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspace=xcintplan_persistent_workspace.pointer,\n temporaryWorkspace=xcintplan_temporary_workspace.pointer,\n outPlan=xcintplan,\n )\n )\n\n del xcintplan_temporary_workspace\n\n cuest_check('Destroy XCIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xcintplan_parameters,\n )\n )\n\n # => RKS Derivatives Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n nocc = np.abs(int(np.sum(Zs)//2))\n\n Cocc_host = np.random.normal(size=(nocc, nao)).astype(np.double)\n Cocc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n Cocc_device_handle = ce.Pointer(Cocc_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocc_device_pointer,\n host_pointer=Cocc_host.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Derivative Compute Routines <= #\n\n Vxcgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * num_atoms,\n )\n Vxcgrad_device_handle = ce.Pointer(Vxcgrad_device_pointer)\n\n xc_derivative_rks_compute_parameters = ce.cuestXCDerivativeRKSComputeParameters()\n cuest_check('XCDerivativeRKSCompute Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS,\n outParameters=xc_derivative_rks_compute_parameters,\n )\n )\n\n cuest_check('XCDerivativeRKSCompute Workspace Query',\n ce.cuestXCDerivativeRKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=xc_derivative_rks_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('XCDerivativeRKSCompute',\n ce.cuestXCDerivativeRKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=xc_derivative_rks_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n cuest_check('Destroy XCDerivativeRKSCompute Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=xc_derivative_rks_compute_parameters,\n )\n )\n\n del Vxc_workspace\n\n cuda_free(\n array=Cocc_device_pointer\n )\n\n Vxcgrad_host_array = np.empty(\n (3 * num_atoms),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxcgrad_host_array.ctypes.data,\n device_pointer=Vxcgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * num_atoms,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxcgrad_device_pointer\n )\n\n # => UKS Derivative Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n # Assume a cation\n nocca = np.abs(int(np.sum(Zs)//2))\n noccb = nocca - 1\n\n # Alpha and Beta occupied molecular orbitals\n Cocca_host = np.random.normal(size=(nocca, nao)).astype(np.double)\n Cocca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocca * nao\n )\n Cocca_device_handle = ce.Pointer(Cocca_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocca_device_pointer,\n host_pointer=Cocca_host.ctypes.data,\n size_in_bytes=sizeof_double * nocca * nao,\n stream=stream_handle.value,\n )\n\n Coccb_host = np.random.normal(size=(noccb, nao)).astype(np.double)\n Coccb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * noccb * nao\n )\n Coccb_device_handle = ce.Pointer(Coccb_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Coccb_device_pointer,\n host_pointer=Coccb_host.ctypes.data,\n size_in_bytes=sizeof_double * noccb * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Derivative Compute Routines <= #\n\n Vxcgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * num_atoms,\n )\n Vxcgrad_device_handle = ce.Pointer(Vxcgrad_device_pointer)\n\n xc_derivative_uks_compute_parameters = ce.cuestXCDerivativeUKSComputeParameters()\n cuest_check('XCDerivativeUKSCompute Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n outParameters=xc_derivative_uks_compute_parameters,\n )\n )\n cuest_check('XCDerivativeUKSCompute Workspace Query',\n ce.cuestXCDerivativeUKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=xc_derivative_uks_compute_parameters,\n numOccupiedAlpha=nocca,\n numOccupiedBeta=noccb,\n coefficientMatrixAlpha=Cocca_device_handle,\n coefficientMatrixBeta=Coccb_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('XCDerivativeUKSCompute',\n ce.cuestXCDerivativeUKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=xc_derivative_uks_compute_parameters,\n numOccupiedAlpha=nocca,\n numOccupiedBeta=noccb,\n coefficientMatrixAlpha=Cocca_device_handle,\n coefficientMatrixBeta=Coccb_device_handle,\n outGradient=Vxcgrad_device_handle,\n )\n )\n\n del Vxc_workspace\n cuest_check('Destroy XCDerivativeUKSCompute Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVEUKSCOMPUTE_PARAMETERS,\n parameters=xc_derivative_uks_compute_parameters,\n )\n )\n\n cuda_free(\n array=Cocca_device_pointer\n )\n cuda_free(\n array=Coccb_device_pointer\n )\n\n Vxcgrad_host_array = np.empty(\n (3 * num_atoms),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxcgrad_host_array.ctypes.data,\n device_pointer=Vxcgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * num_atoms,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxcgrad_device_pointer\n )\n\n # => Cleanup <= #\n\n cuest_check('Destroy XCIntPlan',\n ce.cuestXCIntPlanDestroy(\n handle=xcintplan,\n )\n )\n del xcintplan_persistent_workspace\n\n cuest_check('Destroy MolecularGrid',\n ce.cuestMolecularGridDestroy(\n grid=moleculargrid,\n )\n )\n del grid_persistent_workspace\n\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n del\n# ... truncated ...","source_hash":"662e42c176dd2f694c6eb8ef74c2a4a4c0cd7ed325e60b7df5118bdaaee650fe","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.local_xc_gradient.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.4_exchange_correlation.local_xc_gradient.run.cuest_check#L52-L59","kind":"function","name":"cuest_check","path":"cuEST/python_examples/4_exchange_correlation/local_xc_gradient/run.py","language":"python","start_line":52,"end_line":59,"context_start_line":32,"context_end_line":79,"code":" gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n","source_hash":"662e42c176dd2f694c6eb8ef74c2a4a4c0cd7ed325e60b7df5118bdaaee650fe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.local_xc_potential.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.4_exchange_correlation.local_xc_potential.run#L1-L651","kind":"module","name":"cuEST.python_examples.4_exchange_correlation.local_xc_potential.run","path":"cuEST/python_examples/4_exchange_correlation/local_xc_potential/run.py","language":"python","start_line":1,"end_line":651,"context_start_line":1,"context_end_line":651,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\nfrom helpers.grid_utils import build_ahlrichs_radial_quadrature, symbol_to_ahlrichs_radius\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n stream_handle = ce.data_cudaStream_t()\n cuest_check('Query Handle Stream',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n\n # => Build Molecular Integration Grid <= #\n\n atomgrid_parameters = ce.cuestAtomGridParameters()\n\n cuest_check('Create AtomGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n outParameters=atomgrid_parameters,\n )\n )\n\n atomgrids = []\n for atom,symbol in enumerate(symbols):\n # For simplicity, build an unpruned 75/302 grid using the Ahlrichs radial quadrature scheme\n ahlrichs_radius = symbol_to_ahlrichs_radius(\n symbol=symbol\n )\n radial_nodes, radial_weights = build_ahlrichs_radial_quadrature(\n npoint=75,\n R=ahlrichs_radius,\n )\n num_angular_points = [302]*len(radial_nodes)\n atomgrid_handle = ce.cuestAtomGridHandle()\n cuest_check(f'Create AtomGrid {atom}',\n ce.cuestAtomGridCreate(\n handle=cuest_handle,\n numRadialPoints=75,\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters,\n outAtomGrid=atomgrid_handle,\n )\n )\n atomgrids.append(atomgrid_handle)\n\n cuest_check('Destroy AtomGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n parameters=atomgrid_parameters,\n )\n )\n\n moleculargrid_parameters = ce.cuestMolecularGridParameters()\n\n cuest_check('Create MolecularGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n outParameters=moleculargrid_parameters,\n )\n )\n\n cuest_check('Create MolecularGrid Workspace Query',\n ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n )\n\n grid_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n moleculargrid=ce.cuestMolecularGridHandle()\n\n cuest_check('Create MolecularGrid',\n ce.cuestMolecularGridCreate(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=moleculargrid,\n )\n )\n\n del grid_temporary_workspace\n\n for atom,grid in enumerate(atomgrids):\n cuest_check(f'Destroy AtomGrid{atom}',\n ce.cuestAtomGridDestroy(\n atomGrid=grid,\n )\n )\n\n cuest_check('Destroy MolecularGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n parameters=moleculargrid_parameters,\n )\n )\n\n # => Build XC Integral Plan <= #\n\n xcintplan_parameters = ce.cuestXCIntPlanParameters()\n cuest_check('Create XCIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n outParameters=xcintplan_parameters,\n )\n )\n\n cuest_check('Create XCIntPlan Workspace Query',\n ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ce.cuestXCIntPlanHandle(),\n )\n )\n\n xcintplan = ce.cuestXCIntPlanHandle()\n xcintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n xcintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create XCIntPlan',\n ce.cuestXCIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspace=xcintplan_persistent_workspace.pointer,\n temporaryWorkspace=xcintplan_temporary_workspace.pointer,\n outPlan=xcintplan,\n )\n )\n\n del xcintplan_temporary_workspace\n\n cuest_check('Destroy XCIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xcintplan_parameters,\n )\n )\n\n # => RKS Potential Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n nocc = np.abs(int(np.sum(Zs)//2))\n\n Cocc_host = np.random.normal(size=(nocc, nao)).astype(np.double)\n Cocc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n Cocc_device_handle = ce.Pointer(Cocc_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocc_device_pointer,\n host_pointer=Cocc_host.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Potential Compute Routines <= #\n\n Vxc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxc_device_handle = ce.Pointer(Vxc_device_pointer)\n compute_xc_potential_parameters = ce.cuestXCPotentialRKSComputeParameters()\n cuest_check('XCPotentialRKS Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS,\n outParameters=compute_xc_potential_parameters,\n )\n )\n\n Exc = ce.data_double()\n cuest_check('XCPotentialRKSCompute Workspace Query',\n ce.cuestXCPotentialRKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=compute_xc_potential_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxc_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('XCPotentialRKSCompute',\n ce.cuestXCPotentialRKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=compute_xc_potential_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxc_device_handle,\n )\n )\n\n del Vxc_workspace\n\n cuda_free(\n array=Cocc_device_pointer\n )\n\n cuest_check('Destroy XCPotentialRKS Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=compute_xc_potential_parameters,\n )\n )\n\n Vxc_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxc_host_array.ctypes.data,\n device_pointer=Vxc_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxc_device_pointer\n )\n\n # => UKS Potential Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n # Assume a cation\n nocca = np.abs(int(np.sum(Zs)//2))\n noccb = nocca - 1\n\n # Alpha and Beta occupied molecular orbitals\n Cocca_host = np.random.normal(size=(nocca, nao)).astype(np.double)\n Cocca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocca * nao\n )\n Cocca_device_handle = ce.Pointer(Cocca_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocca_device_pointer,\n host_pointer=Cocca_host.ctypes.data,\n size_in_bytes=sizeof_double * nocca * nao,\n stream=stream_handle.value,\n )\n\n Coccb_host = np.random.normal(size=(noccb, nao)).astype(np.double)\n Coccb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * noccb * nao\n )\n Coccb_device_handle = ce.Pointer(Coccb_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Coccb_device_pointer,\n host_pointer=Coccb_host.ctypes.data,\n size_in_bytes=sizeof_double * noccb * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Potential Compute Routines <= #\n\n Vxca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxca_device_handle = ce.Pointer(Vxca_device_pointer)\n\n Vxcb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxcb_device_handle = ce.Pointer(Vxcb_device_pointer)\n\n compute_xc_potential_parameters = ce.cuestXCPotentialUKSComputeParameters()\n cuest_check('XCPotentialUKS Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALUKSCOMPUTE_PARAMETERS,\n outParameters=compute_xc_potential_parameters,\n )\n )\n\n Exc = ce.data_double()\n cuest_check('XCPotentialUKSCompute Workspace Query',\n ce.cuestXCPotentialUKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=compute_xc_potential_parameters,\n numOccupiedAlpha=nocca,\n numOccupiedBeta=noccb,\n coefficientMatrixAlpha=Cocca_device_handle,\n coefficientMatrixBeta=Coccb_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrixAlpha=Vxca_device_handle,\n outXCPotentialMatrixBeta=Vxcb_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('XCPotentialUKSCompute',\n ce.cuestXCPotentialUKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=compute_xc_potential_parameters,\n numOccupiedAlpha=nocca,\n numOccupiedBeta=noccb,\n coefficientMatrixAlpha=Cocca_device_handle,\n coefficientMatrixBeta=Coccb_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrixAlpha=Vxca_device_handle,\n outXCPotentialMatrixBeta=Vxcb_device_handle,\n )\n )\n\n del Vxc_workspace\n\n cuest_check('Destroy XCPotentialUKS Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALUKSCOMPUTE_PARAMETERS,\n parameters=compute_xc_potential_parameters,\n )\n )\n\n cuda_free(\n array=Cocca_device_pointer\n )\n cuda_free(\n array=Coccb_device_pointer\n )\n\n Vxca_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxca_host_array.ctypes.data,\n device_pointer=Vxca_device_pointer\n# ... truncated ...","source_hash":"c0010d25780dc5fba49aa065c463efdff41d85959134a25bee23185236112a88","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.local_xc_potential.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.4_exchange_correlation.local_xc_potential.run.run#L29-L627","kind":"function","name":"run","path":"cuEST/python_examples/4_exchange_correlation/local_xc_potential/run.py","language":"python","start_line":29,"end_line":627,"context_start_line":9,"context_end_line":647,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\nfrom helpers.grid_utils import build_ahlrichs_radial_quadrature, symbol_to_ahlrichs_radius\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n stream_handle = ce.data_cudaStream_t()\n cuest_check('Query Handle Stream',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n\n # => Build Molecular Integration Grid <= #\n\n atomgrid_parameters = ce.cuestAtomGridParameters()\n\n cuest_check('Create AtomGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n outParameters=atomgrid_parameters,\n )\n )\n\n atomgrids = []\n for atom,symbol in enumerate(symbols):\n # For simplicity, build an unpruned 75/302 grid using the Ahlrichs radial quadrature scheme\n ahlrichs_radius = symbol_to_ahlrichs_radius(\n symbol=symbol\n )\n radial_nodes, radial_weights = build_ahlrichs_radial_quadrature(\n npoint=75,\n R=ahlrichs_radius,\n )\n num_angular_points = [302]*len(radial_nodes)\n atomgrid_handle = ce.cuestAtomGridHandle()\n cuest_check(f'Create AtomGrid {atom}',\n ce.cuestAtomGridCreate(\n handle=cuest_handle,\n numRadialPoints=75,\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters,\n outAtomGrid=atomgrid_handle,\n )\n )\n atomgrids.append(atomgrid_handle)\n\n cuest_check('Destroy AtomGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n parameters=atomgrid_parameters,\n )\n )\n\n moleculargrid_parameters = ce.cuestMolecularGridParameters()\n\n cuest_check('Create MolecularGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n outParameters=moleculargrid_parameters,\n )\n )\n\n cuest_check('Create MolecularGrid Workspace Query',\n ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n )\n\n grid_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n moleculargrid=ce.cuestMolecularGridHandle()\n\n cuest_check('Create MolecularGrid',\n ce.cuestMolecularGridCreate(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=moleculargrid,\n )\n )\n\n del grid_temporary_workspace\n\n for atom,grid in enumerate(atomgrids):\n cuest_check(f'Destroy AtomGrid{atom}',\n ce.cuestAtomGridDestroy(\n atomGrid=grid,\n )\n )\n\n cuest_check('Destroy MolecularGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n parameters=moleculargrid_parameters,\n )\n )\n\n # => Build XC Integral Plan <= #\n\n xcintplan_parameters = ce.cuestXCIntPlanParameters()\n cuest_check('Create XCIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n outParameters=xcintplan_parameters,\n )\n )\n\n cuest_check('Create XCIntPlan Workspace Query',\n ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ce.cuestXCIntPlanHandle(),\n )\n )\n\n xcintplan = ce.cuestXCIntPlanHandle()\n xcintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n xcintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create XCIntPlan',\n ce.cuestXCIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspace=xcintplan_persistent_workspace.pointer,\n temporaryWorkspace=xcintplan_temporary_workspace.pointer,\n outPlan=xcintplan,\n )\n )\n\n del xcintplan_temporary_workspace\n\n cuest_check('Destroy XCIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xcintplan_parameters,\n )\n )\n\n # => RKS Potential Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n nocc = np.abs(int(np.sum(Zs)//2))\n\n Cocc_host = np.random.normal(size=(nocc, nao)).astype(np.double)\n Cocc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n Cocc_device_handle = ce.Pointer(Cocc_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocc_device_pointer,\n host_pointer=Cocc_host.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Potential Compute Routines <= #\n\n Vxc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxc_device_handle = ce.Pointer(Vxc_device_pointer)\n compute_xc_potential_parameters = ce.cuestXCPotentialRKSComputeParameters()\n cuest_check('XCPotentialRKS Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS,\n outParameters=compute_xc_potential_parameters,\n )\n )\n\n Exc = ce.data_double()\n cuest_check('XCPotentialRKSCompute Workspace Query',\n ce.cuestXCPotentialRKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=compute_xc_potential_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxc_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('XCPotentialRKSCompute',\n ce.cuestXCPotentialRKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=compute_xc_potential_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxc_device_handle,\n )\n )\n\n del Vxc_workspace\n\n cuda_free(\n array=Cocc_device_pointer\n )\n\n cuest_check('Destroy XCPotentialRKS Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=compute_xc_potential_parameters,\n )\n )\n\n Vxc_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxc_host_array.ctypes.data,\n device_pointer=Vxc_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxc_device_pointer\n )\n\n # => UKS Potential Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n # Assume a cation\n nocca = np.abs(int(np.sum(Zs)//2))\n noccb = nocca - 1\n\n # Alpha and Beta occupied molecular orbitals\n Cocca_host = np.random.normal(size=(nocca, nao)).astype(np.double)\n Cocca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocca * nao\n )\n Cocca_device_handle = ce.Pointer(Cocca_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocca_device_pointer,\n host_pointer=Cocca_host.ctypes.data,\n size_in_bytes=sizeof_double * nocca * nao,\n stream=stream_handle.value,\n )\n\n Coccb_host = np.random.normal(size=(noccb, nao)).astype(np.double)\n Coccb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * noccb * nao\n )\n Coccb_device_handle = ce.Pointer(Coccb_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Coccb_device_pointer,\n host_pointer=Coccb_host.ctypes.data,\n size_in_bytes=sizeof_double * noccb * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Potential Compute Routines <= #\n\n Vxca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxca_device_handle = ce.Pointer(Vxca_device_pointer)\n\n Vxcb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxcb_device_handle = ce.Pointer(Vxcb_device_pointer)\n\n compute_xc_potential_parameters = ce.cuestXCPotentialUKSComputeParameters()\n cuest_check('XCPotentialUKS Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALUKSCOMPUTE_PARAMETERS,\n outParameters=compute_xc_potential_parameters,\n )\n )\n\n Exc = ce.data_double()\n cuest_check('XCPotentialUKSCompute Workspace Query',\n ce.cuestXCPotentialUKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=compute_xc_potential_parameters,\n numOccupiedAlpha=nocca,\n numOccupiedBeta=noccb,\n coefficientMatrixAlpha=Cocca_device_handle,\n coefficientMatrixBeta=Coccb_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrixAlpha=Vxca_device_handle,\n outXCPotentialMatrixBeta=Vxcb_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('XCPotentialUKSCompute',\n ce.cuestXCPotentialUKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=compute_xc_potential_parameters,\n numOccupiedAlpha=nocca,\n numOccupiedBeta=noccb,\n coefficientMatrixAlpha=Cocca_device_handle,\n coefficientMatrixBeta=Coccb_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrixAlpha=Vxca_device_handle,\n outXCPotentialMatrixBeta=Vxcb_device_handle,\n )\n )\n\n del Vxc_workspace\n\n cuest_check('Destroy XCPotentialUKS Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALUKSCOMPUTE_PARAMETERS,\n parameters=compute_xc_potential_parameters,\n )\n )\n\n cuda_free(\n array=Cocca_device_pointer\n )\n cuda_free(\n array=Coccb_device_pointer\n )\n\n Vxca_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxca_host_array.ctypes.data,\n device_pointer=Vxca_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n stream=stream_handle.value,\n )\n\n Vxcb_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxcb_host_array.ctypes.data,\n device_pointer=Vxcb_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n stream=st\n# ... truncated ...","source_hash":"c0010d25780dc5fba49aa065c463efdff41d85959134a25bee23185236112a88","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.local_xc_potential.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.4_exchange_correlation.local_xc_potential.run.cuest_check#L52-L59","kind":"function","name":"cuest_check","path":"cuEST/python_examples/4_exchange_correlation/local_xc_potential/run.py","language":"python","start_line":52,"end_line":59,"context_start_line":32,"context_end_line":79,"code":" gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n","source_hash":"c0010d25780dc5fba49aa065c463efdff41d85959134a25bee23185236112a88","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.nonlocal_xc_potential.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.4_exchange_correlation.nonlocal_xc_potential.run#L1-L690","kind":"module","name":"cuEST.python_examples.4_exchange_correlation.nonlocal_xc_potential.run","path":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_potential/run.py","language":"python","start_line":1,"end_line":690,"context_start_line":1,"context_end_line":690,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\nfrom helpers.grid_utils import build_ahlrichs_radial_quadrature, symbol_to_ahlrichs_radius\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n stream_handle = ce.data_cudaStream_t()\n cuest_check('Query Handle Stream',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n\n # => Build Molecular Integration Grid <= #\n\n atomgrid_parameters = ce.cuestAtomGridParameters()\n\n cuest_check('Create AtomGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n outParameters=atomgrid_parameters,\n )\n )\n\n atomgrids = []\n for atom,symbol in enumerate(symbols):\n # For simplicity, build an unpruned 75/302 grid using the Ahlrichs radial quadrature scheme\n ahlrichs_radius = symbol_to_ahlrichs_radius(\n symbol=symbol\n )\n radial_nodes, radial_weights = build_ahlrichs_radial_quadrature(\n npoint=75,\n R=ahlrichs_radius,\n )\n num_angular_points = [302]*len(radial_nodes)\n atomgrid_handle = ce.cuestAtomGridHandle()\n cuest_check(f'Create AtomGrid {atom}',\n ce.cuestAtomGridCreate(\n handle=cuest_handle,\n numRadialPoints=75,\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters,\n outAtomGrid=atomgrid_handle,\n )\n )\n atomgrids.append(atomgrid_handle)\n\n cuest_check('Destroy AtomGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n parameters=atomgrid_parameters,\n )\n )\n\n moleculargrid_parameters = ce.cuestMolecularGridParameters()\n\n cuest_check('Create MolecularGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n outParameters=moleculargrid_parameters,\n )\n )\n\n cuest_check('Create MolecularGrid Workspace Query',\n ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n )\n\n grid_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n moleculargrid=ce.cuestMolecularGridHandle()\n\n cuest_check('Create MolecularGrid',\n ce.cuestMolecularGridCreate(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=moleculargrid,\n )\n )\n\n del grid_temporary_workspace\n\n for atom,grid in enumerate(atomgrids):\n cuest_check(f'Destroy AtomGrid{atom}',\n ce.cuestAtomGridDestroy(\n atomGrid=grid,\n )\n )\n\n cuest_check('Destroy MolecularGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n parameters=moleculargrid_parameters,\n )\n )\n\n # => Build XC Integral Plan <= #\n\n xcintplan_parameters = ce.cuestXCIntPlanParameters()\n cuest_check('Create XCIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n outParameters=xcintplan_parameters,\n )\n )\n\n cuest_check('Create XCIntPlan Workspace Query',\n ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ce.cuestXCIntPlanHandle(),\n )\n )\n\n xcintplan = ce.cuestXCIntPlanHandle()\n xcintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n xcintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create XCIntPlan',\n ce.cuestXCIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspace=xcintplan_persistent_workspace.pointer,\n temporaryWorkspace=xcintplan_temporary_workspace.pointer,\n outPlan=xcintplan,\n )\n )\n\n del xcintplan_temporary_workspace\n\n cuest_check('Destroy XCIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xcintplan_parameters,\n )\n )\n\n # => Configure the Nonlocal Potential <= #\n\n nonlocal_xc_compute_parameters = ce.cuestNonlocalXCPotentialRKSComputeParameters()\n\n cuest_check('NonlocalXC Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n outParameters=nonlocal_xc_compute_parameters,\n )\n )\n\n vv10_b = ce.data_double(6.0)\n cuest_check('VV10 b Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n )\n\n vv10_C = ce.data_double(0.01)\n cuest_check('VV10 C Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n )\n\n vv10_scale = ce.data_double(1.0)\n cuest_check('VV10 Scale Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n )\n\n # => RKS Potential Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n nocc = np.abs(int(np.sum(Zs)//2))\n\n Cocc_host = np.random.normal(size=(nocc, nao)).astype(np.double)\n Cocc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n Cocc_device_handle = ce.Pointer(Cocc_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocc_device_pointer,\n host_pointer=Cocc_host.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Potential Compute Routines <= #\n\n Vxc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxc_device_handle = ce.Pointer(Vxc_device_pointer)\n\n Exc = ce.data_double()\n cuest_check('NonlocalXCPotentialRKSCompute Workspace Query',\n ce.cuestNonlocalXCPotentialRKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=nonlocal_xc_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxc_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('NonlocalXCPotentialRKSCompute',\n ce.cuestNonlocalXCPotentialRKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=nonlocal_xc_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxc_device_handle,\n )\n )\n\n del Vxc_workspace\n\n cuda_free(\n array=Cocc_device_pointer\n )\n cuest_check('Destroy NonlocalXC Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n )\n )\n\n Vxc_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxc_host_array.ctypes.data,\n device_pointer=Vxc_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxc_device_pointer\n )\n\n # => UKS Potential Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n # Assume a cation\n nocca = np.abs(int(np.sum(Zs)//2))\n noccb = nocca - 1\n\n # Alpha and Beta occupied molecular orbitals\n Cocca_host = np.random.normal(size=(nocca, nao)).astype(np.double)\n Cocca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocca * nao\n )\n Cocca_device_handle = ce.Pointer(Cocca_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocca_device_pointer,\n host_pointer=Cocca_host.ctypes.data,\n size_in_bytes=sizeof_double * nocca * nao,\n stream=stream_handle.value,\n )\n\n Coccb_host = np.random.normal(size=(noccb, nao)).astype(np.double)\n Coccb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * noccb * nao\n )\n Coccb_device_handle = ce.Pointer(Coccb_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Coccb_device_pointer,\n host_pointer=Coccb_host.ctypes.data,\n size_in_bytes=sizeof_double * noccb * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Potential Compute Routines <= #\n\n Vxc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxc_device_handle = ce.Pointer(Vxc_device_pointer)\n nonlocal_xc_compute_parameters = ce.cuestNonlocalXCPotentialUKSComputeParameters()\n\n cuest_check('NonlocalXC UKS Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS,\n outParameters=nonlocal_xc_compute_parameters,\n )\n )\n vv10_b = ce.data_double(6.0)\n cuest_check('VV10 b UKS Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialUKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n )\n vv10_C = ce.data_double(0.01)\n cuest_check('VV10 C UKS Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameter\n# ... truncated ...","source_hash":"a899e219421e4688f87d2a417ff709780b4311c9dd5489c60d316f5fe5f66943","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.nonlocal_xc_potential.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.4_exchange_correlation.nonlocal_xc_potential.run.run#L29-L666","kind":"function","name":"run","path":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_potential/run.py","language":"python","start_line":29,"end_line":666,"context_start_line":9,"context_end_line":686,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\nfrom helpers.grid_utils import build_ahlrichs_radial_quadrature, symbol_to_ahlrichs_radius\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n stream_handle = ce.data_cudaStream_t()\n cuest_check('Query Handle Stream',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Sets From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n # Orbital Basis\n aobasis_handle = ce.cuestAOBasisHandle()\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n\n # => Build Molecular Integration Grid <= #\n\n atomgrid_parameters = ce.cuestAtomGridParameters()\n\n cuest_check('Create AtomGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n outParameters=atomgrid_parameters,\n )\n )\n\n atomgrids = []\n for atom,symbol in enumerate(symbols):\n # For simplicity, build an unpruned 75/302 grid using the Ahlrichs radial quadrature scheme\n ahlrichs_radius = symbol_to_ahlrichs_radius(\n symbol=symbol\n )\n radial_nodes, radial_weights = build_ahlrichs_radial_quadrature(\n npoint=75,\n R=ahlrichs_radius,\n )\n num_angular_points = [302]*len(radial_nodes)\n atomgrid_handle = ce.cuestAtomGridHandle()\n cuest_check(f'Create AtomGrid {atom}',\n ce.cuestAtomGridCreate(\n handle=cuest_handle,\n numRadialPoints=75,\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters,\n outAtomGrid=atomgrid_handle,\n )\n )\n atomgrids.append(atomgrid_handle)\n\n cuest_check('Destroy AtomGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS,\n parameters=atomgrid_parameters,\n )\n )\n\n moleculargrid_parameters = ce.cuestMolecularGridParameters()\n\n cuest_check('Create MolecularGrid Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n outParameters=moleculargrid_parameters,\n )\n )\n\n cuest_check('Create MolecularGrid Workspace Query',\n ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n )\n\n grid_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n moleculargrid=ce.cuestMolecularGridHandle()\n\n cuest_check('Create MolecularGrid',\n ce.cuestMolecularGridCreate(\n handle=cuest_handle,\n numAtoms=len(Zs),\n atomGrid=atomgrids,\n xyz=xyzs,\n parameters=moleculargrid_parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=moleculargrid,\n )\n )\n\n del grid_temporary_workspace\n\n for atom,grid in enumerate(atomgrids):\n cuest_check(f'Destroy AtomGrid{atom}',\n ce.cuestAtomGridDestroy(\n atomGrid=grid,\n )\n )\n\n cuest_check('Destroy MolecularGrid Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS,\n parameters=moleculargrid_parameters,\n )\n )\n\n # => Build XC Integral Plan <= #\n\n xcintplan_parameters = ce.cuestXCIntPlanParameters()\n cuest_check('Create XCIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n outParameters=xcintplan_parameters,\n )\n )\n\n cuest_check('Create XCIntPlan Workspace Query',\n ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ce.cuestXCIntPlanHandle(),\n )\n )\n\n xcintplan = ce.cuestXCIntPlanHandle()\n xcintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n xcintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create XCIntPlan',\n ce.cuestXCIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n grid=moleculargrid,\n functional=ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE,\n parameters=xcintplan_parameters,\n persistentWorkspace=xcintplan_persistent_workspace.pointer,\n temporaryWorkspace=xcintplan_temporary_workspace.pointer,\n outPlan=xcintplan,\n )\n )\n\n del xcintplan_temporary_workspace\n\n cuest_check('Destroy XCIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xcintplan_parameters,\n )\n )\n\n # => Configure the Nonlocal Potential <= #\n\n nonlocal_xc_compute_parameters = ce.cuestNonlocalXCPotentialRKSComputeParameters()\n\n cuest_check('NonlocalXC Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n outParameters=nonlocal_xc_compute_parameters,\n )\n )\n\n vv10_b = ce.data_double(6.0)\n cuest_check('VV10 b Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n )\n\n vv10_C = ce.data_double(0.01)\n cuest_check('VV10 C Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n )\n\n vv10_scale = ce.data_double(1.0)\n cuest_check('VV10 Scale Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n )\n\n # => RKS Potential Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n nocc = np.abs(int(np.sum(Zs)//2))\n\n Cocc_host = np.random.normal(size=(nocc, nao)).astype(np.double)\n Cocc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocc * nao\n )\n Cocc_device_handle = ce.Pointer(Cocc_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocc_device_pointer,\n host_pointer=Cocc_host.ctypes.data,\n size_in_bytes=sizeof_double * nocc * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Potential Compute Routines <= #\n\n Vxc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxc_device_handle = ce.Pointer(Vxc_device_pointer)\n\n Exc = ce.data_double()\n cuest_check('NonlocalXCPotentialRKSCompute Workspace Query',\n ce.cuestNonlocalXCPotentialRKSComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n parameters=nonlocal_xc_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxc_device_handle,\n )\n )\n\n Vxc_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('NonlocalXCPotentialRKSCompute',\n ce.cuestNonlocalXCPotentialRKSCompute(\n handle=cuest_handle,\n plan=xcintplan,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=Vxc_workspace.pointer,\n parameters=nonlocal_xc_compute_parameters,\n numOccupied=nocc,\n coefficientMatrix=Cocc_device_handle,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxc_device_handle,\n )\n )\n\n del Vxc_workspace\n\n cuda_free(\n array=Cocc_device_pointer\n )\n cuest_check('Destroy NonlocalXC Parameters',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n )\n )\n\n Vxc_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n cuda_memcpy_dtoh(\n host_pointer=Vxc_host_array.ctypes.data,\n device_pointer=Vxc_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n stream=stream_handle.value,\n )\n\n cuda_free(\n array=Vxc_device_pointer\n )\n\n # => UKS Potential Matrix Computation <= #\n\n # => Build Fake Occupied Orbitals <= #\n\n # Assume a cation\n nocca = np.abs(int(np.sum(Zs)//2))\n noccb = nocca - 1\n\n # Alpha and Beta occupied molecular orbitals\n Cocca_host = np.random.normal(size=(nocca, nao)).astype(np.double)\n Cocca_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nocca * nao\n )\n Cocca_device_handle = ce.Pointer(Cocca_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Cocca_device_pointer,\n host_pointer=Cocca_host.ctypes.data,\n size_in_bytes=sizeof_double * nocca * nao,\n stream=stream_handle.value,\n )\n\n Coccb_host = np.random.normal(size=(noccb, nao)).astype(np.double)\n Coccb_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * noccb * nao\n )\n Coccb_device_handle = ce.Pointer(Coccb_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Coccb_device_pointer,\n host_pointer=Coccb_host.ctypes.data,\n size_in_bytes=sizeof_double * noccb * nao,\n stream=stream_handle.value,\n )\n\n # => Call the XC Potential Compute Routines <= #\n\n Vxc_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n Vxc_device_handle = ce.Pointer(Vxc_device_pointer)\n nonlocal_xc_compute_parameters = ce.cuestNonlocalXCPotentialUKSComputeParameters()\n\n cuest_check('NonlocalXC UKS Parameters Create',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS,\n outParameters=nonlocal_xc_compute_parameters,\n )\n )\n vv10_b = ce.data_double(6.0)\n cuest_check('VV10 b UKS Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialUKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n )\n vv10_C = ce.data_double(0.01)\n cuest_check('VV10 C UKS Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters,\n attribute=ce.CuestNonlocalXCPotentialUKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALUKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n )\n vv10_scale = ce.data_double(1.0)\n cuest_check('VV10 Scale UKS Parameter Configure',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestP\n# ... truncated ...","source_hash":"a899e219421e4688f87d2a417ff709780b4311c9dd5489c60d316f5fe5f66943","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.4_exchange_correlation.nonlocal_xc_potential.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.4_exchange_correlation.nonlocal_xc_potential.run.cuest_check#L52-L59","kind":"function","name":"cuest_check","path":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_potential/run.py","language":"python","start_line":52,"end_line":59,"context_start_line":32,"context_end_line":79,"code":" gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2Gb of DRAM for XC evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n","source_hash":"a899e219421e4688f87d2a417ff709780b4311c9dd5489c60d316f5fe5f66943","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.1_basic_data_structures.ao_shells.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.1_basic_data_structures.ao_shells.run#L1-L247","kind":"module","name":"cuEST.python_examples.1_basic_data_structures.ao_shells.run","path":"cuEST/python_examples/1_basic_data_structures/ao_shells/run.py","language":"python","start_line":1,"end_line":247,"context_start_line":1,"context_end_line":247,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nimport sys\nfrom pathlib import Path\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\n\n# This is the def2-SVP basis set definition for O and H\n\nH_basis = {\n 'n_shells' : 3,\n 'shell_types' : [0, 0, 1],\n 'primitive_counts' : [3, 1, 1],\n 'primitive_offsets' : [0, 3, 4],\n 'exponents' : [\n 13.0107010, 1.9622572, 0.44453796,\n 0.12194962,\n 0.8000000\n ],\n 'coefficients' : [\n 0.019682158, 0.13796524, 0.47831935,\n 1.0,\n 1.0\n ],\n }\n\nO_basis = {\n 'n_shells' : 6,\n 'shell_types' : [0, 0, 0, 1, 1, 2],\n 'primitive_counts' : [5, 1, 1, 3, 1, 1],\n 'primitive_offsets' : [0, 5, 6, 7, 10, 11],\n 'exponents' : [\n 2266.1767785, 340.87010191, 77.363135167, 21.479644940, 6.6589433124,\n 0.80975975668,\n 0.25530772234,\n 17.721504317, 3.8635505440, 1.0480920883,\n 0.27641544411,\n 1.2\n ],\n 'coefficients' : [\n -0.0053431809926, -0.039890039230, -0.17853911985, -0.46427684959, -0.44309745172,\n 1.0,\n 1.0,\n 0.043394573193, 0.23094120765, 0.51375311064,\n 1.0,\n 1.0\n ],\n }\n\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\n\ncuest_handle_parameters = ce.cuestHandleParameters()\ncuest_check(\"Parameters Create\",\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\ncuest_handle = ce.cuestHandle()\ncuest_check(\"Cuest Handle Create\",\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\ncuest_check(\"Parameters Destroy\",\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n\naoshell_parameters = ce.cuestAOShellParameters()\ncuest_check(\"AO Shell Parameters Create\",\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n# Make a water molecule as an example\nbasis_is_pure = 1\nshells = []\natom_symbols = [\"O\", \"H\", \"H\"]\natom_bases = [O_basis, H_basis, H_basis]\nfor shellinfo in atom_bases:\n this_atom_shells = []\n\n for offset, count, L in zip(\n shellinfo['primitive_offsets'],\n shellinfo['primitive_counts'],\n shellinfo['shell_types']\n ):\n\n exponents = shellinfo['exponents'][offset:offset+count]\n coefficients = shellinfo['coefficients'][offset:offset+count]\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=coefficients,\n exponents=exponents,\n L=L,\n normalization=1.0,\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(\"AO Shell Create\",\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=basis_is_pure,\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle\n )\n )\n this_atom_shells.append(aoshell_handle)\n shells.append(this_atom_shells)\n\ncuest_check(\"AO Shell Parameters Destroy\",\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n# Query each shell for its metadata, and print\nfor atom_number, atom_shells in enumerate(shells):\n\n print(f\"Atom {atom_number+1} ({atom_symbols[atom_number]})\")\n\n for shell_count, atom_shell in enumerate(atom_shells):\n print(f\"\\tShell {shell_count+1}\")\n is_pure = ce.data_int32_t()\n cuest_check(\"Query IS_PURE\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_IS_PURE,\n attributeValue=is_pure,\n )\n )\n print(f\"\\t\\tIs Pure : {is_pure.value}\")\n\n L = ce.data_uint64_t()\n cuest_check(\"Query L\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_L,\n attributeValue=L,\n )\n )\n print(f\"\\t\\tAngular Momentum : {L.value}\")\n\n nprim = ce.data_uint64_t()\n cuest_check(\"Query Num Primitives\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_NUM_PRIMITIVE,\n attributeValue=nprim,\n )\n )\n print(f\"\\t\\tNum. Primitives : {nprim.value}\")\n\n nao = ce.data_uint64_t()\n cuest_check(\"Query Num Basis Functions\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_NUM_AO,\n attributeValue=nao,\n )\n )\n print(f\"\\t\\tNum. Basis Functions : {nao.value}\")\n\n npure = ce.data_uint64_t()\n cuest_check(\"Query Num Pure Functions\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_NUM_PURE,\n attributeValue=npure,\n )\n )\n print(f\"\\t\\tNum. Pure Functions : {npure.value}\")\n\n ncart = ce.data_uint64_t()\n cuest_check(\"Query Num Cart Functions\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_NUM_CART,\n attributeValue=npure,\n )\n )\n print(f\"\\t\\tNum. Cartesian Functions : {npure.value}\")\n\n# Destroy the shells\nfor atom_shells in shells:\n for atom_shell in atom_shells:\n cuest_check(\"Destroy AO Shell\",\n ce.cuestAOShellDestroy(\n handle=atom_shell,\n )\n )\n\n# Delete the cuEST handle\ncuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )","source_hash":"75b5f9cfb024d13901886e0810141bf82f67940d8c4c9bb3389519a7d55a7dcd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.1_basic_data_structures.ao_shells.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.1_basic_data_structures.ao_shells.run.cuest_check#L69-L75","kind":"function","name":"cuest_check","path":"cuEST/python_examples/1_basic_data_structures/ao_shells/run.py","language":"python","start_line":69,"end_line":75,"context_start_line":49,"context_end_line":95,"code":" 'primitive_offsets' : [0, 5, 6, 7, 10, 11],\n 'exponents' : [\n 2266.1767785, 340.87010191, 77.363135167, 21.479644940, 6.6589433124,\n 0.80975975668,\n 0.25530772234,\n 17.721504317, 3.8635505440, 1.0480920883,\n 0.27641544411,\n 1.2\n ],\n 'coefficients' : [\n -0.0053431809926, -0.039890039230, -0.17853911985, -0.46427684959, -0.44309745172,\n 1.0,\n 1.0,\n 0.043394573193, 0.23094120765, 0.51375311064,\n 1.0,\n 1.0\n ],\n }\n\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\n\ncuest_handle_parameters = ce.cuestHandleParameters()\ncuest_check(\"Parameters Create\",\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\ncuest_handle = ce.cuestHandle()\ncuest_check(\"Cuest Handle Create\",\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\ncuest_check(\"Parameters Destroy\",\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,","source_hash":"75b5f9cfb024d13901886e0810141bf82f67940d8c4c9bb3389519a7d55a7dcd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.1_basic_data_structures.ao_basis.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.1_basic_data_structures.ao_basis.run#L1-L409","kind":"module","name":"cuEST.python_examples.1_basic_data_structures.ao_basis.run","path":"cuEST/python_examples/1_basic_data_structures/ao_basis/run.py","language":"python","start_line":1,"end_line":409,"context_start_line":1,"context_end_line":409,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nimport sys\nfrom pathlib import Path\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\n\n# This is the def2-SVP basis set definition for O and H\n\nH_basis = {\n 'n_shells' : 3,\n 'shell_types' : [0, 0, 1],\n 'primitive_counts' : [3, 1, 1],\n 'primitive_offsets' : [0, 3, 4],\n 'exponents' : [\n 13.0107010, 1.9622572, 0.44453796,\n 0.12194962,\n 0.8000000\n ],\n 'coefficients' : [\n 0.019682158, 0.13796524, 0.47831935,\n 1.0,\n 1.0\n ],\n }\n\nO_basis = {\n 'n_shells' : 6,\n 'shell_types' : [0, 0, 0, 1, 1, 2],\n 'primitive_counts' : [5, 1, 1, 3, 1, 1],\n 'primitive_offsets' : [0, 5, 6, 7, 10, 11],\n 'exponents' : [\n 2266.1767785, 340.87010191, 77.363135167, 21.479644940, 6.6589433124,\n 0.80975975668,\n 0.25530772234,\n 17.721504317, 3.8635505440, 1.0480920883,\n 0.27641544411,\n 1.2\n ],\n 'coefficients' : [\n -0.0053431809926, -0.039890039230, -0.17853911985, -0.46427684959, -0.44309745172,\n 1.0,\n 1.0,\n 0.043394573193, 0.23094120765, 0.51375311064,\n 1.0,\n 1.0\n ],\n }\n\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\n\ncuest_handle_parameters = ce.cuestHandleParameters()\ncuest_check(\"Parameters Create\",\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\ncuest_handle = ce.cuestHandle()\ncuest_check(\"Cuest Handle Create\",\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\ncuest_check(\"Parameters Destroy\",\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n\naoshell_parameters = ce.cuestAOShellParameters()\ncuest_check(\"AO Shell Parameters Create\",\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n# Make a water molecule as an example\nbasis_is_pure = 1\nshells = []\natom_symbols = [\"O\", \"H\", \"H\"]\natom_bases = [O_basis, H_basis, H_basis]\nfor shellinfo in atom_bases:\n this_atom_shells = []\n\n for offset, count, L in zip(\n shellinfo['primitive_offsets'],\n shellinfo['primitive_counts'],\n shellinfo['shell_types']\n ):\n\n exponents = shellinfo['exponents'][offset:offset+count]\n coefficients = shellinfo['coefficients'][offset:offset+count]\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=coefficients,\n exponents=exponents,\n L=L,\n normalization=1.0,\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(\"AO Shell Create\",\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=basis_is_pure,\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle\n )\n )\n this_atom_shells.append(aoshell_handle)\n shells.append(this_atom_shells)\n\nn_shells_per_atom = [len(atom_shells) for atom_shells in shells]\n\ncuest_check(\"AO Shell Parameters Destroy\",\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n# Query each shell for its metadata, and print\nfor atom_number, atom_shells in enumerate(shells):\n\n print(f\"Atom {atom_number+1} ({atom_symbols[atom_number]})\")\n\n for shell_count, atom_shell in enumerate(atom_shells):\n print(f\"\\tShell {shell_count+1}\")\n is_pure = ce.data_int32_t()\n cuest_check(\"Query IS_PURE\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_IS_PURE,\n attributeValue=is_pure,\n )\n )\n print(f\"\\t\\tIs Pure : {is_pure.value}\")\n\n L = ce.data_uint64_t()\n cuest_check(\"Query L\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_L,\n attributeValue=L,\n )\n )\n print(f\"\\t\\tAngular Momentum : {L.value}\")\n\n nprim = ce.data_uint64_t()\n cuest_check(\"Query Num Primitives\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_NUM_PRIMITIVE,\n attributeValue=nprim,\n )\n )\n print(f\"\\t\\tNum. Primitives : {nprim.value}\")\n\n nao = ce.data_uint64_t()\n cuest_check(\"Query Num Basis Functions\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_NUM_AO,\n attributeValue=nao,\n )\n )\n print(f\"\\t\\tNum. Basis Functions : {nao.value}\")\n\n npure = ce.data_uint64_t()\n cuest_check(\"Query Num Pure Functions\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_NUM_PURE,\n attributeValue=npure,\n )\n )\n print(f\"\\t\\tNum. Pure Functions : {npure.value}\")\n\n ncart = ce.data_uint64_t()\n cuest_check(\"Query Num Cart Functions\",\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOSHELL,\n object=atom_shell,\n attribute=ce.CuestAOShellAttributes.CUEST_AOSHELL_NUM_CART,\n attributeValue=npure,\n )\n )\n print(f\"\\t\\tNum. Cartesian Functions : {npure.value}\")\n\n# These workspace descriptors will be used in the resource query to figure out\n# how much device/host RAM will be needed in persistent/temporary workspaces to\n# build the AOBasis object.\npersistent_workspace_descriptor = WorkspaceDescriptor()\ntemporary_workspace_descriptor = WorkspaceDescriptor()\n\naobasis_parameters = ce.cuestAOBasisParameters()\ncuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n\n# We made a list of list of shells above, to easily determine which atom each\n# belongs to. Flatten that list here, for the AOBasis creation routines.\nshells = [ s for atom_shells in shells for s in atom_shells ]\n\naobasis_handle = ce.cuestAOBasisHandle()\n\n# Find out the resources needed to build the AOBasis\ncuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(atom_symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\nprint(\"AO Basis Persistent sizes:\", persistent_workspace_descriptor)\nprint(\"AO Basis Temporary sizes:\", temporary_workspace_descriptor)\n\n# Create the workspaces. The functions called here are just an example of how\n# the host/device workspaces may be created; it is the caller's responsibility\n# to allocate and free these workspaces appropriately.\naobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\naobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\ncuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(atom_symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\ndel aobasis_temporary_workspace\n\nfor i, shell in enumerate(shells):\n cuest_check('Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\ncuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n# Query the basis for metadata and print the results\n\naobasis_is_pure = ce.data_int32_t()\ncuest_check('Query AO Basis Is Pure',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_PURE,\n attributeValue=aobasis_is_pure,\n )\n )\nprint(f\"AO Basis Is Pure : {aobasis_is_pure.value}\")\n\naobasis_num_atom = ce.data_uint64_t()\ncuest_check('Query AO Basis Num Atom',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_ATOM,\n attributeValue=aobasis_num_atom,\n )\n )\nprint(f\"AO Basis Num Atom : {aobasis_num_atom.value}\")\n\naobasis_num_shell = ce.data_uint64_t()\ncuest_check('Query AO Basis Num Shell',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_SHELL,\n attributeValue=aobasis_num_shell,\n )\n )\nprint(f\"AO Basis Num Shell : {aobasis_num_shell.value}\")\n\naobasis_num_ao = ce.data_uint64_t()\ncuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\nprint(f\"AO Basis Num AO : {aobasis_num_ao.value}\")\n\naobasis_num_cart = ce.data_uint64_t()\ncuest_check('Query AO Basis Num Cart',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_CART,\n attributeValue=aobasis_num_cart,\n )\n )\nprint(f\"AO Basis Num Cart : {aobasis_num_cart.value}\")\n\naobasis_num_primitive = ce.data_uint64_t()\ncuest_check('Query AO Basis Num Primitive',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_PRIMITIVE,\n attributeValue=aobasis_num_primitive,\n )\n )\nprint(f\"AO Basis Num Primitive : {aobasis_num_primitive.value}\")\n\naobasis_max_L = ce.data_uint64_t()\ncuest_check('Query AO Basis Num Primitive',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_MAX_L,\n attributeValue=aobasis_max_L,\n )\n )\nprint(f\"AO Basis Max. Ang. Mom. : {aobasis_max_L.value}\")\n\n\ncuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\ndel aobasis_persistent_workspace\n\n# Delete the cuEST handle\ncuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n","source_hash":"5cadb3aac5e36032e002edd8bb480ba2c52213de36e896dc8e2ca0e62d7ae3f3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.1_basic_data_structures.ao_basis.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.1_basic_data_structures.ao_basis.run.cuest_check#L69-L75","kind":"function","name":"cuest_check","path":"cuEST/python_examples/1_basic_data_structures/ao_basis/run.py","language":"python","start_line":69,"end_line":75,"context_start_line":49,"context_end_line":95,"code":" 'primitive_offsets' : [0, 5, 6, 7, 10, 11],\n 'exponents' : [\n 2266.1767785, 340.87010191, 77.363135167, 21.479644940, 6.6589433124,\n 0.80975975668,\n 0.25530772234,\n 17.721504317, 3.8635505440, 1.0480920883,\n 0.27641544411,\n 1.2\n ],\n 'coefficients' : [\n -0.0053431809926, -0.039890039230, -0.17853911985, -0.46427684959, -0.44309745172,\n 1.0,\n 1.0,\n 0.043394573193, 0.23094120765, 0.51375311064,\n 1.0,\n 1.0\n ],\n }\n\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\n\ncuest_handle_parameters = ce.cuestHandleParameters()\ncuest_check(\"Parameters Create\",\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\ncuest_handle = ce.cuestHandle()\ncuest_check(\"Cuest Handle Create\",\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\ncuest_check(\"Parameters Destroy\",\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,","source_hash":"5cadb3aac5e36032e002edd8bb480ba2c52213de36e896dc8e2ca0e62d7ae3f3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.5_effective_core_potentials.ecp_integrals.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.5_effective_core_potentials.ecp_integrals.run#L1-L508","kind":"module","name":"cuEST.python_examples.5_effective_core_potentials.ecp_integrals.run","path":"cuEST/python_examples/5_effective_core_potentials/ecp_integrals/run.py","language":"python","start_line":1,"end_line":508,"context_start_line":1,"context_end_line":508,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser, simple_ecp_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ecp_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, _ = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n ecp_metadata = simple_ecp_parser(\n filename=ecp_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2 GB of DRAM for ECP evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n # => cuEST Handle Setup <= #\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Set From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n aobasis_handle = ce.cuestAOBasisHandle()\n\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build ECP Shells and Atoms <= #\n\n # Create ECP shell parameters (shared for all ECP shell creation calls)\n ecpshell_parameters = ce.cuestECPShellParameters()\n cuest_check('Create ECP Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPSHELL_PARAMETERS,\n outParameters=ecpshell_parameters,\n )\n )\n\n # Create ECP shells once per unique element type. When multiple atoms of the\n # same element are present, their ECP data is identical so the shell handles\n # are shared across all atoms of that element.\n unique_symbol_shells = {} # symbol -> {'top_shell': handle, 'shells': [handles]}\n for symbol, info in zip(symbols, ecp_metadata):\n if info is None or symbol in unique_symbol_shells:\n continue\n\n # Create the top shell (the max-L projector)\n top_shell_info = info['top_shell']\n top_shell_handle = ce.cuestECPShellHandle()\n cuest_check(f'Create ECP Top Shell for {symbol}',\n ce.cuestECPShellCreate(\n handle=cuest_handle,\n L=top_shell_info.L,\n numPrimitive=len(top_shell_info.ns),\n radialPowers=top_shell_info.ns,\n coefficients=top_shell_info.ws,\n exponents=top_shell_info.es,\n parameters=ecpshell_parameters,\n outECPShell=top_shell_handle,\n )\n )\n\n # Create the angular-momentum projected shells\n shell_handles = []\n for k, shell_info in enumerate(info['shells']):\n shell_handle = ce.cuestECPShellHandle()\n cuest_check(f'Create ECP Shell {k} for {symbol}',\n ce.cuestECPShellCreate(\n handle=cuest_handle,\n L=shell_info.L,\n numPrimitive=len(shell_info.ns),\n radialPowers=shell_info.ns,\n coefficients=shell_info.ws,\n exponents=shell_info.es,\n parameters=ecpshell_parameters,\n outECPShell=shell_handle,\n )\n )\n shell_handles.append(shell_handle)\n\n unique_symbol_shells[symbol] = {\n 'top_shell': top_shell_handle,\n 'shells': shell_handles,\n }\n\n cuest_check('Destroy ECP Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPSHELL_PARAMETERS,\n parameters=ecpshell_parameters,\n )\n )\n\n # Create ECP atom parameters (shared for all ECP atom creation calls)\n ecpatom_parameters = ce.cuestECPAtomParameters()\n cuest_check('Create ECP Atom Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPATOM_PARAMETERS,\n outParameters=ecpatom_parameters,\n )\n )\n\n # Create one ECP atom handle per active atom (atoms that carry an ECP)\n ecp_atom_indices = [] # indices into the full atom list\n ecp_atom_handles = [] # corresponding cuestECPAtomHandle objects\n for atom_index, (symbol, info) in enumerate(zip(symbols, ecp_metadata)):\n if info is None:\n continue\n shell_data = unique_symbol_shells[symbol]\n ecpatom_handle = ce.cuestECPAtomHandle()\n cuest_check(f'Create ECP Atom {atom_index}',\n ce.cuestECPAtomCreate(\n handle=cuest_handle,\n numElectrons=info['nelectron'],\n numShells=len(shell_data['shells']),\n shells=shell_data['shells'],\n topShell=shell_data['top_shell'],\n parameters=ecpatom_parameters,\n outECPAtom=ecpatom_handle,\n )\n )\n ecp_atom_indices.append(atom_index)\n ecp_atom_handles.append(ecpatom_handle)\n\n # ECP shell handles are no longer needed once the atoms have been created\n for symbol, shell_data in unique_symbol_shells.items():\n cuest_check(f'Destroy ECP Top Shell for {symbol}',\n ce.cuestECPShellDestroy(\n handle=shell_data['top_shell'],\n )\n )\n for k, shell_handle in enumerate(shell_data['shells']):\n cuest_check(f'Destroy ECP Shell {k} for {symbol}',\n ce.cuestECPShellDestroy(\n handle=shell_handle,\n )\n )\n\n cuest_check('Destroy ECP Atom Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPATOM_PARAMETERS,\n parameters=ecpatom_parameters,\n )\n )\n\n # => Build ECP Integral Plan <= #\n\n ecpintplan_parameters = ce.cuestECPIntPlanParameters()\n cuest_check('Create ECPIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPINTPLAN_PARAMETERS,\n outParameters=ecpintplan_parameters,\n )\n )\n\n ecpintplan_handle = ce.cuestECPIntPlanHandle()\n\n cuest_check('Create ECPIntPlan Workspace Query',\n ce.cuestECPIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n xyz=xyzs,\n numECPAtoms=len(ecp_atom_indices),\n activeIndices=ecp_atom_indices,\n activeAtoms=ecp_atom_handles,\n parameters=ecpintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ecpintplan_handle,\n )\n )\n\n ecpintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n ecpintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create ECPIntPlan',\n ce.cuestECPIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n xyz=xyzs,\n numECPAtoms=len(ecp_atom_indices),\n activeIndices=ecp_atom_indices,\n activeAtoms=ecp_atom_handles,\n parameters=ecpintplan_parameters,\n persistentWorkspace=ecpintplan_persistent_workspace.pointer,\n temporaryWorkspace=ecpintplan_temporary_workspace.pointer,\n outPlan=ecpintplan_handle,\n )\n )\n\n del ecpintplan_temporary_workspace\n\n for i, ecpatom_handle in enumerate(ecp_atom_handles):\n cuest_check(f'Destroy ECP Atom {i}',\n ce.cuestECPAtomDestroy(\n handle=ecpatom_handle,\n )\n )\n\n cuest_check('Destroy ECPIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPINTPLAN_PARAMETERS,\n parameters=ecpintplan_parameters,\n )\n )\n\n # => Compute ECP Integrals <= #\n\n ecpcompute_parameters = ce.cuestECPComputeParameters()\n cuest_check('Create ECPCompute Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPCOMPUTE_PARAMETERS,\n outParameters=ecpcompute_parameters,\n )\n )\n\n ecp_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n ecp_device_handle = ce.Pointer(ecp_device_pointer)\n\n # Find the temporary workspace requirements for the ECP integral evaluation\n cuest_check('ECPCompute Workspace Query',\n ce.cuestECPComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=ecpintplan_handle,\n parameters=ecpcompute_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outECPMatrix=ecp_device_handle,\n )\n )\n\n ecp_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # Compute the ECP matrix (nao x nao)\n cuest_check('ECPCompute',\n ce.cuestECPCompute(\n handle=cuest_handle,\n plan=ecpintplan_handle,\n parameters=ecpcompute_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=ecp_temporary_workspace.pointer,\n outECPMatrix=ecp_device_handle,\n )\n )\n\n del ecp_temporary_workspace\n\n cuest_check('Destroy ECPCompute Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPCOMPUTE_PARAMETERS,\n parameters=ecpcompute_parameters,\n )\n )\n\n ecp_host_array = np.empty(\n nao * nao,\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=ecp_host_array.ctypes.data,\n device_pointer=ecp_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(array=ecp_device_pointer)\n\n # => Cleanup <= #\n\n cuest_check('Destroy ECPIntPlan',\n ce.cuestECPIntPlanDestroy(\n handle=ecpintplan_handle,\n )\n )\n del ecpintplan_persistent_workspace\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n del aobasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Compute ECP integrals using XYZ, GBS, and ECP files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"Molecular coordinates (Angstrom) in basic XYZ format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"Orbital basis set in G94/Psi4 GBS format.\"\n )\n parser.add_argument(\n \"ecp_filename\",\n type=str,\n help=\"Effective core potential basis set file.\"\n )\n\n args = parser.parse_args()\n\n run(\n xyz_filename=args.xyz_filename,\n gbs_filename=args.gbs_filename,\n ecp_filename=args.ecp_filename,\n )","source_hash":"6dd7d24f81c24a61d3135896bc72ca59176a48399eb226e9c334fe4fe8b7b1c0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.5_effective_core_potentials.ecp_integrals.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.5_effective_core_potentials.ecp_integrals.run.run#L28-L480","kind":"function","name":"run","path":"cuEST/python_examples/5_effective_core_potentials/ecp_integrals/run.py","language":"python","start_line":28,"end_line":480,"context_start_line":8,"context_end_line":500,"code":"# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser, simple_ecp_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ecp_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, _ = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n ecp_metadata = simple_ecp_parser(\n filename=ecp_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2 GB of DRAM for ECP evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n # => cuEST Handle Setup <= #\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Set From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n aobasis_handle = ce.cuestAOBasisHandle()\n\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build ECP Shells and Atoms <= #\n\n # Create ECP shell parameters (shared for all ECP shell creation calls)\n ecpshell_parameters = ce.cuestECPShellParameters()\n cuest_check('Create ECP Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPSHELL_PARAMETERS,\n outParameters=ecpshell_parameters,\n )\n )\n\n # Create ECP shells once per unique element type. When multiple atoms of the\n # same element are present, their ECP data is identical so the shell handles\n # are shared across all atoms of that element.\n unique_symbol_shells = {} # symbol -> {'top_shell': handle, 'shells': [handles]}\n for symbol, info in zip(symbols, ecp_metadata):\n if info is None or symbol in unique_symbol_shells:\n continue\n\n # Create the top shell (the max-L projector)\n top_shell_info = info['top_shell']\n top_shell_handle = ce.cuestECPShellHandle()\n cuest_check(f'Create ECP Top Shell for {symbol}',\n ce.cuestECPShellCreate(\n handle=cuest_handle,\n L=top_shell_info.L,\n numPrimitive=len(top_shell_info.ns),\n radialPowers=top_shell_info.ns,\n coefficients=top_shell_info.ws,\n exponents=top_shell_info.es,\n parameters=ecpshell_parameters,\n outECPShell=top_shell_handle,\n )\n )\n\n # Create the angular-momentum projected shells\n shell_handles = []\n for k, shell_info in enumerate(info['shells']):\n shell_handle = ce.cuestECPShellHandle()\n cuest_check(f'Create ECP Shell {k} for {symbol}',\n ce.cuestECPShellCreate(\n handle=cuest_handle,\n L=shell_info.L,\n numPrimitive=len(shell_info.ns),\n radialPowers=shell_info.ns,\n coefficients=shell_info.ws,\n exponents=shell_info.es,\n parameters=ecpshell_parameters,\n outECPShell=shell_handle,\n )\n )\n shell_handles.append(shell_handle)\n\n unique_symbol_shells[symbol] = {\n 'top_shell': top_shell_handle,\n 'shells': shell_handles,\n }\n\n cuest_check('Destroy ECP Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPSHELL_PARAMETERS,\n parameters=ecpshell_parameters,\n )\n )\n\n # Create ECP atom parameters (shared for all ECP atom creation calls)\n ecpatom_parameters = ce.cuestECPAtomParameters()\n cuest_check('Create ECP Atom Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPATOM_PARAMETERS,\n outParameters=ecpatom_parameters,\n )\n )\n\n # Create one ECP atom handle per active atom (atoms that carry an ECP)\n ecp_atom_indices = [] # indices into the full atom list\n ecp_atom_handles = [] # corresponding cuestECPAtomHandle objects\n for atom_index, (symbol, info) in enumerate(zip(symbols, ecp_metadata)):\n if info is None:\n continue\n shell_data = unique_symbol_shells[symbol]\n ecpatom_handle = ce.cuestECPAtomHandle()\n cuest_check(f'Create ECP Atom {atom_index}',\n ce.cuestECPAtomCreate(\n handle=cuest_handle,\n numElectrons=info['nelectron'],\n numShells=len(shell_data['shells']),\n shells=shell_data['shells'],\n topShell=shell_data['top_shell'],\n parameters=ecpatom_parameters,\n outECPAtom=ecpatom_handle,\n )\n )\n ecp_atom_indices.append(atom_index)\n ecp_atom_handles.append(ecpatom_handle)\n\n # ECP shell handles are no longer needed once the atoms have been created\n for symbol, shell_data in unique_symbol_shells.items():\n cuest_check(f'Destroy ECP Top Shell for {symbol}',\n ce.cuestECPShellDestroy(\n handle=shell_data['top_shell'],\n )\n )\n for k, shell_handle in enumerate(shell_data['shells']):\n cuest_check(f'Destroy ECP Shell {k} for {symbol}',\n ce.cuestECPShellDestroy(\n handle=shell_handle,\n )\n )\n\n cuest_check('Destroy ECP Atom Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPATOM_PARAMETERS,\n parameters=ecpatom_parameters,\n )\n )\n\n # => Build ECP Integral Plan <= #\n\n ecpintplan_parameters = ce.cuestECPIntPlanParameters()\n cuest_check('Create ECPIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPINTPLAN_PARAMETERS,\n outParameters=ecpintplan_parameters,\n )\n )\n\n ecpintplan_handle = ce.cuestECPIntPlanHandle()\n\n cuest_check('Create ECPIntPlan Workspace Query',\n ce.cuestECPIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n xyz=xyzs,\n numECPAtoms=len(ecp_atom_indices),\n activeIndices=ecp_atom_indices,\n activeAtoms=ecp_atom_handles,\n parameters=ecpintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ecpintplan_handle,\n )\n )\n\n ecpintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n ecpintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create ECPIntPlan',\n ce.cuestECPIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n xyz=xyzs,\n numECPAtoms=len(ecp_atom_indices),\n activeIndices=ecp_atom_indices,\n activeAtoms=ecp_atom_handles,\n parameters=ecpintplan_parameters,\n persistentWorkspace=ecpintplan_persistent_workspace.pointer,\n temporaryWorkspace=ecpintplan_temporary_workspace.pointer,\n outPlan=ecpintplan_handle,\n )\n )\n\n del ecpintplan_temporary_workspace\n\n for i, ecpatom_handle in enumerate(ecp_atom_handles):\n cuest_check(f'Destroy ECP Atom {i}',\n ce.cuestECPAtomDestroy(\n handle=ecpatom_handle,\n )\n )\n\n cuest_check('Destroy ECPIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPINTPLAN_PARAMETERS,\n parameters=ecpintplan_parameters,\n )\n )\n\n # => Compute ECP Integrals <= #\n\n ecpcompute_parameters = ce.cuestECPComputeParameters()\n cuest_check('Create ECPCompute Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPCOMPUTE_PARAMETERS,\n outParameters=ecpcompute_parameters,\n )\n )\n\n ecp_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n ecp_device_handle = ce.Pointer(ecp_device_pointer)\n\n # Find the temporary workspace requirements for the ECP integral evaluation\n cuest_check('ECPCompute Workspace Query',\n ce.cuestECPComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=ecpintplan_handle,\n parameters=ecpcompute_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outECPMatrix=ecp_device_handle,\n )\n )\n\n ecp_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # Compute the ECP matrix (nao x nao)\n cuest_check('ECPCompute',\n ce.cuestECPCompute(\n handle=cuest_handle,\n plan=ecpintplan_handle,\n parameters=ecpcompute_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=ecp_temporary_workspace.pointer,\n outECPMatrix=ecp_device_handle,\n )\n )\n\n del ecp_temporary_workspace\n\n cuest_check('Destroy ECPCompute Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPCOMPUTE_PARAMETERS,\n parameters=ecpcompute_parameters,\n )\n )\n\n ecp_host_array = np.empty(\n nao * nao,\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=ecp_host_array.ctypes.data,\n device_pointer=ecp_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(array=ecp_device_pointer)\n\n # => Cleanup <= #\n\n cuest_check('Destroy ECPIntPlan',\n ce.cuestECPIntPlanDestroy(\n handle=ecpintplan_handle,\n )\n )\n del ecpintplan_persistent_workspace\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n del aobasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Compute ECP integrals using XYZ, GBS, and ECP files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"Molecular coordinates (Angstrom) in basic XYZ format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"Orbital basis set in G94/Psi4 GBS format.\"\n )\n parser.add_argument(\n \"ecp_filename\",\n type=str,\n help=\"Effective core potential basis set file.\"\n )","source_hash":"6dd7d24f81c24a61d3135896bc72ca59176a48399eb226e9c334fe4fe8b7b1c0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.5_effective_core_potentials.ecp_integrals.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.5_effective_core_potentials.ecp_integrals.run.cuest_check#L57-L64","kind":"function","name":"cuest_check","path":"cuEST/python_examples/5_effective_core_potentials/ecp_integrals/run.py","language":"python","start_line":57,"end_line":64,"context_start_line":37,"context_end_line":84,"code":" symbols, xyzs, _ = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n ecp_metadata = simple_ecp_parser(\n filename=ecp_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2 GB of DRAM for ECP evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n # => cuEST Handle Setup <= #\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )","source_hash":"6dd7d24f81c24a61d3135896bc72ca59176a48399eb226e9c334fe4fe8b7b1c0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.5_effective_core_potentials.ecp_gradients.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.5_effective_core_potentials.ecp_gradients.run#L1-L531","kind":"module","name":"cuEST.python_examples.5_effective_core_potentials.ecp_gradients.run","path":"cuEST/python_examples/5_effective_core_potentials/ecp_gradients/run.py","language":"python","start_line":1,"end_line":531,"context_start_line":1,"context_end_line":531,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser, simple_ecp_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ecp_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n ecp_metadata = simple_ecp_parser(\n filename=ecp_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2 GB of DRAM for ECP evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n # => cuEST Handle Setup <= #\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Set From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n aobasis_handle = ce.cuestAOBasisHandle()\n\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build ECP Shells and Atoms <= #\n\n # Create ECP shell parameters (shared for all ECP shell creation calls)\n ecpshell_parameters = ce.cuestECPShellParameters()\n cuest_check('Create ECP Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPSHELL_PARAMETERS,\n outParameters=ecpshell_parameters,\n )\n )\n\n # Create ECP shells once per unique element type. When multiple atoms of the\n # same element are present, their ECP data is identical so the shell handles\n # are shared across all atoms of that element.\n unique_symbol_shells = {} # symbol -> {'top_shell': handle, 'shells': [handles]}\n for symbol, info in zip(symbols, ecp_metadata):\n if info is None or symbol in unique_symbol_shells:\n continue\n\n # Create the top shell (the max-L projector)\n top_shell_info = info['top_shell']\n top_shell_handle = ce.cuestECPShellHandle()\n cuest_check(f'Create ECP Top Shell for {symbol}',\n ce.cuestECPShellCreate(\n handle=cuest_handle,\n L=top_shell_info.L,\n numPrimitive=len(top_shell_info.ns),\n radialPowers=top_shell_info.ns,\n coefficients=top_shell_info.ws,\n exponents=top_shell_info.es,\n parameters=ecpshell_parameters,\n outECPShell=top_shell_handle,\n )\n )\n\n # Create the angular-momentum projected shells\n shell_handles = []\n for k, shell_info in enumerate(info['shells']):\n shell_handle = ce.cuestECPShellHandle()\n cuest_check(f'Create ECP Shell {k} for {symbol}',\n ce.cuestECPShellCreate(\n handle=cuest_handle,\n L=shell_info.L,\n numPrimitive=len(shell_info.ns),\n radialPowers=shell_info.ns,\n coefficients=shell_info.ws,\n exponents=shell_info.es,\n parameters=ecpshell_parameters,\n outECPShell=shell_handle,\n )\n )\n shell_handles.append(shell_handle)\n\n unique_symbol_shells[symbol] = {\n 'top_shell': top_shell_handle,\n 'shells': shell_handles,\n }\n\n cuest_check('Destroy ECP Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPSHELL_PARAMETERS,\n parameters=ecpshell_parameters,\n )\n )\n\n # Create ECP atom parameters (shared for all ECP atom creation calls)\n ecpatom_parameters = ce.cuestECPAtomParameters()\n cuest_check('Create ECP Atom Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPATOM_PARAMETERS,\n outParameters=ecpatom_parameters,\n )\n )\n\n # Create one ECP atom handle per active atom (atoms that carry an ECP)\n ecp_atom_indices = [] # indices into the full atom list\n ecp_atom_handles = [] # corresponding cuestECPAtomHandle objects\n for atom_index, (symbol, info) in enumerate(zip(symbols, ecp_metadata)):\n if info is None:\n continue\n shell_data = unique_symbol_shells[symbol]\n ecpatom_handle = ce.cuestECPAtomHandle()\n cuest_check(f'Create ECP Atom {atom_index}',\n ce.cuestECPAtomCreate(\n handle=cuest_handle,\n numElectrons=info['nelectron'],\n numShells=len(shell_data['shells']),\n shells=shell_data['shells'],\n topShell=shell_data['top_shell'],\n parameters=ecpatom_parameters,\n outECPAtom=ecpatom_handle,\n )\n )\n ecp_atom_indices.append(atom_index)\n ecp_atom_handles.append(ecpatom_handle)\n\n # ECP shell handles are no longer needed once the atoms have been created\n for symbol, shell_data in unique_symbol_shells.items():\n cuest_check(f'Destroy ECP Top Shell for {symbol}',\n ce.cuestECPShellDestroy(\n handle=shell_data['top_shell'],\n )\n )\n for k, shell_handle in enumerate(shell_data['shells']):\n cuest_check(f'Destroy ECP Shell {k} for {symbol}',\n ce.cuestECPShellDestroy(\n handle=shell_handle,\n )\n )\n\n cuest_check('Destroy ECP Atom Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPATOM_PARAMETERS,\n parameters=ecpatom_parameters,\n )\n )\n\n # => Build ECP Integral Plan <= #\n\n ecpintplan_parameters = ce.cuestECPIntPlanParameters()\n cuest_check('Create ECPIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPINTPLAN_PARAMETERS,\n outParameters=ecpintplan_parameters,\n )\n )\n\n ecpintplan_handle = ce.cuestECPIntPlanHandle()\n\n cuest_check('Create ECPIntPlan Workspace Query',\n ce.cuestECPIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n xyz=xyzs,\n numECPAtoms=len(ecp_atom_indices),\n activeIndices=ecp_atom_indices,\n activeAtoms=ecp_atom_handles,\n parameters=ecpintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ecpintplan_handle,\n )\n )\n\n ecpintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n ecpintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create ECPIntPlan',\n ce.cuestECPIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n xyz=xyzs,\n numECPAtoms=len(ecp_atom_indices),\n activeIndices=ecp_atom_indices,\n activeAtoms=ecp_atom_handles,\n parameters=ecpintplan_parameters,\n persistentWorkspace=ecpintplan_persistent_workspace.pointer,\n temporaryWorkspace=ecpintplan_temporary_workspace.pointer,\n outPlan=ecpintplan_handle,\n )\n )\n\n del ecpintplan_temporary_workspace\n\n for i, ecpatom_handle in enumerate(ecp_atom_handles):\n cuest_check(f'Destroy ECP Atom {i}',\n ce.cuestECPAtomDestroy(\n handle=ecpatom_handle,\n )\n )\n\n cuest_check('Destroy ECPIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPINTPLAN_PARAMETERS,\n parameters=ecpintplan_parameters,\n )\n )\n\n # => Compute ECP Gradients <= #\n\n # The ECP derivative routines contract the integral derivatives against a density\n # matrix and accumulate the result into a [num_atoms, 3] gradient array. A real\n # calculation would supply the SCF density matrix here; we use a random symmetric\n # matrix as a stand-in.\n np.random.seed(0)\n density_host = np.random.normal(size=(nao, nao)).astype(np.double)\n density_host = 0.5 * (density_host + density_host.T) # Symmetrize\n\n density_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n density_device_handle = ce.Pointer(density_device_pointer)\n cuda_memcpy_htod(\n device_pointer=density_device_pointer,\n host_pointer=density_host.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n gradient_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * num_atoms * 3\n )\n gradient_device_handle = ce.Pointer(gradient_device_pointer)\n\n ecpderivcompute_parameters = ce.cuestECPDerivativeComputeParameters()\n cuest_check('Create ECPDerivativeCompute Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=ecpderivcompute_parameters,\n )\n )\n\n # Find the temporary workspace requirements for the ECP gradient evaluation\n cuest_check('ECPDerivativeCompute Workspace Query',\n ce.cuestECPDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=ecpintplan_handle,\n parameters=ecpderivcompute_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=density_device_handle,\n outGradient=gradient_device_handle,\n )\n )\n\n ecp_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # Compute dECP/dR contracted with the density matrix; result is [num_atoms, 3]\n cuest_check('ECPDerivativeCompute',\n ce.cuestECPDerivativeCompute(\n handle=cuest_handle,\n plan=ecpintplan_handle,\n parameters=ecpderivcompute_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=ecp_temporary_workspace.pointer,\n densityMatrix=density_device_handle,\n outGradient=gradient_device_handle,\n )\n )\n\n del ecp_temporary_workspace\n\n cuest_check('Destroy ECPDerivativeCompute Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPDERIVATIVECOMPUTE_PARAMETERS,\n parameters=ecpderivcompute_parameters,\n )\n )\n\n gradient_host_array = np.empty(\n num_atoms * 3,\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=gradient_host_array.ctypes.data,\n device_pointer=gradient_device_pointer,\n size_in_bytes=sizeof_double * num_atoms * 3,\n )\n\n cuda_free(array=density_device_pointer)\n cuda_free(array=gradient_device_pointer)\n\n # => Cleanup <= #\n\n cuest_check('Destroy ECPIntPlan',\n ce.cuestECPIntPlanDestroy(\n handle=ecpintplan_handle,\n )\n )\n del ecpintplan_persistent_workspace\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n del aobasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n \n return gradient_host_array.reshape(num_atoms, 3)\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Compute ECP integral gradients contracted with a density matrix.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"Molecular coordinates (Angstrom) in basic XYZ format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"Orbital basis set in G94/Psi4 GBS format.\"\n )\n parser.add_argument(\n \"ecp_filename\",\n type=str,\n help=\"Effective core potential basis set file.\"\n )\n\n args = parser.parse_args()\n\n run(\n xyz_filename=args.xyz_filename,\n gbs_filename=args.gbs_filename,\n ecp_filename=args.ecp_filename,\n )","source_hash":"5e2fa4700f905447bbcb64a3be9697e20be8d68a84a78b6e0eea98cbb78a3fc5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.5_effective_core_potentials.ecp_gradients.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.5_effective_core_potentials.ecp_gradients.run.run#L28-L503","kind":"function","name":"run","path":"cuEST/python_examples/5_effective_core_potentials/ecp_gradients/run.py","language":"python","start_line":28,"end_line":503,"context_start_line":8,"context_end_line":523,"code":"# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser, simple_ecp_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ecp_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n ecp_metadata = simple_ecp_parser(\n filename=ecp_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2 GB of DRAM for ECP evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n # => cuEST Handle Setup <= #\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Set From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n aobasis_handle = ce.cuestAOBasisHandle()\n\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=num_atoms,\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build ECP Shells and Atoms <= #\n\n # Create ECP shell parameters (shared for all ECP shell creation calls)\n ecpshell_parameters = ce.cuestECPShellParameters()\n cuest_check('Create ECP Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPSHELL_PARAMETERS,\n outParameters=ecpshell_parameters,\n )\n )\n\n # Create ECP shells once per unique element type. When multiple atoms of the\n # same element are present, their ECP data is identical so the shell handles\n # are shared across all atoms of that element.\n unique_symbol_shells = {} # symbol -> {'top_shell': handle, 'shells': [handles]}\n for symbol, info in zip(symbols, ecp_metadata):\n if info is None or symbol in unique_symbol_shells:\n continue\n\n # Create the top shell (the max-L projector)\n top_shell_info = info['top_shell']\n top_shell_handle = ce.cuestECPShellHandle()\n cuest_check(f'Create ECP Top Shell for {symbol}',\n ce.cuestECPShellCreate(\n handle=cuest_handle,\n L=top_shell_info.L,\n numPrimitive=len(top_shell_info.ns),\n radialPowers=top_shell_info.ns,\n coefficients=top_shell_info.ws,\n exponents=top_shell_info.es,\n parameters=ecpshell_parameters,\n outECPShell=top_shell_handle,\n )\n )\n\n # Create the angular-momentum projected shells\n shell_handles = []\n for k, shell_info in enumerate(info['shells']):\n shell_handle = ce.cuestECPShellHandle()\n cuest_check(f'Create ECP Shell {k} for {symbol}',\n ce.cuestECPShellCreate(\n handle=cuest_handle,\n L=shell_info.L,\n numPrimitive=len(shell_info.ns),\n radialPowers=shell_info.ns,\n coefficients=shell_info.ws,\n exponents=shell_info.es,\n parameters=ecpshell_parameters,\n outECPShell=shell_handle,\n )\n )\n shell_handles.append(shell_handle)\n\n unique_symbol_shells[symbol] = {\n 'top_shell': top_shell_handle,\n 'shells': shell_handles,\n }\n\n cuest_check('Destroy ECP Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPSHELL_PARAMETERS,\n parameters=ecpshell_parameters,\n )\n )\n\n # Create ECP atom parameters (shared for all ECP atom creation calls)\n ecpatom_parameters = ce.cuestECPAtomParameters()\n cuest_check('Create ECP Atom Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPATOM_PARAMETERS,\n outParameters=ecpatom_parameters,\n )\n )\n\n # Create one ECP atom handle per active atom (atoms that carry an ECP)\n ecp_atom_indices = [] # indices into the full atom list\n ecp_atom_handles = [] # corresponding cuestECPAtomHandle objects\n for atom_index, (symbol, info) in enumerate(zip(symbols, ecp_metadata)):\n if info is None:\n continue\n shell_data = unique_symbol_shells[symbol]\n ecpatom_handle = ce.cuestECPAtomHandle()\n cuest_check(f'Create ECP Atom {atom_index}',\n ce.cuestECPAtomCreate(\n handle=cuest_handle,\n numElectrons=info['nelectron'],\n numShells=len(shell_data['shells']),\n shells=shell_data['shells'],\n topShell=shell_data['top_shell'],\n parameters=ecpatom_parameters,\n outECPAtom=ecpatom_handle,\n )\n )\n ecp_atom_indices.append(atom_index)\n ecp_atom_handles.append(ecpatom_handle)\n\n # ECP shell handles are no longer needed once the atoms have been created\n for symbol, shell_data in unique_symbol_shells.items():\n cuest_check(f'Destroy ECP Top Shell for {symbol}',\n ce.cuestECPShellDestroy(\n handle=shell_data['top_shell'],\n )\n )\n for k, shell_handle in enumerate(shell_data['shells']):\n cuest_check(f'Destroy ECP Shell {k} for {symbol}',\n ce.cuestECPShellDestroy(\n handle=shell_handle,\n )\n )\n\n cuest_check('Destroy ECP Atom Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPATOM_PARAMETERS,\n parameters=ecpatom_parameters,\n )\n )\n\n # => Build ECP Integral Plan <= #\n\n ecpintplan_parameters = ce.cuestECPIntPlanParameters()\n cuest_check('Create ECPIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPINTPLAN_PARAMETERS,\n outParameters=ecpintplan_parameters,\n )\n )\n\n ecpintplan_handle = ce.cuestECPIntPlanHandle()\n\n cuest_check('Create ECPIntPlan Workspace Query',\n ce.cuestECPIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n xyz=xyzs,\n numECPAtoms=len(ecp_atom_indices),\n activeIndices=ecp_atom_indices,\n activeAtoms=ecp_atom_handles,\n parameters=ecpintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=ecpintplan_handle,\n )\n )\n\n ecpintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n ecpintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create ECPIntPlan',\n ce.cuestECPIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n xyz=xyzs,\n numECPAtoms=len(ecp_atom_indices),\n activeIndices=ecp_atom_indices,\n activeAtoms=ecp_atom_handles,\n parameters=ecpintplan_parameters,\n persistentWorkspace=ecpintplan_persistent_workspace.pointer,\n temporaryWorkspace=ecpintplan_temporary_workspace.pointer,\n outPlan=ecpintplan_handle,\n )\n )\n\n del ecpintplan_temporary_workspace\n\n for i, ecpatom_handle in enumerate(ecp_atom_handles):\n cuest_check(f'Destroy ECP Atom {i}',\n ce.cuestECPAtomDestroy(\n handle=ecpatom_handle,\n )\n )\n\n cuest_check('Destroy ECPIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPINTPLAN_PARAMETERS,\n parameters=ecpintplan_parameters,\n )\n )\n\n # => Compute ECP Gradients <= #\n\n # The ECP derivative routines contract the integral derivatives against a density\n # matrix and accumulate the result into a [num_atoms, 3] gradient array. A real\n # calculation would supply the SCF density matrix here; we use a random symmetric\n # matrix as a stand-in.\n np.random.seed(0)\n density_host = np.random.normal(size=(nao, nao)).astype(np.double)\n density_host = 0.5 * (density_host + density_host.T) # Symmetrize\n\n density_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n density_device_handle = ce.Pointer(density_device_pointer)\n cuda_memcpy_htod(\n device_pointer=density_device_pointer,\n host_pointer=density_host.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n gradient_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * num_atoms * 3\n )\n gradient_device_handle = ce.Pointer(gradient_device_pointer)\n\n ecpderivcompute_parameters = ce.cuestECPDerivativeComputeParameters()\n cuest_check('Create ECPDerivativeCompute Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_ECPDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=ecpderivcompute_parameters,\n )\n )\n\n # Find the temporary workspace requirements for the ECP gradient evaluation\n cuest_check('ECPDerivativeCompute Workspace Query',\n ce.cuestECPDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=ecpintplan_handle,\n parameters=ecpderivcompute_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=density_device_handle,\n outGradient=gradient_device_handle,\n )\n )\n\n ecp_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # Compute dECP/dR contracted with the density matrix; result is [num_atoms, 3]\n cuest_check('ECPDerivativeCompute',\n ce.cuestECPDerivativeCompute(\n handle=cuest_handle,\n plan=ecpintplan_handle,\n parameters=ecpderivcompute_parameters,\n variableBufferSize=variable_buffer_size.pointer,\n temporaryWorkspace=ecp_temporary_workspace.pointer,\n densityMatrix=density_device_handle,\n outGradient=gradient_device_handle,\n )\n )\n\n del ecp_temporary_workspace\n\n cuest_check('Destroy ECPDerivativeCompute Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_ECPDERIVATIVECOMPUTE_PARAMETERS,\n parameters=ecpderivcompute_parameters,\n )\n )\n\n gradient_host_array = np.empty(\n num_atoms * 3,\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=gradient_host_array.ctypes.data,\n device_pointer=gradient_device_pointer,\n size_in_bytes=sizeof_double * num_atoms * 3,\n )\n\n cuda_free(array=density_device_pointer)\n cuda_free(array=gradient_device_pointer)\n\n # => Cleanup <= #\n\n cuest_check('Destroy ECPIntPlan',\n ce.cuestECPIntPlanDestroy(\n handle=ecpintplan_handle,\n )\n )\n del ecpintplan_persistent_workspace\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n del aobasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n \n return gradient_host_array.reshape(num_atoms, 3)\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Compute ECP integral gradients contracted with a density matrix.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"Molecular coordinates (Angstrom) in basic XYZ format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"Orbital basis set in G94/Psi4 GBS format.\"\n )\n parser.add_argument(\n \"ecp_filename\",\n type=str,\n help=\"Effective core potential basis set file.\"\n )","source_hash":"5e2fa4700f905447bbcb64a3be9697e20be8d68a84a78b6e0eea98cbb78a3fc5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.5_effective_core_potentials.ecp_gradients.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.5_effective_core_potentials.ecp_gradients.run.cuest_check#L57-L64","kind":"function","name":"cuest_check","path":"cuEST/python_examples/5_effective_core_potentials/ecp_gradients/run.py","language":"python","start_line":57,"end_line":64,"context_start_line":37,"context_end_line":84,"code":" symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n\n ecp_metadata = simple_ecp_parser(\n filename=ecp_filename,\n symbols=symbols,\n )\n\n num_atoms = len(symbols)\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays.\n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n # Allow 2 GB of DRAM for ECP evaluation routines\n variable_buffer_size = WorkspaceDescriptor(\n host_buffer_size_in_bytes=0,\n device_buffer_size_in_bytes=2000000000,\n )\n\n # => cuEST Handle Setup <= #\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )","source_hash":"5e2fa4700f905447bbcb64a3be9697e20be8d68a84a78b6e0eea98cbb78a3fc5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.0_context.basic_usage.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.0_context.basic_usage.run#L1-L92","kind":"module","name":"cuEST.python_examples.0_context.basic_usage.run","path":"cuEST/python_examples/0_context/basic_usage/run.py","language":"python","start_line":1,"end_line":92,"context_start_line":1,"context_end_line":92,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\n# Create default HandleParameters object to parameterize the cuEST handle.\ncuest_handle_parameters = ce.cuestHandleParameters()\n\ncuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n# Make a handle to hold a C uint64_t type, and populate it with the maximum number\n# of Gauss-Hermite quadrature points supported by by the cuEST handle by default.\nmaxgh_handle = ce.data_uint64_t()\ncuest_check('Query Handle Max Num GH',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_MAX_GAUSS_HERMITE,\n attributeValue=maxgh_handle,\n )\n )\nprint('Handle Max Num GH', maxgh_handle.value)\n\n# Similarly, query for the maximum angular momentum supported for\n# Cartesian->Spherical transforms in this cuEST handle instance.\nmaxl_handle = ce.data_uint64_t()\ncuest_check('Query Handle Max L',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_MAX_L_SOLID_HARMONIC,\n attributeValue=maxl_handle,\n )\n )\nprint('Handle Max L', maxl_handle.value)\n\n# ce.cuestParametersConfigure could be called here to override the default\n# values if required\n\ncuest_handle = ce.cuestHandle()\ncuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n# Once the handle itself has been created, its parameters can be destroyed\ncuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n\n# The handle is ready to be used for calculations\n\n\n# Destroying the handle will also destoy CUDA stream, cuBLAS, and cuSolver\n# handles held by the cuEST handle.\ncuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )","source_hash":"c709dc03bbbb1ce8356be36e308ab614aea46163df9729c2fdd5d23cd649a660","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.0_context.basic_usage.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.0_context.basic_usage.run.cuest_check#L18-L24","kind":"function","name":"cuest_check","path":"cuEST/python_examples/0_context/basic_usage/run.py","language":"python","start_line":18,"end_line":24,"context_start_line":1,"context_end_line":44,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\n# Create default HandleParameters object to parameterize the cuEST handle.\ncuest_handle_parameters = ce.cuestHandleParameters()\n\ncuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n# Make a handle to hold a C uint64_t type, and populate it with the maximum number\n# of Gauss-Hermite quadrature points supported by by the cuEST handle by default.\nmaxgh_handle = ce.data_uint64_t()\ncuest_check('Query Handle Max Num GH',\n ce.cuestParametersQuery(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_MAX_GAUSS_HERMITE,","source_hash":"c709dc03bbbb1ce8356be36e308ab614aea46163df9729c2fdd5d23cd649a660","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.0_context.user_owned_resources.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.0_context.user_owned_resources.run#L1-L132","kind":"module","name":"cuEST.python_examples.0_context.user_owned_resources.run","path":"cuEST/python_examples/0_context/user_owned_resources/run.py","language":"python","start_line":1,"end_line":132,"context_start_line":1,"context_end_line":132,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport sys\nfrom pathlib import Path\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import make_stream,\\\n make_cublas_handle, free_cublas_handle,\\\n make_cusolver_handle, free_cusolver_handle,\\\n set_cublas_stream, set_cusolver_stream\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\nstream = make_stream()\ncublas_c_handle = make_cublas_handle()\ncusolver_c_handle = make_cusolver_handle()\n\nset_cublas_stream(\n handle=cublas_c_handle,\n stream=stream.__int__(),\n )\n\nset_cusolver_stream(\n handle=cusolver_c_handle,\n stream=stream.__int__(),\n )\n\n# Create default HandleParameters object to parameterize the cuEST handle.\ncuest_handle_parameters = ce.cuestHandleParameters()\n\ncuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n# => Configure the cuEST handle paramters <= #\n\nstream_handle = ce.data_cudaStream_t(stream)\ncuest_check('Configure Handle Stream',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUDASTREAM,\n attributeValue=stream_handle,\n )\n )\n\ncublas_handle = ce.data_cublasHandle_t(cublas_c_handle.value)\ncuest_check('Configure Handle cuBLAS',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUBLAS,\n attributeValue=cublas_handle,\n )\n )\n\ncusolver_handle = ce.data_cusolverDnHandle_t(cusolver_c_handle.value)\ncuest_check('Configure Handle cuSolver',\n ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n attribute=ce.CuestHandleParametersAttributes.CUEST_HANDLE_PARAMETERS_CUSOLVER,\n attributeValue=cusolver_handle,\n )\n )\n\n# => Make cuEST Handle <= #\n\ncuest_handle = ce.cuestHandle()\ncuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n# Once the handle itself has been created, its parameters can be destroyed\ncuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n\n# The handle is ready to be used for calculations\n\n\n# Destroying the handle will also destoy CUDA stream, cuBLAS, and cuSolver\n# handles held by the cuEST handle.\ncuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nfree_cublas_handle(\n handle=cublas_c_handle,\n )\nfree_cusolver_handle(\n handle=cusolver_c_handle,\n )\n# A key difference between using cuda.bindings to wrap CUDA (as the stream is\n# in this example) vs. using ctypes (used for cuBLAS and cuSolver) is that the\n# former takes care of memory management automatically, so no call to free the\n# stream is needed. We can optionally free it as follows:\ndel stream","source_hash":"efa9f1e09ce986f651f91145b1a62687e5f08684a2570a0a305b1a3df1d67625","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.0_context.user_owned_resources.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.0_context.user_owned_resources.run.cuest_check#L27-L33","kind":"function","name":"cuest_check","path":"cuEST/python_examples/0_context/user_owned_resources/run.py","language":"python","start_line":27,"end_line":33,"context_start_line":7,"context_end_line":53,"code":"#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport sys\nfrom pathlib import Path\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import make_stream,\\\n make_cublas_handle, free_cublas_handle,\\\n make_cusolver_handle, free_cusolver_handle,\\\n set_cublas_stream, set_cusolver_stream\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\nstream = make_stream()\ncublas_c_handle = make_cublas_handle()\ncusolver_c_handle = make_cusolver_handle()\n\nset_cublas_stream(\n handle=cublas_c_handle,\n stream=stream.__int__(),\n )\n\nset_cusolver_stream(\n handle=cusolver_c_handle,\n stream=stream.__int__(),\n )\n\n# Create default HandleParameters object to parameterize the cuEST handle.\ncuest_handle_parameters = ce.cuestHandleParameters()\n\ncuest_check('Create Handle Params',","source_hash":"efa9f1e09ce986f651f91145b1a62687e5f08684a2570a0a305b1a3df1d67625","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.0_context.basic_multistream_usage.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.0_context.basic_multistream_usage.run#L1-L66","kind":"module","name":"cuEST.python_examples.0_context.basic_multistream_usage.run","path":"cuEST/python_examples/0_context/basic_multistream_usage/run.py","language":"python","start_line":1,"end_line":66,"context_start_line":1,"context_end_line":66,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\ncuest_handle_parameters = ce.cuestHandleParameters()\ncuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n# Create a list of 2 cuEST handles. Each one will hold its own unique\n# resources Stream, cuBLAS, cuSolver.\ncuest_handles = []\nfor _ in range(2):\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n cuest_handles.append(cuest_handle)\n\n\ncuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n\n# The cuEST handles are ready to be used for calculations\n\n\n# Free both of the handles when finished, to free up resources\nfor cuest_handle in cuest_handles:\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )","source_hash":"b97deb716c4bca03b4bbdd68c79eac79707d1971fe87a14018d07eb98f6e10f3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.0_context.basic_multistream_usage.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.0_context.basic_multistream_usage.run.cuest_check#L18-L24","kind":"function","name":"cuest_check","path":"cuEST/python_examples/0_context/basic_multistream_usage/run.py","language":"python","start_line":18,"end_line":24,"context_start_line":1,"context_end_line":44,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\ndef cuest_check(\n title,\n return_code\n ):\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n\ncuest_handle_parameters = ce.cuestHandleParameters()\ncuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n# Create a list of 2 cuEST handles. Each one will hold its own unique\n# resources Stream, cuBLAS, cuSolver.\ncuest_handles = []\nfor _ in range(2):\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )","source_hash":"b97deb716c4bca03b4bbdd68c79eac79707d1971fe87a14018d07eb98f6e10f3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.parsers","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.helpers.parsers#L1-L371","kind":"module","name":"cuEST.python_examples.helpers.parsers","path":"cuEST/python_examples/helpers/parsers.py","language":"python","start_line":1,"end_line":371,"context_start_line":1,"context_end_line":371,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport re\nfrom collections import namedtuple\n\ndef simple_xyz_parser(\n *,\n filename,\n to_bohr_scale_factor,\n ):\n\n elements = [\n \"X\", \"H\", \"HE\", \"LI\", \"BE\", \"B\", \"C\", \"N\", \"O\", \"F\", \"NE\",\n \"NA\", \"MG\", \"AL\", \"SI\", \"P\", \"S\", \"CL\", \"AR\", \"K\", \"CA\",\n \"SC\", \"TI\", \"V\", \"CR\", \"MN\", \"FE\", \"CO\", \"NI\", \"CU\", \"ZN\",\n \"GA\", \"GE\", \"AS\", \"SE\", \"BR\", \"KR\", \"RB\", \"SR\", \"Y\", \"ZR\",\n \"NB\", \"MO\", \"TC\", \"RU\", \"RH\", \"PD\", \"AG\", \"CD\", \"IN\", \"SN\",\n \"SB\", \"TE\", \"I\", \"XE\", \"CS\", \"BA\", \"LA\", \"CE\", \"PR\", \"ND\",\n \"PM\", \"SM\", \"EU\", \"GD\", \"TB\", \"DY\", \"HO\", \"ER\", \"TM\", \"YB\",\n \"LU\", \"HF\", \"TA\", \"W\", \"RE\", \"OS\", \"IR\", \"PT\", \"AU\", \"HG\",\n \"TL\", \"PB\", \"BI\", \"PO\", \"AT\", \"RN\", \"FR\", \"RA\", \"AC\", \"TH\",\n \"PA\", \"U\", \"NP\", \"PU\", \"AM\", \"CM\", \"BK\", \"CF\", \"ES\", \"FM\",\n \"MD\", \"NO\", \"LR\", \"RF\", \"DB\", \"SG\", \"BH\", \"HS\", \"MT\", \"DS\",\n \"RG\", \"CN\", \"NH\", \"FL\", \"MC\", \"LV\", \"TS\", \"OG\"\n ]\n symbols = []\n xyzs = []\n Zs = []\n with open(filename) as fp:\n atom_count = int(fp.readline())\n comment = fp.readline()\n for _ in range(atom_count):\n parts = fp.readline().split()\n symbol = parts[0].upper()\n # The potential integrals routine compute electron-electron interaction\n # integrals; to make this an electron-nucleus interaction we scale Z here\n Z = -1.0 * elements.index(symbol)\n x = float(parts[1]) * to_bohr_scale_factor\n y = float(parts[2]) * to_bohr_scale_factor\n z = float(parts[3]) * to_bohr_scale_factor\n xyzs.extend([x, y, z])\n symbols.append(symbol)\n Zs.append(Z)\n return symbols, xyzs, Zs\n\n\nECPShellInfo = namedtuple('ECPShellInfo', ['L', 'ns', 'ws', 'es'])\n\ndef _ecp_shell_info_from_ecp_lines(\n *,\n lines,\n ):\n _shell_data_ = {\n 'S': 0,\n 'P': 1,\n 'D': 2,\n 'F': 3,\n 'G': 4,\n 'H': 5,\n 'I': 6,\n 'K': 7,\n 'L': 8,\n 'M': 9,\n 'N': 10,\n 'O': 11,\n 'Q': 12,\n 'R': 13,\n 'T': 14,\n 'U': 15,\n 'V': 16,\n 'W': 17,\n 'X': 18,\n 'Y': 19,\n 'Z': 20,\n }\n mobj = re.match(r'^\\s*(\\S+)-ECP\\s+(\\d+)\\s+(\\d+)\\s*$', lines[0], re.IGNORECASE)\n if mobj is None:\n raise RuntimeError('Where is the \"ATOM-ECP max_L nelectron\" line?')\n max_L = int(mobj.group(2))\n nelectron = int(mobj.group(3))\n\n lines2 = lines[1:]\n\n potential_indices = [\n index\n for index, line in enumerate(lines2)\n if re.match(r'^\\s*(\\S+)\\s+potential\\s*$', line, re.IGNORECASE)\n ]\n\n if len(potential_indices) < 1:\n raise RuntimeError('len(potential_indices) < 1')\n\n potential_indices.append(len(lines2))\n\n # Top shell\n\n index = 0\n\n potential_start = potential_indices[index]\n potential_stop = potential_indices[index + 1]\n\n mobj = re.match(r'^\\s*(\\S)\\s+potential\\s*$', lines2[potential_start], re.IGNORECASE)\n if mobj is None:\n raise RuntimeError('Where is the \"max_L potential\" line?')\n\n shell_char = mobj.group(1).upper()\n if shell_char not in _shell_data_:\n raise RuntimeError(f'Unknown shell type: {shell_char}')\n\n if _shell_data_[shell_char] != max_L:\n raise RuntimeError('Invalid max_L')\n\n mobj = re.match(r'^\\s*(\\d+)\\s*$', lines2[potential_start + 1])\n if mobj is None:\n raise RuntimeError('Where is the \"nprimitive\" line?')\n\n nprimitive = int(mobj.group(1))\n\n lines3 = lines2[potential_start + 2 : potential_stop]\n\n if len(lines3) != nprimitive:\n raise RuntimeError('nprimitive is incorrect')\n\n ns = []\n ws = []\n es = []\n for line in lines3:\n mobj = re.match(r'^\\s*(\\d+)\\s+(\\S+)\\s+(\\S+)\\s*$', line)\n if mobj is None:\n raise RuntimeError('where is the \"n e w\" line?')\n ns.append(int(mobj.group(1)))\n es.append(float(mobj.group(2)))\n ws.append(float(mobj.group(3)))\n\n top_shell = ECPShellInfo(L=max_L, ns=ns, ws=ws, es=es)\n\n # Other shells\n\n shells = []\n for index in range(1, len(potential_indices) - 1):\n potential_start = potential_indices[index]\n potential_stop = potential_indices[index + 1]\n\n mobj = re.match(r'^\\s*(\\S)-(\\S)\\s+potential\\s*$', lines2[potential_start], re.IGNORECASE)\n if mobj is None:\n raise RuntimeError('Where is the \"L-max_L potential\" line?')\n\n if _shell_data_[mobj.group(2).upper()] != max_L:\n raise RuntimeError('Invalid max_L')\n\n L = _shell_data_[mobj.group(1).upper()]\n\n mobj = re.match(r'^\\s*(\\d+)\\s*$', lines2[potential_start + 1])\n if mobj is None:\n raise RuntimeError('Where is the \"nprimitive\" line?')\n\n nprimitive = int(mobj.group(1))\n\n lines3 = lines2[potential_start + 2 : potential_stop]\n\n if len(lines3) != nprimitive:\n raise RuntimeError('nprimitive is incorrect')\n\n ns = []\n ws = []\n es = []\n for line in lines3:\n mobj = re.match(r'^\\s*(\\d+)\\s+(\\S+)\\s+(\\S+)\\s*$', line)\n if mobj is None:\n raise RuntimeError('where is the \"n e w\" line?')\n ns.append(int(mobj.group(1)))\n es.append(float(mobj.group(2)))\n ws.append(float(mobj.group(3)))\n\n shells.append(ECPShellInfo(L=L, ns=ns, ws=ws, es=es))\n\n return {\n 'nelectron': nelectron,\n 'shells': shells,\n 'top_shell': top_shell,\n }\n\n\ndef simple_ecp_parser(\n *,\n filename,\n symbols,\n ):\n\n with open(filename) as fp:\n lines = fp.readlines()\n\n # => Cleaning <= #\n\n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]\n # Strip comment lines out\n re_comment = re.compile(r'\\s*!')\n lines = [_ for _ in lines if not re.match(re_comment, _)]\n # Lines must be nonzero \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n\n # Find ECP entries matching this kind of pattern\n # SI 0\n # SI-ECP 2 10\n # But joined onto a single line\n ecp_re = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s*(\\S+)-ECP\\s+(\\d+)\\s+(\\d+)\\s*$')\n ecp_inds = []\n for ind in range(len(lines) - 1):\n line = lines[ind] + lines[ind + 1] # Join into a single line\n if ecp_re.match(line):\n ecp_inds.append(ind)\n ecp_inds.append(len(lines))\n\n # Extract the lines pertaining to each atom symbol\n symbol_ecp_info = {}\n for k in range(len(ecp_inds) - 1):\n ind1 = ecp_inds[k]\n ind2 = ecp_inds[k + 1]\n if (ind2 - ind1) <= 0: # Guard against empty entries\n continue\n mobj = re.match(\n r'^\\s*(\\S+)\\s+(\\d+)\\s*$', lines[ind1]\n ) # Check if the line is a regular basis entry or an ECP entry\n if mobj == None:\n raise Exception(\"Where is the ID V line?\")\n if mobj.group(2) != '0':\n continue # Regular basis entry, not an ECP entry\n # Try to match the next line to something of the form\n # SR-ECP 3 28\n mobj = re.match(r'^\\s*(\\S+)-ECP\\s+(\\d+)\\s+(\\d+)\\s*$', lines[ind1 + 1])\n if mobj is None:\n # This is a regular atom entry, not an ECP entry\n continue\n symbol_ecp_info[mobj.group(1).upper()] = _ecp_shell_info_from_ecp_lines(lines=lines[ind1 + 1 : ind2])\n\n ecp_metadata = []\n for symbol in symbols:\n ecp_metadata.append(symbol_ecp_info.get(symbol.upper(), None))\n\n return ecp_metadata\n\n\ndef simple_gbs_parser(\n *,\n filename,\n symbols,\n ):\n\n shell_types = [\n 'S', 'P', 'D', 'F', 'G', 'H', 'I',\n 'K', 'L', 'M', 'N', 'O', 'Q', 'R',\n 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n ]\n with open(filename) as fp:\n lines = fp.readlines()\n\n # => Cleaning <= #\n\n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]\n # Strip comment lines out\n re_comment = re.compile(r'\\s*!')\n lines = [_ for _ in lines if not re.match(re_comment, _)]\n # Lines must be nonzero \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n\n # => Spherical / Cartesian Tag Line <= #\n\n mobj = re.match(r'^\\s*(spherical|cartesian)\\s*$', lines[0])\n if mobj is None:\n raise RuntimeError(\"First line of GBS file must be 'spherical' or 'cartesian', instead is: %s\" % lines[0])\n\n if mobj.group(1) == 'spherical':\n is_pure = True\n elif mobj.group(1) == 'cartesian':\n is_pure = False\n else:\n raise RuntimeError('Invalid cartesian/spherical label: %s' % mobj.group(1))\n\n lines = lines[1:]\n\n # => Atom Block Location <= #\n\n re_separator = re.compile(r'\\s*\\*\\*\\*\\*\\s*$')\n separator_indices = [k for k, line in enumerate(lines) if re.match(re_separator, line)]\n if len(separator_indices) == 0: \n raise RuntimeError('No **** separators present')\n if separator_indices[-1] + 1 != len(lines):\n raise RuntimeError('Last line must be ****, instead is: %s' % lines[-1])\n lines = lines[:-1]\n separator_indices = separator_indices[:-1]\n\n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n if len(separator_indices) == 0: raise RuntimeError('No **** separators present')\n\n # => Atom IDs and corresponding block index <= #\n\n re_atom_id = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s*$')\n atom_id_lines = [lines[_ + 1] for _ in separator_indices]\n symbol_index_map = {}\n for index, atom_id_line in enumerate(atom_id_lines):\n mobj = re.match(re_atom_id, atom_id_line)\n if mobj is None:\n raise RuntimeError('Malformed atom ID line: %s' % (atom_id_line))\n symbol = mobj.group(1)\n atom_index = int(mobj.group(2))\n if atom_index != 0: \n raise RuntimeError('\"Symbol 0\" is only allowed atom line - multiple basis sets per atom type in GBS files is not supported by this library')\n symbol_upper = symbol.upper()\n if symbol in symbol_index_map:\n raise RuntimeError(f'Duplicate atomic symbol in GBS file: {symbol}')\n symbol_index_map[symbol_upper] = index\n\n re_shell_type = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s+(\\S+)\\s*$')\n re_primitive = re.compile(r'^\\s*(\\S+)\\s+(\\S+)\\s*$')\n\n shellinfo = []\n for symbol in symbols:\n symbol = symbol.upper()\n if symbol not in symbol_index_map:\n raise RuntimeError(f'{symbol} not defined in GBS file')\n block_index = symbol_index_map[symbol]\n index1 = separator_indices[block_index + 0]\n index2 = separator_indices[block_index + 1] if block_index + 1 < len(separator_indices) else len(lines)\n\n block_lines = lines[index1+2:index2]\n shell_type_indices = [k for k, line in enumerate(block_lines) if re.match(re_shell_type, line)]\n\n atom_shells = []\n for index in shell_type_indices:\n shell_type_line = block_lines[index]\n mobj = re.match(re_shell_type, shell_type_line)\n am_symbol_upper = mobj.group(1).upper()\n if am_symbol_upper not in shell_types:\n raise RuntimeError(f'Unknown angular momentum symbol: {am_symbol_upper}')\n L = shell_types.index(am_symbol_upper)\n nprimitive = int(mobj.group(2))\n normalization = float(mobj.group(3))\n exponents = []\n coefficients_raw = []\n for K in range(nprimitive):\n primitive_line = block_lines[index + 1 + K]\n # Replace D with E for FORTRAN notation\n primitive_line = primitive_line.replace('D', 'E')\n primitive_line = primitive_line.replace('d', 'e')\n mobj = re.match(re_primitive, primitive_line)\n exponents.append(float(mobj.group(1)))\n coefficients_raw.append(float(mobj.group(2)))\n atom_shells.append({\n 'is_pure' : is_pure,\n 'L' : L,\n 'exponents' : exponents,\n 'coefficients' : coefficients_raw,\n 'normalization' : normalization,\n })\n shellinfo.append(atom_shells)\n return shellinfo","source_hash":"fb6237d80684b6d37dcf31f251d51dd9d0bdf962c40215af137ea203930be0bc","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.parsers.simple_xyz_parser","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.parsers.simple_xyz_parser#L19-L57","kind":"function","name":"simple_xyz_parser","path":"cuEST/python_examples/helpers/parsers.py","language":"python","start_line":19,"end_line":57,"context_start_line":1,"context_end_line":77,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport re\nfrom collections import namedtuple\n\ndef simple_xyz_parser(\n *,\n filename,\n to_bohr_scale_factor,\n ):\n\n elements = [\n \"X\", \"H\", \"HE\", \"LI\", \"BE\", \"B\", \"C\", \"N\", \"O\", \"F\", \"NE\",\n \"NA\", \"MG\", \"AL\", \"SI\", \"P\", \"S\", \"CL\", \"AR\", \"K\", \"CA\",\n \"SC\", \"TI\", \"V\", \"CR\", \"MN\", \"FE\", \"CO\", \"NI\", \"CU\", \"ZN\",\n \"GA\", \"GE\", \"AS\", \"SE\", \"BR\", \"KR\", \"RB\", \"SR\", \"Y\", \"ZR\",\n \"NB\", \"MO\", \"TC\", \"RU\", \"RH\", \"PD\", \"AG\", \"CD\", \"IN\", \"SN\",\n \"SB\", \"TE\", \"I\", \"XE\", \"CS\", \"BA\", \"LA\", \"CE\", \"PR\", \"ND\",\n \"PM\", \"SM\", \"EU\", \"GD\", \"TB\", \"DY\", \"HO\", \"ER\", \"TM\", \"YB\",\n \"LU\", \"HF\", \"TA\", \"W\", \"RE\", \"OS\", \"IR\", \"PT\", \"AU\", \"HG\",\n \"TL\", \"PB\", \"BI\", \"PO\", \"AT\", \"RN\", \"FR\", \"RA\", \"AC\", \"TH\",\n \"PA\", \"U\", \"NP\", \"PU\", \"AM\", \"CM\", \"BK\", \"CF\", \"ES\", \"FM\",\n \"MD\", \"NO\", \"LR\", \"RF\", \"DB\", \"SG\", \"BH\", \"HS\", \"MT\", \"DS\",\n \"RG\", \"CN\", \"NH\", \"FL\", \"MC\", \"LV\", \"TS\", \"OG\"\n ]\n symbols = []\n xyzs = []\n Zs = []\n with open(filename) as fp:\n atom_count = int(fp.readline())\n comment = fp.readline()\n for _ in range(atom_count):\n parts = fp.readline().split()\n symbol = parts[0].upper()\n # The potential integrals routine compute electron-electron interaction\n # integrals; to make this an electron-nucleus interaction we scale Z here\n Z = -1.0 * elements.index(symbol)\n x = float(parts[1]) * to_bohr_scale_factor\n y = float(parts[2]) * to_bohr_scale_factor\n z = float(parts[3]) * to_bohr_scale_factor\n xyzs.extend([x, y, z])\n symbols.append(symbol)\n Zs.append(Z)\n return symbols, xyzs, Zs\n\n\nECPShellInfo = namedtuple('ECPShellInfo', ['L', 'ns', 'ws', 'es'])\n\ndef _ecp_shell_info_from_ecp_lines(\n *,\n lines,\n ):\n _shell_data_ = {\n 'S': 0,\n 'P': 1,\n 'D': 2,\n 'F': 3,\n 'G': 4,\n 'H': 5,\n 'I': 6,\n 'K': 7,\n 'L': 8,\n 'M': 9,\n 'N': 10,","source_hash":"fb6237d80684b6d37dcf31f251d51dd9d0bdf962c40215af137ea203930be0bc","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.parsers._ecp_shell_info_from_ecp_lines","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.parsers._ecp_shell_info_from_ecp_lines#L62-L194","kind":"function","name":"_ecp_shell_info_from_ecp_lines","path":"cuEST/python_examples/helpers/parsers.py","language":"python","start_line":62,"end_line":194,"context_start_line":42,"context_end_line":214,"code":" with open(filename) as fp:\n atom_count = int(fp.readline())\n comment = fp.readline()\n for _ in range(atom_count):\n parts = fp.readline().split()\n symbol = parts[0].upper()\n # The potential integrals routine compute electron-electron interaction\n # integrals; to make this an electron-nucleus interaction we scale Z here\n Z = -1.0 * elements.index(symbol)\n x = float(parts[1]) * to_bohr_scale_factor\n y = float(parts[2]) * to_bohr_scale_factor\n z = float(parts[3]) * to_bohr_scale_factor\n xyzs.extend([x, y, z])\n symbols.append(symbol)\n Zs.append(Z)\n return symbols, xyzs, Zs\n\n\nECPShellInfo = namedtuple('ECPShellInfo', ['L', 'ns', 'ws', 'es'])\n\ndef _ecp_shell_info_from_ecp_lines(\n *,\n lines,\n ):\n _shell_data_ = {\n 'S': 0,\n 'P': 1,\n 'D': 2,\n 'F': 3,\n 'G': 4,\n 'H': 5,\n 'I': 6,\n 'K': 7,\n 'L': 8,\n 'M': 9,\n 'N': 10,\n 'O': 11,\n 'Q': 12,\n 'R': 13,\n 'T': 14,\n 'U': 15,\n 'V': 16,\n 'W': 17,\n 'X': 18,\n 'Y': 19,\n 'Z': 20,\n }\n mobj = re.match(r'^\\s*(\\S+)-ECP\\s+(\\d+)\\s+(\\d+)\\s*$', lines[0], re.IGNORECASE)\n if mobj is None:\n raise RuntimeError('Where is the \"ATOM-ECP max_L nelectron\" line?')\n max_L = int(mobj.group(2))\n nelectron = int(mobj.group(3))\n\n lines2 = lines[1:]\n\n potential_indices = [\n index\n for index, line in enumerate(lines2)\n if re.match(r'^\\s*(\\S+)\\s+potential\\s*$', line, re.IGNORECASE)\n ]\n\n if len(potential_indices) < 1:\n raise RuntimeError('len(potential_indices) < 1')\n\n potential_indices.append(len(lines2))\n\n # Top shell\n\n index = 0\n\n potential_start = potential_indices[index]\n potential_stop = potential_indices[index + 1]\n\n mobj = re.match(r'^\\s*(\\S)\\s+potential\\s*$', lines2[potential_start], re.IGNORECASE)\n if mobj is None:\n raise RuntimeError('Where is the \"max_L potential\" line?')\n\n shell_char = mobj.group(1).upper()\n if shell_char not in _shell_data_:\n raise RuntimeError(f'Unknown shell type: {shell_char}')\n\n if _shell_data_[shell_char] != max_L:\n raise RuntimeError('Invalid max_L')\n\n mobj = re.match(r'^\\s*(\\d+)\\s*$', lines2[potential_start + 1])\n if mobj is None:\n raise RuntimeError('Where is the \"nprimitive\" line?')\n\n nprimitive = int(mobj.group(1))\n\n lines3 = lines2[potential_start + 2 : potential_stop]\n\n if len(lines3) != nprimitive:\n raise RuntimeError('nprimitive is incorrect')\n\n ns = []\n ws = []\n es = []\n for line in lines3:\n mobj = re.match(r'^\\s*(\\d+)\\s+(\\S+)\\s+(\\S+)\\s*$', line)\n if mobj is None:\n raise RuntimeError('where is the \"n e w\" line?')\n ns.append(int(mobj.group(1)))\n es.append(float(mobj.group(2)))\n ws.append(float(mobj.group(3)))\n\n top_shell = ECPShellInfo(L=max_L, ns=ns, ws=ws, es=es)\n\n # Other shells\n\n shells = []\n for index in range(1, len(potential_indices) - 1):\n potential_start = potential_indices[index]\n potential_stop = potential_indices[index + 1]\n\n mobj = re.match(r'^\\s*(\\S)-(\\S)\\s+potential\\s*$', lines2[potential_start], re.IGNORECASE)\n if mobj is None:\n raise RuntimeError('Where is the \"L-max_L potential\" line?')\n\n if _shell_data_[mobj.group(2).upper()] != max_L:\n raise RuntimeError('Invalid max_L')\n\n L = _shell_data_[mobj.group(1).upper()]\n\n mobj = re.match(r'^\\s*(\\d+)\\s*$', lines2[potential_start + 1])\n if mobj is None:\n raise RuntimeError('Where is the \"nprimitive\" line?')\n\n nprimitive = int(mobj.group(1))\n\n lines3 = lines2[potential_start + 2 : potential_stop]\n\n if len(lines3) != nprimitive:\n raise RuntimeError('nprimitive is incorrect')\n\n ns = []\n ws = []\n es = []\n for line in lines3:\n mobj = re.match(r'^\\s*(\\d+)\\s+(\\S+)\\s+(\\S+)\\s*$', line)\n if mobj is None:\n raise RuntimeError('where is the \"n e w\" line?')\n ns.append(int(mobj.group(1)))\n es.append(float(mobj.group(2)))\n ws.append(float(mobj.group(3)))\n\n shells.append(ECPShellInfo(L=L, ns=ns, ws=ws, es=es))\n\n return {\n 'nelectron': nelectron,\n 'shells': shells,\n 'top_shell': top_shell,\n }\n\n\ndef simple_ecp_parser(\n *,\n filename,\n symbols,\n ):\n\n with open(filename) as fp:\n lines = fp.readlines()\n\n # => Cleaning <= #\n\n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]\n # Strip comment lines out\n re_comment = re.compile(r'\\s*!')\n lines = [_ for _ in lines if not re.match(re_comment, _)]\n # Lines must be nonzero \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')","source_hash":"fb6237d80684b6d37dcf31f251d51dd9d0bdf962c40215af137ea203930be0bc","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.parsers.simple_ecp_parser","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.parsers.simple_ecp_parser#L197-L254","kind":"function","name":"simple_ecp_parser","path":"cuEST/python_examples/helpers/parsers.py","language":"python","start_line":197,"end_line":254,"context_start_line":177,"context_end_line":274,"code":" ns = []\n ws = []\n es = []\n for line in lines3:\n mobj = re.match(r'^\\s*(\\d+)\\s+(\\S+)\\s+(\\S+)\\s*$', line)\n if mobj is None:\n raise RuntimeError('where is the \"n e w\" line?')\n ns.append(int(mobj.group(1)))\n es.append(float(mobj.group(2)))\n ws.append(float(mobj.group(3)))\n\n shells.append(ECPShellInfo(L=L, ns=ns, ws=ws, es=es))\n\n return {\n 'nelectron': nelectron,\n 'shells': shells,\n 'top_shell': top_shell,\n }\n\n\ndef simple_ecp_parser(\n *,\n filename,\n symbols,\n ):\n\n with open(filename) as fp:\n lines = fp.readlines()\n\n # => Cleaning <= #\n\n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]\n # Strip comment lines out\n re_comment = re.compile(r'\\s*!')\n lines = [_ for _ in lines if not re.match(re_comment, _)]\n # Lines must be nonzero \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n\n # Find ECP entries matching this kind of pattern\n # SI 0\n # SI-ECP 2 10\n # But joined onto a single line\n ecp_re = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s*(\\S+)-ECP\\s+(\\d+)\\s+(\\d+)\\s*$')\n ecp_inds = []\n for ind in range(len(lines) - 1):\n line = lines[ind] + lines[ind + 1] # Join into a single line\n if ecp_re.match(line):\n ecp_inds.append(ind)\n ecp_inds.append(len(lines))\n\n # Extract the lines pertaining to each atom symbol\n symbol_ecp_info = {}\n for k in range(len(ecp_inds) - 1):\n ind1 = ecp_inds[k]\n ind2 = ecp_inds[k + 1]\n if (ind2 - ind1) <= 0: # Guard against empty entries\n continue\n mobj = re.match(\n r'^\\s*(\\S+)\\s+(\\d+)\\s*$', lines[ind1]\n ) # Check if the line is a regular basis entry or an ECP entry\n if mobj == None:\n raise Exception(\"Where is the ID V line?\")\n if mobj.group(2) != '0':\n continue # Regular basis entry, not an ECP entry\n # Try to match the next line to something of the form\n # SR-ECP 3 28\n mobj = re.match(r'^\\s*(\\S+)-ECP\\s+(\\d+)\\s+(\\d+)\\s*$', lines[ind1 + 1])\n if mobj is None:\n # This is a regular atom entry, not an ECP entry\n continue\n symbol_ecp_info[mobj.group(1).upper()] = _ecp_shell_info_from_ecp_lines(lines=lines[ind1 + 1 : ind2])\n\n ecp_metadata = []\n for symbol in symbols:\n ecp_metadata.append(symbol_ecp_info.get(symbol.upper(), None))\n\n return ecp_metadata\n\n\ndef simple_gbs_parser(\n *,\n filename,\n symbols,\n ):\n\n shell_types = [\n 'S', 'P', 'D', 'F', 'G', 'H', 'I',\n 'K', 'L', 'M', 'N', 'O', 'Q', 'R',\n 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n ]\n with open(filename) as fp:\n lines = fp.readlines()\n\n # => Cleaning <= #\n\n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]","source_hash":"fb6237d80684b6d37dcf31f251d51dd9d0bdf962c40215af137ea203930be0bc","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.parsers.simple_gbs_parser","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.parsers.simple_gbs_parser#L257-L371","kind":"function","name":"simple_gbs_parser","path":"cuEST/python_examples/helpers/parsers.py","language":"python","start_line":257,"end_line":371,"context_start_line":237,"context_end_line":371,"code":" ) # Check if the line is a regular basis entry or an ECP entry\n if mobj == None:\n raise Exception(\"Where is the ID V line?\")\n if mobj.group(2) != '0':\n continue # Regular basis entry, not an ECP entry\n # Try to match the next line to something of the form\n # SR-ECP 3 28\n mobj = re.match(r'^\\s*(\\S+)-ECP\\s+(\\d+)\\s+(\\d+)\\s*$', lines[ind1 + 1])\n if mobj is None:\n # This is a regular atom entry, not an ECP entry\n continue\n symbol_ecp_info[mobj.group(1).upper()] = _ecp_shell_info_from_ecp_lines(lines=lines[ind1 + 1 : ind2])\n\n ecp_metadata = []\n for symbol in symbols:\n ecp_metadata.append(symbol_ecp_info.get(symbol.upper(), None))\n\n return ecp_metadata\n\n\ndef simple_gbs_parser(\n *,\n filename,\n symbols,\n ):\n\n shell_types = [\n 'S', 'P', 'D', 'F', 'G', 'H', 'I',\n 'K', 'L', 'M', 'N', 'O', 'Q', 'R',\n 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\n ]\n with open(filename) as fp:\n lines = fp.readlines()\n\n # => Cleaning <= #\n\n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]\n # Strip comment lines out\n re_comment = re.compile(r'\\s*!')\n lines = [_ for _ in lines if not re.match(re_comment, _)]\n # Lines must be nonzero \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n\n # => Spherical / Cartesian Tag Line <= #\n\n mobj = re.match(r'^\\s*(spherical|cartesian)\\s*$', lines[0])\n if mobj is None:\n raise RuntimeError(\"First line of GBS file must be 'spherical' or 'cartesian', instead is: %s\" % lines[0])\n\n if mobj.group(1) == 'spherical':\n is_pure = True\n elif mobj.group(1) == 'cartesian':\n is_pure = False\n else:\n raise RuntimeError('Invalid cartesian/spherical label: %s' % mobj.group(1))\n\n lines = lines[1:]\n\n # => Atom Block Location <= #\n\n re_separator = re.compile(r'\\s*\\*\\*\\*\\*\\s*$')\n separator_indices = [k for k, line in enumerate(lines) if re.match(re_separator, line)]\n if len(separator_indices) == 0: \n raise RuntimeError('No **** separators present')\n if separator_indices[-1] + 1 != len(lines):\n raise RuntimeError('Last line must be ****, instead is: %s' % lines[-1])\n lines = lines[:-1]\n separator_indices = separator_indices[:-1]\n\n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n if len(separator_indices) == 0: raise RuntimeError('No **** separators present')\n\n # => Atom IDs and corresponding block index <= #\n\n re_atom_id = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s*$')\n atom_id_lines = [lines[_ + 1] for _ in separator_indices]\n symbol_index_map = {}\n for index, atom_id_line in enumerate(atom_id_lines):\n mobj = re.match(re_atom_id, atom_id_line)\n if mobj is None:\n raise RuntimeError('Malformed atom ID line: %s' % (atom_id_line))\n symbol = mobj.group(1)\n atom_index = int(mobj.group(2))\n if atom_index != 0: \n raise RuntimeError('\"Symbol 0\" is only allowed atom line - multiple basis sets per atom type in GBS files is not supported by this library')\n symbol_upper = symbol.upper()\n if symbol in symbol_index_map:\n raise RuntimeError(f'Duplicate atomic symbol in GBS file: {symbol}')\n symbol_index_map[symbol_upper] = index\n\n re_shell_type = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s+(\\S+)\\s*$')\n re_primitive = re.compile(r'^\\s*(\\S+)\\s+(\\S+)\\s*$')\n\n shellinfo = []\n for symbol in symbols:\n symbol = symbol.upper()\n if symbol not in symbol_index_map:\n raise RuntimeError(f'{symbol} not defined in GBS file')\n block_index = symbol_index_map[symbol]\n index1 = separator_indices[block_index + 0]\n index2 = separator_indices[block_index + 1] if block_index + 1 < len(separator_indices) else len(lines)\n\n block_lines = lines[index1+2:index2]\n shell_type_indices = [k for k, line in enumerate(block_lines) if re.match(re_shell_type, line)]\n\n atom_shells = []\n for index in shell_type_indices:\n shell_type_line = block_lines[index]\n mobj = re.match(re_shell_type, shell_type_line)\n am_symbol_upper = mobj.group(1).upper()\n if am_symbol_upper not in shell_types:\n raise RuntimeError(f'Unknown angular momentum symbol: {am_symbol_upper}')\n L = shell_types.index(am_symbol_upper)\n nprimitive = int(mobj.group(2))\n normalization = float(mobj.group(3))\n exponents = []\n coefficients_raw = []\n for K in range(nprimitive):\n primitive_line = block_lines[index + 1 + K]\n # Replace D with E for FORTRAN notation\n primitive_line = primitive_line.replace('D', 'E')\n primitive_line = primitive_line.replace('d', 'e')\n mobj = re.match(re_primitive, primitive_line)\n exponents.append(float(mobj.group(1)))\n coefficients_raw.append(float(mobj.group(2)))\n atom_shells.append({\n 'is_pure' : is_pure,\n 'L' : L,\n 'exponents' : exponents,\n 'coefficients' : coefficients_raw,\n 'normalization' : normalization,\n })\n shellinfo.append(atom_shells)\n return shellinfo","source_hash":"fb6237d80684b6d37dcf31f251d51dd9d0bdf962c40215af137ea203930be0bc","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.utilities","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.helpers.utilities#L1-L51","kind":"module","name":"cuEST.python_examples.helpers.utilities","path":"cuEST/python_examples/helpers/utilities.py","language":"python","start_line":1,"end_line":51,"context_start_line":1,"context_end_line":51,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\ntry:\n import numpy as np\nexcept ImportError:\n raise RuntimeError(\"numpy could not be imported. It is available via\\n\\tpip install numpy\")\n\ndef normalize_shell_coefficients(\n coefficients,\n exponents,\n L,\n normalization,\n ):\n \"\"\"\n Normalizes a Gaussian shell of primitive functions, so that their self overlap is the\n value provided by the \"normalization\" argument.\n \"\"\"\n\n exponents = np.array(exponents)\n coefficients = np.array(coefficients)\n assert len(exponents) == len(coefficients)\n\n dfact = 1\n for l in range(1, L+1):\n dfact *= 2 * l - 1\n\n # Primitive normalization\n output = np.sqrt( 2**L * (2 * exponents)**(L+1.5) / (np.pi**1.5 * dfact) ) * coefficients\n\n # Contraction normalization\n Q = 0.0\n for c1, e1 in zip(coefficients, exponents):\n for c2, e2 in zip(coefficients, exponents):\n Q += (np.sqrt(4 * e1 * e2) / (e1 + e2)) ** (L + 1.5) * c1 * c2\n Q = Q**(-0.5)\n Q *= np.sqrt(normalization)\n\n return output * Q","source_hash":"21c23fc5fe09b1c858a5c595363ec9db306f6cc7848bf55e86948079a44797ef","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.utilities.normalize_shell_coefficients","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.utilities.normalize_shell_coefficients#L21-L51","kind":"function","name":"normalize_shell_coefficients","path":"cuEST/python_examples/helpers/utilities.py","language":"python","start_line":21,"end_line":51,"context_start_line":1,"context_end_line":51,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\ntry:\n import numpy as np\nexcept ImportError:\n raise RuntimeError(\"numpy could not be imported. It is available via\\n\\tpip install numpy\")\n\ndef normalize_shell_coefficients(\n coefficients,\n exponents,\n L,\n normalization,\n ):\n \"\"\"\n Normalizes a Gaussian shell of primitive functions, so that their self overlap is the\n value provided by the \"normalization\" argument.\n \"\"\"\n\n exponents = np.array(exponents)\n coefficients = np.array(coefficients)\n assert len(exponents) == len(coefficients)\n\n dfact = 1\n for l in range(1, L+1):\n dfact *= 2 * l - 1\n\n # Primitive normalization\n output = np.sqrt( 2**L * (2 * exponents)**(L+1.5) / (np.pi**1.5 * dfact) ) * coefficients\n\n # Contraction normalization\n Q = 0.0\n for c1, e1 in zip(coefficients, exponents):\n for c2, e2 in zip(coefficients, exponents):\n Q += (np.sqrt(4 * e1 * e2) / (e1 + e2)) ** (L + 1.5) * c1 * c2\n Q = Q**(-0.5)\n Q *= np.sqrt(normalization)\n\n return output * Q","source_hash":"21c23fc5fe09b1c858a5c595363ec9db306f6cc7848bf55e86948079a44797ef","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.grid_utils","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.helpers.grid_utils#L1-L85","kind":"module","name":"cuEST.python_examples.helpers.grid_utils","path":"cuEST/python_examples/helpers/grid_utils.py","language":"python","start_line":1,"end_line":85,"context_start_line":1,"context_end_line":85,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\ndef symbol_to_ahlrichs_radius(\n *,\n symbol,\n ):\n\n symbol = symbol.upper()\n\n radii = {\n \"X\" : 1.00, \n \"H\" : 0.80,\n \"HE\" : 0.90,\n \"LI\" : 1.80,\n \"BE\" : 1.40,\n \"B\" : 1.30,\n \"C\" : 1.10,\n \"N\" : 0.90,\n \"O\" : 0.90,\n \"F\" : 0.90,\n \"NE\" : 0.90,\n \"NA\" : 1.40,\n \"MG\" : 1.30,\n \"AL\" : 1.30,\n \"SI\" : 1.20,\n \"P\" : 1.10,\n \"S\" : 1.00,\n \"CL\" : 1.00,\n \"AR\" : 1.00,\n \"K\" : 1.50,\n \"CA\" : 1.40,\n \"SC\" : 1.30,\n \"TI\" : 1.20,\n \"V\" : 1.20,\n \"CR\" : 1.20,\n \"MN\" : 1.20,\n \"FE\" : 1.20,\n \"CO\" : 1.20,\n \"NI\" : 1.10,\n \"CU\" : 1.10,\n \"ZN\" : 1.10,\n \"GA\" : 1.10,\n \"GE\" : 1.00,\n \"AS\" : 0.90,\n \"SE\" : 0.90,\n \"BR\" : 0.90,\n \"KR\" : 0.90,\n }\n\n return radii.get(symbol, 1.0)\n\n\ndef build_ahlrichs_radial_quadrature(\n *,\n npoint,\n R,\n ):\n\n alpha = 0.6\n\n n = np.arange(1.0, npoint+1.0)\n z = n * np.pi / (npoint + 1.0)\n x = np.cos(z)\n y = np.sin(z)\n u = np.log((1.0 - x) / 2.0)\n v = ((1.0 + x)**alpha) / np.log(2.0)\n radial_nodes = - R * v * u\n radial_weights = np.pi / (npoint + 1.0) * y * R * v * (-alpha * u / (1.0 + x) + 1.0 / (1.0 - x)) * radial_nodes**2\n\n return np.flip(radial_nodes), np.flip(radial_weights)","source_hash":"f8ef3d463fa70bf20d789fb2f925e577ce39a278cbd3340e527f47b2f1125205","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.grid_utils.symbol_to_ahlrichs_radius","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.grid_utils.symbol_to_ahlrichs_radius#L18-L65","kind":"function","name":"symbol_to_ahlrichs_radius","path":"cuEST/python_examples/helpers/grid_utils.py","language":"python","start_line":18,"end_line":65,"context_start_line":1,"context_end_line":85,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\ndef symbol_to_ahlrichs_radius(\n *,\n symbol,\n ):\n\n symbol = symbol.upper()\n\n radii = {\n \"X\" : 1.00, \n \"H\" : 0.80,\n \"HE\" : 0.90,\n \"LI\" : 1.80,\n \"BE\" : 1.40,\n \"B\" : 1.30,\n \"C\" : 1.10,\n \"N\" : 0.90,\n \"O\" : 0.90,\n \"F\" : 0.90,\n \"NE\" : 0.90,\n \"NA\" : 1.40,\n \"MG\" : 1.30,\n \"AL\" : 1.30,\n \"SI\" : 1.20,\n \"P\" : 1.10,\n \"S\" : 1.00,\n \"CL\" : 1.00,\n \"AR\" : 1.00,\n \"K\" : 1.50,\n \"CA\" : 1.40,\n \"SC\" : 1.30,\n \"TI\" : 1.20,\n \"V\" : 1.20,\n \"CR\" : 1.20,\n \"MN\" : 1.20,\n \"FE\" : 1.20,\n \"CO\" : 1.20,\n \"NI\" : 1.10,\n \"CU\" : 1.10,\n \"ZN\" : 1.10,\n \"GA\" : 1.10,\n \"GE\" : 1.00,\n \"AS\" : 0.90,\n \"SE\" : 0.90,\n \"BR\" : 0.90,\n \"KR\" : 0.90,\n }\n\n return radii.get(symbol, 1.0)\n\n\ndef build_ahlrichs_radial_quadrature(\n *,\n npoint,\n R,\n ):\n\n alpha = 0.6\n\n n = np.arange(1.0, npoint+1.0)\n z = n * np.pi / (npoint + 1.0)\n x = np.cos(z)\n y = np.sin(z)\n u = np.log((1.0 - x) / 2.0)\n v = ((1.0 + x)**alpha) / np.log(2.0)\n radial_nodes = - R * v * u\n radial_weights = np.pi / (npoint + 1.0) * y * R * v * (-alpha * u / (1.0 + x) + 1.0 / (1.0 - x)) * radial_nodes**2\n\n return np.flip(radial_nodes), np.flip(radial_weights)","source_hash":"f8ef3d463fa70bf20d789fb2f925e577ce39a278cbd3340e527f47b2f1125205","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.grid_utils.build_ahlrichs_radial_quadrature","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.grid_utils.build_ahlrichs_radial_quadrature#L68-L85","kind":"function","name":"build_ahlrichs_radial_quadrature","path":"cuEST/python_examples/helpers/grid_utils.py","language":"python","start_line":68,"end_line":85,"context_start_line":48,"context_end_line":85,"code":" \"TI\" : 1.20,\n \"V\" : 1.20,\n \"CR\" : 1.20,\n \"MN\" : 1.20,\n \"FE\" : 1.20,\n \"CO\" : 1.20,\n \"NI\" : 1.10,\n \"CU\" : 1.10,\n \"ZN\" : 1.10,\n \"GA\" : 1.10,\n \"GE\" : 1.00,\n \"AS\" : 0.90,\n \"SE\" : 0.90,\n \"BR\" : 0.90,\n \"KR\" : 0.90,\n }\n\n return radii.get(symbol, 1.0)\n\n\ndef build_ahlrichs_radial_quadrature(\n *,\n npoint,\n R,\n ):\n\n alpha = 0.6\n\n n = np.arange(1.0, npoint+1.0)\n z = n * np.pi / (npoint + 1.0)\n x = np.cos(z)\n y = np.sin(z)\n u = np.log((1.0 - x) / 2.0)\n v = ((1.0 + x)**alpha) / np.log(2.0)\n radial_nodes = - R * v * u\n radial_weights = np.pi / (npoint + 1.0) * y * R * v * (-alpha * u / (1.0 + x) + 1.0 / (1.0 - x)) * radial_nodes**2\n\n return np.flip(radial_nodes), np.flip(radial_weights)","source_hash":"f8ef3d463fa70bf20d789fb2f925e577ce39a278cbd3340e527f47b2f1125205","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.helpers.cuda_utils#L1-L364","kind":"module","name":"cuEST.python_examples.helpers.cuda_utils","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":1,"end_line":364,"context_start_line":1,"context_end_line":364,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# There are numerous way to access GPU resources from Python. High level\n# packages such as CuPy, TensorFlow and Pytorch can simplify allocations and\n# transfers between host and device. Here we demonstrate two lower level\n# approaches to accessing CUDA functions to provide these utilities: 1) using\n# the cuda-bindings package to access native CUDA in Pythonic way, and 2) using\n# the ctypes module to directly access these functions from the CUDA runtime\n# library. A real implementation should ideally use a single unified\n# mechanism, but a mixture is used here for demonstration purposes.\n\nimport ctypes\ntry:\n import numpy as np\nexcept ImportError:\n raise RuntimeError(\"numpy could not be imported. It is available via\\n\\tpip install numpy\")\n\ntry:\n import cuda.bindings.runtime as cuda\nexcept ImportError:\n raise RuntimeError(\"cuda.bindings could not be imported. It is available via\\n\\tpip install cuda-bindings\")\n\n\n# These will be used by the ctypes-powered utility functions below.\ntry:\n _cublas = ctypes.cdll.LoadLibrary('libcublas.so')\nexcept OSError as err:\n raise RuntimeError(\"Could not load cuBLAS library.\") from err\n\ntry:\n _cusolver = ctypes.cdll.LoadLibrary('libcusolver.so')\nexcept OSError as err:\n raise RuntimeError(\"Could not load cuSolver library.\") from err\n\n\n\ndef make_stream():\n \"\"\"\n This function should return a new cuestStream_t (or Python\n equivalent) representing a CUDA stream.\n \"\"\"\n\n ret, stream = cuda.cudaStreamCreate()\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to make CUDA stream:\", ret)\n\n return stream\n\n\ndef cuda_malloc(\n *,\n size_in_bytes,\n ):\n \"\"\"\n This function should allocate device memory, and return an integer\n representation of the address of the resulting block.\n \"\"\"\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n\ndef cuda_memcpy_dtoh(\n *,\n host_pointer,\n device_pointer,\n size_in_bytes,\n stream=0,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToHost,\n stream=stream)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to host failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)\n\n\ndef cuda_memcpy_htod(\n *,\n device_pointer,\n host_pointer,\n size_in_bytes,\n stream=0,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyHostToDevice,\n stream=stream)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from host to device failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)\n\n\ndef cuda_free(\n array\n ):\n \"\"\"\n This function should free memory allocated on the device, passed in\n as an integer representation of its device pointer\n \"\"\"\n\n ret = cuda.cudaFree(array)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n\ndef make_cublas_handle():\n \"\"\"\n Helper function demonstrating how to use ctypes to access the C\n cuBLAS API to make a new cuBLAS handle.\n \"\"\"\n handle = ctypes.c_void_p()\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasCreate_v2.restype = ctypes.c_int\n _cublas.cublasCreate_v2.argtypes = [ctypes.POINTER(ctypes.c_void_p)]\n\n status = _cublas.cublasCreate_v2(ctypes.byref(handle))\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasCreate_v2 failed with status {status}\")\n\n return handle\n\n\ndef free_cublas_handle(\n *,\n handle\n ):\n\n \"\"\"\n Helper function to free cuBLAS resource handle.\n \"\"\"\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasDestroy_v2.restype = ctypes.c_int\n _cublas.cublasDestroy_v2.argtypes = [ctypes.c_void_p]\n\n status = _cublas.cublasDestroy_v2(handle)\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasDestroy_v2 failed with status {status}\")\n\n\ndef make_cusolver_handle():\n \"\"\"\n Make a cuSolver handle via the CUDA C API.\n \"\"\"\n handle = ctypes.c_void_p()\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnCreate.restype = ctypes.c_int\n _cusolver.cusolverDnCreate.argtypes = [ctypes.POINTER(ctypes.c_void_p)]\n\n status = _cusolver.cusolverDnCreate(ctypes.byref(handle))\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnCreate failed with status {status}\")\n\n return handle\n\n\ndef free_cusolver_handle(\n handle\n ):\n \"\"\"\n Free resources associated with a cuSolver handle.\n \"\"\"\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnDestroy.restype = ctypes.c_int\n _cusolver.cusolverDnDestroy.argtypes = [ctypes.c_void_p]\n\n status = _cusolver.cusolverDnDestroy(handle)\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnDestroy failed with status {status}\")\n\n\ndef set_cublas_stream(\n *,\n handle,\n stream,\n ):\n \"\"\"\n Set the active stream for a given cuBLAS handle\n \"\"\"\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasSetStream_v2.restype = ctypes.c_int\n _cublas.cublasSetStream_v2.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n\n status = _cublas.cublasSetStream_v2(handle, stream)\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasSetStream failed with status {status}\")\n\n\ndef set_cusolver_stream(\n *,\n handle,\n stream,\n ):\n \"\"\"\n Set the stream for a given cuSolver handle.\n \"\"\"\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnSetStream.restype = ctypes.c_int\n _cusolver.cusolverDnSetStream.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n\n status = _cusolver.cusolverDnSetStream(handle, stream)\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnSetStream failed with status {status}\")\n\n\nclass WorkspaceDescriptor:\n \"\"\"\n This helper function needs to implement the following C structure,\n and define a pointer method that returns a pointer to it.\n\n typedef struct {\n size_t hostBufferSizeInBytes; ///< Required size of host workspace buffer in bytes\n size_t deviceBufferSizeInBytes; ///< Required size of device workspace buffer in bytes\n } cuestWorkspaceDescriptor_t;\n\n This implementation uses Numpy, as the ctypes.data member provides a\n convenient way to access a pointer to the object\n \"\"\"\n\n def __init__(\n self,\n *,\n host_buffer_size_in_bytes = 0,\n device_buffer_size_in_bytes = 0,\n ):\n\n _workspace_descriptor_dtype = np.dtype([\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n self.struct = np.empty(1, dtype=_workspace_descriptor_dtype)\n self.struct['deviceBufferSizeInBytes'] = device_buffer_size_in_bytes\n self.struct['hostBufferSizeInBytes'] = host_buffer_size_in_bytes\n\n def __str__(\n self,\n ):\n\n host_size = self.struct['hostBufferSizeInBytes'].item()\n device_size = self.struct['deviceBufferSizeInBytes'].item()\n return f'host buffer size = {host_size} bytes, device buffer size = {device_size} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n\nclass Workspace:\n \"\"\"\n This helper function needs to implement the following C structure,\n and define a pointer method that returns a pointer to it.\n\n typedef struct {\n uintptr_t hostBuffer; ///< Opaque pointer to host-side workspace buffer\n size_t hostBufferSizeInBytes; ///< Size of host workspace in bytes\n uintptr_t deviceBuffer; ///< Opaque pointer to device-side (GPU) workspace buffer\n size_t deviceBufferSizeInBytes; ///< Size of device workspace in bytes\n } cuestWorkspace_t;\n\n This implementation uses Numpy, as the ctypes.data member provides a\n convenient way to access a pointer to the object\n \"\"\"\n def __init__(\n self,\n *,\n workspaceDescriptor,\n ):\n _workspace_dtype = np.dtype([\n (\"hostBuffer\", np.uintp, ),\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBuffer\", np.uintp, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n host_buffer_size_in_bytes = workspaceDescriptor.struct['hostBufferSizeInBytes'].item()\n device_buffer_size_in_bytes = workspaceDescriptor.struct['deviceBufferSizeInBytes'].item()\n\n self.struct = np.empty(1, dtype=_workspace_dtype)\n self.struct['deviceBufferSizeInBytes'] = device_buffer_size_in_bytes\n self.struct['hostBufferSizeInBytes'] = host_buffer_size_in_bytes\n\n if device_buffer_size_in_bytes:\n ret, pointer = cuda.cudaMalloc(device_buffer_size_in_bytes)\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Failed to allocate workspace\", ret)\n self.struct['deviceBuffer'] = pointer\n else:\n self.struct['deviceBuffer'] = 0\n\n if host_buffer_size_in_bytes:\n self.cpu_memory = np.zeros(host_buffer_size_in_bytes, dtype=np.int8)\n self.struct['hostBuffer'] = self.cpu_memory.ctypes.data\n else:\n self.struct['hostBuffer'] = 0\n self.cpu_memory = None\n\n def __del__(\n self,\n ):\n\n if self.struct['deviceBuffer']:\n ret = cuda.cudaFree(self.struct['deviceBuffer'].item())\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to deallocate workspace:\", ret[0])\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.make_stream","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.make_stream#L50-L61","kind":"function","name":"make_stream","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":50,"end_line":61,"context_start_line":30,"context_end_line":81,"code":"\ntry:\n import cuda.bindings.runtime as cuda\nexcept ImportError:\n raise RuntimeError(\"cuda.bindings could not be imported. It is available via\\n\\tpip install cuda-bindings\")\n\n\n# These will be used by the ctypes-powered utility functions below.\ntry:\n _cublas = ctypes.cdll.LoadLibrary('libcublas.so')\nexcept OSError as err:\n raise RuntimeError(\"Could not load cuBLAS library.\") from err\n\ntry:\n _cusolver = ctypes.cdll.LoadLibrary('libcusolver.so')\nexcept OSError as err:\n raise RuntimeError(\"Could not load cuSolver library.\") from err\n\n\n\ndef make_stream():\n \"\"\"\n This function should return a new cuestStream_t (or Python\n equivalent) representing a CUDA stream.\n \"\"\"\n\n ret, stream = cuda.cudaStreamCreate()\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to make CUDA stream:\", ret)\n\n return stream\n\n\ndef cuda_malloc(\n *,\n size_in_bytes,\n ):\n \"\"\"\n This function should allocate device memory, and return an integer\n representation of the address of the resulting block.\n \"\"\"\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n\ndef cuda_memcpy_dtoh(\n *,","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.cuda_malloc","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.cuda_malloc#L64-L77","kind":"function","name":"cuda_malloc","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":64,"end_line":77,"context_start_line":44,"context_end_line":97,"code":" _cusolver = ctypes.cdll.LoadLibrary('libcusolver.so')\nexcept OSError as err:\n raise RuntimeError(\"Could not load cuSolver library.\") from err\n\n\n\ndef make_stream():\n \"\"\"\n This function should return a new cuestStream_t (or Python\n equivalent) representing a CUDA stream.\n \"\"\"\n\n ret, stream = cuda.cudaStreamCreate()\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to make CUDA stream:\", ret)\n\n return stream\n\n\ndef cuda_malloc(\n *,\n size_in_bytes,\n ):\n \"\"\"\n This function should allocate device memory, and return an integer\n representation of the address of the resulting block.\n \"\"\"\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n\ndef cuda_memcpy_dtoh(\n *,\n host_pointer,\n device_pointer,\n size_in_bytes,\n stream=0,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.cuda_memcpy_dtoh","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.cuda_memcpy_dtoh#L80-L104","kind":"function","name":"cuda_memcpy_dtoh","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":80,"end_line":104,"context_start_line":60,"context_end_line":124,"code":"\n return stream\n\n\ndef cuda_malloc(\n *,\n size_in_bytes,\n ):\n \"\"\"\n This function should allocate device memory, and return an integer\n representation of the address of the resulting block.\n \"\"\"\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n\ndef cuda_memcpy_dtoh(\n *,\n host_pointer,\n device_pointer,\n size_in_bytes,\n stream=0,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToHost,\n stream=stream)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to host failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)\n\n\ndef cuda_memcpy_htod(\n *,\n device_pointer,\n host_pointer,\n size_in_bytes,\n stream=0,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.cuda_memcpy_htod","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.cuda_memcpy_htod#L107-L131","kind":"function","name":"cuda_memcpy_htod","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":107,"end_line":131,"context_start_line":87,"context_end_line":151,"code":" \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToHost,\n stream=stream)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to host failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)\n\n\ndef cuda_memcpy_htod(\n *,\n device_pointer,\n host_pointer,\n size_in_bytes,\n stream=0,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyHostToDevice,\n stream=stream)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from host to device failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)\n\n\ndef cuda_free(\n array\n ):\n \"\"\"\n This function should free memory allocated on the device, passed in\n as an integer representation of its device pointer\n \"\"\"\n\n ret = cuda.cudaFree(array)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n\ndef make_cublas_handle():\n \"\"\"\n Helper function demonstrating how to use ctypes to access the C\n cuBLAS API to make a new cuBLAS handle.","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.cuda_free","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.cuda_free#L134-L145","kind":"function","name":"cuda_free","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":134,"end_line":145,"context_start_line":114,"context_end_line":165,"code":" \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyHostToDevice,\n stream=stream)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from host to device failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)\n\n\ndef cuda_free(\n array\n ):\n \"\"\"\n This function should free memory allocated on the device, passed in\n as an integer representation of its device pointer\n \"\"\"\n\n ret = cuda.cudaFree(array)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n\ndef make_cublas_handle():\n \"\"\"\n Helper function demonstrating how to use ctypes to access the C\n cuBLAS API to make a new cuBLAS handle.\n \"\"\"\n handle = ctypes.c_void_p()\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasCreate_v2.restype = ctypes.c_int\n _cublas.cublasCreate_v2.argtypes = [ctypes.POINTER(ctypes.c_void_p)]\n\n status = _cublas.cublasCreate_v2(ctypes.byref(handle))\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasCreate_v2 failed with status {status}\")\n\n return handle\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.make_cublas_handle","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.make_cublas_handle#L148-L164","kind":"function","name":"make_cublas_handle","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":148,"end_line":164,"context_start_line":128,"context_end_line":184,"code":" if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from host to device failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)\n\n\ndef cuda_free(\n array\n ):\n \"\"\"\n This function should free memory allocated on the device, passed in\n as an integer representation of its device pointer\n \"\"\"\n\n ret = cuda.cudaFree(array)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n\ndef make_cublas_handle():\n \"\"\"\n Helper function demonstrating how to use ctypes to access the C\n cuBLAS API to make a new cuBLAS handle.\n \"\"\"\n handle = ctypes.c_void_p()\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasCreate_v2.restype = ctypes.c_int\n _cublas.cublasCreate_v2.argtypes = [ctypes.POINTER(ctypes.c_void_p)]\n\n status = _cublas.cublasCreate_v2(ctypes.byref(handle))\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasCreate_v2 failed with status {status}\")\n\n return handle\n\n\ndef free_cublas_handle(\n *,\n handle\n ):\n\n \"\"\"\n Helper function to free cuBLAS resource handle.\n \"\"\"\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasDestroy_v2.restype = ctypes.c_int\n _cublas.cublasDestroy_v2.argtypes = [ctypes.c_void_p]\n\n status = _cublas.cublasDestroy_v2(handle)\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasDestroy_v2 failed with status {status}\")\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.free_cublas_handle","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.free_cublas_handle#L167-L183","kind":"function","name":"free_cublas_handle","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":167,"end_line":183,"context_start_line":147,"context_end_line":203,"code":"\ndef make_cublas_handle():\n \"\"\"\n Helper function demonstrating how to use ctypes to access the C\n cuBLAS API to make a new cuBLAS handle.\n \"\"\"\n handle = ctypes.c_void_p()\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasCreate_v2.restype = ctypes.c_int\n _cublas.cublasCreate_v2.argtypes = [ctypes.POINTER(ctypes.c_void_p)]\n\n status = _cublas.cublasCreate_v2(ctypes.byref(handle))\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasCreate_v2 failed with status {status}\")\n\n return handle\n\n\ndef free_cublas_handle(\n *,\n handle\n ):\n\n \"\"\"\n Helper function to free cuBLAS resource handle.\n \"\"\"\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasDestroy_v2.restype = ctypes.c_int\n _cublas.cublasDestroy_v2.argtypes = [ctypes.c_void_p]\n\n status = _cublas.cublasDestroy_v2(handle)\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasDestroy_v2 failed with status {status}\")\n\n\ndef make_cusolver_handle():\n \"\"\"\n Make a cuSolver handle via the CUDA C API.\n \"\"\"\n handle = ctypes.c_void_p()\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnCreate.restype = ctypes.c_int\n _cusolver.cusolverDnCreate.argtypes = [ctypes.POINTER(ctypes.c_void_p)]\n\n status = _cusolver.cusolverDnCreate(ctypes.byref(handle))\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnCreate failed with status {status}\")\n\n return handle\n\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.make_cusolver_handle","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.make_cusolver_handle#L186-L201","kind":"function","name":"make_cusolver_handle","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":186,"end_line":201,"context_start_line":166,"context_end_line":221,"code":"\ndef free_cublas_handle(\n *,\n handle\n ):\n\n \"\"\"\n Helper function to free cuBLAS resource handle.\n \"\"\"\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasDestroy_v2.restype = ctypes.c_int\n _cublas.cublasDestroy_v2.argtypes = [ctypes.c_void_p]\n\n status = _cublas.cublasDestroy_v2(handle)\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasDestroy_v2 failed with status {status}\")\n\n\ndef make_cusolver_handle():\n \"\"\"\n Make a cuSolver handle via the CUDA C API.\n \"\"\"\n handle = ctypes.c_void_p()\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnCreate.restype = ctypes.c_int\n _cusolver.cusolverDnCreate.argtypes = [ctypes.POINTER(ctypes.c_void_p)]\n\n status = _cusolver.cusolverDnCreate(ctypes.byref(handle))\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnCreate failed with status {status}\")\n\n return handle\n\n\ndef free_cusolver_handle(\n handle\n ):\n \"\"\"\n Free resources associated with a cuSolver handle.\n \"\"\"\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnDestroy.restype = ctypes.c_int\n _cusolver.cusolverDnDestroy.argtypes = [ctypes.c_void_p]\n\n status = _cusolver.cusolverDnDestroy(handle)\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnDestroy failed with status {status}\")\n\n\ndef set_cublas_stream(","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.free_cusolver_handle","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.free_cusolver_handle#L204-L218","kind":"function","name":"free_cusolver_handle","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":204,"end_line":218,"context_start_line":184,"context_end_line":238,"code":"\n\ndef make_cusolver_handle():\n \"\"\"\n Make a cuSolver handle via the CUDA C API.\n \"\"\"\n handle = ctypes.c_void_p()\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnCreate.restype = ctypes.c_int\n _cusolver.cusolverDnCreate.argtypes = [ctypes.POINTER(ctypes.c_void_p)]\n\n status = _cusolver.cusolverDnCreate(ctypes.byref(handle))\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnCreate failed with status {status}\")\n\n return handle\n\n\ndef free_cusolver_handle(\n handle\n ):\n \"\"\"\n Free resources associated with a cuSolver handle.\n \"\"\"\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnDestroy.restype = ctypes.c_int\n _cusolver.cusolverDnDestroy.argtypes = [ctypes.c_void_p]\n\n status = _cusolver.cusolverDnDestroy(handle)\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnDestroy failed with status {status}\")\n\n\ndef set_cublas_stream(\n *,\n handle,\n stream,\n ):\n \"\"\"\n Set the active stream for a given cuBLAS handle\n \"\"\"\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasSetStream_v2.restype = ctypes.c_int\n _cublas.cublasSetStream_v2.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n\n status = _cublas.cublasSetStream_v2(handle, stream)\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasSetStream failed with status {status}\")\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.set_cublas_stream","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.set_cublas_stream#L221-L237","kind":"function","name":"set_cublas_stream","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":221,"end_line":237,"context_start_line":201,"context_end_line":257,"code":" return handle\n\n\ndef free_cusolver_handle(\n handle\n ):\n \"\"\"\n Free resources associated with a cuSolver handle.\n \"\"\"\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnDestroy.restype = ctypes.c_int\n _cusolver.cusolverDnDestroy.argtypes = [ctypes.c_void_p]\n\n status = _cusolver.cusolverDnDestroy(handle)\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnDestroy failed with status {status}\")\n\n\ndef set_cublas_stream(\n *,\n handle,\n stream,\n ):\n \"\"\"\n Set the active stream for a given cuBLAS handle\n \"\"\"\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasSetStream_v2.restype = ctypes.c_int\n _cublas.cublasSetStream_v2.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n\n status = _cublas.cublasSetStream_v2(handle, stream)\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasSetStream failed with status {status}\")\n\n\ndef set_cusolver_stream(\n *,\n handle,\n stream,\n ):\n \"\"\"\n Set the stream for a given cuSolver handle.\n \"\"\"\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnSetStream.restype = ctypes.c_int\n _cusolver.cusolverDnSetStream.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n\n status = _cusolver.cusolverDnSetStream(handle, stream)\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnSetStream failed with status {status}\")\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.set_cusolver_stream","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.set_cusolver_stream#L240-L256","kind":"function","name":"set_cusolver_stream","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":240,"end_line":256,"context_start_line":220,"context_end_line":276,"code":"\ndef set_cublas_stream(\n *,\n handle,\n stream,\n ):\n \"\"\"\n Set the active stream for a given cuBLAS handle\n \"\"\"\n\n CUBLAS_STATUS_SUCCESS = 0\n\n _cublas.cublasSetStream_v2.restype = ctypes.c_int\n _cublas.cublasSetStream_v2.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n\n status = _cublas.cublasSetStream_v2(handle, stream)\n if status != CUBLAS_STATUS_SUCCESS:\n raise RuntimeError(f\"cublasSetStream failed with status {status}\")\n\n\ndef set_cusolver_stream(\n *,\n handle,\n stream,\n ):\n \"\"\"\n Set the stream for a given cuSolver handle.\n \"\"\"\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnSetStream.restype = ctypes.c_int\n _cusolver.cusolverDnSetStream.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n\n status = _cusolver.cusolverDnSetStream(handle, stream)\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnSetStream failed with status {status}\")\n\n\nclass WorkspaceDescriptor:\n \"\"\"\n This helper function needs to implement the following C structure,\n and define a pointer method that returns a pointer to it.\n\n typedef struct {\n size_t hostBufferSizeInBytes; ///< Required size of host workspace buffer in bytes\n size_t deviceBufferSizeInBytes; ///< Required size of device workspace buffer in bytes\n } cuestWorkspaceDescriptor_t;\n\n This implementation uses Numpy, as the ctypes.data member provides a\n convenient way to access a pointer to the object\n \"\"\"\n\n def __init__(\n self,\n *,\n host_buffer_size_in_bytes = 0,","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.WorkspaceDescriptor","uri":"program://CUDALibrarySamples/class/cuEST.python_examples.helpers.cuda_utils.WorkspaceDescriptor#L259-L300","kind":"class","name":"WorkspaceDescriptor","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":259,"end_line":300,"context_start_line":239,"context_end_line":320,"code":"\ndef set_cusolver_stream(\n *,\n handle,\n stream,\n ):\n \"\"\"\n Set the stream for a given cuSolver handle.\n \"\"\"\n\n CUSOLVER_STATUS_SUCCESS = 0\n\n _cusolver.cusolverDnSetStream.restype = ctypes.c_int\n _cusolver.cusolverDnSetStream.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n\n status = _cusolver.cusolverDnSetStream(handle, stream)\n if status != CUSOLVER_STATUS_SUCCESS:\n raise RuntimeError(f\"cusolverDnSetStream failed with status {status}\")\n\n\nclass WorkspaceDescriptor:\n \"\"\"\n This helper function needs to implement the following C structure,\n and define a pointer method that returns a pointer to it.\n\n typedef struct {\n size_t hostBufferSizeInBytes; ///< Required size of host workspace buffer in bytes\n size_t deviceBufferSizeInBytes; ///< Required size of device workspace buffer in bytes\n } cuestWorkspaceDescriptor_t;\n\n This implementation uses Numpy, as the ctypes.data member provides a\n convenient way to access a pointer to the object\n \"\"\"\n\n def __init__(\n self,\n *,\n host_buffer_size_in_bytes = 0,\n device_buffer_size_in_bytes = 0,\n ):\n\n _workspace_descriptor_dtype = np.dtype([\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n self.struct = np.empty(1, dtype=_workspace_descriptor_dtype)\n self.struct['deviceBufferSizeInBytes'] = device_buffer_size_in_bytes\n self.struct['hostBufferSizeInBytes'] = host_buffer_size_in_bytes\n\n def __str__(\n self,\n ):\n\n host_size = self.struct['hostBufferSizeInBytes'].item()\n device_size = self.struct['deviceBufferSizeInBytes'].item()\n return f'host buffer size = {host_size} bytes, device buffer size = {device_size} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n\nclass Workspace:\n \"\"\"\n This helper function needs to implement the following C structure,\n and define a pointer method that returns a pointer to it.\n\n typedef struct {\n uintptr_t hostBuffer; ///< Opaque pointer to host-side workspace buffer\n size_t hostBufferSizeInBytes; ///< Size of host workspace in bytes\n uintptr_t deviceBuffer; ///< Opaque pointer to device-side (GPU) workspace buffer\n size_t deviceBufferSizeInBytes; ///< Size of device workspace in bytes\n } cuestWorkspace_t;\n\n This implementation uses Numpy, as the ctypes.data member provides a\n convenient way to access a pointer to the object\n \"\"\"\n def __init__(\n self,\n *,\n workspaceDescriptor,","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.Workspace","uri":"program://CUDALibrarySamples/class/cuEST.python_examples.helpers.cuda_utils.Workspace#L302-L363","kind":"class","name":"Workspace","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":302,"end_line":363,"context_start_line":282,"context_end_line":364,"code":" (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n self.struct = np.empty(1, dtype=_workspace_descriptor_dtype)\n self.struct['deviceBufferSizeInBytes'] = device_buffer_size_in_bytes\n self.struct['hostBufferSizeInBytes'] = host_buffer_size_in_bytes\n\n def __str__(\n self,\n ):\n\n host_size = self.struct['hostBufferSizeInBytes'].item()\n device_size = self.struct['deviceBufferSizeInBytes'].item()\n return f'host buffer size = {host_size} bytes, device buffer size = {device_size} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n\nclass Workspace:\n \"\"\"\n This helper function needs to implement the following C structure,\n and define a pointer method that returns a pointer to it.\n\n typedef struct {\n uintptr_t hostBuffer; ///< Opaque pointer to host-side workspace buffer\n size_t hostBufferSizeInBytes; ///< Size of host workspace in bytes\n uintptr_t deviceBuffer; ///< Opaque pointer to device-side (GPU) workspace buffer\n size_t deviceBufferSizeInBytes; ///< Size of device workspace in bytes\n } cuestWorkspace_t;\n\n This implementation uses Numpy, as the ctypes.data member provides a\n convenient way to access a pointer to the object\n \"\"\"\n def __init__(\n self,\n *,\n workspaceDescriptor,\n ):\n _workspace_dtype = np.dtype([\n (\"hostBuffer\", np.uintp, ),\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBuffer\", np.uintp, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n host_buffer_size_in_bytes = workspaceDescriptor.struct['hostBufferSizeInBytes'].item()\n device_buffer_size_in_bytes = workspaceDescriptor.struct['deviceBufferSizeInBytes'].item()\n\n self.struct = np.empty(1, dtype=_workspace_dtype)\n self.struct['deviceBufferSizeInBytes'] = device_buffer_size_in_bytes\n self.struct['hostBufferSizeInBytes'] = host_buffer_size_in_bytes\n\n if device_buffer_size_in_bytes:\n ret, pointer = cuda.cudaMalloc(device_buffer_size_in_bytes)\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Failed to allocate workspace\", ret)\n self.struct['deviceBuffer'] = pointer\n else:\n self.struct['deviceBuffer'] = 0\n\n if host_buffer_size_in_bytes:\n self.cpu_memory = np.zeros(host_buffer_size_in_bytes, dtype=np.int8)\n self.struct['hostBuffer'] = self.cpu_memory.ctypes.data\n else:\n self.struct['hostBuffer'] = 0\n self.cpu_memory = None\n\n def __del__(\n self,\n ):\n\n if self.struct['deviceBuffer']:\n ret = cuda.cudaFree(self.struct['deviceBuffer'].item())\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to deallocate workspace:\", ret[0])\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.__init__","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.__init__#L317-L350","kind":"function","name":"__init__","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":317,"end_line":350,"context_start_line":297,"context_end_line":364,"code":"\n @property\n def pointer(self):\n return self.struct.ctypes.data\n\nclass Workspace:\n \"\"\"\n This helper function needs to implement the following C structure,\n and define a pointer method that returns a pointer to it.\n\n typedef struct {\n uintptr_t hostBuffer; ///< Opaque pointer to host-side workspace buffer\n size_t hostBufferSizeInBytes; ///< Size of host workspace in bytes\n uintptr_t deviceBuffer; ///< Opaque pointer to device-side (GPU) workspace buffer\n size_t deviceBufferSizeInBytes; ///< Size of device workspace in bytes\n } cuestWorkspace_t;\n\n This implementation uses Numpy, as the ctypes.data member provides a\n convenient way to access a pointer to the object\n \"\"\"\n def __init__(\n self,\n *,\n workspaceDescriptor,\n ):\n _workspace_dtype = np.dtype([\n (\"hostBuffer\", np.uintp, ),\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBuffer\", np.uintp, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n host_buffer_size_in_bytes = workspaceDescriptor.struct['hostBufferSizeInBytes'].item()\n device_buffer_size_in_bytes = workspaceDescriptor.struct['deviceBufferSizeInBytes'].item()\n\n self.struct = np.empty(1, dtype=_workspace_dtype)\n self.struct['deviceBufferSizeInBytes'] = device_buffer_size_in_bytes\n self.struct['hostBufferSizeInBytes'] = host_buffer_size_in_bytes\n\n if device_buffer_size_in_bytes:\n ret, pointer = cuda.cudaMalloc(device_buffer_size_in_bytes)\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Failed to allocate workspace\", ret)\n self.struct['deviceBuffer'] = pointer\n else:\n self.struct['deviceBuffer'] = 0\n\n if host_buffer_size_in_bytes:\n self.cpu_memory = np.zeros(host_buffer_size_in_bytes, dtype=np.int8)\n self.struct['hostBuffer'] = self.cpu_memory.ctypes.data\n else:\n self.struct['hostBuffer'] = 0\n self.cpu_memory = None\n\n def __del__(\n self,\n ):\n\n if self.struct['deviceBuffer']:\n ret = cuda.cudaFree(self.struct['deviceBuffer'].item())\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to deallocate workspace:\", ret[0])\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.__str__","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.__str__#L290-L296","kind":"function","name":"__str__","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":290,"end_line":296,"context_start_line":270,"context_end_line":316,"code":" convenient way to access a pointer to the object\n \"\"\"\n\n def __init__(\n self,\n *,\n host_buffer_size_in_bytes = 0,\n device_buffer_size_in_bytes = 0,\n ):\n\n _workspace_descriptor_dtype = np.dtype([\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n self.struct = np.empty(1, dtype=_workspace_descriptor_dtype)\n self.struct['deviceBufferSizeInBytes'] = device_buffer_size_in_bytes\n self.struct['hostBufferSizeInBytes'] = host_buffer_size_in_bytes\n\n def __str__(\n self,\n ):\n\n host_size = self.struct['hostBufferSizeInBytes'].item()\n device_size = self.struct['deviceBufferSizeInBytes'].item()\n return f'host buffer size = {host_size} bytes, device buffer size = {device_size} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n\nclass Workspace:\n \"\"\"\n This helper function needs to implement the following C structure,\n and define a pointer method that returns a pointer to it.\n\n typedef struct {\n uintptr_t hostBuffer; ///< Opaque pointer to host-side workspace buffer\n size_t hostBufferSizeInBytes; ///< Size of host workspace in bytes\n uintptr_t deviceBuffer; ///< Opaque pointer to device-side (GPU) workspace buffer\n size_t deviceBufferSizeInBytes; ///< Size of device workspace in bytes\n } cuestWorkspace_t;\n\n This implementation uses Numpy, as the ctypes.data member provides a\n convenient way to access a pointer to the object\n \"\"\"","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.pointer","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.pointer#L362-L363","kind":"function","name":"pointer","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":362,"end_line":363,"context_start_line":342,"context_end_line":364,"code":" else:\n self.struct['deviceBuffer'] = 0\n\n if host_buffer_size_in_bytes:\n self.cpu_memory = np.zeros(host_buffer_size_in_bytes, dtype=np.int8)\n self.struct['hostBuffer'] = self.cpu_memory.ctypes.data\n else:\n self.struct['hostBuffer'] = 0\n self.cpu_memory = None\n\n def __del__(\n self,\n ):\n\n if self.struct['deviceBuffer']:\n ret = cuda.cudaFree(self.struct['deviceBuffer'].item())\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to deallocate workspace:\", ret[0])\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.helpers.cuda_utils.__del__","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.helpers.cuda_utils.__del__#L352-L359","kind":"function","name":"__del__","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":352,"end_line":359,"context_start_line":332,"context_end_line":364,"code":"\n self.struct = np.empty(1, dtype=_workspace_dtype)\n self.struct['deviceBufferSizeInBytes'] = device_buffer_size_in_bytes\n self.struct['hostBufferSizeInBytes'] = host_buffer_size_in_bytes\n\n if device_buffer_size_in_bytes:\n ret, pointer = cuda.cudaMalloc(device_buffer_size_in_bytes)\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Failed to allocate workspace\", ret)\n self.struct['deviceBuffer'] = pointer\n else:\n self.struct['deviceBuffer'] = 0\n\n if host_buffer_size_in_bytes:\n self.cpu_memory = np.zeros(host_buffer_size_in_bytes, dtype=np.int8)\n self.struct['hostBuffer'] = self.cpu_memory.ctypes.data\n else:\n self.struct['hostBuffer'] = 0\n self.cpu_memory = None\n\n def __del__(\n self,\n ):\n\n if self.struct['deviceBuffer']:\n ret = cuda.cudaFree(self.struct['deviceBuffer'].item())\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to deallocate workspace:\", ret[0])\n\n @property\n def pointer(self):\n return self.struct.ctypes.data\n","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.2_one_electron_integrals.one_electron_gradients.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.2_one_electron_integrals.one_electron_gradients.run#L1-L508","kind":"module","name":"cuEST.python_examples.2_one_electron_integrals.one_electron_gradients.run","path":"cuEST/python_examples/2_one_electron_integrals/one_electron_gradients/run.py","language":"python","start_line":1,"end_line":508,"context_start_line":1,"context_end_line":508,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Set From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n aobasis_handle = ce.cuestAOBasisHandle()\n\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build One Electron Integral Plan <= #\n\n oeintplan_handle = ce.cuestOEIntPlanHandle()\n oeintplan_parameters = ce.cuestOEIntPlanParameters()\n\n cuest_check('Create OEIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n outParameters=oeintplan_parameters,\n )\n )\n\n cuest_check('Create OEIntPlan Workspace Query',\n ce.cuestOEIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n pairList=aopairlist_handle,\n parameters=oeintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=oeintplan_handle,\n )\n )\n\n oeintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n oeintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create OEIntPlan',\n ce.cuestOEIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n pairList=aopairlist_handle,\n parameters=oeintplan_parameters,\n persistentWorkspace=oeintplan_persistent_workspace.pointer,\n temporaryWorkspace=oeintplan_temporary_workspace.pointer,\n outPlan=oeintplan_handle,\n )\n )\n\n del oeintplan_temporary_workspace\n\n cuest_check('Destroy OEIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n parameters=oeintplan_parameters,\n )\n )\n\n # => Fake Density Matrix <= #\n\n densitymatrix_device_handle = ce.Pointer()\n densitymatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n densitymatrix_device_handle.value = np.intp(densitymatrix_device_pointer)\n densitymatrix_host_array = np.random.normal(size=(nao, nao)).astype(np.double)\n densitymatrix_host_array = np.ravel(densitymatrix_host_array + densitymatrix_host_array.T)\n cuda_memcpy_htod(\n device_pointer=densitymatrix_device_pointer,\n host_pointer=densitymatrix_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n # => Overlap Gradients <= #\n\n compute_overlap_gradient_parameters = ce.cuestOverlapDerivativeComputeParameters()\n cuest_check('Create Overlap Grad Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_OVERLAPDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=compute_overlap_gradient_parameters,\n )\n )\n\n overlapgrad_device_handle = ce.Pointer()\n cuest_check('Compute Overlap Grad Workspace Query',\n ce.cuestOverlapDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_overlap_gradient_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=densitymatrix_device_handle,\n outGradient=overlapgrad_device_handle,\n )\n )\n\n overlapgrad_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n overlapgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * len(symbols) \n )\n overlapgrad_device_handle.value = np.intp(overlapgrad_device_pointer)\n\n cuest_check('Compute Overlap Derivative',\n ce.cuestOverlapDerivativeCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_overlap_gradient_parameters,\n temporaryWorkspace=overlapgrad_temporary_workspace.pointer,\n densityMatrix=densitymatrix_device_handle,\n outGradient=overlapgrad_device_handle,\n )\n )\n\n del overlapgrad_temporary_workspace\n cuest_check('Destroy Overlap Grad Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_OVERLAPDERIVATIVECOMPUTE_PARAMETERS,\n parameters=compute_overlap_gradient_parameters,\n )\n )\n\n overlapgrad_host_array = np.empty(\n (3 * len(symbols),),\n dtype=np.double\n )\n\n overlapgrad_host_handle = ce.Pointer(overlapgrad_host_array.ctypes.data)\n cuda_memcpy_dtoh(\n host_pointer=overlapgrad_host_array.ctypes.data,\n device_pointer=overlapgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * len(symbols),\n )\n\n cuda_free(\n array=overlapgrad_device_pointer\n )\n\n # => Kinetic Gradients <= #\n\n compute_kinetic_gradient_parameters = ce.cuestKineticDerivativeComputeParameters()\n cuest_check('Create Kinetic Grad Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_KINETICDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=compute_kinetic_gradient_parameters,\n )\n )\n\n kineticgrad_device_handle = ce.Pointer()\n cuest_check('Compute Kinetic Grad Workspace Query',\n ce.cuestKineticDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_kinetic_gradient_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=densitymatrix_device_handle,\n outGradient=kineticgrad_device_handle,\n )\n )\n\n kineticgrad_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n kineticgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * len(symbols) \n )\n kineticgrad_device_handle.value = np.intp(kineticgrad_device_pointer)\n\n cuest_check('Compute Kinetic Derivative',\n ce.cuestKineticDerivativeCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_kinetic_gradient_parameters,\n temporaryWorkspace=kineticgrad_temporary_workspace.pointer,\n densityMatrix=densitymatrix_device_handle,\n outGradient=kineticgrad_device_handle,\n )\n )\n\n del kineticgrad_temporary_workspace\n cuest_check('Destroy Kinetic Grad Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_KINETICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=compute_kinetic_gradient_parameters,\n )\n )\n\n kineticgrad_host_array = np.empty(\n (3 * len(symbols),),\n dtype=np.double\n )\n\n kineticgrad_host_handle = ce.Pointer(kineticgrad_host_array.ctypes.data)\n cuda_memcpy_dtoh(\n host_pointer=kineticgrad_host_array.ctypes.data,\n device_pointer=kineticgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * len(symbols),\n )\n\n cuda_free(\n array=kineticgrad_device_pointer\n )\n\n # => Cleanup <= #\n\n cuda_free(\n array=densitymatrix_device_pointer\n )\n\n cuest_check('Destroy OEIntPlan',\n ce.cuestOEIntPlanDestroy(\n handle=oeintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n handle=aopairlist_handle,\n )\n )\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n del oeintplan_persistent_workspace\n del aopairlist_persistent_workspace\n del aobasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Run using XYZ and GBS files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"The file with molecular coordinates (Angstrom) in basic xyz format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"The basis set file in G94/Psi4 GBS format.\"\n )\n\n args = parser.parse_args()\n\n run(\n xyz_filename=args.xyz_filename,\n gbs_filename=args.gbs_filename,\n )\n","source_hash":"f8cbbc25effd43edf23493bb76f0d9961372dd0a996ff00617ff32b81bcd3664","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.2_one_electron_integrals.one_electron_gradients.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.2_one_electron_integrals.one_electron_gradients.run.run#L29-L485","kind":"function","name":"run","path":"cuEST/python_examples/2_one_electron_integrals/one_electron_gradients/run.py","language":"python","start_line":29,"end_line":485,"context_start_line":9,"context_end_line":505,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Set From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n aobasis_handle = ce.cuestAOBasisHandle()\n\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build One Electron Integral Plan <= #\n\n oeintplan_handle = ce.cuestOEIntPlanHandle()\n oeintplan_parameters = ce.cuestOEIntPlanParameters()\n\n cuest_check('Create OEIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n outParameters=oeintplan_parameters,\n )\n )\n\n cuest_check('Create OEIntPlan Workspace Query',\n ce.cuestOEIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n pairList=aopairlist_handle,\n parameters=oeintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=oeintplan_handle,\n )\n )\n\n oeintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n oeintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create OEIntPlan',\n ce.cuestOEIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n pairList=aopairlist_handle,\n parameters=oeintplan_parameters,\n persistentWorkspace=oeintplan_persistent_workspace.pointer,\n temporaryWorkspace=oeintplan_temporary_workspace.pointer,\n outPlan=oeintplan_handle,\n )\n )\n\n del oeintplan_temporary_workspace\n\n cuest_check('Destroy OEIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n parameters=oeintplan_parameters,\n )\n )\n\n # => Fake Density Matrix <= #\n\n densitymatrix_device_handle = ce.Pointer()\n densitymatrix_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n densitymatrix_device_handle.value = np.intp(densitymatrix_device_pointer)\n densitymatrix_host_array = np.random.normal(size=(nao, nao)).astype(np.double)\n densitymatrix_host_array = np.ravel(densitymatrix_host_array + densitymatrix_host_array.T)\n cuda_memcpy_htod(\n device_pointer=densitymatrix_device_pointer,\n host_pointer=densitymatrix_host_array.ctypes.data,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n # => Overlap Gradients <= #\n\n compute_overlap_gradient_parameters = ce.cuestOverlapDerivativeComputeParameters()\n cuest_check('Create Overlap Grad Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_OVERLAPDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=compute_overlap_gradient_parameters,\n )\n )\n\n overlapgrad_device_handle = ce.Pointer()\n cuest_check('Compute Overlap Grad Workspace Query',\n ce.cuestOverlapDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_overlap_gradient_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=densitymatrix_device_handle,\n outGradient=overlapgrad_device_handle,\n )\n )\n\n overlapgrad_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n overlapgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * len(symbols) \n )\n overlapgrad_device_handle.value = np.intp(overlapgrad_device_pointer)\n\n cuest_check('Compute Overlap Derivative',\n ce.cuestOverlapDerivativeCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_overlap_gradient_parameters,\n temporaryWorkspace=overlapgrad_temporary_workspace.pointer,\n densityMatrix=densitymatrix_device_handle,\n outGradient=overlapgrad_device_handle,\n )\n )\n\n del overlapgrad_temporary_workspace\n cuest_check('Destroy Overlap Grad Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_OVERLAPDERIVATIVECOMPUTE_PARAMETERS,\n parameters=compute_overlap_gradient_parameters,\n )\n )\n\n overlapgrad_host_array = np.empty(\n (3 * len(symbols),),\n dtype=np.double\n )\n\n overlapgrad_host_handle = ce.Pointer(overlapgrad_host_array.ctypes.data)\n cuda_memcpy_dtoh(\n host_pointer=overlapgrad_host_array.ctypes.data,\n device_pointer=overlapgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * len(symbols),\n )\n\n cuda_free(\n array=overlapgrad_device_pointer\n )\n\n # => Kinetic Gradients <= #\n\n compute_kinetic_gradient_parameters = ce.cuestKineticDerivativeComputeParameters()\n cuest_check('Create Kinetic Grad Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_KINETICDERIVATIVECOMPUTE_PARAMETERS,\n outParameters=compute_kinetic_gradient_parameters,\n )\n )\n\n kineticgrad_device_handle = ce.Pointer()\n cuest_check('Compute Kinetic Grad Workspace Query',\n ce.cuestKineticDerivativeComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_kinetic_gradient_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=densitymatrix_device_handle,\n outGradient=kineticgrad_device_handle,\n )\n )\n\n kineticgrad_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n kineticgrad_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * 3 * len(symbols) \n )\n kineticgrad_device_handle.value = np.intp(kineticgrad_device_pointer)\n\n cuest_check('Compute Kinetic Derivative',\n ce.cuestKineticDerivativeCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_kinetic_gradient_parameters,\n temporaryWorkspace=kineticgrad_temporary_workspace.pointer,\n densityMatrix=densitymatrix_device_handle,\n outGradient=kineticgrad_device_handle,\n )\n )\n\n del kineticgrad_temporary_workspace\n cuest_check('Destroy Kinetic Grad Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_KINETICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=compute_kinetic_gradient_parameters,\n )\n )\n\n kineticgrad_host_array = np.empty(\n (3 * len(symbols),),\n dtype=np.double\n )\n\n kineticgrad_host_handle = ce.Pointer(kineticgrad_host_array.ctypes.data)\n cuda_memcpy_dtoh(\n host_pointer=kineticgrad_host_array.ctypes.data,\n device_pointer=kineticgrad_device_pointer,\n size_in_bytes=sizeof_double * 3 * len(symbols),\n )\n\n cuda_free(\n array=kineticgrad_device_pointer\n )\n\n # => Cleanup <= #\n\n cuda_free(\n array=densitymatrix_device_pointer\n )\n\n cuest_check('Destroy OEIntPlan',\n ce.cuestOEIntPlanDestroy(\n handle=oeintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n handle=aopairlist_handle,\n )\n )\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n del oeintplan_persistent_workspace\n del aopairlist_persistent_workspace\n del aobasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Run using XYZ and GBS files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"The file with molecular coordinates (Angstrom) in basic xyz format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"The basis set file in G94/Psi4 GBS format.\"\n )\n\n args = parser.parse_args()\n\n run(\n xyz_filename=args.xyz_filename,","source_hash":"f8cbbc25effd43edf23493bb76f0d9961372dd0a996ff00617ff32b81bcd3664","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.2_one_electron_integrals.one_electron_gradients.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.2_one_electron_integrals.one_electron_gradients.run.cuest_check#L53-L60","kind":"function","name":"cuest_check","path":"cuEST/python_examples/2_one_electron_integrals/one_electron_gradients/run.py","language":"python","start_line":53,"end_line":60,"context_start_line":33,"context_end_line":80,"code":" ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(","source_hash":"f8cbbc25effd43edf23493bb76f0d9961372dd0a996ff00617ff32b81bcd3664","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.2_one_electron_integrals.one_electron_integrals.run","uri":"program://CUDALibrarySamples/module/cuEST.python_examples.2_one_electron_integrals.one_electron_integrals.run#L1-L594","kind":"module","name":"cuEST.python_examples.2_one_electron_integrals.one_electron_integrals.run","path":"cuEST/python_examples/2_one_electron_integrals/one_electron_integrals/run.py","language":"python","start_line":1,"end_line":594,"context_start_line":1,"context_end_line":594,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Set From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n aobasis_handle = ce.cuestAOBasisHandle()\n\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build One Electron Integral Plan <= #\n\n oeintplan_handle = ce.cuestOEIntPlanHandle()\n oeintplan_parameters = ce.cuestOEIntPlanParameters()\n\n cuest_check('Create OEIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n outParameters=oeintplan_parameters,\n )\n )\n\n cuest_check('Create OEIntPlan Workspace Query',\n ce.cuestOEIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n pairList=aopairlist_handle,\n parameters=oeintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=oeintplan_handle,\n )\n )\n\n oeintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n oeintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create OEIntPlan',\n ce.cuestOEIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n pairList=aopairlist_handle,\n parameters=oeintplan_parameters,\n persistentWorkspace=oeintplan_persistent_workspace.pointer,\n temporaryWorkspace=oeintplan_temporary_workspace.pointer,\n outPlan=oeintplan_handle,\n )\n )\n\n del oeintplan_temporary_workspace\n\n cuest_check('Destroy OEIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n parameters=oeintplan_parameters,\n )\n )\n\n # => Overlap Integrals <= #\n\n overlapint_device_handle = ce.Pointer()\n compute_overlap_parameters = ce.cuestOverlapComputeParameters()\n cuest_check('Create Overlap Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_OVERLAPCOMPUTE_PARAMETERS,\n outParameters=compute_overlap_parameters,\n )\n )\n\n # Find Memory Requirements\n cuest_check('Compute Overlap Ints Workspace Query',\n ce.cuestOverlapComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_overlap_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outSMatrix=overlapint_device_handle,\n )\n )\n\n overlapint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n overlapint_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n overlapint_device_handle.value = np.intp(overlapint_device_pointer)\n\n # Compute Integrals\n cuest_check('Compute Overlap Ints',\n ce.cuestOverlapCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_overlap_parameters,\n temporaryWorkspace=overlapint_temporary_workspace.pointer,\n outSMatrix=overlapint_device_handle,\n )\n )\n\n del overlapint_temporary_workspace\n\n cuest_check('Destroy Overlap Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_OVERLAPCOMPUTE_PARAMETERS,\n parameters=compute_overlap_parameters,\n )\n )\n\n overlapint_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=overlapint_host_array.ctypes.data,\n device_pointer=overlapint_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=overlapint_device_pointer\n )\n\n # => Kinetic Integrals <= #\n\n kineticint_device_handle = ce.Pointer()\n compute_kinetic_parameters = ce.cuestKineticComputeParameters()\n cuest_check('Create Kinetic Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_KINETICCOMPUTE_PARAMETERS,\n outParameters=compute_kinetic_parameters,\n )\n )\n\n # Find Memory Requirements\n cuest_check('Compute Kinetic Ints Workspace Query',\n ce.cuestKineticComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_kinetic_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outTMatrix=kineticint_device_handle,\n )\n )\n\n kineticint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n kineticint_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n kineticint_device_handle.value = np.intp(kineticint_device_pointer)\n\n # Compute Integrals\n cuest_check('Compute Kinetic Ints',\n ce.cuestKineticCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_kinetic_parameters,\n temporaryWorkspace=kineticint_temporary_workspace.pointer,\n outTMatrix=kineticint_device_handle,\n )\n )\n\n del kineticint_temporary_workspace\n\n cuest_check('Destroy Kinetic Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_KINETICCOMPUTE_PARAMETERS,\n parameters=compute_kinetic_parameters,\n )\n )\n\n kineticint_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=kineticint_host_array.ctypes.data,\n device_pointer=kineticint_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=kineticint_device_pointer\n )\n\n # => Potential Integrals <= #\n\n potentialint_device_handle = ce.Pointer()\n\n # Move the position and (negated) charges of the atoms to the GPU\n xyzs_device_handle = ce.Pointer()\n xyzs = np.array(xyzs)\n xyzs_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * len(xyzs)\n )\n xyzs_device_handle.value = np.intp(xyzs_device_pointer)\n cuda_memcpy_htod(\n device_pointer=xyzs_device_pointer,\n host_pointer=xyzs.ctypes.data,\n size_in_bytes=sizeof_double * len(xyzs),\n )\n\n # The integral compute in cuEST are electron repulsion integrals but we're intersted\n # in a nucleus in the ket here, so the Z values have been scaled by -1 in the parser\n Zs_device_handle = ce.Pointer()\n Zs = np.array(Zs)\n Zs_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * len(Zs)\n )\n Zs_device_handle.value = np.intp(Zs_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Zs_device_pointer,\n host_pointer=Zs.ctypes.data,\n size_in_bytes=sizeof_double * len(Zs),\n )\n\n potential_compute_parameters = ce.cuestPotentialComputeParameters()\n cuest_check('Create Potential Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_POTENTIALCOMPUTE_PARAMETERS,\n outParameters=potential_compute_parameters,\n )\n )\n\n # Find Memory Requirements\n cuest_check('Compute potential Ints Workspace Query',\n ce.cuestPotentialComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=potential_compute_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numCharges=len(symbols),\n xyz=xyzs_device_handle,\n q=Zs_device_handle,\n outVMatrix=potentialint_device_handle,\n )\n )\n\n potentialint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n potentialint_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n potentialint_device_handle.value = np.intp(potentialint_device_pointer)\n\n # Compute Integrals\n cuest_check('Compute potential Ints',\n ce.cuestPotentialCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=potential_compute_parameters,\n temporaryWorkspace=potentialint_temporary_workspace.pointer,\n numCharges=len(symbols),\n xyz=xyzs_device_handle,\n q=Zs_device_handle,\n outVMatrix=potentialint_device_handle,\n )\n )\n cuda_free(\n array=xyzs_device_pointer,\n )\n cuda_free(\n array=Zs_device_pointer,\n )\n\n del potentialint_temporary_workspace\n\n cuest_check('Destroy Potential Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_POTENTIALCOMPUTE_PARAMETERS,\n parameters=potential_compute_parameters,\n )\n )\n\n potentialint_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=potentialint_host_array.ctypes.data,\n device_pointer=potentialint_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=potentialint_device_pointer\n )\n\n\n # => Cleanup <= #\n\n cuest_check('Destroy OEIntPlan',\n ce.cuestOEIntPlanDestroy(\n handle=oeintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n handle=aopairlist_handle,\n )\n )\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n del oeintplan_persistent_workspace\n del aopairlist_persistent_workspace\n del aobasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Run using XYZ and GBS files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"The file with molecular coordinates (Angstrom) in basic xyz format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"The basis set file in G94/Psi4 GBS format.\"\n )\n\n args = parser.parse_args()\n\n run(\n xyz_filename=args.xyz_filename,\n gbs_filename=args.gbs_filename,\n )\n","source_hash":"7ec86e183dd48e9b686e1b68eb31372fa264804b170af9647e1dcb4b621914e7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.2_one_electron_integrals.one_electron_integrals.run.run","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.2_one_electron_integrals.one_electron_integrals.run.run#L29-L571","kind":"function","name":"run","path":"cuEST/python_examples/2_one_electron_integrals/one_electron_integrals/run.py","language":"python","start_line":29,"end_line":571,"context_start_line":9,"context_end_line":591,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))\nfrom helpers.cuda_utils import cuda_malloc, cuda_free, cuda_memcpy_dtoh, cuda_memcpy_htod, WorkspaceDescriptor, Workspace\nfrom helpers.utilities import normalize_shell_coefficients\nfrom helpers.parsers import simple_xyz_parser, simple_gbs_parser\n\ndef run(\n *,\n xyz_filename,\n gbs_filename,\n ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(\n parameters=cuest_handle_parameters,\n handle=cuest_handle,\n )\n )\n\n cuest_check('Destroy Handle Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n parameters=cuest_handle_parameters,\n )\n )\n\n aoshell_parameters = ce.cuestAOShellParameters()\n cuest_check('Create AO Shell Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n outParameters=aoshell_parameters,\n )\n )\n\n # => Build Gaussian Shells From Basis Parser Info <= #\n\n shells = []\n n_shells_per_atom = []\n shell_count = 1\n for atom_shells in shellinfo:\n n_shells_per_atom.append(len(atom_shells))\n for shell in atom_shells:\n L = shell['L']\n exponents = shell['exponents']\n raw_coefficients = shell['coefficients']\n normalized_coefficients = normalize_shell_coefficients(\n coefficients=raw_coefficients,\n exponents=exponents,\n L=L,\n normalization=shell['normalization'],\n )\n aoshell_handle = ce.cuestAOShellHandle()\n cuest_check(f'Create AO Shell {shell_count}',\n ce.cuestAOShellCreate(\n handle=cuest_handle,\n isPure=shell['is_pure'],\n L=L,\n numPrimitive=len(exponents),\n exponents=exponents,\n coefficients=normalized_coefficients,\n parameters=aoshell_parameters,\n outShell=aoshell_handle)\n )\n shells.append(aoshell_handle)\n shell_count += 1\n\n cuest_check('Destroy AO Shell Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n parameters=aoshell_parameters,\n )\n )\n\n # => Build Basis Set From Gaussian Shells <= #\n\n aobasis_parameters = ce.cuestAOBasisParameters()\n\n cuest_check('Create AO Basis Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n outParameters=aobasis_parameters,\n )\n )\n\n aobasis_handle = ce.cuestAOBasisHandle()\n\n cuest_check('Create AOBasis Workspace Query',\n ce.cuestAOBasisCreateWorkspaceQuery(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n aobasis_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aobasis_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOBasis',\n ce.cuestAOBasisCreate(\n handle=cuest_handle,\n numAtoms=len(symbols),\n numShellsPerAtom=n_shells_per_atom,\n shells=shells,\n parameters=aobasis_parameters,\n persistentWorkspace=aobasis_persistent_workspace.pointer,\n temporaryWorkspace=aobasis_temporary_workspace.pointer,\n outBasis=aobasis_handle,\n )\n )\n\n del aobasis_temporary_workspace\n\n for i, shell in enumerate(shells):\n cuest_check(f'Destroy AO Shell {i+1}',\n ce.cuestAOShellDestroy(\n handle=shell,\n )\n )\n aobasis_num_ao = ce.data_uint64_t()\n cuest_check('Query AO Basis Num AO',\n ce.cuestQuery(\n handle=cuest_handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=aobasis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=aobasis_num_ao,\n )\n )\n nao = aobasis_num_ao.value\n\n cuest_check('Destroy AO Basis Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n parameters=aobasis_parameters,\n )\n )\n\n # => Build Pair List <= #\n\n aopairlist_handle = ce.cuestAOPairListHandle()\n\n aopairlist_parameters = ce.cuestAOPairListParameters()\n\n cuest_check('Create AOPairList Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n outParameters=aopairlist_parameters,\n )\n )\n\n cuest_check('Create AOPairList Workspace Query',\n ce.cuestAOPairListCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n aopairlist_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n aopairlist_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create AOPairList',\n ce.cuestAOPairListCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n numAtoms=len(symbols),\n xyz=xyzs,\n thresholdPQ=threshold_pq,\n parameters=aopairlist_parameters,\n persistentWorkspace=aopairlist_persistent_workspace.pointer,\n temporaryWorkspace=aopairlist_temporary_workspace.pointer,\n outPairList=aopairlist_handle,\n )\n )\n\n del aopairlist_temporary_workspace\n\n cuest_check('Destroy AOPairList Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n parameters=aopairlist_parameters,\n )\n )\n\n # => Build One Electron Integral Plan <= #\n\n oeintplan_handle = ce.cuestOEIntPlanHandle()\n oeintplan_parameters = ce.cuestOEIntPlanParameters()\n\n cuest_check('Create OEIntPlan Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n outParameters=oeintplan_parameters,\n )\n )\n\n cuest_check('Create OEIntPlan Workspace Query',\n ce.cuestOEIntPlanCreateWorkspaceQuery(\n handle=cuest_handle,\n basis=aobasis_handle,\n pairList=aopairlist_handle,\n parameters=oeintplan_parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=oeintplan_handle,\n )\n )\n\n oeintplan_persistent_workspace = Workspace(workspaceDescriptor=persistent_workspace_descriptor)\n oeintplan_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n cuest_check('Create OEIntPlan',\n ce.cuestOEIntPlanCreate(\n handle=cuest_handle,\n basis=aobasis_handle,\n pairList=aopairlist_handle,\n parameters=oeintplan_parameters,\n persistentWorkspace=oeintplan_persistent_workspace.pointer,\n temporaryWorkspace=oeintplan_temporary_workspace.pointer,\n outPlan=oeintplan_handle,\n )\n )\n\n del oeintplan_temporary_workspace\n\n cuest_check('Destroy OEIntPlan Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n parameters=oeintplan_parameters,\n )\n )\n\n # => Overlap Integrals <= #\n\n overlapint_device_handle = ce.Pointer()\n compute_overlap_parameters = ce.cuestOverlapComputeParameters()\n cuest_check('Create Overlap Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_OVERLAPCOMPUTE_PARAMETERS,\n outParameters=compute_overlap_parameters,\n )\n )\n\n # Find Memory Requirements\n cuest_check('Compute Overlap Ints Workspace Query',\n ce.cuestOverlapComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_overlap_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outSMatrix=overlapint_device_handle,\n )\n )\n\n overlapint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n overlapint_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n overlapint_device_handle.value = np.intp(overlapint_device_pointer)\n\n # Compute Integrals\n cuest_check('Compute Overlap Ints',\n ce.cuestOverlapCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_overlap_parameters,\n temporaryWorkspace=overlapint_temporary_workspace.pointer,\n outSMatrix=overlapint_device_handle,\n )\n )\n\n del overlapint_temporary_workspace\n\n cuest_check('Destroy Overlap Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_OVERLAPCOMPUTE_PARAMETERS,\n parameters=compute_overlap_parameters,\n )\n )\n\n overlapint_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=overlapint_host_array.ctypes.data,\n device_pointer=overlapint_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=overlapint_device_pointer\n )\n\n # => Kinetic Integrals <= #\n\n kineticint_device_handle = ce.Pointer()\n compute_kinetic_parameters = ce.cuestKineticComputeParameters()\n cuest_check('Create Kinetic Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_KINETICCOMPUTE_PARAMETERS,\n outParameters=compute_kinetic_parameters,\n )\n )\n\n # Find Memory Requirements\n cuest_check('Compute Kinetic Ints Workspace Query',\n ce.cuestKineticComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_kinetic_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outTMatrix=kineticint_device_handle,\n )\n )\n\n kineticint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n kineticint_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n kineticint_device_handle.value = np.intp(kineticint_device_pointer)\n\n # Compute Integrals\n cuest_check('Compute Kinetic Ints',\n ce.cuestKineticCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=compute_kinetic_parameters,\n temporaryWorkspace=kineticint_temporary_workspace.pointer,\n outTMatrix=kineticint_device_handle,\n )\n )\n\n del kineticint_temporary_workspace\n\n cuest_check('Destroy Kinetic Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_KINETICCOMPUTE_PARAMETERS,\n parameters=compute_kinetic_parameters,\n )\n )\n\n kineticint_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=kineticint_host_array.ctypes.data,\n device_pointer=kineticint_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=kineticint_device_pointer\n )\n\n # => Potential Integrals <= #\n\n potentialint_device_handle = ce.Pointer()\n\n # Move the position and (negated) charges of the atoms to the GPU\n xyzs_device_handle = ce.Pointer()\n xyzs = np.array(xyzs)\n xyzs_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * len(xyzs)\n )\n xyzs_device_handle.value = np.intp(xyzs_device_pointer)\n cuda_memcpy_htod(\n device_pointer=xyzs_device_pointer,\n host_pointer=xyzs.ctypes.data,\n size_in_bytes=sizeof_double * len(xyzs),\n )\n\n # The integral compute in cuEST are electron repulsion integrals but we're intersted\n # in a nucleus in the ket here, so the Z values have been scaled by -1 in the parser\n Zs_device_handle = ce.Pointer()\n Zs = np.array(Zs)\n Zs_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * len(Zs)\n )\n Zs_device_handle.value = np.intp(Zs_device_pointer)\n cuda_memcpy_htod(\n device_pointer=Zs_device_pointer,\n host_pointer=Zs.ctypes.data,\n size_in_bytes=sizeof_double * len(Zs),\n )\n\n potential_compute_parameters = ce.cuestPotentialComputeParameters()\n cuest_check('Create Potential Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_POTENTIALCOMPUTE_PARAMETERS,\n outParameters=potential_compute_parameters,\n )\n )\n\n # Find Memory Requirements\n cuest_check('Compute potential Ints Workspace Query',\n ce.cuestPotentialComputeWorkspaceQuery(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=potential_compute_parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numCharges=len(symbols),\n xyz=xyzs_device_handle,\n q=Zs_device_handle,\n outVMatrix=potentialint_device_handle,\n )\n )\n\n potentialint_temporary_workspace = Workspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n potentialint_device_pointer = cuda_malloc(\n size_in_bytes=sizeof_double * nao**2\n )\n potentialint_device_handle.value = np.intp(potentialint_device_pointer)\n\n # Compute Integrals\n cuest_check('Compute potential Ints',\n ce.cuestPotentialCompute(\n handle=cuest_handle,\n plan=oeintplan_handle,\n parameters=potential_compute_parameters,\n temporaryWorkspace=potentialint_temporary_workspace.pointer,\n numCharges=len(symbols),\n xyz=xyzs_device_handle,\n q=Zs_device_handle,\n outVMatrix=potentialint_device_handle,\n )\n )\n cuda_free(\n array=xyzs_device_pointer,\n )\n cuda_free(\n array=Zs_device_pointer,\n )\n\n del potentialint_temporary_workspace\n\n cuest_check('Destroy Potential Params',\n ce.cuestParametersDestroy(\n parametersType=ce.CuestParametersType.CUEST_POTENTIALCOMPUTE_PARAMETERS,\n parameters=potential_compute_parameters,\n )\n )\n\n potentialint_host_array = np.empty(\n (nao * nao),\n dtype=np.double\n )\n\n cuda_memcpy_dtoh(\n host_pointer=potentialint_host_array.ctypes.data,\n device_pointer=potentialint_device_pointer,\n size_in_bytes=sizeof_double * nao**2,\n )\n\n cuda_free(\n array=potentialint_device_pointer\n )\n\n\n # => Cleanup <= #\n\n cuest_check('Destroy OEIntPlan',\n ce.cuestOEIntPlanDestroy(\n handle=oeintplan_handle,\n )\n )\n\n cuest_check('Destroy AOPairList',\n ce.cuestAOPairListDestroy(\n handle=aopairlist_handle,\n )\n )\n\n cuest_check('Destroy AOBasis',\n ce.cuestAOBasisDestroy(\n handle=aobasis_handle,\n )\n )\n\n del oeintplan_persistent_workspace\n del aopairlist_persistent_workspace\n del aobasis_persistent_workspace\n\n cuest_check('Destroy Cuest Handle',\n ce.cuestDestroy(\n handle=cuest_handle,\n )\n )\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=\"Run using XYZ and GBS files.\"\n )\n parser.add_argument(\n \"xyz_filename\",\n type=str,\n help=\"The file with molecular coordinates (Angstrom) in basic xyz format.\"\n )\n parser.add_argument(\n \"gbs_filename\",\n type=str,\n help=\"The basis set file in G94/Psi4 GBS format.\"\n )\n\n args = parser.parse_args()\n\n run(\n xyz_filename=args.xyz_filename,","source_hash":"7ec86e183dd48e9b686e1b68eb31372fa264804b170af9647e1dcb4b621914e7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.python_examples.2_one_electron_integrals.one_electron_integrals.run.cuest_check","uri":"program://CUDALibrarySamples/function/cuEST.python_examples.2_one_electron_integrals.one_electron_integrals.run.cuest_check#L53-L60","kind":"function","name":"cuest_check","path":"cuEST/python_examples/2_one_electron_integrals/one_electron_integrals/run.py","language":"python","start_line":53,"end_line":60,"context_start_line":33,"context_end_line":80,"code":" ):\n\n # => Parse User Input <= #\n\n symbols, xyzs, Zs = simple_xyz_parser(\n filename=xyz_filename,\n to_bohr_scale_factor=1.0 / 0.52917720859,\n )\n\n shellinfo = simple_gbs_parser(\n filename=gbs_filename,\n symbols=symbols,\n )\n # The screening threshold used to filter out insignificant shell pairs by their overlap\n threshold_pq = 1.0e-14\n\n sizeof_double = np.dtype('double').itemsize\n\n # => Set Up cuEST <= #\n\n def cuest_check(\n title,\n return_code\n ):\n \" A simple helper function to call cuEST functions and check the return code. \"\n\n if return_code != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError(f\"{title} failed with code {return_code}\")\n\n # These are user-provided functions that are responsible for allocating\n # host and device workspace arrays. We use \n persistent_workspace_descriptor = WorkspaceDescriptor()\n temporary_workspace_descriptor = WorkspaceDescriptor()\n\n cuest_handle_parameters = ce.cuestHandleParameters()\n\n cuest_check('Create Handle Params',\n ce.cuestParametersCreate(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n outParameters=cuest_handle_parameters,\n )\n )\n\n # Here we allow cuEST to use the default stream, cuBLAS, etc., but those\n # parameters should be set in the handle parameters before this call.\n cuest_handle = ce.cuestHandle()\n cuest_check('Create Cuest Handle',\n ce.cuestCreate(","source_hash":"7ec86e183dd48e9b686e1b68eb31372fa264804b170af9647e1dcb4b621914e7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.b3lyp1_grad_1.test","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.test.b3lyp1_grad_1.test#L1-L158","kind":"module","name":"cuEST.cuest_scf_examples.test.b3lyp1_grad_1.test","path":"cuEST/cuest_scf_examples/test/b3lyp1_grad_1/test.py","language":"python","start_line":1,"end_line":158,"context_start_line":1,"context_end_line":158,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='B3LYP1',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_b3lyp1():\n\n import numpy as np\n\n E2 = -1.7706120600238987E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0075339, -0.0084374, 0.0100722,],\n [ -0.0129560, 0.0085460, 0.0005812,],\n [ 0.0044460, 0.0022805, 0.0010485,],\n [ -0.0020780, -0.0035621, -0.0209380,],\n [ 0.0085310, 0.0155217, 0.0060141,],\n [ -0.0078534, -0.0143469, -0.0203861,],\n [ -0.0039985, 0.0014855, 0.0145814,],\n [ 0.0129959, -0.0260229, -0.0206831,],\n [ 0.0072781, 0.0073819, 0.0204639,],\n [ 0.0376327, -0.0016436, -0.0066890,],\n [ 0.0007142, 0.0060887, -0.0293362,],\n [ 0.0132803, -0.0171365, 0.0107301,],\n [ -0.0079049, 0.0167075, 0.0061632,],\n [ -0.0049003, -0.0178073, 0.0007884,],\n [ -0.0050590, 0.0118507, 0.0137120,],\n [ 0.0172510, -0.0082200, -0.0076180,],\n [ 0.0083788, -0.0033765, -0.0019021,],\n [ -0.0035890, 0.0030032, 0.0026220,],\n [ 0.0043617, -0.0019763, -0.0035190,],\n [ -0.0268906, 0.0019632, -0.0069977,],\n [ -0.0186261, 0.0274140, 0.0066706,],\n [ 0.0017896, -0.0036556, 0.0113431,],\n [ -0.0113727, -0.0156116, 0.0042445,],\n [ -0.0052975, 0.0008700, -0.0042885,],\n [ -0.0055663, -0.0056535, 0.0005495,],\n [ 0.0050889, 0.0027446, -0.0019316,],\n [ -0.0003030, 0.0040000, -0.0006066,],\n [ -0.0031004, -0.0063099, -0.0115974,],\n [ -0.0066769, 0.0058210, 0.0058223,],\n [ -0.0351842, 0.0081270, 0.0334958,],\n [ -0.0159176, 0.0189273, -0.0111036,],\n [ 0.0025764, 0.0080068, 0.0079594,],\n [ 0.0013813, -0.0236045, -0.0069523,],\n [ 0.0318463, -0.0078926, -0.0303061,],\n [ -0.0009451, -0.0115094, 0.0105833,],\n [ 0.0008331, 0.0022270, 0.0000064,],\n [ 0.0019510, 0.0046119, -0.0002960,],\n [ -0.0029637, -0.0033469, 0.0003911,],\n [ 0.0040628, 0.0045491, 0.0016492,],\n [ -0.0008783, -0.0055257, 0.0018305,],\n [ -0.0012048, 0.0001091, -0.0009157,],\n [ 0.0015754, -0.0009992, -0.0017813,],\n [ 0.0009701, 0.0001342, 0.0012882,],\n [ 0.0001547, 0.0015543, 0.0007688,],\n [ -0.0010241, -0.0002313, -0.0017558,],\n [ 0.0012272, -0.0006063, 0.0008811,],\n [ 0.0015072, 0.0000462, -0.0046693,],\n [ -0.0014937, -0.0028328, 0.0087670,],\n [ 0.0046354, 0.0016553, -0.0012502,],\n [ 0.0014366, 0.0047094, 0.0063387,],\n [ -0.0022968, 0.0000738, 0.0005287,],\n [ 0.0039856, 0.0014382, 0.0012495,],\n [ 0.0060950, 0.0005016, -0.0011365,],\n [ -0.0008533, 0.0031655, -0.0023299,],\n [ -0.0007804, 0.0005323, 0.0018985,],\n [ -0.0002041, -0.0011274, -0.0012298,],\n [ -0.0009716, -0.0005681, -0.0004076,],\n [ 0.0029277, 0.0017253, -0.0028413,],\n [ 0.0021441, -0.0008873, 0.0014046,],\n [ 0.0032778, 0.0023101, 0.0021565,],\n [ -0.0008991, 0.0014957, 0.0035126,],\n [ 0.0002489, 0.0004832, -0.0023380,],\n [ -0.0015628, -0.0015595, -0.0014371,],\n [ 0.0024810, -0.0005167, -0.0010865,],\n [ 0.0024702, 0.0014808, 0.0032646,],\n [ -0.0018446, 0.0033328, 0.0073731,],\n [ 0.0031945, 0.0080925, -0.0024241,],\n ])\n\n E1, G1 = run_rhf(primary_name='def2-tzvp')\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"c29d425d6cdea49aaf24a459228d531f24b6f0d787b9654f57a4e96f555f444d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.b3lyp1_grad_1.test.run_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.b3lyp1_grad_1.test.run_rhf#L24-L70","kind":"function","name":"run_rhf","path":"cuEST/cuest_scf_examples/test/b3lyp1_grad_1/test.py","language":"python","start_line":24,"end_line":70,"context_start_line":4,"context_end_line":90,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='B3LYP1',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_b3lyp1():\n\n import numpy as np\n\n E2 = -1.7706120600238987E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0075339, -0.0084374, 0.0100722,],\n [ -0.0129560, 0.0085460, 0.0005812,],\n [ 0.0044460, 0.0022805, 0.0010485,],\n [ -0.0020780, -0.0035621, -0.0209380,],\n [ 0.0085310, 0.0155217, 0.0060141,],\n [ -0.0078534, -0.0143469, -0.0203861,],\n [ -0.0039985, 0.0014855, 0.0145814,],\n [ 0.0129959, -0.0260229, -0.0206831,],\n [ 0.0072781, 0.0073819, 0.0204639,],\n [ 0.0376327, -0.0016436, -0.0066890,],\n [ 0.0007142, 0.0060887, -0.0293362,],","source_hash":"c29d425d6cdea49aaf24a459228d531f24b6f0d787b9654f57a4e96f555f444d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.b3lyp1_grad_1.test.test_b3lyp1","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.b3lyp1_grad_1.test.test_b3lyp1#L72-L158","kind":"function","name":"test_b3lyp1","path":"cuEST/cuest_scf_examples/test/b3lyp1_grad_1/test.py","language":"python","start_line":72,"end_line":158,"context_start_line":52,"context_end_line":158,"code":" charge=charge,\n xc_functional_name='B3LYP1',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_b3lyp1():\n\n import numpy as np\n\n E2 = -1.7706120600238987E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0075339, -0.0084374, 0.0100722,],\n [ -0.0129560, 0.0085460, 0.0005812,],\n [ 0.0044460, 0.0022805, 0.0010485,],\n [ -0.0020780, -0.0035621, -0.0209380,],\n [ 0.0085310, 0.0155217, 0.0060141,],\n [ -0.0078534, -0.0143469, -0.0203861,],\n [ -0.0039985, 0.0014855, 0.0145814,],\n [ 0.0129959, -0.0260229, -0.0206831,],\n [ 0.0072781, 0.0073819, 0.0204639,],\n [ 0.0376327, -0.0016436, -0.0066890,],\n [ 0.0007142, 0.0060887, -0.0293362,],\n [ 0.0132803, -0.0171365, 0.0107301,],\n [ -0.0079049, 0.0167075, 0.0061632,],\n [ -0.0049003, -0.0178073, 0.0007884,],\n [ -0.0050590, 0.0118507, 0.0137120,],\n [ 0.0172510, -0.0082200, -0.0076180,],\n [ 0.0083788, -0.0033765, -0.0019021,],\n [ -0.0035890, 0.0030032, 0.0026220,],\n [ 0.0043617, -0.0019763, -0.0035190,],\n [ -0.0268906, 0.0019632, -0.0069977,],\n [ -0.0186261, 0.0274140, 0.0066706,],\n [ 0.0017896, -0.0036556, 0.0113431,],\n [ -0.0113727, -0.0156116, 0.0042445,],\n [ -0.0052975, 0.0008700, -0.0042885,],\n [ -0.0055663, -0.0056535, 0.0005495,],\n [ 0.0050889, 0.0027446, -0.0019316,],\n [ -0.0003030, 0.0040000, -0.0006066,],\n [ -0.0031004, -0.0063099, -0.0115974,],\n [ -0.0066769, 0.0058210, 0.0058223,],\n [ -0.0351842, 0.0081270, 0.0334958,],\n [ -0.0159176, 0.0189273, -0.0111036,],\n [ 0.0025764, 0.0080068, 0.0079594,],\n [ 0.0013813, -0.0236045, -0.0069523,],\n [ 0.0318463, -0.0078926, -0.0303061,],\n [ -0.0009451, -0.0115094, 0.0105833,],\n [ 0.0008331, 0.0022270, 0.0000064,],\n [ 0.0019510, 0.0046119, -0.0002960,],\n [ -0.0029637, -0.0033469, 0.0003911,],\n [ 0.0040628, 0.0045491, 0.0016492,],\n [ -0.0008783, -0.0055257, 0.0018305,],\n [ -0.0012048, 0.0001091, -0.0009157,],\n [ 0.0015754, -0.0009992, -0.0017813,],\n [ 0.0009701, 0.0001342, 0.0012882,],\n [ 0.0001547, 0.0015543, 0.0007688,],\n [ -0.0010241, -0.0002313, -0.0017558,],\n [ 0.0012272, -0.0006063, 0.0008811,],\n [ 0.0015072, 0.0000462, -0.0046693,],\n [ -0.0014937, -0.0028328, 0.0087670,],\n [ 0.0046354, 0.0016553, -0.0012502,],\n [ 0.0014366, 0.0047094, 0.0063387,],\n [ -0.0022968, 0.0000738, 0.0005287,],\n [ 0.0039856, 0.0014382, 0.0012495,],\n [ 0.0060950, 0.0005016, -0.0011365,],\n [ -0.0008533, 0.0031655, -0.0023299,],\n [ -0.0007804, 0.0005323, 0.0018985,],\n [ -0.0002041, -0.0011274, -0.0012298,],\n [ -0.0009716, -0.0005681, -0.0004076,],\n [ 0.0029277, 0.0017253, -0.0028413,],\n [ 0.0021441, -0.0008873, 0.0014046,],\n [ 0.0032778, 0.0023101, 0.0021565,],\n [ -0.0008991, 0.0014957, 0.0035126,],\n [ 0.0002489, 0.0004832, -0.0023380,],\n [ -0.0015628, -0.0015595, -0.0014371,],\n [ 0.0024810, -0.0005167, -0.0010865,],\n [ 0.0024702, 0.0014808, 0.0032646,],\n [ -0.0018446, 0.0033328, 0.0073731,],\n [ 0.0031945, 0.0080925, -0.0024241,],\n ])\n\n E1, G1 = run_rhf(primary_name='def2-tzvp')\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"c29d425d6cdea49aaf24a459228d531f24b6f0d787b9654f57a4e96f555f444d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_pcm.test","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.test.rhf_pcm.test#L1-L161","kind":"module","name":"cuEST.cuest_scf_examples.test.rhf_pcm.test","path":"cuEST/cuest_scf_examples/test/rhf_pcm/test.py","language":"python","start_line":1,"end_line":161,"context_start_line":1,"context_end_line":161,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='HF',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n pcm_num_angular_points_per_hydrogen_atom=110,\n pcm_num_angular_points_per_heavy_atom=110,\n pcm_epsilon=80.0,\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_rhf():\n\n import numpy as np\n\n E2 = -1.7603457152124370E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0184988, -0.0343845, 0.0273796],\n [ -0.0379316, 0.0278096, -0.0081553],\n [ 0.0283527, 0.0232373, 0.0250976],\n [ 0.0053911, -0.0031072, -0.0507543],\n [ 0.0309708, 0.0302571, 0.0317611],\n [ -0.0188022, -0.0369833, -0.0517220],\n [ -0.0065059, 0.0053585, 0.0335458],\n [ 0.0092830, -0.0376305, -0.0282209],\n [ 0.0138367, 0.0106862, 0.0273180],\n [ 0.0589491, 0.0023250, -0.0163916],\n [ 0.0051612, 0.0106007, -0.0539697],\n [ 0.0462200, -0.0602542, 0.0402997],\n [ -0.0056771, 0.0223969, 0.0126297],\n [ -0.0116759, -0.0260531, 0.0048811],\n [ -0.0100212, 0.0187439, 0.0116294],\n [ 0.0232106, -0.0156805, -0.0132428],\n [ 0.0125720, -0.0095002, -0.0004171],\n [ -0.0033301, 0.0088493, 0.0037391],\n [ 0.0083042, -0.0051456, -0.0084316],\n [ -0.0420767, 0.0002935, -0.0006771],\n [ -0.0338492, 0.0334450, -0.0067477],\n [ 0.0067036, -0.0032993, 0.0169881],\n [ -0.0116312, -0.0162091, 0.0035779],\n [ 0.0063908, -0.0078621, 0.0088007],\n [ -0.0090302, -0.0103273, -0.0032672],\n [ 0.0089824, -0.0003942, -0.0005032],\n [ -0.0032007, 0.0061253, 0.0036111],\n [ -0.0080791, -0.0064064, -0.0207911],\n [ -0.0036370, 0.0047253, 0.0060230],\n [ -0.0535494, 0.0176575, 0.0591499],\n [ -0.0513839, 0.0653972, -0.0429843],\n [ -0.0002590, 0.0084638, 0.0102601],\n [ -0.0023809, -0.0365184, 0.0054908],\n [ 0.0449690, -0.0199295, -0.0597143],\n [ 0.0010033, -0.0134220, 0.0149047],\n [ 0.0056473, -0.0016361, -0.0018693],\n [ 0.0035635, 0.0023108, -0.0060661],\n [ -0.0059505, -0.0020846, 0.0092711],\n [ 0.0074199, 0.0076297, -0.0044440],\n [ -0.0093278, -0.0030117, 0.0029823],\n [ -0.0060894, -0.0011337, -0.0026556],\n [ 0.0045012, -0.0037991, -0.0054157],\n [ 0.0018104, -0.0030781, 0.0055600],\n [ 0.0002117, 0.0076567, 0.0022764],\n [ -0.0059578, -0.0001824, -0.0026886],\n [ 0.0016187, -0.0026258, 0.0056940],\n [ -0.0055311, -0.0032632, -0.0117384],\n [ -0.0054090, -0.0015283, 0.0209616],\n [ 0.0040352, 0.0022232, -0.0110271],\n [ 0.0075102, 0.0111909, 0.0184628],\n [ -0.0043351, 0.0017731, 0.0051392],\n [ 0.0059134, 0.0066259, -0.0003254],\n [ 0.0115309, -0.0026361, 0.0025671],\n [ 0.0006331, 0.0080836, -0.0051774],\n [ -0.0047574, 0.0029485, 0.0051459],\n [ -0.0036562, -0.0030800, -0.0048458],\n [ -0.0029043, -0.0040270, -0.0048385],\n [ 0.0049893, 0.0054211, -0.0058340],\n [ 0.0058859, -0.0037815, 0.0025470],\n [ 0.0091569, 0.0031425, 0.0043669],\n [ -0.0025388, 0.0048138, 0.0093207],\n [ -0.0073157, -0.0014136, -0.0032850],\n [ -0.0036892, -0.0058502, -0.0061210],\n [ 0.0088250, -0.0019554, -0.0007071],\n [ 0.0080319, 0.0033563, -0.0012707],\n [ -0.0081279, 0.0046624, 0.0033626],\n [ 0.0055249, 0.0199835, -0.0004452],\n ])\n\n E1, G1 = run_rhf(primary_name='def2-tzvp')\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"ae1122b9eae7c75ba0c9754e19de58c596734ebfcd8f21269400171f7cfd42d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_pcm.test.run_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.rhf_pcm.test.run_rhf#L24-L73","kind":"function","name":"run_rhf","path":"cuEST/cuest_scf_examples/test/rhf_pcm/test.py","language":"python","start_line":24,"end_line":73,"context_start_line":4,"context_end_line":93,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='HF',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n pcm_num_angular_points_per_hydrogen_atom=110,\n pcm_num_angular_points_per_heavy_atom=110,\n pcm_epsilon=80.0,\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_rhf():\n\n import numpy as np\n\n E2 = -1.7603457152124370E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0184988, -0.0343845, 0.0273796],\n [ -0.0379316, 0.0278096, -0.0081553],\n [ 0.0283527, 0.0232373, 0.0250976],\n [ 0.0053911, -0.0031072, -0.0507543],\n [ 0.0309708, 0.0302571, 0.0317611],\n [ -0.0188022, -0.0369833, -0.0517220],\n [ -0.0065059, 0.0053585, 0.0335458],\n [ 0.0092830, -0.0376305, -0.0282209],\n [ 0.0138367, 0.0106862, 0.0273180],\n [ 0.0589491, 0.0023250, -0.0163916],\n [ 0.0051612, 0.0106007, -0.0539697],","source_hash":"ae1122b9eae7c75ba0c9754e19de58c596734ebfcd8f21269400171f7cfd42d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_pcm.test.test_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.rhf_pcm.test.test_rhf#L75-L161","kind":"function","name":"test_rhf","path":"cuEST/cuest_scf_examples/test/rhf_pcm/test.py","language":"python","start_line":75,"end_line":161,"context_start_line":55,"context_end_line":161,"code":" auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n pcm_num_angular_points_per_hydrogen_atom=110,\n pcm_num_angular_points_per_heavy_atom=110,\n pcm_epsilon=80.0,\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_rhf():\n\n import numpy as np\n\n E2 = -1.7603457152124370E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0184988, -0.0343845, 0.0273796],\n [ -0.0379316, 0.0278096, -0.0081553],\n [ 0.0283527, 0.0232373, 0.0250976],\n [ 0.0053911, -0.0031072, -0.0507543],\n [ 0.0309708, 0.0302571, 0.0317611],\n [ -0.0188022, -0.0369833, -0.0517220],\n [ -0.0065059, 0.0053585, 0.0335458],\n [ 0.0092830, -0.0376305, -0.0282209],\n [ 0.0138367, 0.0106862, 0.0273180],\n [ 0.0589491, 0.0023250, -0.0163916],\n [ 0.0051612, 0.0106007, -0.0539697],\n [ 0.0462200, -0.0602542, 0.0402997],\n [ -0.0056771, 0.0223969, 0.0126297],\n [ -0.0116759, -0.0260531, 0.0048811],\n [ -0.0100212, 0.0187439, 0.0116294],\n [ 0.0232106, -0.0156805, -0.0132428],\n [ 0.0125720, -0.0095002, -0.0004171],\n [ -0.0033301, 0.0088493, 0.0037391],\n [ 0.0083042, -0.0051456, -0.0084316],\n [ -0.0420767, 0.0002935, -0.0006771],\n [ -0.0338492, 0.0334450, -0.0067477],\n [ 0.0067036, -0.0032993, 0.0169881],\n [ -0.0116312, -0.0162091, 0.0035779],\n [ 0.0063908, -0.0078621, 0.0088007],\n [ -0.0090302, -0.0103273, -0.0032672],\n [ 0.0089824, -0.0003942, -0.0005032],\n [ -0.0032007, 0.0061253, 0.0036111],\n [ -0.0080791, -0.0064064, -0.0207911],\n [ -0.0036370, 0.0047253, 0.0060230],\n [ -0.0535494, 0.0176575, 0.0591499],\n [ -0.0513839, 0.0653972, -0.0429843],\n [ -0.0002590, 0.0084638, 0.0102601],\n [ -0.0023809, -0.0365184, 0.0054908],\n [ 0.0449690, -0.0199295, -0.0597143],\n [ 0.0010033, -0.0134220, 0.0149047],\n [ 0.0056473, -0.0016361, -0.0018693],\n [ 0.0035635, 0.0023108, -0.0060661],\n [ -0.0059505, -0.0020846, 0.0092711],\n [ 0.0074199, 0.0076297, -0.0044440],\n [ -0.0093278, -0.0030117, 0.0029823],\n [ -0.0060894, -0.0011337, -0.0026556],\n [ 0.0045012, -0.0037991, -0.0054157],\n [ 0.0018104, -0.0030781, 0.0055600],\n [ 0.0002117, 0.0076567, 0.0022764],\n [ -0.0059578, -0.0001824, -0.0026886],\n [ 0.0016187, -0.0026258, 0.0056940],\n [ -0.0055311, -0.0032632, -0.0117384],\n [ -0.0054090, -0.0015283, 0.0209616],\n [ 0.0040352, 0.0022232, -0.0110271],\n [ 0.0075102, 0.0111909, 0.0184628],\n [ -0.0043351, 0.0017731, 0.0051392],\n [ 0.0059134, 0.0066259, -0.0003254],\n [ 0.0115309, -0.0026361, 0.0025671],\n [ 0.0006331, 0.0080836, -0.0051774],\n [ -0.0047574, 0.0029485, 0.0051459],\n [ -0.0036562, -0.0030800, -0.0048458],\n [ -0.0029043, -0.0040270, -0.0048385],\n [ 0.0049893, 0.0054211, -0.0058340],\n [ 0.0058859, -0.0037815, 0.0025470],\n [ 0.0091569, 0.0031425, 0.0043669],\n [ -0.0025388, 0.0048138, 0.0093207],\n [ -0.0073157, -0.0014136, -0.0032850],\n [ -0.0036892, -0.0058502, -0.0061210],\n [ 0.0088250, -0.0019554, -0.0007071],\n [ 0.0080319, 0.0033563, -0.0012707],\n [ -0.0081279, 0.0046624, 0.0033626],\n [ 0.0055249, 0.0199835, -0.0004452],\n ])\n\n E1, G1 = run_rhf(primary_name='def2-tzvp')\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"ae1122b9eae7c75ba0c9754e19de58c596734ebfcd8f21269400171f7cfd42d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_1.test","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.test.rhf_1.test#L1-L83","kind":"module","name":"cuEST.cuest_scf_examples.test.rhf_1.test","path":"cuEST/cuest_scf_examples/test/rhf_1/test.py","language":"python","start_line":1,"end_line":83,"context_start_line":1,"context_end_line":83,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n primary=primary,\n xc_functional_name='HF',\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n )\n \n rhf.solve()\n\n return rhf.scalars['Escf']\n\ndef test_rhf():\n\n reference_values = {\n 'sto-3g' : -1.7371712774897262E+03,\n 'def2-svp' : -1.7583044466471508E+03,\n 'def2-tzvp' : -1.7602954939152182E+03,\n # def2-QZVP really wants an 80 GB A100 - disabling by default\n # 'def2-qzvp' : -1.7603826412465432E+03,\n }\n\n for primary_name, E2 in reference_values.items():\n\n E1 = run_rhf(primary_name=primary_name)\n dE = abs(E1 - E2)\n assert(dE < 1.0E-6)\n \n print(dE)","source_hash":"15e06e9f0176e175dc27f288e0edcdaa1193dba5e9abd5625fafe18c13140764","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_1.test.run_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.rhf_1.test.run_rhf#L24-L65","kind":"function","name":"run_rhf","path":"cuEST/cuest_scf_examples/test/rhf_1/test.py","language":"python","start_line":24,"end_line":65,"context_start_line":4,"context_end_line":83,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n primary=primary,\n xc_functional_name='HF',\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n )\n \n rhf.solve()\n\n return rhf.scalars['Escf']\n\ndef test_rhf():\n\n reference_values = {\n 'sto-3g' : -1.7371712774897262E+03,\n 'def2-svp' : -1.7583044466471508E+03,\n 'def2-tzvp' : -1.7602954939152182E+03,\n # def2-QZVP really wants an 80 GB A100 - disabling by default\n # 'def2-qzvp' : -1.7603826412465432E+03,\n }\n\n for primary_name, E2 in reference_values.items():\n\n E1 = run_rhf(primary_name=primary_name)\n dE = abs(E1 - E2)\n assert(dE < 1.0E-6)\n \n print(dE)","source_hash":"15e06e9f0176e175dc27f288e0edcdaa1193dba5e9abd5625fafe18c13140764","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_1.test.test_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.rhf_1.test.test_rhf#L67-L83","kind":"function","name":"test_rhf","path":"cuEST/cuest_scf_examples/test/rhf_1/test.py","language":"python","start_line":67,"end_line":83,"context_start_line":47,"context_end_line":83,"code":" minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n primary=primary,\n xc_functional_name='HF',\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n )\n \n rhf.solve()\n\n return rhf.scalars['Escf']\n\ndef test_rhf():\n\n reference_values = {\n 'sto-3g' : -1.7371712774897262E+03,\n 'def2-svp' : -1.7583044466471508E+03,\n 'def2-tzvp' : -1.7602954939152182E+03,\n # def2-QZVP really wants an 80 GB A100 - disabling by default\n # 'def2-qzvp' : -1.7603826412465432E+03,\n }\n\n for primary_name, E2 in reference_values.items():\n\n E1 = run_rhf(primary_name=primary_name)\n dE = abs(E1 - E2)\n assert(dE < 1.0E-6)\n \n print(dE)","source_hash":"15e06e9f0176e175dc27f288e0edcdaa1193dba5e9abd5625fafe18c13140764","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.b97mv_grad_1.test","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.test.b97mv_grad_1.test#L1-L158","kind":"module","name":"cuEST.cuest_scf_examples.test.b97mv_grad_1.test","path":"cuEST/cuest_scf_examples/test/b97mv_grad_1/test.py","language":"python","start_line":1,"end_line":158,"context_start_line":1,"context_end_line":158,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='B97M-V',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_b97mv():\n\n import numpy as np\n\n E2 = -1.7704492618735078E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0106596, -0.0156799, 0.0145414,],\n [-0.0197646, 0.0137893, -0.0018952,],\n [ 0.0088908, 0.0068987, 0.0064756,],\n [ 0.0006182, -0.0042745, -0.0271809,],\n [ 0.0114778, 0.0174686, 0.0108210,],\n [-0.0112086, -0.0174245, -0.0243939,],\n [-0.0049056, 0.0039996, 0.0214965,],\n [ 0.0131420, -0.0238833, -0.0197356,],\n [ 0.0069684, 0.0060010, 0.0215369,],\n [ 0.0360612, -0.0017413, -0.0056847,],\n [ 0.0010948, 0.0105423, -0.0295461,],\n [ 0.0130757, -0.0167972, 0.0104620,],\n [-0.0056738, 0.0133255, 0.0062157,],\n [-0.0053860, -0.0188959, 0.0008743,],\n [-0.0062759, 0.0098235, 0.0106342,],\n [ 0.0172062, -0.0082411, -0.0046346,],\n [ 0.0057534, -0.0003341, -0.0062477,],\n [-0.0046297, -0.0011964, 0.0020192,],\n [ 0.0010280, -0.0005629, -0.0000546,],\n [-0.0255061, 0.0011339, -0.0057105,],\n [-0.0185690, 0.0252412, 0.0065229,],\n [-0.0000765, -0.0033603, 0.0102771,],\n [-0.0117633, -0.0154561, 0.0034439,],\n [-0.0055208, 0.0012165, -0.0067281,],\n [-0.0032842, -0.0025623, 0.0030395,],\n [ 0.0018487, 0.0056124, -0.0044792,],\n [ 0.0033705, 0.0025224, -0.0046141,],\n [-0.0008305, -0.0063373, -0.0079543,],\n [-0.0104291, 0.0039389, 0.0059832,],\n [-0.0324778, 0.0085888, 0.0316638,],\n [-0.0110840, 0.0127289, -0.0076844,],\n [ 0.0049426, 0.0048814, 0.0045765,],\n [ 0.0016614, -0.0221686, -0.0066648,],\n [ 0.0301663, -0.0081270, -0.0294829,],\n [-0.0003956, -0.0099346, 0.0050353,],\n [ 0.0021097, 0.0007955, 0.0002088,],\n [ 0.0021282, 0.0038946, -0.0025163,],\n [-0.0026446, -0.0039521, 0.0011721,],\n [ 0.0046033, 0.0046392, -0.0000268,],\n [-0.0021881, -0.0055075, 0.0015075,],\n [-0.0036517, -0.0008585, -0.0017543,],\n [ 0.0028364, -0.0026402, -0.0033413,],\n [ 0.0013393, -0.0015564, 0.0034227,],\n [-0.0000501, 0.0026277, 0.0016033,],\n [-0.0034870, -0.0006808, -0.0022617,],\n [ 0.0014405, -0.0017353, 0.0032705,],\n [ 0.0013591, -0.0009285, -0.0052868,],\n [-0.0025191, -0.0031309, 0.0117281,],\n [ 0.0056894, 0.0010170, -0.0023023,],\n [ 0.0019322, 0.0061851, 0.0088318,],\n [-0.0031094, 0.0008149, 0.0022319,],\n [ 0.0049323, 0.0034812, 0.0009759,],\n [ 0.0072225, 0.0006121, -0.0003196,],\n [-0.0002752, 0.0054103, -0.0035896,],\n [-0.0022374, 0.0017045, 0.0028161,],\n [-0.0016208, -0.0018633, -0.0027254,],\n [-0.0016862, -0.0014531, -0.0019444,],\n [ 0.0041234, 0.0034255, -0.0042112,],\n [ 0.0031555, -0.0010435, 0.0009888,],\n [ 0.0051177, 0.0025433, 0.0026988,],\n [-0.0014040, 0.0018589, 0.0051271,],\n [ 0.0001667, 0.0007933, -0.0018817,],\n [-0.0024006, -0.0026783, -0.0028726,],\n [ 0.0044775, -0.0008214, -0.0012893,],\n [ 0.0047634, 0.0022124, 0.0021387,],\n [-0.0030317, 0.0038995, 0.0063474,],\n [ 0.0040435, 0.0121992, -0.0016736,],\n ])\n\n E1, G1 = run_rhf(primary_name='def2-tzvp')\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"80f6753bdd9b8c566ecf03a80897216f535056bde1d62e200955f9f3db8eebdd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.b97mv_grad_1.test.run_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.b97mv_grad_1.test.run_rhf#L24-L70","kind":"function","name":"run_rhf","path":"cuEST/cuest_scf_examples/test/b97mv_grad_1/test.py","language":"python","start_line":24,"end_line":70,"context_start_line":4,"context_end_line":90,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='B97M-V',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_b97mv():\n\n import numpy as np\n\n E2 = -1.7704492618735078E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0106596, -0.0156799, 0.0145414,],\n [-0.0197646, 0.0137893, -0.0018952,],\n [ 0.0088908, 0.0068987, 0.0064756,],\n [ 0.0006182, -0.0042745, -0.0271809,],\n [ 0.0114778, 0.0174686, 0.0108210,],\n [-0.0112086, -0.0174245, -0.0243939,],\n [-0.0049056, 0.0039996, 0.0214965,],\n [ 0.0131420, -0.0238833, -0.0197356,],\n [ 0.0069684, 0.0060010, 0.0215369,],\n [ 0.0360612, -0.0017413, -0.0056847,],\n [ 0.0010948, 0.0105423, -0.0295461,],","source_hash":"80f6753bdd9b8c566ecf03a80897216f535056bde1d62e200955f9f3db8eebdd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.b97mv_grad_1.test.test_b97mv","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.b97mv_grad_1.test.test_b97mv#L72-L158","kind":"function","name":"test_b97mv","path":"cuEST/cuest_scf_examples/test/b97mv_grad_1/test.py","language":"python","start_line":72,"end_line":158,"context_start_line":52,"context_end_line":158,"code":" charge=charge,\n xc_functional_name='B97M-V',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_b97mv():\n\n import numpy as np\n\n E2 = -1.7704492618735078E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0106596, -0.0156799, 0.0145414,],\n [-0.0197646, 0.0137893, -0.0018952,],\n [ 0.0088908, 0.0068987, 0.0064756,],\n [ 0.0006182, -0.0042745, -0.0271809,],\n [ 0.0114778, 0.0174686, 0.0108210,],\n [-0.0112086, -0.0174245, -0.0243939,],\n [-0.0049056, 0.0039996, 0.0214965,],\n [ 0.0131420, -0.0238833, -0.0197356,],\n [ 0.0069684, 0.0060010, 0.0215369,],\n [ 0.0360612, -0.0017413, -0.0056847,],\n [ 0.0010948, 0.0105423, -0.0295461,],\n [ 0.0130757, -0.0167972, 0.0104620,],\n [-0.0056738, 0.0133255, 0.0062157,],\n [-0.0053860, -0.0188959, 0.0008743,],\n [-0.0062759, 0.0098235, 0.0106342,],\n [ 0.0172062, -0.0082411, -0.0046346,],\n [ 0.0057534, -0.0003341, -0.0062477,],\n [-0.0046297, -0.0011964, 0.0020192,],\n [ 0.0010280, -0.0005629, -0.0000546,],\n [-0.0255061, 0.0011339, -0.0057105,],\n [-0.0185690, 0.0252412, 0.0065229,],\n [-0.0000765, -0.0033603, 0.0102771,],\n [-0.0117633, -0.0154561, 0.0034439,],\n [-0.0055208, 0.0012165, -0.0067281,],\n [-0.0032842, -0.0025623, 0.0030395,],\n [ 0.0018487, 0.0056124, -0.0044792,],\n [ 0.0033705, 0.0025224, -0.0046141,],\n [-0.0008305, -0.0063373, -0.0079543,],\n [-0.0104291, 0.0039389, 0.0059832,],\n [-0.0324778, 0.0085888, 0.0316638,],\n [-0.0110840, 0.0127289, -0.0076844,],\n [ 0.0049426, 0.0048814, 0.0045765,],\n [ 0.0016614, -0.0221686, -0.0066648,],\n [ 0.0301663, -0.0081270, -0.0294829,],\n [-0.0003956, -0.0099346, 0.0050353,],\n [ 0.0021097, 0.0007955, 0.0002088,],\n [ 0.0021282, 0.0038946, -0.0025163,],\n [-0.0026446, -0.0039521, 0.0011721,],\n [ 0.0046033, 0.0046392, -0.0000268,],\n [-0.0021881, -0.0055075, 0.0015075,],\n [-0.0036517, -0.0008585, -0.0017543,],\n [ 0.0028364, -0.0026402, -0.0033413,],\n [ 0.0013393, -0.0015564, 0.0034227,],\n [-0.0000501, 0.0026277, 0.0016033,],\n [-0.0034870, -0.0006808, -0.0022617,],\n [ 0.0014405, -0.0017353, 0.0032705,],\n [ 0.0013591, -0.0009285, -0.0052868,],\n [-0.0025191, -0.0031309, 0.0117281,],\n [ 0.0056894, 0.0010170, -0.0023023,],\n [ 0.0019322, 0.0061851, 0.0088318,],\n [-0.0031094, 0.0008149, 0.0022319,],\n [ 0.0049323, 0.0034812, 0.0009759,],\n [ 0.0072225, 0.0006121, -0.0003196,],\n [-0.0002752, 0.0054103, -0.0035896,],\n [-0.0022374, 0.0017045, 0.0028161,],\n [-0.0016208, -0.0018633, -0.0027254,],\n [-0.0016862, -0.0014531, -0.0019444,],\n [ 0.0041234, 0.0034255, -0.0042112,],\n [ 0.0031555, -0.0010435, 0.0009888,],\n [ 0.0051177, 0.0025433, 0.0026988,],\n [-0.0014040, 0.0018589, 0.0051271,],\n [ 0.0001667, 0.0007933, -0.0018817,],\n [-0.0024006, -0.0026783, -0.0028726,],\n [ 0.0044775, -0.0008214, -0.0012893,],\n [ 0.0047634, 0.0022124, 0.0021387,],\n [-0.0030317, 0.0038995, 0.0063474,],\n [ 0.0040435, 0.0121992, -0.0016736,],\n ])\n\n E1, G1 = run_rhf(primary_name='def2-tzvp')\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"80f6753bdd9b8c566ecf03a80897216f535056bde1d62e200955f9f3db8eebdd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_grad_1.test","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.test.rhf_grad_1.test#L1-L159","kind":"module","name":"cuEST.cuest_scf_examples.test.rhf_grad_1.test","path":"cuEST/cuest_scf_examples/test/rhf_grad_1/test.py","language":"python","start_line":1,"end_line":159,"context_start_line":1,"context_end_line":159,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='HF',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_rhf():\n\n import numpy as np\n\n E2 = -1.7602954939152182E+03 # Internal reference\n E3 = -1.7602954939140413E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0208597, -0.0356780, 0.0281067],\n [ -0.0408624, 0.0282052, -0.0084045],\n [ 0.0253546, 0.0218243, 0.0242479],\n [ 0.0090637, -0.0044771, -0.0618983],\n [ 0.0344967, 0.0323332, 0.0372294],\n [ -0.0262053, -0.0418410, -0.0582010],\n [ -0.0098429, 0.0126417, 0.0546539],\n [ 0.0112808, -0.0335221, -0.0275379],\n [ 0.0127417, 0.0098751, 0.0221619],\n [ 0.0508128, -0.0012480, -0.0168725],\n [ 0.0014983, 0.0048573, -0.0411949],\n [ 0.0477820, -0.0621228, 0.0412027],\n [ -0.0050371, 0.0225184, 0.0126377],\n [ -0.0116681, -0.0265052, 0.0049367],\n [ -0.0106237, 0.0190111, 0.0112511],\n [ 0.0227971, -0.0156068, -0.0105452],\n [ 0.0121413, -0.0101201, -0.0016905],\n [ -0.0030149, 0.0082268, 0.0034705],\n [ 0.0085837, -0.0041588, -0.0078855],\n [ -0.0434603, 0.0007589, 0.0141763],\n [ -0.0390102, 0.0286030, -0.0122543],\n [ 0.0058979, -0.0037244, 0.0162883],\n [ -0.0113994, -0.0164766, 0.0029828],\n [ 0.0019021, -0.0053864, 0.0070392],\n [ -0.0095757, -0.0090207, -0.0020937],\n [ 0.0083523, 0.0004829, -0.0004781],\n [ -0.0029454, 0.0059150, 0.0021849],\n [ -0.0057341, -0.0055926, -0.0192969],\n [ -0.0032889, 0.0036989, 0.0063679],\n [ -0.0385153, 0.0253514, 0.0658022],\n [ -0.0526046, 0.0668111, -0.0438756],\n [ 0.0006937, 0.0094747, 0.0103117],\n [ 0.0037456, -0.0390302, -0.0276055],\n [ 0.0532312, -0.0174919, -0.0588797],\n [ 0.0006649, -0.0157475, 0.0113979],\n [ 0.0055180, -0.0021850, -0.0012850],\n [ 0.0032198, 0.0022361, -0.0062879],\n [ -0.0051346, -0.0025929, 0.0084412],\n [ 0.0064862, 0.0081799, -0.0042450],\n [ -0.0085572, -0.0029933, 0.0030293],\n [ -0.0064755, -0.0008781, -0.0026522],\n [ 0.0047295, -0.0035292, -0.0056022],\n [ 0.0018127, -0.0028931, 0.0059839],\n [ 0.0005288, 0.0079685, 0.0022861],\n [ -0.0063595, -0.0008092, -0.0032737],\n [ 0.0018779, -0.0028706, 0.0056260],\n [ -0.0043175, -0.0031250, -0.0122338],\n [ -0.0060574, -0.0030624, 0.0232496],\n [ 0.0064236, 0.0022386, -0.0104025],\n [ 0.0067458, 0.0127649, 0.0191777],\n [ -0.0055109, 0.0014812, 0.0051545],\n [ 0.0061676, 0.0063676, -0.0008665],\n [ 0.0125817, -0.0030474, 0.0010893],\n [ 0.0012520, 0.0080011, -0.0052251],\n [ -0.0048426, 0.0027812, 0.0058644],\n [ -0.0031752, -0.0037730, -0.0049010],\n [ -0.0037059, -0.0042413, -0.0042426],\n [ 0.0051362, 0.0057527, -0.0052669],\n [ 0.0063753, -0.0033135, 0.0032430],\n [ 0.0093046, 0.0031410, 0.0034192],\n [ -0.0035042, 0.0025311, 0.0095088],\n [ -0.0073677, -0.0005880, -0.0040605],\n [ -0.0038629, -0.0053111, -0.0056777],\n [ 0.0082404, -0.0021031, -0.0003102],\n [ 0.0077767, 0.0035413, -0.0001143],\n [ -0.0078661, 0.0050328, 0.0046209],\n [ 0.0061681, 0.0224595, -0.0017824],\n ])\n\n E1, G1 = run_rhf(primary_name='def2-tzvp')\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"744ef1bc9ee5fa9bb64090ea994a9b1dcc8f6a4c9f0a08017f3d46afb582ffa7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_grad_1.test.run_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.rhf_grad_1.test.run_rhf#L24-L70","kind":"function","name":"run_rhf","path":"cuEST/cuest_scf_examples/test/rhf_grad_1/test.py","language":"python","start_line":24,"end_line":70,"context_start_line":4,"context_end_line":90,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule_filename = os.path.join(filedir, 'paxlovid.xyz')\n \n molecule = cuest_scf.Molecule.parse_from_xyz_file(molecule_filename)\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='HF',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_rhf():\n\n import numpy as np\n\n E2 = -1.7602954939152182E+03 # Internal reference\n E3 = -1.7602954939140413E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0208597, -0.0356780, 0.0281067],\n [ -0.0408624, 0.0282052, -0.0084045],\n [ 0.0253546, 0.0218243, 0.0242479],\n [ 0.0090637, -0.0044771, -0.0618983],\n [ 0.0344967, 0.0323332, 0.0372294],\n [ -0.0262053, -0.0418410, -0.0582010],\n [ -0.0098429, 0.0126417, 0.0546539],\n [ 0.0112808, -0.0335221, -0.0275379],\n [ 0.0127417, 0.0098751, 0.0221619],\n [ 0.0508128, -0.0012480, -0.0168725],","source_hash":"744ef1bc9ee5fa9bb64090ea994a9b1dcc8f6a4c9f0a08017f3d46afb582ffa7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.rhf_grad_1.test.test_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.rhf_grad_1.test.test_rhf#L72-L159","kind":"function","name":"test_rhf","path":"cuEST/cuest_scf_examples/test/rhf_grad_1/test.py","language":"python","start_line":72,"end_line":159,"context_start_line":52,"context_end_line":159,"code":" charge=charge,\n xc_functional_name='HF',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\ndef test_rhf():\n\n import numpy as np\n\n E2 = -1.7602954939152182E+03 # Internal reference\n E3 = -1.7602954939140413E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [ -0.0208597, -0.0356780, 0.0281067],\n [ -0.0408624, 0.0282052, -0.0084045],\n [ 0.0253546, 0.0218243, 0.0242479],\n [ 0.0090637, -0.0044771, -0.0618983],\n [ 0.0344967, 0.0323332, 0.0372294],\n [ -0.0262053, -0.0418410, -0.0582010],\n [ -0.0098429, 0.0126417, 0.0546539],\n [ 0.0112808, -0.0335221, -0.0275379],\n [ 0.0127417, 0.0098751, 0.0221619],\n [ 0.0508128, -0.0012480, -0.0168725],\n [ 0.0014983, 0.0048573, -0.0411949],\n [ 0.0477820, -0.0621228, 0.0412027],\n [ -0.0050371, 0.0225184, 0.0126377],\n [ -0.0116681, -0.0265052, 0.0049367],\n [ -0.0106237, 0.0190111, 0.0112511],\n [ 0.0227971, -0.0156068, -0.0105452],\n [ 0.0121413, -0.0101201, -0.0016905],\n [ -0.0030149, 0.0082268, 0.0034705],\n [ 0.0085837, -0.0041588, -0.0078855],\n [ -0.0434603, 0.0007589, 0.0141763],\n [ -0.0390102, 0.0286030, -0.0122543],\n [ 0.0058979, -0.0037244, 0.0162883],\n [ -0.0113994, -0.0164766, 0.0029828],\n [ 0.0019021, -0.0053864, 0.0070392],\n [ -0.0095757, -0.0090207, -0.0020937],\n [ 0.0083523, 0.0004829, -0.0004781],\n [ -0.0029454, 0.0059150, 0.0021849],\n [ -0.0057341, -0.0055926, -0.0192969],\n [ -0.0032889, 0.0036989, 0.0063679],\n [ -0.0385153, 0.0253514, 0.0658022],\n [ -0.0526046, 0.0668111, -0.0438756],\n [ 0.0006937, 0.0094747, 0.0103117],\n [ 0.0037456, -0.0390302, -0.0276055],\n [ 0.0532312, -0.0174919, -0.0588797],\n [ 0.0006649, -0.0157475, 0.0113979],\n [ 0.0055180, -0.0021850, -0.0012850],\n [ 0.0032198, 0.0022361, -0.0062879],\n [ -0.0051346, -0.0025929, 0.0084412],\n [ 0.0064862, 0.0081799, -0.0042450],\n [ -0.0085572, -0.0029933, 0.0030293],\n [ -0.0064755, -0.0008781, -0.0026522],\n [ 0.0047295, -0.0035292, -0.0056022],\n [ 0.0018127, -0.0028931, 0.0059839],\n [ 0.0005288, 0.0079685, 0.0022861],\n [ -0.0063595, -0.0008092, -0.0032737],\n [ 0.0018779, -0.0028706, 0.0056260],\n [ -0.0043175, -0.0031250, -0.0122338],\n [ -0.0060574, -0.0030624, 0.0232496],\n [ 0.0064236, 0.0022386, -0.0104025],\n [ 0.0067458, 0.0127649, 0.0191777],\n [ -0.0055109, 0.0014812, 0.0051545],\n [ 0.0061676, 0.0063676, -0.0008665],\n [ 0.0125817, -0.0030474, 0.0010893],\n [ 0.0012520, 0.0080011, -0.0052251],\n [ -0.0048426, 0.0027812, 0.0058644],\n [ -0.0031752, -0.0037730, -0.0049010],\n [ -0.0037059, -0.0042413, -0.0042426],\n [ 0.0051362, 0.0057527, -0.0052669],\n [ 0.0063753, -0.0033135, 0.0032430],\n [ 0.0093046, 0.0031410, 0.0034192],\n [ -0.0035042, 0.0025311, 0.0095088],\n [ -0.0073677, -0.0005880, -0.0040605],\n [ -0.0038629, -0.0053111, -0.0056777],\n [ 0.0082404, -0.0021031, -0.0003102],\n [ 0.0077767, 0.0035413, -0.0001143],\n [ -0.0078661, 0.0050328, 0.0046209],\n [ 0.0061681, 0.0224595, -0.0017824],\n ])\n\n E1, G1 = run_rhf(primary_name='def2-tzvp')\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"744ef1bc9ee5fa9bb64090ea994a9b1dcc8f6a4c9f0a08017f3d46afb582ffa7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test#L1-L380","kind":"module","name":"cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":1,"end_line":380,"context_start_line":1,"context_end_line":380,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\nimport numpy as np\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n xc_grid_level,\n xc_grid_family,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule = cuest_scf.Molecule.parse_from_xyz_string(\"\"\"\n C -2.779381 1.358796 -0.017634\n N -1.370791 1.405167 -0.366529\n F -2.968627 1.790547 1.252788\n H -3.367136 1.987227 -0.691709\n Cl -3.330473 -0.311805 -0.186740\n O -0.662015 0.806738 0.752014\n Br 0.836087 1.898704 1.267596\n H -1.224487 0.696240 -1.080917\"\"\")\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='BLYP',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n xc_grid_level=xc_grid_level,\n xc_grid_family=xc_grid_family,\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\n\ndef test_blyp1_grid1():\n\n import numpy as np\n\n E2 = -3.3026700806219742E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0090490, -0.0104565, -0.0117094],\n [-0.0100463, -0.0018479, -0.0243732],\n [-0.0001783, -0.0048707, 0.0004488],\n [ 0.0044712, -0.0040387, 0.0094299],\n [ 0.0207582, 0.0281712, 0.0004648],\n [ 0.0022800, -0.0044285, 0.0125760],\n [-0.0020055, -0.0027708, -0.0023172],\n [-0.0062302, 0.0002419, 0.0154801],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=1,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid2():\n\n import numpy as np\n\n E2 = -3.3026741241897430E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0086464, -0.0111337, -0.0115950],\n [-0.0121519, -0.0020085, -0.0230772],\n [ 0.0004133, -0.0041646, -0.0006530],\n [ 0.0037753, -0.0052239, 0.0098708],\n [ 0.0207992, 0.0285744, 0.0007199],\n [ 0.0048984, -0.0025692, 0.0129005],\n [-0.0053030, -0.0049576, -0.0035499],\n [-0.0037849, 0.0014830, 0.0153839],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=2,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid3():\n\n import numpy as np\n\n E2 = -3.3026735923753740E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085272, -0.0110104, -0.0109514],\n [-0.0123139, -0.0019728, -0.0230565],\n [ 0.0004201, -0.0042886, -0.0013846],\n [ 0.0038463, -0.0051010, 0.0097640],\n [ 0.0207357, 0.0284409, 0.0009540],\n [ 0.0034311, -0.0037979, 0.0124144],\n [-0.0036314, -0.0037463, -0.0029304],\n [-0.0039608, 0.0014761, 0.0151904],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=3,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid4():\n\n import numpy as np\n\n E2 = -3.3026735859656069E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084841, -0.0110430, -0.0108776],\n [-0.0123528, -0.0020159, -0.0231832],\n [ 0.0004196, -0.0044269, -0.0013943],\n [ 0.0037538, -0.0050221, 0.0096938],\n [ 0.0207927, 0.0285202, 0.0009296],\n [ 0.0042107, -0.0032913, 0.0127780],\n [-0.0043379, -0.0042486, -0.0032213],\n [-0.0040020, 0.0015277, 0.0152750],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=4,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid5():\n\n import numpy as np\n\n E2 = -3.3026736646568511E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084501, -0.0109916, -0.0107023],\n [-0.0122833, -0.0020737, -0.0231218],\n [ 0.0004239, -0.0044861, -0.0015387],\n [ 0.0037366, -0.0049973, 0.0096706],\n [ 0.0207652, 0.0285071, 0.0009151],\n [ 0.0038299, -0.0034625, 0.0125407],\n [-0.0040454, -0.0040482, -0.0030641],\n [-0.0039768, 0.0015524, 0.0153005],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=5,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg0():\n\n import numpy as np\n\n E2 = -3.3026843865092101E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085120, -0.0110529, -0.0103269],\n [-0.0114557, -0.0016662, -0.0232143],\n [ 0.0002911, -0.0047466, -0.0017821],\n [ 0.0038813, -0.0050415, 0.0097291],\n [ 0.0209246, 0.0287900, -0.0000189],\n [ 0.0030973, -0.0048202, 0.0137675],\n [-0.0039907, -0.0032770, -0.0038259],\n [-0.0042358, 0.0018145, 0.0156714],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=0,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg1():\n\n E2 = -3.3026752311472001E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085473, -0.0112361, -0.0108816],\n [-0.0122674, -0.0022214, -0.0229901],\n [ 0.0005008, -0.0043548, -0.0012217],\n [ 0.0036445, -0.0049861, 0.0095828],\n [ 0.0207480, 0.0285826, 0.0008645],\n [ 0.0044558, -0.0031672, 0.0127055],\n [-0.0048013, -0.0042453, -0.0032890],\n [-0.0037329, 0.0016284, 0.0152296],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=1,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg2():\n\n E2 = -3.3026736460982765E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084323, -0.0111196, -0.0108407],\n [-0.0121870, -0.0020630, -0.0230002],\n [ 0.0003711, -0.0044170, -0.0012362],\n [ 0.0037095, -0.0048980, 0.0095853],\n [ 0.0207128, 0.0284073, 0.0008231],\n [ 0.0026341, -0.0039898, 0.0121270],\n [-0.0030084, -0.0036482, -0.0028789],\n [-0.0037998, 0.0017283, 0.0154206],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=2,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg3():\n\n E2 = -3.3026737110443828E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085442, -0.0110449, -0.0106980],\n [-0.0123756, -0.0020051, -0.0229404],\n [ 0.0003864, -0.0045772, -0.0015611],\n [ 0.0037599, -0.0050463, 0.0096945],\n [ 0.0208292, 0.0286330, 0.0008832],\n [ 0.0038349, -0.0035991, 0.0123249],\n [-0.0039995, -0.0039321, -0.0028949],\n [-0.0038911, 0.0015716, 0.0151917],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=3,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.run_rhf","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.run_rhf#L24-L80","kind":"function","name":"run_rhf","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":24,"end_line":80,"context_start_line":4,"context_end_line":100,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\nimport numpy as np\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\ncuest_handle = cuest_scf.CuestHandle()\n\ndef run_rhf(\n *,\n primary_name,\n xc_grid_level,\n xc_grid_family,\n ):\n\n # Reasonable default - as coarse as 1.0E-10 yields high-precision results\n # Coarser can save some CoreDF memory and lower runtime\n threshold_pq = 1.0E-14\n\n molecule = cuest_scf.Molecule.parse_from_xyz_string(\"\"\"\n C -2.779381 1.358796 -0.017634\n N -1.370791 1.405167 -0.366529\n F -2.968627 1.790547 1.252788\n H -3.367136 1.987227 -0.691709\n Cl -3.330473 -0.311805 -0.186740\n O -0.662015 0.806738 0.752014\n Br 0.836087 1.898704 1.267596\n H -1.224487 0.696240 -1.080917\"\"\")\n charge = 0\n \n auxiliary_name = 'def2-universal-jkfit'\n minao_name = 'minao-1'\n \n primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\n auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\n minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n \n primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\n auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\n minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n \n rhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n xc_functional_name='BLYP',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n xc_grid_level=xc_grid_level,\n xc_grid_family=xc_grid_family,\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\n\ndef test_blyp1_grid1():\n\n import numpy as np\n\n E2 = -3.3026700806219742E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0090490, -0.0104565, -0.0117094],\n [-0.0100463, -0.0018479, -0.0243732],\n [-0.0001783, -0.0048707, 0.0004488],\n [ 0.0044712, -0.0040387, 0.0094299],\n [ 0.0207582, 0.0281712, 0.0004648],\n [ 0.0022800, -0.0044285, 0.0125760],\n [-0.0020055, -0.0027708, -0.0023172],\n [-0.0062302, 0.0002419, 0.0154801],\n ])\n","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid1","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid1#L83-L114","kind":"function","name":"test_blyp1_grid1","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":83,"end_line":114,"context_start_line":63,"context_end_line":134,"code":" auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n g_convergence=1.0E-8, # Tighter for gradient check\n xc_grid_level=xc_grid_level,\n xc_grid_family=xc_grid_family,\n )\n \n rhf.solve()\n\n E = rhf.compute_energy()\n\n G = rhf.compute_gradient()\n\n return E, G\n\n\ndef test_blyp1_grid1():\n\n import numpy as np\n\n E2 = -3.3026700806219742E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0090490, -0.0104565, -0.0117094],\n [-0.0100463, -0.0018479, -0.0243732],\n [-0.0001783, -0.0048707, 0.0004488],\n [ 0.0044712, -0.0040387, 0.0094299],\n [ 0.0207582, 0.0281712, 0.0004648],\n [ 0.0022800, -0.0044285, 0.0125760],\n [-0.0020055, -0.0027708, -0.0023172],\n [-0.0062302, 0.0002419, 0.0154801],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=1,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid2():\n\n import numpy as np\n\n E2 = -3.3026741241897430E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0086464, -0.0111337, -0.0115950],\n [-0.0121519, -0.0020085, -0.0230772],\n [ 0.0004133, -0.0041646, -0.0006530],\n [ 0.0037753, -0.0052239, 0.0098708],\n [ 0.0207992, 0.0285744, 0.0007199],\n [ 0.0048984, -0.0025692, 0.0129005],\n [-0.0053030, -0.0049576, -0.0035499],\n [-0.0037849, 0.0014830, 0.0153839],\n ])\n","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid2","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid2#L117-L148","kind":"function","name":"test_blyp1_grid2","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":117,"end_line":148,"context_start_line":97,"context_end_line":168,"code":" [-0.0020055, -0.0027708, -0.0023172],\n [-0.0062302, 0.0002419, 0.0154801],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=1,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid2():\n\n import numpy as np\n\n E2 = -3.3026741241897430E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0086464, -0.0111337, -0.0115950],\n [-0.0121519, -0.0020085, -0.0230772],\n [ 0.0004133, -0.0041646, -0.0006530],\n [ 0.0037753, -0.0052239, 0.0098708],\n [ 0.0207992, 0.0285744, 0.0007199],\n [ 0.0048984, -0.0025692, 0.0129005],\n [-0.0053030, -0.0049576, -0.0035499],\n [-0.0037849, 0.0014830, 0.0153839],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=2,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid3():\n\n import numpy as np\n\n E2 = -3.3026735923753740E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085272, -0.0110104, -0.0109514],\n [-0.0123139, -0.0019728, -0.0230565],\n [ 0.0004201, -0.0042886, -0.0013846],\n [ 0.0038463, -0.0051010, 0.0097640],\n [ 0.0207357, 0.0284409, 0.0009540],\n [ 0.0034311, -0.0037979, 0.0124144],\n [-0.0036314, -0.0037463, -0.0029304],\n [-0.0039608, 0.0014761, 0.0151904],\n ])\n","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid3","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid3#L151-L182","kind":"function","name":"test_blyp1_grid3","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":151,"end_line":182,"context_start_line":131,"context_end_line":202,"code":" [-0.0053030, -0.0049576, -0.0035499],\n [-0.0037849, 0.0014830, 0.0153839],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=2,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid3():\n\n import numpy as np\n\n E2 = -3.3026735923753740E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085272, -0.0110104, -0.0109514],\n [-0.0123139, -0.0019728, -0.0230565],\n [ 0.0004201, -0.0042886, -0.0013846],\n [ 0.0038463, -0.0051010, 0.0097640],\n [ 0.0207357, 0.0284409, 0.0009540],\n [ 0.0034311, -0.0037979, 0.0124144],\n [-0.0036314, -0.0037463, -0.0029304],\n [-0.0039608, 0.0014761, 0.0151904],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=3,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid4():\n\n import numpy as np\n\n E2 = -3.3026735859656069E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084841, -0.0110430, -0.0108776],\n [-0.0123528, -0.0020159, -0.0231832],\n [ 0.0004196, -0.0044269, -0.0013943],\n [ 0.0037538, -0.0050221, 0.0096938],\n [ 0.0207927, 0.0285202, 0.0009296],\n [ 0.0042107, -0.0032913, 0.0127780],\n [-0.0043379, -0.0042486, -0.0032213],\n [-0.0040020, 0.0015277, 0.0152750],\n ])\n","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid4","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid4#L185-L216","kind":"function","name":"test_blyp1_grid4","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":185,"end_line":216,"context_start_line":165,"context_end_line":236,"code":" [-0.0036314, -0.0037463, -0.0029304],\n [-0.0039608, 0.0014761, 0.0151904],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=3,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid4():\n\n import numpy as np\n\n E2 = -3.3026735859656069E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084841, -0.0110430, -0.0108776],\n [-0.0123528, -0.0020159, -0.0231832],\n [ 0.0004196, -0.0044269, -0.0013943],\n [ 0.0037538, -0.0050221, 0.0096938],\n [ 0.0207927, 0.0285202, 0.0009296],\n [ 0.0042107, -0.0032913, 0.0127780],\n [-0.0043379, -0.0042486, -0.0032213],\n [-0.0040020, 0.0015277, 0.0152750],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=4,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid5():\n\n import numpy as np\n\n E2 = -3.3026736646568511E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084501, -0.0109916, -0.0107023],\n [-0.0122833, -0.0020737, -0.0231218],\n [ 0.0004239, -0.0044861, -0.0015387],\n [ 0.0037366, -0.0049973, 0.0096706],\n [ 0.0207652, 0.0285071, 0.0009151],\n [ 0.0038299, -0.0034625, 0.0125407],\n [-0.0040454, -0.0040482, -0.0030641],\n [-0.0039768, 0.0015524, 0.0153005],\n ])\n","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid5","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_grid5#L219-L250","kind":"function","name":"test_blyp1_grid5","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":219,"end_line":250,"context_start_line":199,"context_end_line":270,"code":" [-0.0043379, -0.0042486, -0.0032213],\n [-0.0040020, 0.0015277, 0.0152750],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=4,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_grid5():\n\n import numpy as np\n\n E2 = -3.3026736646568511E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084501, -0.0109916, -0.0107023],\n [-0.0122833, -0.0020737, -0.0231218],\n [ 0.0004239, -0.0044861, -0.0015387],\n [ 0.0037366, -0.0049973, 0.0096706],\n [ 0.0207652, 0.0285071, 0.0009151],\n [ 0.0038299, -0.0034625, 0.0125407],\n [-0.0040454, -0.0040482, -0.0030641],\n [-0.0039768, 0.0015524, 0.0153005],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=5,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg0():\n\n import numpy as np\n\n E2 = -3.3026843865092101E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085120, -0.0110529, -0.0103269],\n [-0.0114557, -0.0016662, -0.0232143],\n [ 0.0002911, -0.0047466, -0.0017821],\n [ 0.0038813, -0.0050415, 0.0097291],\n [ 0.0209246, 0.0287900, -0.0000189],\n [ 0.0030973, -0.0048202, 0.0137675],\n [-0.0039907, -0.0032770, -0.0038259],\n [-0.0042358, 0.0018145, 0.0156714],\n ])\n","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_sg0","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_sg0#L253-L284","kind":"function","name":"test_blyp1_sg0","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":253,"end_line":284,"context_start_line":233,"context_end_line":304,"code":" [-0.0040454, -0.0040482, -0.0030641],\n [-0.0039768, 0.0015524, 0.0153005],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='GRID',\n xc_grid_level=5,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg0():\n\n import numpy as np\n\n E2 = -3.3026843865092101E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085120, -0.0110529, -0.0103269],\n [-0.0114557, -0.0016662, -0.0232143],\n [ 0.0002911, -0.0047466, -0.0017821],\n [ 0.0038813, -0.0050415, 0.0097291],\n [ 0.0209246, 0.0287900, -0.0000189],\n [ 0.0030973, -0.0048202, 0.0137675],\n [-0.0039907, -0.0032770, -0.0038259],\n [-0.0042358, 0.0018145, 0.0156714],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=0,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg1():\n\n E2 = -3.3026752311472001E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085473, -0.0112361, -0.0108816],\n [-0.0122674, -0.0022214, -0.0229901],\n [ 0.0005008, -0.0043548, -0.0012217],\n [ 0.0036445, -0.0049861, 0.0095828],\n [ 0.0207480, 0.0285826, 0.0008645],\n [ 0.0044558, -0.0031672, 0.0127055],\n [-0.0048013, -0.0042453, -0.0032890],\n [-0.0037329, 0.0016284, 0.0152296],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_sg1","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_sg1#L287-L316","kind":"function","name":"test_blyp1_sg1","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":287,"end_line":316,"context_start_line":267,"context_end_line":336,"code":" [-0.0039907, -0.0032770, -0.0038259],\n [-0.0042358, 0.0018145, 0.0156714],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=0,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg1():\n\n E2 = -3.3026752311472001E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085473, -0.0112361, -0.0108816],\n [-0.0122674, -0.0022214, -0.0229901],\n [ 0.0005008, -0.0043548, -0.0012217],\n [ 0.0036445, -0.0049861, 0.0095828],\n [ 0.0207480, 0.0285826, 0.0008645],\n [ 0.0044558, -0.0031672, 0.0127055],\n [-0.0048013, -0.0042453, -0.0032890],\n [-0.0037329, 0.0016284, 0.0152296],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=1,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg2():\n\n E2 = -3.3026736460982765E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084323, -0.0111196, -0.0108407],\n [-0.0121870, -0.0020630, -0.0230002],\n [ 0.0003711, -0.0044170, -0.0012362],\n [ 0.0037095, -0.0048980, 0.0095853],\n [ 0.0207128, 0.0284073, 0.0008231],\n [ 0.0026341, -0.0039898, 0.0121270],\n [-0.0030084, -0.0036482, -0.0028789],\n [-0.0037998, 0.0017283, 0.0154206],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_sg2","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_sg2#L319-L348","kind":"function","name":"test_blyp1_sg2","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":319,"end_line":348,"context_start_line":299,"context_end_line":368,"code":" [-0.0048013, -0.0042453, -0.0032890],\n [-0.0037329, 0.0016284, 0.0152296],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=1,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg2():\n\n E2 = -3.3026736460982765E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0084323, -0.0111196, -0.0108407],\n [-0.0121870, -0.0020630, -0.0230002],\n [ 0.0003711, -0.0044170, -0.0012362],\n [ 0.0037095, -0.0048980, 0.0095853],\n [ 0.0207128, 0.0284073, 0.0008231],\n [ 0.0026341, -0.0039898, 0.0121270],\n [-0.0030084, -0.0036482, -0.0028789],\n [-0.0037998, 0.0017283, 0.0154206],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=2,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg3():\n\n E2 = -3.3026737110443828E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085442, -0.0110449, -0.0106980],\n [-0.0123756, -0.0020051, -0.0229404],\n [ 0.0003864, -0.0045772, -0.0015611],\n [ 0.0037599, -0.0050463, 0.0096945],\n [ 0.0208292, 0.0286330, 0.0008832],\n [ 0.0038349, -0.0035991, 0.0123249],\n [-0.0039995, -0.0039321, -0.0028949],\n [-0.0038911, 0.0015716, 0.0151917],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_sg3","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.test.blyp_grad_grids_1.test.test_blyp1_sg3#L351-L380","kind":"function","name":"test_blyp1_sg3","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":351,"end_line":380,"context_start_line":331,"context_end_line":380,"code":" [-0.0030084, -0.0036482, -0.0028789],\n [-0.0037998, 0.0017283, 0.0154206],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=2,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)\n\n\ndef test_blyp1_sg3():\n\n E2 = -3.3026737110443828E+03 # External code\n\n # External code we trust\n G2 = np.array([\n [-0.0085442, -0.0110449, -0.0106980],\n [-0.0123756, -0.0020051, -0.0229404],\n [ 0.0003864, -0.0045772, -0.0015611],\n [ 0.0037599, -0.0050463, 0.0096945],\n [ 0.0208292, 0.0286330, 0.0008832],\n [ 0.0038349, -0.0035991, 0.0123249],\n [-0.0039995, -0.0039321, -0.0028949],\n [-0.0038911, 0.0015716, 0.0151917],\n ])\n\n E1, G1 = run_rhf(\n primary_name='def2-svp',\n xc_grid_family='SG',\n xc_grid_level=3,\n )\n G1 = G1.to_numpy()\n dE = abs(E1 - E2)\n dG = np.max(np.abs(G1 - G2))\n\n print(dE)\n print(dG)\n\n assert(dE < 1.0E-6)\n assert(dG < 1.0E-6)","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure#L1-L186","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":1,"end_line":186,"context_start_line":1,"context_end_line":186,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n \nclass SADAtomStructure(object):\n\n def __init__(\n self,\n *,\n N : int,\n Ls : list,\n actives : list,\n ):\n\n self.N = N\n self.Ls = Ls\n self.actives = actives\n\n if not all(isinstance(_, int) for _ in Ls): raise RuntimeError('Ls is not list of int')\n if not all(isinstance(_, bool) for _ in actives): raise RuntimeError('actives is not list of bool')\n if list(sorted(actives)) != actives: raise RuntimeError('actives is not sorted')\n\n if self.N > 0 and self.nao_active == 0:\n raise RuntimeError('N > 0 and nao_active == 0')\n\n @property\n def nshell(self):\n return len(self.Ls)\n\n @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active\n\n \"\"\"\n Works in terms of RHF docc\n \"\"\"\n @property\n def nocc(self):\n if self.nao == 0:\n return np.array([])\n nocc_total = self.N / 2\n if self.nao_inactive > nocc_total:\n raise RuntimeError('nao_inactive > nocc_total. N = %d' % self.N)\n if self.nao < nocc_total:\n raise RuntimeError('nao < nocc_total. N = %d' % self.N)\n nocc_active = nocc_total - self.nao_inactive\n n = nocc_active / self.nao_active\n return np.array(\n [1.0] * self.nao_inactive +\n [n] * self.nao_active)\n\n @property\n def string(self):\n s = 'SADAtomStructure: N = %d\\n' % (self.N)\n for P in range(self.nshell):\n s += '%1d : %s\\n' % (self.Ls[P], 'active' if self.actives[P] else 'inactive')\n return s\n\n @property\n def aufbau_string(self):\n symbols = ['s', 'p', 'd', 'f']\n if self.max_L >= len(symbols): raise RuntimeError('max_L too high for symbol table')\n\n s = ''\n s += '['\n for P in range(self.nshell):\n if P > 0 and self.actives[P] and not self.actives[P-1]:\n s += ']['\n L = self.Ls[P] \n s += str(sum(1 for L2 in self.Ls[:P] if L2 == L) + 1 + L)\n s += symbols[L]\n s += ']'\n\n return s\n\n def __str__(self):\n return self.aufbau_string\n\n \"\"\"\n Technique used here:\n - In the S block, only the highest s shell is open.\n - In the P block, both the highest s and highest p shells are open.\n - In the D block, only the highest d shell is open.\n - In the F block, only the highest f shell is open.\n \n Specific choice:\n - The closed and open blocks are strictly canonicalized according to\n (n, l) ordering.\n \"\"\"\n\n @staticmethod\n def build(N):\n if N == 0:\n # Gh [][]\n return SADAtomStructure(\n N=N,\n Ls=[],\n actives=[], \n )\n elif N >= 1 and N <= 2:\n # H - He: [][1s]\n return SADAtomStructure(\n N=N,\n Ls=[0],\n actives=[True],\n )\n elif N >= 3 and N <= 4:\n # Li - Be: [1s][2s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0],\n actives=[False]*1 + [True]*1,\n )\n elif N >= 5 and N <= 10:\n # B - Ne: [1s][2s2p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1],\n actives=[False]*1 + [True]*2,\n )\n elif N >= 11 and N <= 12:\n # Na - Mg: [1s2s2p][3s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0],\n actives=[False]*3 + [True]*1,\n )\n elif N >= 13 and N <= 18:\n # Al - Ar: [1s2s2p][3s3p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1],\n actives=[False]*3 + [True]*2,\n )\n elif N >= 19 and N <= 20:\n # K - Ca: [1s2s2p3s3p][4s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 0],\n actives=[False]*5 + [True]*1,\n )\n elif N >= 21 and N <= 30:\n # Sc - Zn: [1s2s2p3s3p4s][3d]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 0, 2],\n actives=[False]*6 + [True]*1,\n )\n elif N >= 31 and N <= 36:\n # Ga - Kr: [1s2s2p3s3p3d][4s4p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 2, 0, 1],\n actives=[False]*6 + [True]*2,\n )\n # NOTE: We have the definitions for these down to Z=118, but have not\n # had time to format them - please reach out to cuEST product team if\n # you need these defined (note that you likely also need ECPs if this\n # deep)\n else:\n raise RuntimeError('Unknown SADAtomStructure for atomic number N = %d' % N)","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.SADAtomStructure","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.SADAtomStructure#L18-L186","kind":"class","name":"SADAtomStructure","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":18,"end_line":186,"context_start_line":1,"context_end_line":186,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n \nclass SADAtomStructure(object):\n\n def __init__(\n self,\n *,\n N : int,\n Ls : list,\n actives : list,\n ):\n\n self.N = N\n self.Ls = Ls\n self.actives = actives\n\n if not all(isinstance(_, int) for _ in Ls): raise RuntimeError('Ls is not list of int')\n if not all(isinstance(_, bool) for _ in actives): raise RuntimeError('actives is not list of bool')\n if list(sorted(actives)) != actives: raise RuntimeError('actives is not sorted')\n\n if self.N > 0 and self.nao_active == 0:\n raise RuntimeError('N > 0 and nao_active == 0')\n\n @property\n def nshell(self):\n return len(self.Ls)\n\n @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active\n\n \"\"\"\n Works in terms of RHF docc\n \"\"\"\n @property\n def nocc(self):\n if self.nao == 0:\n return np.array([])\n nocc_total = self.N / 2\n if self.nao_inactive > nocc_total:\n raise RuntimeError('nao_inactive > nocc_total. N = %d' % self.N)\n if self.nao < nocc_total:\n raise RuntimeError('nao < nocc_total. N = %d' % self.N)\n nocc_active = nocc_total - self.nao_inactive\n n = nocc_active / self.nao_active\n return np.array(\n [1.0] * self.nao_inactive +\n [n] * self.nao_active)\n\n @property\n def string(self):\n s = 'SADAtomStructure: N = %d\\n' % (self.N)\n for P in range(self.nshell):\n s += '%1d : %s\\n' % (self.Ls[P], 'active' if self.actives[P] else 'inactive')\n return s\n\n @property\n def aufbau_string(self):\n symbols = ['s', 'p', 'd', 'f']\n if self.max_L >= len(symbols): raise RuntimeError('max_L too high for symbol table')\n\n s = ''\n s += '['\n for P in range(self.nshell):\n if P > 0 and self.actives[P] and not self.actives[P-1]:\n s += ']['\n L = self.Ls[P] \n s += str(sum(1 for L2 in self.Ls[:P] if L2 == L) + 1 + L)\n s += symbols[L]\n s += ']'\n\n return s\n\n def __str__(self):\n return self.aufbau_string\n\n \"\"\"\n Technique used here:\n - In the S block, only the highest s shell is open.\n - In the P block, both the highest s and highest p shells are open.\n - In the D block, only the highest d shell is open.\n - In the F block, only the highest f shell is open.\n \n Specific choice:\n - The closed and open blocks are strictly canonicalized according to\n (n, l) ordering.\n \"\"\"\n\n @staticmethod\n def build(N):\n if N == 0:\n # Gh [][]\n return SADAtomStructure(\n N=N,\n Ls=[],\n actives=[], \n )\n elif N >= 1 and N <= 2:\n # H - He: [][1s]\n return SADAtomStructure(\n N=N,\n Ls=[0],\n actives=[True],\n )\n elif N >= 3 and N <= 4:\n # Li - Be: [1s][2s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0],\n actives=[False]*1 + [True]*1,\n )\n elif N >= 5 and N <= 10:\n # B - Ne: [1s][2s2p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1],\n actives=[False]*1 + [True]*2,\n )\n elif N >= 11 and N <= 12:\n # Na - Mg: [1s2s2p][3s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0],\n actives=[False]*3 + [True]*1,\n )\n elif N >= 13 and N <= 18:\n # Al - Ar: [1s2s2p][3s3p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1],\n actives=[False]*3 + [True]*2,\n )\n elif N >= 19 and N <= 20:\n # K - Ca: [1s2s2p3s3p][4s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 0],\n actives=[False]*5 + [True]*1,\n )\n elif N >= 21 and N <= 30:\n # Sc - Zn: [1s2s2p3s3p4s][3d]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 0, 2],\n actives=[False]*6 + [True]*1,\n )\n elif N >= 31 and N <= 36:\n # Ga - Kr: [1s2s2p3s3p3d][4s4p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 2, 0, 1],\n actives=[False]*6 + [True]*2,\n )\n # NOTE: We have the definitions for these down to Z=118, but have not\n # had time to format them - please reach out to cuEST product team if\n # you need these defined (note that you likely also need ECPs if this\n # deep)\n else:\n raise RuntimeError('Unknown SADAtomStructure for atomic number N = %d' % N)","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.__init__#L20-L37","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":20,"end_line":37,"context_start_line":1,"context_end_line":57,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n \nclass SADAtomStructure(object):\n\n def __init__(\n self,\n *,\n N : int,\n Ls : list,\n actives : list,\n ):\n\n self.N = N\n self.Ls = Ls\n self.actives = actives\n\n if not all(isinstance(_, int) for _ in Ls): raise RuntimeError('Ls is not list of int')\n if not all(isinstance(_, bool) for _ in actives): raise RuntimeError('actives is not list of bool')\n if list(sorted(actives)) != actives: raise RuntimeError('actives is not sorted')\n\n if self.N > 0 and self.nao_active == 0:\n raise RuntimeError('N > 0 and nao_active == 0')\n\n @property\n def nshell(self):\n return len(self.Ls)\n\n @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nshell","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nshell#L40-L41","kind":"function","name":"nshell","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":40,"end_line":41,"context_start_line":20,"context_end_line":61,"code":" def __init__(\n self,\n *,\n N : int,\n Ls : list,\n actives : list,\n ):\n\n self.N = N\n self.Ls = Ls\n self.actives = actives\n\n if not all(isinstance(_, int) for _ in Ls): raise RuntimeError('Ls is not list of int')\n if not all(isinstance(_, bool) for _ in actives): raise RuntimeError('actives is not list of bool')\n if list(sorted(actives)) != actives: raise RuntimeError('actives is not sorted')\n\n if self.N > 0 and self.nao_active == 0:\n raise RuntimeError('N > 0 and nao_active == 0')\n\n @property\n def nshell(self):\n return len(self.Ls)\n\n @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active\n\n \"\"\"\n Works in terms of RHF docc\n \"\"\"","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.max_L","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.max_L#L44-L45","kind":"function","name":"max_L","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":44,"end_line":45,"context_start_line":24,"context_end_line":65,"code":" Ls : list,\n actives : list,\n ):\n\n self.N = N\n self.Ls = Ls\n self.actives = actives\n\n if not all(isinstance(_, int) for _ in Ls): raise RuntimeError('Ls is not list of int')\n if not all(isinstance(_, bool) for _ in actives): raise RuntimeError('actives is not list of bool')\n if list(sorted(actives)) != actives: raise RuntimeError('actives is not sorted')\n\n if self.N > 0 and self.nao_active == 0:\n raise RuntimeError('N > 0 and nao_active == 0')\n\n @property\n def nshell(self):\n return len(self.Ls)\n\n @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active\n\n \"\"\"\n Works in terms of RHF docc\n \"\"\"\n @property\n def nocc(self):\n if self.nao == 0:\n return np.array([])","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nao_inactive","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nao_inactive#L48-L49","kind":"function","name":"nao_inactive","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":48,"end_line":49,"context_start_line":28,"context_end_line":69,"code":" self.N = N\n self.Ls = Ls\n self.actives = actives\n\n if not all(isinstance(_, int) for _ in Ls): raise RuntimeError('Ls is not list of int')\n if not all(isinstance(_, bool) for _ in actives): raise RuntimeError('actives is not list of bool')\n if list(sorted(actives)) != actives: raise RuntimeError('actives is not sorted')\n\n if self.N > 0 and self.nao_active == 0:\n raise RuntimeError('N > 0 and nao_active == 0')\n\n @property\n def nshell(self):\n return len(self.Ls)\n\n @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active\n\n \"\"\"\n Works in terms of RHF docc\n \"\"\"\n @property\n def nocc(self):\n if self.nao == 0:\n return np.array([])\n nocc_total = self.N / 2\n if self.nao_inactive > nocc_total:\n raise RuntimeError('nao_inactive > nocc_total. N = %d' % self.N)\n if self.nao < nocc_total:","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nao_active","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nao_active#L52-L53","kind":"function","name":"nao_active","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":52,"end_line":53,"context_start_line":32,"context_end_line":73,"code":" if not all(isinstance(_, int) for _ in Ls): raise RuntimeError('Ls is not list of int')\n if not all(isinstance(_, bool) for _ in actives): raise RuntimeError('actives is not list of bool')\n if list(sorted(actives)) != actives: raise RuntimeError('actives is not sorted')\n\n if self.N > 0 and self.nao_active == 0:\n raise RuntimeError('N > 0 and nao_active == 0')\n\n @property\n def nshell(self):\n return len(self.Ls)\n\n @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active\n\n \"\"\"\n Works in terms of RHF docc\n \"\"\"\n @property\n def nocc(self):\n if self.nao == 0:\n return np.array([])\n nocc_total = self.N / 2\n if self.nao_inactive > nocc_total:\n raise RuntimeError('nao_inactive > nocc_total. N = %d' % self.N)\n if self.nao < nocc_total:\n raise RuntimeError('nao < nocc_total. N = %d' % self.N)\n nocc_active = nocc_total - self.nao_inactive\n n = nocc_active / self.nao_active\n return np.array(","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nao","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nao#L56-L57","kind":"function","name":"nao","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":56,"end_line":57,"context_start_line":36,"context_end_line":77,"code":" if self.N > 0 and self.nao_active == 0:\n raise RuntimeError('N > 0 and nao_active == 0')\n\n @property\n def nshell(self):\n return len(self.Ls)\n\n @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active\n\n \"\"\"\n Works in terms of RHF docc\n \"\"\"\n @property\n def nocc(self):\n if self.nao == 0:\n return np.array([])\n nocc_total = self.N / 2\n if self.nao_inactive > nocc_total:\n raise RuntimeError('nao_inactive > nocc_total. N = %d' % self.N)\n if self.nao < nocc_total:\n raise RuntimeError('nao < nocc_total. N = %d' % self.N)\n nocc_active = nocc_total - self.nao_inactive\n n = nocc_active / self.nao_active\n return np.array(\n [1.0] * self.nao_inactive +\n [n] * self.nao_active)\n\n @property","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nocc","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.nocc#L63-L75","kind":"function","name":"nocc","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":63,"end_line":75,"context_start_line":43,"context_end_line":95,"code":" @property\n def max_L(self):\n return max(self.Ls) if self.nshell else 0\n \n @property\n def nao_inactive(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if not active)\n\n @property\n def nao_active(self):\n return sum(2*L + 1 for L, active in zip(self.Ls, self.actives) if active)\n\n @property\n def nao(self):\n return self.nao_inactive + self.nao_active\n\n \"\"\"\n Works in terms of RHF docc\n \"\"\"\n @property\n def nocc(self):\n if self.nao == 0:\n return np.array([])\n nocc_total = self.N / 2\n if self.nao_inactive > nocc_total:\n raise RuntimeError('nao_inactive > nocc_total. N = %d' % self.N)\n if self.nao < nocc_total:\n raise RuntimeError('nao < nocc_total. N = %d' % self.N)\n nocc_active = nocc_total - self.nao_inactive\n n = nocc_active / self.nao_active\n return np.array(\n [1.0] * self.nao_inactive +\n [n] * self.nao_active)\n\n @property\n def string(self):\n s = 'SADAtomStructure: N = %d\\n' % (self.N)\n for P in range(self.nshell):\n s += '%1d : %s\\n' % (self.Ls[P], 'active' if self.actives[P] else 'inactive')\n return s\n\n @property\n def aufbau_string(self):\n symbols = ['s', 'p', 'd', 'f']\n if self.max_L >= len(symbols): raise RuntimeError('max_L too high for symbol table')\n\n s = ''\n s += '['\n for P in range(self.nshell):\n if P > 0 and self.actives[P] and not self.actives[P-1]:\n s += ']['\n L = self.Ls[P] \n s += str(sum(1 for L2 in self.Ls[:P] if L2 == L) + 1 + L)","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.string#L78-L82","kind":"function","name":"string","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":78,"end_line":82,"context_start_line":58,"context_end_line":102,"code":"\n \"\"\"\n Works in terms of RHF docc\n \"\"\"\n @property\n def nocc(self):\n if self.nao == 0:\n return np.array([])\n nocc_total = self.N / 2\n if self.nao_inactive > nocc_total:\n raise RuntimeError('nao_inactive > nocc_total. N = %d' % self.N)\n if self.nao < nocc_total:\n raise RuntimeError('nao < nocc_total. N = %d' % self.N)\n nocc_active = nocc_total - self.nao_inactive\n n = nocc_active / self.nao_active\n return np.array(\n [1.0] * self.nao_inactive +\n [n] * self.nao_active)\n\n @property\n def string(self):\n s = 'SADAtomStructure: N = %d\\n' % (self.N)\n for P in range(self.nshell):\n s += '%1d : %s\\n' % (self.Ls[P], 'active' if self.actives[P] else 'inactive')\n return s\n\n @property\n def aufbau_string(self):\n symbols = ['s', 'p', 'd', 'f']\n if self.max_L >= len(symbols): raise RuntimeError('max_L too high for symbol table')\n\n s = ''\n s += '['\n for P in range(self.nshell):\n if P > 0 and self.actives[P] and not self.actives[P-1]:\n s += ']['\n L = self.Ls[P] \n s += str(sum(1 for L2 in self.Ls[:P] if L2 == L) + 1 + L)\n s += symbols[L]\n s += ']'\n\n return s\n\n def __str__(self):\n return self.aufbau_string","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.aufbau_string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.aufbau_string#L85-L99","kind":"function","name":"aufbau_string","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":85,"end_line":99,"context_start_line":65,"context_end_line":119,"code":" return np.array([])\n nocc_total = self.N / 2\n if self.nao_inactive > nocc_total:\n raise RuntimeError('nao_inactive > nocc_total. N = %d' % self.N)\n if self.nao < nocc_total:\n raise RuntimeError('nao < nocc_total. N = %d' % self.N)\n nocc_active = nocc_total - self.nao_inactive\n n = nocc_active / self.nao_active\n return np.array(\n [1.0] * self.nao_inactive +\n [n] * self.nao_active)\n\n @property\n def string(self):\n s = 'SADAtomStructure: N = %d\\n' % (self.N)\n for P in range(self.nshell):\n s += '%1d : %s\\n' % (self.Ls[P], 'active' if self.actives[P] else 'inactive')\n return s\n\n @property\n def aufbau_string(self):\n symbols = ['s', 'p', 'd', 'f']\n if self.max_L >= len(symbols): raise RuntimeError('max_L too high for symbol table')\n\n s = ''\n s += '['\n for P in range(self.nshell):\n if P > 0 and self.actives[P] and not self.actives[P-1]:\n s += ']['\n L = self.Ls[P] \n s += str(sum(1 for L2 in self.Ls[:P] if L2 == L) + 1 + L)\n s += symbols[L]\n s += ']'\n\n return s\n\n def __str__(self):\n return self.aufbau_string\n\n \"\"\"\n Technique used here:\n - In the S block, only the highest s shell is open.\n - In the P block, both the highest s and highest p shells are open.\n - In the D block, only the highest d shell is open.\n - In the F block, only the highest f shell is open.\n \n Specific choice:\n - The closed and open blocks are strictly canonicalized according to\n (n, l) ordering.\n \"\"\"\n\n @staticmethod\n def build(N):\n if N == 0:\n # Gh [][]","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.__str__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.__str__#L101-L102","kind":"function","name":"__str__","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":101,"end_line":102,"context_start_line":81,"context_end_line":122,"code":" s += '%1d : %s\\n' % (self.Ls[P], 'active' if self.actives[P] else 'inactive')\n return s\n\n @property\n def aufbau_string(self):\n symbols = ['s', 'p', 'd', 'f']\n if self.max_L >= len(symbols): raise RuntimeError('max_L too high for symbol table')\n\n s = ''\n s += '['\n for P in range(self.nshell):\n if P > 0 and self.actives[P] and not self.actives[P-1]:\n s += ']['\n L = self.Ls[P] \n s += str(sum(1 for L2 in self.Ls[:P] if L2 == L) + 1 + L)\n s += symbols[L]\n s += ']'\n\n return s\n\n def __str__(self):\n return self.aufbau_string\n\n \"\"\"\n Technique used here:\n - In the S block, only the highest s shell is open.\n - In the P block, both the highest s and highest p shells are open.\n - In the D block, only the highest d shell is open.\n - In the F block, only the highest f shell is open.\n \n Specific choice:\n - The closed and open blocks are strictly canonicalized according to\n (n, l) ordering.\n \"\"\"\n\n @staticmethod\n def build(N):\n if N == 0:\n # Gh [][]\n return SADAtomStructure(\n N=N,\n Ls=[],","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.build","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_atom_structure.build#L117-L186","kind":"function","name":"build","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":117,"end_line":186,"context_start_line":97,"context_end_line":186,"code":" s += ']'\n\n return s\n\n def __str__(self):\n return self.aufbau_string\n\n \"\"\"\n Technique used here:\n - In the S block, only the highest s shell is open.\n - In the P block, both the highest s and highest p shells are open.\n - In the D block, only the highest d shell is open.\n - In the F block, only the highest f shell is open.\n \n Specific choice:\n - The closed and open blocks are strictly canonicalized according to\n (n, l) ordering.\n \"\"\"\n\n @staticmethod\n def build(N):\n if N == 0:\n # Gh [][]\n return SADAtomStructure(\n N=N,\n Ls=[],\n actives=[], \n )\n elif N >= 1 and N <= 2:\n # H - He: [][1s]\n return SADAtomStructure(\n N=N,\n Ls=[0],\n actives=[True],\n )\n elif N >= 3 and N <= 4:\n # Li - Be: [1s][2s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0],\n actives=[False]*1 + [True]*1,\n )\n elif N >= 5 and N <= 10:\n # B - Ne: [1s][2s2p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1],\n actives=[False]*1 + [True]*2,\n )\n elif N >= 11 and N <= 12:\n # Na - Mg: [1s2s2p][3s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0],\n actives=[False]*3 + [True]*1,\n )\n elif N >= 13 and N <= 18:\n # Al - Ar: [1s2s2p][3s3p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1],\n actives=[False]*3 + [True]*2,\n )\n elif N >= 19 and N <= 20:\n # K - Ca: [1s2s2p3s3p][4s]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 0],\n actives=[False]*5 + [True]*1,\n )\n elif N >= 21 and N <= 30:\n # Sc - Zn: [1s2s2p3s3p4s][3d]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 0, 2],\n actives=[False]*6 + [True]*1,\n )\n elif N >= 31 and N <= 36:\n # Ga - Kr: [1s2s2p3s3p3d][4s4p]\n return SADAtomStructure(\n N=N,\n Ls=[0, 0, 1, 0, 1, 2, 0, 1],\n actives=[False]*6 + [True]*2,\n )\n # NOTE: We have the definitions for these down to Z=118, but have not\n # had time to format them - please reach out to cuEST product team if\n # you need these defined (note that you likely also need ECPs if this\n # deep)\n else:\n raise RuntimeError('Unknown SADAtomStructure for atomic number N = %d' % N)","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.xc_functionals","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.xc_functionals#L1-L79","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.xc_functionals","path":"cuEST/cuest_scf_examples/cuest_scf/xc_functionals.py","language":"python","start_line":1,"end_line":79,"context_start_line":1,"context_end_line":79,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nclass XCFunctionalInfo(object):\n\n @staticmethod\n def string_to_enum(\n functional_name : str,\n ):\n\n if functional_name.lower() == 'hf':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_HF\n elif functional_name.lower() == 'b3lyp1':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP1\n elif functional_name.lower() == 'b3lyp5':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP5\n elif functional_name.lower() == 'b97':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97\n elif functional_name.lower() == 'blyp':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_BLYP\n elif functional_name.lower() == 'm06-l':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_M06L\n elif functional_name.lower() == 'pbe':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE\n elif functional_name.lower() == 'pbe0':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE0\n elif functional_name.lower() == 'r2scan':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_R2SCAN\n elif functional_name.lower() == 'svwn5':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_SVWN5\n elif functional_name.lower() == 'b97m-v':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97MV\n else:\n raise RuntimeError('Unknown DFT functional')\n\n @staticmethod\n def enum_to_string(\n functional_enum : ce.CuestXCIntPlanParametersFunctional,\n ):\n\n if functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_HF:\n return 'HF'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP1:\n return 'B3LYP1'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP5:\n return 'B3LYP5'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97:\n return 'B97'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_BLYP:\n return 'BLYP'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_M06L:\n return 'M06-L'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE:\n return 'PBE'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE0:\n return 'PBE0'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_R2SCAN:\n return 'r2SCAN'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_SVWN5:\n return 'SVWN5'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97MV:\n return 'B97M-V'\n else:\n raise RuntimeError('Unknown DFT functional')\n","source_hash":"467544ce3291f2b7cec35b4285dc8b18da71b433c161a763e1843d8127212dd0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.xc_functionals.XCFunctionalInfo","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.xc_functionals.XCFunctionalInfo#L18-L78","kind":"class","name":"XCFunctionalInfo","path":"cuEST/cuest_scf_examples/cuest_scf/xc_functionals.py","language":"python","start_line":18,"end_line":78,"context_start_line":1,"context_end_line":79,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nclass XCFunctionalInfo(object):\n\n @staticmethod\n def string_to_enum(\n functional_name : str,\n ):\n\n if functional_name.lower() == 'hf':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_HF\n elif functional_name.lower() == 'b3lyp1':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP1\n elif functional_name.lower() == 'b3lyp5':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP5\n elif functional_name.lower() == 'b97':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97\n elif functional_name.lower() == 'blyp':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_BLYP\n elif functional_name.lower() == 'm06-l':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_M06L\n elif functional_name.lower() == 'pbe':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE\n elif functional_name.lower() == 'pbe0':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE0\n elif functional_name.lower() == 'r2scan':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_R2SCAN\n elif functional_name.lower() == 'svwn5':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_SVWN5\n elif functional_name.lower() == 'b97m-v':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97MV\n else:\n raise RuntimeError('Unknown DFT functional')\n\n @staticmethod\n def enum_to_string(\n functional_enum : ce.CuestXCIntPlanParametersFunctional,\n ):\n\n if functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_HF:\n return 'HF'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP1:\n return 'B3LYP1'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP5:\n return 'B3LYP5'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97:\n return 'B97'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_BLYP:\n return 'BLYP'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_M06L:\n return 'M06-L'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE:\n return 'PBE'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE0:\n return 'PBE0'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_R2SCAN:\n return 'r2SCAN'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_SVWN5:\n return 'SVWN5'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97MV:\n return 'B97M-V'\n else:\n raise RuntimeError('Unknown DFT functional')\n","source_hash":"467544ce3291f2b7cec35b4285dc8b18da71b433c161a763e1843d8127212dd0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.xc_functionals.string_to_enum","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.xc_functionals.string_to_enum#L21-L48","kind":"function","name":"string_to_enum","path":"cuEST/cuest_scf_examples/cuest_scf/xc_functionals.py","language":"python","start_line":21,"end_line":48,"context_start_line":1,"context_end_line":68,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nclass XCFunctionalInfo(object):\n\n @staticmethod\n def string_to_enum(\n functional_name : str,\n ):\n\n if functional_name.lower() == 'hf':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_HF\n elif functional_name.lower() == 'b3lyp1':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP1\n elif functional_name.lower() == 'b3lyp5':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP5\n elif functional_name.lower() == 'b97':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97\n elif functional_name.lower() == 'blyp':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_BLYP\n elif functional_name.lower() == 'm06-l':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_M06L\n elif functional_name.lower() == 'pbe':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE\n elif functional_name.lower() == 'pbe0':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE0\n elif functional_name.lower() == 'r2scan':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_R2SCAN\n elif functional_name.lower() == 'svwn5':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_SVWN5\n elif functional_name.lower() == 'b97m-v':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97MV\n else:\n raise RuntimeError('Unknown DFT functional')\n\n @staticmethod\n def enum_to_string(\n functional_enum : ce.CuestXCIntPlanParametersFunctional,\n ):\n\n if functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_HF:\n return 'HF'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP1:\n return 'B3LYP1'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP5:\n return 'B3LYP5'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97:\n return 'B97'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_BLYP:\n return 'BLYP'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_M06L:\n return 'M06-L'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE:\n return 'PBE'","source_hash":"467544ce3291f2b7cec35b4285dc8b18da71b433c161a763e1843d8127212dd0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.xc_functionals.enum_to_string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.xc_functionals.enum_to_string#L51-L78","kind":"function","name":"enum_to_string","path":"cuEST/cuest_scf_examples/cuest_scf/xc_functionals.py","language":"python","start_line":51,"end_line":78,"context_start_line":31,"context_end_line":79,"code":" elif functional_name.lower() == 'b97':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97\n elif functional_name.lower() == 'blyp':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_BLYP\n elif functional_name.lower() == 'm06-l':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_M06L\n elif functional_name.lower() == 'pbe':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE\n elif functional_name.lower() == 'pbe0':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE0\n elif functional_name.lower() == 'r2scan':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_R2SCAN\n elif functional_name.lower() == 'svwn5':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_SVWN5\n elif functional_name.lower() == 'b97m-v':\n return ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97MV\n else:\n raise RuntimeError('Unknown DFT functional')\n\n @staticmethod\n def enum_to_string(\n functional_enum : ce.CuestXCIntPlanParametersFunctional,\n ):\n\n if functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_HF:\n return 'HF'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP1:\n return 'B3LYP1'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B3LYP5:\n return 'B3LYP5'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97:\n return 'B97'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_BLYP:\n return 'BLYP'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_M06L:\n return 'M06-L'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE:\n return 'PBE'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_PBE0:\n return 'PBE0'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_R2SCAN:\n return 'r2SCAN'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_SVWN5:\n return 'SVWN5'\n elif functional_enum == ce.CuestXCIntPlanParametersFunctional.CUEST_XCINTPLAN_PARAMETERS_FUNCTIONAL_B97MV:\n return 'B97M-V'\n else:\n raise RuntimeError('Unknown DFT functional')\n","source_hash":"467544ce3291f2b7cec35b4285dc8b18da71b433c161a763e1843d8127212dd0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid#L1-L846","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":1,"end_line":846,"context_start_line":1,"context_end_line":846,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .memoized_property import memoized_property\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\n\nfrom .cuest_parameters import CuestParameters\n\nfrom .periodic_table import PeriodicTable\n\nfrom .unit_conversions import UnitConversions\n\n\nimport numpy as np\n\n\n# => Helpers to generate the SGn family of grids <= #\n\n\n# Table of Bragg-Slater Atomic Radii (Angstroms)\n#\n# J.C. Slater, Symmetry and Energy Bands in Crystals,\n# Dover, N.Y. 1972, page 55.\n# The radii of noble gas atoms are set to be equal \n# to the radii of the corresponding halogen atoms.\n# The radius of At is set to be equal to the radius of Po. \n# The radius of Fr is set to be equal to the radius of Cs. \n_bragg_slater_radii_in_ang = [\n1.00, # Dummy\n0.35, 0.35, # He \n1.45,1.05, 0.85,0.70,0.65,0.60,0.50,0.50, # Ne \n1.80,1.50, 1.25,1.10,1.00,1.00,1.00,1.00, # Ar \n2.20,1.80,1.60,1.40,1.35,1.40,1.40,1.40,1.35,1.35,1.35,1.35,1.30,1.25,1.15,1.15,1.15,1.15, # Kr \n2.35,2.00,1.80,1.55,1.45,1.45,1.35,1.30,1.35,1.40,1.60,1.55,1.55,1.45,1.45,1.40,1.40,1.40, # Xe \n2.60,2.15,\n 1.95,1.85,1.85,1.85,1.85,1.85,1.85,1.80,1.75,1.75,1.75,1.75,1.75,1.75, # Lanthanide Series\n 1.75,1.55,1.45,1.35,1.35,1.30,1.35,1.35,1.35,1.50,1.90,1.80,1.60,1.90,1.90,1.90, # Rn \n2.60,2.15,\n 1.95,1.80,1.80,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75, # Actinide Series\n 1.75,1.55,1.55] # Last Element is Db = 105\n\n\ndef _symbol_to_handy_radius(\n symbol \n ):\n\n N = PeriodicTable.symbol_upper_to_N_table[symbol.upper()]\n if N < 0 or N > 105:\n raise RuntimeError(f\"Element number {N} is not supported in quadrature rules\")\n\n return UnitConversions.conversions['bohr_per_ang'] * _bragg_slater_radii_in_ang[N]\n\n\n_multiexp_grids = {}\n_multiexp_grids[23] = [\n 1.5058924745841485E-03, 1.9397997519812427E-01,\n 9.9491128468613462E-03, 2.6236396365964215E-01,\n 2.6212787562513891E-02, 2.6742812676396960E-01,\n 5.0215014094684117E-02, 2.4866202472840934E-01,\n 8.1660512821456047E-02, 2.1982849560935092E-01,\n 1.2009269427713717E-01, 1.8749582392684871E-01,\n 1.6491579716600493E-01, 1.5523427291530381E-01,\n 2.1541139722601380E-01, 1.2506617470764020E-01,\n 2.7075407329850221E-01, 9.8100418872550485E-02,\n 3.3002759271630688E-01, 7.4860364849398689E-02,\n 3.9224199352412348E-01, 5.5477247414684391E-02,\n 4.5635157223202683E-01, 3.9817159733692153E-02,\n 5.2127362052638904E-01, 2.7571576765107419E-02,\n 5.8590767062942084E-01, 1.8325604666401547E-02,\n 6.4915496391179928E-01, 1.1611019656801417E-02,\n 7.0993783394310539E-01, 6.9477499303844600E-03,\n 7.6721868628476320E-01, 3.8757714610574293E-03,\n 8.2001826057974259E-01, 1.9785635068497289E-03,\n 8.6743287798275903E-01, 8.9889253062980484E-04,\n 9.0865042304171706E-01, 3.4755788975769891E-04,\n 9.4296495577173689E-01, 1.0572868056731358E-04,\n 9.6979055758591737E-01, 2.1565953939261409E-05,\n 9.8868121412417898E-01, 1.9205788879728225E-06\n ]\n_multiexp_grids[26] = [\n 1.2118959531441655E-03, 1.6590959790074028E-01,\n 7.9508350834212021E-03, 2.2996905094874989E-01,\n 2.0911970701014439E-02, 2.4044079379163869E-01,\n 4.0062890303616018E-02, 2.2975862025927751E-01,\n 6.5227756094948006E-02, 2.0930163443099781E-01,\n 9.6124873966380614E-02, 1.8456387321242523E-01,\n 1.3238114512422217E-01, 1.5860582735470496E-01,\n 1.7354177117918737E-01, 1.3324603342450497E-01,\n 2.1907886291165971E-01, 1.0957766175447055E-01,\n 2.6840004931968464E-01, 8.8230076743000874E-02,\n 3.2085745807052080E-01, 6.9518256800206554E-02,\n 3.7575717144832965E-01, 5.3537150852983870E-02,\n 4.3236914470191778E-01, 4.0226455838504871E-02,\n 4.8993751506621985E-01, 2.9418139625084539E-02,\n 5.4769119749545303E-01, 2.0873023457481800E-02,\n 6.0485464446878279E-01, 1.4309796296644042E-02,\n 6.6065863649024748E-01, 9.4283196275204324E-03,\n 7.1435096447486734E-01, 5.9282775235989377E-03,\n 7.6520686385149628E-01, 3.5237959667717032E-03,\n 8.1253906250257690E-01, 1.9544295871423150E-03,\n 8.5570731112497822E-01, 9.9280471150256034E-04,\n 8.9412727813918980E-01, 4.4916603235275061E-04,\n 9.2727872393893851E-01, 1.7307202304493732E-04,\n 9.5471297844715652E-01, 5.2504259615682031E-05,\n 9.7606029628496505E-01, 1.0687185195322842E-05,\n 9.9104255389177465E-01, 9.5039183893269103E-07\n ]\n\n\ndef _build_multiexp_radial_quadrature(\n *,\n npoint,\n R,\n ):\n \"\"\"\n P.M.W. Gill, S.H. Chien, J. Comp. Chem., 24, 732 (2003)\n R. M. Parrish https://arxiv.org/abs/2305.01621\n \"\"\"\n xu = np.array(_multiexp_grids[npoint])\n\n x = np.flip(xu[::2])\n u = np.flip(xu[1::2])\n radial_nodes = -R * np.log(x)\n radial_weights = R**3 * u / x\n\n return radial_nodes, radial_weights\n\n\ndef _build_handy_radial_quadrature(\n *,\n npoint,\n R,\n ):\n \"\"\" Euler-Macluarin rules, per C.W. Murray, N.C. Handy, G.J. Laming, Mol. Phys., 78, 997 (1993) \"\"\"\n\n x = np.arange(1.0, npoint+1.0) / (npoint + 1.0)\n radial_nodes = R * x**2 / (1.0 - x)**2\n radial_weights = 2 * R**3 * x**5 / ((npoint + 1.0) * (1.0 - x)**7)\n\n return radial_nodes, radial_weights\n\n\ndef _build_de2_radial_quadrature(\n *,\n npoint,\n R,\n r_start,\n r_end,\n alpha\n ):\n \"\"\" Build a double exponential radial grid: M. Mitani and Y. Yoshioka, Theor Chem Acc (2012) 131:1169 \"\"\"\n\n # Use Newton's method to convert the endpoints of the quadrature from the (input) r (taken as\n # input) to x. For SG2 and SG3 Newton's method always converges in fewer than 10 iterations.\n\n # Find x_start from r_start using Newton's method\n x_start = -2.3\n converged = False\n for i in range(100):\n x_start_old = x_start\n exp_neg_x = np.exp(-x_start)\n f = np.exp(alpha * x_start - exp_neg_x) - r_start\n df = (alpha + exp_neg_x) * np.exp(alpha * x_start - exp_neg_x)\n x_start = x_start - f / df\n if np.abs(x_start_old - x_start) < 1.0e-14:\n converged = True\n break\n if not converged:\n raise RuntimeError(\"Unable to find x_start in DE2 setup\")\n\n # Find x_end from r_end using Newton's method\n x_end = 1.25\n converged = False\n for i in range(100):\n x_end_old = x_end\n exp_neg_x = np.exp(-x_end)\n f = np.exp(alpha * x_end - exp_neg_x) - r_end\n df = (alpha + exp_neg_x) * np.exp(alpha * x_end - exp_neg_x)\n x_end = x_end - f / df\n if np.abs(x_end_old - x_end) < 1.0e-14:\n converged = True\n break\n if not converged:\n raise RuntimeError(\"Unable to find x_end in DE2 setup\")\n\n # Generate uniform grid in x space\n h = (x_end - x_start) / (npoint - 1)\n x = np.linspace(x_start, x_end, npoint)\n\n # Transform to r space and calculate weights\n radial_nodes = np.exp(alpha * x - np.exp(-x))\n radial_weights = h * np.exp(3.0 * alpha * x - 3.0 * np.exp(-x)) * (alpha + np.exp(-x))\n\n return radial_nodes, radial_weights\n\n\ndef _get_sg_pruning_pattern(grid_level):\n match grid_level:\n case 0:\n return 194, 50, {\n 'H' : (\"MULTIEXP\", 23, 1.30, None, None, [(6, 6), (18,3), (26,1), (38,1), (74,1), (110,1), (146,6), (86,1), (50,1), (38,1), (18,1)]),\n 'LI' : (\"MULTIEXP\", 23, 1.95, None, None, [(6, 6), (18,3), (26,1), (38,1), (74,1), (110,1), (146,6), (86,1), (50,1), (38,1), (18,1)]),\n 'BE' : (\"MULTIEXP\", 23, 2.20, None, None, [(6, 4), (18,2), (26,1), (38,2), (74,1), (86,1), (110,2), (146,5), (50,1), (38,1), (18,1), (6,2)]),\n 'B' : (\"MULTIEXP\", 23, 1.45, None, None, [(6, 4), (26,4), (38,3), (86,3), (146,6), (38,1), (6,2)]),\n 'C' : (\"MULTIEXP\", 23, 1.20, None, None, [(6, 6), (18,2), (26,1), (38,2), (50,2), (86,1), (110,1), (146,1), (170,2), (146,2), (86,1), (38,1), (18,1)]),\n 'N' : (\"MULTIEXP\", 23, 1.10, None, None, [(6, 6), (18,3), (26,1), (38,2), (74,2), (110,1), (170,2), (146,3), (86,1), (50,2)]),\n 'O' : (\"MULTIEXP\", 23, 1.10, None, None, [(6, 5), (18,1), (26,2), (38,1), (50,4), (86,1), (110,5), (86,1), (50,1), (38,1), (6,1)]),\n 'F' : (\"MULTIEXP\", 23, 1.20, None, None, [(6, 4), (38,2), (50,4), (74,2), (110,2), (146,2), (110,2), (86,3), (50,1), (6,1)]),\n 'NA' : (\"MULTIEXP\", 26, 2.30, None, None, [(6, 6), (18,2), (26,3), (38,1), (50,2), (110,8), (74,2), (6,2)]),\n 'MG' : (\"MULTIEXP\", 26, 2.20, None, None, [(6, 5), (18,2), (26,2), (38,2), (50,2), (74,1), (110,2), (146,4), (110,1), (86,1), (38,2), (18,1), (6,1)]),\n 'AL' : (\"MULTIEXP\", 26, 2.10, None, None, [(6, 6), (18,2), (26,1), (38,2), (50,2), (74,1), (86,1), (146,2), (170,2), (110,2), (86,1), (74,1), (26,1), (18,1), (6,1)]),\n 'SI' : (\"MULTIEXP\", 26, 1.30, None, None, [(6, 5), (18,4), (38,4), (50,3), (74,1), (110,2), (146,1), (170,3), (86,1), (50,1), (6,1)]),\n 'P' : (\"MULTIEXP\", 26, 1.30, None, None, [(6, 5), (18,4), (38,4), (50,3), (74,1), (110,2), (146,1), (170,3), (86,1), (50,1), (6,1)]),\n 'S' : (\"MULTIEXP\", 26, 1.10, None, None, [(6, 4), (18,1), (26,8), (38,2), (50,1), (74,2), (110,1), (170,3), (146,1), (110,1), (50,1), (6,1)]),\n 'CL' : (\"MULTIEXP\", 26, 1.45, None, None, [(6, 4), (18,7), (26,2), (38,2), (50,1), (74,1), (110,2), (170,3), (146,1), (110,1), (86,1), (6,1)]),\n 'HE' : (\"HANDY\", 50, 0.5882, None, None, [(6,16), (38,5), (86,4), (194,9), (86,16), ]),\n 'NE' : (\"HANDY\", 50, 0.6838, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17), ]),\n 'AR' : (\"HANDY\", 50, 1.3333, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19), ]),\n }\n case 1:\n return 194, 50, {\n 'H' : (\"HANDY\", 50, 1.0000, None, None, [(6,16), (38,5), (86,4), (194,9), (86,16)]),\n 'HE' : (\"HANDY\", 50, 0.5882, None, None, [(6,16), (38,5), (86,4), (194,9), (86,16)]),\n 'LI' : (\"HANDY\", 50, 3.0769, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'BE' : (\"HANDY\", 50, 2.0513, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'B' : (\"HANDY\", 50, 1.5385, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'C' : (\"HANDY\", 50, 1.2308, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'N' : (\"HANDY\", 50, 1.0256, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'O' : (\"HANDY\", 50, 0.8791, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'F' : (\"HANDY\", 50, 0.7692, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'NE' : (\"HANDY\", 50, 0.6838, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'NA' : (\"HANDY\", 50, 4.0909, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'MG' : (\"HANDY\", 50, 3.1579, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'AL' : (\"HANDY\", 50, 2.5714, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'SI' : (\"HANDY\", 50, 2.1687, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'P' : (\"HANDY\", 50, 1.8750, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'S' : (\"HANDY\", 50, 1.6514, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'CL' : (\"HANDY\", 50, 1.4754, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'AR' : (\"HANDY\", 50, 1.3333, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n }\n case 2:\n return 302, 75, {\n 'H' : (\"DE2\", 75, 1.50, 15.0, 2.6, [(6,35), (110,12), (302,16), (86,7), (26,5)]),\n 'LI' : (\"DE2\", 75, 3.87, 38.7, 3.2, [(6,35), (110,12), (302,17), (86,7), (50,4)]),\n 'BE' : (\"DE2\", 75, 2.65, 26.5, 2.4, [(6,35), (110,12), (302,17), (86,7), (50,4)]),\n 'B' : (\"DE2\", 75, 2.20, 22.0, 2.4, [(6,35), (110,12), (302,17), (146,7), (26,4)]),\n 'C' : (\"DE2\", 75, 1.71, 17.1, 2.2, [(6,35), (110,12), (302,17), (146,7), (26,4)]),\n 'N' : (\"DE2\", 75, 1.41, 14.1, 2.2, [(6,35), (110,12), (302,17), (86,7), (26,4)]),\n 'O' : (\"DE2\", 75, 1.23, 12.3, 2.2, [(6,30), (110,14), (302,18), (146,8), (50,5)]),\n 'F' : (\"DE2\", 75, 1.08, 10.8, 2.2, [(6,26), (110,16), (302,19), (110,8), (50,6)]),\n 'NA' : (\"DE2\", 75, 4.21, 42.1, 3.2, [(6,35), (110,12), (302,17), (86,7), (50,4)]),\n 'MG' : (\"DE2\", 75, 3.25, 32.5, 2.4, [(6,35), (110,12), (302,17), (86,7), (50,4)]),\n 'AL' : (\"DE2\", 75, 3.43, 34.3, 2.5, [(6,32), (110,15), (302,17), (146,7), (86,4)]),\n 'SI' : (\"DE2\", 75, 2.75, 27.5, 2.3, [(6,32), (110,15), (302,17), (146,7), (50,4)]),\n 'P' : (\"DE2\", 75, 2.32, 23.2, 2.5, [(6,30), (110,14), (302,17), (146,7), (38,7)]),\n 'S' : (\"DE2\", 75, 2.06, 20.6, 2.5, [(6,30), (110,14), (302,17), (146,7), (38,7)]),\n 'CL' : (\"DE2\", 75, 1.84, 18.4, 2.5, [(6,26), (110,16), (302,19), (110,8), (50,6)]),\n }\n case 3:\n return 590, 99, {\n 'H' : (\"DE2\", 99, 1.50, 15.0, 2.7, [(6,45), (110,16), (590,21), (194,10), (50,7)]),\n 'LI' : (\"DE2\", 99, 3.87, 38.7, 3.0, [(6,46), (110,16), (590,22), (146, 9), (50,6)]),\n 'BE' : (\"DE2\", 99, 2.65, 26.5, 2.4, [(6,42), (86,6), (110,14), (590,22), (194, 3), (146, 6), (50,6)]),\n 'B' : (\"DE2\", 99, 2.20, 22.0, 2.4, [(6,42), (86,6), (110,14), (590,22), (194, 9), (50,6)]),\n 'C' : (\"DE2\", 99, 1.71, 17.1, 2.4, [(6,46), (146,16), (590,22), (302,1), (194, 2), (146, 6), (86,6)]),\n 'N' : (\"DE2\", 99, 1.41, 14.1, 2.4, [(6,40), (110,18), (590,24), (146,11), (50,6)]),\n 'O' : (\"DE2\", 99, 1.23, 12.3, 2.6, [(6,40), (110,14), (194,2), (302,2), (590,24), (302,1), (194, 1), (146, 8), (50,7)]),\n 'F' : (\"DE2\", 99, 1.08, 10.8, 2.1, [(6,35), (110,17), (194,4), (590,25), (194, 2), (110,8), (50,8)]),\n 'NA' : (\"DE2\", 99, 4.21, 42.1, 3.2, [(6,46), (110,16), (590,22), (146, 9), (50,6)]),\n 'MG' : (\"DE2\", 99, 3.25, 32.5, 2.6, [(6,48), (110,15), (590,20), (146, 7), (50,9)]),\n 'AL' : (\"DE2\", 99, 3.43, 34.3, 2.6, [(6,42), (86,6), (110,14), (590,22), (194, 3), (146, 6), (50,6)]),\n 'SI' : (\"DE2\", 99, 2.75, 27.5, 2.8, [(6,42), (86,6), (110,14), (590,22), (194, 9), (50,6)]),\n 'P' : (\"DE2\", 99, 2.32, 23.2, 2.4, [(6,35), (86,1), (110,18), (194,4), (590,25), (194, 2), (146, 8), (50,6)]),\n 'S' : (\"DE2\", 99, 2.06, 20.6, 2.4, [(6,35), (86,1), (110,18), (194,4), (590,25), (194, 2), (146, 8), (50,6)]),\n 'CL' : (\"DE2\", 99, 1.84, 18.4, 2.6, [(6,35), (110,17), (194,4), (590,25), (194, 2), (110,8), (50,8)]),\n }\n case _:\n raise RuntimeError(\"Unexpected SG grid level\")\n\n# => Helpers to generate the GRIDn family of grids <= #\n\ndef _symbol_to_ahlrichs_radius(\n *,\n symbol,\n ):\n\n symbol = symbol.upper()\n\n radii = {\n \"X\" : 1.00, \n \"H\" : 0.80,\n \"HE\" : 0.90,\n \"LI\" : 1.80,\n \"BE\" : 1.40,\n \"B\" : 1.30,\n \"C\" : 1.10,\n \"N\" : 0.90,\n \"O\" : 0.90,\n \"F\" : 0.90,\n \"NE\" : 0.90,\n \"NA\" : 1.40,\n \"MG\" : 1.30,\n \"AL\" : 1.30,\n \"SI\" : 1.20,\n \"P\" : 1.10,\n \"S\" : 1.00,\n \"CL\" : 1.00,\n \"AR\" : 1.00,\n \"K\" : 1.50,\n \"CA\" : 1.40,\n \"SC\" : 1.30,\n \"TI\" : 1.20,\n \"V\" : 1.20,\n \"CR\" : 1.20,\n \"MN\" : 1.20,\n \"FE\" : 1.20,\n \"CO\" : 1.20,\n \"NI\" : 1.10,\n \"CU\" : 1.10,\n \"ZN\" : 1.10,\n \"GA\" : 1.10,\n \"GE\" : 1.00,\n \"AS\" : 0.90,\n \"SE\" : 0.90,\n \"BR\" : 0.90,\n \"KR\" : 0.90,\n }\n\n return radii.get(symbol, 1.0)\n\n\ndef _build_ahlrichs_radial_quadrature(\n *,\n npoint,\n R,\n ):\n\n alpha = 0.6\n\n n = np.arange(1.0, npoint+1.0)\n z = n * np.pi / (npoint + 1.0)\n x = np.cos(z)\n y = np.sin(z)\n u = np.log((1.0 - x) / 2.0)\n v = ((1.0 + x)**alpha) / np.log(2.0)\n radial_nodes = - R * v * u\n radial_weights = np.pi / (npoint + 1.0) * y * R * v * (-alpha * u / (1.0 + x) + 1.0 / (1.0 - x)) * radial_nodes**2\n\n return np.flip(radial_nodes).tolist(), np.flip(radial_weights).tolist()\n\n\ndef _get_grid_pruning_pattern(grid_level):\n match grid_level:\n case 1:\n return 194, 50, {\n 'H' : [(14,6), (50,4), (50,10) ],\n 'HE' : [(14,6), (50,4), (50,10) ],\n 'LI' : [(14,8), (50,4), (110,13)],\n 'BE' : [(14,8), (50,4), (110,13)],\n 'B' : [(14,8), (50,4), (110,13)],\n 'C' : [(14,8), (50,4), (110,13)],\n 'N' : [(14,8), (50,4), (110,13)],\n 'O' : [(14,8), (50,4), (110,13)],\n 'F' : [(14,8), (50,4), (110,13)],\n 'NE' : [(14,8), (50,4), (110,13)],\n 'NA' : [(14,10), (50,5), (110,15)],\n 'MG' : [(14,10), (50,5), (110,15)],\n 'AL' : [(14,10), (50,5), (110,15)],\n 'SI' : [(14,10), (50,5), (110,15)],\n 'P' : [(14,10), (50,5), (110,15)],\n 'S' : [(14,10), (50,5), (110,15)],\n 'CL' : [(14,10), (50,5), (110,15)],\n 'AR' : [(14,10), (50,5), (110,15)],\n 'K' : [(14,11), (50,6), (110,18)],\n 'CA' : [(14,11), (50,6), (110,18)],\n 'SC' : [(14,11), (50,6), (110,18)],\n 'TI' : [(14,11), (50,6), (110,18)],\n 'V' : [(14,11), (50,6), (110,18)],\n 'CR' : [(14,11), (50,6), (110,18)],\n 'MN' : [(14,11), (50,6), (110,18)],\n 'FE' : [(14,11), (50,6), (110,18)],\n 'CO' : [(14,11), (50,6), (110,18)],\n 'NI' : [(14,11), (50,6), (110,18)],\n 'CU' : [(14,11), (50,6), (110,18)],\n 'ZN' : [(14,11), (50,6), (110,18)],\n 'GA' : [(14,11), (50,6), (110,18)],\n 'GE' : [(14,11), (50,6), (110,18)],\n 'AS' : [(14,11), (50,6), (110,18)],\n 'SE' : [(14,11), (50,6), (110,18)],\n 'BR' : [(14,11), (50,6), (110,18)],\n 'KR' : [(14,11), (50,6), (110,18)],\n }\n case 2:\n return 302, 55, {\n 'H' : [(14,8), (50,4), (110,13)],\n 'HE' : [(14,8), (50,4), (110,13)],\n 'LI' : [(14,10), (50,5), (194,15)],\n 'BE' : [(14,10), (50,5), (194,15)],\n 'B' : [(14,10), (50,5), (194,15)],\n 'C' : [(14,10), (50,5), (194,15)],\n 'N' : [(14,10), (50,5)\n# ... truncated ...","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._symbol_to_handy_radius","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._symbol_to_handy_radius#L61-L69","kind":"function","name":"_symbol_to_handy_radius","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":61,"end_line":69,"context_start_line":41,"context_end_line":89,"code":"# Dover, N.Y. 1972, page 55.\n# The radii of noble gas atoms are set to be equal \n# to the radii of the corresponding halogen atoms.\n# The radius of At is set to be equal to the radius of Po. \n# The radius of Fr is set to be equal to the radius of Cs. \n_bragg_slater_radii_in_ang = [\n1.00, # Dummy\n0.35, 0.35, # He \n1.45,1.05, 0.85,0.70,0.65,0.60,0.50,0.50, # Ne \n1.80,1.50, 1.25,1.10,1.00,1.00,1.00,1.00, # Ar \n2.20,1.80,1.60,1.40,1.35,1.40,1.40,1.40,1.35,1.35,1.35,1.35,1.30,1.25,1.15,1.15,1.15,1.15, # Kr \n2.35,2.00,1.80,1.55,1.45,1.45,1.35,1.30,1.35,1.40,1.60,1.55,1.55,1.45,1.45,1.40,1.40,1.40, # Xe \n2.60,2.15,\n 1.95,1.85,1.85,1.85,1.85,1.85,1.85,1.80,1.75,1.75,1.75,1.75,1.75,1.75, # Lanthanide Series\n 1.75,1.55,1.45,1.35,1.35,1.30,1.35,1.35,1.35,1.50,1.90,1.80,1.60,1.90,1.90,1.90, # Rn \n2.60,2.15,\n 1.95,1.80,1.80,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75, # Actinide Series\n 1.75,1.55,1.55] # Last Element is Db = 105\n\n\ndef _symbol_to_handy_radius(\n symbol \n ):\n\n N = PeriodicTable.symbol_upper_to_N_table[symbol.upper()]\n if N < 0 or N > 105:\n raise RuntimeError(f\"Element number {N} is not supported in quadrature rules\")\n\n return UnitConversions.conversions['bohr_per_ang'] * _bragg_slater_radii_in_ang[N]\n\n\n_multiexp_grids = {}\n_multiexp_grids[23] = [\n 1.5058924745841485E-03, 1.9397997519812427E-01,\n 9.9491128468613462E-03, 2.6236396365964215E-01,\n 2.6212787562513891E-02, 2.6742812676396960E-01,\n 5.0215014094684117E-02, 2.4866202472840934E-01,\n 8.1660512821456047E-02, 2.1982849560935092E-01,\n 1.2009269427713717E-01, 1.8749582392684871E-01,\n 1.6491579716600493E-01, 1.5523427291530381E-01,\n 2.1541139722601380E-01, 1.2506617470764020E-01,\n 2.7075407329850221E-01, 9.8100418872550485E-02,\n 3.3002759271630688E-01, 7.4860364849398689E-02,\n 3.9224199352412348E-01, 5.5477247414684391E-02,\n 4.5635157223202683E-01, 3.9817159733692153E-02,\n 5.2127362052638904E-01, 2.7571576765107419E-02,\n 5.8590767062942084E-01, 1.8325604666401547E-02,\n 6.4915496391179928E-01, 1.1611019656801417E-02,\n 7.0993783394310539E-01, 6.9477499303844600E-03,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._build_multiexp_radial_quadrature","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._build_multiexp_radial_quadrature#L128-L144","kind":"function","name":"_build_multiexp_radial_quadrature","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":128,"end_line":144,"context_start_line":108,"context_end_line":164,"code":" 2.6840004931968464E-01, 8.8230076743000874E-02,\n 3.2085745807052080E-01, 6.9518256800206554E-02,\n 3.7575717144832965E-01, 5.3537150852983870E-02,\n 4.3236914470191778E-01, 4.0226455838504871E-02,\n 4.8993751506621985E-01, 2.9418139625084539E-02,\n 5.4769119749545303E-01, 2.0873023457481800E-02,\n 6.0485464446878279E-01, 1.4309796296644042E-02,\n 6.6065863649024748E-01, 9.4283196275204324E-03,\n 7.1435096447486734E-01, 5.9282775235989377E-03,\n 7.6520686385149628E-01, 3.5237959667717032E-03,\n 8.1253906250257690E-01, 1.9544295871423150E-03,\n 8.5570731112497822E-01, 9.9280471150256034E-04,\n 8.9412727813918980E-01, 4.4916603235275061E-04,\n 9.2727872393893851E-01, 1.7307202304493732E-04,\n 9.5471297844715652E-01, 5.2504259615682031E-05,\n 9.7606029628496505E-01, 1.0687185195322842E-05,\n 9.9104255389177465E-01, 9.5039183893269103E-07\n ]\n\n\ndef _build_multiexp_radial_quadrature(\n *,\n npoint,\n R,\n ):\n \"\"\"\n P.M.W. Gill, S.H. Chien, J. Comp. Chem., 24, 732 (2003)\n R. M. Parrish https://arxiv.org/abs/2305.01621\n \"\"\"\n xu = np.array(_multiexp_grids[npoint])\n\n x = np.flip(xu[::2])\n u = np.flip(xu[1::2])\n radial_nodes = -R * np.log(x)\n radial_weights = R**3 * u / x\n\n return radial_nodes, radial_weights\n\n\ndef _build_handy_radial_quadrature(\n *,\n npoint,\n R,\n ):\n \"\"\" Euler-Macluarin rules, per C.W. Murray, N.C. Handy, G.J. Laming, Mol. Phys., 78, 997 (1993) \"\"\"\n\n x = np.arange(1.0, npoint+1.0) / (npoint + 1.0)\n radial_nodes = R * x**2 / (1.0 - x)**2\n radial_weights = 2 * R**3 * x**5 / ((npoint + 1.0) * (1.0 - x)**7)\n\n return radial_nodes, radial_weights\n\n\ndef _build_de2_radial_quadrature(\n *,\n npoint,\n R,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._build_handy_radial_quadrature","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._build_handy_radial_quadrature#L147-L158","kind":"function","name":"_build_handy_radial_quadrature","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":147,"end_line":158,"context_start_line":127,"context_end_line":178,"code":"\ndef _build_multiexp_radial_quadrature(\n *,\n npoint,\n R,\n ):\n \"\"\"\n P.M.W. Gill, S.H. Chien, J. Comp. Chem., 24, 732 (2003)\n R. M. Parrish https://arxiv.org/abs/2305.01621\n \"\"\"\n xu = np.array(_multiexp_grids[npoint])\n\n x = np.flip(xu[::2])\n u = np.flip(xu[1::2])\n radial_nodes = -R * np.log(x)\n radial_weights = R**3 * u / x\n\n return radial_nodes, radial_weights\n\n\ndef _build_handy_radial_quadrature(\n *,\n npoint,\n R,\n ):\n \"\"\" Euler-Macluarin rules, per C.W. Murray, N.C. Handy, G.J. Laming, Mol. Phys., 78, 997 (1993) \"\"\"\n\n x = np.arange(1.0, npoint+1.0) / (npoint + 1.0)\n radial_nodes = R * x**2 / (1.0 - x)**2\n radial_weights = 2 * R**3 * x**5 / ((npoint + 1.0) * (1.0 - x)**7)\n\n return radial_nodes, radial_weights\n\n\ndef _build_de2_radial_quadrature(\n *,\n npoint,\n R,\n r_start,\n r_end,\n alpha\n ):\n \"\"\" Build a double exponential radial grid: M. Mitani and Y. Yoshioka, Theor Chem Acc (2012) 131:1169 \"\"\"\n\n # Use Newton's method to convert the endpoints of the quadrature from the (input) r (taken as\n # input) to x. For SG2 and SG3 Newton's method always converges in fewer than 10 iterations.\n\n # Find x_start from r_start using Newton's method\n x_start = -2.3\n converged = False\n for i in range(100):\n x_start_old = x_start","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._build_de2_radial_quadrature","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._build_de2_radial_quadrature#L161-L212","kind":"function","name":"_build_de2_radial_quadrature","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":161,"end_line":212,"context_start_line":141,"context_end_line":232,"code":" radial_nodes = -R * np.log(x)\n radial_weights = R**3 * u / x\n\n return radial_nodes, radial_weights\n\n\ndef _build_handy_radial_quadrature(\n *,\n npoint,\n R,\n ):\n \"\"\" Euler-Macluarin rules, per C.W. Murray, N.C. Handy, G.J. Laming, Mol. Phys., 78, 997 (1993) \"\"\"\n\n x = np.arange(1.0, npoint+1.0) / (npoint + 1.0)\n radial_nodes = R * x**2 / (1.0 - x)**2\n radial_weights = 2 * R**3 * x**5 / ((npoint + 1.0) * (1.0 - x)**7)\n\n return radial_nodes, radial_weights\n\n\ndef _build_de2_radial_quadrature(\n *,\n npoint,\n R,\n r_start,\n r_end,\n alpha\n ):\n \"\"\" Build a double exponential radial grid: M. Mitani and Y. Yoshioka, Theor Chem Acc (2012) 131:1169 \"\"\"\n\n # Use Newton's method to convert the endpoints of the quadrature from the (input) r (taken as\n # input) to x. For SG2 and SG3 Newton's method always converges in fewer than 10 iterations.\n\n # Find x_start from r_start using Newton's method\n x_start = -2.3\n converged = False\n for i in range(100):\n x_start_old = x_start\n exp_neg_x = np.exp(-x_start)\n f = np.exp(alpha * x_start - exp_neg_x) - r_start\n df = (alpha + exp_neg_x) * np.exp(alpha * x_start - exp_neg_x)\n x_start = x_start - f / df\n if np.abs(x_start_old - x_start) < 1.0e-14:\n converged = True\n break\n if not converged:\n raise RuntimeError(\"Unable to find x_start in DE2 setup\")\n\n # Find x_end from r_end using Newton's method\n x_end = 1.25\n converged = False\n for i in range(100):\n x_end_old = x_end\n exp_neg_x = np.exp(-x_end)\n f = np.exp(alpha * x_end - exp_neg_x) - r_end\n df = (alpha + exp_neg_x) * np.exp(alpha * x_end - exp_neg_x)\n x_end = x_end - f / df\n if np.abs(x_end_old - x_end) < 1.0e-14:\n converged = True\n break\n if not converged:\n raise RuntimeError(\"Unable to find x_end in DE2 setup\")\n\n # Generate uniform grid in x space\n h = (x_end - x_start) / (npoint - 1)\n x = np.linspace(x_start, x_end, npoint)\n\n # Transform to r space and calculate weights\n radial_nodes = np.exp(alpha * x - np.exp(-x))\n radial_weights = h * np.exp(3.0 * alpha * x - 3.0 * np.exp(-x)) * (alpha + np.exp(-x))\n\n return radial_nodes, radial_weights\n\n\ndef _get_sg_pruning_pattern(grid_level):\n match grid_level:\n case 0:\n return 194, 50, {\n 'H' : (\"MULTIEXP\", 23, 1.30, None, None, [(6, 6), (18,3), (26,1), (38,1), (74,1), (110,1), (146,6), (86,1), (50,1), (38,1), (18,1)]),\n 'LI' : (\"MULTIEXP\", 23, 1.95, None, None, [(6, 6), (18,3), (26,1), (38,1), (74,1), (110,1), (146,6), (86,1), (50,1), (38,1), (18,1)]),\n 'BE' : (\"MULTIEXP\", 23, 2.20, None, None, [(6, 4), (18,2), (26,1), (38,2), (74,1), (86,1), (110,2), (146,5), (50,1), (38,1), (18,1), (6,2)]),\n 'B' : (\"MULTIEXP\", 23, 1.45, None, None, [(6, 4), (26,4), (38,3), (86,3), (146,6), (38,1), (6,2)]),\n 'C' : (\"MULTIEXP\", 23, 1.20, None, None, [(6, 6), (18,2), (26,1), (38,2), (50,2), (86,1), (110,1), (146,1), (170,2), (146,2), (86,1), (38,1), (18,1)]),\n 'N' : (\"MULTIEXP\", 23, 1.10, None, None, [(6, 6), (18,3), (26,1), (38,2), (74,2), (110,1), (170,2), (146,3), (86,1), (50,2)]),\n 'O' : (\"MULTIEXP\", 23, 1.10, None, None, [(6, 5), (18,1), (26,2), (38,1), (50,4), (86,1), (110,5), (86,1), (50,1), (38,1), (6,1)]),\n 'F' : (\"MULTIEXP\", 23, 1.20, None, None, [(6, 4), (38,2), (50,4), (74,2), (110,2), (146,2), (110,2), (86,3), (50,1), (6,1)]),\n 'NA' : (\"MULTIEXP\", 26, 2.30, None, None, [(6, 6), (18,2), (26,3), (38,1), (50,2), (110,8), (74,2), (6,2)]),\n 'MG' : (\"MULTIEXP\", 26, 2.20, None, None, [(6, 5), (18,2), (26,2), (38,2), (50,2), (74,1), (110,2), (146,4), (110,1), (86,1), (38,2), (18,1), (6,1)]),\n 'AL' : (\"MULTIEXP\", 26, 2.10, None, None, [(6, 6), (18,2), (26,1), (38,2), (50,2), (74,1), (86,1), (146,2), (170,2), (110,2), (86,1), (74,1), (26,1), (18,1), (6,1)]),\n 'SI' : (\"MULTIEXP\", 26, 1.30, None, None, [(6, 5), (18,4), (38,4), (50,3), (74,1), (110,2), (146,1), (170,3), (86,1), (50,1), (6,1)]),\n 'P' : (\"MULTIEXP\", 26, 1.30, None, None, [(6, 5), (18,4), (38,4), (50,3), (74,1), (110,2), (146,1), (170,3), (86,1), (50,1), (6,1)]),\n 'S' : (\"MULTIEXP\", 26, 1.10, None, None, [(6, 4), (18,1), (26,8), (38,2), (50,1), (74,2), (110,1), (170,3), (146,1), (110,1), (50,1), (6,1)]),","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._get_sg_pruning_pattern","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._get_sg_pruning_pattern#L215-L296","kind":"function","name":"_get_sg_pruning_pattern","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":215,"end_line":296,"context_start_line":195,"context_end_line":316,"code":" f = np.exp(alpha * x_end - exp_neg_x) - r_end\n df = (alpha + exp_neg_x) * np.exp(alpha * x_end - exp_neg_x)\n x_end = x_end - f / df\n if np.abs(x_end_old - x_end) < 1.0e-14:\n converged = True\n break\n if not converged:\n raise RuntimeError(\"Unable to find x_end in DE2 setup\")\n\n # Generate uniform grid in x space\n h = (x_end - x_start) / (npoint - 1)\n x = np.linspace(x_start, x_end, npoint)\n\n # Transform to r space and calculate weights\n radial_nodes = np.exp(alpha * x - np.exp(-x))\n radial_weights = h * np.exp(3.0 * alpha * x - 3.0 * np.exp(-x)) * (alpha + np.exp(-x))\n\n return radial_nodes, radial_weights\n\n\ndef _get_sg_pruning_pattern(grid_level):\n match grid_level:\n case 0:\n return 194, 50, {\n 'H' : (\"MULTIEXP\", 23, 1.30, None, None, [(6, 6), (18,3), (26,1), (38,1), (74,1), (110,1), (146,6), (86,1), (50,1), (38,1), (18,1)]),\n 'LI' : (\"MULTIEXP\", 23, 1.95, None, None, [(6, 6), (18,3), (26,1), (38,1), (74,1), (110,1), (146,6), (86,1), (50,1), (38,1), (18,1)]),\n 'BE' : (\"MULTIEXP\", 23, 2.20, None, None, [(6, 4), (18,2), (26,1), (38,2), (74,1), (86,1), (110,2), (146,5), (50,1), (38,1), (18,1), (6,2)]),\n 'B' : (\"MULTIEXP\", 23, 1.45, None, None, [(6, 4), (26,4), (38,3), (86,3), (146,6), (38,1), (6,2)]),\n 'C' : (\"MULTIEXP\", 23, 1.20, None, None, [(6, 6), (18,2), (26,1), (38,2), (50,2), (86,1), (110,1), (146,1), (170,2), (146,2), (86,1), (38,1), (18,1)]),\n 'N' : (\"MULTIEXP\", 23, 1.10, None, None, [(6, 6), (18,3), (26,1), (38,2), (74,2), (110,1), (170,2), (146,3), (86,1), (50,2)]),\n 'O' : (\"MULTIEXP\", 23, 1.10, None, None, [(6, 5), (18,1), (26,2), (38,1), (50,4), (86,1), (110,5), (86,1), (50,1), (38,1), (6,1)]),\n 'F' : (\"MULTIEXP\", 23, 1.20, None, None, [(6, 4), (38,2), (50,4), (74,2), (110,2), (146,2), (110,2), (86,3), (50,1), (6,1)]),\n 'NA' : (\"MULTIEXP\", 26, 2.30, None, None, [(6, 6), (18,2), (26,3), (38,1), (50,2), (110,8), (74,2), (6,2)]),\n 'MG' : (\"MULTIEXP\", 26, 2.20, None, None, [(6, 5), (18,2), (26,2), (38,2), (50,2), (74,1), (110,2), (146,4), (110,1), (86,1), (38,2), (18,1), (6,1)]),\n 'AL' : (\"MULTIEXP\", 26, 2.10, None, None, [(6, 6), (18,2), (26,1), (38,2), (50,2), (74,1), (86,1), (146,2), (170,2), (110,2), (86,1), (74,1), (26,1), (18,1), (6,1)]),\n 'SI' : (\"MULTIEXP\", 26, 1.30, None, None, [(6, 5), (18,4), (38,4), (50,3), (74,1), (110,2), (146,1), (170,3), (86,1), (50,1), (6,1)]),\n 'P' : (\"MULTIEXP\", 26, 1.30, None, None, [(6, 5), (18,4), (38,4), (50,3), (74,1), (110,2), (146,1), (170,3), (86,1), (50,1), (6,1)]),\n 'S' : (\"MULTIEXP\", 26, 1.10, None, None, [(6, 4), (18,1), (26,8), (38,2), (50,1), (74,2), (110,1), (170,3), (146,1), (110,1), (50,1), (6,1)]),\n 'CL' : (\"MULTIEXP\", 26, 1.45, None, None, [(6, 4), (18,7), (26,2), (38,2), (50,1), (74,1), (110,2), (170,3), (146,1), (110,1), (86,1), (6,1)]),\n 'HE' : (\"HANDY\", 50, 0.5882, None, None, [(6,16), (38,5), (86,4), (194,9), (86,16), ]),\n 'NE' : (\"HANDY\", 50, 0.6838, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17), ]),\n 'AR' : (\"HANDY\", 50, 1.3333, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19), ]),\n }\n case 1:\n return 194, 50, {\n 'H' : (\"HANDY\", 50, 1.0000, None, None, [(6,16), (38,5), (86,4), (194,9), (86,16)]),\n 'HE' : (\"HANDY\", 50, 0.5882, None, None, [(6,16), (38,5), (86,4), (194,9), (86,16)]),\n 'LI' : (\"HANDY\", 50, 3.0769, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'BE' : (\"HANDY\", 50, 2.0513, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'B' : (\"HANDY\", 50, 1.5385, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'C' : (\"HANDY\", 50, 1.2308, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'N' : (\"HANDY\", 50, 1.0256, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'O' : (\"HANDY\", 50, 0.8791, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'F' : (\"HANDY\", 50, 0.7692, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'NE' : (\"HANDY\", 50, 0.6838, None, None, [(6,14), (38,7), (86,3), (194,9), (86,17)]),\n 'NA' : (\"HANDY\", 50, 4.0909, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'MG' : (\"HANDY\", 50, 3.1579, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'AL' : (\"HANDY\", 50, 2.5714, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'SI' : (\"HANDY\", 50, 2.1687, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'P' : (\"HANDY\", 50, 1.8750, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'S' : (\"HANDY\", 50, 1.6514, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'CL' : (\"HANDY\", 50, 1.4754, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n 'AR' : (\"HANDY\", 50, 1.3333, None, None, [(6,12), (38,7), (86,5), (194,7), (86,19)]),\n }\n case 2:\n return 302, 75, {\n 'H' : (\"DE2\", 75, 1.50, 15.0, 2.6, [(6,35), (110,12), (302,16), (86,7), (26,5)]),\n 'LI' : (\"DE2\", 75, 3.87, 38.7, 3.2, [(6,35), (110,12), (302,17), (86,7), (50,4)]),\n 'BE' : (\"DE2\", 75, 2.65, 26.5, 2.4, [(6,35), (110,12), (302,17), (86,7), (50,4)]),\n 'B' : (\"DE2\", 75, 2.20, 22.0, 2.4, [(6,35), (110,12), (302,17), (146,7), (26,4)]),\n 'C' : (\"DE2\", 75, 1.71, 17.1, 2.2, [(6,35), (110,12), (302,17), (146,7), (26,4)]),\n 'N' : (\"DE2\", 75, 1.41, 14.1, 2.2, [(6,35), (110,12), (302,17), (86,7), (26,4)]),\n 'O' : (\"DE2\", 75, 1.23, 12.3, 2.2, [(6,30), (110,14), (302,18), (146,8), (50,5)]),\n 'F' : (\"DE2\", 75, 1.08, 10.8, 2.2, [(6,26), (110,16), (302,19), (110,8), (50,6)]),\n 'NA' : (\"DE2\", 75, 4.21, 42.1, 3.2, [(6,35), (110,12), (302,17), (86,7), (50,4)]),\n 'MG' : (\"DE2\", 75, 3.25, 32.5, 2.4, [(6,35), (110,12), (302,17), (86,7), (50,4)]),\n 'AL' : (\"DE2\", 75, 3.43, 34.3, 2.5, [(6,32), (110,15), (302,17), (146,7), (86,4)]),\n 'SI' : (\"DE2\", 75, 2.75, 27.5, 2.3, [(6,32), (110,15), (302,17), (146,7), (50,4)]),\n 'P' : (\"DE2\", 75, 2.32, 23.2, 2.5, [(6,30), (110,14), (302,17), (146,7), (38,7)]),\n 'S' : (\"DE2\", 75, 2.06, 20.6, 2.5, [(6,30), (110,14), (302,17), (146,7), (38,7)]),\n 'CL' : (\"DE2\", 75, 1.84, 18.4, 2.5, [(6,26), (110,16), (302,19), (110,8), (50,6)]),\n }\n case 3:\n return 590, 99, {\n 'H' : (\"DE2\", 99, 1.50, 15.0, 2.7, [(6,45), (110,16), (590,21), (194,10), (50,7)]),\n 'LI' : (\"DE2\", 99, 3.87, 38.7, 3.0, [(6,46), (110,16), (590,22), (146, 9), (50,6)]),\n 'BE' : (\"DE2\", 99, 2.65, 26.5, 2.4, [(6,42), (86,6), (110,14), (590,22), (194, 3), (146, 6), (50,6)]),\n 'B' : (\"DE2\", 99, 2.20, 22.0, 2.4, [(6,42), (86,6), (110,14), (590,22), (194, 9), (50,6)]),\n 'C' : (\"DE2\", 99, 1.71, 17.1, 2.4, [(6,46), (146,16), (590,22), (302,1), (194, 2), (146, 6), (86,6)]),\n 'N' : (\"DE2\", 99, 1.41, 14.1, 2.4, [(6,40), (110,18), (590,24), (146,11), (50,6)]),\n 'O' : (\"DE2\", 99, 1.23, 12.3, 2.6, [(6,40), (110,14), (194,2), (302,2), (590,24), (302,1), (194, 1), (146, 8), (50,7)]),\n 'F' : (\"DE2\", 99, 1.08, 10.8, 2.1, [(6,35), (110,17), (194,4), (590,25), (194, 2), (110,8), (50,8)]),\n 'NA' : (\"DE2\", 99, 4.21, 42.1, 3.2, [(6,46), (110,16), (590,22), (146, 9), (50,6)]),\n 'MG' : (\"DE2\", 99, 3.25, 32.5, 2.6, [(6,48), (110,15), (590,20), (146, 7), (50,9)]),\n 'AL' : (\"DE2\", 99, 3.43, 34.3, 2.6, [(6,42), (86,6), (110,14), (590,22), (194, 3), (146, 6), (50,6)]),\n 'SI' : (\"DE2\", 99, 2.75, 27.5, 2.8, [(6,42), (86,6), (110,14), (590,22), (194, 9), (50,6)]),\n 'P' : (\"DE2\", 99, 2.32, 23.2, 2.4, [(6,35), (86,1), (110,18), (194,4), (590,25), (194, 2), (146, 8), (50,6)]),\n 'S' : (\"DE2\", 99, 2.06, 20.6, 2.4, [(6,35), (86,1), (110,18), (194,4), (590,25), (194, 2), (146, 8), (50,6)]),\n 'CL' : (\"DE2\", 99, 1.84, 18.4, 2.6, [(6,35), (110,17), (194,4), (590,25), (194, 2), (110,8), (50,8)]),\n }\n case _:\n raise RuntimeError(\"Unexpected SG grid level\")\n\n# => Helpers to generate the GRIDn family of grids <= #\n\ndef _symbol_to_ahlrichs_radius(\n *,\n symbol,\n ):\n\n symbol = symbol.upper()\n\n radii = {\n \"X\" : 1.00, \n \"H\" : 0.80,\n \"HE\" : 0.90,\n \"LI\" : 1.80,\n \"BE\" : 1.40,\n \"B\" : 1.30,\n \"C\" : 1.10,\n \"N\" : 0.90,\n \"O\" : 0.90,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._symbol_to_ahlrichs_radius","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._symbol_to_ahlrichs_radius#L300-L347","kind":"function","name":"_symbol_to_ahlrichs_radius","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":300,"end_line":347,"context_start_line":280,"context_end_line":367,"code":" 'LI' : (\"DE2\", 99, 3.87, 38.7, 3.0, [(6,46), (110,16), (590,22), (146, 9), (50,6)]),\n 'BE' : (\"DE2\", 99, 2.65, 26.5, 2.4, [(6,42), (86,6), (110,14), (590,22), (194, 3), (146, 6), (50,6)]),\n 'B' : (\"DE2\", 99, 2.20, 22.0, 2.4, [(6,42), (86,6), (110,14), (590,22), (194, 9), (50,6)]),\n 'C' : (\"DE2\", 99, 1.71, 17.1, 2.4, [(6,46), (146,16), (590,22), (302,1), (194, 2), (146, 6), (86,6)]),\n 'N' : (\"DE2\", 99, 1.41, 14.1, 2.4, [(6,40), (110,18), (590,24), (146,11), (50,6)]),\n 'O' : (\"DE2\", 99, 1.23, 12.3, 2.6, [(6,40), (110,14), (194,2), (302,2), (590,24), (302,1), (194, 1), (146, 8), (50,7)]),\n 'F' : (\"DE2\", 99, 1.08, 10.8, 2.1, [(6,35), (110,17), (194,4), (590,25), (194, 2), (110,8), (50,8)]),\n 'NA' : (\"DE2\", 99, 4.21, 42.1, 3.2, [(6,46), (110,16), (590,22), (146, 9), (50,6)]),\n 'MG' : (\"DE2\", 99, 3.25, 32.5, 2.6, [(6,48), (110,15), (590,20), (146, 7), (50,9)]),\n 'AL' : (\"DE2\", 99, 3.43, 34.3, 2.6, [(6,42), (86,6), (110,14), (590,22), (194, 3), (146, 6), (50,6)]),\n 'SI' : (\"DE2\", 99, 2.75, 27.5, 2.8, [(6,42), (86,6), (110,14), (590,22), (194, 9), (50,6)]),\n 'P' : (\"DE2\", 99, 2.32, 23.2, 2.4, [(6,35), (86,1), (110,18), (194,4), (590,25), (194, 2), (146, 8), (50,6)]),\n 'S' : (\"DE2\", 99, 2.06, 20.6, 2.4, [(6,35), (86,1), (110,18), (194,4), (590,25), (194, 2), (146, 8), (50,6)]),\n 'CL' : (\"DE2\", 99, 1.84, 18.4, 2.6, [(6,35), (110,17), (194,4), (590,25), (194, 2), (110,8), (50,8)]),\n }\n case _:\n raise RuntimeError(\"Unexpected SG grid level\")\n\n# => Helpers to generate the GRIDn family of grids <= #\n\ndef _symbol_to_ahlrichs_radius(\n *,\n symbol,\n ):\n\n symbol = symbol.upper()\n\n radii = {\n \"X\" : 1.00, \n \"H\" : 0.80,\n \"HE\" : 0.90,\n \"LI\" : 1.80,\n \"BE\" : 1.40,\n \"B\" : 1.30,\n \"C\" : 1.10,\n \"N\" : 0.90,\n \"O\" : 0.90,\n \"F\" : 0.90,\n \"NE\" : 0.90,\n \"NA\" : 1.40,\n \"MG\" : 1.30,\n \"AL\" : 1.30,\n \"SI\" : 1.20,\n \"P\" : 1.10,\n \"S\" : 1.00,\n \"CL\" : 1.00,\n \"AR\" : 1.00,\n \"K\" : 1.50,\n \"CA\" : 1.40,\n \"SC\" : 1.30,\n \"TI\" : 1.20,\n \"V\" : 1.20,\n \"CR\" : 1.20,\n \"MN\" : 1.20,\n \"FE\" : 1.20,\n \"CO\" : 1.20,\n \"NI\" : 1.10,\n \"CU\" : 1.10,\n \"ZN\" : 1.10,\n \"GA\" : 1.10,\n \"GE\" : 1.00,\n \"AS\" : 0.90,\n \"SE\" : 0.90,\n \"BR\" : 0.90,\n \"KR\" : 0.90,\n }\n\n return radii.get(symbol, 1.0)\n\n\ndef _build_ahlrichs_radial_quadrature(\n *,\n npoint,\n R,\n ):\n\n alpha = 0.6\n\n n = np.arange(1.0, npoint+1.0)\n z = n * np.pi / (npoint + 1.0)\n x = np.cos(z)\n y = np.sin(z)\n u = np.log((1.0 - x) / 2.0)\n v = ((1.0 + x)**alpha) / np.log(2.0)\n radial_nodes = - R * v * u\n radial_weights = np.pi / (npoint + 1.0) * y * R * v * (-alpha * u / (1.0 + x) + 1.0 / (1.0 - x)) * radial_nodes**2\n\n return np.flip(radial_nodes).tolist(), np.flip(radial_weights).tolist()","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._build_ahlrichs_radial_quadrature","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._build_ahlrichs_radial_quadrature#L350-L367","kind":"function","name":"_build_ahlrichs_radial_quadrature","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":350,"end_line":367,"context_start_line":330,"context_end_line":387,"code":" \"TI\" : 1.20,\n \"V\" : 1.20,\n \"CR\" : 1.20,\n \"MN\" : 1.20,\n \"FE\" : 1.20,\n \"CO\" : 1.20,\n \"NI\" : 1.10,\n \"CU\" : 1.10,\n \"ZN\" : 1.10,\n \"GA\" : 1.10,\n \"GE\" : 1.00,\n \"AS\" : 0.90,\n \"SE\" : 0.90,\n \"BR\" : 0.90,\n \"KR\" : 0.90,\n }\n\n return radii.get(symbol, 1.0)\n\n\ndef _build_ahlrichs_radial_quadrature(\n *,\n npoint,\n R,\n ):\n\n alpha = 0.6\n\n n = np.arange(1.0, npoint+1.0)\n z = n * np.pi / (npoint + 1.0)\n x = np.cos(z)\n y = np.sin(z)\n u = np.log((1.0 - x) / 2.0)\n v = ((1.0 + x)**alpha) / np.log(2.0)\n radial_nodes = - R * v * u\n radial_weights = np.pi / (npoint + 1.0) * y * R * v * (-alpha * u / (1.0 + x) + 1.0 / (1.0 - x)) * radial_nodes**2\n\n return np.flip(radial_nodes).tolist(), np.flip(radial_weights).tolist()\n\n\ndef _get_grid_pruning_pattern(grid_level):\n match grid_level:\n case 1:\n return 194, 50, {\n 'H' : [(14,6), (50,4), (50,10) ],\n 'HE' : [(14,6), (50,4), (50,10) ],\n 'LI' : [(14,8), (50,4), (110,13)],\n 'BE' : [(14,8), (50,4), (110,13)],\n 'B' : [(14,8), (50,4), (110,13)],\n 'C' : [(14,8), (50,4), (110,13)],\n 'N' : [(14,8), (50,4), (110,13)],\n 'O' : [(14,8), (50,4), (110,13)],\n 'F' : [(14,8), (50,4), (110,13)],\n 'NE' : [(14,8), (50,4), (110,13)],\n 'NA' : [(14,10), (50,5), (110,15)],\n 'MG' : [(14,10), (50,5), (110,15)],\n 'AL' : [(14,10), (50,5), (110,15)],\n 'SI' : [(14,10), (50,5), (110,15)],","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._get_grid_pruning_pattern","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid._get_grid_pruning_pattern#L370-L568","kind":"function","name":"_get_grid_pruning_pattern","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":370,"end_line":568,"context_start_line":350,"context_end_line":588,"code":"def _build_ahlrichs_radial_quadrature(\n *,\n npoint,\n R,\n ):\n\n alpha = 0.6\n\n n = np.arange(1.0, npoint+1.0)\n z = n * np.pi / (npoint + 1.0)\n x = np.cos(z)\n y = np.sin(z)\n u = np.log((1.0 - x) / 2.0)\n v = ((1.0 + x)**alpha) / np.log(2.0)\n radial_nodes = - R * v * u\n radial_weights = np.pi / (npoint + 1.0) * y * R * v * (-alpha * u / (1.0 + x) + 1.0 / (1.0 - x)) * radial_nodes**2\n\n return np.flip(radial_nodes).tolist(), np.flip(radial_weights).tolist()\n\n\ndef _get_grid_pruning_pattern(grid_level):\n match grid_level:\n case 1:\n return 194, 50, {\n 'H' : [(14,6), (50,4), (50,10) ],\n 'HE' : [(14,6), (50,4), (50,10) ],\n 'LI' : [(14,8), (50,4), (110,13)],\n 'BE' : [(14,8), (50,4), (110,13)],\n 'B' : [(14,8), (50,4), (110,13)],\n 'C' : [(14,8), (50,4), (110,13)],\n 'N' : [(14,8), (50,4), (110,13)],\n 'O' : [(14,8), (50,4), (110,13)],\n 'F' : [(14,8), (50,4), (110,13)],\n 'NE' : [(14,8), (50,4), (110,13)],\n 'NA' : [(14,10), (50,5), (110,15)],\n 'MG' : [(14,10), (50,5), (110,15)],\n 'AL' : [(14,10), (50,5), (110,15)],\n 'SI' : [(14,10), (50,5), (110,15)],\n 'P' : [(14,10), (50,5), (110,15)],\n 'S' : [(14,10), (50,5), (110,15)],\n 'CL' : [(14,10), (50,5), (110,15)],\n 'AR' : [(14,10), (50,5), (110,15)],\n 'K' : [(14,11), (50,6), (110,18)],\n 'CA' : [(14,11), (50,6), (110,18)],\n 'SC' : [(14,11), (50,6), (110,18)],\n 'TI' : [(14,11), (50,6), (110,18)],\n 'V' : [(14,11), (50,6), (110,18)],\n 'CR' : [(14,11), (50,6), (110,18)],\n 'MN' : [(14,11), (50,6), (110,18)],\n 'FE' : [(14,11), (50,6), (110,18)],\n 'CO' : [(14,11), (50,6), (110,18)],\n 'NI' : [(14,11), (50,6), (110,18)],\n 'CU' : [(14,11), (50,6), (110,18)],\n 'ZN' : [(14,11), (50,6), (110,18)],\n 'GA' : [(14,11), (50,6), (110,18)],\n 'GE' : [(14,11), (50,6), (110,18)],\n 'AS' : [(14,11), (50,6), (110,18)],\n 'SE' : [(14,11), (50,6), (110,18)],\n 'BR' : [(14,11), (50,6), (110,18)],\n 'KR' : [(14,11), (50,6), (110,18)],\n }\n case 2:\n return 302, 55, {\n 'H' : [(14,8), (50,4), (110,13)],\n 'HE' : [(14,8), (50,4), (110,13)],\n 'LI' : [(14,10), (50,5), (194,15)],\n 'BE' : [(14,10), (50,5), (194,15)],\n 'B' : [(14,10), (50,5), (194,15)],\n 'C' : [(14,10), (50,5), (194,15)],\n 'N' : [(14,10), (50,5), (194,15)],\n 'O' : [(14,10), (50,5), (194,15)],\n 'F' : [(14,10), (50,5), (194,15)],\n 'NE' : [(14,10), (50,5), (194,15)],\n 'NA' : [(14,11), (50,6), (194,18)],\n 'MG' : [(14,11), (50,6), (194,18)],\n 'AL' : [(14,11), (50,6), (194,18)],\n 'SI' : [(14,11), (50,6), (194,18)],\n 'P' : [(14,11), (50,6), (194,18)],\n 'S' : [(14,11), (50,6), (194,18)],\n 'CL' : [(14,11), (50,6), (194,18)],\n 'AR' : [(14,11), (50,6), (194,18)],\n 'K' : [(14,13), (50,7), (194,20)],\n 'CA' : [(14,13), (50,7), (194,20)],\n 'SC' : [(14,13), (50,7), (194,20)],\n 'TI' : [(14,13), (50,7), (194,20)],\n 'V' : [(14,13), (50,7), (194,20)],\n 'CR' : [(14,13), (50,7), (194,20)],\n 'MN' : [(14,13), (50,7), (194,20)],\n 'FE' : [(14,13), (50,7), (194,20)],\n 'CO' : [(14,13), (50,7), (194,20)],\n 'NI' : [(14,13), (50,7), (194,20)],\n 'CU' : [(14,13), (50,7), (194,20)],\n 'ZN' : [(14,13), (50,7), (194,20)],\n 'GA' : [(14,13), (50,7), (194,20)],\n 'GE' : [(14,13), (50,7), (194,20)],\n 'AS' : [(14,13), (50,7), (194,20)],\n 'SE' : [(14,13), (50,7), (194,20)],\n 'BR' : [(14,13), (50,7), (194,20)],\n 'KR' : [(14,13), (50,7), (194,20)],\n }\n case 3:\n return 434, 60, {\n 'H' : [(14,10), (50,5), (194,15)],\n 'HE' : [(14,10), (50,5), (194,15)],\n 'LI' : [(14,11), (50,6), (302,18)],\n 'BE' : [(14,11), (50,6), (302,18)],\n 'B' : [(14,11), (50,6), (302,18)],\n 'C' : [(14,11), (50,6), (302,18)],\n 'N' : [(14,11), (50,6), (302,18)],\n 'O' : [(14,11), (50,6), (302,18)],\n 'F' : [(14,11), (50,6), (302,18)],\n 'NE' : [(14,11), (50,6), (302,18)],\n 'NA' : [(14,13), (50,7), (302,20)],\n 'MG' : [(14,13), (50,7), (302,20)],\n 'AL' : [(14,13), (50,7), (302,20)],\n 'SI' : [(14,13), (50,7), (302,20)],\n 'P' : [(14,13), (50,7), (302,20)],\n 'S' : [(14,13), (50,7), (302,20)],\n 'CL' : [(14,13), (50,7), (302,20)],\n 'AR' : [(14,13), (50,7), (302,20)],\n 'K' : [(14,15), (50,7), (302,23)],\n 'CA' : [(14,15), (50,7), (302,23)],\n 'SC' : [(14,15), (50,7), (302,23)],\n 'TI' : [(14,15), (50,7), (302,23)],\n 'V' : [(14,15), (50,7), (302,23)],\n 'CR' : [(14,15), (50,7), (302,23)],\n 'MN' : [(14,15), (50,7), (302,23)],\n 'FE' : [(14,15), (50,7), (302,23)],\n 'CO' : [(14,15), (50,7), (302,23)],\n 'NI' : [(14,15), (50,7), (302,23)],\n 'CU' : [(14,15), (50,7), (302,23)],\n 'ZN' : [(14,15), (50,7), (302,23)],\n 'GA' : [(14,15), (50,7), (302,23)],\n 'GE' : [(14,15), (50,7), (302,23)],\n 'AS' : [(14,15), (50,7), (302,23)],\n 'SE' : [(14,15), (50,7), (302,23)],\n 'BR' : [(14,15), (50,7), (302,23)],\n 'KR' : [(14,15), (50,7), (302,23)],\n }\n case 4:\n return 770, 65, {\n 'H' : [(14,11), (50,6), (302,18)],\n 'HE' : [(14,11), (50,6), (302,18)],\n 'LI' : [(14,13), (50,7), (434,20)],\n 'BE' : [(14,13), (50,7), (434,20)],\n 'B' : [(14,13), (50,7), (434,20)],\n 'C' : [(14,13), (50,7), (434,20)],\n 'N' : [(14,13), (50,7), (434,20)],\n 'O' : [(14,13), (50,7), (434,20)],\n 'F' : [(14,13), (50,7), (434,20)],\n 'NE' : [(14,13), (50,7), (434,20)],\n 'NA' : [(14,15), (50,7), (434,23)],\n 'MG' : [(14,15), (50,7), (434,23)],\n 'AL' : [(14,15), (50,7), (434,23)],\n 'SI' : [(14,15), (50,7), (434,23)],\n 'P' : [(14,15), (50,7), (434,23)],\n 'S' : [(14,15), (50,7), (434,23)],\n 'CL' : [(14,15), (50,7), (434,23)],\n 'AR' : [(14,15), (50,7), (434,23)],\n 'K' : [(14,16), (50,9), (434,25)],\n 'CA' : [(14,16), (50,9), (434,25)],\n 'SC' : [(14,16), (50,9), (434,25)],\n 'TI' : [(14,16), (50,9), (434,25)],\n 'V' : [(14,16), (50,9), (434,25)],\n 'CR' : [(14,16), (50,9), (434,25)],\n 'MN' : [(14,16), (50,9), (434,25)],\n 'FE' : [(14,16), (50,9), (434,25)],\n 'CO' : [(14,16), (50,9), (434,25)],\n 'NI' : [(14,16), (50,9), (434,25)],\n 'CU' : [(14,16), (50,9), (434,25)],\n 'ZN' : [(14,16), (50,9), (434,25)],\n 'GA' : [(14,16), (50,9), (434,25)],\n 'GE' : [(14,16), (50,9), (434,25)],\n 'AS' : [(14,16), (50,9), (434,25)],\n 'SE' : [(14,16), (50,9), (434,25)],\n 'BR' : [(14,16), (50,9), (434,25)],\n 'KR' : [(14,16), (50,9), (434,25)],\n }\n case 5:\n return 1202, 75, {\n 'H' : [(14,15), (50,7), (434,23)],\n 'HE' : [(14,15), (50,7), (434,23)],\n 'LI' : [(14,16), (50,9), (770,25)],\n 'BE' : [(14,16), (50,9), (770,25)],\n 'B' : [(14,16), (50,9), (770,25)],\n 'C' : [(14,16), (50,9), (770,25)],\n 'N' : [(14,16), (50,9), (770,25)],\n 'O' : [(14,16), (50,9), (770,25)],\n 'F' : [(14,16), (50,9), (770,25)],\n 'NE' : [(14,16), (50,9), (770,25)],\n 'NA' : [(14,18), (50,9), (770,28)],\n 'MG' : [(14,18), (50,9), (770,28)],\n 'AL' : [(14,18), (50,9), (770,28)],\n 'SI' : [(14,18), (50,9), (770,28)],\n 'P' : [(14,18), (50,9), (770,28)],\n 'S' : [(14,18), (50,9), (770,28)],\n 'CL' : [(14,18), (50,9), (770,28)],\n 'AR' : [(14,18), (50,9), (770,28)],\n 'K' : [(14,20), (50,10), (770,30)],\n 'CA' : [(14,20), (50,10), (770,30)],\n 'SC' : [(14,20), (50,10), (770,30)],\n 'TI' : [(14,20), (50,10), (770,30)],\n 'V' : [(14,20), (50,10), (770,30)],\n 'CR' : [(14,20), (50,10), (770,30)],\n 'MN' : [(14,20), (50,10), (770,30)],\n 'FE' : [(14,20), (50,10), (770,30)],\n 'CO' : [(14,20), (50,10), (770,30)],\n 'NI' : [(14,20), (50,10), (770,30)],\n 'CU' : [(14,20), (50,10), (770,30)],\n 'ZN' : [(14,20), (50,10), (770,30)],\n 'GA' : [(14,20), (50,10), (770,30)],\n 'GE' : [(14,20), (50,10), (770,30)],\n 'AS' : [(14,20), (50,10), (770,30)],\n 'SE' : [(14,20), (50,10), (770,30)],\n 'BR' : [(14,20), (50,10), (770,30)],\n 'KR' : [(14,20), (50,10), (770,30)],\n }\n case _:\n raise RuntimeError(\"Unexpected grid level\")\n\n\nclass CuestAtomGridList(object):\n\n def __init__(self):\n self.handles = []\n\n def append(self, handle):\n self.handles.append(handle)\n\n def __del__(self):\n for handle in self.handles:\n status = ce.cuestAtomGridDestroy(atomGrid=handle)\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAtomGridDestroy failed')\n\n\nclass CuestMolecularGrid(object):\n \"\"\"\n Builds integration grids according to one of two pruning schemes:","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.CuestAtomGridList","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.CuestAtomGridList#L571-L583","kind":"class","name":"CuestAtomGridList","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":571,"end_line":583,"context_start_line":551,"context_end_line":603,"code":" 'TI' : [(14,20), (50,10), (770,30)],\n 'V' : [(14,20), (50,10), (770,30)],\n 'CR' : [(14,20), (50,10), (770,30)],\n 'MN' : [(14,20), (50,10), (770,30)],\n 'FE' : [(14,20), (50,10), (770,30)],\n 'CO' : [(14,20), (50,10), (770,30)],\n 'NI' : [(14,20), (50,10), (770,30)],\n 'CU' : [(14,20), (50,10), (770,30)],\n 'ZN' : [(14,20), (50,10), (770,30)],\n 'GA' : [(14,20), (50,10), (770,30)],\n 'GE' : [(14,20), (50,10), (770,30)],\n 'AS' : [(14,20), (50,10), (770,30)],\n 'SE' : [(14,20), (50,10), (770,30)],\n 'BR' : [(14,20), (50,10), (770,30)],\n 'KR' : [(14,20), (50,10), (770,30)],\n }\n case _:\n raise RuntimeError(\"Unexpected grid level\")\n\n\nclass CuestAtomGridList(object):\n\n def __init__(self):\n self.handles = []\n\n def append(self, handle):\n self.handles.append(handle)\n\n def __del__(self):\n for handle in self.handles:\n status = ce.cuestAtomGridDestroy(atomGrid=handle)\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAtomGridDestroy failed')\n\n\nclass CuestMolecularGrid(object):\n \"\"\"\n Builds integration grids according to one of two pruning schemes:\n\n family = GRID: The GRIDn pruning scheme\n * O. Treutler and R. Ahlrichs, J. Chem. Phys., 102, 346 (1995) \n where valid values are 1 <= n <= 5, where larger numbers yield larger grids.\n\n family = SG: The SGn pruning scheme\n * S-H. Chien, P.M.W. Gill, J. Comput. Chem., 27, 730 (2006)\n * P.M.W. Gill, B.G. Johnson, J.A. Pople, Chem. Phys. Lett., 209(5-6), 506 (1993)\n * S. Dasgupta and J. M. HerbertJ. Comput. Chem., 38, 869 (2017)\n where valid values are 0 <= n <= 3, where larger numbers yield larger grids.\n \"\"\"\n def __init__(\n self,\n *,\n handle : CuestHandle,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.CuestMolecularGrid","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.CuestMolecularGrid#L586-L845","kind":"class","name":"CuestMolecularGrid","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":586,"end_line":845,"context_start_line":566,"context_end_line":846,"code":" }\n case _:\n raise RuntimeError(\"Unexpected grid level\")\n\n\nclass CuestAtomGridList(object):\n\n def __init__(self):\n self.handles = []\n\n def append(self, handle):\n self.handles.append(handle)\n\n def __del__(self):\n for handle in self.handles:\n status = ce.cuestAtomGridDestroy(atomGrid=handle)\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAtomGridDestroy failed')\n\n\nclass CuestMolecularGrid(object):\n \"\"\"\n Builds integration grids according to one of two pruning schemes:\n\n family = GRID: The GRIDn pruning scheme\n * O. Treutler and R. Ahlrichs, J. Chem. Phys., 102, 346 (1995) \n where valid values are 1 <= n <= 5, where larger numbers yield larger grids.\n\n family = SG: The SGn pruning scheme\n * S-H. Chien, P.M.W. Gill, J. Comput. Chem., 27, 730 (2006)\n * P.M.W. Gill, B.G. Johnson, J.A. Pople, Chem. Phys. Lett., 209(5-6), 506 (1993)\n * S. Dasgupta and J. M. HerbertJ. Comput. Chem., 38, 869 (2017)\n where valid values are 0 <= n <= 3, where larger numbers yield larger grids.\n \"\"\"\n def __init__(\n self,\n *,\n handle : CuestHandle,\n grid_level : int,\n xyz : np.ndarray,\n Ns : list[int],\n family=\"GRID\",\n ):\n\n self.initialized = False\n family = family.upper()\n\n supported_families = [\"GRID\", \"SG\"]\n if family not in supported_families:\n raise RuntimeError(f\"Unrecognized grid family '{family}'. Supported values are {', '.join(supported_families)}\")\n\n if family == \"GRID\":\n if grid_level < 1 or grid_level > 5:\n raise RuntimeError(\"Only grid_level 1 to 5 (inclusive) is supported for the GRID family\")\n self.grid_name = f'GRID{grid_level}'\n default_n_angular, default_n_radial, pruning_map = _get_grid_pruning_pattern(grid_level)\n else:\n if grid_level < 0 or grid_level > 3:\n raise RuntimeError(\"Only grid_level 0 to 3 (inclusive) is supported for the SG family\")\n default_n_angular, default_n_radial, pruning_map = _get_sg_pruning_pattern(grid_level)\n self.grid_name = f'SG{grid_level}'\n\n self.handle = handle\n\n atomgrid_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS)\n\n atomgrids = CuestAtomGridList()\n for atom,N in enumerate(Ns):\n symbol_upper = PeriodicTable.N_to_symbol_upper_table[N]\n if family == 'GRID':\n # GRIDn family\n ahlrichs_radius = _symbol_to_ahlrichs_radius(\n symbol=symbol_upper,\n )\n if symbol_upper in pruning_map:\n num_angular_points = []\n for n_angular, reps in pruning_map[symbol_upper]:\n num_angular_points.extend([n_angular]*reps)\n else:\n num_angular_points = [default_n_angular] * default_n_radial\n\n radial_nodes, radial_weights = _build_ahlrichs_radial_quadrature(\n npoint=len(num_angular_points),\n R=ahlrichs_radius,\n )\n else:\n # SGn family\n if symbol_upper in pruning_map:\n num_angular_points = []\n radial_quadrature_type, npoints, R, r_end, alpha, n_angular_and_reps = pruning_map[symbol_upper]\n for n_angular, reps in n_angular_and_reps:\n num_angular_points.extend([n_angular]*reps)\n if radial_quadrature_type == \"HANDY\":\n radial_nodes, radial_weights = _build_handy_radial_quadrature(\n npoint=npoints,\n R=R,\n )\n elif radial_quadrature_type == \"MULTIEXP\":\n radial_nodes, radial_weights = _build_multiexp_radial_quadrature(\n npoint=npoints,\n R=R,\n )\n elif radial_quadrature_type == \"DE2\":\n radial_nodes, radial_weights = _build_de2_radial_quadrature(\n npoint=npoints,\n R=R,\n r_start=1e-7,\n r_end=r_end,\n alpha=alpha,\n )\n else:\n raise RuntimeError(\"Unexpected radial quadrature type\")\n else:\n # For atoms without an explicit spec we build an unpruned Euler-Maclaurin grid\n num_angular_points = [default_n_angular] * default_n_radial\n\n R = _symbol_to_handy_radius(symbol_upper)\n radial_nodes, radial_weights = _build_handy_radial_quadrature(\n npoint=default_n_radial,\n R=R,\n )\n\n atomgrid_handle = ce.cuestAtomGridHandle()\n status = ce.cuestAtomGridCreate(\n handle=handle.handle,\n numRadialPoints=len(num_angular_points),\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters.parameters,\n outAtomGrid=atomgrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAtomGridCreate failed')\n atomgrids.append(atomgrid_handle)\n\n del atomgrid_parameters\n\n moleculargrid_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS)\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=handle.handle,\n numAtoms=len(Ns),\n atomGrid=atomgrids.handles,\n xyz=list(xyz.ravel()),\n parameters=moleculargrid_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularGridCreateWorkspaceQuery failed')\n\n grid_persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n self.moleculargrid_handle = ce.cuestMolecularGridHandle()\n\n status = ce.cuestMolecularGridCreate(\n handle=handle.handle,\n numAtoms=len(Ns),\n atomGrid=atomgrids.handles,\n xyz=list(xyz.ravel()),\n parameters=moleculargrid_parameters.parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=self.moleculargrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularGridCreate failed')\n\n del moleculargrid_parameters\n del grid_temporary_workspace\n del atomgrids\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = grid_persistent_workspace\n\n self.initialized = True\n\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestMolecularGridDestroy(\n grid=self.moleculargrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularDestroy failed')\n\n @memoized_property\n def natom(self):\n natom = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_ATOM,\n attributeValue=natom,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return natom.value\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def max_point(self):\n max_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_POINT,\n attributeValue=max_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_point.value\n\n @memoized_property\n def max_radial_point(self):\n max_radial_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_RADIAL_POINT,\n attributeValue=max_radial_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_radial_point.value\n\n @memoized_property\n def max_angular_point(self):\n max_angular_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_ANGULAR_POINT,\n attributeValue=max_angular_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_angular_point.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'MolecularGrid:\\n'\n s += '%-18s = %10s\\n' % ('scheme name', self.grid_name)\n s += '%-18s = %10d\\n' % ('natom', self.natom)\n s += '%-18s = %10d\\n' % ('atomic max npoint', self.max_point)\n s += '%-18s = %10d\\n' % ('radial max npoint', self.max_radial_point)\n s += '%-18s = %10d\\n' % ('angular max npoint', self.max_angular_point)\n s += '%-18s = %10d\\n' % ('total npoint', self.npoint)\n return s\n","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.__init__#L600-L747","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":600,"end_line":747,"context_start_line":580,"context_end_line":767,"code":" for handle in self.handles:\n status = ce.cuestAtomGridDestroy(atomGrid=handle)\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAtomGridDestroy failed')\n\n\nclass CuestMolecularGrid(object):\n \"\"\"\n Builds integration grids according to one of two pruning schemes:\n\n family = GRID: The GRIDn pruning scheme\n * O. Treutler and R. Ahlrichs, J. Chem. Phys., 102, 346 (1995) \n where valid values are 1 <= n <= 5, where larger numbers yield larger grids.\n\n family = SG: The SGn pruning scheme\n * S-H. Chien, P.M.W. Gill, J. Comput. Chem., 27, 730 (2006)\n * P.M.W. Gill, B.G. Johnson, J.A. Pople, Chem. Phys. Lett., 209(5-6), 506 (1993)\n * S. Dasgupta and J. M. HerbertJ. Comput. Chem., 38, 869 (2017)\n where valid values are 0 <= n <= 3, where larger numbers yield larger grids.\n \"\"\"\n def __init__(\n self,\n *,\n handle : CuestHandle,\n grid_level : int,\n xyz : np.ndarray,\n Ns : list[int],\n family=\"GRID\",\n ):\n\n self.initialized = False\n family = family.upper()\n\n supported_families = [\"GRID\", \"SG\"]\n if family not in supported_families:\n raise RuntimeError(f\"Unrecognized grid family '{family}'. Supported values are {', '.join(supported_families)}\")\n\n if family == \"GRID\":\n if grid_level < 1 or grid_level > 5:\n raise RuntimeError(\"Only grid_level 1 to 5 (inclusive) is supported for the GRID family\")\n self.grid_name = f'GRID{grid_level}'\n default_n_angular, default_n_radial, pruning_map = _get_grid_pruning_pattern(grid_level)\n else:\n if grid_level < 0 or grid_level > 3:\n raise RuntimeError(\"Only grid_level 0 to 3 (inclusive) is supported for the SG family\")\n default_n_angular, default_n_radial, pruning_map = _get_sg_pruning_pattern(grid_level)\n self.grid_name = f'SG{grid_level}'\n\n self.handle = handle\n\n atomgrid_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_ATOMGRID_PARAMETERS)\n\n atomgrids = CuestAtomGridList()\n for atom,N in enumerate(Ns):\n symbol_upper = PeriodicTable.N_to_symbol_upper_table[N]\n if family == 'GRID':\n # GRIDn family\n ahlrichs_radius = _symbol_to_ahlrichs_radius(\n symbol=symbol_upper,\n )\n if symbol_upper in pruning_map:\n num_angular_points = []\n for n_angular, reps in pruning_map[symbol_upper]:\n num_angular_points.extend([n_angular]*reps)\n else:\n num_angular_points = [default_n_angular] * default_n_radial\n\n radial_nodes, radial_weights = _build_ahlrichs_radial_quadrature(\n npoint=len(num_angular_points),\n R=ahlrichs_radius,\n )\n else:\n # SGn family\n if symbol_upper in pruning_map:\n num_angular_points = []\n radial_quadrature_type, npoints, R, r_end, alpha, n_angular_and_reps = pruning_map[symbol_upper]\n for n_angular, reps in n_angular_and_reps:\n num_angular_points.extend([n_angular]*reps)\n if radial_quadrature_type == \"HANDY\":\n radial_nodes, radial_weights = _build_handy_radial_quadrature(\n npoint=npoints,\n R=R,\n )\n elif radial_quadrature_type == \"MULTIEXP\":\n radial_nodes, radial_weights = _build_multiexp_radial_quadrature(\n npoint=npoints,\n R=R,\n )\n elif radial_quadrature_type == \"DE2\":\n radial_nodes, radial_weights = _build_de2_radial_quadrature(\n npoint=npoints,\n R=R,\n r_start=1e-7,\n r_end=r_end,\n alpha=alpha,\n )\n else:\n raise RuntimeError(\"Unexpected radial quadrature type\")\n else:\n # For atoms without an explicit spec we build an unpruned Euler-Maclaurin grid\n num_angular_points = [default_n_angular] * default_n_radial\n\n R = _symbol_to_handy_radius(symbol_upper)\n radial_nodes, radial_weights = _build_handy_radial_quadrature(\n npoint=default_n_radial,\n R=R,\n )\n\n atomgrid_handle = ce.cuestAtomGridHandle()\n status = ce.cuestAtomGridCreate(\n handle=handle.handle,\n numRadialPoints=len(num_angular_points),\n radialNodes=radial_nodes,\n radialWeights=radial_weights,\n numAngularPoints=num_angular_points,\n parameters=atomgrid_parameters.parameters,\n outAtomGrid=atomgrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAtomGridCreate failed')\n atomgrids.append(atomgrid_handle)\n\n del atomgrid_parameters\n\n moleculargrid_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_MOLECULARGRID_PARAMETERS)\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestMolecularGridCreateWorkspaceQuery(\n handle=handle.handle,\n numAtoms=len(Ns),\n atomGrid=atomgrids.handles,\n xyz=list(xyz.ravel()),\n parameters=moleculargrid_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outGrid=ce.cuestMolecularGridHandle(),\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularGridCreateWorkspaceQuery failed')\n\n grid_persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n grid_temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n self.moleculargrid_handle = ce.cuestMolecularGridHandle()\n\n status = ce.cuestMolecularGridCreate(\n handle=handle.handle,\n numAtoms=len(Ns),\n atomGrid=atomgrids.handles,\n xyz=list(xyz.ravel()),\n parameters=moleculargrid_parameters.parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=self.moleculargrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularGridCreate failed')\n\n del moleculargrid_parameters\n del grid_temporary_workspace\n del atomgrids\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = grid_persistent_workspace\n\n self.initialized = True\n\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestMolecularGridDestroy(\n grid=self.moleculargrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularDestroy failed')\n\n @memoized_property\n def natom(self):\n natom = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_ATOM,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.append","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.append#L576-L577","kind":"function","name":"append","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":576,"end_line":577,"context_start_line":556,"context_end_line":597,"code":" 'CO' : [(14,20), (50,10), (770,30)],\n 'NI' : [(14,20), (50,10), (770,30)],\n 'CU' : [(14,20), (50,10), (770,30)],\n 'ZN' : [(14,20), (50,10), (770,30)],\n 'GA' : [(14,20), (50,10), (770,30)],\n 'GE' : [(14,20), (50,10), (770,30)],\n 'AS' : [(14,20), (50,10), (770,30)],\n 'SE' : [(14,20), (50,10), (770,30)],\n 'BR' : [(14,20), (50,10), (770,30)],\n 'KR' : [(14,20), (50,10), (770,30)],\n }\n case _:\n raise RuntimeError(\"Unexpected grid level\")\n\n\nclass CuestAtomGridList(object):\n\n def __init__(self):\n self.handles = []\n\n def append(self, handle):\n self.handles.append(handle)\n\n def __del__(self):\n for handle in self.handles:\n status = ce.cuestAtomGridDestroy(atomGrid=handle)\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAtomGridDestroy failed')\n\n\nclass CuestMolecularGrid(object):\n \"\"\"\n Builds integration grids according to one of two pruning schemes:\n\n family = GRID: The GRIDn pruning scheme\n * O. Treutler and R. Ahlrichs, J. Chem. Phys., 102, 346 (1995) \n where valid values are 1 <= n <= 5, where larger numbers yield larger grids.\n\n family = SG: The SGn pruning scheme\n * S-H. Chien, P.M.W. Gill, J. Comput. Chem., 27, 730 (2006)\n * P.M.W. Gill, B.G. Johnson, J.A. Pople, Chem. Phys. Lett., 209(5-6), 506 (1993)\n * S. Dasgupta and J. M. HerbertJ. Comput. Chem., 38, 869 (2017)","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.__del__#L750-L758","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":750,"end_line":758,"context_start_line":730,"context_end_line":778,"code":" atomGrid=atomgrids.handles,\n xyz=list(xyz.ravel()),\n parameters=moleculargrid_parameters.parameters,\n persistentWorkspace=grid_persistent_workspace.pointer,\n temporaryWorkspace=grid_temporary_workspace.pointer,\n outGrid=self.moleculargrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularGridCreate failed')\n\n del moleculargrid_parameters\n del grid_temporary_workspace\n del atomgrids\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = grid_persistent_workspace\n\n self.initialized = True\n\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestMolecularGridDestroy(\n grid=self.moleculargrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularDestroy failed')\n\n @memoized_property\n def natom(self):\n natom = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_ATOM,\n attributeValue=natom,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return natom.value\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.natom","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.natom#L761-L772","kind":"function","name":"natom","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":761,"end_line":772,"context_start_line":741,"context_end_line":792,"code":" del grid_temporary_workspace\n del atomgrids\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = grid_persistent_workspace\n\n self.initialized = True\n\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestMolecularGridDestroy(\n grid=self.moleculargrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularDestroy failed')\n\n @memoized_property\n def natom(self):\n natom = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_ATOM,\n attributeValue=natom,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return natom.value\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def max_point(self):\n max_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.npoint","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.npoint#L775-L786","kind":"function","name":"npoint","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":775,"end_line":786,"context_start_line":755,"context_end_line":806,"code":" grid=self.moleculargrid_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestMolecularDestroy failed')\n\n @memoized_property\n def natom(self):\n natom = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_ATOM,\n attributeValue=natom,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return natom.value\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def max_point(self):\n max_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_POINT,\n attributeValue=max_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_point.value\n\n @memoized_property\n def max_radial_point(self):\n max_radial_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.max_point","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.max_point#L789-L800","kind":"function","name":"max_point","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":789,"end_line":800,"context_start_line":769,"context_end_line":820,"code":" )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return natom.value\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def max_point(self):\n max_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_POINT,\n attributeValue=max_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_point.value\n\n @memoized_property\n def max_radial_point(self):\n max_radial_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_RADIAL_POINT,\n attributeValue=max_radial_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_radial_point.value\n\n @memoized_property\n def max_angular_point(self):\n max_angular_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.max_radial_point","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.max_radial_point#L803-L814","kind":"function","name":"max_radial_point","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":803,"end_line":814,"context_start_line":783,"context_end_line":834,"code":" )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def max_point(self):\n max_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_POINT,\n attributeValue=max_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_point.value\n\n @memoized_property\n def max_radial_point(self):\n max_radial_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_RADIAL_POINT,\n attributeValue=max_radial_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_radial_point.value\n\n @memoized_property\n def max_angular_point(self):\n max_angular_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_ANGULAR_POINT,\n attributeValue=max_angular_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_angular_point.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.max_angular_point","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.max_angular_point#L817-L828","kind":"function","name":"max_angular_point","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":817,"end_line":828,"context_start_line":797,"context_end_line":846,"code":" )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_point.value\n\n @memoized_property\n def max_radial_point(self):\n max_radial_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_RADIAL_POINT,\n attributeValue=max_radial_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_radial_point.value\n\n @memoized_property\n def max_angular_point(self):\n max_angular_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_ANGULAR_POINT,\n attributeValue=max_angular_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_angular_point.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'MolecularGrid:\\n'\n s += '%-18s = %10s\\n' % ('scheme name', self.grid_name)\n s += '%-18s = %10d\\n' % ('natom', self.natom)\n s += '%-18s = %10d\\n' % ('atomic max npoint', self.max_point)\n s += '%-18s = %10d\\n' % ('radial max npoint', self.max_radial_point)\n s += '%-18s = %10d\\n' % ('angular max npoint', self.max_angular_point)\n s += '%-18s = %10d\\n' % ('total npoint', self.npoint)\n return s\n","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.__str__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.__str__#L832-L833","kind":"function","name":"__str__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":832,"end_line":833,"context_start_line":812,"context_end_line":846,"code":" if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_radial_point.value\n\n @memoized_property\n def max_angular_point(self):\n max_angular_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_ANGULAR_POINT,\n attributeValue=max_angular_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_angular_point.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'MolecularGrid:\\n'\n s += '%-18s = %10s\\n' % ('scheme name', self.grid_name)\n s += '%-18s = %10d\\n' % ('natom', self.natom)\n s += '%-18s = %10d\\n' % ('atomic max npoint', self.max_point)\n s += '%-18s = %10d\\n' % ('radial max npoint', self.max_radial_point)\n s += '%-18s = %10d\\n' % ('angular max npoint', self.max_angular_point)\n s += '%-18s = %10d\\n' % ('total npoint', self.npoint)\n return s\n","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_molecular_grid.string#L836-L845","kind":"function","name":"string","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":836,"end_line":845,"context_start_line":816,"context_end_line":846,"code":" @memoized_property\n def max_angular_point(self):\n max_angular_point = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_MOLECULARGRID,\n object=self.moleculargrid_handle,\n attribute=ce.CuestMolecularGridAttributes.CUEST_MOLECULARGRID_MAX_ANGULAR_POINT,\n attributeValue=max_angular_point,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return max_angular_point.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'MolecularGrid:\\n'\n s += '%-18s = %10s\\n' % ('scheme name', self.grid_name)\n s += '%-18s = %10d\\n' % ('natom', self.natom)\n s += '%-18s = %10d\\n' % ('atomic max npoint', self.max_point)\n s += '%-18s = %10d\\n' % ('radial max npoint', self.max_radial_point)\n s += '%-18s = %10d\\n' % ('angular max npoint', self.max_angular_point)\n s += '%-18s = %10d\\n' % ('total npoint', self.npoint)\n return s\n","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.diis","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.diis#L1-L131","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.diis","path":"cuEST/cuest_scf_examples/cuest_scf/diis.py","language":"python","start_line":1,"end_line":131,"context_start_line":1,"context_end_line":131,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nfrom .gpu_matrix import GPUMatrix\nfrom .gpu_matrix_utility import GPUMatrixUtility\n \nclass DIIS(object):\n\n def __init__(\n self,\n *,\n max_nvector : int, \n ):\n\n self.max_nvector = max_nvector\n\n self.state_vectors = []\n self.error_vectors = []\n\n self.Efull = np.zeros((max_nvector,)*2)\n \n @property\n def nvector(self) -> int:\n return len(self.state_vectors)\n\n @property\n def E(self) -> np.ndarray:\n return self.Efull[:self.nvector, :self.nvector]\n\n def iterate(\n self,\n *,\n state_vector : GPUMatrix,\n error_vector : GPUMatrix,\n ) -> np.ndarray:\n\n # Worst-error replacement DIIS history update\n \n pivot = None\n if self.nvector < self.max_nvector:\n pivot = self.nvector\n self.state_vectors.append(state_vector.clone())\n self.error_vectors.append(error_vector.clone())\n else:\n pivot = np.argmax(np.diag(self.E))\n self.state_vectors[pivot] = state_vector.clone()\n self.error_vectors[pivot] = error_vector.clone()\n\n # Error metric inner product update\n\n for ind in range(self.nvector):\n Eval = GPUMatrixUtility.ddot(\n x=self.error_vectors[ind],\n y=self.error_vectors[pivot],\n )\n self.E[ind, pivot] = Eval\n self.E[pivot, ind] = Eval\n\n # DIIS extrapolation\n\n state_vector2 = GPUMatrix(\n nrows=state_vector.nrows,\n ncols=state_vector.ncols,\n dtype=state_vector.dtype,\n initialize=True,\n )\n c, L = self.diis_coefficients\n for ind in range(self.nvector):\n GPUMatrixUtility.daxpy(\n alpha=c[ind],\n x=self.state_vectors[ind],\n y=state_vector2,\n )\n return state_vector2\n\n @property\n def diis_coefficients(self) -> (np.ndarray, float):\n \n E = self.E \n\n B = np.zeros((self.nvector + 1,)*2)\n B[:-1, :-1] = E\n B[:-1, -1] = 1.0\n B[-1, :-1] = 1.0\n \n # Negative and zero trapping\n \n for ind in range(self.nvector):\n # Negatives are illegal\n if B[ind, ind] < 0.0:\n raise RuntimeError('Negative diagonal in B matrix.')\n # Zeros are serendipitous convergence\n if B[ind, ind] == 0.0:\n d = np.zeros(self.nvector)\n d[ind] = 1.0\n return d, 0.0\n\n # Balancing\n\n s = np.zeros((self.nvector + 1,))\n s[:-1] = np.diag(E)**(-0.5)\n s[-1] = 1.0\n\n B[...] *= np.outer(s, s)\n\n # Inversion\n\n # NOTE: We are calling numpy.linalg.inv here for simplicity\n # Production codes may desire a conditioned inverse, least-norm\n # solution, or fallback plan for relative condition numbers >~ 1.0E12\n Binv = np.linalg.inv(B) \n \n # Result (last column of Binv plus balance)\n \n d = s[:-1] * Binv[:-1, -1]\n L = Binv[-1, -1]\n\n return d, L","source_hash":"ca94912fbf6c1ddae85a8d8987d438cd293e455753b97cc5d30943db8db3c594","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.diis.DIIS","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.diis.DIIS#L20-L131","kind":"class","name":"DIIS","path":"cuEST/cuest_scf_examples/cuest_scf/diis.py","language":"python","start_line":20,"end_line":131,"context_start_line":1,"context_end_line":131,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nfrom .gpu_matrix import GPUMatrix\nfrom .gpu_matrix_utility import GPUMatrixUtility\n \nclass DIIS(object):\n\n def __init__(\n self,\n *,\n max_nvector : int, \n ):\n\n self.max_nvector = max_nvector\n\n self.state_vectors = []\n self.error_vectors = []\n\n self.Efull = np.zeros((max_nvector,)*2)\n \n @property\n def nvector(self) -> int:\n return len(self.state_vectors)\n\n @property\n def E(self) -> np.ndarray:\n return self.Efull[:self.nvector, :self.nvector]\n\n def iterate(\n self,\n *,\n state_vector : GPUMatrix,\n error_vector : GPUMatrix,\n ) -> np.ndarray:\n\n # Worst-error replacement DIIS history update\n \n pivot = None\n if self.nvector < self.max_nvector:\n pivot = self.nvector\n self.state_vectors.append(state_vector.clone())\n self.error_vectors.append(error_vector.clone())\n else:\n pivot = np.argmax(np.diag(self.E))\n self.state_vectors[pivot] = state_vector.clone()\n self.error_vectors[pivot] = error_vector.clone()\n\n # Error metric inner product update\n\n for ind in range(self.nvector):\n Eval = GPUMatrixUtility.ddot(\n x=self.error_vectors[ind],\n y=self.error_vectors[pivot],\n )\n self.E[ind, pivot] = Eval\n self.E[pivot, ind] = Eval\n\n # DIIS extrapolation\n\n state_vector2 = GPUMatrix(\n nrows=state_vector.nrows,\n ncols=state_vector.ncols,\n dtype=state_vector.dtype,\n initialize=True,\n )\n c, L = self.diis_coefficients\n for ind in range(self.nvector):\n GPUMatrixUtility.daxpy(\n alpha=c[ind],\n x=self.state_vectors[ind],\n y=state_vector2,\n )\n return state_vector2\n\n @property\n def diis_coefficients(self) -> (np.ndarray, float):\n \n E = self.E \n\n B = np.zeros((self.nvector + 1,)*2)\n B[:-1, :-1] = E\n B[:-1, -1] = 1.0\n B[-1, :-1] = 1.0\n \n # Negative and zero trapping\n \n for ind in range(self.nvector):\n # Negatives are illegal\n if B[ind, ind] < 0.0:\n raise RuntimeError('Negative diagonal in B matrix.')\n # Zeros are serendipitous convergence\n if B[ind, ind] == 0.0:\n d = np.zeros(self.nvector)\n d[ind] = 1.0\n return d, 0.0\n\n # Balancing\n\n s = np.zeros((self.nvector + 1,))\n s[:-1] = np.diag(E)**(-0.5)\n s[-1] = 1.0\n\n B[...] *= np.outer(s, s)\n\n # Inversion\n\n # NOTE: We are calling numpy.linalg.inv here for simplicity\n # Production codes may desire a conditioned inverse, least-norm\n # solution, or fallback plan for relative condition numbers >~ 1.0E12\n Binv = np.linalg.inv(B) \n \n # Result (last column of Binv plus balance)\n \n d = s[:-1] * Binv[:-1, -1]\n L = Binv[-1, -1]\n\n return d, L","source_hash":"ca94912fbf6c1ddae85a8d8987d438cd293e455753b97cc5d30943db8db3c594","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.diis.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.diis.__init__#L22-L33","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/diis.py","language":"python","start_line":22,"end_line":33,"context_start_line":2,"context_end_line":53,"code":"# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nfrom .gpu_matrix import GPUMatrix\nfrom .gpu_matrix_utility import GPUMatrixUtility\n \nclass DIIS(object):\n\n def __init__(\n self,\n *,\n max_nvector : int, \n ):\n\n self.max_nvector = max_nvector\n\n self.state_vectors = []\n self.error_vectors = []\n\n self.Efull = np.zeros((max_nvector,)*2)\n \n @property\n def nvector(self) -> int:\n return len(self.state_vectors)\n\n @property\n def E(self) -> np.ndarray:\n return self.Efull[:self.nvector, :self.nvector]\n\n def iterate(\n self,\n *,\n state_vector : GPUMatrix,\n error_vector : GPUMatrix,\n ) -> np.ndarray:\n\n # Worst-error replacement DIIS history update\n \n pivot = None\n if self.nvector < self.max_nvector:","source_hash":"ca94912fbf6c1ddae85a8d8987d438cd293e455753b97cc5d30943db8db3c594","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.diis.nvector","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.diis.nvector#L36-L37","kind":"function","name":"nvector","path":"cuEST/cuest_scf_examples/cuest_scf/diis.py","language":"python","start_line":36,"end_line":37,"context_start_line":16,"context_end_line":57,"code":"import numpy as np\nfrom .gpu_matrix import GPUMatrix\nfrom .gpu_matrix_utility import GPUMatrixUtility\n \nclass DIIS(object):\n\n def __init__(\n self,\n *,\n max_nvector : int, \n ):\n\n self.max_nvector = max_nvector\n\n self.state_vectors = []\n self.error_vectors = []\n\n self.Efull = np.zeros((max_nvector,)*2)\n \n @property\n def nvector(self) -> int:\n return len(self.state_vectors)\n\n @property\n def E(self) -> np.ndarray:\n return self.Efull[:self.nvector, :self.nvector]\n\n def iterate(\n self,\n *,\n state_vector : GPUMatrix,\n error_vector : GPUMatrix,\n ) -> np.ndarray:\n\n # Worst-error replacement DIIS history update\n \n pivot = None\n if self.nvector < self.max_nvector:\n pivot = self.nvector\n self.state_vectors.append(state_vector.clone())\n self.error_vectors.append(error_vector.clone())\n else:","source_hash":"ca94912fbf6c1ddae85a8d8987d438cd293e455753b97cc5d30943db8db3c594","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.diis.E","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.diis.E#L40-L41","kind":"function","name":"E","path":"cuEST/cuest_scf_examples/cuest_scf/diis.py","language":"python","start_line":40,"end_line":41,"context_start_line":20,"context_end_line":61,"code":"class DIIS(object):\n\n def __init__(\n self,\n *,\n max_nvector : int, \n ):\n\n self.max_nvector = max_nvector\n\n self.state_vectors = []\n self.error_vectors = []\n\n self.Efull = np.zeros((max_nvector,)*2)\n \n @property\n def nvector(self) -> int:\n return len(self.state_vectors)\n\n @property\n def E(self) -> np.ndarray:\n return self.Efull[:self.nvector, :self.nvector]\n\n def iterate(\n self,\n *,\n state_vector : GPUMatrix,\n error_vector : GPUMatrix,\n ) -> np.ndarray:\n\n # Worst-error replacement DIIS history update\n \n pivot = None\n if self.nvector < self.max_nvector:\n pivot = self.nvector\n self.state_vectors.append(state_vector.clone())\n self.error_vectors.append(error_vector.clone())\n else:\n pivot = np.argmax(np.diag(self.E))\n self.state_vectors[pivot] = state_vector.clone()\n self.error_vectors[pivot] = error_vector.clone()\n","source_hash":"ca94912fbf6c1ddae85a8d8987d438cd293e455753b97cc5d30943db8db3c594","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.diis.iterate","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.diis.iterate#L43-L87","kind":"function","name":"iterate","path":"cuEST/cuest_scf_examples/cuest_scf/diis.py","language":"python","start_line":43,"end_line":87,"context_start_line":23,"context_end_line":107,"code":" self,\n *,\n max_nvector : int, \n ):\n\n self.max_nvector = max_nvector\n\n self.state_vectors = []\n self.error_vectors = []\n\n self.Efull = np.zeros((max_nvector,)*2)\n \n @property\n def nvector(self) -> int:\n return len(self.state_vectors)\n\n @property\n def E(self) -> np.ndarray:\n return self.Efull[:self.nvector, :self.nvector]\n\n def iterate(\n self,\n *,\n state_vector : GPUMatrix,\n error_vector : GPUMatrix,\n ) -> np.ndarray:\n\n # Worst-error replacement DIIS history update\n \n pivot = None\n if self.nvector < self.max_nvector:\n pivot = self.nvector\n self.state_vectors.append(state_vector.clone())\n self.error_vectors.append(error_vector.clone())\n else:\n pivot = np.argmax(np.diag(self.E))\n self.state_vectors[pivot] = state_vector.clone()\n self.error_vectors[pivot] = error_vector.clone()\n\n # Error metric inner product update\n\n for ind in range(self.nvector):\n Eval = GPUMatrixUtility.ddot(\n x=self.error_vectors[ind],\n y=self.error_vectors[pivot],\n )\n self.E[ind, pivot] = Eval\n self.E[pivot, ind] = Eval\n\n # DIIS extrapolation\n\n state_vector2 = GPUMatrix(\n nrows=state_vector.nrows,\n ncols=state_vector.ncols,\n dtype=state_vector.dtype,\n initialize=True,\n )\n c, L = self.diis_coefficients\n for ind in range(self.nvector):\n GPUMatrixUtility.daxpy(\n alpha=c[ind],\n x=self.state_vectors[ind],\n y=state_vector2,\n )\n return state_vector2\n\n @property\n def diis_coefficients(self) -> (np.ndarray, float):\n \n E = self.E \n\n B = np.zeros((self.nvector + 1,)*2)\n B[:-1, :-1] = E\n B[:-1, -1] = 1.0\n B[-1, :-1] = 1.0\n \n # Negative and zero trapping\n \n for ind in range(self.nvector):\n # Negatives are illegal\n if B[ind, ind] < 0.0:\n raise RuntimeError('Negative diagonal in B matrix.')\n # Zeros are serendipitous convergence\n if B[ind, ind] == 0.0:\n d = np.zeros(self.nvector)","source_hash":"ca94912fbf6c1ddae85a8d8987d438cd293e455753b97cc5d30943db8db3c594","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.diis.diis_coefficients","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.diis.diis_coefficients#L90-L131","kind":"function","name":"diis_coefficients","path":"cuEST/cuest_scf_examples/cuest_scf/diis.py","language":"python","start_line":90,"end_line":131,"context_start_line":70,"context_end_line":131,"code":" self.E[pivot, ind] = Eval\n\n # DIIS extrapolation\n\n state_vector2 = GPUMatrix(\n nrows=state_vector.nrows,\n ncols=state_vector.ncols,\n dtype=state_vector.dtype,\n initialize=True,\n )\n c, L = self.diis_coefficients\n for ind in range(self.nvector):\n GPUMatrixUtility.daxpy(\n alpha=c[ind],\n x=self.state_vectors[ind],\n y=state_vector2,\n )\n return state_vector2\n\n @property\n def diis_coefficients(self) -> (np.ndarray, float):\n \n E = self.E \n\n B = np.zeros((self.nvector + 1,)*2)\n B[:-1, :-1] = E\n B[:-1, -1] = 1.0\n B[-1, :-1] = 1.0\n \n # Negative and zero trapping\n \n for ind in range(self.nvector):\n # Negatives are illegal\n if B[ind, ind] < 0.0:\n raise RuntimeError('Negative diagonal in B matrix.')\n # Zeros are serendipitous convergence\n if B[ind, ind] == 0.0:\n d = np.zeros(self.nvector)\n d[ind] = 1.0\n return d, 0.0\n\n # Balancing\n\n s = np.zeros((self.nvector + 1,))\n s[:-1] = np.diag(E)**(-0.5)\n s[-1] = 1.0\n\n B[...] *= np.outer(s, s)\n\n # Inversion\n\n # NOTE: We are calling numpy.linalg.inv here for simplicity\n # Production codes may desire a conditioned inverse, least-norm\n # solution, or fallback plan for relative condition numbers >~ 1.0E12\n Binv = np.linalg.inv(B) \n \n # Result (last column of Binv plus balance)\n \n d = s[:-1] * Binv[:-1, -1]\n L = Binv[-1, -1]\n\n return d, L","source_hash":"ca94912fbf6c1ddae85a8d8987d438cd293e455753b97cc5d30943db8db3c594","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.periodic_table","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.periodic_table#L1-L142","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.periodic_table","path":"cuEST/cuest_scf_examples/cuest_scf/periodic_table.py","language":"python","start_line":1,"end_line":142,"context_start_line":1,"context_end_line":142,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nclass PeriodicTable(object):\n\n symbol_to_N_table = {\n 'X' : 0,\n 'H' : 1,\n 'He' : 2,\n 'Li' : 3,\n 'Be' : 4,\n 'B' : 5,\n 'C' : 6,\n 'N' : 7,\n 'O' : 8,\n 'F' : 9,\n 'Ne' : 10,\n 'Na' : 11,\n 'Mg' : 12,\n 'Al' : 13,\n 'Si' : 14,\n 'P' : 15,\n 'S' : 16,\n 'Cl' : 17,\n 'Ar' : 18,\n 'K' : 19,\n 'Ca' : 20,\n 'Sc' : 21,\n 'Ti' : 22,\n 'V' : 23,\n 'Cr' : 24,\n 'Mn' : 25,\n 'Fe' : 26,\n 'Co' : 27,\n 'Ni' : 28,\n 'Cu' : 29,\n 'Zn' : 30,\n 'Ga' : 31,\n 'Ge' : 32,\n 'As' : 33,\n 'Se' : 34,\n 'Br' : 35,\n 'Kr' : 36,\n 'Rb' : 37,\n 'Sr' : 38,\n 'Y' : 39,\n 'Zr' : 40,\n 'Nb' : 41,\n 'Mo' : 42,\n 'Tc' : 43,\n 'Ru' : 44,\n 'Rh' : 45,\n 'Pd' : 46,\n 'Ag' : 47,\n 'Cd' : 48,\n 'In' : 49,\n 'Sn' : 50,\n 'Sb' : 51,\n 'Te' : 52,\n 'I' : 53,\n 'Xe' : 54,\n 'Cs' : 55,\n 'Ba' : 56,\n 'La' : 57,\n 'Ce' : 58,\n 'Pr' : 59,\n 'Nd' : 60,\n 'Pm' : 61,\n 'Sm' : 62,\n 'Eu' : 63,\n 'Gd' : 64,\n 'Tb' : 65,\n 'Dy' : 66,\n 'Ho' : 67,\n 'Er' : 68,\n 'Tm' : 69,\n 'Yb' : 70,\n 'Lu' : 71,\n 'Hf' : 72,\n 'Ta' : 73,\n 'W' : 74,\n 'Re' : 75,\n 'Os' : 76,\n 'Ir' : 77,\n 'Pt' : 78,\n 'Au' : 79,\n 'Hg' : 80,\n 'Tl' : 81,\n 'Pb' : 82,\n 'Bi' : 83,\n 'Po' : 84,\n 'At' : 85,\n 'Rn' : 86,\n 'Fr' : 87,\n 'Ra' : 88,\n 'Ac' : 89,\n 'Th' : 90,\n 'Pa' : 91,\n 'U' : 92,\n 'Np' : 93,\n 'Pu' : 94,\n 'Am' : 95,\n 'Cm' : 96,\n 'Bk' : 97,\n 'Cf' : 98,\n 'Es' : 99,\n 'Fm' : 100,\n 'Md' : 101,\n 'No' : 102,\n 'Lr' : 103,\n 'Rf' : 104,\n 'Db' : 105,\n 'Sg' : 106,\n 'Bh' : 107,\n 'Hs' : 108,\n 'Mt' : 109,\n 'Ds' : 110,\n 'Rg' : 111,\n 'Cn' : 112,\n 'Nh' : 113,\n 'Fl' : 114,\n 'Mc' : 115,\n 'Lv' : 116,\n 'Ts' : 117,\n 'Og' : 118,\n }\n\n symbol_upper_to_N_table = { symbol.upper() : N for symbol, N in symbol_to_N_table.items() }\n\n N_to_symbol_upper_table = { v : k for k, v in symbol_upper_to_N_table.items() }","source_hash":"0342e41060e0eb94cf40568a90cf72bdec3a731c1ec4d4376fa4a407c9762737","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.periodic_table.PeriodicTable","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.periodic_table.PeriodicTable#L16-L142","kind":"class","name":"PeriodicTable","path":"cuEST/cuest_scf_examples/cuest_scf/periodic_table.py","language":"python","start_line":16,"end_line":142,"context_start_line":1,"context_end_line":142,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nclass PeriodicTable(object):\n\n symbol_to_N_table = {\n 'X' : 0,\n 'H' : 1,\n 'He' : 2,\n 'Li' : 3,\n 'Be' : 4,\n 'B' : 5,\n 'C' : 6,\n 'N' : 7,\n 'O' : 8,\n 'F' : 9,\n 'Ne' : 10,\n 'Na' : 11,\n 'Mg' : 12,\n 'Al' : 13,\n 'Si' : 14,\n 'P' : 15,\n 'S' : 16,\n 'Cl' : 17,\n 'Ar' : 18,\n 'K' : 19,\n 'Ca' : 20,\n 'Sc' : 21,\n 'Ti' : 22,\n 'V' : 23,\n 'Cr' : 24,\n 'Mn' : 25,\n 'Fe' : 26,\n 'Co' : 27,\n 'Ni' : 28,\n 'Cu' : 29,\n 'Zn' : 30,\n 'Ga' : 31,\n 'Ge' : 32,\n 'As' : 33,\n 'Se' : 34,\n 'Br' : 35,\n 'Kr' : 36,\n 'Rb' : 37,\n 'Sr' : 38,\n 'Y' : 39,\n 'Zr' : 40,\n 'Nb' : 41,\n 'Mo' : 42,\n 'Tc' : 43,\n 'Ru' : 44,\n 'Rh' : 45,\n 'Pd' : 46,\n 'Ag' : 47,\n 'Cd' : 48,\n 'In' : 49,\n 'Sn' : 50,\n 'Sb' : 51,\n 'Te' : 52,\n 'I' : 53,\n 'Xe' : 54,\n 'Cs' : 55,\n 'Ba' : 56,\n 'La' : 57,\n 'Ce' : 58,\n 'Pr' : 59,\n 'Nd' : 60,\n 'Pm' : 61,\n 'Sm' : 62,\n 'Eu' : 63,\n 'Gd' : 64,\n 'Tb' : 65,\n 'Dy' : 66,\n 'Ho' : 67,\n 'Er' : 68,\n 'Tm' : 69,\n 'Yb' : 70,\n 'Lu' : 71,\n 'Hf' : 72,\n 'Ta' : 73,\n 'W' : 74,\n 'Re' : 75,\n 'Os' : 76,\n 'Ir' : 77,\n 'Pt' : 78,\n 'Au' : 79,\n 'Hg' : 80,\n 'Tl' : 81,\n 'Pb' : 82,\n 'Bi' : 83,\n 'Po' : 84,\n 'At' : 85,\n 'Rn' : 86,\n 'Fr' : 87,\n 'Ra' : 88,\n 'Ac' : 89,\n 'Th' : 90,\n 'Pa' : 91,\n 'U' : 92,\n 'Np' : 93,\n 'Pu' : 94,\n 'Am' : 95,\n 'Cm' : 96,\n 'Bk' : 97,\n 'Cf' : 98,\n 'Es' : 99,\n 'Fm' : 100,\n 'Md' : 101,\n 'No' : 102,\n 'Lr' : 103,\n 'Rf' : 104,\n 'Db' : 105,\n 'Sg' : 106,\n 'Bh' : 107,\n 'Hs' : 108,\n 'Mt' : 109,\n 'Ds' : 110,\n 'Rg' : 111,\n 'Cn' : 112,\n 'Nh' : 113,\n 'Fl' : 114,\n 'Mc' : 115,\n 'Lv' : 116,\n 'Ts' : 117,\n 'Og' : 118,\n }\n\n symbol_upper_to_N_table = { symbol.upper() : N for symbol, N in symbol_to_N_table.items() }\n\n N_to_symbol_upper_table = { v : k for k, v in symbol_upper_to_N_table.items() }","source_hash":"0342e41060e0eb94cf40568a90cf72bdec3a731c1ec4d4376fa4a407c9762737","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace#L1-L74","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_workspace","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","language":"python","start_line":1,"end_line":74,"context_start_line":1,"context_end_line":74,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .cuda_utility import CudaUtility\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\n\nclass CuestWorkspace():\n\n _dtype = np.dtype([\n (\"hostBuffer\", np.uintp, ),\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBuffer\", np.uintp, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n def __init__(\n self,\n *,\n workspaceDescriptor: CuestWorkspaceDescriptor,\n ):\n\n self.initialized = False\n\n hostBufferSizeInBytes = workspaceDescriptor.struct['hostBufferSizeInBytes']\n deviceBufferSizeInBytes = workspaceDescriptor.struct['deviceBufferSizeInBytes']\n\n self.struct = np.array(1, dtype=self._dtype)\n self.struct['deviceBufferSizeInBytes'] = deviceBufferSizeInBytes\n self.struct['hostBufferSizeInBytes'] = hostBufferSizeInBytes\n\n if deviceBufferSizeInBytes:\n self.struct['deviceBuffer'] = CudaUtility.cuda_malloc(size_in_bytes=deviceBufferSizeInBytes)\n else:\n self.struct['deviceBuffer'] = 0\n\n if hostBufferSizeInBytes:\n self.struct['hostBuffer'] = CudaUtility.cuda_malloc_host(size_in_bytes=hostBufferSizeInBytes)\n else:\n self.struct['hostBuffer'] = 0\n\n # NOTE: A production code might put separate flags in for device/host\n self.initialized = True\n\n def __del__(\n self,\n ):\n\n if not self.initialized: return\n\n if self.struct['deviceBuffer']:\n CudaUtility.cuda_free(int(self.struct['deviceBuffer']))\n\n if self.struct['hostBuffer']:\n CudaUtility.cuda_free_host(int(self.struct['hostBuffer']))\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"6c76bb1163d31d7e4a773c3eff26bda2eb75e70c06244c3de4266f9457843436","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace.CuestWorkspace","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace.CuestWorkspace#L22-L74","kind":"class","name":"CuestWorkspace","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","language":"python","start_line":22,"end_line":74,"context_start_line":2,"context_end_line":74,"code":"# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .cuda_utility import CudaUtility\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\n\nclass CuestWorkspace():\n\n _dtype = np.dtype([\n (\"hostBuffer\", np.uintp, ),\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBuffer\", np.uintp, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n def __init__(\n self,\n *,\n workspaceDescriptor: CuestWorkspaceDescriptor,\n ):\n\n self.initialized = False\n\n hostBufferSizeInBytes = workspaceDescriptor.struct['hostBufferSizeInBytes']\n deviceBufferSizeInBytes = workspaceDescriptor.struct['deviceBufferSizeInBytes']\n\n self.struct = np.array(1, dtype=self._dtype)\n self.struct['deviceBufferSizeInBytes'] = deviceBufferSizeInBytes\n self.struct['hostBufferSizeInBytes'] = hostBufferSizeInBytes\n\n if deviceBufferSizeInBytes:\n self.struct['deviceBuffer'] = CudaUtility.cuda_malloc(size_in_bytes=deviceBufferSizeInBytes)\n else:\n self.struct['deviceBuffer'] = 0\n\n if hostBufferSizeInBytes:\n self.struct['hostBuffer'] = CudaUtility.cuda_malloc_host(size_in_bytes=hostBufferSizeInBytes)\n else:\n self.struct['hostBuffer'] = 0\n\n # NOTE: A production code might put separate flags in for device/host\n self.initialized = True\n\n def __del__(\n self,\n ):\n\n if not self.initialized: return\n\n if self.struct['deviceBuffer']:\n CudaUtility.cuda_free(int(self.struct['deviceBuffer']))\n\n if self.struct['hostBuffer']:\n CudaUtility.cuda_free_host(int(self.struct['hostBuffer']))\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"6c76bb1163d31d7e4a773c3eff26bda2eb75e70c06244c3de4266f9457843436","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace.__init__#L32-L58","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","language":"python","start_line":32,"end_line":58,"context_start_line":12,"context_end_line":74,"code":"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .cuda_utility import CudaUtility\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\n\nclass CuestWorkspace():\n\n _dtype = np.dtype([\n (\"hostBuffer\", np.uintp, ),\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBuffer\", np.uintp, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n def __init__(\n self,\n *,\n workspaceDescriptor: CuestWorkspaceDescriptor,\n ):\n\n self.initialized = False\n\n hostBufferSizeInBytes = workspaceDescriptor.struct['hostBufferSizeInBytes']\n deviceBufferSizeInBytes = workspaceDescriptor.struct['deviceBufferSizeInBytes']\n\n self.struct = np.array(1, dtype=self._dtype)\n self.struct['deviceBufferSizeInBytes'] = deviceBufferSizeInBytes\n self.struct['hostBufferSizeInBytes'] = hostBufferSizeInBytes\n\n if deviceBufferSizeInBytes:\n self.struct['deviceBuffer'] = CudaUtility.cuda_malloc(size_in_bytes=deviceBufferSizeInBytes)\n else:\n self.struct['deviceBuffer'] = 0\n\n if hostBufferSizeInBytes:\n self.struct['hostBuffer'] = CudaUtility.cuda_malloc_host(size_in_bytes=hostBufferSizeInBytes)\n else:\n self.struct['hostBuffer'] = 0\n\n # NOTE: A production code might put separate flags in for device/host\n self.initialized = True\n\n def __del__(\n self,\n ):\n\n if not self.initialized: return\n\n if self.struct['deviceBuffer']:\n CudaUtility.cuda_free(int(self.struct['deviceBuffer']))\n\n if self.struct['hostBuffer']:\n CudaUtility.cuda_free_host(int(self.struct['hostBuffer']))\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"6c76bb1163d31d7e4a773c3eff26bda2eb75e70c06244c3de4266f9457843436","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace.__del__#L60-L70","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","language":"python","start_line":60,"end_line":70,"context_start_line":40,"context_end_line":74,"code":" hostBufferSizeInBytes = workspaceDescriptor.struct['hostBufferSizeInBytes']\n deviceBufferSizeInBytes = workspaceDescriptor.struct['deviceBufferSizeInBytes']\n\n self.struct = np.array(1, dtype=self._dtype)\n self.struct['deviceBufferSizeInBytes'] = deviceBufferSizeInBytes\n self.struct['hostBufferSizeInBytes'] = hostBufferSizeInBytes\n\n if deviceBufferSizeInBytes:\n self.struct['deviceBuffer'] = CudaUtility.cuda_malloc(size_in_bytes=deviceBufferSizeInBytes)\n else:\n self.struct['deviceBuffer'] = 0\n\n if hostBufferSizeInBytes:\n self.struct['hostBuffer'] = CudaUtility.cuda_malloc_host(size_in_bytes=hostBufferSizeInBytes)\n else:\n self.struct['hostBuffer'] = 0\n\n # NOTE: A production code might put separate flags in for device/host\n self.initialized = True\n\n def __del__(\n self,\n ):\n\n if not self.initialized: return\n\n if self.struct['deviceBuffer']:\n CudaUtility.cuda_free(int(self.struct['deviceBuffer']))\n\n if self.struct['hostBuffer']:\n CudaUtility.cuda_free_host(int(self.struct['hostBuffer']))\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"6c76bb1163d31d7e4a773c3eff26bda2eb75e70c06244c3de4266f9457843436","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace.pointer","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace.pointer#L73-L74","kind":"function","name":"pointer","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","language":"python","start_line":73,"end_line":74,"context_start_line":53,"context_end_line":74,"code":" self.struct['hostBuffer'] = CudaUtility.cuda_malloc_host(size_in_bytes=hostBufferSizeInBytes)\n else:\n self.struct['hostBuffer'] = 0\n\n # NOTE: A production code might put separate flags in for device/host\n self.initialized = True\n\n def __del__(\n self,\n ):\n\n if not self.initialized: return\n\n if self.struct['deviceBuffer']:\n CudaUtility.cuda_free(int(self.struct['deviceBuffer']))\n\n if self.struct['hostBuffer']:\n CudaUtility.cuda_free_host(int(self.struct['hostBuffer']))\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"6c76bb1163d31d7e4a773c3eff26bda2eb75e70c06244c3de4266f9457843436","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan#L1-L335","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":1,"end_line":335,"context_start_line":1,"context_end_line":335,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .memoized_property import memoized_property\n\nimport cuest.bindings as ce \nimport numpy as np\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_molecular_grid import CuestMolecularGrid\n\nfrom .cuest_parameters import CuestParameters\n\nfrom .cuest_oe_int_plan import CuestOEIntPlan\nfrom .periodic_table import PeriodicTable\nfrom .unit_conversions import UnitConversions\n\n\n# York and Karplus, J. Phys. Chem. A, 103, 11060-11079 (1999) - Table 1.\n_zeta_map = {\n 14 : 4.865,\n 26 : 4.855,\n 50 : 4.893,\n 110 : 4.901,\n 194 : 4.903,\n 302 : 4.905,\n 434 : 4.906,\n 590 : 4.905,\n 770 : 4.899,\n 974 : 4.907,\n 1202 : 4.907,\n }\n\n# First source:\n# Truhlar and coworkers, J. Phys. Chem. A, 113, 5806-5812 (2009) - Table 12.\n#\n# Second source (radii not given in the 2009 paper come from here):\n# CRC Handbook of Chemistry and Physics, 95th Edition.\n# Pages 9-49 to 9-50.\n# Atomic Radii of the Elements\n# Manjeera Mantina, Rosendo Valero, Christopher J. Cramer, and Donald G. Truhlar\n#\n_bondi_radii_ang = {\n 'H' : 1.10,\n 'HE' : 1.40,\n 'LI' : 1.81,\n 'BE' : 1.53,\n 'B' : 1.92,\n 'C' : 1.70,\n 'N' : 1.55,\n 'O' : 1.52,\n 'F' : 1.47,\n 'NE' : 1.54,\n 'NA' : 2.27,\n 'MG' : 1.73,\n 'AL' : 1.84,\n 'SI' : 2.10,\n 'P' : 1.80,\n 'S' : 1.80,\n 'CL' : 1.75,\n 'AR' : 1.88,\n 'K' : 2.75,\n 'CA' : 2.31,\n 'SC' : 2.15,\n 'TI' : 2.11,\n 'V' : 2.07,\n 'CR' : 2.06,\n 'MN' : 2.05,\n 'FE' : 2.04,\n 'CO' : 2.00,\n 'NI' : 1.97,\n 'CU' : 1.96,\n 'ZN' : 2.01,\n 'GA' : 1.87,\n 'GE' : 2.11,\n 'AS' : 1.85,\n 'SE' : 1.90,\n 'BR' : 1.83,\n 'KR' : 2.02,\n 'RB' : 3.03,\n 'SR' : 2.49,\n 'Y' : 2.32,\n 'ZR' : 2.23,\n 'NB' : 2.18,\n 'MO' : 2.17,\n 'TC' : 2.16,\n 'RU' : 2.13,\n 'RH' : 2.10,\n 'PD' : 2.10,\n 'AG' : 2.11,\n 'CD' : 2.18,\n 'IN' : 1.93,\n 'SN' : 2.17,\n 'SB' : 2.06,\n 'TE' : 2.06,\n 'I' : 1.98,\n 'XE' : 2.16,\n 'CS' : 3.43,\n 'BA' : 2.68,\n 'LA' : 2.43,\n 'CE' : 2.42,\n 'PR' : 2.40,\n 'ND' : 2.39,\n 'PM' : 2.38,\n 'SM' : 2.36,\n 'EU' : 2.35,\n 'GD' : 2.34,\n 'TB' : 2.33,\n 'DY' : 2.31,\n 'HO' : 2.30,\n 'ER' : 2.29,\n 'TM' : 2.27,\n 'YB' : 2.26,\n 'LU' : 2.24,\n 'HF' : 2.23,\n 'TA' : 2.22,\n 'W' : 2.18,\n 'RE' : 2.16,\n 'OS' : 2.16,\n 'IR' : 2.13,\n 'PT' : 2.13,\n 'AU' : 2.14,\n 'HG' : 2.23,\n 'TL' : 1.96,\n 'PB' : 2.02,\n 'BI' : 2.07,\n 'PO' : 1.97,\n 'AT' : 2.02,\n 'RN' : 2.20,\n 'FR' : 3.48,\n 'RA' : 2.83,\n 'AC' : 2.47,\n 'TH' : 2.45,\n 'PA' : 2.43,\n 'U' : 2.41,\n 'NP' : 2.39,\n 'PU' : 2.43,\n 'AM' : 2.44,\n 'CM' : 2.45,\n 'BK' : 2.44,\n 'CF' : 2.45,\n 'ES' : 2.45,\n 'FM' : 2.45,\n 'MD' : 2.46,\n 'NO' : 2.46,\n 'LR' : 2.46,\n }\n\nclass CuestPCMIntPlan(object):\n\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n intPlan : CuestOEIntPlan,\n epsilon : float,\n x_prefactor : float,\n num_angular_points_per_hydrogen_atom : int,\n num_angular_points_per_heavy_atom : int,\n Ns : np.ndarray,\n effective_nuclear_charges : np.ndarray,\n cutoff : float,\n convergence_tol : float,\n atomic_radii_scale=1.2\n ):\n\n bohr_per_ang=UnitConversions.conversions['bohr_per_ang']\n\n if num_angular_points_per_hydrogen_atom not in _zeta_map:\n raise RuntimeError(f\"Invalid num_angular_points_per_hydrogen_atom value ({num_angular_points_per_hydrogen_atom}) is not a valid Lebedev number\")\n if num_angular_points_per_heavy_atom not in _zeta_map:\n raise RuntimeError(f\"Invalid num_angular_points_per_heavy_atom value ({num_angular_points_per_heavy_atom}) is not a valid Lebedev number\")\n\n self.initialized = False\n\n self.handle = handle\n self.num_angular_points_per_hydrogen_atom=num_angular_points_per_hydrogen_atom\n self.num_angular_points_per_heavy_atom=num_angular_points_per_heavy_atom\n self.epsilon=epsilon\n self.x_prefactor=x_prefactor\n self.cutoff = cutoff\n self.convergence_tol = convergence_tol\n\n symbols_upper = [PeriodicTable.N_to_symbol_upper_table[N] for N in Ns]\n for sym in symbols_upper:\n if sym not in _bondi_radii_ang:\n raise RuntimeError(f\"No Bondi radius defined for element {sym}\")\n grid_sizes = [num_angular_points_per_hydrogen_atom if s == \"H\" else num_angular_points_per_heavy_atom for s in symbols_upper]\n zetas=[_zeta_map[grid_size] for grid_size in grid_sizes]\n atomic_radii=atomic_radii_scale*np.array([_bondi_radii_ang[symbol_upper] * bohr_per_ang for symbol_upper in symbols_upper])\n\n pcm_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n )\n\n pcm_cutoff = ce.data_double(self.cutoff)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n parameters=pcm_int_plan_parameters.parameters,\n attribute=ce.CuestPCMIntPlanParametersAttributes.CUEST_PCMINTPLAN_PARAMETERS_CUTOFF,\n attributeValue=pcm_cutoff,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n pcm_x_prefactor = ce.data_double(self.x_prefactor)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n parameters=pcm_int_plan_parameters.parameters,\n attribute=ce.CuestPCMIntPlanParametersAttributes.CUEST_PCMINTPLAN_PARAMETERS_X_PREFACTOR,\n attributeValue=pcm_x_prefactor,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n self.pcm_int_plan_handle = ce.cuestPCMIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n intPlan=intPlan.oe_int_plan_handle,\n parameters=pcm_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numAngularPointsPerAtom=grid_sizes,\n epsilon=epsilon,\n zetas=zetas,\n atomicRadii=atomic_radii,\n effectiveNuclearCharges=effective_nuclear_charges,\n outPlan=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestPCMIntPlanCreate(\n handle=handle.handle,\n intPlan=intPlan.oe_int_plan_handle,\n parameters=pcm_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numAngularPointsPerAtom=grid_sizes,\n epsilon=epsilon,\n zetas=zetas,\n atomicRadii=atomic_radii,\n effectiveNuclearCharges=effective_nuclear_charges,\n outPlan=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestPCMIntPlanDestroy(\n handle=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanDestroy failed')\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def n_active_point(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_ACTIVE_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'PCMIntPlan:\\n'\n s += '%-10s = %10.4f\\n' % ('dielectric', self.epsilon)\n s += '%-10s = %10.1e\\n' % ('tolerance', self.convergence_tol)\n s += '%-10s = %10.1e\\n' % ('cutoff', self.cutoff)\n s += '%-10s = %10d\\n' % ('npoint', self.npoint)\n s += '%-10s = %10d\\n' % ('nactive', self.n_active_point)\n return s\n","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.CuestPCMIntPlan","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.CuestPCMIntPlan#L165-L334","kind":"class","name":"CuestPCMIntPlan","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":165,"end_line":334,"context_start_line":145,"context_end_line":335,"code":" 'RN' : 2.20,\n 'FR' : 3.48,\n 'RA' : 2.83,\n 'AC' : 2.47,\n 'TH' : 2.45,\n 'PA' : 2.43,\n 'U' : 2.41,\n 'NP' : 2.39,\n 'PU' : 2.43,\n 'AM' : 2.44,\n 'CM' : 2.45,\n 'BK' : 2.44,\n 'CF' : 2.45,\n 'ES' : 2.45,\n 'FM' : 2.45,\n 'MD' : 2.46,\n 'NO' : 2.46,\n 'LR' : 2.46,\n }\n\nclass CuestPCMIntPlan(object):\n\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n intPlan : CuestOEIntPlan,\n epsilon : float,\n x_prefactor : float,\n num_angular_points_per_hydrogen_atom : int,\n num_angular_points_per_heavy_atom : int,\n Ns : np.ndarray,\n effective_nuclear_charges : np.ndarray,\n cutoff : float,\n convergence_tol : float,\n atomic_radii_scale=1.2\n ):\n\n bohr_per_ang=UnitConversions.conversions['bohr_per_ang']\n\n if num_angular_points_per_hydrogen_atom not in _zeta_map:\n raise RuntimeError(f\"Invalid num_angular_points_per_hydrogen_atom value ({num_angular_points_per_hydrogen_atom}) is not a valid Lebedev number\")\n if num_angular_points_per_heavy_atom not in _zeta_map:\n raise RuntimeError(f\"Invalid num_angular_points_per_heavy_atom value ({num_angular_points_per_heavy_atom}) is not a valid Lebedev number\")\n\n self.initialized = False\n\n self.handle = handle\n self.num_angular_points_per_hydrogen_atom=num_angular_points_per_hydrogen_atom\n self.num_angular_points_per_heavy_atom=num_angular_points_per_heavy_atom\n self.epsilon=epsilon\n self.x_prefactor=x_prefactor\n self.cutoff = cutoff\n self.convergence_tol = convergence_tol\n\n symbols_upper = [PeriodicTable.N_to_symbol_upper_table[N] for N in Ns]\n for sym in symbols_upper:\n if sym not in _bondi_radii_ang:\n raise RuntimeError(f\"No Bondi radius defined for element {sym}\")\n grid_sizes = [num_angular_points_per_hydrogen_atom if s == \"H\" else num_angular_points_per_heavy_atom for s in symbols_upper]\n zetas=[_zeta_map[grid_size] for grid_size in grid_sizes]\n atomic_radii=atomic_radii_scale*np.array([_bondi_radii_ang[symbol_upper] * bohr_per_ang for symbol_upper in symbols_upper])\n\n pcm_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n )\n\n pcm_cutoff = ce.data_double(self.cutoff)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n parameters=pcm_int_plan_parameters.parameters,\n attribute=ce.CuestPCMIntPlanParametersAttributes.CUEST_PCMINTPLAN_PARAMETERS_CUTOFF,\n attributeValue=pcm_cutoff,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n pcm_x_prefactor = ce.data_double(self.x_prefactor)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n parameters=pcm_int_plan_parameters.parameters,\n attribute=ce.CuestPCMIntPlanParametersAttributes.CUEST_PCMINTPLAN_PARAMETERS_X_PREFACTOR,\n attributeValue=pcm_x_prefactor,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n self.pcm_int_plan_handle = ce.cuestPCMIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n intPlan=intPlan.oe_int_plan_handle,\n parameters=pcm_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numAngularPointsPerAtom=grid_sizes,\n epsilon=epsilon,\n zetas=zetas,\n atomicRadii=atomic_radii,\n effectiveNuclearCharges=effective_nuclear_charges,\n outPlan=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestPCMIntPlanCreate(\n handle=handle.handle,\n intPlan=intPlan.oe_int_plan_handle,\n parameters=pcm_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numAngularPointsPerAtom=grid_sizes,\n epsilon=epsilon,\n zetas=zetas,\n atomicRadii=atomic_radii,\n effectiveNuclearCharges=effective_nuclear_charges,\n outPlan=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestPCMIntPlanDestroy(\n handle=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanDestroy failed')\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def n_active_point(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_ACTIVE_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'PCMIntPlan:\\n'\n s += '%-10s = %10.4f\\n' % ('dielectric', self.epsilon)\n s += '%-10s = %10.1e\\n' % ('tolerance', self.convergence_tol)\n s += '%-10s = %10.1e\\n' % ('cutoff', self.cutoff)\n s += '%-10s = %10d\\n' % ('npoint', self.npoint)\n s += '%-10s = %10d\\n' % ('nactive', self.n_active_point)\n return s\n","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.__init__#L168-L280","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":168,"end_line":280,"context_start_line":148,"context_end_line":300,"code":" 'AC' : 2.47,\n 'TH' : 2.45,\n 'PA' : 2.43,\n 'U' : 2.41,\n 'NP' : 2.39,\n 'PU' : 2.43,\n 'AM' : 2.44,\n 'CM' : 2.45,\n 'BK' : 2.44,\n 'CF' : 2.45,\n 'ES' : 2.45,\n 'FM' : 2.45,\n 'MD' : 2.46,\n 'NO' : 2.46,\n 'LR' : 2.46,\n }\n\nclass CuestPCMIntPlan(object):\n\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n intPlan : CuestOEIntPlan,\n epsilon : float,\n x_prefactor : float,\n num_angular_points_per_hydrogen_atom : int,\n num_angular_points_per_heavy_atom : int,\n Ns : np.ndarray,\n effective_nuclear_charges : np.ndarray,\n cutoff : float,\n convergence_tol : float,\n atomic_radii_scale=1.2\n ):\n\n bohr_per_ang=UnitConversions.conversions['bohr_per_ang']\n\n if num_angular_points_per_hydrogen_atom not in _zeta_map:\n raise RuntimeError(f\"Invalid num_angular_points_per_hydrogen_atom value ({num_angular_points_per_hydrogen_atom}) is not a valid Lebedev number\")\n if num_angular_points_per_heavy_atom not in _zeta_map:\n raise RuntimeError(f\"Invalid num_angular_points_per_heavy_atom value ({num_angular_points_per_heavy_atom}) is not a valid Lebedev number\")\n\n self.initialized = False\n\n self.handle = handle\n self.num_angular_points_per_hydrogen_atom=num_angular_points_per_hydrogen_atom\n self.num_angular_points_per_heavy_atom=num_angular_points_per_heavy_atom\n self.epsilon=epsilon\n self.x_prefactor=x_prefactor\n self.cutoff = cutoff\n self.convergence_tol = convergence_tol\n\n symbols_upper = [PeriodicTable.N_to_symbol_upper_table[N] for N in Ns]\n for sym in symbols_upper:\n if sym not in _bondi_radii_ang:\n raise RuntimeError(f\"No Bondi radius defined for element {sym}\")\n grid_sizes = [num_angular_points_per_hydrogen_atom if s == \"H\" else num_angular_points_per_heavy_atom for s in symbols_upper]\n zetas=[_zeta_map[grid_size] for grid_size in grid_sizes]\n atomic_radii=atomic_radii_scale*np.array([_bondi_radii_ang[symbol_upper] * bohr_per_ang for symbol_upper in symbols_upper])\n\n pcm_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n )\n\n pcm_cutoff = ce.data_double(self.cutoff)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n parameters=pcm_int_plan_parameters.parameters,\n attribute=ce.CuestPCMIntPlanParametersAttributes.CUEST_PCMINTPLAN_PARAMETERS_CUTOFF,\n attributeValue=pcm_cutoff,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n pcm_x_prefactor = ce.data_double(self.x_prefactor)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMINTPLAN_PARAMETERS,\n parameters=pcm_int_plan_parameters.parameters,\n attribute=ce.CuestPCMIntPlanParametersAttributes.CUEST_PCMINTPLAN_PARAMETERS_X_PREFACTOR,\n attributeValue=pcm_x_prefactor,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n self.pcm_int_plan_handle = ce.cuestPCMIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n intPlan=intPlan.oe_int_plan_handle,\n parameters=pcm_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numAngularPointsPerAtom=grid_sizes,\n epsilon=epsilon,\n zetas=zetas,\n atomicRadii=atomic_radii,\n effectiveNuclearCharges=effective_nuclear_charges,\n outPlan=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestPCMIntPlanCreate(\n handle=handle.handle,\n intPlan=intPlan.oe_int_plan_handle,\n parameters=pcm_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numAngularPointsPerAtom=grid_sizes,\n epsilon=epsilon,\n zetas=zetas,\n atomicRadii=atomic_radii,\n effectiveNuclearCharges=effective_nuclear_charges,\n outPlan=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestPCMIntPlanDestroy(\n handle=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanDestroy failed')\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_POINT,\n attributeValue=npoint,","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.__del__#L282-L290","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":282,"end_line":290,"context_start_line":262,"context_end_line":310,"code":" handle=handle.handle,\n intPlan=intPlan.oe_int_plan_handle,\n parameters=pcm_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numAngularPointsPerAtom=grid_sizes,\n epsilon=epsilon,\n zetas=zetas,\n atomicRadii=atomic_radii,\n effectiveNuclearCharges=effective_nuclear_charges,\n outPlan=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestPCMIntPlanDestroy(\n handle=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanDestroy failed')\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def n_active_point(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.npoint","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.npoint#L293-L304","kind":"function","name":"npoint","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":293,"end_line":304,"context_start_line":273,"context_end_line":324,"code":" )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestPCMIntPlanDestroy(\n handle=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanDestroy failed')\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def n_active_point(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_ACTIVE_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.n_active_point","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.n_active_point#L307-L318","kind":"function","name":"n_active_point","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":307,"end_line":318,"context_start_line":287,"context_end_line":335,"code":" handle=self.pcm_int_plan_handle,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMIntPlanDestroy failed')\n\n @memoized_property\n def npoint(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def n_active_point(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_ACTIVE_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'PCMIntPlan:\\n'\n s += '%-10s = %10.4f\\n' % ('dielectric', self.epsilon)\n s += '%-10s = %10.1e\\n' % ('tolerance', self.convergence_tol)\n s += '%-10s = %10.1e\\n' % ('cutoff', self.cutoff)\n s += '%-10s = %10d\\n' % ('npoint', self.npoint)\n s += '%-10s = %10d\\n' % ('nactive', self.n_active_point)\n return s\n","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.__str__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.__str__#L322-L323","kind":"function","name":"__str__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":322,"end_line":323,"context_start_line":302,"context_end_line":335,"code":" if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n @memoized_property\n def n_active_point(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_ACTIVE_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'PCMIntPlan:\\n'\n s += '%-10s = %10.4f\\n' % ('dielectric', self.epsilon)\n s += '%-10s = %10.1e\\n' % ('tolerance', self.convergence_tol)\n s += '%-10s = %10.1e\\n' % ('cutoff', self.cutoff)\n s += '%-10s = %10d\\n' % ('npoint', self.npoint)\n s += '%-10s = %10d\\n' % ('nactive', self.n_active_point)\n return s\n","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_plan.string#L326-L334","kind":"function","name":"string","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":326,"end_line":334,"context_start_line":306,"context_end_line":335,"code":" @memoized_property\n def n_active_point(self):\n npoint = ce.data_uint64_t()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_PCMINTPLAN,\n object=self.pcm_int_plan_handle,\n attribute=ce.CuestPCMIntPlanAttributes.CUEST_PCMINTPLAN_NUM_ACTIVE_POINT,\n attributeValue=npoint,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return npoint.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'PCMIntPlan:\\n'\n s += '%-10s = %10.4f\\n' % ('dielectric', self.epsilon)\n s += '%-10s = %10.1e\\n' % ('tolerance', self.convergence_tol)\n s += '%-10s = %10.1e\\n' % ('cutoff', self.cutoff)\n s += '%-10s = %10d\\n' % ('npoint', self.npoint)\n s += '%-10s = %10d\\n' % ('nactive', self.n_active_point)\n return s\n","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list#L1-L106","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_pair_list.py","language":"python","start_line":1,"end_line":106,"context_start_line":1,"context_end_line":106,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\n\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestAOPairList(object):\n\n def __init__( \n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n xyz : np.ndarray,\n threshold_pq : float,\n ):\n\n self.initialized = False\n\n if xyz.ndim != 2: raise RuntimeError('xyz.shape is not (ntom, 3)')\n if xyz.shape != (xyz.shape[0], 3): raise RuntimeError('xyz.shape is not (ntom, 3)')\n\n self.handle = handle\n\n ao_pair_list_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n )\n\n self.ao_pair_list_handle = ce.cuestAOPairListHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestAOPairListCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n numAtoms=xyz.shape[0],\n xyz=list(xyz.ravel()),\n thresholdPQ=threshold_pq,\n parameters=ao_pair_list_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestAOPairListCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n numAtoms=xyz.shape[0],\n xyz=list(xyz.ravel()),\n thresholdPQ=threshold_pq,\n parameters=ao_pair_list_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPairList=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOPairListDestroy(\n handle=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListDestroy failed')","source_hash":"a8dcbaa3ab7ed6482989f99ab9f840dea2849f66fae5b39667d03834f7cc5220","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list.CuestAOPairList","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list.CuestAOPairList#L28-L106","kind":"class","name":"CuestAOPairList","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_pair_list.py","language":"python","start_line":28,"end_line":106,"context_start_line":8,"context_end_line":106,"code":"# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\n\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestAOPairList(object):\n\n def __init__( \n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n xyz : np.ndarray,\n threshold_pq : float,\n ):\n\n self.initialized = False\n\n if xyz.ndim != 2: raise RuntimeError('xyz.shape is not (ntom, 3)')\n if xyz.shape != (xyz.shape[0], 3): raise RuntimeError('xyz.shape is not (ntom, 3)')\n\n self.handle = handle\n\n ao_pair_list_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n )\n\n self.ao_pair_list_handle = ce.cuestAOPairListHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestAOPairListCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n numAtoms=xyz.shape[0],\n xyz=list(xyz.ravel()),\n thresholdPQ=threshold_pq,\n parameters=ao_pair_list_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestAOPairListCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n numAtoms=xyz.shape[0],\n xyz=list(xyz.ravel()),\n thresholdPQ=threshold_pq,\n parameters=ao_pair_list_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPairList=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOPairListDestroy(\n handle=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListDestroy failed')","source_hash":"a8dcbaa3ab7ed6482989f99ab9f840dea2849f66fae5b39667d03834f7cc5220","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list.__init__#L30-L95","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_pair_list.py","language":"python","start_line":30,"end_line":95,"context_start_line":10,"context_end_line":106,"code":"# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\n\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestAOPairList(object):\n\n def __init__( \n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n xyz : np.ndarray,\n threshold_pq : float,\n ):\n\n self.initialized = False\n\n if xyz.ndim != 2: raise RuntimeError('xyz.shape is not (ntom, 3)')\n if xyz.shape != (xyz.shape[0], 3): raise RuntimeError('xyz.shape is not (ntom, 3)')\n\n self.handle = handle\n\n ao_pair_list_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOPAIRLIST_PARAMETERS,\n )\n\n self.ao_pair_list_handle = ce.cuestAOPairListHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestAOPairListCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n numAtoms=xyz.shape[0],\n xyz=list(xyz.ravel()),\n thresholdPQ=threshold_pq,\n parameters=ao_pair_list_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPairList=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestAOPairListCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n numAtoms=xyz.shape[0],\n xyz=list(xyz.ravel()),\n thresholdPQ=threshold_pq,\n parameters=ao_pair_list_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPairList=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOPairListDestroy(\n handle=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListDestroy failed')","source_hash":"a8dcbaa3ab7ed6482989f99ab9f840dea2849f66fae5b39667d03834f7cc5220","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_pair_list.__del__#L97-L106","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_pair_list.py","language":"python","start_line":97,"end_line":106,"context_start_line":77,"context_end_line":106,"code":" status = ce.cuestAOPairListCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n numAtoms=xyz.shape[0],\n xyz=list(xyz.ravel()),\n thresholdPQ=threshold_pq,\n parameters=ao_pair_list_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPairList=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOPairListDestroy(\n handle=self.ao_pair_list_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOPairListDestroy failed')","source_hash":"a8dcbaa3ab7ed6482989f99ab9f840dea2849f66fae5b39667d03834f7cc5220","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_parameters","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_parameters#L1-L51","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_parameters","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_parameters.py","language":"python","start_line":1,"end_line":51,"context_start_line":1,"context_end_line":51,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nclass CuestParameters(object):\n \n def __init__(\n self,\n *,\n parametersType,\n ): \n\n self.initialized = False\n\n self.parametersType = parametersType\n self.parameters = ce.Parameters()\n\n status = ce.cuestParametersCreate(\n parametersType=self.parametersType,\n outParameters=self.parameters,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_parameters_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestParametersDestroy(\n parametersType=self.parametersType,\n parameters=self.parameters,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_parameters_destroy failed')","source_hash":"272380704cd2c9b18a5c4ff67763b1dd09a89966320e489794fda600df422022","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_parameters.CuestParameters","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_parameters.CuestParameters#L18-L51","kind":"class","name":"CuestParameters","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_parameters.py","language":"python","start_line":18,"end_line":51,"context_start_line":1,"context_end_line":51,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nclass CuestParameters(object):\n \n def __init__(\n self,\n *,\n parametersType,\n ): \n\n self.initialized = False\n\n self.parametersType = parametersType\n self.parameters = ce.Parameters()\n\n status = ce.cuestParametersCreate(\n parametersType=self.parametersType,\n outParameters=self.parameters,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_parameters_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestParametersDestroy(\n parametersType=self.parametersType,\n parameters=self.parameters,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_parameters_destroy failed')","source_hash":"272380704cd2c9b18a5c4ff67763b1dd09a89966320e489794fda600df422022","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_parameters.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_parameters.__init__#L20-L39","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_parameters.py","language":"python","start_line":20,"end_line":39,"context_start_line":1,"context_end_line":51,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nclass CuestParameters(object):\n \n def __init__(\n self,\n *,\n parametersType,\n ): \n\n self.initialized = False\n\n self.parametersType = parametersType\n self.parameters = ce.Parameters()\n\n status = ce.cuestParametersCreate(\n parametersType=self.parametersType,\n outParameters=self.parameters,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_parameters_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestParametersDestroy(\n parametersType=self.parametersType,\n parameters=self.parameters,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_parameters_destroy failed')","source_hash":"272380704cd2c9b18a5c4ff67763b1dd09a89966320e489794fda600df422022","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_parameters.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_parameters.__del__#L41-L51","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_parameters.py","language":"python","start_line":41,"end_line":51,"context_start_line":21,"context_end_line":51,"code":" self,\n *,\n parametersType,\n ): \n\n self.initialized = False\n\n self.parametersType = parametersType\n self.parameters = ce.Parameters()\n\n status = ce.cuestParametersCreate(\n parametersType=self.parametersType,\n outParameters=self.parameters,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_parameters_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestParametersDestroy(\n parametersType=self.parametersType,\n parameters=self.parameters,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_parameters_destroy failed')","source_hash":"272380704cd2c9b18a5c4ff67763b1dd09a89966320e489794fda600df422022","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_handle","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_handle#L1-L78","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_handle","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","language":"python","start_line":1,"end_line":78,"context_start_line":1,"context_end_line":78,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestHandle(object):\n\n def __init__(\n self,\n ):\n\n self.initialized = False\n\n cuest_handle_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n )\n\n # NOTE: The CuestHandle has a number of defaultable parameters that\n # production codes may wish to expose to the user. Notable among these\n # is the CUDA stream. The CuestHandle will default to the host stream\n # (0), which is blocking. However, production codes may wish to provide\n # a custom stream to the CuestHandle, which will allow for asynchronous\n # cuEST library calls. Any such calls must use CUDA device memory that\n # is synchronized with the stream.\n\n self.handle = ce.cuestHandle()\n \n status = ce.cuestCreate(\n parameters=cuest_handle_parameters.parameters,\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDestroy(\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_destroy failed')\n\n def set_math_mode(\n self,\n *,\n mode,\n ):\n\n if not self.initialized: return\n\n status = ce.cuestSetMathMode(\n handle=self.handle,\n mode=mode,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_set_math_mode failed')\n","source_hash":"214b0f20a2e7b55eca82236111bed8fcd47bd2856fb979521af24cee6fe6704d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_handle.CuestHandle","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_handle.CuestHandle#L20-L77","kind":"class","name":"CuestHandle","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","language":"python","start_line":20,"end_line":77,"context_start_line":1,"context_end_line":78,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestHandle(object):\n\n def __init__(\n self,\n ):\n\n self.initialized = False\n\n cuest_handle_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n )\n\n # NOTE: The CuestHandle has a number of defaultable parameters that\n # production codes may wish to expose to the user. Notable among these\n # is the CUDA stream. The CuestHandle will default to the host stream\n # (0), which is blocking. However, production codes may wish to provide\n # a custom stream to the CuestHandle, which will allow for asynchronous\n # cuEST library calls. Any such calls must use CUDA device memory that\n # is synchronized with the stream.\n\n self.handle = ce.cuestHandle()\n \n status = ce.cuestCreate(\n parameters=cuest_handle_parameters.parameters,\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDestroy(\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_destroy failed')\n\n def set_math_mode(\n self,\n *,\n mode,\n ):\n\n if not self.initialized: return\n\n status = ce.cuestSetMathMode(\n handle=self.handle,\n mode=mode,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_set_math_mode failed')\n","source_hash":"214b0f20a2e7b55eca82236111bed8fcd47bd2856fb979521af24cee6fe6704d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_handle.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_handle.__init__#L22-L50","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","language":"python","start_line":22,"end_line":50,"context_start_line":2,"context_end_line":70,"code":"# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestHandle(object):\n\n def __init__(\n self,\n ):\n\n self.initialized = False\n\n cuest_handle_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_HANDLE_PARAMETERS,\n )\n\n # NOTE: The CuestHandle has a number of defaultable parameters that\n # production codes may wish to expose to the user. Notable among these\n # is the CUDA stream. The CuestHandle will default to the host stream\n # (0), which is blocking. However, production codes may wish to provide\n # a custom stream to the CuestHandle, which will allow for asynchronous\n # cuEST library calls. Any such calls must use CUDA device memory that\n # is synchronized with the stream.\n\n self.handle = ce.cuestHandle()\n \n status = ce.cuestCreate(\n parameters=cuest_handle_parameters.parameters,\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDestroy(\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_destroy failed')\n\n def set_math_mode(\n self,\n *,\n mode,\n ):\n\n if not self.initialized: return\n","source_hash":"214b0f20a2e7b55eca82236111bed8fcd47bd2856fb979521af24cee6fe6704d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_handle.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_handle.__del__#L52-L61","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","language":"python","start_line":52,"end_line":61,"context_start_line":32,"context_end_line":78,"code":" # NOTE: The CuestHandle has a number of defaultable parameters that\n # production codes may wish to expose to the user. Notable among these\n # is the CUDA stream. The CuestHandle will default to the host stream\n # (0), which is blocking. However, production codes may wish to provide\n # a custom stream to the CuestHandle, which will allow for asynchronous\n # cuEST library calls. Any such calls must use CUDA device memory that\n # is synchronized with the stream.\n\n self.handle = ce.cuestHandle()\n \n status = ce.cuestCreate(\n parameters=cuest_handle_parameters.parameters,\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDestroy(\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_destroy failed')\n\n def set_math_mode(\n self,\n *,\n mode,\n ):\n\n if not self.initialized: return\n\n status = ce.cuestSetMathMode(\n handle=self.handle,\n mode=mode,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_set_math_mode failed')\n","source_hash":"214b0f20a2e7b55eca82236111bed8fcd47bd2856fb979521af24cee6fe6704d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_handle.set_math_mode","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_handle.set_math_mode#L63-L77","kind":"function","name":"set_math_mode","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","language":"python","start_line":63,"end_line":77,"context_start_line":43,"context_end_line":78,"code":" parameters=cuest_handle_parameters.parameters,\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_create failed')\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDestroy(\n handle=self.handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_destroy failed')\n\n def set_math_mode(\n self,\n *,\n mode,\n ):\n\n if not self.initialized: return\n\n status = ce.cuestSetMathMode(\n handle=self.handle,\n mode=mode,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest_set_math_mode failed')\n","source_hash":"214b0f20a2e7b55eca82236111bed8fcd47bd2856fb979521af24cee6fe6704d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.memoized_property","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.memoized_property#L1-L55","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.memoized_property","path":"cuEST/cuest_scf_examples/cuest_scf/memoized_property.py","language":"python","start_line":1,"end_line":55,"context_start_line":1,"context_end_line":55,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom functools import wraps\n\ndef memoized_property(fget):\n \"\"\"\n Return a property attribute for new-style classes that only calls its getter on the first\n access. The result is stored and on subsequent accesses is returned, preventing the need to\n call the getter any more.\n\n Example::\n\n >>> class C(object):\n ... load_name_count = 0\n ... @memoized_property\n ... def name(self):\n ... \"name's docstring\"\n ... self.load_name_count += 1\n ... return \"the name\"\n >>> c = C()\n >>> c.load_name_count\n 0\n >>> c.name\n \"the name\"\n >>> c.load_name_count\n 1\n >>> c.name\n \"the name\"\n >>> c.load_name_count\n 1\n\n \"\"\"\n attr_name = '_{0}'.format(fget.__name__)\n\n @wraps(fget)\n def fget_memoized(self):\n if not hasattr(self, attr_name):\n setattr(self, attr_name, fget(self))\n return getattr(self, attr_name)\n\n return property(fget_memoized)\n","source_hash":"8069164d32bdbb2b7232c2fcfcb30de43b98007308880408a70961160d436d7b","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.memoized_property.memoized_property","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.memoized_property.memoized_property#L18-L54","kind":"function","name":"memoized_property","path":"cuEST/cuest_scf_examples/cuest_scf/memoized_property.py","language":"python","start_line":18,"end_line":54,"context_start_line":1,"context_end_line":55,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom functools import wraps\n\ndef memoized_property(fget):\n \"\"\"\n Return a property attribute for new-style classes that only calls its getter on the first\n access. The result is stored and on subsequent accesses is returned, preventing the need to\n call the getter any more.\n\n Example::\n\n >>> class C(object):\n ... load_name_count = 0\n ... @memoized_property\n ... def name(self):\n ... \"name's docstring\"\n ... self.load_name_count += 1\n ... return \"the name\"\n >>> c = C()\n >>> c.load_name_count\n 0\n >>> c.name\n \"the name\"\n >>> c.load_name_count\n 1\n >>> c.name\n \"the name\"\n >>> c.load_name_count\n 1\n\n \"\"\"\n attr_name = '_{0}'.format(fget.__name__)\n\n @wraps(fget)\n def fget_memoized(self):\n if not hasattr(self, attr_name):\n setattr(self, attr_name, fget(self))\n return getattr(self, attr_name)\n\n return property(fget_memoized)\n","source_hash":"8069164d32bdbb2b7232c2fcfcb30de43b98007308880408a70961160d436d7b","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.memoized_property.fget_memoized","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.memoized_property.fget_memoized#L49-L52","kind":"function","name":"fget_memoized","path":"cuEST/cuest_scf_examples/cuest_scf/memoized_property.py","language":"python","start_line":49,"end_line":52,"context_start_line":29,"context_end_line":55,"code":" ... def name(self):\n ... \"name's docstring\"\n ... self.load_name_count += 1\n ... return \"the name\"\n >>> c = C()\n >>> c.load_name_count\n 0\n >>> c.name\n \"the name\"\n >>> c.load_name_count\n 1\n >>> c.name\n \"the name\"\n >>> c.load_name_count\n 1\n\n \"\"\"\n attr_name = '_{0}'.format(fget.__name__)\n\n @wraps(fget)\n def fget_memoized(self):\n if not hasattr(self, attr_name):\n setattr(self, attr_name, fget(self))\n return getattr(self, attr_name)\n\n return property(fget_memoized)\n","source_hash":"8069164d32bdbb2b7232c2fcfcb30de43b98007308880408a70961160d436d7b","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.rhf#L1-L1313","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.rhf","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":1,"end_line":1313,"context_start_line":1,"context_end_line":1313,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .memoized_property import memoized_property\n\nfrom .molecule import Molecule\nfrom .ao_basis import AOBasis\nfrom .sad_guess import SADGuess\nfrom .diis import DIIS\nfrom .xc_functionals import XCFunctionalInfo\n\nfrom .cuda_utility import CudaUtility\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_molecular_grid import CuestMolecularGrid\nfrom .cuest_ao_pair_list import CuestAOPairList\nfrom .cuest_oe_int_plan import CuestOEIntPlan\nfrom .cuest_oe_int_compute import CuestOEIntCompute\nfrom .cuest_df_int_plan import CuestDFIntPlan\nfrom .cuest_df_int_compute import CuestDFIntCompute\nfrom .cuest_xc_int_plan import CuestXCIntPlan\nfrom .cuest_xc_int_compute import CuestXCIntCompute\nfrom .cuest_pcm_int_plan import CuestPCMIntPlan\nfrom .cuest_pcm_int_compute import CuestPCMIntCompute\n\nfrom .gpu_matrix import GPUMatrix\nfrom .gpu_matrix_utility import GPUMatrixUtility\n\nimport time\n\nclass RHF(object):\n\n def __init__(\n self,\n *,\n cuest_handle : CuestHandle,\n molecule : Molecule,\n charge : int,\n xc_functional_name : str = None,\n primary : AOBasis,\n auxiliary : AOBasis,\n minao : AOBasis,\n primary_name : str = None,\n auxiliary_name : str = None,\n minao_name : str = None,\n print_level : int = 2,\n threshold_pq : float = 1.0E-12,\n threshold_canonical : float = 1.0E-6,\n df_fitting_eigenvalue_cutoff : float = 1.0e-12,\n diis_max_nvector : int = 6,\n maxiter : int = 100,\n g_convergence : float = 1.0E-6,\n xc_threshold_collocation : float = 1.0e-18,\n xc_grid_level : int = 2,\n xc_grid_family : str = \"GRID\",\n nlc_threshold_collocation : float = 1.0e-18,\n nlc_grid_level : int = 1,\n nlc_grid_family : str = \"GRID\",\n dfk_int8_slice_count_start : int = 6,\n dfk_int8_modulus_count_start : int = 5,\n dfk_int8_slice_count_end : int = 6,\n dfk_int8_modulus_count_end : int = 9,\n pcm_epsilon: float = 1.0, # 1.0 for gas phase, >1.0 for solvated calc.\n pcm_x_prefactor: float = 0.0, # 0.0 for CPCM, 0.5 for COSMO\n pcm_cutoff: float = 1.0e-10,\n pcm_convergence_tol: float = 1e-10,\n pcm_num_angular_points_per_hydrogen_atom: int = 110,\n pcm_num_angular_points_per_heavy_atom: int = 194,\n ):\n\n\n self.cuest_handle = cuest_handle\n\n self.molecule = molecule\n self.charge = charge\n\n self.xc_functional = XCFunctionalInfo.string_to_enum(xc_functional_name)\n\n self.primary = primary\n self.auxiliary = auxiliary\n self.minao = minao\n\n self.primary_name = primary_name\n self.auxiliary_name = auxiliary_name\n self.minao_name = minao_name\n\n self.xc_threshold_collocation = xc_threshold_collocation\n self.xc_grid_level = xc_grid_level\n self.xc_grid_family = xc_grid_family\n\n self.nlc_threshold_collocation = nlc_threshold_collocation\n self.nlc_grid_level = nlc_grid_level\n self.nlc_grid_family = nlc_grid_family\n\n self.print_level = print_level\n\n self.threshold_pq = threshold_pq\n self.threshold_canonical = threshold_canonical\n self.df_fitting_eigenvalue_cutoff = df_fitting_eigenvalue_cutoff\n self.diis_max_nvector = diis_max_nvector\n self.maxiter = maxiter\n self.g_convergence = g_convergence\n\n self.pcm_num_angular_points_per_heavy_atom = pcm_num_angular_points_per_heavy_atom\n self.pcm_num_angular_points_per_hydrogen_atom = pcm_num_angular_points_per_hydrogen_atom\n self.pcm_epsilon = pcm_epsilon\n self.pcm_x_prefactor = pcm_x_prefactor\n self.pcm_cutoff = pcm_cutoff\n self.pcm_convergence_tol = pcm_convergence_tol\n self.pcm_q = None\n\n self.dfk_int8_slice_count_start = dfk_int8_slice_count_start\n self.dfk_int8_modulus_count_start = dfk_int8_modulus_count_start\n self.dfk_int8_slice_count_end = dfk_int8_slice_count_end\n self.dfk_int8_modulus_count_end = dfk_int8_modulus_count_end\n\n if primary.natom != molecule.natom: raise RuntimeError('primary.natom != molecule.natom')\n if auxiliary.natom != molecule.natom: raise RuntimeError('auxiliary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n self.sizes = {}\n self.scalars = {}\n self.tensors = {}\n\n self.is_solved = False\n self.is_converged = False\n\n self.gpu_xyz = GPUMatrix.from_numpy(self.molecule.xyz)\n self.gpu_Z = GPUMatrix.from_numpy(self.molecule.Z.reshape(-1,1))\n GPUMatrixUtility.scale(\n matrix=self.gpu_Z,\n scale=-1.0,\n )\n\n # => Cuest Objects <= #\n\n @memoized_property\n def cuest_primary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.primary,\n )\n \n @memoized_property\n def cuest_auxiliary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.auxiliary,\n )\n\n @memoized_property\n def cuest_xc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.xc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.xc_grid_family,\n )\n \n @memoized_property\n def cuest_nlc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.nlc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.nlc_grid_family,\n )\n \n @memoized_property\n def cuest_ao_pair_list(self):\n return CuestAOPairList(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n xyz=self.molecule.xyz,\n threshold_pq=self.threshold_pq,\n )\n\n @memoized_property\n def cuest_oe_int_plan(self):\n return CuestOEIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n ao_pair_list=self.cuest_ao_pair_list,\n ) \n\n @memoized_property\n def cuest_df_int_plan(self):\n return CuestDFIntPlan(\n handle=self.cuest_handle,\n primary=self.cuest_primary,\n auxiliary=self.cuest_auxiliary,\n ao_pair_list=self.cuest_ao_pair_list,\n exchange_scale=self.cuest_xc_int_plan.exchange_scale,\n df_fitting_eigenvalue_cutoff=self.df_fitting_eigenvalue_cutoff,\n )\n\n @memoized_property\n def cuest_xc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_xc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.xc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_nlc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_nlc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.nlc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_pcm_int_plan(self):\n if self.pcm_epsilon<=1.0:\n return None\n else:\n return CuestPCMIntPlan(\n handle=self.cuest_handle,\n intPlan=self.cuest_oe_int_plan,\n num_angular_points_per_heavy_atom=self.pcm_num_angular_points_per_heavy_atom,\n num_angular_points_per_hydrogen_atom=self.pcm_num_angular_points_per_hydrogen_atom,\n epsilon=self.pcm_epsilon,\n x_prefactor=self.pcm_x_prefactor,\n Ns=self.molecule.N,\n effective_nuclear_charges=self.molecule.Z,\n cutoff=self.pcm_cutoff,\n convergence_tol=self.pcm_convergence_tol,\n ) \n\n @property\n def do_pcm(self):\n return self.cuest_pcm_int_plan is not None\n\n\n # => Integrals <= #\n\n def compute_overlap(self):\n\n S = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Sptr=S.pointer,\n )\n\n return S\n \n def compute_kinetic(self):\n\n T = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n )\n\n CuestOEIntCompute.kinetic(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Tptr=T.pointer,\n )\n\n return T\n \n def compute_potential(self):\n\n xyz = self.gpu_xyz\n q = self.gpu_Z\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Vptr=V.pointer,\n ncharge=self.molecule.natom,\n xyz=xyz.pointer,\n q=q.pointer,\n )\n\n return V\n\n def compute_coulomb(\n self, \n D,\n ):\n\n J = D.clone()\n\n CuestDFIntCompute.coulomb(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Jptr=J.pointer,\n Dptr=D.pointer,\n )\n\n return J\n \n def compute_exchange(\n self, \n Cocc,\n dfk_int8_slice_count,\n dfk_int8_modulus_count,\n ):\n\n K = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n if self.cuest_df_int_plan.exchange_scale == 0.0:\n K.zero()\n return K\n\n CuestDFIntCompute.symmetric_exchange(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Kptr=K.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n dfk_int8_slice_count=dfk_int8_slice_count,\n dfk_int8_modulus_count=dfk_int8_modulus_count,\n )\n\n return K\n\n def compute_local_exchange_correlation(\n self, \n Cocc,\n ):\n\n if self.xc_functional == 0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.local_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return Exc, Vxc\n\n def compute_nonlocal_exchange_correlation(\n self, \n Cocc,\n ):\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.nonlocal_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return Exc, Vxc\n \n def compute_pcm_energy_and_potential(\n self, \n q,\n D,\n ):\n \n outQ = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n )\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Epcm, converged, residual = CuestPCMIntCompute.compute_pcm_energy_and_potential(\n handle=self.cuest_handle,\n pcm_int_plan=self.cuest_pcm_int_plan,\n Dptr=D.pointer, \n inQptr=q.pointer,\n outQptr=outQ.pointer,\n Vptr=V.pointer,\n )\n\n return Epcm, V, outQ\n\n # => Integral Derivatives (Gradients) <= #\n\n def compute_pcm_gradient(\n self, \n q,\n D,\n ):\n \n npoint = self.cuest_pcm_int_plan.npoint\n \n outQ = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n )\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestPCMIntCompute.compute_pcm_gradient(\n handle=self.cuest_handle,\n pcm_int_plan=self.cuest_pcm_int_plan,\n Dptr=D.pointer, \n inQptr=q.pointer,\n outQptr=outQ.pointer,\n Gptr=G.pointer,\n )\n\n return G\n\n def compute_overlap_gradient(\n self,\n W, # Energy-weighted density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Wptr=W.pointer,\n )\n\n return G\n\n def compute_kinetic_gradient(\n self,\n D, # Density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.kinetic_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Dptr=D.pointer,\n )\n\n return G\n\n def compute_potential_gradient(\n self,\n D, # Density matrix\n ): \n\n Gbasis = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n Gcharge = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n ncharge=self.molecule.natom,\n xyz=self.gpu_xyz.pointer,\n q=self.gpu_Z.pointer,\n Dptr=D.pointer,\n GptrBasis=Gbasis.pointer,\n GptrCharge=Gcharge.pointer,\n )\n\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Gcharge,\n y=Gbasis,\n )\n\n return Gbasis\n\n def compute_coulomb_and_exchange_gradient(\n self, \n *,\n scaleJ,\n DJ,\n scaleK,\n CoccsK,\n ):\n\n noccsK = [_.shape[0] for _ in CoccsK]\n assert len(CoccsK) == 1\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestDFIntCompute.coulomb_and_exchange_gradient(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n scaleJ=scaleJ,\n DJptr=DJ.pointer,\n scaleK=scaleK, \n noccsK=noccsK,\n CoccsKptr=CoccsK[0].pointer,\n Gptr=G.pointer,\n )\n\n return G\n\n def compute_local_exchange_correlation_gradient(\n self, \n Cocc,\n ):\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n if self.xc_functional == 0:\n G.zero()\n return G\n\n CuestXCIntCompute.local_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return G\n\n def compute_nonlocal_exchange_correlation_gradient(\n self, \n Cocc,\n ):\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n G.zero()\n return G\n\n CuestXCIntCompute.nonlocal_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return G\n\n # => Main Solve Routines <= #\n \n def solve(self):\n\n self.is_solved = False\n self.is_converged = False\n\n self.header()\n\n # Plan initializations (to cleanly separate from iterations). The orthogonalization\n # calls for S, so most of these are automatically instantiated in that routine. Build\n # them here to get an idea of how long they take.\n _ = self.cuest_ao_pair_list\n\n _ = self.cuest_oe_int_plan\n\n _ = self.cuest_xc_int_plan\n\n start = time.time()\n _ = self.cuest_df_int_plan\n stop = time.time()\n \n _ = self.cuest_nlc_int_plan\n\n _ = self.cuest_pcm_int_plan\n\n self.compute_guess()\n\n self.compute_orthogonalization()\n\n self.compute_occupations()\n\n if self.print_level > 0:\n print('DFIntPlan Initialize Time: %11.3E [s]' % (stop - start))\n print('')\n\n self.solve_diis()\n\n self.trailer()\n\n self.is_solved = True\n\n def header(self):\n \n self.start_time = time.time()\n \n if self.print_level:\n print('==> cuEST RHF (Python) <==\\n')\n \n if self.print_level > 1:\n\n print('natom = %4d' % (self.molecule.natom))\n print('charge = %4d' % (self.charge))\n print('')\n\n print('Primary Basis: %s' % (self.primary_name if self.primary_name is not None else ''))\n print('')\n print(self.primary)\n\n print('Auxiliary Basis: %s' % (self.auxiliary_name if self.auxiliary_name is not None else ''))\n print('')\n print(self.auxiliary)\n\n print('MinAO Basis: %s' % (self.minao_name if self.minao_name is not None else ''))\n print('')\n print(self.minao)\n\n print(self.cuest_xc_int_plan)\n \n print('XC Grid:')\n print('')\n print(self.cuest_xc_grid)\n\n print('Nonlocal XC Grid:')\n print('')\n print(self.cuest_nlc_grid)\n\n if self.do_pcm:\n print('PCM:')\n print('')\n print(self.cuest_pcm_int_plan)\n\n def trailer(self):\n\n if self.print_level:\n print('cuEST RHF Time: %11.3E [s]\\n' % (time.time() - self.start_time))\n \n del self.start_time\n \n if self.print_level:\n print('==> End cuEST RHF (Python) <==\\n')\n\n def compute_guess(self):\n\n if self.print_level > 0:\n print('SAD Guess:\\n')\n\n self.sad_guess = SADGuess.build(\n molecule=self.mol\n# ... truncated ...","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.RHF","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.rhf.RHF#L46-L1312","kind":"class","name":"RHF","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":46,"end_line":1312,"context_start_line":26,"context_end_line":1313,"code":"from .cuda_utility import CudaUtility\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_molecular_grid import CuestMolecularGrid\nfrom .cuest_ao_pair_list import CuestAOPairList\nfrom .cuest_oe_int_plan import CuestOEIntPlan\nfrom .cuest_oe_int_compute import CuestOEIntCompute\nfrom .cuest_df_int_plan import CuestDFIntPlan\nfrom .cuest_df_int_compute import CuestDFIntCompute\nfrom .cuest_xc_int_plan import CuestXCIntPlan\nfrom .cuest_xc_int_compute import CuestXCIntCompute\nfrom .cuest_pcm_int_plan import CuestPCMIntPlan\nfrom .cuest_pcm_int_compute import CuestPCMIntCompute\n\nfrom .gpu_matrix import GPUMatrix\nfrom .gpu_matrix_utility import GPUMatrixUtility\n\nimport time\n\nclass RHF(object):\n\n def __init__(\n self,\n *,\n cuest_handle : CuestHandle,\n molecule : Molecule,\n charge : int,\n xc_functional_name : str = None,\n primary : AOBasis,\n auxiliary : AOBasis,\n minao : AOBasis,\n primary_name : str = None,\n auxiliary_name : str = None,\n minao_name : str = None,\n print_level : int = 2,\n threshold_pq : float = 1.0E-12,\n threshold_canonical : float = 1.0E-6,\n df_fitting_eigenvalue_cutoff : float = 1.0e-12,\n diis_max_nvector : int = 6,\n maxiter : int = 100,\n g_convergence : float = 1.0E-6,\n xc_threshold_collocation : float = 1.0e-18,\n xc_grid_level : int = 2,\n xc_grid_family : str = \"GRID\",\n nlc_threshold_collocation : float = 1.0e-18,\n nlc_grid_level : int = 1,\n nlc_grid_family : str = \"GRID\",\n dfk_int8_slice_count_start : int = 6,\n dfk_int8_modulus_count_start : int = 5,\n dfk_int8_slice_count_end : int = 6,\n dfk_int8_modulus_count_end : int = 9,\n pcm_epsilon: float = 1.0, # 1.0 for gas phase, >1.0 for solvated calc.\n pcm_x_prefactor: float = 0.0, # 0.0 for CPCM, 0.5 for COSMO\n pcm_cutoff: float = 1.0e-10,\n pcm_convergence_tol: float = 1e-10,\n pcm_num_angular_points_per_hydrogen_atom: int = 110,\n pcm_num_angular_points_per_heavy_atom: int = 194,\n ):\n\n\n self.cuest_handle = cuest_handle\n\n self.molecule = molecule\n self.charge = charge\n\n self.xc_functional = XCFunctionalInfo.string_to_enum(xc_functional_name)\n\n self.primary = primary\n self.auxiliary = auxiliary\n self.minao = minao\n\n self.primary_name = primary_name\n self.auxiliary_name = auxiliary_name\n self.minao_name = minao_name\n\n self.xc_threshold_collocation = xc_threshold_collocation\n self.xc_grid_level = xc_grid_level\n self.xc_grid_family = xc_grid_family\n\n self.nlc_threshold_collocation = nlc_threshold_collocation\n self.nlc_grid_level = nlc_grid_level\n self.nlc_grid_family = nlc_grid_family\n\n self.print_level = print_level\n\n self.threshold_pq = threshold_pq\n self.threshold_canonical = threshold_canonical\n self.df_fitting_eigenvalue_cutoff = df_fitting_eigenvalue_cutoff\n self.diis_max_nvector = diis_max_nvector\n self.maxiter = maxiter\n self.g_convergence = g_convergence\n\n self.pcm_num_angular_points_per_heavy_atom = pcm_num_angular_points_per_heavy_atom\n self.pcm_num_angular_points_per_hydrogen_atom = pcm_num_angular_points_per_hydrogen_atom\n self.pcm_epsilon = pcm_epsilon\n self.pcm_x_prefactor = pcm_x_prefactor\n self.pcm_cutoff = pcm_cutoff\n self.pcm_convergence_tol = pcm_convergence_tol\n self.pcm_q = None\n\n self.dfk_int8_slice_count_start = dfk_int8_slice_count_start\n self.dfk_int8_modulus_count_start = dfk_int8_modulus_count_start\n self.dfk_int8_slice_count_end = dfk_int8_slice_count_end\n self.dfk_int8_modulus_count_end = dfk_int8_modulus_count_end\n\n if primary.natom != molecule.natom: raise RuntimeError('primary.natom != molecule.natom')\n if auxiliary.natom != molecule.natom: raise RuntimeError('auxiliary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n self.sizes = {}\n self.scalars = {}\n self.tensors = {}\n\n self.is_solved = False\n self.is_converged = False\n\n self.gpu_xyz = GPUMatrix.from_numpy(self.molecule.xyz)\n self.gpu_Z = GPUMatrix.from_numpy(self.molecule.Z.reshape(-1,1))\n GPUMatrixUtility.scale(\n matrix=self.gpu_Z,\n scale=-1.0,\n )\n\n # => Cuest Objects <= #\n\n @memoized_property\n def cuest_primary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.primary,\n )\n \n @memoized_property\n def cuest_auxiliary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.auxiliary,\n )\n\n @memoized_property\n def cuest_xc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.xc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.xc_grid_family,\n )\n \n @memoized_property\n def cuest_nlc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.nlc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.nlc_grid_family,\n )\n \n @memoized_property\n def cuest_ao_pair_list(self):\n return CuestAOPairList(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n xyz=self.molecule.xyz,\n threshold_pq=self.threshold_pq,\n )\n\n @memoized_property\n def cuest_oe_int_plan(self):\n return CuestOEIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n ao_pair_list=self.cuest_ao_pair_list,\n ) \n\n @memoized_property\n def cuest_df_int_plan(self):\n return CuestDFIntPlan(\n handle=self.cuest_handle,\n primary=self.cuest_primary,\n auxiliary=self.cuest_auxiliary,\n ao_pair_list=self.cuest_ao_pair_list,\n exchange_scale=self.cuest_xc_int_plan.exchange_scale,\n df_fitting_eigenvalue_cutoff=self.df_fitting_eigenvalue_cutoff,\n )\n\n @memoized_property\n def cuest_xc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_xc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.xc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_nlc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_nlc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.nlc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_pcm_int_plan(self):\n if self.pcm_epsilon<=1.0:\n return None\n else:\n return CuestPCMIntPlan(\n handle=self.cuest_handle,\n intPlan=self.cuest_oe_int_plan,\n num_angular_points_per_heavy_atom=self.pcm_num_angular_points_per_heavy_atom,\n num_angular_points_per_hydrogen_atom=self.pcm_num_angular_points_per_hydrogen_atom,\n epsilon=self.pcm_epsilon,\n x_prefactor=self.pcm_x_prefactor,\n Ns=self.molecule.N,\n effective_nuclear_charges=self.molecule.Z,\n cutoff=self.pcm_cutoff,\n convergence_tol=self.pcm_convergence_tol,\n ) \n\n @property\n def do_pcm(self):\n return self.cuest_pcm_int_plan is not None\n\n\n # => Integrals <= #\n\n def compute_overlap(self):\n\n S = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Sptr=S.pointer,\n )\n\n return S\n \n def compute_kinetic(self):\n\n T = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n )\n\n CuestOEIntCompute.kinetic(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Tptr=T.pointer,\n )\n\n return T\n \n def compute_potential(self):\n\n xyz = self.gpu_xyz\n q = self.gpu_Z\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Vptr=V.pointer,\n ncharge=self.molecule.natom,\n xyz=xyz.pointer,\n q=q.pointer,\n )\n\n return V\n\n def compute_coulomb(\n self, \n D,\n ):\n\n J = D.clone()\n\n CuestDFIntCompute.coulomb(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Jptr=J.pointer,\n Dptr=D.pointer,\n )\n\n return J\n \n def compute_exchange(\n self, \n Cocc,\n dfk_int8_slice_count,\n dfk_int8_modulus_count,\n ):\n\n K = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n if self.cuest_df_int_plan.exchange_scale == 0.0:\n K.zero()\n return K\n\n CuestDFIntCompute.symmetric_exchange(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Kptr=K.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n dfk_int8_slice_count=dfk_int8_slice_count,\n dfk_int8_modulus_count=dfk_int8_modulus_count,\n )\n\n return K\n\n def compute_local_exchange_correlation(\n self, \n Cocc,\n ):\n\n if self.xc_functional == 0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.local_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return Exc, Vxc\n\n def compute_nonlocal_exchange_correlation(\n self, \n Cocc,\n ):\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.nonlocal_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return Exc, Vxc\n \n def compute_pcm_energy_and_potential(\n self, \n q,\n D,\n ):\n \n outQ = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n )\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Epcm, converged, residual = CuestPCMIntCompute.compute_pcm_energy_and_potential(\n handle=self.cuest_handle,\n pcm_int_plan=self.cuest_pcm_int_plan,\n Dptr=D.pointer, \n inQptr=q.pointer,\n outQptr=outQ.pointer,\n Vptr=V.pointer,\n )\n\n return Epcm, V, outQ\n\n # => Integral Derivatives (Gradients) <= #\n\n def compute_pcm_gradient(\n self, \n q,\n D,\n ):\n \n npoint = self.cuest_pcm_int_plan.npoint\n \n outQ = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n )\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestPCMIntCompute.compute_pcm_gradient(\n handle=self.cuest_handle,\n pcm_int_plan=self.cuest_pcm_int_plan,\n Dptr=D.pointer, \n inQptr=q.pointer,\n outQptr=outQ.pointer,\n Gptr=G.pointer,\n )\n\n return G\n\n def compute_overlap_gradient(\n self,\n W, # Energy-weighted density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Wptr=W.pointer,\n )\n\n return G\n\n def compute_kinetic_gradient(\n self,\n D, # Density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.kinetic_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Dptr=D.pointer,\n )\n\n return G\n\n def compute_potential_gradient(\n self,\n D, # Density matrix\n ): \n\n Gbasis = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n Gcharge = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n ncharge=self.molecule.natom,\n xyz=self.gpu_xyz.pointer,\n q=self.gpu_Z.pointer,\n Dptr=D.pointer,\n GptrBasis=Gbasis.pointer,\n GptrCharge=Gcharge.pointer,\n )\n\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Gcharge,\n y=Gbasis,\n )\n\n return Gbasis\n\n def compute_coulomb_and_exchange_gradient(\n self, \n *,\n scaleJ,\n DJ,\n scaleK,\n CoccsK,\n ):\n\n noccsK = [_.shape[0] for _ in CoccsK]\n assert len(CoccsK) == 1\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestDFIntCompute.coulomb_and_exchange_gradient(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n scaleJ=scaleJ,\n DJptr=DJ.pointer,\n scaleK=scaleK, \n noccsK=noccsK,\n CoccsKptr=CoccsK[0].pointer,\n Gptr=G.pointer,\n )\n\n return G\n\n def compute_local_exchange_correlation_gradient(\n self, \n Cocc,\n ):\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n if self.xc_functional == 0:\n G.zero()\n return G\n\n CuestXCIntCompute.local_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return G\n\n def compute_nonlocal_exchange_correlation_gradient(\n self, \n Cocc,\n ):\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n G.zero()\n return G\n\n CuestXCIntCompute.nonlocal_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return G\n\n # => Main Solve Routines <= #\n \n def solve(self):\n\n self.is_solved = False\n self.is_converged = False\n\n self.header()\n\n # Plan initializations (to cleanly separate from iterations). The orthogonalization\n # calls for S, so most of these are automatically instantiated in that routine. Build\n # them here to get an idea of how long they take.\n _ = self.cuest_ao_pair_list\n\n _ = self.cuest_oe_int_plan\n\n _ = self.cuest_xc_int_plan\n\n start = time.time()\n _ = self.cuest_df_int_plan\n stop = time.time()\n \n _ = self.cuest_nlc_int_plan\n\n _ = self.cuest_pcm_int_plan\n\n self.compute_guess()\n\n self.compute_orthogonalization()\n\n self.compute_occupations()\n\n if self.print_level > 0:\n print('DFIntPlan Initialize Time: %11.3E [s]' % (stop - start))\n print('')\n\n self.solve_diis()\n\n self.trailer()\n\n self.is_solved = True\n\n def header(self):\n \n self.start_time = time.time()\n \n if self.print_level:\n print('==> cuEST RHF (Python) <==\\n')\n \n if self.print_level > 1:\n\n print('natom = %4d' % (self.molecule.natom))\n print('charge = %4d' % (self.charge))\n print('')\n\n print('Primary Basis: %s' % (self.primary_name if self.primary_name is not None else ''))\n print('')\n print(self.primary)\n\n print('Auxiliary Basis: %s' % (self.auxiliary_name if self.auxiliary_name is not None else ''))\n print('')\n print(self.auxiliary)\n\n print('MinAO Basis: %s' % (self.minao_name if self.minao_name is not None else ''))\n print('')\n print(self.minao)\n\n print(self.cuest_xc_int_plan)\n \n print('XC Grid:')\n print('')\n print(self.cuest_xc_grid)\n\n print('Nonlocal XC Grid:')\n print('')\n print(self.cuest_nlc_grid)\n\n if self.do_pcm:\n print('PCM:')\n print('')\n print(self.cuest_pcm_int_plan)\n\n def trailer(self):\n\n if self.print_level:\n print('cuEST RHF Time: %11.3E [s]\\n' % (time.time() - self.start_time))\n \n del self.start_time\n \n if self.print_level:\n print('==> End cuEST RHF (Python) <==\\n')\n\n def compute_guess(self):\n\n if self.print_level > 0:\n print('SAD Guess:\\n')\n\n self.sad_guess = SADGuess.build(\n molecule=self.molecule,\n primary=self.primary,\n minao=self.minao,\n )\n\n # For now this will be size (nminao, nao), which is usually larger than\n # (nocc, nao) due to fractional occupations in SAD\n self.tensors['Cocc'] = GPUMatrix.from_numpy(self.sad_guess.compute_Cocc())\n\n # For now this is not a pure state, and corresponds to the neutral SAD\n # guess\n self.tensors['D'] = GPUMatrix.from_numpy(self.sad_guess.compute_Docc())\n\n def compute_orthogonalization(self):\n\n if self.print_level > 0:\n print('Orthogonalization:\\n')\n\n S = self.compute_overlap()\n\n s, U = GPUMatrixUtility.eigh(matrix=S)\n s = s.to_numpy().reshape(-1)\n U = U.to_numpy()\n\n # Canonical orthogonalization is traditionally done on an absolute eigenvalue threshold basis\n sind = s > self.threshold_canonical\n# ... truncated ...","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":true} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.__init__#L48-L148","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":48,"end_line":148,"context_start_line":28,"context_end_line":168,"code":"from .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_molecular_grid import CuestMolecularGrid\nfrom .cuest_ao_pair_list import CuestAOPairList\nfrom .cuest_oe_int_plan import CuestOEIntPlan\nfrom .cuest_oe_int_compute import CuestOEIntCompute\nfrom .cuest_df_int_plan import CuestDFIntPlan\nfrom .cuest_df_int_compute import CuestDFIntCompute\nfrom .cuest_xc_int_plan import CuestXCIntPlan\nfrom .cuest_xc_int_compute import CuestXCIntCompute\nfrom .cuest_pcm_int_plan import CuestPCMIntPlan\nfrom .cuest_pcm_int_compute import CuestPCMIntCompute\n\nfrom .gpu_matrix import GPUMatrix\nfrom .gpu_matrix_utility import GPUMatrixUtility\n\nimport time\n\nclass RHF(object):\n\n def __init__(\n self,\n *,\n cuest_handle : CuestHandle,\n molecule : Molecule,\n charge : int,\n xc_functional_name : str = None,\n primary : AOBasis,\n auxiliary : AOBasis,\n minao : AOBasis,\n primary_name : str = None,\n auxiliary_name : str = None,\n minao_name : str = None,\n print_level : int = 2,\n threshold_pq : float = 1.0E-12,\n threshold_canonical : float = 1.0E-6,\n df_fitting_eigenvalue_cutoff : float = 1.0e-12,\n diis_max_nvector : int = 6,\n maxiter : int = 100,\n g_convergence : float = 1.0E-6,\n xc_threshold_collocation : float = 1.0e-18,\n xc_grid_level : int = 2,\n xc_grid_family : str = \"GRID\",\n nlc_threshold_collocation : float = 1.0e-18,\n nlc_grid_level : int = 1,\n nlc_grid_family : str = \"GRID\",\n dfk_int8_slice_count_start : int = 6,\n dfk_int8_modulus_count_start : int = 5,\n dfk_int8_slice_count_end : int = 6,\n dfk_int8_modulus_count_end : int = 9,\n pcm_epsilon: float = 1.0, # 1.0 for gas phase, >1.0 for solvated calc.\n pcm_x_prefactor: float = 0.0, # 0.0 for CPCM, 0.5 for COSMO\n pcm_cutoff: float = 1.0e-10,\n pcm_convergence_tol: float = 1e-10,\n pcm_num_angular_points_per_hydrogen_atom: int = 110,\n pcm_num_angular_points_per_heavy_atom: int = 194,\n ):\n\n\n self.cuest_handle = cuest_handle\n\n self.molecule = molecule\n self.charge = charge\n\n self.xc_functional = XCFunctionalInfo.string_to_enum(xc_functional_name)\n\n self.primary = primary\n self.auxiliary = auxiliary\n self.minao = minao\n\n self.primary_name = primary_name\n self.auxiliary_name = auxiliary_name\n self.minao_name = minao_name\n\n self.xc_threshold_collocation = xc_threshold_collocation\n self.xc_grid_level = xc_grid_level\n self.xc_grid_family = xc_grid_family\n\n self.nlc_threshold_collocation = nlc_threshold_collocation\n self.nlc_grid_level = nlc_grid_level\n self.nlc_grid_family = nlc_grid_family\n\n self.print_level = print_level\n\n self.threshold_pq = threshold_pq\n self.threshold_canonical = threshold_canonical\n self.df_fitting_eigenvalue_cutoff = df_fitting_eigenvalue_cutoff\n self.diis_max_nvector = diis_max_nvector\n self.maxiter = maxiter\n self.g_convergence = g_convergence\n\n self.pcm_num_angular_points_per_heavy_atom = pcm_num_angular_points_per_heavy_atom\n self.pcm_num_angular_points_per_hydrogen_atom = pcm_num_angular_points_per_hydrogen_atom\n self.pcm_epsilon = pcm_epsilon\n self.pcm_x_prefactor = pcm_x_prefactor\n self.pcm_cutoff = pcm_cutoff\n self.pcm_convergence_tol = pcm_convergence_tol\n self.pcm_q = None\n\n self.dfk_int8_slice_count_start = dfk_int8_slice_count_start\n self.dfk_int8_modulus_count_start = dfk_int8_modulus_count_start\n self.dfk_int8_slice_count_end = dfk_int8_slice_count_end\n self.dfk_int8_modulus_count_end = dfk_int8_modulus_count_end\n\n if primary.natom != molecule.natom: raise RuntimeError('primary.natom != molecule.natom')\n if auxiliary.natom != molecule.natom: raise RuntimeError('auxiliary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n self.sizes = {}\n self.scalars = {}\n self.tensors = {}\n\n self.is_solved = False\n self.is_converged = False\n\n self.gpu_xyz = GPUMatrix.from_numpy(self.molecule.xyz)\n self.gpu_Z = GPUMatrix.from_numpy(self.molecule.Z.reshape(-1,1))\n GPUMatrixUtility.scale(\n matrix=self.gpu_Z,\n scale=-1.0,\n )\n\n # => Cuest Objects <= #\n\n @memoized_property\n def cuest_primary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.primary,\n )\n \n @memoized_property\n def cuest_auxiliary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.auxiliary,\n )\n\n @memoized_property\n def cuest_xc_grid(self):\n return CuestMolecularGrid(","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_primary","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_primary#L153-L157","kind":"function","name":"cuest_primary","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":153,"end_line":157,"context_start_line":133,"context_end_line":177,"code":" if auxiliary.natom != molecule.natom: raise RuntimeError('auxiliary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n self.sizes = {}\n self.scalars = {}\n self.tensors = {}\n\n self.is_solved = False\n self.is_converged = False\n\n self.gpu_xyz = GPUMatrix.from_numpy(self.molecule.xyz)\n self.gpu_Z = GPUMatrix.from_numpy(self.molecule.Z.reshape(-1,1))\n GPUMatrixUtility.scale(\n matrix=self.gpu_Z,\n scale=-1.0,\n )\n\n # => Cuest Objects <= #\n\n @memoized_property\n def cuest_primary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.primary,\n )\n \n @memoized_property\n def cuest_auxiliary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.auxiliary,\n )\n\n @memoized_property\n def cuest_xc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.xc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.xc_grid_family,\n )\n \n @memoized_property\n def cuest_nlc_grid(self):","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_auxiliary","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_auxiliary#L160-L164","kind":"function","name":"cuest_auxiliary","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":160,"end_line":164,"context_start_line":140,"context_end_line":184,"code":" self.is_solved = False\n self.is_converged = False\n\n self.gpu_xyz = GPUMatrix.from_numpy(self.molecule.xyz)\n self.gpu_Z = GPUMatrix.from_numpy(self.molecule.Z.reshape(-1,1))\n GPUMatrixUtility.scale(\n matrix=self.gpu_Z,\n scale=-1.0,\n )\n\n # => Cuest Objects <= #\n\n @memoized_property\n def cuest_primary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.primary,\n )\n \n @memoized_property\n def cuest_auxiliary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.auxiliary,\n )\n\n @memoized_property\n def cuest_xc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.xc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.xc_grid_family,\n )\n \n @memoized_property\n def cuest_nlc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.nlc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.nlc_grid_family,\n )","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_xc_grid","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_xc_grid#L167-L174","kind":"function","name":"cuest_xc_grid","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":167,"end_line":174,"context_start_line":147,"context_end_line":194,"code":" scale=-1.0,\n )\n\n # => Cuest Objects <= #\n\n @memoized_property\n def cuest_primary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.primary,\n )\n \n @memoized_property\n def cuest_auxiliary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.auxiliary,\n )\n\n @memoized_property\n def cuest_xc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.xc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.xc_grid_family,\n )\n \n @memoized_property\n def cuest_nlc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.nlc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.nlc_grid_family,\n )\n \n @memoized_property\n def cuest_ao_pair_list(self):\n return CuestAOPairList(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n xyz=self.molecule.xyz,\n threshold_pq=self.threshold_pq,\n )\n","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_nlc_grid","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_nlc_grid#L177-L184","kind":"function","name":"cuest_nlc_grid","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":177,"end_line":184,"context_start_line":157,"context_end_line":204,"code":" )\n \n @memoized_property\n def cuest_auxiliary(self):\n return CuestAOBasis(\n handle=self.cuest_handle, \n basis=self.auxiliary,\n )\n\n @memoized_property\n def cuest_xc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.xc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.xc_grid_family,\n )\n \n @memoized_property\n def cuest_nlc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.nlc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.nlc_grid_family,\n )\n \n @memoized_property\n def cuest_ao_pair_list(self):\n return CuestAOPairList(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n xyz=self.molecule.xyz,\n threshold_pq=self.threshold_pq,\n )\n\n @memoized_property\n def cuest_oe_int_plan(self):\n return CuestOEIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n ao_pair_list=self.cuest_ao_pair_list,\n ) \n\n @memoized_property\n def cuest_df_int_plan(self):","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_ao_pair_list","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_ao_pair_list#L187-L193","kind":"function","name":"cuest_ao_pair_list","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":187,"end_line":193,"context_start_line":167,"context_end_line":213,"code":" def cuest_xc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.xc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.xc_grid_family,\n )\n \n @memoized_property\n def cuest_nlc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.nlc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.nlc_grid_family,\n )\n \n @memoized_property\n def cuest_ao_pair_list(self):\n return CuestAOPairList(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n xyz=self.molecule.xyz,\n threshold_pq=self.threshold_pq,\n )\n\n @memoized_property\n def cuest_oe_int_plan(self):\n return CuestOEIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n ao_pair_list=self.cuest_ao_pair_list,\n ) \n\n @memoized_property\n def cuest_df_int_plan(self):\n return CuestDFIntPlan(\n handle=self.cuest_handle,\n primary=self.cuest_primary,\n auxiliary=self.cuest_auxiliary,\n ao_pair_list=self.cuest_ao_pair_list,\n exchange_scale=self.cuest_xc_int_plan.exchange_scale,\n df_fitting_eigenvalue_cutoff=self.df_fitting_eigenvalue_cutoff,\n )\n","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_oe_int_plan","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_oe_int_plan#L196-L201","kind":"function","name":"cuest_oe_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":196,"end_line":201,"context_start_line":176,"context_end_line":221,"code":" @memoized_property\n def cuest_nlc_grid(self):\n return CuestMolecularGrid(\n handle=self.cuest_handle, \n grid_level=self.nlc_grid_level,\n xyz=self.molecule.xyz,\n Ns=self.molecule.N,\n family=self.nlc_grid_family,\n )\n \n @memoized_property\n def cuest_ao_pair_list(self):\n return CuestAOPairList(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n xyz=self.molecule.xyz,\n threshold_pq=self.threshold_pq,\n )\n\n @memoized_property\n def cuest_oe_int_plan(self):\n return CuestOEIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n ao_pair_list=self.cuest_ao_pair_list,\n ) \n\n @memoized_property\n def cuest_df_int_plan(self):\n return CuestDFIntPlan(\n handle=self.cuest_handle,\n primary=self.cuest_primary,\n auxiliary=self.cuest_auxiliary,\n ao_pair_list=self.cuest_ao_pair_list,\n exchange_scale=self.cuest_xc_int_plan.exchange_scale,\n df_fitting_eigenvalue_cutoff=self.df_fitting_eigenvalue_cutoff,\n )\n\n @memoized_property\n def cuest_xc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_xc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.xc_threshold_collocation,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_df_int_plan","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_df_int_plan#L204-L212","kind":"function","name":"cuest_df_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":204,"end_line":212,"context_start_line":184,"context_end_line":232,"code":" )\n \n @memoized_property\n def cuest_ao_pair_list(self):\n return CuestAOPairList(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n xyz=self.molecule.xyz,\n threshold_pq=self.threshold_pq,\n )\n\n @memoized_property\n def cuest_oe_int_plan(self):\n return CuestOEIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n ao_pair_list=self.cuest_ao_pair_list,\n ) \n\n @memoized_property\n def cuest_df_int_plan(self):\n return CuestDFIntPlan(\n handle=self.cuest_handle,\n primary=self.cuest_primary,\n auxiliary=self.cuest_auxiliary,\n ao_pair_list=self.cuest_ao_pair_list,\n exchange_scale=self.cuest_xc_int_plan.exchange_scale,\n df_fitting_eigenvalue_cutoff=self.df_fitting_eigenvalue_cutoff,\n )\n\n @memoized_property\n def cuest_xc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_xc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.xc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_nlc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_nlc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.nlc_threshold_collocation,\n ) ","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_xc_int_plan","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_xc_int_plan#L215-L222","kind":"function","name":"cuest_xc_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":215,"end_line":222,"context_start_line":195,"context_end_line":242,"code":" @memoized_property\n def cuest_oe_int_plan(self):\n return CuestOEIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n ao_pair_list=self.cuest_ao_pair_list,\n ) \n\n @memoized_property\n def cuest_df_int_plan(self):\n return CuestDFIntPlan(\n handle=self.cuest_handle,\n primary=self.cuest_primary,\n auxiliary=self.cuest_auxiliary,\n ao_pair_list=self.cuest_ao_pair_list,\n exchange_scale=self.cuest_xc_int_plan.exchange_scale,\n df_fitting_eigenvalue_cutoff=self.df_fitting_eigenvalue_cutoff,\n )\n\n @memoized_property\n def cuest_xc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_xc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.xc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_nlc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_nlc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.nlc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_pcm_int_plan(self):\n if self.pcm_epsilon<=1.0:\n return None\n else:\n return CuestPCMIntPlan(\n handle=self.cuest_handle,\n intPlan=self.cuest_oe_int_plan,\n num_angular_points_per_heavy_atom=self.pcm_num_angular_points_per_heavy_atom,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_nlc_int_plan","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_nlc_int_plan#L225-L232","kind":"function","name":"cuest_nlc_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":225,"end_line":232,"context_start_line":205,"context_end_line":252,"code":" return CuestDFIntPlan(\n handle=self.cuest_handle,\n primary=self.cuest_primary,\n auxiliary=self.cuest_auxiliary,\n ao_pair_list=self.cuest_ao_pair_list,\n exchange_scale=self.cuest_xc_int_plan.exchange_scale,\n df_fitting_eigenvalue_cutoff=self.df_fitting_eigenvalue_cutoff,\n )\n\n @memoized_property\n def cuest_xc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_xc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.xc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_nlc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_nlc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.nlc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_pcm_int_plan(self):\n if self.pcm_epsilon<=1.0:\n return None\n else:\n return CuestPCMIntPlan(\n handle=self.cuest_handle,\n intPlan=self.cuest_oe_int_plan,\n num_angular_points_per_heavy_atom=self.pcm_num_angular_points_per_heavy_atom,\n num_angular_points_per_hydrogen_atom=self.pcm_num_angular_points_per_hydrogen_atom,\n epsilon=self.pcm_epsilon,\n x_prefactor=self.pcm_x_prefactor,\n Ns=self.molecule.N,\n effective_nuclear_charges=self.molecule.Z,\n cutoff=self.pcm_cutoff,\n convergence_tol=self.pcm_convergence_tol,\n ) \n\n @property","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_pcm_int_plan","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.cuest_pcm_int_plan#L235-L250","kind":"function","name":"cuest_pcm_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":235,"end_line":250,"context_start_line":215,"context_end_line":270,"code":" def cuest_xc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_xc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.xc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_nlc_int_plan(self):\n return CuestXCIntPlan(\n handle=self.cuest_handle,\n basis=self.cuest_primary,\n grid=self.cuest_nlc_grid,\n functional=self.xc_functional,\n xc_threshold_collocation=self.nlc_threshold_collocation,\n ) \n\n @memoized_property\n def cuest_pcm_int_plan(self):\n if self.pcm_epsilon<=1.0:\n return None\n else:\n return CuestPCMIntPlan(\n handle=self.cuest_handle,\n intPlan=self.cuest_oe_int_plan,\n num_angular_points_per_heavy_atom=self.pcm_num_angular_points_per_heavy_atom,\n num_angular_points_per_hydrogen_atom=self.pcm_num_angular_points_per_hydrogen_atom,\n epsilon=self.pcm_epsilon,\n x_prefactor=self.pcm_x_prefactor,\n Ns=self.molecule.N,\n effective_nuclear_charges=self.molecule.Z,\n cutoff=self.pcm_cutoff,\n convergence_tol=self.pcm_convergence_tol,\n ) \n\n @property\n def do_pcm(self):\n return self.cuest_pcm_int_plan is not None\n\n\n # => Integrals <= #\n\n def compute_overlap(self):\n\n S = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Sptr=S.pointer,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.do_pcm","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.do_pcm#L253-L254","kind":"function","name":"do_pcm","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":253,"end_line":254,"context_start_line":233,"context_end_line":274,"code":"\n @memoized_property\n def cuest_pcm_int_plan(self):\n if self.pcm_epsilon<=1.0:\n return None\n else:\n return CuestPCMIntPlan(\n handle=self.cuest_handle,\n intPlan=self.cuest_oe_int_plan,\n num_angular_points_per_heavy_atom=self.pcm_num_angular_points_per_heavy_atom,\n num_angular_points_per_hydrogen_atom=self.pcm_num_angular_points_per_hydrogen_atom,\n epsilon=self.pcm_epsilon,\n x_prefactor=self.pcm_x_prefactor,\n Ns=self.molecule.N,\n effective_nuclear_charges=self.molecule.Z,\n cutoff=self.pcm_cutoff,\n convergence_tol=self.pcm_convergence_tol,\n ) \n\n @property\n def do_pcm(self):\n return self.cuest_pcm_int_plan is not None\n\n\n # => Integrals <= #\n\n def compute_overlap(self):\n\n S = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Sptr=S.pointer,\n )\n\n return S\n ","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_overlap","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_overlap#L259-L273","kind":"function","name":"compute_overlap","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":259,"end_line":273,"context_start_line":239,"context_end_line":293,"code":" return CuestPCMIntPlan(\n handle=self.cuest_handle,\n intPlan=self.cuest_oe_int_plan,\n num_angular_points_per_heavy_atom=self.pcm_num_angular_points_per_heavy_atom,\n num_angular_points_per_hydrogen_atom=self.pcm_num_angular_points_per_hydrogen_atom,\n epsilon=self.pcm_epsilon,\n x_prefactor=self.pcm_x_prefactor,\n Ns=self.molecule.N,\n effective_nuclear_charges=self.molecule.Z,\n cutoff=self.pcm_cutoff,\n convergence_tol=self.pcm_convergence_tol,\n ) \n\n @property\n def do_pcm(self):\n return self.cuest_pcm_int_plan is not None\n\n\n # => Integrals <= #\n\n def compute_overlap(self):\n\n S = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Sptr=S.pointer,\n )\n\n return S\n \n def compute_kinetic(self):\n\n T = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n )\n\n CuestOEIntCompute.kinetic(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Tptr=T.pointer,\n )\n\n return T\n \n def compute_potential(self):\n\n xyz = self.gpu_xyz\n q = self.gpu_Z","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_kinetic","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_kinetic#L275-L288","kind":"function","name":"compute_kinetic","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":275,"end_line":288,"context_start_line":255,"context_end_line":308,"code":"\n\n # => Integrals <= #\n\n def compute_overlap(self):\n\n S = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Sptr=S.pointer,\n )\n\n return S\n \n def compute_kinetic(self):\n\n T = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n )\n\n CuestOEIntCompute.kinetic(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Tptr=T.pointer,\n )\n\n return T\n \n def compute_potential(self):\n\n xyz = self.gpu_xyz\n q = self.gpu_Z\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Vptr=V.pointer,\n ncharge=self.molecule.natom,\n xyz=xyz.pointer,\n q=q.pointer,\n )","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_potential","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_potential#L290-L310","kind":"function","name":"compute_potential","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":290,"end_line":310,"context_start_line":270,"context_end_line":330,"code":" Sptr=S.pointer,\n )\n\n return S\n \n def compute_kinetic(self):\n\n T = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n )\n\n CuestOEIntCompute.kinetic(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Tptr=T.pointer,\n )\n\n return T\n \n def compute_potential(self):\n\n xyz = self.gpu_xyz\n q = self.gpu_Z\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Vptr=V.pointer,\n ncharge=self.molecule.natom,\n xyz=xyz.pointer,\n q=q.pointer,\n )\n\n return V\n\n def compute_coulomb(\n self, \n D,\n ):\n\n J = D.clone()\n\n CuestDFIntCompute.coulomb(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Jptr=J.pointer,\n Dptr=D.pointer,\n )\n\n return J\n \n def compute_exchange(\n self, \n Cocc,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_coulomb","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_coulomb#L312-L326","kind":"function","name":"compute_coulomb","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":312,"end_line":326,"context_start_line":292,"context_end_line":346,"code":" xyz = self.gpu_xyz\n q = self.gpu_Z\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Vptr=V.pointer,\n ncharge=self.molecule.natom,\n xyz=xyz.pointer,\n q=q.pointer,\n )\n\n return V\n\n def compute_coulomb(\n self, \n D,\n ):\n\n J = D.clone()\n\n CuestDFIntCompute.coulomb(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Jptr=J.pointer,\n Dptr=D.pointer,\n )\n\n return J\n \n def compute_exchange(\n self, \n Cocc,\n dfk_int8_slice_count,\n dfk_int8_modulus_count,\n ):\n\n K = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n if self.cuest_df_int_plan.exchange_scale == 0.0:\n K.zero()\n return K\n\n CuestDFIntCompute.symmetric_exchange(\n handle=self.cuest_handle,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_exchange","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_exchange#L328-L355","kind":"function","name":"compute_exchange","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":328,"end_line":355,"context_start_line":308,"context_end_line":375,"code":" )\n\n return V\n\n def compute_coulomb(\n self, \n D,\n ):\n\n J = D.clone()\n\n CuestDFIntCompute.coulomb(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Jptr=J.pointer,\n Dptr=D.pointer,\n )\n\n return J\n \n def compute_exchange(\n self, \n Cocc,\n dfk_int8_slice_count,\n dfk_int8_modulus_count,\n ):\n\n K = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n if self.cuest_df_int_plan.exchange_scale == 0.0:\n K.zero()\n return K\n\n CuestDFIntCompute.symmetric_exchange(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Kptr=K.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n dfk_int8_slice_count=dfk_int8_slice_count,\n dfk_int8_modulus_count=dfk_int8_modulus_count,\n )\n\n return K\n\n def compute_local_exchange_correlation(\n self, \n Cocc,\n ):\n\n if self.xc_functional == 0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.local_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_local_exchange_correlation","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_local_exchange_correlation#L357-L379","kind":"function","name":"compute_local_exchange_correlation","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":357,"end_line":379,"context_start_line":337,"context_end_line":399,"code":" ncols=self.primary.nao,\n dtype=np.double,\n )\n\n if self.cuest_df_int_plan.exchange_scale == 0.0:\n K.zero()\n return K\n\n CuestDFIntCompute.symmetric_exchange(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n Kptr=K.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n dfk_int8_slice_count=dfk_int8_slice_count,\n dfk_int8_modulus_count=dfk_int8_modulus_count,\n )\n\n return K\n\n def compute_local_exchange_correlation(\n self, \n Cocc,\n ):\n\n if self.xc_functional == 0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.local_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return Exc, Vxc\n\n def compute_nonlocal_exchange_correlation(\n self, \n Cocc,\n ):\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.nonlocal_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_nonlocal_exchange_correlation","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_nonlocal_exchange_correlation#L381-L403","kind":"function","name":"compute_nonlocal_exchange_correlation","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":381,"end_line":403,"context_start_line":361,"context_end_line":423,"code":"\n if self.xc_functional == 0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.local_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return Exc, Vxc\n\n def compute_nonlocal_exchange_correlation(\n self, \n Cocc,\n ):\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.nonlocal_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return Exc, Vxc\n \n def compute_pcm_energy_and_potential(\n self, \n q,\n D,\n ):\n \n outQ = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n )\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Epcm, converged, residual = CuestPCMIntCompute.compute_pcm_energy_and_potential(","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_pcm_energy_and_potential","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_pcm_energy_and_potential#L405-L432","kind":"function","name":"compute_pcm_energy_and_potential","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":405,"end_line":432,"context_start_line":385,"context_end_line":452,"code":"\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n return 0.0, None\n\n Vxc = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Exc = CuestXCIntCompute.nonlocal_exchange_correlation(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Vxcptr=Vxc.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return Exc, Vxc\n \n def compute_pcm_energy_and_potential(\n self, \n q,\n D,\n ):\n \n outQ = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n )\n\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Epcm, converged, residual = CuestPCMIntCompute.compute_pcm_energy_and_potential(\n handle=self.cuest_handle,\n pcm_int_plan=self.cuest_pcm_int_plan,\n Dptr=D.pointer, \n inQptr=q.pointer,\n outQptr=outQ.pointer,\n Vptr=V.pointer,\n )\n\n return Epcm, V, outQ\n\n # => Integral Derivatives (Gradients) <= #\n\n def compute_pcm_gradient(\n self, \n q,\n D,\n ):\n \n npoint = self.cuest_pcm_int_plan.npoint\n \n outQ = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n )\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_pcm_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_pcm_gradient#L436-L465","kind":"function","name":"compute_pcm_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":436,"end_line":465,"context_start_line":416,"context_end_line":485,"code":"\n V = GPUMatrix(\n nrows=self.primary.nao,\n ncols=self.primary.nao,\n dtype=np.double,\n )\n\n Epcm, converged, residual = CuestPCMIntCompute.compute_pcm_energy_and_potential(\n handle=self.cuest_handle,\n pcm_int_plan=self.cuest_pcm_int_plan,\n Dptr=D.pointer, \n inQptr=q.pointer,\n outQptr=outQ.pointer,\n Vptr=V.pointer,\n )\n\n return Epcm, V, outQ\n\n # => Integral Derivatives (Gradients) <= #\n\n def compute_pcm_gradient(\n self, \n q,\n D,\n ):\n \n npoint = self.cuest_pcm_int_plan.npoint\n \n outQ = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n )\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestPCMIntCompute.compute_pcm_gradient(\n handle=self.cuest_handle,\n pcm_int_plan=self.cuest_pcm_int_plan,\n Dptr=D.pointer, \n inQptr=q.pointer,\n outQptr=outQ.pointer,\n Gptr=G.pointer,\n )\n\n return G\n\n def compute_overlap_gradient(\n self,\n W, # Energy-weighted density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Wptr=W.pointer,\n )\n\n return G","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_overlap_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_overlap_gradient#L467-L485","kind":"function","name":"compute_overlap_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":467,"end_line":485,"context_start_line":447,"context_end_line":505,"code":" dtype=np.double,\n )\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestPCMIntCompute.compute_pcm_gradient(\n handle=self.cuest_handle,\n pcm_int_plan=self.cuest_pcm_int_plan,\n Dptr=D.pointer, \n inQptr=q.pointer,\n outQptr=outQ.pointer,\n Gptr=G.pointer,\n )\n\n return G\n\n def compute_overlap_gradient(\n self,\n W, # Energy-weighted density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Wptr=W.pointer,\n )\n\n return G\n\n def compute_kinetic_gradient(\n self,\n D, # Density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.kinetic_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Dptr=D.pointer,\n )\n\n return G","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_kinetic_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_kinetic_gradient#L487-L505","kind":"function","name":"compute_kinetic_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":487,"end_line":505,"context_start_line":467,"context_end_line":525,"code":" def compute_overlap_gradient(\n self,\n W, # Energy-weighted density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.overlap_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Wptr=W.pointer,\n )\n\n return G\n\n def compute_kinetic_gradient(\n self,\n D, # Density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.kinetic_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Dptr=D.pointer,\n )\n\n return G\n\n def compute_potential_gradient(\n self,\n D, # Density matrix\n ): \n\n Gbasis = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n Gcharge = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_potential_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_potential_gradient#L507-L540","kind":"function","name":"compute_potential_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":507,"end_line":540,"context_start_line":487,"context_end_line":560,"code":" def compute_kinetic_gradient(\n self,\n D, # Density matrix\n ): \n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.kinetic_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n Gptr=G.pointer,\n Dptr=D.pointer,\n )\n\n return G\n\n def compute_potential_gradient(\n self,\n D, # Density matrix\n ): \n\n Gbasis = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n Gcharge = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestOEIntCompute.potential_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n ncharge=self.molecule.natom,\n xyz=self.gpu_xyz.pointer,\n q=self.gpu_Z.pointer,\n Dptr=D.pointer,\n GptrBasis=Gbasis.pointer,\n GptrCharge=Gcharge.pointer,\n )\n\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Gcharge,\n y=Gbasis,\n )\n\n return Gbasis\n\n def compute_coulomb_and_exchange_gradient(\n self, \n *,\n scaleJ,\n DJ,\n scaleK,\n CoccsK,\n ):\n\n noccsK = [_.shape[0] for _ in CoccsK]\n assert len(CoccsK) == 1\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestDFIntCompute.coulomb_and_exchange_gradient(","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_coulomb_and_exchange_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_coulomb_and_exchange_gradient#L542-L571","kind":"function","name":"compute_coulomb_and_exchange_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":542,"end_line":571,"context_start_line":522,"context_end_line":591,"code":"\n CuestOEIntCompute.potential_gradient(\n handle=self.cuest_handle,\n oe_int_plan=self.cuest_oe_int_plan,\n ncharge=self.molecule.natom,\n xyz=self.gpu_xyz.pointer,\n q=self.gpu_Z.pointer,\n Dptr=D.pointer,\n GptrBasis=Gbasis.pointer,\n GptrCharge=Gcharge.pointer,\n )\n\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Gcharge,\n y=Gbasis,\n )\n\n return Gbasis\n\n def compute_coulomb_and_exchange_gradient(\n self, \n *,\n scaleJ,\n DJ,\n scaleK,\n CoccsK,\n ):\n\n noccsK = [_.shape[0] for _ in CoccsK]\n assert len(CoccsK) == 1\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestDFIntCompute.coulomb_and_exchange_gradient(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n scaleJ=scaleJ,\n DJptr=DJ.pointer,\n scaleK=scaleK, \n noccsK=noccsK,\n CoccsKptr=CoccsK[0].pointer,\n Gptr=G.pointer,\n )\n\n return G\n\n def compute_local_exchange_correlation_gradient(\n self, \n Cocc,\n ):\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n if self.xc_functional == 0:\n G.zero()\n return G\n\n CuestXCIntCompute.local_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_local_exchange_correlation_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_local_exchange_correlation_gradient#L573-L595","kind":"function","name":"compute_local_exchange_correlation_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":573,"end_line":595,"context_start_line":553,"context_end_line":615,"code":"\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n CuestDFIntCompute.coulomb_and_exchange_gradient(\n handle=self.cuest_handle,\n df_int_plan=self.cuest_df_int_plan,\n scaleJ=scaleJ,\n DJptr=DJ.pointer,\n scaleK=scaleK, \n noccsK=noccsK,\n CoccsKptr=CoccsK[0].pointer,\n Gptr=G.pointer,\n )\n\n return G\n\n def compute_local_exchange_correlation_gradient(\n self, \n Cocc,\n ):\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n if self.xc_functional == 0:\n G.zero()\n return G\n\n CuestXCIntCompute.local_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return G\n\n def compute_nonlocal_exchange_correlation_gradient(\n self, \n Cocc,\n ):\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n G.zero()\n return G\n\n CuestXCIntCompute.nonlocal_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Gptr=G.pointer,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_nonlocal_exchange_correlation_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_nonlocal_exchange_correlation_gradient#L597-L620","kind":"function","name":"compute_nonlocal_exchange_correlation_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":597,"end_line":620,"context_start_line":577,"context_end_line":640,"code":"\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n if self.xc_functional == 0:\n G.zero()\n return G\n\n CuestXCIntCompute.local_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_xc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return G\n\n def compute_nonlocal_exchange_correlation_gradient(\n self, \n Cocc,\n ):\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n )\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n G.zero()\n return G\n\n CuestXCIntCompute.nonlocal_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return G\n\n # => Main Solve Routines <= #\n \n def solve(self):\n\n self.is_solved = False\n self.is_converged = False\n\n self.header()\n\n # Plan initializations (to cleanly separate from iterations). The orthogonalization\n # calls for S, so most of these are automatically instantiated in that routine. Build\n # them here to get an idea of how long they take.\n _ = self.cuest_ao_pair_list\n\n _ = self.cuest_oe_int_plan\n\n _ = self.cuest_xc_int_plan\n\n start = time.time()","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.solve","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.solve#L624-L662","kind":"function","name":"solve","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":624,"end_line":662,"context_start_line":604,"context_end_line":682,"code":" ncols=3,\n dtype=np.double,\n )\n\n if self.cuest_nlc_int_plan.vv10_scale == 0.0:\n G.zero()\n return G\n\n CuestXCIntCompute.nonlocal_exchange_correlation_gradient(\n handle=self.cuest_handle,\n xc_int_plan=self.cuest_nlc_int_plan,\n Gptr=G.pointer,\n nocc=Cocc.shape[0],\n Coccptr=Cocc.pointer,\n )\n\n return G\n\n # => Main Solve Routines <= #\n \n def solve(self):\n\n self.is_solved = False\n self.is_converged = False\n\n self.header()\n\n # Plan initializations (to cleanly separate from iterations). The orthogonalization\n # calls for S, so most of these are automatically instantiated in that routine. Build\n # them here to get an idea of how long they take.\n _ = self.cuest_ao_pair_list\n\n _ = self.cuest_oe_int_plan\n\n _ = self.cuest_xc_int_plan\n\n start = time.time()\n _ = self.cuest_df_int_plan\n stop = time.time()\n \n _ = self.cuest_nlc_int_plan\n\n _ = self.cuest_pcm_int_plan\n\n self.compute_guess()\n\n self.compute_orthogonalization()\n\n self.compute_occupations()\n\n if self.print_level > 0:\n print('DFIntPlan Initialize Time: %11.3E [s]' % (stop - start))\n print('')\n\n self.solve_diis()\n\n self.trailer()\n\n self.is_solved = True\n\n def header(self):\n \n self.start_time = time.time()\n \n if self.print_level:\n print('==> cuEST RHF (Python) <==\\n')\n \n if self.print_level > 1:\n\n print('natom = %4d' % (self.molecule.natom))\n print('charge = %4d' % (self.charge))\n print('')\n\n print('Primary Basis: %s' % (self.primary_name if self.primary_name is not None else ''))\n print('')\n print(self.primary)\n\n print('Auxiliary Basis: %s' % (self.auxiliary_name if self.auxiliary_name is not None else ''))\n print('')","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.header","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.header#L664-L702","kind":"function","name":"header","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":664,"end_line":702,"context_start_line":644,"context_end_line":722,"code":" _ = self.cuest_nlc_int_plan\n\n _ = self.cuest_pcm_int_plan\n\n self.compute_guess()\n\n self.compute_orthogonalization()\n\n self.compute_occupations()\n\n if self.print_level > 0:\n print('DFIntPlan Initialize Time: %11.3E [s]' % (stop - start))\n print('')\n\n self.solve_diis()\n\n self.trailer()\n\n self.is_solved = True\n\n def header(self):\n \n self.start_time = time.time()\n \n if self.print_level:\n print('==> cuEST RHF (Python) <==\\n')\n \n if self.print_level > 1:\n\n print('natom = %4d' % (self.molecule.natom))\n print('charge = %4d' % (self.charge))\n print('')\n\n print('Primary Basis: %s' % (self.primary_name if self.primary_name is not None else ''))\n print('')\n print(self.primary)\n\n print('Auxiliary Basis: %s' % (self.auxiliary_name if self.auxiliary_name is not None else ''))\n print('')\n print(self.auxiliary)\n\n print('MinAO Basis: %s' % (self.minao_name if self.minao_name is not None else ''))\n print('')\n print(self.minao)\n\n print(self.cuest_xc_int_plan)\n \n print('XC Grid:')\n print('')\n print(self.cuest_xc_grid)\n\n print('Nonlocal XC Grid:')\n print('')\n print(self.cuest_nlc_grid)\n\n if self.do_pcm:\n print('PCM:')\n print('')\n print(self.cuest_pcm_int_plan)\n\n def trailer(self):\n\n if self.print_level:\n print('cuEST RHF Time: %11.3E [s]\\n' % (time.time() - self.start_time))\n \n del self.start_time\n \n if self.print_level:\n print('==> End cuEST RHF (Python) <==\\n')\n\n def compute_guess(self):\n\n if self.print_level > 0:\n print('SAD Guess:\\n')\n\n self.sad_guess = SADGuess.build(\n molecule=self.molecule,\n primary=self.primary,\n minao=self.minao,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.trailer","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.trailer#L704-L712","kind":"function","name":"trailer","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":704,"end_line":712,"context_start_line":684,"context_end_line":732,"code":"\n print('MinAO Basis: %s' % (self.minao_name if self.minao_name is not None else ''))\n print('')\n print(self.minao)\n\n print(self.cuest_xc_int_plan)\n \n print('XC Grid:')\n print('')\n print(self.cuest_xc_grid)\n\n print('Nonlocal XC Grid:')\n print('')\n print(self.cuest_nlc_grid)\n\n if self.do_pcm:\n print('PCM:')\n print('')\n print(self.cuest_pcm_int_plan)\n\n def trailer(self):\n\n if self.print_level:\n print('cuEST RHF Time: %11.3E [s]\\n' % (time.time() - self.start_time))\n \n del self.start_time\n \n if self.print_level:\n print('==> End cuEST RHF (Python) <==\\n')\n\n def compute_guess(self):\n\n if self.print_level > 0:\n print('SAD Guess:\\n')\n\n self.sad_guess = SADGuess.build(\n molecule=self.molecule,\n primary=self.primary,\n minao=self.minao,\n )\n\n # For now this will be size (nminao, nao), which is usually larger than\n # (nocc, nao) due to fractional occupations in SAD\n self.tensors['Cocc'] = GPUMatrix.from_numpy(self.sad_guess.compute_Cocc())\n\n # For now this is not a pure state, and corresponds to the neutral SAD\n # guess\n self.tensors['D'] = GPUMatrix.from_numpy(self.sad_guess.compute_Docc())\n","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_guess","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_guess#L714-L731","kind":"function","name":"compute_guess","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":714,"end_line":731,"context_start_line":694,"context_end_line":751,"code":"\n print('Nonlocal XC Grid:')\n print('')\n print(self.cuest_nlc_grid)\n\n if self.do_pcm:\n print('PCM:')\n print('')\n print(self.cuest_pcm_int_plan)\n\n def trailer(self):\n\n if self.print_level:\n print('cuEST RHF Time: %11.3E [s]\\n' % (time.time() - self.start_time))\n \n del self.start_time\n \n if self.print_level:\n print('==> End cuEST RHF (Python) <==\\n')\n\n def compute_guess(self):\n\n if self.print_level > 0:\n print('SAD Guess:\\n')\n\n self.sad_guess = SADGuess.build(\n molecule=self.molecule,\n primary=self.primary,\n minao=self.minao,\n )\n\n # For now this will be size (nminao, nao), which is usually larger than\n # (nocc, nao) due to fractional occupations in SAD\n self.tensors['Cocc'] = GPUMatrix.from_numpy(self.sad_guess.compute_Cocc())\n\n # For now this is not a pure state, and corresponds to the neutral SAD\n # guess\n self.tensors['D'] = GPUMatrix.from_numpy(self.sad_guess.compute_Docc())\n\n def compute_orthogonalization(self):\n\n if self.print_level > 0:\n print('Orthogonalization:\\n')\n\n S = self.compute_overlap()\n\n s, U = GPUMatrixUtility.eigh(matrix=S)\n s = s.to_numpy().reshape(-1)\n U = U.to_numpy()\n\n # Canonical orthogonalization is traditionally done on an absolute eigenvalue threshold basis\n sind = s > self.threshold_canonical\n \n s2 = s[sind]\n U2 = U[:, sind]\n\n X = np.einsum('ij,j->ji', U2, s2**(-0.5))\n","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_orthogonalization","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_orthogonalization#L733-L763","kind":"function","name":"compute_orthogonalization","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":733,"end_line":763,"context_start_line":713,"context_end_line":783,"code":"\n def compute_guess(self):\n\n if self.print_level > 0:\n print('SAD Guess:\\n')\n\n self.sad_guess = SADGuess.build(\n molecule=self.molecule,\n primary=self.primary,\n minao=self.minao,\n )\n\n # For now this will be size (nminao, nao), which is usually larger than\n # (nocc, nao) due to fractional occupations in SAD\n self.tensors['Cocc'] = GPUMatrix.from_numpy(self.sad_guess.compute_Cocc())\n\n # For now this is not a pure state, and corresponds to the neutral SAD\n # guess\n self.tensors['D'] = GPUMatrix.from_numpy(self.sad_guess.compute_Docc())\n\n def compute_orthogonalization(self):\n\n if self.print_level > 0:\n print('Orthogonalization:\\n')\n\n S = self.compute_overlap()\n\n s, U = GPUMatrixUtility.eigh(matrix=S)\n s = s.to_numpy().reshape(-1)\n U = U.to_numpy()\n\n # Canonical orthogonalization is traditionally done on an absolute eigenvalue threshold basis\n sind = s > self.threshold_canonical\n \n s2 = s[sind]\n U2 = U[:, sind]\n\n X = np.einsum('ij,j->ji', U2, s2**(-0.5))\n\n # This should be numerically zero:\n # d = np.max(np.abs(np.dot(np.dot(X, S), X.T) - np.eye(X.shape[0])))\n\n self.tensors['S'] = S\n self.tensors['X'] = GPUMatrix.from_numpy(X)\n\n if self.print_level > 0:\n print('threshold_canonical = %11.3E' % (self.threshold_canonical))\n print('nao = %11d' % (X.shape[1]))\n print('nmo = %11d' % (X.shape[0]))\n print('ndiscard = %11d' % (X.shape[1] - X.shape[0]))\n print('')\n\n def compute_occupations(self):\n\n if self.print_level > 0:\n print('Occupations:\\n')\n\n Q = np.sum(self.molecule.Z) - self.charge\n nocc = int(Q / 2)\n \n if 2 * nocc != Q: raise RuntimeError('molecule is not closed shell')\n\n nvir = self.tensors['X'].shape[0] - nocc\n\n self.sizes['nocc'] = nocc\n self.sizes['nvir'] = nvir\n\n if self.print_level > 0:\n print('%-5s = %5d' % ('nocc', self.sizes['nocc']))\n print('%-5s = %5d' % ('nvir', self.sizes['nvir']))\n print('')","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_occupations","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_occupations#L765-L783","kind":"function","name":"compute_occupations","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":765,"end_line":783,"context_start_line":745,"context_end_line":803,"code":" sind = s > self.threshold_canonical\n \n s2 = s[sind]\n U2 = U[:, sind]\n\n X = np.einsum('ij,j->ji', U2, s2**(-0.5))\n\n # This should be numerically zero:\n # d = np.max(np.abs(np.dot(np.dot(X, S), X.T) - np.eye(X.shape[0])))\n\n self.tensors['S'] = S\n self.tensors['X'] = GPUMatrix.from_numpy(X)\n\n if self.print_level > 0:\n print('threshold_canonical = %11.3E' % (self.threshold_canonical))\n print('nao = %11d' % (X.shape[1]))\n print('nmo = %11d' % (X.shape[0]))\n print('ndiscard = %11d' % (X.shape[1] - X.shape[0]))\n print('')\n\n def compute_occupations(self):\n\n if self.print_level > 0:\n print('Occupations:\\n')\n\n Q = np.sum(self.molecule.Z) - self.charge\n nocc = int(Q / 2)\n \n if 2 * nocc != Q: raise RuntimeError('molecule is not closed shell')\n\n nvir = self.tensors['X'].shape[0] - nocc\n\n self.sizes['nocc'] = nocc\n self.sizes['nvir'] = nvir\n\n if self.print_level > 0:\n print('%-5s = %5d' % ('nocc', self.sizes['nocc']))\n print('%-5s = %5d' % ('nvir', self.sizes['nvir']))\n print('')\n\n def compute_Enuc(self):\n \n xyz = self.molecule.xyz\n Z = self.molecule.Z\n\n Enuc = 0.0\n for A in range(xyz.shape[0]):\n xyzA = xyz[A, :] \n ZA = Z[A]\n for B in range(xyz.shape[0]):\n if A == B: continue\n xyzB = xyz[B, :] \n ZB = Z[B]\n rAB = np.sqrt(np.sum((xyzA - xyzB)**2))\n Enuc += 0.5 * ZA * ZB / rAB\n return Enuc\n\n def compute_Enuc_gradient(self):\n","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_Enuc","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_Enuc#L785-L800","kind":"function","name":"compute_Enuc","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":785,"end_line":800,"context_start_line":765,"context_end_line":820,"code":" def compute_occupations(self):\n\n if self.print_level > 0:\n print('Occupations:\\n')\n\n Q = np.sum(self.molecule.Z) - self.charge\n nocc = int(Q / 2)\n \n if 2 * nocc != Q: raise RuntimeError('molecule is not closed shell')\n\n nvir = self.tensors['X'].shape[0] - nocc\n\n self.sizes['nocc'] = nocc\n self.sizes['nvir'] = nvir\n\n if self.print_level > 0:\n print('%-5s = %5d' % ('nocc', self.sizes['nocc']))\n print('%-5s = %5d' % ('nvir', self.sizes['nvir']))\n print('')\n\n def compute_Enuc(self):\n \n xyz = self.molecule.xyz\n Z = self.molecule.Z\n\n Enuc = 0.0\n for A in range(xyz.shape[0]):\n xyzA = xyz[A, :] \n ZA = Z[A]\n for B in range(xyz.shape[0]):\n if A == B: continue\n xyzB = xyz[B, :] \n ZB = Z[B]\n rAB = np.sqrt(np.sum((xyzA - xyzB)**2))\n Enuc += 0.5 * ZA * ZB / rAB\n return Enuc\n\n def compute_Enuc_gradient(self):\n\n xyz = self.molecule.xyz\n Z = self.molecule.Z\n\n Gnuc = np.zeros((self.molecule.natom, 3))\n for A in range(xyz.shape[0]):\n xyzA = xyz[A, :] \n ZA = Z[A]\n for B in range(xyz.shape[0]):\n if A == B: continue\n xyzB = xyz[B, :] \n ZB = Z[B]\n rAB = np.sqrt(np.sum((xyzA - xyzB)**2))\n Gnuc[A, :] -= ZA * ZB / rAB**3 * (xyzA - xyzB)\n return GPUMatrix.from_numpy(Gnuc)\n\n def find_slice_count(\n self,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_Enuc_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_Enuc_gradient#L802-L817","kind":"function","name":"compute_Enuc_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":802,"end_line":817,"context_start_line":782,"context_end_line":837,"code":" print('%-5s = %5d' % ('nvir', self.sizes['nvir']))\n print('')\n\n def compute_Enuc(self):\n \n xyz = self.molecule.xyz\n Z = self.molecule.Z\n\n Enuc = 0.0\n for A in range(xyz.shape[0]):\n xyzA = xyz[A, :] \n ZA = Z[A]\n for B in range(xyz.shape[0]):\n if A == B: continue\n xyzB = xyz[B, :] \n ZB = Z[B]\n rAB = np.sqrt(np.sum((xyzA - xyzB)**2))\n Enuc += 0.5 * ZA * ZB / rAB\n return Enuc\n\n def compute_Enuc_gradient(self):\n\n xyz = self.molecule.xyz\n Z = self.molecule.Z\n\n Gnuc = np.zeros((self.molecule.natom, 3))\n for A in range(xyz.shape[0]):\n xyzA = xyz[A, :] \n ZA = Z[A]\n for B in range(xyz.shape[0]):\n if A == B: continue\n xyzB = xyz[B, :] \n ZB = Z[B]\n rAB = np.sqrt(np.sum((xyzA - xyzB)**2))\n Gnuc[A, :] -= ZA * ZB / rAB**3 * (xyzA - xyzB)\n return GPUMatrix.from_numpy(Gnuc)\n\n def find_slice_count(\n self,\n *,\n slice_start,\n slice_end,\n dG_start,\n dG_end,\n dG,\n ):\n\n if dG >= dG_start:\n return slice_start\n\n if dG <= dG_end:\n return slice_end\n\n log_dG_start = np.log10(dG_start)\n log_dG_end = np.log10(dG_end)\n log_dG = np.log10(dG)","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.find_slice_count","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.find_slice_count#L819-L841","kind":"function","name":"find_slice_count","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":819,"end_line":841,"context_start_line":799,"context_end_line":861,"code":" Enuc += 0.5 * ZA * ZB / rAB\n return Enuc\n\n def compute_Enuc_gradient(self):\n\n xyz = self.molecule.xyz\n Z = self.molecule.Z\n\n Gnuc = np.zeros((self.molecule.natom, 3))\n for A in range(xyz.shape[0]):\n xyzA = xyz[A, :] \n ZA = Z[A]\n for B in range(xyz.shape[0]):\n if A == B: continue\n xyzB = xyz[B, :] \n ZB = Z[B]\n rAB = np.sqrt(np.sum((xyzA - xyzB)**2))\n Gnuc[A, :] -= ZA * ZB / rAB**3 * (xyzA - xyzB)\n return GPUMatrix.from_numpy(Gnuc)\n\n def find_slice_count(\n self,\n *,\n slice_start,\n slice_end,\n dG_start,\n dG_end,\n dG,\n ):\n\n if dG >= dG_start:\n return slice_start\n\n if dG <= dG_end:\n return slice_end\n\n log_dG_start = np.log10(dG_start)\n log_dG_end = np.log10(dG_end)\n log_dG = np.log10(dG)\n\n t = (log_dG - log_dG_start) / (log_dG_end - log_dG_start)\n\n return int(round(slice_start + t * ( slice_end - slice_start)))\n\n def solve_diis(self):\n\n if self.print_level > 0:\n print('=> Solve DIIS <=\\n')\n\n # Threshold PQ (odd place to report this, but so be it)\n\n if self.print_level > 0:\n print('threshold_pq = %11.3E' % self.threshold_pq)\n print('')\n\n\n # PCM Initialization\n\n if self.do_pcm:\n self.pcm_q = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.solve_diis","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.solve_diis#L843-L1157","kind":"function","name":"solve_diis","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":843,"end_line":1157,"context_start_line":823,"context_end_line":1177,"code":" slice_end,\n dG_start,\n dG_end,\n dG,\n ):\n\n if dG >= dG_start:\n return slice_start\n\n if dG <= dG_end:\n return slice_end\n\n log_dG_start = np.log10(dG_start)\n log_dG_end = np.log10(dG_end)\n log_dG = np.log10(dG)\n\n t = (log_dG - log_dG_start) / (log_dG_end - log_dG_start)\n\n return int(round(slice_start + t * ( slice_end - slice_start)))\n\n def solve_diis(self):\n\n if self.print_level > 0:\n print('=> Solve DIIS <=\\n')\n\n # Threshold PQ (odd place to report this, but so be it)\n\n if self.print_level > 0:\n print('threshold_pq = %11.3E' % self.threshold_pq)\n print('')\n\n\n # PCM Initialization\n\n if self.do_pcm:\n self.pcm_q = GPUMatrix(\n nrows=self.cuest_pcm_int_plan.npoint,\n ncols=1,\n dtype=np.double,\n initialize=True,\n )\n self.pcm_q.zero()\n\n # External Nuclear-repulsion energy\n\n Enuc = self.compute_Enuc()\n self.scalars['Enuc'] = Enuc\n\n if self.print_level > 0:\n print('Enuc = %24.16E' % (Enuc))\n print('')\n \n S = self.tensors['S']\n X = self.tensors['X']\n\n # Core Hamiltonian\n\n T = self.compute_kinetic()\n V = self.compute_potential()\n\n # NOTE: This is typically where other static external potential terms\n # are added, e.g., ECP, QM/MM electrostatics, external perturbations,\n # etc.\n\n H = T.clone()\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=V,\n y=H,\n )\n\n diis = DIIS(max_nvector=self.diis_max_nvector)\n\n if self.print_level > 1:\n print('DIIS:')\n print('max nvector = %11d' % self.diis_max_nvector)\n print('')\n\n if self.print_level > 1:\n print('Convergence Options:')\n print('max iterations = %11d' % self.maxiter)\n print('g convergence = %11.3E' % self.g_convergence)\n print('')\n\n # Main SCF Iterative Loop \n\n start = time.time()\n self.is_converged = False\n Eold = 0.0\n E = 0.0\n dG = 1.0\n print('%-4s: %24s %11s %11s %8s' % ('Iter', 'Energy', 'dE', 'dG', 'Time[s]'))\n for iteration in range(self.maxiter):\n\n D = self.tensors['D'] \n Cocc = self.tensors['Cocc']\n\n # Find slice count\n dfk_int8_slice_count = self.find_slice_count(\n slice_start=self.dfk_int8_slice_count_start,\n slice_end=self.dfk_int8_slice_count_end,\n dG_start=1.0,\n dG_end=self.g_convergence,\n dG=dG,\n )\n dfk_int8_modulus_count = self.find_slice_count(\n slice_start=self.dfk_int8_modulus_count_start,\n slice_end=self.dfk_int8_modulus_count_end,\n dG_start=1.0,\n dG_end=self.g_convergence,\n dG=dG,\n )\n\n # Fock Matrix\n\n J = self.compute_coulomb(D=D)\n\n K = self.compute_exchange(\n Cocc=Cocc,\n dfk_int8_slice_count=dfk_int8_slice_count,\n dfk_int8_modulus_count=dfk_int8_modulus_count,\n )\n\n Exc, Vxc = self.compute_local_exchange_correlation(Cocc=Cocc)\n\n Enlc, Vnlc = self.compute_nonlocal_exchange_correlation(Cocc=Cocc)\n\n # NOTE: This is typically where other electron-dependent Fock\n # matrix terms are added, e.g., PCM, wK.\n\n F = H.clone()\n GPUMatrixUtility.daxpy(\n alpha=2.0,\n x=J,\n y=F,\n )\n GPUMatrixUtility.daxpy(\n alpha=-1.0,\n x=K,\n y=F,\n )\n\n # SCF Energy\n\n E = 0.0\n E += Enuc\n E += 1.0 * GPUMatrixUtility.ddot(\n x=D,\n y=H,\n )\n E += 1.0 * GPUMatrixUtility.ddot(\n x=D,\n y=F,\n )\n\n # Include PCM\n if self.do_pcm:\n # PCM expects the total density, so temporarily scale by 2.0\n GPUMatrixUtility.scale(\n matrix=D,\n scale=2.0,\n )\n Epcm, Vpcm, q_out = self.compute_pcm_energy_and_potential(\n q=self.pcm_q, \n D=D)\n GPUMatrixUtility.scale(\n matrix=D,\n scale=0.5,\n )\n\n self.pcm_q = q_out\n\n E += Epcm\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Vpcm,\n y=F,\n )\n\n E += Exc\n E += Enlc\n self.scalars['Escf'] = E\n\n # Add Vxc to the Fock matrix after calculating the energy\n\n if Vxc is not None:\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Vxc,\n y=F,\n )\n if Vnlc is not None:\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Vnlc,\n y=F,\n )\n\n dE = E - Eold\n Eold = E\n\n # Orbital Gradient (zero at convergence)\n # G = XSDFX' - XFDSX'\n\n # G = np.dot(np.dot(np.dot(np.dot(X, S), D), F), X.T)\n # Faster in large basis sets\n\n L1 = GPUMatrixUtility.matrix_multiply(\n mat1=Cocc,\n mat2=S,\n transpose1=False,\n transpose2=False,\n )\n L = GPUMatrixUtility.matrix_multiply(\n mat1=L1,\n mat2=X,\n transpose1=False,\n transpose2=True,\n )\n R1 = GPUMatrixUtility.matrix_multiply(\n mat1=Cocc,\n mat2=F,\n transpose1=False,\n transpose2=False,\n )\n R = GPUMatrixUtility.matrix_multiply(\n mat1=R1,\n mat2=X,\n transpose1=False,\n transpose2=True,\n )\n\n G = GPUMatrixUtility.matrix_multiply(\n mat1=L,\n mat2=R,\n transpose1=True,\n transpose2=False,\n )\n G = GPUMatrixUtility.dgeam(\n mat1=G,\n alpha=1.0,\n transpose1=False,\n mat2=G,\n beta=-1.0,\n transpose2=True,\n )\n\n G_np = G.to_numpy()\n\n dG = np.max(np.abs(G_np))\n\n # Convergence Trace\n\n stop = time.time()\n if self.print_level:\n print('%-4d: %24.16E %11.3E %11.3E %8.3f (%2d moduli, %2d slices)' % (iteration, E, dE, dG, stop-start, dfk_int8_modulus_count, dfk_int8_slice_count))\n start = stop\n\n # Convergence Check\n\n if iteration > 0 and dG < self.g_convergence:\n self.is_converged = True\n break\n\n # This ensures that we do not extrapolate/diagonalize if maxiter is reached\n if iteration >= self.maxiter - 1:\n break\n\n # DIIS Extrapolation (also updates DIIS history)\n\n\n if iteration > 0:\n F = diis.iterate(\n state_vector=F,\n error_vector=G,\n )\n\n # Fock Matrix Diagonalization\n\n tmp = GPUMatrixUtility.matrix_multiply(\n mat1=X,\n mat2=F,\n transpose1=False,\n transpose2=False,\n )\n F2 = GPUMatrixUtility.matrix_multiply(\n mat1=tmp,\n mat2=X,\n transpose1=False,\n transpose2=True,\n )\n\n eps, U2 = GPUMatrixUtility.eigh(matrix=F2)\n\n C = GPUMatrixUtility.matrix_multiply(\n mat1=U2,\n mat2=X,\n transpose1=True,\n transpose2=False,\n )\n\n # New Occupied Orbitals and Density Matrix\n\n C_np = C.to_numpy()\n Cocc_np = C_np[:self.sizes['nocc'], :]\n Cocc = GPUMatrix.from_numpy(Cocc_np)\n \n D = GPUMatrixUtility.matrix_multiply(\n mat1=Cocc,\n mat2=Cocc,\n transpose1=True,\n transpose2=False,\n )\n \n self.tensors['D'] = D\n self.tensors['Cocc'] = Cocc\n\n self.tensors['C'] = C\n self.tensors['eps'] = eps\n\n # => Print Convergence <= #\n\n if self.print_level > 0:\n if self.is_converged:\n print('SCF Converged\\n')\n else:\n print('SCF Failed\\n')\n\n # => Print Final Energy <= #\n\n if self.print_level:\n print('SCF Energy = %24.16E\\n' % E)\n\n if self.print_level > 0:\n print('=> End Solve DIIS <=\\n')\n\n def compute_energy(self):\n\n if not self.is_solved:\n self.solve()\n\n if not self.is_converged:\n raise RuntimeError('Not converged')\n \n return self.scalars['Escf']\n\n def compute_gradient(self):\n\n if not self.is_solved:\n self.solve()\n\n if not self.is_converged:\n raise RuntimeError('Not converged')\n \n # Occupied orbitals / density matrix","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_energy","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_energy#L1159-L1167","kind":"function","name":"compute_energy","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":1159,"end_line":1167,"context_start_line":1139,"context_end_line":1187,"code":"\n self.tensors['C'] = C\n self.tensors['eps'] = eps\n\n # => Print Convergence <= #\n\n if self.print_level > 0:\n if self.is_converged:\n print('SCF Converged\\n')\n else:\n print('SCF Failed\\n')\n\n # => Print Final Energy <= #\n\n if self.print_level:\n print('SCF Energy = %24.16E\\n' % E)\n\n if self.print_level > 0:\n print('=> End Solve DIIS <=\\n')\n\n def compute_energy(self):\n\n if not self.is_solved:\n self.solve()\n\n if not self.is_converged:\n raise RuntimeError('Not converged')\n \n return self.scalars['Escf']\n\n def compute_gradient(self):\n\n if not self.is_solved:\n self.solve()\n\n if not self.is_converged:\n raise RuntimeError('Not converged')\n \n # Occupied orbitals / density matrix\n \n Cocc = self.tensors['Cocc']\n D = self.tensors['D']\n\n # Energy-weighted density matrix\n \n eps_occ_np = self.tensors['eps'].to_numpy()[:self.sizes['nocc']]\n Cocc_np = Cocc.to_numpy()\n Vocc_np = np.einsum('ip,id->ipd', Cocc_np, eps_occ_np).reshape(Cocc_np.shape[0], Cocc_np.shape[1])\n W_np = np.dot(Vocc_np.T, Cocc_np)","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.rhf.compute_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.rhf.compute_gradient#L1169-L1312","kind":"function","name":"compute_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":1169,"end_line":1312,"context_start_line":1149,"context_end_line":1313,"code":" print('SCF Failed\\n')\n\n # => Print Final Energy <= #\n\n if self.print_level:\n print('SCF Energy = %24.16E\\n' % E)\n\n if self.print_level > 0:\n print('=> End Solve DIIS <=\\n')\n\n def compute_energy(self):\n\n if not self.is_solved:\n self.solve()\n\n if not self.is_converged:\n raise RuntimeError('Not converged')\n \n return self.scalars['Escf']\n\n def compute_gradient(self):\n\n if not self.is_solved:\n self.solve()\n\n if not self.is_converged:\n raise RuntimeError('Not converged')\n \n # Occupied orbitals / density matrix\n \n Cocc = self.tensors['Cocc']\n D = self.tensors['D']\n\n # Energy-weighted density matrix\n \n eps_occ_np = self.tensors['eps'].to_numpy()[:self.sizes['nocc']]\n Cocc_np = Cocc.to_numpy()\n Vocc_np = np.einsum('ip,id->ipd', Cocc_np, eps_occ_np).reshape(Cocc_np.shape[0], Cocc_np.shape[1])\n W_np = np.dot(Vocc_np.T, Cocc_np)\n W = GPUMatrix.from_numpy(W_np)\n\n # Nuclear gradient (classical)\n\n Gnuc = self.compute_Enuc_gradient()\n GPUMatrixUtility.scale(\n matrix=Gnuc,\n scale=+1.0,\n )\n\n # Overlap gradient\n\n GS = self.compute_overlap_gradient(W)\n GPUMatrixUtility.scale(\n matrix=GS,\n scale=-2.0,\n )\n\n # Kinetic gradient\n\n GT = self.compute_kinetic_gradient(D)\n GPUMatrixUtility.scale(\n matrix=GT,\n scale=+2.0,\n )\n\n # Potential gradient\n\n GV = self.compute_potential_gradient(D)\n GPUMatrixUtility.scale(\n matrix=GV,\n scale=+2.0,\n )\n\n # United Coulomb + Exchange gradient\n\n GJK = self.compute_coulomb_and_exchange_gradient(\n scaleJ=+2.0,\n DJ=D,\n scaleK=-1.0,\n CoccsK=[Cocc],\n )\n\n # Local exchange-correlation gradient\n\n GVxc = self.compute_local_exchange_correlation_gradient(Cocc)\n GPUMatrixUtility.scale(\n matrix=GVxc,\n scale=+1.0,\n )\n\n # Nonlocal exchange-correlation gradient\n\n GVnlc = self.compute_nonlocal_exchange_correlation_gradient(Cocc)\n GPUMatrixUtility.scale(\n matrix=GVnlc,\n scale=+1.0,\n )\n\n # PCM gradient\n\n Gpcm = None\n if self.do_pcm:\n GPUMatrixUtility.scale(\n matrix=D,\n scale=2.0,\n )\n Gpcm = self.compute_pcm_gradient(\n q=self.pcm_q,\n D=D)\n GPUMatrixUtility.scale(\n matrix=D,\n scale=0.5,\n )\n\n G = GPUMatrix(\n nrows=self.primary.natom,\n ncols=3,\n dtype=np.double,\n initialize=True,\n )\n\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Gnuc,\n y=G,\n )\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=GS,\n y=G,\n )\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=GT,\n y=G,\n )\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=GV,\n y=G,\n )\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=GJK,\n y=G,\n )\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=GVxc,\n y=G,\n )\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=GVnlc,\n y=G,\n )\n if self.do_pcm:\n GPUMatrixUtility.daxpy(\n alpha=1.0,\n x=Gpcm,\n y=G,\n )\n\n return G\n","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuda_utility#L1-L162","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuda_utility","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":1,"end_line":162,"context_start_line":1,"context_end_line":162,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nimport cuda.bindings.runtime as cuda\n\nclass CudaUtility(object):\n\n @staticmethod\n def cuda_malloc(size_in_bytes):\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n @staticmethod\n def cuda_free(pointer):\n \n ret = cuda.cudaFree(pointer)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n @staticmethod\n def cuda_malloc_host(size_in_bytes):\n \n # NOTE: we are using cudaMallocHost as an expediency here. \n # Ideally, in production codes, this would be simple malloc or similar\n # as pinned memory is not required here.\n\n ret, pointer = cuda.cudaMallocHost(size_in_bytes)\n \n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate host array:\", ret)\n \n return pointer\n\n @staticmethod\n def cuda_free_host(pointer):\n\n ret = cuda.cudaFreeHost(pointer)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free host array:\", ret[0])\n\n @staticmethod\n def cuda_memcpy_dtoh(\n *,\n host_pointer,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToHost,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to host failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n \n @staticmethod\n def cuda_memcpy_htod(\n *,\n device_pointer,\n host_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyHostToDevice,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from host to device failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n\n @staticmethod\n def cuda_memcpy_dtod(\n *,\n dst_device_pointer,\n src_device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to two\n device memory allocations, and copy size_in_bytes bytes from the\n src memory to the destination memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=dst_device_pointer,\n src=src_device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToDevice,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to device failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n\n @staticmethod\n def cuda_zero_memory(\n *,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n Initialize a chunk of device memory to the zero. The stream to execute this can be optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemsetAsync(\n devPtr=device_pointer,\n value=0,\n count=size_in_bytes,\n stream=stream,\n )\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"CUDA memset failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.CudaUtility","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.CudaUtility#L19-L162","kind":"class","name":"CudaUtility","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":19,"end_line":162,"context_start_line":1,"context_end_line":162,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nimport cuda.bindings.runtime as cuda\n\nclass CudaUtility(object):\n\n @staticmethod\n def cuda_malloc(size_in_bytes):\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n @staticmethod\n def cuda_free(pointer):\n \n ret = cuda.cudaFree(pointer)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n @staticmethod\n def cuda_malloc_host(size_in_bytes):\n \n # NOTE: we are using cudaMallocHost as an expediency here. \n # Ideally, in production codes, this would be simple malloc or similar\n # as pinned memory is not required here.\n\n ret, pointer = cuda.cudaMallocHost(size_in_bytes)\n \n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate host array:\", ret)\n \n return pointer\n\n @staticmethod\n def cuda_free_host(pointer):\n\n ret = cuda.cudaFreeHost(pointer)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free host array:\", ret[0])\n\n @staticmethod\n def cuda_memcpy_dtoh(\n *,\n host_pointer,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToHost,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to host failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n \n @staticmethod\n def cuda_memcpy_htod(\n *,\n device_pointer,\n host_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyHostToDevice,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from host to device failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n\n @staticmethod\n def cuda_memcpy_dtod(\n *,\n dst_device_pointer,\n src_device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to two\n device memory allocations, and copy size_in_bytes bytes from the\n src memory to the destination memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=dst_device_pointer,\n src=src_device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToDevice,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to device failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n\n @staticmethod\n def cuda_zero_memory(\n *,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n Initialize a chunk of device memory to the zero. The stream to execute this can be optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemsetAsync(\n devPtr=device_pointer,\n value=0,\n count=size_in_bytes,\n stream=stream,\n )\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"CUDA memset failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_malloc","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_malloc#L22-L28","kind":"function","name":"cuda_malloc","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":22,"end_line":28,"context_start_line":2,"context_end_line":48,"code":"# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nimport cuda.bindings.runtime as cuda\n\nclass CudaUtility(object):\n\n @staticmethod\n def cuda_malloc(size_in_bytes):\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n @staticmethod\n def cuda_free(pointer):\n \n ret = cuda.cudaFree(pointer)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n @staticmethod\n def cuda_malloc_host(size_in_bytes):\n \n # NOTE: we are using cudaMallocHost as an expediency here. \n # Ideally, in production codes, this would be simple malloc or similar\n # as pinned memory is not required here.\n\n ret, pointer = cuda.cudaMallocHost(size_in_bytes)\n \n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate host array:\", ret)","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_free","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_free#L31-L36","kind":"function","name":"cuda_free","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":31,"end_line":36,"context_start_line":11,"context_end_line":56,"code":"# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nimport cuda.bindings.runtime as cuda\n\nclass CudaUtility(object):\n\n @staticmethod\n def cuda_malloc(size_in_bytes):\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n @staticmethod\n def cuda_free(pointer):\n \n ret = cuda.cudaFree(pointer)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n @staticmethod\n def cuda_malloc_host(size_in_bytes):\n \n # NOTE: we are using cudaMallocHost as an expediency here. \n # Ideally, in production codes, this would be simple malloc or similar\n # as pinned memory is not required here.\n\n ret, pointer = cuda.cudaMallocHost(size_in_bytes)\n \n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate host array:\", ret)\n \n return pointer\n\n @staticmethod\n def cuda_free_host(pointer):\n\n ret = cuda.cudaFreeHost(pointer)\n","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_malloc_host","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_malloc_host#L39-L50","kind":"function","name":"cuda_malloc_host","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":39,"end_line":50,"context_start_line":19,"context_end_line":70,"code":"class CudaUtility(object):\n\n @staticmethod\n def cuda_malloc(size_in_bytes):\n ret, pointer = cuda.cudaMalloc(size_in_bytes)\n\n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate CUDA array:\", ret)\n\n return pointer\n\n @staticmethod\n def cuda_free(pointer):\n \n ret = cuda.cudaFree(pointer)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n @staticmethod\n def cuda_malloc_host(size_in_bytes):\n \n # NOTE: we are using cudaMallocHost as an expediency here. \n # Ideally, in production codes, this would be simple malloc or similar\n # as pinned memory is not required here.\n\n ret, pointer = cuda.cudaMallocHost(size_in_bytes)\n \n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate host array:\", ret)\n \n return pointer\n\n @staticmethod\n def cuda_free_host(pointer):\n\n ret = cuda.cudaFreeHost(pointer)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free host array:\", ret[0])\n\n @staticmethod\n def cuda_memcpy_dtoh(\n *,\n host_pointer,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_free_host","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_free_host#L53-L58","kind":"function","name":"cuda_free_host","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":53,"end_line":58,"context_start_line":33,"context_end_line":78,"code":" ret = cuda.cudaFree(pointer)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free CUDA array:\", ret[0])\n\n @staticmethod\n def cuda_malloc_host(size_in_bytes):\n \n # NOTE: we are using cudaMallocHost as an expediency here. \n # Ideally, in production codes, this would be simple malloc or similar\n # as pinned memory is not required here.\n\n ret, pointer = cuda.cudaMallocHost(size_in_bytes)\n \n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate host array:\", ret)\n \n return pointer\n\n @staticmethod\n def cuda_free_host(pointer):\n\n ret = cuda.cudaFreeHost(pointer)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free host array:\", ret[0])\n\n @staticmethod\n def cuda_memcpy_dtoh(\n *,\n host_pointer,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_memcpy_dtoh","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_memcpy_dtoh#L61-L85","kind":"function","name":"cuda_memcpy_dtoh","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":61,"end_line":85,"context_start_line":41,"context_end_line":105,"code":" # NOTE: we are using cudaMallocHost as an expediency here. \n # Ideally, in production codes, this would be simple malloc or similar\n # as pinned memory is not required here.\n\n ret, pointer = cuda.cudaMallocHost(size_in_bytes)\n \n if ret != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to allocate host array:\", ret)\n \n return pointer\n\n @staticmethod\n def cuda_free_host(pointer):\n\n ret = cuda.cudaFreeHost(pointer)\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Unable to free host array:\", ret[0])\n\n @staticmethod\n def cuda_memcpy_dtoh(\n *,\n host_pointer,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToHost,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to host failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n \n @staticmethod\n def cuda_memcpy_htod(\n *,\n device_pointer,\n host_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_memcpy_htod","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_memcpy_htod#L88-L112","kind":"function","name":"cuda_memcpy_htod","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":88,"end_line":112,"context_start_line":68,"context_end_line":132,"code":" \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n device memory to the host memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=host_pointer,\n src=device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToHost,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to host failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n \n @staticmethod\n def cuda_memcpy_htod(\n *,\n device_pointer,\n host_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyHostToDevice,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from host to device failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n\n @staticmethod\n def cuda_memcpy_dtod(\n *,\n dst_device_pointer,\n src_device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to two\n device memory allocations, and copy size_in_bytes bytes from the\n src memory to the destination memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=dst_device_pointer,\n src=src_device_pointer,\n count=size_in_bytes,","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_memcpy_dtod","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_memcpy_dtod#L115-L139","kind":"function","name":"cuda_memcpy_dtod","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":115,"end_line":139,"context_start_line":95,"context_end_line":159,"code":" \"\"\"\n This function should take integer representations of pointers to host\n and device memory allocations, and copy size_in_bytes bytes from the\n host memory to the device memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=device_pointer,\n src=host_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyHostToDevice,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from host to device failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n\n @staticmethod\n def cuda_memcpy_dtod(\n *,\n dst_device_pointer,\n src_device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n This function should take integer representations of pointers to two\n device memory allocations, and copy size_in_bytes bytes from the\n src memory to the destination memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=dst_device_pointer,\n src=src_device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToDevice,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to device failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n\n @staticmethod\n def cuda_zero_memory(\n *,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n Initialize a chunk of device memory to the zero. The stream to execute this can be optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemsetAsync(\n devPtr=device_pointer,\n value=0,\n count=size_in_bytes,\n stream=stream,\n )\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_zero_memory","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuda_utility.cuda_zero_memory#L142-L162","kind":"function","name":"cuda_zero_memory","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":142,"end_line":162,"context_start_line":122,"context_end_line":162,"code":" \"\"\"\n This function should take integer representations of pointers to two\n device memory allocations, and copy size_in_bytes bytes from the\n src memory to the destination memory. The stream to execute this can be\n optionally provided.\n \"\"\"\n \n ret = cuda.cudaMemcpyAsync(\n dst=dst_device_pointer,\n src=src_device_pointer,\n count=size_in_bytes,\n kind=cuda.cudaMemcpyKind.cudaMemcpyDeviceToDevice,\n stream=stream)\n \n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"Copy from device to device failed:\", ret[0])\n \n cuda.cudaStreamSynchronize(stream)\n\n @staticmethod\n def cuda_zero_memory(\n *,\n device_pointer,\n size_in_bytes,\n stream=None,\n ):\n \"\"\"\n Initialize a chunk of device memory to the zero. The stream to execute this can be optionally provided.\n \"\"\"\n\n ret = cuda.cudaMemsetAsync(\n devPtr=device_pointer,\n value=0,\n count=size_in_bytes,\n stream=stream,\n )\n\n if ret[0] != cuda.cudaError_t.cudaSuccess:\n raise RuntimeError(\"CUDA memset failed:\", ret[0])\n\n cuda.cudaStreamSynchronize(stream)","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis#L1-L276","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":1,"end_line":276,"context_start_line":1,"context_end_line":276,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .ao_basis import AOBasis\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_shell import CuestAOShell\n\nfrom .cuest_parameters import CuestParameters\n \nclass CuestAOBasis(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : AOBasis,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n shells = [CuestAOShell(\n handle=handle,\n ao_shell=shell) for shell in basis.shells_unrolled]\n\n # Careful - \"shells\" owns these handles. \n # OK as we will use readonly during this constructor\n shells_raw = [_.ao_shell_handle for _ in shells]\n\n nshell_per_atom = [len(_) for _ in basis.shells] \n\n ao_basis_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n )\n\n self.ao_basis_handle = ce.cuestAOBasisHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestAOBasisCreateWorkspaceQuery(\n handle=handle.handle,\n numAtoms=basis.natom,\n numShellsPerAtom=nshell_per_atom,\n shells=shells_raw,\n parameters=ao_basis_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisCreateWorkspaceQuery failed')\n \n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestAOBasisCreate(\n handle=handle.handle,\n numAtoms=basis.natom,\n numShellsPerAtom=nshell_per_atom,\n shells=shells_raw,\n parameters=ao_basis_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outBasis=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOBasisDestroy(\n handle=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisDestroy failed')\n\n @property\n def is_pure(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_PURE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_cart(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_mixed(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_MIXED,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def natom(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_ATOM,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nshell(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_SHELL,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nao(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def ncart(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nprimitive(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_PRIMITIVE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def max_L(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_MAX_L,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n def __str__(self):\n s = ''\n s += 'CuestAOBasis:\\n'\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.CuestAOBasis","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.CuestAOBasis#L28-L276","kind":"class","name":"CuestAOBasis","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":28,"end_line":276,"context_start_line":8,"context_end_line":276,"code":"# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .ao_basis import AOBasis\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_shell import CuestAOShell\n\nfrom .cuest_parameters import CuestParameters\n \nclass CuestAOBasis(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : AOBasis,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n shells = [CuestAOShell(\n handle=handle,\n ao_shell=shell) for shell in basis.shells_unrolled]\n\n # Careful - \"shells\" owns these handles. \n # OK as we will use readonly during this constructor\n shells_raw = [_.ao_shell_handle for _ in shells]\n\n nshell_per_atom = [len(_) for _ in basis.shells] \n\n ao_basis_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n )\n\n self.ao_basis_handle = ce.cuestAOBasisHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestAOBasisCreateWorkspaceQuery(\n handle=handle.handle,\n numAtoms=basis.natom,\n numShellsPerAtom=nshell_per_atom,\n shells=shells_raw,\n parameters=ao_basis_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisCreateWorkspaceQuery failed')\n \n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestAOBasisCreate(\n handle=handle.handle,\n numAtoms=basis.natom,\n numShellsPerAtom=nshell_per_atom,\n shells=shells_raw,\n parameters=ao_basis_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outBasis=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOBasisDestroy(\n handle=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisDestroy failed')\n\n @property\n def is_pure(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_PURE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_cart(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_mixed(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_MIXED,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def natom(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_ATOM,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nshell(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_SHELL,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nao(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def ncart(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nprimitive(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_PRIMITIVE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def max_L(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_MAX_L,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n def __str__(self):\n s = ''\n s += 'CuestAOBasis:\\n'\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.__init__#L30-L98","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":30,"end_line":98,"context_start_line":10,"context_end_line":118,"code":"# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .ao_basis import AOBasis\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_shell import CuestAOShell\n\nfrom .cuest_parameters import CuestParameters\n \nclass CuestAOBasis(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : AOBasis,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n shells = [CuestAOShell(\n handle=handle,\n ao_shell=shell) for shell in basis.shells_unrolled]\n\n # Careful - \"shells\" owns these handles. \n # OK as we will use readonly during this constructor\n shells_raw = [_.ao_shell_handle for _ in shells]\n\n nshell_per_atom = [len(_) for _ in basis.shells] \n\n ao_basis_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOBASIS_PARAMETERS,\n )\n\n self.ao_basis_handle = ce.cuestAOBasisHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestAOBasisCreateWorkspaceQuery(\n handle=handle.handle,\n numAtoms=basis.natom,\n numShellsPerAtom=nshell_per_atom,\n shells=shells_raw,\n parameters=ao_basis_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outBasis=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisCreateWorkspaceQuery failed')\n \n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestAOBasisCreate(\n handle=handle.handle,\n numAtoms=basis.natom,\n numShellsPerAtom=nshell_per_atom,\n shells=shells_raw,\n parameters=ao_basis_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outBasis=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOBasisDestroy(\n handle=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisDestroy failed')\n\n @property\n def is_pure(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.__del__#L100-L109","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":100,"end_line":109,"context_start_line":80,"context_end_line":129,"code":"\n status = ce.cuestAOBasisCreate(\n handle=handle.handle,\n numAtoms=basis.natom,\n numShellsPerAtom=nshell_per_atom,\n shells=shells_raw,\n parameters=ao_basis_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outBasis=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOBasisDestroy(\n handle=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisDestroy failed')\n\n @property\n def is_pure(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_PURE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_cart(self):","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.is_pure","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.is_pure#L112-L126","kind":"function","name":"is_pure","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":112,"end_line":126,"context_start_line":92,"context_end_line":146,"code":" if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOBasisDestroy(\n handle=self.ao_basis_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOBasisDestroy failed')\n\n @property\n def is_pure(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_PURE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_cart(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_mixed(self):","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.is_cart","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.is_cart#L129-L143","kind":"function","name":"is_cart","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":129,"end_line":143,"context_start_line":109,"context_end_line":163,"code":" raise RuntimeError('cuestAOBasisDestroy failed')\n\n @property\n def is_pure(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_PURE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_cart(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_mixed(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_MIXED,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def natom(self):","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.is_mixed","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.is_mixed#L146-L160","kind":"function","name":"is_mixed","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":146,"end_line":160,"context_start_line":126,"context_end_line":180,"code":" return bool(query.value)\n\n @property\n def is_cart(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def is_mixed(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_MIXED,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def natom(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_ATOM,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nshell(self):","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.natom","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.natom#L163-L177","kind":"function","name":"natom","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":163,"end_line":177,"context_start_line":143,"context_end_line":197,"code":" return bool(query.value)\n\n @property\n def is_mixed(self):\n query = ce.data_int32_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_IS_MIXED,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return bool(query.value)\n\n @property\n def natom(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_ATOM,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nshell(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_SHELL,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nao(self):","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.nshell","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.nshell#L180-L194","kind":"function","name":"nshell","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":180,"end_line":194,"context_start_line":160,"context_end_line":214,"code":" return bool(query.value)\n\n @property\n def natom(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_ATOM,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nshell(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_SHELL,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nao(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def ncart(self):","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.nao","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.nao#L197-L211","kind":"function","name":"nao","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":197,"end_line":211,"context_start_line":177,"context_end_line":231,"code":" return int(query.value)\n\n @property\n def nshell(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_SHELL,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nao(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def ncart(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nprimitive(self):","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.ncart","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.ncart#L214-L228","kind":"function","name":"ncart","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":214,"end_line":228,"context_start_line":194,"context_end_line":248,"code":" return int(query.value)\n\n @property\n def nao(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_AO,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def ncart(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nprimitive(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_PRIMITIVE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def max_L(self):","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.nprimitive","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.nprimitive#L231-L245","kind":"function","name":"nprimitive","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":231,"end_line":245,"context_start_line":211,"context_end_line":265,"code":" return int(query.value)\n\n @property\n def ncart(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_CART,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def nprimitive(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_PRIMITIVE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def max_L(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_MAX_L,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n def __str__(self):\n s = ''","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.max_L","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.max_L#L248-L262","kind":"function","name":"max_L","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":248,"end_line":262,"context_start_line":228,"context_end_line":276,"code":" return int(query.value)\n\n @property\n def nprimitive(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_NUM_PRIMITIVE,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n @property\n def max_L(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_MAX_L,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n def __str__(self):\n s = ''\n s += 'CuestAOBasis:\\n'\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.__str__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_basis.__str__#L264-L276","kind":"function","name":"__str__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":264,"end_line":276,"context_start_line":244,"context_end_line":276,"code":"\n return int(query.value)\n\n @property\n def max_L(self):\n query = ce.data_uint64_t()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_AOBASIS,\n object=self.ao_basis_handle,\n attribute=ce.CuestAOBasisAttributes.CUEST_AOBASIS_MAX_L,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return int(query.value)\n\n def __str__(self):\n s = ''\n s += 'CuestAOBasis:\\n'\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility#L1-L270","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":1,"end_line":270,"context_start_line":1,"context_end_line":270,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nimport atexit\n\nimport nvmath.bindings.cublas as cublas\nimport nvmath.bindings.cusolverDn as cusolver\nimport nvmath.bindings.cusolver as cusolver_base\nfrom .gpu_matrix import GPUMatrix\n\n# these handles are module-scoped, making them singletons\ncublas_handle = cublas.create()\n# Read scalar parameters like alpha and beta from CPU RAM\ncublas.set_pointer_mode(\n cublas_handle,\n cublas.PointerMode.HOST\n )\ncusolver_handle = cusolver.create()\n\ndef _delete_handles():\n global cublas_handle, cusolver_handle\n cublas.destroy(cublas_handle)\n cusolver.destroy(cusolver_handle)\n\natexit.register(_delete_handles)\n\nclass GPUMatrixUtility(object):\n\n @staticmethod\n def matrix_multiply(\n *,\n mat1,\n mat2,\n transpose1,\n transpose2,\n scale=1.0,\n ):\n\n alpha = np.array(\n scale,\n dtype=np.double,\n )\n beta = np.array(\n 0.0,\n dtype=np.double,\n )\n m = mat1.ncols if transpose1 else mat1.nrows\n n = mat2.nrows if transpose2 else mat2.ncols\n k1 = mat1.nrows if transpose1 else mat1.ncols\n k2 = mat2.ncols if transpose2 else mat2.nrows\n assert k1 == k2\n\n c = GPUMatrix(\n nrows=m,\n ncols=n,\n )\n\n cublas.dgemm(\n handle=cublas_handle,\n transa=cublas.Operation.T if transpose2 else cublas.Operation.N,\n transb=cublas.Operation.T if transpose1 else cublas.Operation.N,\n m=n,\n n=m,\n k=k1,\n alpha=alpha.ctypes.data,\n a=mat2.pointer,\n lda=mat2.ncols,\n b=mat1.pointer,\n ldb=mat1.ncols,\n beta=beta.ctypes.data,\n c=c.pointer,\n ldc=c.ncols,\n )\n\n return c\n\n @staticmethod\n def ddot(\n *,\n x,\n y,\n ):\n\n result = np.empty(1, dtype=np.double)\n\n cublas.ddot(\n handle = cublas_handle,\n n=x.size,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n result=result.ctypes.data,\n )\n return result[0]\n\n\n @staticmethod\n def dgeam(\n *,\n transpose1,\n alpha,\n mat1,\n transpose2,\n beta,\n mat2,\n ):\n\n assert mat1.nrows == mat1.ncols\n assert mat2.nrows == mat2.ncols\n assert mat1.nrows == mat2.nrows\n\n C = mat1.clone()\n\n alpha=np.array(\n alpha,\n dtype=np.double,\n )\n beta=np.array(\n beta,\n dtype=np.double,\n )\n\n cublas.dgeam(\n handle=cublas_handle,\n transa=cublas.Operation.T if transpose1 else cublas.Operation.N,\n transb=cublas.Operation.T if transpose2 else cublas.Operation.N,\n m=mat1.nrows,\n n=mat2.ncols,\n alpha=alpha.ctypes.data,\n a=mat1.pointer,\n lda=mat1.ncols,\n beta=beta.ctypes.data,\n b=mat2.pointer,\n ldb=mat2.ncols,\n c=C.pointer,\n ldc=C.ncols,\n )\n\n return C\n\n @staticmethod\n def daxpy(\n *,\n alpha,\n x,\n y,\n ):\n\n alpha=np.array(\n alpha,\n dtype=np.double,\n )\n\n cublas.daxpy(\n handle=cublas_handle,\n n=x.size,\n alpha=alpha.ctypes.data,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n )\n\n @staticmethod\n def scale(\n *,\n matrix,\n scale,\n ):\n\n alpha=np.array(\n scale,\n dtype=np.double,\n )\n cublas.dscal(\n handle=cublas_handle,\n n=matrix.size,\n alpha=alpha.ctypes.data,\n x=matrix.pointer,\n incx=1,\n )\n\n @staticmethod\n def eigh(\n *,\n matrix\n ):\n\n jobz = cusolver_base.EigMode.VECTOR\n uplo = cublas.FillMode.LOWER\n\n assert matrix.nrows == matrix.ncols\n\n evecs = matrix.clone()\n evals = GPUMatrix(\n nrows=matrix.nrows,\n ncols=1,\n dtype=matrix.dtype,\n initialize=False,\n )\n\n d_info = GPUMatrix(\n nrows=1,\n ncols=1,\n dtype=np.int64,\n )\n\n # Workspace query\n lwork = np.empty(\n 1,\n dtype=np.int64\n )\n lwork = cusolver.dsyevd_buffer_size(\n handle=cusolver_handle,\n jobz=jobz,\n uplo=uplo,\n n=evecs.ncols,\n a=evecs.pointer,\n lda=evecs.ncols,\n w=evals.pointer,\n )\n\n d_work = GPUMatrix(\n nrows=lwork,\n ncols=1,\n dtype=np.double,\n )\n\n # Compute eigenvalues/eigenvectors in-place\n cusolver.dsyevd(\n handle=cusolver_handle,\n jobz=jobz,\n uplo=uplo,\n n=evecs.ncols,\n a=evecs.pointer,\n lda=evecs.ncols,\n w=evals.pointer,\n work=d_work.pointer,\n lwork=lwork,\n info=d_info.pointer,\n )\n\n info_host = d_info.to_numpy()\n if info_host[0, 0] != 0:\n raise RuntimeError(f\"dsyevd failed with info = {info_host[0, 0]}\")\n\n evecs = GPUMatrixUtility.dgeam(\n transpose1=True,\n alpha=1.0,\n mat1=evecs,\n transpose2=False,\n beta=0.0,\n mat2=evecs,\n )\n\n return evals, evecs","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility._delete_handles","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility._delete_handles#L33-L36","kind":"function","name":"_delete_handles","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":33,"end_line":36,"context_start_line":13,"context_end_line":56,"code":"# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nimport atexit\n\nimport nvmath.bindings.cublas as cublas\nimport nvmath.bindings.cusolverDn as cusolver\nimport nvmath.bindings.cusolver as cusolver_base\nfrom .gpu_matrix import GPUMatrix\n\n# these handles are module-scoped, making them singletons\ncublas_handle = cublas.create()\n# Read scalar parameters like alpha and beta from CPU RAM\ncublas.set_pointer_mode(\n cublas_handle,\n cublas.PointerMode.HOST\n )\ncusolver_handle = cusolver.create()\n\ndef _delete_handles():\n global cublas_handle, cusolver_handle\n cublas.destroy(cublas_handle)\n cusolver.destroy(cusolver_handle)\n\natexit.register(_delete_handles)\n\nclass GPUMatrixUtility(object):\n\n @staticmethod\n def matrix_multiply(\n *,\n mat1,\n mat2,\n transpose1,\n transpose2,\n scale=1.0,\n ):\n\n alpha = np.array(\n scale,\n dtype=np.double,\n )\n beta = np.array(","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.GPUMatrixUtility","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.GPUMatrixUtility#L40-L270","kind":"class","name":"GPUMatrixUtility","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":40,"end_line":270,"context_start_line":20,"context_end_line":270,"code":"import nvmath.bindings.cusolverDn as cusolver\nimport nvmath.bindings.cusolver as cusolver_base\nfrom .gpu_matrix import GPUMatrix\n\n# these handles are module-scoped, making them singletons\ncublas_handle = cublas.create()\n# Read scalar parameters like alpha and beta from CPU RAM\ncublas.set_pointer_mode(\n cublas_handle,\n cublas.PointerMode.HOST\n )\ncusolver_handle = cusolver.create()\n\ndef _delete_handles():\n global cublas_handle, cusolver_handle\n cublas.destroy(cublas_handle)\n cusolver.destroy(cusolver_handle)\n\natexit.register(_delete_handles)\n\nclass GPUMatrixUtility(object):\n\n @staticmethod\n def matrix_multiply(\n *,\n mat1,\n mat2,\n transpose1,\n transpose2,\n scale=1.0,\n ):\n\n alpha = np.array(\n scale,\n dtype=np.double,\n )\n beta = np.array(\n 0.0,\n dtype=np.double,\n )\n m = mat1.ncols if transpose1 else mat1.nrows\n n = mat2.nrows if transpose2 else mat2.ncols\n k1 = mat1.nrows if transpose1 else mat1.ncols\n k2 = mat2.ncols if transpose2 else mat2.nrows\n assert k1 == k2\n\n c = GPUMatrix(\n nrows=m,\n ncols=n,\n )\n\n cublas.dgemm(\n handle=cublas_handle,\n transa=cublas.Operation.T if transpose2 else cublas.Operation.N,\n transb=cublas.Operation.T if transpose1 else cublas.Operation.N,\n m=n,\n n=m,\n k=k1,\n alpha=alpha.ctypes.data,\n a=mat2.pointer,\n lda=mat2.ncols,\n b=mat1.pointer,\n ldb=mat1.ncols,\n beta=beta.ctypes.data,\n c=c.pointer,\n ldc=c.ncols,\n )\n\n return c\n\n @staticmethod\n def ddot(\n *,\n x,\n y,\n ):\n\n result = np.empty(1, dtype=np.double)\n\n cublas.ddot(\n handle = cublas_handle,\n n=x.size,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n result=result.ctypes.data,\n )\n return result[0]\n\n\n @staticmethod\n def dgeam(\n *,\n transpose1,\n alpha,\n mat1,\n transpose2,\n beta,\n mat2,\n ):\n\n assert mat1.nrows == mat1.ncols\n assert mat2.nrows == mat2.ncols\n assert mat1.nrows == mat2.nrows\n\n C = mat1.clone()\n\n alpha=np.array(\n alpha,\n dtype=np.double,\n )\n beta=np.array(\n beta,\n dtype=np.double,\n )\n\n cublas.dgeam(\n handle=cublas_handle,\n transa=cublas.Operation.T if transpose1 else cublas.Operation.N,\n transb=cublas.Operation.T if transpose2 else cublas.Operation.N,\n m=mat1.nrows,\n n=mat2.ncols,\n alpha=alpha.ctypes.data,\n a=mat1.pointer,\n lda=mat1.ncols,\n beta=beta.ctypes.data,\n b=mat2.pointer,\n ldb=mat2.ncols,\n c=C.pointer,\n ldc=C.ncols,\n )\n\n return C\n\n @staticmethod\n def daxpy(\n *,\n alpha,\n x,\n y,\n ):\n\n alpha=np.array(\n alpha,\n dtype=np.double,\n )\n\n cublas.daxpy(\n handle=cublas_handle,\n n=x.size,\n alpha=alpha.ctypes.data,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n )\n\n @staticmethod\n def scale(\n *,\n matrix,\n scale,\n ):\n\n alpha=np.array(\n scale,\n dtype=np.double,\n )\n cublas.dscal(\n handle=cublas_handle,\n n=matrix.size,\n alpha=alpha.ctypes.data,\n x=matrix.pointer,\n incx=1,\n )\n\n @staticmethod\n def eigh(\n *,\n matrix\n ):\n\n jobz = cusolver_base.EigMode.VECTOR\n uplo = cublas.FillMode.LOWER\n\n assert matrix.nrows == matrix.ncols\n\n evecs = matrix.clone()\n evals = GPUMatrix(\n nrows=matrix.nrows,\n ncols=1,\n dtype=matrix.dtype,\n initialize=False,\n )\n\n d_info = GPUMatrix(\n nrows=1,\n ncols=1,\n dtype=np.int64,\n )\n\n # Workspace query\n lwork = np.empty(\n 1,\n dtype=np.int64\n )\n lwork = cusolver.dsyevd_buffer_size(\n handle=cusolver_handle,\n jobz=jobz,\n uplo=uplo,\n n=evecs.ncols,\n a=evecs.pointer,\n lda=evecs.ncols,\n w=evals.pointer,\n )\n\n d_work = GPUMatrix(\n nrows=lwork,\n ncols=1,\n dtype=np.double,\n )\n\n # Compute eigenvalues/eigenvectors in-place\n cusolver.dsyevd(\n handle=cusolver_handle,\n jobz=jobz,\n uplo=uplo,\n n=evecs.ncols,\n a=evecs.pointer,\n lda=evecs.ncols,\n w=evals.pointer,\n work=d_work.pointer,\n lwork=lwork,\n info=d_info.pointer,\n )\n\n info_host = d_info.to_numpy()\n if info_host[0, 0] != 0:\n raise RuntimeError(f\"dsyevd failed with info = {info_host[0, 0]}\")\n\n evecs = GPUMatrixUtility.dgeam(\n transpose1=True,\n alpha=1.0,\n mat1=evecs,\n transpose2=False,\n beta=0.0,\n mat2=evecs,\n )\n\n return evals, evecs","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.matrix_multiply","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.matrix_multiply#L43-L88","kind":"function","name":"matrix_multiply","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":43,"end_line":88,"context_start_line":23,"context_end_line":108,"code":"\n# these handles are module-scoped, making them singletons\ncublas_handle = cublas.create()\n# Read scalar parameters like alpha and beta from CPU RAM\ncublas.set_pointer_mode(\n cublas_handle,\n cublas.PointerMode.HOST\n )\ncusolver_handle = cusolver.create()\n\ndef _delete_handles():\n global cublas_handle, cusolver_handle\n cublas.destroy(cublas_handle)\n cusolver.destroy(cusolver_handle)\n\natexit.register(_delete_handles)\n\nclass GPUMatrixUtility(object):\n\n @staticmethod\n def matrix_multiply(\n *,\n mat1,\n mat2,\n transpose1,\n transpose2,\n scale=1.0,\n ):\n\n alpha = np.array(\n scale,\n dtype=np.double,\n )\n beta = np.array(\n 0.0,\n dtype=np.double,\n )\n m = mat1.ncols if transpose1 else mat1.nrows\n n = mat2.nrows if transpose2 else mat2.ncols\n k1 = mat1.nrows if transpose1 else mat1.ncols\n k2 = mat2.ncols if transpose2 else mat2.nrows\n assert k1 == k2\n\n c = GPUMatrix(\n nrows=m,\n ncols=n,\n )\n\n cublas.dgemm(\n handle=cublas_handle,\n transa=cublas.Operation.T if transpose2 else cublas.Operation.N,\n transb=cublas.Operation.T if transpose1 else cublas.Operation.N,\n m=n,\n n=m,\n k=k1,\n alpha=alpha.ctypes.data,\n a=mat2.pointer,\n lda=mat2.ncols,\n b=mat1.pointer,\n ldb=mat1.ncols,\n beta=beta.ctypes.data,\n c=c.pointer,\n ldc=c.ncols,\n )\n\n return c\n\n @staticmethod\n def ddot(\n *,\n x,\n y,\n ):\n\n result = np.empty(1, dtype=np.double)\n\n cublas.ddot(\n handle = cublas_handle,\n n=x.size,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n result=result.ctypes.data,\n )\n return result[0]","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.ddot","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.ddot#L91-L108","kind":"function","name":"ddot","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":91,"end_line":108,"context_start_line":71,"context_end_line":128,"code":" cublas.dgemm(\n handle=cublas_handle,\n transa=cublas.Operation.T if transpose2 else cublas.Operation.N,\n transb=cublas.Operation.T if transpose1 else cublas.Operation.N,\n m=n,\n n=m,\n k=k1,\n alpha=alpha.ctypes.data,\n a=mat2.pointer,\n lda=mat2.ncols,\n b=mat1.pointer,\n ldb=mat1.ncols,\n beta=beta.ctypes.data,\n c=c.pointer,\n ldc=c.ncols,\n )\n\n return c\n\n @staticmethod\n def ddot(\n *,\n x,\n y,\n ):\n\n result = np.empty(1, dtype=np.double)\n\n cublas.ddot(\n handle = cublas_handle,\n n=x.size,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n result=result.ctypes.data,\n )\n return result[0]\n\n\n @staticmethod\n def dgeam(\n *,\n transpose1,\n alpha,\n mat1,\n transpose2,\n beta,\n mat2,\n ):\n\n assert mat1.nrows == mat1.ncols\n assert mat2.nrows == mat2.ncols\n assert mat1.nrows == mat2.nrows\n\n C = mat1.clone()\n\n alpha=np.array(","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.dgeam","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.dgeam#L112-L153","kind":"function","name":"dgeam","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":112,"end_line":153,"context_start_line":92,"context_end_line":173,"code":" *,\n x,\n y,\n ):\n\n result = np.empty(1, dtype=np.double)\n\n cublas.ddot(\n handle = cublas_handle,\n n=x.size,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n result=result.ctypes.data,\n )\n return result[0]\n\n\n @staticmethod\n def dgeam(\n *,\n transpose1,\n alpha,\n mat1,\n transpose2,\n beta,\n mat2,\n ):\n\n assert mat1.nrows == mat1.ncols\n assert mat2.nrows == mat2.ncols\n assert mat1.nrows == mat2.nrows\n\n C = mat1.clone()\n\n alpha=np.array(\n alpha,\n dtype=np.double,\n )\n beta=np.array(\n beta,\n dtype=np.double,\n )\n\n cublas.dgeam(\n handle=cublas_handle,\n transa=cublas.Operation.T if transpose1 else cublas.Operation.N,\n transb=cublas.Operation.T if transpose2 else cublas.Operation.N,\n m=mat1.nrows,\n n=mat2.ncols,\n alpha=alpha.ctypes.data,\n a=mat1.pointer,\n lda=mat1.ncols,\n beta=beta.ctypes.data,\n b=mat2.pointer,\n ldb=mat2.ncols,\n c=C.pointer,\n ldc=C.ncols,\n )\n\n return C\n\n @staticmethod\n def daxpy(\n *,\n alpha,\n x,\n y,\n ):\n\n alpha=np.array(\n alpha,\n dtype=np.double,\n )\n\n cublas.daxpy(\n handle=cublas_handle,\n n=x.size,\n alpha=alpha.ctypes.data,\n x=x.pointer,\n incx=1,","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.daxpy","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.daxpy#L156-L176","kind":"function","name":"daxpy","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":156,"end_line":176,"context_start_line":136,"context_end_line":196,"code":"\n cublas.dgeam(\n handle=cublas_handle,\n transa=cublas.Operation.T if transpose1 else cublas.Operation.N,\n transb=cublas.Operation.T if transpose2 else cublas.Operation.N,\n m=mat1.nrows,\n n=mat2.ncols,\n alpha=alpha.ctypes.data,\n a=mat1.pointer,\n lda=mat1.ncols,\n beta=beta.ctypes.data,\n b=mat2.pointer,\n ldb=mat2.ncols,\n c=C.pointer,\n ldc=C.ncols,\n )\n\n return C\n\n @staticmethod\n def daxpy(\n *,\n alpha,\n x,\n y,\n ):\n\n alpha=np.array(\n alpha,\n dtype=np.double,\n )\n\n cublas.daxpy(\n handle=cublas_handle,\n n=x.size,\n alpha=alpha.ctypes.data,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n )\n\n @staticmethod\n def scale(\n *,\n matrix,\n scale,\n ):\n\n alpha=np.array(\n scale,\n dtype=np.double,\n )\n cublas.dscal(\n handle=cublas_handle,\n n=matrix.size,\n alpha=alpha.ctypes.data,\n x=matrix.pointer,\n incx=1,\n )\n","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.scale","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.scale#L179-L195","kind":"function","name":"scale","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":179,"end_line":195,"context_start_line":159,"context_end_line":215,"code":" x,\n y,\n ):\n\n alpha=np.array(\n alpha,\n dtype=np.double,\n )\n\n cublas.daxpy(\n handle=cublas_handle,\n n=x.size,\n alpha=alpha.ctypes.data,\n x=x.pointer,\n incx=1,\n y=y.pointer,\n incy=1,\n )\n\n @staticmethod\n def scale(\n *,\n matrix,\n scale,\n ):\n\n alpha=np.array(\n scale,\n dtype=np.double,\n )\n cublas.dscal(\n handle=cublas_handle,\n n=matrix.size,\n alpha=alpha.ctypes.data,\n x=matrix.pointer,\n incx=1,\n )\n\n @staticmethod\n def eigh(\n *,\n matrix\n ):\n\n jobz = cusolver_base.EigMode.VECTOR\n uplo = cublas.FillMode.LOWER\n\n assert matrix.nrows == matrix.ncols\n\n evecs = matrix.clone()\n evals = GPUMatrix(\n nrows=matrix.nrows,\n ncols=1,\n dtype=matrix.dtype,\n initialize=False,\n )\n","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.eigh","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix_utility.eigh#L198-L270","kind":"function","name":"eigh","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":198,"end_line":270,"context_start_line":178,"context_end_line":270,"code":" @staticmethod\n def scale(\n *,\n matrix,\n scale,\n ):\n\n alpha=np.array(\n scale,\n dtype=np.double,\n )\n cublas.dscal(\n handle=cublas_handle,\n n=matrix.size,\n alpha=alpha.ctypes.data,\n x=matrix.pointer,\n incx=1,\n )\n\n @staticmethod\n def eigh(\n *,\n matrix\n ):\n\n jobz = cusolver_base.EigMode.VECTOR\n uplo = cublas.FillMode.LOWER\n\n assert matrix.nrows == matrix.ncols\n\n evecs = matrix.clone()\n evals = GPUMatrix(\n nrows=matrix.nrows,\n ncols=1,\n dtype=matrix.dtype,\n initialize=False,\n )\n\n d_info = GPUMatrix(\n nrows=1,\n ncols=1,\n dtype=np.int64,\n )\n\n # Workspace query\n lwork = np.empty(\n 1,\n dtype=np.int64\n )\n lwork = cusolver.dsyevd_buffer_size(\n handle=cusolver_handle,\n jobz=jobz,\n uplo=uplo,\n n=evecs.ncols,\n a=evecs.pointer,\n lda=evecs.ncols,\n w=evals.pointer,\n )\n\n d_work = GPUMatrix(\n nrows=lwork,\n ncols=1,\n dtype=np.double,\n )\n\n # Compute eigenvalues/eigenvectors in-place\n cusolver.dsyevd(\n handle=cusolver_handle,\n jobz=jobz,\n uplo=uplo,\n n=evecs.ncols,\n a=evecs.pointer,\n lda=evecs.ncols,\n w=evals.pointer,\n work=d_work.pointer,\n lwork=lwork,\n info=d_info.pointer,\n )\n\n info_host = d_info.to_numpy()\n if info_host[0, 0] != 0:\n raise RuntimeError(f\"dsyevd failed with info = {info_host[0, 0]}\")\n\n evecs = GPUMatrixUtility.dgeam(\n transpose1=True,\n alpha=1.0,\n mat1=evecs,\n transpose2=False,\n beta=0.0,\n mat2=evecs,\n )\n\n return evals, evecs","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan#L1-L97","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_plan.py","language":"python","start_line":1,"end_line":97,"context_start_line":1,"context_end_line":97,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_ao_pair_list import CuestAOPairList\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestOEIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n ao_pair_list : CuestAOPairList,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n oe_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n )\n\n self.oe_int_plan_handle = ce.cuestOEIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOEIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=oe_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestOEIntPlanCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=oe_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestOEIntPlanDestroy(\n handle=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanDestroy failed')","source_hash":"8bc734a7656d5f831b2d5261d6a91e8fbc335123560308a94d58feb644452508","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan.CuestOEIntPlan","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan.CuestOEIntPlan#L27-L97","kind":"class","name":"CuestOEIntPlan","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_plan.py","language":"python","start_line":27,"end_line":97,"context_start_line":7,"context_end_line":97,"code":"#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_ao_pair_list import CuestAOPairList\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestOEIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n ao_pair_list : CuestAOPairList,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n oe_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n )\n\n self.oe_int_plan_handle = ce.cuestOEIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOEIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=oe_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestOEIntPlanCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=oe_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestOEIntPlanDestroy(\n handle=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanDestroy failed')","source_hash":"8bc734a7656d5f831b2d5261d6a91e8fbc335123560308a94d58feb644452508","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan.__init__#L29-L86","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_plan.py","language":"python","start_line":29,"end_line":86,"context_start_line":9,"context_end_line":97,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_ao_pair_list import CuestAOPairList\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestOEIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n ao_pair_list : CuestAOPairList,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n oe_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_OEINTPLAN_PARAMETERS,\n )\n\n self.oe_int_plan_handle = ce.cuestOEIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOEIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=oe_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestOEIntPlanCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=oe_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestOEIntPlanDestroy(\n handle=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanDestroy failed')","source_hash":"8bc734a7656d5f831b2d5261d6a91e8fbc335123560308a94d58feb644452508","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_plan.__del__#L88-L97","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_plan.py","language":"python","start_line":88,"end_line":97,"context_start_line":68,"context_end_line":97,"code":" # => Creation <= #\n\n status = ce.cuestOEIntPlanCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=oe_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestOEIntPlanDestroy(\n handle=self.oe_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOEIntPlanDestroy failed')","source_hash":"8bc734a7656d5f831b2d5261d6a91e8fbc335123560308a94d58feb644452508","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute#L1-L282","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","language":"python","start_line":1,"end_line":282,"context_start_line":1,"context_end_line":282,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_df_int_plan import CuestDFIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestDFIntCompute(object):\n\n @staticmethod\n def coulomb(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n Dptr,\n Jptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n Jptr2 = ce.Pointer()\n Jptr2.value = np.intp(Jptr)\n\n # => Workspace query <= #\n\n dfj_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFCOULOMBCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFCoulombComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfj_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n outCoulombMatrix=Jptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFCoulombComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestDFCoulombCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfj_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n outCoulombMatrix=Jptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFCoulombCompute failed')\n del dfj_compute_parameters\n\n\n @staticmethod\n def symmetric_exchange(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n nocc,\n Coccptr,\n Kptr,\n dfk_int8_slice_count,\n dfk_int8_modulus_count,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Kptr2 = ce.Pointer()\n Kptr2.value = np.intp(Kptr)\n\n # => Workspace query <= #\n\n dfk_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS)\n\n slice_count = ce.data_uint64_t(dfk_int8_slice_count)\n modulus_count = ce.data_uint64_t(dfk_int8_modulus_count)\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n parameters=dfk_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricExchangeComputeParametersAttributes.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS_INT8_SLICE_COUNT,\n attributeValue=slice_count,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n parameters=dfk_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricExchangeComputeParametersAttributes.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS_INT8_MODULUS_COUNT,\n attributeValue=modulus_count,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n exchangeint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFSymmetricExchangeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfk_compute_parameters.parameters,\n variableBufferSize=exchangeint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outExchangeMatrix=Kptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFExchangeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestDFSymmetricExchangeCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfk_compute_parameters.parameters,\n variableBufferSize=exchangeint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outExchangeMatrix=Kptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFExchangeCompute failed')\n del dfk_compute_parameters\n\n\n @staticmethod\n def coulomb_and_exchange_gradient(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n scaleJ,\n DJptr,\n scaleK,\n noccsK,\n CoccsKptr,\n Gptr,\n ):\n\n DJptr2 = ce.Pointer()\n DJptr2.value = np.intp(DJptr)\n\n CoccsKptr2 = ce.Pointer()\n CoccsKptr2.value = np.intp(CoccsKptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => Workspace query <= #\n\n df_grad_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n memory_policy_data = ce.data_cuestDFSymmetricDerivativeComputeMemoryPolicy_t(ce.CuestDFSymmetricDerivativeComputeMemoryPolicy.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_MEMORY_POLICY_FULL)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=df_grad_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricDerivativeComputeParametersAttributes.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS_MEMORY_POLICY,\n attributeValue=memory_policy_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeComputeWorkspaceQuery failed')\n\n try:\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n except RuntimeError:\n memory_policy_data = ce.data_cuestDFSymmetricDerivativeComputeMemoryPolicy_t(ce.CuestDFSymmetricDerivativeComputeMemoryPolicy.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_MEMORY_POLICY_BLOCKED)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=df_grad_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricDerivativeComputeParametersAttributes.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS_MEMORY_POLICY,\n attributeValue=memory_policy_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeComputeWorkspaceQuery failed')\n\n try:\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n except RuntimeError:\n raise RuntimeError('Cannot allocate memory for cuestDFSymmetricDerivativeCompute')\n\n status = ce.cuestDFSymmetricDerivativeCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeCompute failed')\n del df_grad_compute_parameters\n\n","source_hash":"f5273739ec00a0245d5d47bd329c3fe5906be55be378ab13511174c0bcf324e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute.CuestDFIntCompute","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute.CuestDFIntCompute#L27-L280","kind":"class","name":"CuestDFIntCompute","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","language":"python","start_line":27,"end_line":280,"context_start_line":7,"context_end_line":282,"code":"#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_df_int_plan import CuestDFIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestDFIntCompute(object):\n\n @staticmethod\n def coulomb(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n Dptr,\n Jptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n Jptr2 = ce.Pointer()\n Jptr2.value = np.intp(Jptr)\n\n # => Workspace query <= #\n\n dfj_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFCOULOMBCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFCoulombComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfj_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n outCoulombMatrix=Jptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFCoulombComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestDFCoulombCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfj_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n outCoulombMatrix=Jptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFCoulombCompute failed')\n del dfj_compute_parameters\n\n\n @staticmethod\n def symmetric_exchange(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n nocc,\n Coccptr,\n Kptr,\n dfk_int8_slice_count,\n dfk_int8_modulus_count,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Kptr2 = ce.Pointer()\n Kptr2.value = np.intp(Kptr)\n\n # => Workspace query <= #\n\n dfk_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS)\n\n slice_count = ce.data_uint64_t(dfk_int8_slice_count)\n modulus_count = ce.data_uint64_t(dfk_int8_modulus_count)\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n parameters=dfk_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricExchangeComputeParametersAttributes.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS_INT8_SLICE_COUNT,\n attributeValue=slice_count,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n parameters=dfk_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricExchangeComputeParametersAttributes.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS_INT8_MODULUS_COUNT,\n attributeValue=modulus_count,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n exchangeint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFSymmetricExchangeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfk_compute_parameters.parameters,\n variableBufferSize=exchangeint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outExchangeMatrix=Kptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFExchangeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestDFSymmetricExchangeCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfk_compute_parameters.parameters,\n variableBufferSize=exchangeint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outExchangeMatrix=Kptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFExchangeCompute failed')\n del dfk_compute_parameters\n\n\n @staticmethod\n def coulomb_and_exchange_gradient(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n scaleJ,\n DJptr,\n scaleK,\n noccsK,\n CoccsKptr,\n Gptr,\n ):\n\n DJptr2 = ce.Pointer()\n DJptr2.value = np.intp(DJptr)\n\n CoccsKptr2 = ce.Pointer()\n CoccsKptr2.value = np.intp(CoccsKptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => Workspace query <= #\n\n df_grad_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n memory_policy_data = ce.data_cuestDFSymmetricDerivativeComputeMemoryPolicy_t(ce.CuestDFSymmetricDerivativeComputeMemoryPolicy.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_MEMORY_POLICY_FULL)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=df_grad_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricDerivativeComputeParametersAttributes.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS_MEMORY_POLICY,\n attributeValue=memory_policy_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeComputeWorkspaceQuery failed')\n\n try:\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n except RuntimeError:\n memory_policy_data = ce.data_cuestDFSymmetricDerivativeComputeMemoryPolicy_t(ce.CuestDFSymmetricDerivativeComputeMemoryPolicy.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_MEMORY_POLICY_BLOCKED)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=df_grad_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricDerivativeComputeParametersAttributes.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS_MEMORY_POLICY,\n attributeValue=memory_policy_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeComputeWorkspaceQuery failed')\n\n try:\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n except RuntimeError:\n raise RuntimeError('Cannot allocate memory for cuestDFSymmetricDerivativeCompute')\n\n status = ce.cuestDFSymmetricDerivativeCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeCompute failed')\n del df_grad_compute_parameters\n\n","source_hash":"f5273739ec00a0245d5d47bd329c3fe5906be55be378ab13511174c0bcf324e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute.coulomb","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute.coulomb#L30-L75","kind":"function","name":"coulomb","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","language":"python","start_line":30,"end_line":75,"context_start_line":10,"context_end_line":95,"code":"# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_df_int_plan import CuestDFIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestDFIntCompute(object):\n\n @staticmethod\n def coulomb(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n Dptr,\n Jptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n Jptr2 = ce.Pointer()\n Jptr2.value = np.intp(Jptr)\n\n # => Workspace query <= #\n\n dfj_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFCOULOMBCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFCoulombComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfj_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n outCoulombMatrix=Jptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFCoulombComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestDFCoulombCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfj_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n outCoulombMatrix=Jptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFCoulombCompute failed')\n del dfj_compute_parameters\n\n\n @staticmethod\n def symmetric_exchange(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n nocc,\n Coccptr,\n Kptr,\n dfk_int8_slice_count,\n dfk_int8_modulus_count,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Kptr2 = ce.Pointer()\n Kptr2.value = np.intp(Kptr)\n","source_hash":"f5273739ec00a0245d5d47bd329c3fe5906be55be378ab13511174c0bcf324e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute.symmetric_exchange","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute.symmetric_exchange#L79-L159","kind":"function","name":"symmetric_exchange","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","language":"python","start_line":79,"end_line":159,"context_start_line":59,"context_end_line":179,"code":" if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFCoulombComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestDFCoulombCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfj_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n outCoulombMatrix=Jptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFCoulombCompute failed')\n del dfj_compute_parameters\n\n\n @staticmethod\n def symmetric_exchange(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n nocc,\n Coccptr,\n Kptr,\n dfk_int8_slice_count,\n dfk_int8_modulus_count,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Kptr2 = ce.Pointer()\n Kptr2.value = np.intp(Kptr)\n\n # => Workspace query <= #\n\n dfk_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS)\n\n slice_count = ce.data_uint64_t(dfk_int8_slice_count)\n modulus_count = ce.data_uint64_t(dfk_int8_modulus_count)\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n parameters=dfk_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricExchangeComputeParametersAttributes.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS_INT8_SLICE_COUNT,\n attributeValue=slice_count,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS,\n parameters=dfk_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricExchangeComputeParametersAttributes.CUEST_DFSYMMETRICEXCHANGECOMPUTE_PARAMETERS_INT8_MODULUS_COUNT,\n attributeValue=modulus_count,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n exchangeint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFSymmetricExchangeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfk_compute_parameters.parameters,\n variableBufferSize=exchangeint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outExchangeMatrix=Kptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFExchangeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestDFSymmetricExchangeCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfk_compute_parameters.parameters,\n variableBufferSize=exchangeint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outExchangeMatrix=Kptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFExchangeCompute failed')\n del dfk_compute_parameters\n\n\n @staticmethod\n def coulomb_and_exchange_gradient(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n scaleJ,\n DJptr,\n scaleK,\n noccsK,\n CoccsKptr,\n Gptr,\n ):\n\n DJptr2 = ce.Pointer()\n DJptr2.value = np.intp(DJptr)\n\n CoccsKptr2 = ce.Pointer()\n CoccsKptr2.value = np.intp(CoccsKptr)","source_hash":"f5273739ec00a0245d5d47bd329c3fe5906be55be378ab13511174c0bcf324e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute.coulomb_and_exchange_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_compute.coulomb_and_exchange_gradient#L163-L280","kind":"function","name":"coulomb_and_exchange_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","language":"python","start_line":163,"end_line":280,"context_start_line":143,"context_end_line":282,"code":"\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestDFSymmetricExchangeCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=dfk_compute_parameters.parameters,\n variableBufferSize=exchangeint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outExchangeMatrix=Kptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFExchangeCompute failed')\n del dfk_compute_parameters\n\n\n @staticmethod\n def coulomb_and_exchange_gradient(\n *,\n handle : CuestHandle,\n df_int_plan : CuestDFIntPlan,\n scaleJ,\n DJptr,\n scaleK,\n noccsK,\n CoccsKptr,\n Gptr,\n ):\n\n DJptr2 = ce.Pointer()\n DJptr2.value = np.intp(DJptr)\n\n CoccsKptr2 = ce.Pointer()\n CoccsKptr2.value = np.intp(CoccsKptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => Workspace query <= #\n\n df_grad_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n memory_policy_data = ce.data_cuestDFSymmetricDerivativeComputeMemoryPolicy_t(ce.CuestDFSymmetricDerivativeComputeMemoryPolicy.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_MEMORY_POLICY_FULL)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=df_grad_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricDerivativeComputeParametersAttributes.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS_MEMORY_POLICY,\n attributeValue=memory_policy_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeComputeWorkspaceQuery failed')\n\n try:\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n except RuntimeError:\n memory_policy_data = ce.data_cuestDFSymmetricDerivativeComputeMemoryPolicy_t(ce.CuestDFSymmetricDerivativeComputeMemoryPolicy.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_MEMORY_POLICY_BLOCKED)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS,\n parameters=df_grad_compute_parameters.parameters,\n attribute=ce.CuestDFSymmetricDerivativeComputeParametersAttributes.CUEST_DFSYMMETRICDERIVATIVECOMPUTE_PARAMETERS_MEMORY_POLICY,\n attributeValue=memory_policy_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestDFSymmetricDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeComputeWorkspaceQuery failed')\n\n try:\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n except RuntimeError:\n raise RuntimeError('Cannot allocate memory for cuestDFSymmetricDerivativeCompute')\n\n status = ce.cuestDFSymmetricDerivativeCompute(\n handle=handle.handle,\n plan=df_int_plan.df_int_plan_handle,\n parameters=df_grad_compute_parameters.parameters,\n variableBufferSize=variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n densityScale=scaleJ,\n densityMatrix=DJptr2,\n coefficientScale=scaleK,\n numCoefficientMatrices=len(noccsK),\n numOccupied=noccsK,\n coefficientMatrices=CoccsKptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFSymmetricDerivativeCompute failed')\n del df_grad_compute_parameters\n\n","source_hash":"f5273739ec00a0245d5d47bd329c3fe5906be55be378ab13511174c0bcf324e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_results","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_results#L1-L51","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_results","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_results.py","language":"python","start_line":1,"end_line":51,"context_start_line":1,"context_end_line":51,"code":"# Copyright 2025-2026 NVIDIA CORPORATION & AFFILIATES.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nclass CuestResults(object):\n\n def __init__(\n self,\n *,\n resultsType,\n results_handle,\n ):\n\n self.initialized = False\n\n self.resultsType = resultsType\n self.results = results_handle\n\n status = ce.cuestResultsCreate(\n resultsType=self.resultsType,\n outResults=self.results,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsCreate failed: %d' % status)\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestResultsDestroy(\n resultsType=self.resultsType,\n results=self.results,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsDestroy failed: %d' % status)","source_hash":"4a4ab48383fcac003a7f438e1e21b20a24cdedca881929d29d74e2dcb07502d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_results.CuestResults","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_results.CuestResults#L17-L51","kind":"class","name":"CuestResults","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_results.py","language":"python","start_line":17,"end_line":51,"context_start_line":1,"context_end_line":51,"code":"# Copyright 2025-2026 NVIDIA CORPORATION & AFFILIATES.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nclass CuestResults(object):\n\n def __init__(\n self,\n *,\n resultsType,\n results_handle,\n ):\n\n self.initialized = False\n\n self.resultsType = resultsType\n self.results = results_handle\n\n status = ce.cuestResultsCreate(\n resultsType=self.resultsType,\n outResults=self.results,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsCreate failed: %d' % status)\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestResultsDestroy(\n resultsType=self.resultsType,\n results=self.results,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsDestroy failed: %d' % status)","source_hash":"4a4ab48383fcac003a7f438e1e21b20a24cdedca881929d29d74e2dcb07502d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_results.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_results.__init__#L19-L39","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_results.py","language":"python","start_line":19,"end_line":39,"context_start_line":1,"context_end_line":51,"code":"# Copyright 2025-2026 NVIDIA CORPORATION & AFFILIATES.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nclass CuestResults(object):\n\n def __init__(\n self,\n *,\n resultsType,\n results_handle,\n ):\n\n self.initialized = False\n\n self.resultsType = resultsType\n self.results = results_handle\n\n status = ce.cuestResultsCreate(\n resultsType=self.resultsType,\n outResults=self.results,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsCreate failed: %d' % status)\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestResultsDestroy(\n resultsType=self.resultsType,\n results=self.results,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsDestroy failed: %d' % status)","source_hash":"4a4ab48383fcac003a7f438e1e21b20a24cdedca881929d29d74e2dcb07502d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_results.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_results.__del__#L41-L51","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_results.py","language":"python","start_line":41,"end_line":51,"context_start_line":21,"context_end_line":51,"code":" *,\n resultsType,\n results_handle,\n ):\n\n self.initialized = False\n\n self.resultsType = resultsType\n self.results = results_handle\n\n status = ce.cuestResultsCreate(\n resultsType=self.resultsType,\n outResults=self.results,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsCreate failed: %d' % status)\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestResultsDestroy(\n resultsType=self.resultsType,\n results=self.results,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsDestroy failed: %d' % status)","source_hash":"4a4ab48383fcac003a7f438e1e21b20a24cdedca881929d29d74e2dcb07502d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan#L1-L132","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_plan.py","language":"python","start_line":1,"end_line":132,"context_start_line":1,"context_end_line":132,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_ao_pair_list import CuestAOPairList\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestDFIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n primary : CuestAOBasis,\n auxiliary : CuestAOBasis,\n ao_pair_list : CuestAOPairList,\n exchange_scale : float = 1.0,\n df_fitting_eigenvalue_cutoff : float = 1.0e-12,\n ):\n\n self.initialized = False\n\n self.handle = handle\n self.exchange_scale = exchange_scale\n self.df_fitting_eigenvalue_cutoff = df_fitting_eigenvalue_cutoff\n\n # NOTE: The CuestDFIntPlan has several defaultable parameters that\n # production codes may wish to override and expose as user-accessible\n # parameters.\n\n df_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n )\n\n exchange_scale_data = ce.data_double(self.exchange_scale)\n df_fitting_eigenvalue_cutoff_data = ce.data_double(self.df_fitting_eigenvalue_cutoff)\n\n self.df_int_plan_handle = ce.cuestDFIntPlanHandle()\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=df_int_plan_parameters.parameters,\n attribute=ce.CuestDFIntPlanParametersAttributes.CUEST_DFINTPLAN_PARAMETERS_EXCHANGE_FRACTION,\n attributeValue=exchange_scale_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=df_int_plan_parameters.parameters,\n attribute=ce.CuestDFIntPlanParametersAttributes.CUEST_DFINTPLAN_PARAMETERS_FITTING_CUTOFF,\n attributeValue=df_fitting_eigenvalue_cutoff_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n primaryBasis=primary.ao_basis_handle,\n auxiliaryBasis=auxiliary.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=df_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanCreateWorkspaceQuery failed')\n\n # Most likely place to run out of device memory, so we will add a custom RuntimeError\n try:\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n except RuntimeError as e:\n raise RuntimeError(\"CuestDFIntPlan workspace allocation failed - out of memory for CoreDF\") from e\n\n # => Creation <= #\n\n status = ce.cuestDFIntPlanCreate(\n handle=handle.handle,\n primaryBasis=primary.ao_basis_handle,\n auxiliaryBasis=auxiliary.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=df_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDFIntPlanDestroy(\n handle=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanDestroy failed')","source_hash":"01290eddc89b5cac743575d81129c5e3d86030bbfb3ebf23d3d1695de7691181","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan.CuestDFIntPlan","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan.CuestDFIntPlan#L27-L132","kind":"class","name":"CuestDFIntPlan","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_plan.py","language":"python","start_line":27,"end_line":132,"context_start_line":7,"context_end_line":132,"code":"#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_ao_pair_list import CuestAOPairList\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestDFIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n primary : CuestAOBasis,\n auxiliary : CuestAOBasis,\n ao_pair_list : CuestAOPairList,\n exchange_scale : float = 1.0,\n df_fitting_eigenvalue_cutoff : float = 1.0e-12,\n ):\n\n self.initialized = False\n\n self.handle = handle\n self.exchange_scale = exchange_scale\n self.df_fitting_eigenvalue_cutoff = df_fitting_eigenvalue_cutoff\n\n # NOTE: The CuestDFIntPlan has several defaultable parameters that\n # production codes may wish to override and expose as user-accessible\n # parameters.\n\n df_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n )\n\n exchange_scale_data = ce.data_double(self.exchange_scale)\n df_fitting_eigenvalue_cutoff_data = ce.data_double(self.df_fitting_eigenvalue_cutoff)\n\n self.df_int_plan_handle = ce.cuestDFIntPlanHandle()\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=df_int_plan_parameters.parameters,\n attribute=ce.CuestDFIntPlanParametersAttributes.CUEST_DFINTPLAN_PARAMETERS_EXCHANGE_FRACTION,\n attributeValue=exchange_scale_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=df_int_plan_parameters.parameters,\n attribute=ce.CuestDFIntPlanParametersAttributes.CUEST_DFINTPLAN_PARAMETERS_FITTING_CUTOFF,\n attributeValue=df_fitting_eigenvalue_cutoff_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n primaryBasis=primary.ao_basis_handle,\n auxiliaryBasis=auxiliary.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=df_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanCreateWorkspaceQuery failed')\n\n # Most likely place to run out of device memory, so we will add a custom RuntimeError\n try:\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n except RuntimeError as e:\n raise RuntimeError(\"CuestDFIntPlan workspace allocation failed - out of memory for CoreDF\") from e\n\n # => Creation <= #\n\n status = ce.cuestDFIntPlanCreate(\n handle=handle.handle,\n primaryBasis=primary.ao_basis_handle,\n auxiliaryBasis=auxiliary.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=df_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDFIntPlanDestroy(\n handle=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanDestroy failed')","source_hash":"01290eddc89b5cac743575d81129c5e3d86030bbfb3ebf23d3d1695de7691181","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan.__init__#L29-L121","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_plan.py","language":"python","start_line":29,"end_line":121,"context_start_line":9,"context_end_line":132,"code":"#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_ao_pair_list import CuestAOPairList\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestDFIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n primary : CuestAOBasis,\n auxiliary : CuestAOBasis,\n ao_pair_list : CuestAOPairList,\n exchange_scale : float = 1.0,\n df_fitting_eigenvalue_cutoff : float = 1.0e-12,\n ):\n\n self.initialized = False\n\n self.handle = handle\n self.exchange_scale = exchange_scale\n self.df_fitting_eigenvalue_cutoff = df_fitting_eigenvalue_cutoff\n\n # NOTE: The CuestDFIntPlan has several defaultable parameters that\n # production codes may wish to override and expose as user-accessible\n # parameters.\n\n df_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n )\n\n exchange_scale_data = ce.data_double(self.exchange_scale)\n df_fitting_eigenvalue_cutoff_data = ce.data_double(self.df_fitting_eigenvalue_cutoff)\n\n self.df_int_plan_handle = ce.cuestDFIntPlanHandle()\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=df_int_plan_parameters.parameters,\n attribute=ce.CuestDFIntPlanParametersAttributes.CUEST_DFINTPLAN_PARAMETERS_EXCHANGE_FRACTION,\n attributeValue=exchange_scale_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_DFINTPLAN_PARAMETERS,\n parameters=df_int_plan_parameters.parameters,\n attribute=ce.CuestDFIntPlanParametersAttributes.CUEST_DFINTPLAN_PARAMETERS_FITTING_CUTOFF,\n attributeValue=df_fitting_eigenvalue_cutoff_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed')\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestDFIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n primaryBasis=primary.ao_basis_handle,\n auxiliaryBasis=auxiliary.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=df_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanCreateWorkspaceQuery failed')\n\n # Most likely place to run out of device memory, so we will add a custom RuntimeError\n try:\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n except RuntimeError as e:\n raise RuntimeError(\"CuestDFIntPlan workspace allocation failed - out of memory for CoreDF\") from e\n\n # => Creation <= #\n\n status = ce.cuestDFIntPlanCreate(\n handle=handle.handle,\n primaryBasis=primary.ao_basis_handle,\n auxiliaryBasis=auxiliary.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=df_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDFIntPlanDestroy(\n handle=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanDestroy failed')","source_hash":"01290eddc89b5cac743575d81129c5e3d86030bbfb3ebf23d3d1695de7691181","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_df_int_plan.__del__#L123-L132","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_plan.py","language":"python","start_line":123,"end_line":132,"context_start_line":103,"context_end_line":132,"code":"\n status = ce.cuestDFIntPlanCreate(\n handle=handle.handle,\n primaryBasis=primary.ao_basis_handle,\n auxiliaryBasis=auxiliary.ao_basis_handle,\n pairList=ao_pair_list.ao_pair_list_handle,\n parameters=df_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestDFIntPlanDestroy(\n handle=self.df_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestDFIntPlanDestroy failed')","source_hash":"01290eddc89b5cac743575d81129c5e3d86030bbfb3ebf23d3d1695de7691181","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.unit_conversions","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.unit_conversions#L1-L25","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.unit_conversions","path":"cuEST/cuest_scf_examples/cuest_scf/unit_conversions.py","language":"python","start_line":1,"end_line":25,"context_start_line":1,"context_end_line":25,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nclass UnitConversions(object):\n\n conversions = {\n 'ang_per_bohr' : 0.52917720859, # PSI4\n }\n\n for key, value in conversions.copy().items():\n U1, U2 = key.split('_per_')\n key2 = U2 + '_per_' + U1\n conversions[key2] = 1.0 / value","source_hash":"b759427172fc1cbfb09dfc49dd310cc635a9d82b4e58585731cbf7c32170838e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.unit_conversions.UnitConversions","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.unit_conversions.UnitConversions#L16-L25","kind":"class","name":"UnitConversions","path":"cuEST/cuest_scf_examples/cuest_scf/unit_conversions.py","language":"python","start_line":16,"end_line":25,"context_start_line":1,"context_end_line":25,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nclass UnitConversions(object):\n\n conversions = {\n 'ang_per_bohr' : 0.52917720859, # PSI4\n }\n\n for key, value in conversions.copy().items():\n U1, U2 = key.split('_per_')\n key2 = U2 + '_per_' + U1\n conversions[key2] = 1.0 / value","source_hash":"b759427172fc1cbfb09dfc49dd310cc635a9d82b4e58585731cbf7c32170838e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.molecule","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.molecule#L1-L133","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.molecule","path":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","language":"python","start_line":1,"end_line":133,"context_start_line":1,"context_end_line":133,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .unit_conversions import UnitConversions\nfrom .periodic_table import PeriodicTable\n\nclass Molecule(object):\n\n def __init__(\n self,\n *,\n N : np.ndarray,\n Z : np.ndarray,\n xyz : np.ndarray,\n ):\n\n self.N = N\n self.Z = Z\n self.xyz = xyz\n\n if self.N.shape != (self.natom,): raise RuntimeError('N.shape is not (natom,)')\n if self.Z.shape != (self.natom,): raise RuntimeError('Z.shape is not (natom,)')\n if self.xyz.shape != (self.natom, 3): raise RuntimeError('xyz.shape is not (natom, 3)')\n\n if self.N.dtype != np.uint64: raise RuntimeError('N.dtype is not np.uint64')\n if self.Z.dtype != np.float64: raise RuntimeError('Z.dtype is not np.float64')\n if self.xyz.dtype != np.float64: raise RuntimeError('xyz.dtype is not np.float64')\n\n @property\n def natom(self):\n return len(self.N)\n\n @staticmethod\n def parse_from_xyz_lines(\n lines,\n *,\n bohr_per_ang=UnitConversions.conversions['bohr_per_ang'],\n ):\n \n # Strip fringe blank lines (but not internal blank lines)\n lines = '\\n'.join(lines).strip().split('\\n')\n \n if len(lines) == 0:\n return Molecule(\n N=np.zeros((0,), dtype=np.uint64),\n Z=np.zeros((0,)),\n xyz=np.zeros((0, 3)),\n )\n \n import re\n \n # Natom line \n # (optional, but we enforce natom and length of file if specified)\n mobj = re.match(r'^\\s*(\\d+)\\s*$', lines[0])\n if mobj:\n natom = int(mobj.group(1))\n lines = lines[2:]\n if len(lines) != natom:\n raise RuntimeError('natom line specified %d atoms, but %d lines remain in XYZ file' % (natom, len(lines)))\n \n re_atom_line = re.compile(r'^\\s*(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*$')\n\n Ns = []\n Zs = []\n xyzs = []\n \n for lindex, line in enumerate(lines):\n mobj = re.match(re_atom_line, line)\n if mobj is None:\n raise RuntimeError('Malformed xyz atom line #%d: %s' % (lindex, line))\n \n symbol = mobj.group(1)\n x = float(mobj.group(2))\n y = float(mobj.group(3))\n z = float(mobj.group(4))\n \n x *= bohr_per_ang\n y *= bohr_per_ang\n z *= bohr_per_ang\n \n # NOTE: This does not handle extravagant symbol names like \"Gh(He)\" or \"OXT\" or \"H23\"\n symbol_upper = symbol.upper()\n \n if symbol_upper not in PeriodicTable.symbol_upper_to_N_table:\n raise RuntimeError('Symbol %s is not in periodic table: %s' % (symbol_upper, line))\n \n N = PeriodicTable.symbol_upper_to_N_table[symbol_upper] \n Z = float(N)\n \n Ns.append(N)\n Zs.append(Z)\n xyzs.append((x, y, z))\n \n Ns = np.array(Ns, dtype=np.uint64)\n Zs = np.array(Zs)\n xyzs = np.array(xyzs)\n\n return Molecule(\n N=Ns,\n Z=Zs,\n xyz=xyzs,\n )\n \n @staticmethod\n def parse_from_xyz_string(\n string,\n **kwargs):\n \n return Molecule.parse_from_xyz_lines(lines=string.split('\\n'), **kwargs)\n \n @staticmethod\n def parse_from_xyz_file(\n filename,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return Molecule.parse_from_xyz_lines(lines=lines, **kwargs)","source_hash":"4c1269623d592f1aadae94551dbd607d3533a30782b7f635b6ef29821fcb8628","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.molecule.Molecule","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.molecule.Molecule#L21-L133","kind":"class","name":"Molecule","path":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","language":"python","start_line":21,"end_line":133,"context_start_line":1,"context_end_line":133,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .unit_conversions import UnitConversions\nfrom .periodic_table import PeriodicTable\n\nclass Molecule(object):\n\n def __init__(\n self,\n *,\n N : np.ndarray,\n Z : np.ndarray,\n xyz : np.ndarray,\n ):\n\n self.N = N\n self.Z = Z\n self.xyz = xyz\n\n if self.N.shape != (self.natom,): raise RuntimeError('N.shape is not (natom,)')\n if self.Z.shape != (self.natom,): raise RuntimeError('Z.shape is not (natom,)')\n if self.xyz.shape != (self.natom, 3): raise RuntimeError('xyz.shape is not (natom, 3)')\n\n if self.N.dtype != np.uint64: raise RuntimeError('N.dtype is not np.uint64')\n if self.Z.dtype != np.float64: raise RuntimeError('Z.dtype is not np.float64')\n if self.xyz.dtype != np.float64: raise RuntimeError('xyz.dtype is not np.float64')\n\n @property\n def natom(self):\n return len(self.N)\n\n @staticmethod\n def parse_from_xyz_lines(\n lines,\n *,\n bohr_per_ang=UnitConversions.conversions['bohr_per_ang'],\n ):\n \n # Strip fringe blank lines (but not internal blank lines)\n lines = '\\n'.join(lines).strip().split('\\n')\n \n if len(lines) == 0:\n return Molecule(\n N=np.zeros((0,), dtype=np.uint64),\n Z=np.zeros((0,)),\n xyz=np.zeros((0, 3)),\n )\n \n import re\n \n # Natom line \n # (optional, but we enforce natom and length of file if specified)\n mobj = re.match(r'^\\s*(\\d+)\\s*$', lines[0])\n if mobj:\n natom = int(mobj.group(1))\n lines = lines[2:]\n if len(lines) != natom:\n raise RuntimeError('natom line specified %d atoms, but %d lines remain in XYZ file' % (natom, len(lines)))\n \n re_atom_line = re.compile(r'^\\s*(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*$')\n\n Ns = []\n Zs = []\n xyzs = []\n \n for lindex, line in enumerate(lines):\n mobj = re.match(re_atom_line, line)\n if mobj is None:\n raise RuntimeError('Malformed xyz atom line #%d: %s' % (lindex, line))\n \n symbol = mobj.group(1)\n x = float(mobj.group(2))\n y = float(mobj.group(3))\n z = float(mobj.group(4))\n \n x *= bohr_per_ang\n y *= bohr_per_ang\n z *= bohr_per_ang\n \n # NOTE: This does not handle extravagant symbol names like \"Gh(He)\" or \"OXT\" or \"H23\"\n symbol_upper = symbol.upper()\n \n if symbol_upper not in PeriodicTable.symbol_upper_to_N_table:\n raise RuntimeError('Symbol %s is not in periodic table: %s' % (symbol_upper, line))\n \n N = PeriodicTable.symbol_upper_to_N_table[symbol_upper] \n Z = float(N)\n \n Ns.append(N)\n Zs.append(Z)\n xyzs.append((x, y, z))\n \n Ns = np.array(Ns, dtype=np.uint64)\n Zs = np.array(Zs)\n xyzs = np.array(xyzs)\n\n return Molecule(\n N=Ns,\n Z=Zs,\n xyz=xyzs,\n )\n \n @staticmethod\n def parse_from_xyz_string(\n string,\n **kwargs):\n \n return Molecule.parse_from_xyz_lines(lines=string.split('\\n'), **kwargs)\n \n @staticmethod\n def parse_from_xyz_file(\n filename,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return Molecule.parse_from_xyz_lines(lines=lines, **kwargs)","source_hash":"4c1269623d592f1aadae94551dbd607d3533a30782b7f635b6ef29821fcb8628","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.molecule.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.molecule.__init__#L23-L41","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","language":"python","start_line":23,"end_line":41,"context_start_line":3,"context_end_line":61,"code":"#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .unit_conversions import UnitConversions\nfrom .periodic_table import PeriodicTable\n\nclass Molecule(object):\n\n def __init__(\n self,\n *,\n N : np.ndarray,\n Z : np.ndarray,\n xyz : np.ndarray,\n ):\n\n self.N = N\n self.Z = Z\n self.xyz = xyz\n\n if self.N.shape != (self.natom,): raise RuntimeError('N.shape is not (natom,)')\n if self.Z.shape != (self.natom,): raise RuntimeError('Z.shape is not (natom,)')\n if self.xyz.shape != (self.natom, 3): raise RuntimeError('xyz.shape is not (natom, 3)')\n\n if self.N.dtype != np.uint64: raise RuntimeError('N.dtype is not np.uint64')\n if self.Z.dtype != np.float64: raise RuntimeError('Z.dtype is not np.float64')\n if self.xyz.dtype != np.float64: raise RuntimeError('xyz.dtype is not np.float64')\n\n @property\n def natom(self):\n return len(self.N)\n\n @staticmethod\n def parse_from_xyz_lines(\n lines,\n *,\n bohr_per_ang=UnitConversions.conversions['bohr_per_ang'],\n ):\n \n # Strip fringe blank lines (but not internal blank lines)\n lines = '\\n'.join(lines).strip().split('\\n')\n \n if len(lines) == 0:\n return Molecule(\n N=np.zeros((0,), dtype=np.uint64),\n Z=np.zeros((0,)),\n xyz=np.zeros((0, 3)),","source_hash":"4c1269623d592f1aadae94551dbd607d3533a30782b7f635b6ef29821fcb8628","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.molecule.natom","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.molecule.natom#L44-L45","kind":"function","name":"natom","path":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","language":"python","start_line":44,"end_line":45,"context_start_line":24,"context_end_line":65,"code":" self,\n *,\n N : np.ndarray,\n Z : np.ndarray,\n xyz : np.ndarray,\n ):\n\n self.N = N\n self.Z = Z\n self.xyz = xyz\n\n if self.N.shape != (self.natom,): raise RuntimeError('N.shape is not (natom,)')\n if self.Z.shape != (self.natom,): raise RuntimeError('Z.shape is not (natom,)')\n if self.xyz.shape != (self.natom, 3): raise RuntimeError('xyz.shape is not (natom, 3)')\n\n if self.N.dtype != np.uint64: raise RuntimeError('N.dtype is not np.uint64')\n if self.Z.dtype != np.float64: raise RuntimeError('Z.dtype is not np.float64')\n if self.xyz.dtype != np.float64: raise RuntimeError('xyz.dtype is not np.float64')\n\n @property\n def natom(self):\n return len(self.N)\n\n @staticmethod\n def parse_from_xyz_lines(\n lines,\n *,\n bohr_per_ang=UnitConversions.conversions['bohr_per_ang'],\n ):\n \n # Strip fringe blank lines (but not internal blank lines)\n lines = '\\n'.join(lines).strip().split('\\n')\n \n if len(lines) == 0:\n return Molecule(\n N=np.zeros((0,), dtype=np.uint64),\n Z=np.zeros((0,)),\n xyz=np.zeros((0, 3)),\n )\n \n import re\n ","source_hash":"4c1269623d592f1aadae94551dbd607d3533a30782b7f635b6ef29821fcb8628","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.molecule.parse_from_xyz_lines","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.molecule.parse_from_xyz_lines#L48-L116","kind":"function","name":"parse_from_xyz_lines","path":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","language":"python","start_line":48,"end_line":116,"context_start_line":28,"context_end_line":133,"code":" xyz : np.ndarray,\n ):\n\n self.N = N\n self.Z = Z\n self.xyz = xyz\n\n if self.N.shape != (self.natom,): raise RuntimeError('N.shape is not (natom,)')\n if self.Z.shape != (self.natom,): raise RuntimeError('Z.shape is not (natom,)')\n if self.xyz.shape != (self.natom, 3): raise RuntimeError('xyz.shape is not (natom, 3)')\n\n if self.N.dtype != np.uint64: raise RuntimeError('N.dtype is not np.uint64')\n if self.Z.dtype != np.float64: raise RuntimeError('Z.dtype is not np.float64')\n if self.xyz.dtype != np.float64: raise RuntimeError('xyz.dtype is not np.float64')\n\n @property\n def natom(self):\n return len(self.N)\n\n @staticmethod\n def parse_from_xyz_lines(\n lines,\n *,\n bohr_per_ang=UnitConversions.conversions['bohr_per_ang'],\n ):\n \n # Strip fringe blank lines (but not internal blank lines)\n lines = '\\n'.join(lines).strip().split('\\n')\n \n if len(lines) == 0:\n return Molecule(\n N=np.zeros((0,), dtype=np.uint64),\n Z=np.zeros((0,)),\n xyz=np.zeros((0, 3)),\n )\n \n import re\n \n # Natom line \n # (optional, but we enforce natom and length of file if specified)\n mobj = re.match(r'^\\s*(\\d+)\\s*$', lines[0])\n if mobj:\n natom = int(mobj.group(1))\n lines = lines[2:]\n if len(lines) != natom:\n raise RuntimeError('natom line specified %d atoms, but %d lines remain in XYZ file' % (natom, len(lines)))\n \n re_atom_line = re.compile(r'^\\s*(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*$')\n\n Ns = []\n Zs = []\n xyzs = []\n \n for lindex, line in enumerate(lines):\n mobj = re.match(re_atom_line, line)\n if mobj is None:\n raise RuntimeError('Malformed xyz atom line #%d: %s' % (lindex, line))\n \n symbol = mobj.group(1)\n x = float(mobj.group(2))\n y = float(mobj.group(3))\n z = float(mobj.group(4))\n \n x *= bohr_per_ang\n y *= bohr_per_ang\n z *= bohr_per_ang\n \n # NOTE: This does not handle extravagant symbol names like \"Gh(He)\" or \"OXT\" or \"H23\"\n symbol_upper = symbol.upper()\n \n if symbol_upper not in PeriodicTable.symbol_upper_to_N_table:\n raise RuntimeError('Symbol %s is not in periodic table: %s' % (symbol_upper, line))\n \n N = PeriodicTable.symbol_upper_to_N_table[symbol_upper] \n Z = float(N)\n \n Ns.append(N)\n Zs.append(Z)\n xyzs.append((x, y, z))\n \n Ns = np.array(Ns, dtype=np.uint64)\n Zs = np.array(Zs)\n xyzs = np.array(xyzs)\n\n return Molecule(\n N=Ns,\n Z=Zs,\n xyz=xyzs,\n )\n \n @staticmethod\n def parse_from_xyz_string(\n string,\n **kwargs):\n \n return Molecule.parse_from_xyz_lines(lines=string.split('\\n'), **kwargs)\n \n @staticmethod\n def parse_from_xyz_file(\n filename,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return Molecule.parse_from_xyz_lines(lines=lines, **kwargs)","source_hash":"4c1269623d592f1aadae94551dbd607d3533a30782b7f635b6ef29821fcb8628","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.molecule.parse_from_xyz_string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.molecule.parse_from_xyz_string#L119-L123","kind":"function","name":"parse_from_xyz_string","path":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","language":"python","start_line":119,"end_line":123,"context_start_line":99,"context_end_line":133,"code":" raise RuntimeError('Symbol %s is not in periodic table: %s' % (symbol_upper, line))\n \n N = PeriodicTable.symbol_upper_to_N_table[symbol_upper] \n Z = float(N)\n \n Ns.append(N)\n Zs.append(Z)\n xyzs.append((x, y, z))\n \n Ns = np.array(Ns, dtype=np.uint64)\n Zs = np.array(Zs)\n xyzs = np.array(xyzs)\n\n return Molecule(\n N=Ns,\n Z=Zs,\n xyz=xyzs,\n )\n \n @staticmethod\n def parse_from_xyz_string(\n string,\n **kwargs):\n \n return Molecule.parse_from_xyz_lines(lines=string.split('\\n'), **kwargs)\n \n @staticmethod\n def parse_from_xyz_file(\n filename,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return Molecule.parse_from_xyz_lines(lines=lines, **kwargs)","source_hash":"4c1269623d592f1aadae94551dbd607d3533a30782b7f635b6ef29821fcb8628","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.molecule.parse_from_xyz_file","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.molecule.parse_from_xyz_file#L126-L133","kind":"function","name":"parse_from_xyz_file","path":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","language":"python","start_line":126,"end_line":133,"context_start_line":106,"context_end_line":133,"code":" xyzs.append((x, y, z))\n \n Ns = np.array(Ns, dtype=np.uint64)\n Zs = np.array(Zs)\n xyzs = np.array(xyzs)\n\n return Molecule(\n N=Ns,\n Z=Zs,\n xyz=xyzs,\n )\n \n @staticmethod\n def parse_from_xyz_string(\n string,\n **kwargs):\n \n return Molecule.parse_from_xyz_lines(lines=string.split('\\n'), **kwargs)\n \n @staticmethod\n def parse_from_xyz_file(\n filename,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return Molecule.parse_from_xyz_lines(lines=lines, **kwargs)","source_hash":"4c1269623d592f1aadae94551dbd607d3533a30782b7f635b6ef29821fcb8628","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell#L1-L71","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_shell.py","language":"python","start_line":1,"end_line":71,"context_start_line":1,"context_end_line":71,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .ao_shell import AOShell\n\nfrom .cuest_handle import CuestHandle\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestAOShell(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n ao_shell : AOShell,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n ao_shell_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n )\n\n self.ao_shell_handle = ce.cuestAOShellHandle()\n\n status = ce.cuestAOShellCreate(\n handle=handle.handle,\n isPure=ao_shell.is_pure,\n L=ao_shell.L,\n numPrimitive=ao_shell.nprimitive,\n exponents=ao_shell.exponents,\n coefficients=ao_shell.coefficients,\n parameters=ao_shell_parameters.parameters,\n outShell=self.ao_shell_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOShellCreate failed')\n\n self.initialized = True\n \n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOShellDestroy(\n handle=self.ao_shell_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOShellDestroy failed')\n\n # NOTE: Production codes may want to provide parameter queries here to\n # inspect the contents of the AOShell object","source_hash":"79122d931dbe4de7158ffeea2c9eb72cbe0873a47401a8d5b01a7be68af57798","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell.CuestAOShell","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell.CuestAOShell#L24-L68","kind":"class","name":"CuestAOShell","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_shell.py","language":"python","start_line":24,"end_line":68,"context_start_line":4,"context_end_line":71,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .ao_shell import AOShell\n\nfrom .cuest_handle import CuestHandle\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestAOShell(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n ao_shell : AOShell,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n ao_shell_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n )\n\n self.ao_shell_handle = ce.cuestAOShellHandle()\n\n status = ce.cuestAOShellCreate(\n handle=handle.handle,\n isPure=ao_shell.is_pure,\n L=ao_shell.L,\n numPrimitive=ao_shell.nprimitive,\n exponents=ao_shell.exponents,\n coefficients=ao_shell.coefficients,\n parameters=ao_shell_parameters.parameters,\n outShell=self.ao_shell_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOShellCreate failed')\n\n self.initialized = True\n \n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOShellDestroy(\n handle=self.ao_shell_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOShellDestroy failed')\n\n # NOTE: Production codes may want to provide parameter queries here to\n # inspect the contents of the AOShell object","source_hash":"79122d931dbe4de7158ffeea2c9eb72cbe0873a47401a8d5b01a7be68af57798","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell.__init__#L26-L57","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_shell.py","language":"python","start_line":26,"end_line":57,"context_start_line":6,"context_end_line":71,"code":"# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .ao_shell import AOShell\n\nfrom .cuest_handle import CuestHandle\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestAOShell(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n ao_shell : AOShell,\n ):\n\n self.initialized = False\n\n self.handle = handle\n\n ao_shell_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_AOSHELL_PARAMETERS,\n )\n\n self.ao_shell_handle = ce.cuestAOShellHandle()\n\n status = ce.cuestAOShellCreate(\n handle=handle.handle,\n isPure=ao_shell.is_pure,\n L=ao_shell.L,\n numPrimitive=ao_shell.nprimitive,\n exponents=ao_shell.exponents,\n coefficients=ao_shell.coefficients,\n parameters=ao_shell_parameters.parameters,\n outShell=self.ao_shell_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOShellCreate failed')\n\n self.initialized = True\n \n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOShellDestroy(\n handle=self.ao_shell_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOShellDestroy failed')\n\n # NOTE: Production codes may want to provide parameter queries here to\n # inspect the contents of the AOShell object","source_hash":"79122d931dbe4de7158ffeea2c9eb72cbe0873a47401a8d5b01a7be68af57798","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_ao_shell.__del__#L59-L68","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_shell.py","language":"python","start_line":59,"end_line":68,"context_start_line":39,"context_end_line":71,"code":" )\n\n self.ao_shell_handle = ce.cuestAOShellHandle()\n\n status = ce.cuestAOShellCreate(\n handle=handle.handle,\n isPure=ao_shell.is_pure,\n L=ao_shell.L,\n numPrimitive=ao_shell.nprimitive,\n exponents=ao_shell.exponents,\n coefficients=ao_shell.coefficients,\n parameters=ao_shell_parameters.parameters,\n outShell=self.ao_shell_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOShellCreate failed')\n\n self.initialized = True\n \n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestAOShellDestroy(\n handle=self.ao_shell_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestAOShellDestroy failed')\n\n # NOTE: Production codes may want to provide parameter queries here to\n # inspect the contents of the AOShell object","source_hash":"79122d931dbe4de7158ffeea2c9eb72cbe0873a47401a8d5b01a7be68af57798","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix#L1-L107","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.gpu_matrix","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":1,"end_line":107,"context_start_line":1,"context_end_line":107,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .cuda_utility import CudaUtility\n\nclass GPUMatrix(object):\n\n @staticmethod\n def from_numpy(cpu_array):\n\n assert len(cpu_array.shape) == 2\n matrix = GPUMatrix(\n nrows=cpu_array.shape[0],\n ncols=cpu_array.shape[1],\n dtype=cpu_array.dtype,\n )\n\n CudaUtility.cuda_memcpy_htod(\n device_pointer=matrix.pointer,\n host_pointer=cpu_array.ctypes.data,\n size_in_bytes=matrix.nrows*matrix.ncols*matrix.type_size,\n )\n\n return matrix\n\n @property\n def shape(self):\n return (self.nrows, self.ncols)\n\n def zero(self):\n CudaUtility.cuda_zero_memory(\n device_pointer=self.pointer,\n size_in_bytes=self.size*self.type_size,\n )\n\n def __init__(\n self,\n *,\n nrows,\n ncols,\n dtype=np.double,\n initialize=True,\n ):\n\n self.type_size = np.empty(1, dtype=dtype).itemsize\n self.nrows = nrows\n self.ncols = ncols\n self.dtype = dtype\n self.size = nrows * ncols\n\n self.pointer = CudaUtility.cuda_malloc(\n size_in_bytes=self.size*self.type_size,\n )\n\n if initialize:\n self.zero()\n\n\n def __del__(self):\n if hasattr(self, 'pointer') and self.pointer:\n CudaUtility.cuda_free(pointer=self.pointer)\n\n\n def to_numpy(self):\n cpu_array = np.empty(\n self.shape,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtoh(\n host_pointer=cpu_array.ctypes.data,\n device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return cpu_array\n\n\n def clone(self):\n matrix = GPUMatrix(\n nrows=self.nrows,\n ncols=self.ncols,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtod(\n dst_device_pointer=matrix.pointer,\n src_device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return matrix\n","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.GPUMatrix","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.GPUMatrix#L20-L106","kind":"class","name":"GPUMatrix","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":20,"end_line":106,"context_start_line":1,"context_end_line":107,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .cuda_utility import CudaUtility\n\nclass GPUMatrix(object):\n\n @staticmethod\n def from_numpy(cpu_array):\n\n assert len(cpu_array.shape) == 2\n matrix = GPUMatrix(\n nrows=cpu_array.shape[0],\n ncols=cpu_array.shape[1],\n dtype=cpu_array.dtype,\n )\n\n CudaUtility.cuda_memcpy_htod(\n device_pointer=matrix.pointer,\n host_pointer=cpu_array.ctypes.data,\n size_in_bytes=matrix.nrows*matrix.ncols*matrix.type_size,\n )\n\n return matrix\n\n @property\n def shape(self):\n return (self.nrows, self.ncols)\n\n def zero(self):\n CudaUtility.cuda_zero_memory(\n device_pointer=self.pointer,\n size_in_bytes=self.size*self.type_size,\n )\n\n def __init__(\n self,\n *,\n nrows,\n ncols,\n dtype=np.double,\n initialize=True,\n ):\n\n self.type_size = np.empty(1, dtype=dtype).itemsize\n self.nrows = nrows\n self.ncols = ncols\n self.dtype = dtype\n self.size = nrows * ncols\n\n self.pointer = CudaUtility.cuda_malloc(\n size_in_bytes=self.size*self.type_size,\n )\n\n if initialize:\n self.zero()\n\n\n def __del__(self):\n if hasattr(self, 'pointer') and self.pointer:\n CudaUtility.cuda_free(pointer=self.pointer)\n\n\n def to_numpy(self):\n cpu_array = np.empty(\n self.shape,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtoh(\n host_pointer=cpu_array.ctypes.data,\n device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return cpu_array\n\n\n def clone(self):\n matrix = GPUMatrix(\n nrows=self.nrows,\n ncols=self.ncols,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtod(\n dst_device_pointer=matrix.pointer,\n src_device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return matrix\n","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.from_numpy","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.from_numpy#L23-L38","kind":"function","name":"from_numpy","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":23,"end_line":38,"context_start_line":3,"context_end_line":58,"code":"#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .cuda_utility import CudaUtility\n\nclass GPUMatrix(object):\n\n @staticmethod\n def from_numpy(cpu_array):\n\n assert len(cpu_array.shape) == 2\n matrix = GPUMatrix(\n nrows=cpu_array.shape[0],\n ncols=cpu_array.shape[1],\n dtype=cpu_array.dtype,\n )\n\n CudaUtility.cuda_memcpy_htod(\n device_pointer=matrix.pointer,\n host_pointer=cpu_array.ctypes.data,\n size_in_bytes=matrix.nrows*matrix.ncols*matrix.type_size,\n )\n\n return matrix\n\n @property\n def shape(self):\n return (self.nrows, self.ncols)\n\n def zero(self):\n CudaUtility.cuda_zero_memory(\n device_pointer=self.pointer,\n size_in_bytes=self.size*self.type_size,\n )\n\n def __init__(\n self,\n *,\n nrows,\n ncols,\n dtype=np.double,\n initialize=True,\n ):\n","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.shape","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.shape#L41-L42","kind":"function","name":"shape","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":41,"end_line":42,"context_start_line":21,"context_end_line":62,"code":"\n @staticmethod\n def from_numpy(cpu_array):\n\n assert len(cpu_array.shape) == 2\n matrix = GPUMatrix(\n nrows=cpu_array.shape[0],\n ncols=cpu_array.shape[1],\n dtype=cpu_array.dtype,\n )\n\n CudaUtility.cuda_memcpy_htod(\n device_pointer=matrix.pointer,\n host_pointer=cpu_array.ctypes.data,\n size_in_bytes=matrix.nrows*matrix.ncols*matrix.type_size,\n )\n\n return matrix\n\n @property\n def shape(self):\n return (self.nrows, self.ncols)\n\n def zero(self):\n CudaUtility.cuda_zero_memory(\n device_pointer=self.pointer,\n size_in_bytes=self.size*self.type_size,\n )\n\n def __init__(\n self,\n *,\n nrows,\n ncols,\n dtype=np.double,\n initialize=True,\n ):\n\n self.type_size = np.empty(1, dtype=dtype).itemsize\n self.nrows = nrows\n self.ncols = ncols\n self.dtype = dtype","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.zero","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.zero#L44-L48","kind":"function","name":"zero","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":44,"end_line":48,"context_start_line":24,"context_end_line":68,"code":"\n assert len(cpu_array.shape) == 2\n matrix = GPUMatrix(\n nrows=cpu_array.shape[0],\n ncols=cpu_array.shape[1],\n dtype=cpu_array.dtype,\n )\n\n CudaUtility.cuda_memcpy_htod(\n device_pointer=matrix.pointer,\n host_pointer=cpu_array.ctypes.data,\n size_in_bytes=matrix.nrows*matrix.ncols*matrix.type_size,\n )\n\n return matrix\n\n @property\n def shape(self):\n return (self.nrows, self.ncols)\n\n def zero(self):\n CudaUtility.cuda_zero_memory(\n device_pointer=self.pointer,\n size_in_bytes=self.size*self.type_size,\n )\n\n def __init__(\n self,\n *,\n nrows,\n ncols,\n dtype=np.double,\n initialize=True,\n ):\n\n self.type_size = np.empty(1, dtype=dtype).itemsize\n self.nrows = nrows\n self.ncols = ncols\n self.dtype = dtype\n self.size = nrows * ncols\n\n self.pointer = CudaUtility.cuda_malloc(\n size_in_bytes=self.size*self.type_size,\n )\n","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.__init__#L50-L70","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":50,"end_line":70,"context_start_line":30,"context_end_line":90,"code":" )\n\n CudaUtility.cuda_memcpy_htod(\n device_pointer=matrix.pointer,\n host_pointer=cpu_array.ctypes.data,\n size_in_bytes=matrix.nrows*matrix.ncols*matrix.type_size,\n )\n\n return matrix\n\n @property\n def shape(self):\n return (self.nrows, self.ncols)\n\n def zero(self):\n CudaUtility.cuda_zero_memory(\n device_pointer=self.pointer,\n size_in_bytes=self.size*self.type_size,\n )\n\n def __init__(\n self,\n *,\n nrows,\n ncols,\n dtype=np.double,\n initialize=True,\n ):\n\n self.type_size = np.empty(1, dtype=dtype).itemsize\n self.nrows = nrows\n self.ncols = ncols\n self.dtype = dtype\n self.size = nrows * ncols\n\n self.pointer = CudaUtility.cuda_malloc(\n size_in_bytes=self.size*self.type_size,\n )\n\n if initialize:\n self.zero()\n\n\n def __del__(self):\n if hasattr(self, 'pointer') and self.pointer:\n CudaUtility.cuda_free(pointer=self.pointer)\n\n\n def to_numpy(self):\n cpu_array = np.empty(\n self.shape,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtoh(\n host_pointer=cpu_array.ctypes.data,\n device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return cpu_array","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.__del__#L73-L75","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":73,"end_line":75,"context_start_line":53,"context_end_line":95,"code":" nrows,\n ncols,\n dtype=np.double,\n initialize=True,\n ):\n\n self.type_size = np.empty(1, dtype=dtype).itemsize\n self.nrows = nrows\n self.ncols = ncols\n self.dtype = dtype\n self.size = nrows * ncols\n\n self.pointer = CudaUtility.cuda_malloc(\n size_in_bytes=self.size*self.type_size,\n )\n\n if initialize:\n self.zero()\n\n\n def __del__(self):\n if hasattr(self, 'pointer') and self.pointer:\n CudaUtility.cuda_free(pointer=self.pointer)\n\n\n def to_numpy(self):\n cpu_array = np.empty(\n self.shape,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtoh(\n host_pointer=cpu_array.ctypes.data,\n device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return cpu_array\n\n\n def clone(self):\n matrix = GPUMatrix(\n nrows=self.nrows,","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.to_numpy","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.to_numpy#L78-L90","kind":"function","name":"to_numpy","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":78,"end_line":90,"context_start_line":58,"context_end_line":107,"code":"\n self.type_size = np.empty(1, dtype=dtype).itemsize\n self.nrows = nrows\n self.ncols = ncols\n self.dtype = dtype\n self.size = nrows * ncols\n\n self.pointer = CudaUtility.cuda_malloc(\n size_in_bytes=self.size*self.type_size,\n )\n\n if initialize:\n self.zero()\n\n\n def __del__(self):\n if hasattr(self, 'pointer') and self.pointer:\n CudaUtility.cuda_free(pointer=self.pointer)\n\n\n def to_numpy(self):\n cpu_array = np.empty(\n self.shape,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtoh(\n host_pointer=cpu_array.ctypes.data,\n device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return cpu_array\n\n\n def clone(self):\n matrix = GPUMatrix(\n nrows=self.nrows,\n ncols=self.ncols,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtod(\n dst_device_pointer=matrix.pointer,\n src_device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return matrix\n","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.clone","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.gpu_matrix.clone#L93-L106","kind":"function","name":"clone","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":93,"end_line":106,"context_start_line":73,"context_end_line":107,"code":" def __del__(self):\n if hasattr(self, 'pointer') and self.pointer:\n CudaUtility.cuda_free(pointer=self.pointer)\n\n\n def to_numpy(self):\n cpu_array = np.empty(\n self.shape,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtoh(\n host_pointer=cpu_array.ctypes.data,\n device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return cpu_array\n\n\n def clone(self):\n matrix = GPUMatrix(\n nrows=self.nrows,\n ncols=self.ncols,\n dtype=self.dtype,\n )\n\n CudaUtility.cuda_memcpy_dtod(\n dst_device_pointer=matrix.pointer,\n src_device_pointer=self.pointer,\n size_in_bytes=self.nrows*self.ncols*self.type_size,\n )\n\n return matrix\n","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.sad_guess#L1-L140","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.sad_guess","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":1,"end_line":140,"context_start_line":1,"context_end_line":140,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np \n\nfrom .molecule import Molecule \nfrom .ao_basis import AOBasis\nfrom .sad_atom_structure import SADAtomStructure\nfrom .sad_guess_atom import SADGuessAtom\n\nfrom .memoized_property import memoized_property\n\nclass SADGuess(object):\n\n def __init__(\n self,\n *,\n sad_guess_atoms : list,\n ):\n\n self.sad_guess_atoms = sad_guess_atoms\n\n if not all(isinstance(_, SADGuessAtom) for _ in sad_guess_atoms): raise RuntimeError('sad_guess_atoms is not list of SADGuessAtom')\n\n @property\n def natom(self):\n return len(self.sad_guess_atoms)\n\n @memoized_property\n def primary(self):\n return AOBasis.concatenate(_.primary for _ in self.sad_guess_atoms)\n\n @memoized_property\n def minao(self):\n return AOBasis.concatenate(_.minao for _ in self.sad_guess_atoms)\n\n def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C\n Focc2 = np.einsum('i,ip->ip', np.sqrt(nocc2), Cocc2)\n nprimary = sad_guess_atom.primary.nao\n nminao = sad_guess_atom.minao.nao\n Cocc[minao_start:minao_start+nminao, primary_start:primary_start+nprimary] = Focc2\n primary_start += nprimary\n minao_start += nminao\n return Cocc\n\n def compute_Docc(self):\n Cocc = self.compute_Cocc()\n return np.dot(Cocc.T, Cocc)\n\n @staticmethod\n def build(\n *,\n molecule : Molecule,\n primary : AOBasis,\n minao : AOBasis,\n ):\n\n if primary.natom != molecule.natom: raise RuntimeError('primary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n unique_sad_guess_atoms = {}\n\n structures = [SADAtomStructure.build(N=N) for N in molecule.N]\n primary_atoms = primary.atomize()\n minao_atoms = minao.atomize()\n\n for N, structure, primary_atom, minao_atom in zip(molecule.N, structures, primary_atoms, minao_atoms):\n if N not in unique_sad_guess_atoms:\n minao_atom2 = SADGuess.reorder_minao(\n minao=minao_atom,\n structure=structure,\n )\n unique_sad_guess_atoms[N] = SADGuessAtom(\n primary=primary_atom,\n minao=minao_atom2,\n structure=structure,\n )\n\n return SADGuess(\n sad_guess_atoms=[unique_sad_guess_atoms[N] for N in molecule.N],\n )\n \n \"\"\"\n Sometimes a GBS file is ordered in its own way, which does not correspond\n to the order of inactive and active shells in SADAtomStructure. E.g., an\n element like S might have its MINAO basis file ordered as 1s2s3s2p3p but\n the SADAtomStructure order is [1s2s2p][3s3p]. This function provides a sort\n of sheep and goats shuffle to transform a 1-atom AOBasis object to another\n 1-atom AOBasis object with the order of structure, if this is topologically\n possible.\n \"\"\"\n @staticmethod\n def reorder_minao(\n *,\n minao : AOBasis,\n structure : SADAtomStructure,\n ):\n\n if minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if list(sorted(shell.L for shell in minao.shells[0])) != list(sorted(structure.Ls)):\n raise RuntimeError('minao and structure do not have topological agreement on L structure. N = %d' % (structure.N))\n\n back_map = {}\n Ns = [0 for L in range(minao.max_L+1)] \n index = 0\n for shell in minao.shells[0]:\n L = shell.L\n N = Ns[L]\n back_map[N, L] = index\n Ns[L] += 1\n index += 1\n\n shells = []\n Ns = [0 for L in range(minao.max_L+1)] \n for L in structure.Ls:\n N = Ns[L]\n index = back_map[N, L]\n shells.append(minao.shells[0][index].clone())\n Ns[L] += 1\n\n return AOBasis(shells=[shells])","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.SADGuess","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.sad_guess.SADGuess#L25-L140","kind":"class","name":"SADGuess","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":25,"end_line":140,"context_start_line":5,"context_end_line":140,"code":"# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np \n\nfrom .molecule import Molecule \nfrom .ao_basis import AOBasis\nfrom .sad_atom_structure import SADAtomStructure\nfrom .sad_guess_atom import SADGuessAtom\n\nfrom .memoized_property import memoized_property\n\nclass SADGuess(object):\n\n def __init__(\n self,\n *,\n sad_guess_atoms : list,\n ):\n\n self.sad_guess_atoms = sad_guess_atoms\n\n if not all(isinstance(_, SADGuessAtom) for _ in sad_guess_atoms): raise RuntimeError('sad_guess_atoms is not list of SADGuessAtom')\n\n @property\n def natom(self):\n return len(self.sad_guess_atoms)\n\n @memoized_property\n def primary(self):\n return AOBasis.concatenate(_.primary for _ in self.sad_guess_atoms)\n\n @memoized_property\n def minao(self):\n return AOBasis.concatenate(_.minao for _ in self.sad_guess_atoms)\n\n def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C\n Focc2 = np.einsum('i,ip->ip', np.sqrt(nocc2), Cocc2)\n nprimary = sad_guess_atom.primary.nao\n nminao = sad_guess_atom.minao.nao\n Cocc[minao_start:minao_start+nminao, primary_start:primary_start+nprimary] = Focc2\n primary_start += nprimary\n minao_start += nminao\n return Cocc\n\n def compute_Docc(self):\n Cocc = self.compute_Cocc()\n return np.dot(Cocc.T, Cocc)\n\n @staticmethod\n def build(\n *,\n molecule : Molecule,\n primary : AOBasis,\n minao : AOBasis,\n ):\n\n if primary.natom != molecule.natom: raise RuntimeError('primary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n unique_sad_guess_atoms = {}\n\n structures = [SADAtomStructure.build(N=N) for N in molecule.N]\n primary_atoms = primary.atomize()\n minao_atoms = minao.atomize()\n\n for N, structure, primary_atom, minao_atom in zip(molecule.N, structures, primary_atoms, minao_atoms):\n if N not in unique_sad_guess_atoms:\n minao_atom2 = SADGuess.reorder_minao(\n minao=minao_atom,\n structure=structure,\n )\n unique_sad_guess_atoms[N] = SADGuessAtom(\n primary=primary_atom,\n minao=minao_atom2,\n structure=structure,\n )\n\n return SADGuess(\n sad_guess_atoms=[unique_sad_guess_atoms[N] for N in molecule.N],\n )\n \n \"\"\"\n Sometimes a GBS file is ordered in its own way, which does not correspond\n to the order of inactive and active shells in SADAtomStructure. E.g., an\n element like S might have its MINAO basis file ordered as 1s2s3s2p3p but\n the SADAtomStructure order is [1s2s2p][3s3p]. This function provides a sort\n of sheep and goats shuffle to transform a 1-atom AOBasis object to another\n 1-atom AOBasis object with the order of structure, if this is topologically\n possible.\n \"\"\"\n @staticmethod\n def reorder_minao(\n *,\n minao : AOBasis,\n structure : SADAtomStructure,\n ):\n\n if minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if list(sorted(shell.L for shell in minao.shells[0])) != list(sorted(structure.Ls)):\n raise RuntimeError('minao and structure do not have topological agreement on L structure. N = %d' % (structure.N))\n\n back_map = {}\n Ns = [0 for L in range(minao.max_L+1)] \n index = 0\n for shell in minao.shells[0]:\n L = shell.L\n N = Ns[L]\n back_map[N, L] = index\n Ns[L] += 1\n index += 1\n\n shells = []\n Ns = [0 for L in range(minao.max_L+1)] \n for L in structure.Ls:\n N = Ns[L]\n index = back_map[N, L]\n shells.append(minao.shells[0][index].clone())\n Ns[L] += 1\n\n return AOBasis(shells=[shells])","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess.__init__#L27-L35","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":27,"end_line":35,"context_start_line":7,"context_end_line":55,"code":"#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np \n\nfrom .molecule import Molecule \nfrom .ao_basis import AOBasis\nfrom .sad_atom_structure import SADAtomStructure\nfrom .sad_guess_atom import SADGuessAtom\n\nfrom .memoized_property import memoized_property\n\nclass SADGuess(object):\n\n def __init__(\n self,\n *,\n sad_guess_atoms : list,\n ):\n\n self.sad_guess_atoms = sad_guess_atoms\n\n if not all(isinstance(_, SADGuessAtom) for _ in sad_guess_atoms): raise RuntimeError('sad_guess_atoms is not list of SADGuessAtom')\n\n @property\n def natom(self):\n return len(self.sad_guess_atoms)\n\n @memoized_property\n def primary(self):\n return AOBasis.concatenate(_.primary for _ in self.sad_guess_atoms)\n\n @memoized_property\n def minao(self):\n return AOBasis.concatenate(_.minao for _ in self.sad_guess_atoms)\n\n def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.natom","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess.natom#L38-L39","kind":"function","name":"natom","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":38,"end_line":39,"context_start_line":18,"context_end_line":59,"code":"from .molecule import Molecule \nfrom .ao_basis import AOBasis\nfrom .sad_atom_structure import SADAtomStructure\nfrom .sad_guess_atom import SADGuessAtom\n\nfrom .memoized_property import memoized_property\n\nclass SADGuess(object):\n\n def __init__(\n self,\n *,\n sad_guess_atoms : list,\n ):\n\n self.sad_guess_atoms = sad_guess_atoms\n\n if not all(isinstance(_, SADGuessAtom) for _ in sad_guess_atoms): raise RuntimeError('sad_guess_atoms is not list of SADGuessAtom')\n\n @property\n def natom(self):\n return len(self.sad_guess_atoms)\n\n @memoized_property\n def primary(self):\n return AOBasis.concatenate(_.primary for _ in self.sad_guess_atoms)\n\n @memoized_property\n def minao(self):\n return AOBasis.concatenate(_.minao for _ in self.sad_guess_atoms)\n\n def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C\n Focc2 = np.einsum('i,ip->ip', np.sqrt(nocc2), Cocc2)\n nprimary = sad_guess_atom.primary.nao\n nminao = sad_guess_atom.minao.nao\n Cocc[minao_start:minao_start+nminao, primary_start:primary_start+nprimary] = Focc2","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.primary","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess.primary#L42-L43","kind":"function","name":"primary","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":42,"end_line":43,"context_start_line":22,"context_end_line":63,"code":"\nfrom .memoized_property import memoized_property\n\nclass SADGuess(object):\n\n def __init__(\n self,\n *,\n sad_guess_atoms : list,\n ):\n\n self.sad_guess_atoms = sad_guess_atoms\n\n if not all(isinstance(_, SADGuessAtom) for _ in sad_guess_atoms): raise RuntimeError('sad_guess_atoms is not list of SADGuessAtom')\n\n @property\n def natom(self):\n return len(self.sad_guess_atoms)\n\n @memoized_property\n def primary(self):\n return AOBasis.concatenate(_.primary for _ in self.sad_guess_atoms)\n\n @memoized_property\n def minao(self):\n return AOBasis.concatenate(_.minao for _ in self.sad_guess_atoms)\n\n def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C\n Focc2 = np.einsum('i,ip->ip', np.sqrt(nocc2), Cocc2)\n nprimary = sad_guess_atom.primary.nao\n nminao = sad_guess_atom.minao.nao\n Cocc[minao_start:minao_start+nminao, primary_start:primary_start+nprimary] = Focc2\n primary_start += nprimary\n minao_start += nminao\n return Cocc\n","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.minao","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess.minao#L46-L47","kind":"function","name":"minao","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":46,"end_line":47,"context_start_line":26,"context_end_line":67,"code":"\n def __init__(\n self,\n *,\n sad_guess_atoms : list,\n ):\n\n self.sad_guess_atoms = sad_guess_atoms\n\n if not all(isinstance(_, SADGuessAtom) for _ in sad_guess_atoms): raise RuntimeError('sad_guess_atoms is not list of SADGuessAtom')\n\n @property\n def natom(self):\n return len(self.sad_guess_atoms)\n\n @memoized_property\n def primary(self):\n return AOBasis.concatenate(_.primary for _ in self.sad_guess_atoms)\n\n @memoized_property\n def minao(self):\n return AOBasis.concatenate(_.minao for _ in self.sad_guess_atoms)\n\n def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C\n Focc2 = np.einsum('i,ip->ip', np.sqrt(nocc2), Cocc2)\n nprimary = sad_guess_atom.primary.nao\n nminao = sad_guess_atom.minao.nao\n Cocc[minao_start:minao_start+nminao, primary_start:primary_start+nprimary] = Focc2\n primary_start += nprimary\n minao_start += nminao\n return Cocc\n\n def compute_Docc(self):\n Cocc = self.compute_Cocc()\n return np.dot(Cocc.T, Cocc)\n","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.compute_Cocc","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess.compute_Cocc#L49-L62","kind":"function","name":"compute_Cocc","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":49,"end_line":62,"context_start_line":29,"context_end_line":82,"code":" *,\n sad_guess_atoms : list,\n ):\n\n self.sad_guess_atoms = sad_guess_atoms\n\n if not all(isinstance(_, SADGuessAtom) for _ in sad_guess_atoms): raise RuntimeError('sad_guess_atoms is not list of SADGuessAtom')\n\n @property\n def natom(self):\n return len(self.sad_guess_atoms)\n\n @memoized_property\n def primary(self):\n return AOBasis.concatenate(_.primary for _ in self.sad_guess_atoms)\n\n @memoized_property\n def minao(self):\n return AOBasis.concatenate(_.minao for _ in self.sad_guess_atoms)\n\n def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C\n Focc2 = np.einsum('i,ip->ip', np.sqrt(nocc2), Cocc2)\n nprimary = sad_guess_atom.primary.nao\n nminao = sad_guess_atom.minao.nao\n Cocc[minao_start:minao_start+nminao, primary_start:primary_start+nprimary] = Focc2\n primary_start += nprimary\n minao_start += nminao\n return Cocc\n\n def compute_Docc(self):\n Cocc = self.compute_Cocc()\n return np.dot(Cocc.T, Cocc)\n\n @staticmethod\n def build(\n *,\n molecule : Molecule,\n primary : AOBasis,\n minao : AOBasis,\n ):\n\n if primary.natom != molecule.natom: raise RuntimeError('primary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n unique_sad_guess_atoms = {}\n\n structures = [SADAtomStructure.build(N=N) for N in molecule.N]\n primary_atoms = primary.atomize()","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.compute_Docc","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess.compute_Docc#L64-L66","kind":"function","name":"compute_Docc","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":64,"end_line":66,"context_start_line":44,"context_end_line":86,"code":"\n @memoized_property\n def minao(self):\n return AOBasis.concatenate(_.minao for _ in self.sad_guess_atoms)\n\n def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C\n Focc2 = np.einsum('i,ip->ip', np.sqrt(nocc2), Cocc2)\n nprimary = sad_guess_atom.primary.nao\n nminao = sad_guess_atom.minao.nao\n Cocc[minao_start:minao_start+nminao, primary_start:primary_start+nprimary] = Focc2\n primary_start += nprimary\n minao_start += nminao\n return Cocc\n\n def compute_Docc(self):\n Cocc = self.compute_Cocc()\n return np.dot(Cocc.T, Cocc)\n\n @staticmethod\n def build(\n *,\n molecule : Molecule,\n primary : AOBasis,\n minao : AOBasis,\n ):\n\n if primary.natom != molecule.natom: raise RuntimeError('primary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n unique_sad_guess_atoms = {}\n\n structures = [SADAtomStructure.build(N=N) for N in molecule.N]\n primary_atoms = primary.atomize()\n minao_atoms = minao.atomize()\n\n for N, structure, primary_atom, minao_atom in zip(molecule.N, structures, primary_atoms, minao_atoms):\n if N not in unique_sad_guess_atoms:","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.build","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess.build#L69-L99","kind":"function","name":"build","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":69,"end_line":99,"context_start_line":49,"context_end_line":119,"code":" def compute_Cocc(self):\n Cocc = np.zeros((self.minao.nao, self.primary.nao))\n primary_start = 0\n minao_start = 0\n for A, sad_guess_atom in enumerate(self.sad_guess_atoms):\n nocc2 = sad_guess_atom.structure.nocc\n Cocc2 = sad_guess_atom.C\n Focc2 = np.einsum('i,ip->ip', np.sqrt(nocc2), Cocc2)\n nprimary = sad_guess_atom.primary.nao\n nminao = sad_guess_atom.minao.nao\n Cocc[minao_start:minao_start+nminao, primary_start:primary_start+nprimary] = Focc2\n primary_start += nprimary\n minao_start += nminao\n return Cocc\n\n def compute_Docc(self):\n Cocc = self.compute_Cocc()\n return np.dot(Cocc.T, Cocc)\n\n @staticmethod\n def build(\n *,\n molecule : Molecule,\n primary : AOBasis,\n minao : AOBasis,\n ):\n\n if primary.natom != molecule.natom: raise RuntimeError('primary.natom != molecule.natom')\n if minao.natom != molecule.natom: raise RuntimeError('minao.natom != molecule.natom')\n\n unique_sad_guess_atoms = {}\n\n structures = [SADAtomStructure.build(N=N) for N in molecule.N]\n primary_atoms = primary.atomize()\n minao_atoms = minao.atomize()\n\n for N, structure, primary_atom, minao_atom in zip(molecule.N, structures, primary_atoms, minao_atoms):\n if N not in unique_sad_guess_atoms:\n minao_atom2 = SADGuess.reorder_minao(\n minao=minao_atom,\n structure=structure,\n )\n unique_sad_guess_atoms[N] = SADGuessAtom(\n primary=primary_atom,\n minao=minao_atom2,\n structure=structure,\n )\n\n return SADGuess(\n sad_guess_atoms=[unique_sad_guess_atoms[N] for N in molecule.N],\n )\n \n \"\"\"\n Sometimes a GBS file is ordered in its own way, which does not correspond\n to the order of inactive and active shells in SADAtomStructure. E.g., an\n element like S might have its MINAO basis file ordered as 1s2s3s2p3p but\n the SADAtomStructure order is [1s2s2p][3s3p]. This function provides a sort\n of sheep and goats shuffle to transform a 1-atom AOBasis object to another\n 1-atom AOBasis object with the order of structure, if this is topologically\n possible.\n \"\"\"\n @staticmethod\n def reorder_minao(\n *,\n minao : AOBasis,\n structure : SADAtomStructure,\n ):\n\n if minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if list(sorted(shell.L for shell in minao.shells[0])) != list(sorted(structure.Ls)):","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess.reorder_minao","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess.reorder_minao#L111-L140","kind":"function","name":"reorder_minao","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":111,"end_line":140,"context_start_line":91,"context_end_line":140,"code":" unique_sad_guess_atoms[N] = SADGuessAtom(\n primary=primary_atom,\n minao=minao_atom2,\n structure=structure,\n )\n\n return SADGuess(\n sad_guess_atoms=[unique_sad_guess_atoms[N] for N in molecule.N],\n )\n \n \"\"\"\n Sometimes a GBS file is ordered in its own way, which does not correspond\n to the order of inactive and active shells in SADAtomStructure. E.g., an\n element like S might have its MINAO basis file ordered as 1s2s3s2p3p but\n the SADAtomStructure order is [1s2s2p][3s3p]. This function provides a sort\n of sheep and goats shuffle to transform a 1-atom AOBasis object to another\n 1-atom AOBasis object with the order of structure, if this is topologically\n possible.\n \"\"\"\n @staticmethod\n def reorder_minao(\n *,\n minao : AOBasis,\n structure : SADAtomStructure,\n ):\n\n if minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if list(sorted(shell.L for shell in minao.shells[0])) != list(sorted(structure.Ls)):\n raise RuntimeError('minao and structure do not have topological agreement on L structure. N = %d' % (structure.N))\n\n back_map = {}\n Ns = [0 for L in range(minao.max_L+1)] \n index = 0\n for shell in minao.shells[0]:\n L = shell.L\n N = Ns[L]\n back_map[N, L] = index\n Ns[L] += 1\n index += 1\n\n shells = []\n Ns = [0 for L in range(minao.max_L+1)] \n for L in structure.Ls:\n N = Ns[L]\n index = back_map[N, L]\n shells.append(minao.shells[0][index].clone())\n Ns[L] += 1\n\n return AOBasis(shells=[shells])","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.ao_shell#L1-L145","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.ao_shell","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":1,"end_line":145,"context_start_line":1,"context_end_line":145,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n \nclass AOShell(object):\n\n def __init__(\n self,\n *,\n is_pure : bool, \n L : int,\n exponents : np.ndarray,\n coefficients : np.ndarray,\n ):\n\n self.is_pure = is_pure\n self.L = L\n self.exponents = exponents\n self.coefficients = coefficients\n\n if exponents.shape != (self.nprimitive,): raise RuntimeError('exponents.shape != (nprimitive,)')\n if coefficients.shape != (self.nprimitive,): raise RuntimeError('coefficients.shape != (nprimitive,)')\n\n if L < 0: raise RuntimeError('L < 0')\n\n @property\n def nprimitive(self):\n return len(self.exponents)\n \n @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_cart(self):\n return AOShell(\n is_pure=False,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def __eq__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return False\n if self.nprimitive != other.nprimitive: return False\n if self.is_pure != other.is_pure: return False\n if any(self.exponents != other.exponents): return False\n if any(self.coefficients != other.coefficients): return False\n return True\n\n def __ne__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return True\n if self.nprimitive != other.nprimitive: return True\n if self.is_pure != other.is_pure: return True\n if any(self.exponents != other.exponents): return True\n if any(self.coefficients != other.coefficients): return True\n return False\n\n @staticmethod\n def compute_normalized_coefficients(\n *,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n\n dfact = 1\n for l in range(1,L+1):\n dfact *= 2*l-1\n\n coefficients = coefficients_raw * np.sqrt(2**L * (2.0 * exponents)**(L + 1.5) / (np.pi**(1.5) * dfact))\n\n V = 0.0\n for k1 in range(len(coefficients)): \n for k2 in range(len(coefficients)):\n V += (np.sqrt(4.0 * exponents[k1] * exponents[k2]) / (exponents[k1] + exponents[k2]))**(L + 1.5) * coefficients_raw[k1] * coefficients_raw[k2]\n\n coefficients *= np.sqrt(normalization / V)\n\n return coefficients\n\n @staticmethod\n def build_from_raw_data(\n *,\n is_pure,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n\n coefficients = AOShell.compute_normalized_coefficients(\n L=L,\n exponents=exponents,\n coefficients_raw=coefficients_raw,\n normalization=normalization,\n )\n\n return AOShell(\n is_pure=is_pure,\n L=L,\n exponents=exponents,\n coefficients=coefficients,\n )","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.AOShell","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.ao_shell.AOShell#L18-L145","kind":"class","name":"AOShell","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":18,"end_line":145,"context_start_line":1,"context_end_line":145,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n \nclass AOShell(object):\n\n def __init__(\n self,\n *,\n is_pure : bool, \n L : int,\n exponents : np.ndarray,\n coefficients : np.ndarray,\n ):\n\n self.is_pure = is_pure\n self.L = L\n self.exponents = exponents\n self.coefficients = coefficients\n\n if exponents.shape != (self.nprimitive,): raise RuntimeError('exponents.shape != (nprimitive,)')\n if coefficients.shape != (self.nprimitive,): raise RuntimeError('coefficients.shape != (nprimitive,)')\n\n if L < 0: raise RuntimeError('L < 0')\n\n @property\n def nprimitive(self):\n return len(self.exponents)\n \n @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_cart(self):\n return AOShell(\n is_pure=False,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def __eq__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return False\n if self.nprimitive != other.nprimitive: return False\n if self.is_pure != other.is_pure: return False\n if any(self.exponents != other.exponents): return False\n if any(self.coefficients != other.coefficients): return False\n return True\n\n def __ne__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return True\n if self.nprimitive != other.nprimitive: return True\n if self.is_pure != other.is_pure: return True\n if any(self.exponents != other.exponents): return True\n if any(self.coefficients != other.coefficients): return True\n return False\n\n @staticmethod\n def compute_normalized_coefficients(\n *,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n\n dfact = 1\n for l in range(1,L+1):\n dfact *= 2*l-1\n\n coefficients = coefficients_raw * np.sqrt(2**L * (2.0 * exponents)**(L + 1.5) / (np.pi**(1.5) * dfact))\n\n V = 0.0\n for k1 in range(len(coefficients)): \n for k2 in range(len(coefficients)):\n V += (np.sqrt(4.0 * exponents[k1] * exponents[k2]) / (exponents[k1] + exponents[k2]))**(L + 1.5) * coefficients_raw[k1] * coefficients_raw[k2]\n\n coefficients *= np.sqrt(normalization / V)\n\n return coefficients\n\n @staticmethod\n def build_from_raw_data(\n *,\n is_pure,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n\n coefficients = AOShell.compute_normalized_coefficients(\n L=L,\n exponents=exponents,\n coefficients_raw=coefficients_raw,\n normalization=normalization,\n )\n\n return AOShell(\n is_pure=is_pure,\n L=L,\n exponents=exponents,\n coefficients=coefficients,\n )","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.__init__#L20-L37","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":20,"end_line":37,"context_start_line":1,"context_end_line":57,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n \nclass AOShell(object):\n\n def __init__(\n self,\n *,\n is_pure : bool, \n L : int,\n exponents : np.ndarray,\n coefficients : np.ndarray,\n ):\n\n self.is_pure = is_pure\n self.L = L\n self.exponents = exponents\n self.coefficients = coefficients\n\n if exponents.shape != (self.nprimitive,): raise RuntimeError('exponents.shape != (nprimitive,)')\n if coefficients.shape != (self.nprimitive,): raise RuntimeError('coefficients.shape != (nprimitive,)')\n\n if L < 0: raise RuntimeError('L < 0')\n\n @property\n def nprimitive(self):\n return len(self.exponents)\n \n @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.nprimitive","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.nprimitive#L40-L41","kind":"function","name":"nprimitive","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":40,"end_line":41,"context_start_line":20,"context_end_line":61,"code":" def __init__(\n self,\n *,\n is_pure : bool, \n L : int,\n exponents : np.ndarray,\n coefficients : np.ndarray,\n ):\n\n self.is_pure = is_pure\n self.L = L\n self.exponents = exponents\n self.coefficients = coefficients\n\n if exponents.shape != (self.nprimitive,): raise RuntimeError('exponents.shape != (nprimitive,)')\n if coefficients.shape != (self.nprimitive,): raise RuntimeError('coefficients.shape != (nprimitive,)')\n\n if L < 0: raise RuntimeError('L < 0')\n\n @property\n def nprimitive(self):\n return len(self.exponents)\n \n @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.npure","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.npure#L44-L45","kind":"function","name":"npure","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":44,"end_line":45,"context_start_line":24,"context_end_line":65,"code":" L : int,\n exponents : np.ndarray,\n coefficients : np.ndarray,\n ):\n\n self.is_pure = is_pure\n self.L = L\n self.exponents = exponents\n self.coefficients = coefficients\n\n if exponents.shape != (self.nprimitive,): raise RuntimeError('exponents.shape != (nprimitive,)')\n if coefficients.shape != (self.nprimitive,): raise RuntimeError('coefficients.shape != (nprimitive,)')\n\n if L < 0: raise RuntimeError('L < 0')\n\n @property\n def nprimitive(self):\n return len(self.exponents)\n \n @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.ncart","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.ncart#L48-L49","kind":"function","name":"ncart","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":48,"end_line":49,"context_start_line":28,"context_end_line":69,"code":"\n self.is_pure = is_pure\n self.L = L\n self.exponents = exponents\n self.coefficients = coefficients\n\n if exponents.shape != (self.nprimitive,): raise RuntimeError('exponents.shape != (nprimitive,)')\n if coefficients.shape != (self.nprimitive,): raise RuntimeError('coefficients.shape != (nprimitive,)')\n\n if L < 0: raise RuntimeError('L < 0')\n\n @property\n def nprimitive(self):\n return len(self.exponents)\n \n @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.nao","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.nao#L52-L53","kind":"function","name":"nao","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":52,"end_line":53,"context_start_line":32,"context_end_line":73,"code":" self.coefficients = coefficients\n\n if exponents.shape != (self.nprimitive,): raise RuntimeError('exponents.shape != (nprimitive,)')\n if coefficients.shape != (self.nprimitive,): raise RuntimeError('coefficients.shape != (nprimitive,)')\n\n if L < 0: raise RuntimeError('L < 0')\n\n @property\n def nprimitive(self):\n return len(self.exponents)\n \n @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_cart(self):\n return AOShell(\n is_pure=False,","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.clone","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.clone#L55-L61","kind":"function","name":"clone","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":55,"end_line":61,"context_start_line":35,"context_end_line":81,"code":" if coefficients.shape != (self.nprimitive,): raise RuntimeError('coefficients.shape != (nprimitive,)')\n\n if L < 0: raise RuntimeError('L < 0')\n\n @property\n def nprimitive(self):\n return len(self.exponents)\n \n @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_cart(self):\n return AOShell(\n is_pure=False,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def __eq__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.update_to_pure","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.update_to_pure#L63-L69","kind":"function","name":"update_to_pure","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":63,"end_line":69,"context_start_line":43,"context_end_line":89,"code":" @property\n def npure(self):\n return 2 * self.L + 1\n\n @property\n def ncart(self):\n return (self.L + 1) * (self.L + 2) // 2\n\n @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_cart(self):\n return AOShell(\n is_pure=False,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def __eq__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return False\n if self.nprimitive != other.nprimitive: return False\n if self.is_pure != other.is_pure: return False\n if any(self.exponents != other.exponents): return False\n if any(self.coefficients != other.coefficients): return False\n return True\n\n def __ne__(self, other):","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.update_to_cart","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.update_to_cart#L71-L77","kind":"function","name":"update_to_cart","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":71,"end_line":77,"context_start_line":51,"context_end_line":97,"code":" @property\n def nao(self):\n return self.npure if self.is_pure else self.ncart\n\n def clone(self):\n return AOShell(\n is_pure=self.is_pure,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_cart(self):\n return AOShell(\n is_pure=False,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def __eq__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return False\n if self.nprimitive != other.nprimitive: return False\n if self.is_pure != other.is_pure: return False\n if any(self.exponents != other.exponents): return False\n if any(self.coefficients != other.coefficients): return False\n return True\n\n def __ne__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return True\n if self.nprimitive != other.nprimitive: return True\n if self.is_pure != other.is_pure: return True\n if any(self.exponents != other.exponents): return True\n if any(self.coefficients != other.coefficients): return True\n return False","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.__eq__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.__eq__#L79-L87","kind":"function","name":"__eq__","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":79,"end_line":87,"context_start_line":59,"context_end_line":107,"code":" exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_pure(self):\n return AOShell(\n is_pure=True,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def update_to_cart(self):\n return AOShell(\n is_pure=False,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def __eq__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return False\n if self.nprimitive != other.nprimitive: return False\n if self.is_pure != other.is_pure: return False\n if any(self.exponents != other.exponents): return False\n if any(self.coefficients != other.coefficients): return False\n return True\n\n def __ne__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return True\n if self.nprimitive != other.nprimitive: return True\n if self.is_pure != other.is_pure: return True\n if any(self.exponents != other.exponents): return True\n if any(self.coefficients != other.coefficients): return True\n return False\n\n @staticmethod\n def compute_normalized_coefficients(\n *,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.__ne__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.__ne__#L89-L97","kind":"function","name":"__ne__","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":89,"end_line":97,"context_start_line":69,"context_end_line":117,"code":" )\n\n def update_to_cart(self):\n return AOShell(\n is_pure=False,\n L=self.L,\n exponents=self.exponents.copy(),\n coefficients=self.coefficients.copy(),\n )\n\n def __eq__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return False\n if self.nprimitive != other.nprimitive: return False\n if self.is_pure != other.is_pure: return False\n if any(self.exponents != other.exponents): return False\n if any(self.coefficients != other.coefficients): return False\n return True\n\n def __ne__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return True\n if self.nprimitive != other.nprimitive: return True\n if self.is_pure != other.is_pure: return True\n if any(self.exponents != other.exponents): return True\n if any(self.coefficients != other.coefficients): return True\n return False\n\n @staticmethod\n def compute_normalized_coefficients(\n *,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n\n dfact = 1\n for l in range(1,L+1):\n dfact *= 2*l-1\n\n coefficients = coefficients_raw * np.sqrt(2**L * (2.0 * exponents)**(L + 1.5) / (np.pi**(1.5) * dfact))\n\n V = 0.0\n for k1 in range(len(coefficients)): \n for k2 in range(len(coefficients)):\n V += (np.sqrt(4.0 * exponents[k1] * exponents[k2]) / (exponents[k1] + exponents[k2]))**(L + 1.5) * coefficients_raw[k1] * coefficients_raw[k2]","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.compute_normalized_coefficients","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.compute_normalized_coefficients#L100-L121","kind":"function","name":"compute_normalized_coefficients","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":100,"end_line":121,"context_start_line":80,"context_end_line":141,"code":" if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return False\n if self.nprimitive != other.nprimitive: return False\n if self.is_pure != other.is_pure: return False\n if any(self.exponents != other.exponents): return False\n if any(self.coefficients != other.coefficients): return False\n return True\n\n def __ne__(self, other):\n if not isinstance(other, AOShell):\n return NotImplemented\n if self.L != other.L: return True\n if self.nprimitive != other.nprimitive: return True\n if self.is_pure != other.is_pure: return True\n if any(self.exponents != other.exponents): return True\n if any(self.coefficients != other.coefficients): return True\n return False\n\n @staticmethod\n def compute_normalized_coefficients(\n *,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n\n dfact = 1\n for l in range(1,L+1):\n dfact *= 2*l-1\n\n coefficients = coefficients_raw * np.sqrt(2**L * (2.0 * exponents)**(L + 1.5) / (np.pi**(1.5) * dfact))\n\n V = 0.0\n for k1 in range(len(coefficients)): \n for k2 in range(len(coefficients)):\n V += (np.sqrt(4.0 * exponents[k1] * exponents[k2]) / (exponents[k1] + exponents[k2]))**(L + 1.5) * coefficients_raw[k1] * coefficients_raw[k2]\n\n coefficients *= np.sqrt(normalization / V)\n\n return coefficients\n\n @staticmethod\n def build_from_raw_data(\n *,\n is_pure,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n\n coefficients = AOShell.compute_normalized_coefficients(\n L=L,\n exponents=exponents,\n coefficients_raw=coefficients_raw,\n normalization=normalization,\n )\n\n return AOShell(\n is_pure=is_pure,","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_shell.build_from_raw_data","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_shell.build_from_raw_data#L124-L145","kind":"function","name":"build_from_raw_data","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":124,"end_line":145,"context_start_line":104,"context_end_line":145,"code":" coefficients_raw,\n normalization=1.0,\n ):\n\n dfact = 1\n for l in range(1,L+1):\n dfact *= 2*l-1\n\n coefficients = coefficients_raw * np.sqrt(2**L * (2.0 * exponents)**(L + 1.5) / (np.pi**(1.5) * dfact))\n\n V = 0.0\n for k1 in range(len(coefficients)): \n for k2 in range(len(coefficients)):\n V += (np.sqrt(4.0 * exponents[k1] * exponents[k2]) / (exponents[k1] + exponents[k2]))**(L + 1.5) * coefficients_raw[k1] * coefficients_raw[k2]\n\n coefficients *= np.sqrt(normalization / V)\n\n return coefficients\n\n @staticmethod\n def build_from_raw_data(\n *,\n is_pure,\n L,\n exponents,\n coefficients_raw,\n normalization=1.0,\n ):\n\n coefficients = AOShell.compute_normalized_coefficients(\n L=L,\n exponents=exponents,\n coefficients_raw=coefficients_raw,\n normalization=normalization,\n )\n\n return AOShell(\n is_pure=is_pure,\n L=L,\n exponents=exponents,\n coefficients=coefficients,\n )","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.ao_basis#L1-L369","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.ao_basis","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":1,"end_line":369,"context_start_line":1,"context_end_line":369,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .periodic_table import PeriodicTable\n\nfrom .ao_shell import AOShell\n\nfrom .memoized_property import memoized_property\n \nclass AOBasis(object):\n\n def __init__( \n self,\n *,\n shells : list,\n ):\n\n self.shells = shells\n\n if not all(isinstance(_, list) for _ in shells): raise RuntimeError('shells is not list of lists')\n if not all(isinstance(_, AOShell) for _ in self.shells_unrolled): raise RuntimeError('shells is not list of list of AOShell')\n\n @memoized_property\n def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'AOBasis:\\n';\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s;\n\n @property\n def detail_string(self):\n s = ''\n s += '%-5s : %7s %2s %5s %5s %5s %10s %10s %10s %10s %10s\\n' % (\n 'shell',\n 'is_pure',\n 'L',\n 'nao',\n 'ncart',\n 'nprim', \n 'ao_start',\n 'cart_start',\n 'prim_start',\n 'atom',\n 'atom_shell',\n )\n P = 0\n for A in range(self.natom):\n for P2 in range(len(self.shells[A])):\n shell = self.shells[A][P2]\n s += '%-5d : %7s %2d %5d %5d %5d %10d %10d %10d %10d %10d\\n' % (\n P,\n shell.is_pure,\n shell.L,\n shell.nao,\n shell.ncart,\n shell.nprimitive,\n self.shell_ao_starts[P],\n self.shell_cart_starts[P],\n self.shell_primitive_starts[P],\n self.shell_atoms[P],\n self.shell_atom_shells[P],\n )\n P += 1\n return s\n\n # => GBS File AOBasis Parsing <= #\n \n angular_momentum_table = {\n 'S' : 0, \n 'P' : 1, \n 'D' : 2, \n 'F' : 3, \n 'G' : 4, \n 'H' : 5, \n 'I' : 6, \n 'K' : 7, \n 'L' : 8, \n 'M' : 9, \n 'N' : 10,\n 'O' : 11,\n 'Q' : 12,\n 'R' : 13,\n 'T' : 14,\n 'U' : 15,\n 'V' : 16,\n 'W' : 17,\n 'X' : 18,\n 'Y' : 19,\n 'Z' : 20,\n }\n\n @staticmethod\n def parse_from_gbs_lines(\n *,\n lines,\n molecule,\n ):\n \n import re\n \n # => Cleaning <= #\n \n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]\n # Strip comment lines out\n re_comment = re.compile(r'\\s*!')\n lines = [_ for _ in lines if not re.match(re_comment, _)]\n # Lines must be nonzero \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n \n # => Spherical / Cartesian Tag Line <= #\n \n mobj = re.match(r'^\\s*(spherical|cartesian)\\s*$', lines[0])\n if mobj is None:\n raise RuntimeError(\"First line of GBS file must be 'spherical' or 'cartesian', instead is: %s\" % lines[0])\n \n if mobj.group(1) == 'spherical':\n is_pure = True\n elif mobj.group(1) == 'cartesian':\n is_pure = False\n else:\n raise RuntimeError('Invalid cartesian/spherical label: %s' % mobj.group(1))\n \n lines = lines[1:]\n \n # => Atom Block Location <= #\n \n re_separator = re.compile(r'\\s*\\*\\*\\*\\*\\s*$')\n separator_indices = [k for k, line in enumerate(lines) if re.match(re_separator, line)]\n if len(separator_indices) == 0: \n raise RuntimeError('No **** separators present')\n if separator_indices[-1] + 1 != len(lines):\n raise RuntimeError('Last line must be ****, instead is: %s' % lines[-1])\n lines = lines[:-1]\n separator_indices = separator_indices[:-1]\n \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n if len(separator_indices) == 0: raise RuntimeError('No **** separators present')\n \n # => Atom IDs and corresponding block index <= #\n \n re_atom_id = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s*$')\n atom_id_lines = [lines[_ + 1] for _ in separator_indices]\n N_index_map = {}\n for index, atom_id_line in enumerate(atom_id_lines):\n mobj = re.match(re_atom_id, atom_id_line)\n if mobj is None:\n raise RuntimeError('Malformed atom ID line: %s' % (atom_id_line))\n symbol = mobj.group(1)\n atom_index = int(mobj.group(2))\n if atom_index != 0: \n raise RuntimeError('\"Symbol 0\" is only allowed atom line - multiple basis sets per atom type in GBS files is not supported by this library')\n symbol_upper = symbol.upper()\n if symbol_upper not in PeriodicTable.symbol_upper_to_N_table:\n raise RuntimeError('Unknown atomic in GBS file symbol: %s' % symbol)\n N = PeriodicTable.symbol_upper_to_N_table[symbol_upper]\n if N in N_index_map:\n raise RuntimeError('Duplicate atomic symbol in GBS file: %s' % symbol)\n N_index_map[N] = index\n \n # => Unique atoms in molecule (will parse only these) <= #\n \n unique_N = list(set(molecule.N[...]))\n \n re_shell_type = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s+(\\S+)\\s*$')\n re_primitive = re.compile(r'^\\s*(\\S+)\\s+(\\S+)\\s*$')\n \n N_to_shells_map = {}\n for N in unique_N:\n if N not in N_index_map:\n raise RuntimeError('N not in GBS file: %d' % (N))\n block_index = N_index_map[N]\n index1 = separator_indices[block_index + 0]\n index2 = separator_indices[block_index + 1] if block_index + 1 < len(separator_indices) else len(lines)\n \n block_lines = lines[index1+2:index2]\n shell_type_indices = [k for k, line in enumerate(block_lines) if re.match(re_shell_type, line)]\n \n shells = []\n for index in shell_type_indices:\n shell_type_line = block_lines[index]\n mobj = re.match(re_shell_type, shell_type_line)\n am_symbol_upper = mobj.group(1).upper()\n if am_symbol_upper not in AOBasis.angular_momentum_table:\n raise RuntimeError('Unknown angular momentum symbol: %s' % am_symbol_upper)\n L = AOBasis.angular_momentum_table[am_symbol_upper]\n nprimitive = int(mobj.group(2))\n normalization = float(mobj.group(3))\n exponents = []\n coefficients_raw = []\n for K in range(nprimitive):\n primitive_line = block_lines[index + 1 + K]\n # Hack to replace D with E for FORTRAN notation\n primitive_line = primitive_line.replace('D', 'E')\n primitive_line = primitive_line.replace('d', 'e')\n mobj = re.match(re_primitive, primitive_line)\n exponents += [float(mobj.group(1))]\n coefficients_raw += [float(mobj.group(2))]\n exponents = np.array(exponents)\n coefficients_raw = np.array(coefficients_raw)\n shells.append(AOShell.build_from_raw_data(\n is_pure=is_pure,\n L=L,\n exponents=exponents,\n coefficients_raw=coefficients_raw,\n normalization=normalization,\n ))\n N_to_shells_map[N] = shells\n \n # => AOBasis <= #\n \n shells = []\n for N in molecule.N:\n shells.append(N_to_shells_map[N])\n \n return AOBasis(\n shells=shells,\n )\n \n @staticmethod\n def parse_from_gbs_string(\n string,\n *,\n molecule,\n **kwargs):\n \n return AOBasis.parse_from_gbs_lines(lines=string.split('\\n'), molecule=molecule, **kwargs) \n \n @staticmethod\n def parse_from_gbs_file(\n filename,\n *,\n molecule,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return AOBasis.parse_from_gbs_lines(\n lines=lines,\n molecule=molecule,\n **kwargs)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.AOBasis","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.ao_basis.AOBasis#L24-L369","kind":"class","name":"AOBasis","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":24,"end_line":369,"context_start_line":4,"context_end_line":369,"code":"# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .periodic_table import PeriodicTable\n\nfrom .ao_shell import AOShell\n\nfrom .memoized_property import memoized_property\n \nclass AOBasis(object):\n\n def __init__( \n self,\n *,\n shells : list,\n ):\n\n self.shells = shells\n\n if not all(isinstance(_, list) for _ in shells): raise RuntimeError('shells is not list of lists')\n if not all(isinstance(_, AOShell) for _ in self.shells_unrolled): raise RuntimeError('shells is not list of list of AOShell')\n\n @memoized_property\n def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'AOBasis:\\n';\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s;\n\n @property\n def detail_string(self):\n s = ''\n s += '%-5s : %7s %2s %5s %5s %5s %10s %10s %10s %10s %10s\\n' % (\n 'shell',\n 'is_pure',\n 'L',\n 'nao',\n 'ncart',\n 'nprim', \n 'ao_start',\n 'cart_start',\n 'prim_start',\n 'atom',\n 'atom_shell',\n )\n P = 0\n for A in range(self.natom):\n for P2 in range(len(self.shells[A])):\n shell = self.shells[A][P2]\n s += '%-5d : %7s %2d %5d %5d %5d %10d %10d %10d %10d %10d\\n' % (\n P,\n shell.is_pure,\n shell.L,\n shell.nao,\n shell.ncart,\n shell.nprimitive,\n self.shell_ao_starts[P],\n self.shell_cart_starts[P],\n self.shell_primitive_starts[P],\n self.shell_atoms[P],\n self.shell_atom_shells[P],\n )\n P += 1\n return s\n\n # => GBS File AOBasis Parsing <= #\n \n angular_momentum_table = {\n 'S' : 0, \n 'P' : 1, \n 'D' : 2, \n 'F' : 3, \n 'G' : 4, \n 'H' : 5, \n 'I' : 6, \n 'K' : 7, \n 'L' : 8, \n 'M' : 9, \n 'N' : 10,\n 'O' : 11,\n 'Q' : 12,\n 'R' : 13,\n 'T' : 14,\n 'U' : 15,\n 'V' : 16,\n 'W' : 17,\n 'X' : 18,\n 'Y' : 19,\n 'Z' : 20,\n }\n\n @staticmethod\n def parse_from_gbs_lines(\n *,\n lines,\n molecule,\n ):\n \n import re\n \n # => Cleaning <= #\n \n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]\n # Strip comment lines out\n re_comment = re.compile(r'\\s*!')\n lines = [_ for _ in lines if not re.match(re_comment, _)]\n # Lines must be nonzero \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n \n # => Spherical / Cartesian Tag Line <= #\n \n mobj = re.match(r'^\\s*(spherical|cartesian)\\s*$', lines[0])\n if mobj is None:\n raise RuntimeError(\"First line of GBS file must be 'spherical' or 'cartesian', instead is: %s\" % lines[0])\n \n if mobj.group(1) == 'spherical':\n is_pure = True\n elif mobj.group(1) == 'cartesian':\n is_pure = False\n else:\n raise RuntimeError('Invalid cartesian/spherical label: %s' % mobj.group(1))\n \n lines = lines[1:]\n \n # => Atom Block Location <= #\n \n re_separator = re.compile(r'\\s*\\*\\*\\*\\*\\s*$')\n separator_indices = [k for k, line in enumerate(lines) if re.match(re_separator, line)]\n if len(separator_indices) == 0: \n raise RuntimeError('No **** separators present')\n if separator_indices[-1] + 1 != len(lines):\n raise RuntimeError('Last line must be ****, instead is: %s' % lines[-1])\n lines = lines[:-1]\n separator_indices = separator_indices[:-1]\n \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n if len(separator_indices) == 0: raise RuntimeError('No **** separators present')\n \n # => Atom IDs and corresponding block index <= #\n \n re_atom_id = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s*$')\n atom_id_lines = [lines[_ + 1] for _ in separator_indices]\n N_index_map = {}\n for index, atom_id_line in enumerate(atom_id_lines):\n mobj = re.match(re_atom_id, atom_id_line)\n if mobj is None:\n raise RuntimeError('Malformed atom ID line: %s' % (atom_id_line))\n symbol = mobj.group(1)\n atom_index = int(mobj.group(2))\n if atom_index != 0: \n raise RuntimeError('\"Symbol 0\" is only allowed atom line - multiple basis sets per atom type in GBS files is not supported by this library')\n symbol_upper = symbol.upper()\n if symbol_upper not in PeriodicTable.symbol_upper_to_N_table:\n raise RuntimeError('Unknown atomic in GBS file symbol: %s' % symbol)\n N = PeriodicTable.symbol_upper_to_N_table[symbol_upper]\n if N in N_index_map:\n raise RuntimeError('Duplicate atomic symbol in GBS file: %s' % symbol)\n N_index_map[N] = index\n \n # => Unique atoms in molecule (will parse only these) <= #\n \n unique_N = list(set(molecule.N[...]))\n \n re_shell_type = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s+(\\S+)\\s*$')\n re_primitive = re.compile(r'^\\s*(\\S+)\\s+(\\S+)\\s*$')\n \n N_to_shells_map = {}\n for N in unique_N:\n if N not in N_index_map:\n raise RuntimeError('N not in GBS file: %d' % (N))\n block_index = N_index_map[N]\n index1 = separator_indices[block_index + 0]\n index2 = separator_indices[block_index + 1] if block_index + 1 < len(separator_indices) else len(lines)\n \n block_lines = lines[index1+2:index2]\n shell_type_indices = [k for k, line in enumerate(block_lines) if re.match(re_shell_type, line)]\n \n shells = []\n for index in shell_type_indices:\n shell_type_line = block_lines[index]\n mobj = re.match(re_shell_type, shell_type_line)\n am_symbol_upper = mobj.group(1).upper()\n if am_symbol_upper not in AOBasis.angular_momentum_table:\n raise RuntimeError('Unknown angular momentum symbol: %s' % am_symbol_upper)\n L = AOBasis.angular_momentum_table[am_symbol_upper]\n nprimitive = int(mobj.group(2))\n normalization = float(mobj.group(3))\n exponents = []\n coefficients_raw = []\n for K in range(nprimitive):\n primitive_line = block_lines[index + 1 + K]\n # Hack to replace D with E for FORTRAN notation\n primitive_line = primitive_line.replace('D', 'E')\n primitive_line = primitive_line.replace('d', 'e')\n mobj = re.match(re_primitive, primitive_line)\n exponents += [float(mobj.group(1))]\n coefficients_raw += [float(mobj.group(2))]\n exponents = np.array(exponents)\n coefficients_raw = np.array(coefficients_raw)\n shells.append(AOShell.build_from_raw_data(\n is_pure=is_pure,\n L=L,\n exponents=exponents,\n coefficients_raw=coefficients_raw,\n normalization=normalization,\n ))\n N_to_shells_map[N] = shells\n \n # => AOBasis <= #\n \n shells = []\n for N in molecule.N:\n shells.append(N_to_shells_map[N])\n \n return AOBasis(\n shells=shells,\n )\n \n @staticmethod\n def parse_from_gbs_string(\n string,\n *,\n molecule,\n **kwargs):\n \n return AOBasis.parse_from_gbs_lines(lines=string.split('\\n'), molecule=molecule, **kwargs) \n \n @staticmethod\n def parse_from_gbs_file(\n filename,\n *,\n molecule,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return AOBasis.parse_from_gbs_lines(\n lines=lines,\n molecule=molecule,\n **kwargs)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.__init__#L26-L35","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":26,"end_line":35,"context_start_line":6,"context_end_line":55,"code":"# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .periodic_table import PeriodicTable\n\nfrom .ao_shell import AOShell\n\nfrom .memoized_property import memoized_property\n \nclass AOBasis(object):\n\n def __init__( \n self,\n *,\n shells : list,\n ):\n\n self.shells = shells\n\n if not all(isinstance(_, list) for _ in shells): raise RuntimeError('shells is not list of lists')\n if not all(isinstance(_, AOShell) for _ in self.shells_unrolled): raise RuntimeError('shells is not list of list of AOShell')\n\n @memoized_property\n def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.is_pure","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.is_pure#L38-L39","kind":"function","name":"is_pure","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":38,"end_line":39,"context_start_line":18,"context_end_line":59,"code":"from .periodic_table import PeriodicTable\n\nfrom .ao_shell import AOShell\n\nfrom .memoized_property import memoized_property\n \nclass AOBasis(object):\n\n def __init__( \n self,\n *,\n shells : list,\n ):\n\n self.shells = shells\n\n if not all(isinstance(_, list) for _ in shells): raise RuntimeError('shells is not list of lists')\n if not all(isinstance(_, AOShell) for _ in self.shells_unrolled): raise RuntimeError('shells is not list of list of AOShell')\n\n @memoized_property\n def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.is_cart","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.is_cart#L42-L43","kind":"function","name":"is_cart","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":42,"end_line":43,"context_start_line":22,"context_end_line":63,"code":"from .memoized_property import memoized_property\n \nclass AOBasis(object):\n\n def __init__( \n self,\n *,\n shells : list,\n ):\n\n self.shells = shells\n\n if not all(isinstance(_, list) for _ in shells): raise RuntimeError('shells is not list of lists')\n if not all(isinstance(_, AOShell) for _ in self.shells_unrolled): raise RuntimeError('shells is not list of list of AOShell')\n\n @memoized_property\n def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.is_mixed","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.is_mixed#L46-L47","kind":"function","name":"is_mixed","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":46,"end_line":47,"context_start_line":26,"context_end_line":67,"code":" def __init__( \n self,\n *,\n shells : list,\n ):\n\n self.shells = shells\n\n if not all(isinstance(_, list) for _ in shells): raise RuntimeError('shells is not list of lists')\n if not all(isinstance(_, AOShell) for _ in self.shells_unrolled): raise RuntimeError('shells is not list of list of AOShell')\n\n @memoized_property\n def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.natom","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.natom#L50-L51","kind":"function","name":"natom","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":50,"end_line":51,"context_start_line":30,"context_end_line":71,"code":" ):\n\n self.shells = shells\n\n if not all(isinstance(_, list) for _ in shells): raise RuntimeError('shells is not list of lists')\n if not all(isinstance(_, AOShell) for _ in self.shells_unrolled): raise RuntimeError('shells is not list of list of AOShell')\n\n @memoized_property\n def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.nshell","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.nshell#L54-L55","kind":"function","name":"nshell","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":54,"end_line":55,"context_start_line":34,"context_end_line":75,"code":" if not all(isinstance(_, list) for _ in shells): raise RuntimeError('shells is not list of lists')\n if not all(isinstance(_, AOShell) for _ in self.shells_unrolled): raise RuntimeError('shells is not list of list of AOShell')\n\n @memoized_property\n def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.nao","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.nao#L58-L59","kind":"function","name":"nao","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":58,"end_line":59,"context_start_line":38,"context_end_line":79,"code":" def is_pure(self):\n return all(_.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.ncart","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.ncart#L62-L63","kind":"function","name":"ncart","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":62,"end_line":63,"context_start_line":42,"context_end_line":83,"code":" def is_cart(self):\n return all(not _.is_pure for _ in self.shells_unrolled)\n\n @memoized_property\n def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.nprimitive","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.nprimitive#L66-L67","kind":"function","name":"nprimitive","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":66,"end_line":67,"context_start_line":46,"context_end_line":87,"code":" def is_mixed(self):\n return (not self.is_pure) and (not self.is_cart)\n\n @memoized_property\n def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.max_L","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.max_L#L70-L71","kind":"function","name":"max_L","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":70,"end_line":71,"context_start_line":50,"context_end_line":91,"code":" def natom(self):\n return len(self.shells)\n\n @memoized_property\n def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.shells_unrolled","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.shells_unrolled#L74-L75","kind":"function","name":"shells_unrolled","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":74,"end_line":75,"context_start_line":54,"context_end_line":95,"code":" def nshell(self):\n return len(self.shells_unrolled)\n\n @memoized_property\n def nao(self):\n return sum(_.nao for _ in self.shells_unrolled)\n\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_ao_starts","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_ao_starts#L80-L82","kind":"function","name":"shell_ao_starts","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":80,"end_line":82,"context_start_line":60,"context_end_line":102,"code":"\n @memoized_property\n def ncart(self):\n return sum(_.ncart for _ in self.shells_unrolled)\n\n @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_cart_starts","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_cart_starts#L85-L87","kind":"function","name":"shell_cart_starts","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":85,"end_line":87,"context_start_line":65,"context_end_line":107,"code":" @memoized_property\n def nprimitive(self):\n return sum(_.nprimitive for _ in self.shells_unrolled)\n\n @memoized_property\n def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_primitive_starts","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_primitive_starts#L90-L92","kind":"function","name":"shell_primitive_starts","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":90,"end_line":92,"context_start_line":70,"context_end_line":112,"code":" def max_L(self):\n return max(_.L for _ in self.shells_unrolled) if self.nshell else 0\n\n @memoized_property\n def shells_unrolled(self):\n return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_atoms","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_atoms#L95-L96","kind":"function","name":"shell_atoms","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":95,"end_line":96,"context_start_line":75,"context_end_line":116,"code":" return [item for sublist in self.shells for item in sublist]\n\n # => Indexing <= #\n\n @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_atom_shells","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.shell_atom_shells#L99-L100","kind":"function","name":"shell_atom_shells","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":99,"end_line":100,"context_start_line":79,"context_end_line":120,"code":" @memoized_property\n def shell_ao_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.update_to_pure","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.update_to_pure#L102-L103","kind":"function","name":"update_to_pure","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":102,"end_line":103,"context_start_line":82,"context_end_line":123,"code":" return [0] + list(np.cumsum([_.nao for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.update_to_cart","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.update_to_cart#L105-L106","kind":"function","name":"update_to_cart","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":105,"end_line":106,"context_start_line":85,"context_end_line":126,"code":" def shell_cart_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.ncart for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.clone","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.clone#L108-L112","kind":"function","name":"clone","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":108,"end_line":112,"context_start_line":88,"context_end_line":132,"code":"\n @memoized_property\n def shell_primitive_starts(self):\n if self.nshell == 0: return []\n return [0] + list(np.cumsum([_.nprimitive for _ in self.shells_unrolled]))[:-1]\n\n @memoized_property\n def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.concatenate","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.concatenate#L115-L119","kind":"function","name":"concatenate","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":115,"end_line":119,"context_start_line":95,"context_end_line":139,"code":" def shell_atoms(self):\n return [item for sublist in [[A]*len(shells2) for A, shells2 in enumerate(self.shells)] for item in sublist]\n\n @memoized_property\n def shell_atom_shells(self):\n return [item for sublist in [list(range(len(shells2))) for shells2 in self.shells] for item in sublist]\n\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.subset","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.subset#L121-L122","kind":"function","name":"subset","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":121,"end_line":122,"context_start_line":101,"context_end_line":142,"code":"\n def update_to_pure(self):\n return AOBasis(shells=[[shell.update_to_pure() for shell in shells2] for shells2 in self.shells])\n\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.atomize","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.atomize#L124-L125","kind":"function","name":"atomize","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":124,"end_line":125,"context_start_line":104,"context_end_line":145,"code":"\n def update_to_cart(self):\n return AOBasis(shells=[[shell.update_to_cart() for shell in shells2] for shells2 in self.shells])\n\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'AOBasis:\\n';","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.__eq__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.__eq__#L127-L130","kind":"function","name":"__eq__","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":127,"end_line":130,"context_start_line":107,"context_end_line":150,"code":"\n def clone(self):\n shells = [] \n for shells2 in self.shells:\n shells.append([_.clone() for _ in shells2])\n return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'AOBasis:\\n';\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.__ne__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.__ne__#L132-L135","kind":"function","name":"__ne__","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":132,"end_line":135,"context_start_line":112,"context_end_line":155,"code":" return AOBasis(shells=shells)\n\n @staticmethod\n def concatenate(bases):\n shells = []\n for basis in bases:\n shells += basis.clone().shells\n return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'AOBasis:\\n';\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s;","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.__str__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.__str__#L139-L140","kind":"function","name":"__str__","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":139,"end_line":140,"context_start_line":119,"context_end_line":160,"code":" return AOBasis(shells=shells)\n\n def subset(self, indices):\n return AOBasis(shells=[[shell.clone() for shell in self.shells[A]] for A in indices])\n\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'AOBasis:\\n';\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s;\n\n @property\n def detail_string(self):\n s = ''\n s += '%-5s : %7s %2s %5s %5s %5s %10s %10s %10s %10s %10s\\n' % (","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.string#L143-L155","kind":"function","name":"string","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":143,"end_line":155,"context_start_line":123,"context_end_line":175,"code":"\n def atomize(self):\n return [self.subset(indices=[A]) for A in range(self.natom)]\n\n def __eq__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled == other.shells_unrolled \n\n def __ne__(self, other):\n if not isinstance(other, AOBasis):\n return NotImplemented\n return self.shells_unrolled != other.shells_unrolled \n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'AOBasis:\\n';\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s;\n\n @property\n def detail_string(self):\n s = ''\n s += '%-5s : %7s %2s %5s %5s %5s %10s %10s %10s %10s %10s\\n' % (\n 'shell',\n 'is_pure',\n 'L',\n 'nao',\n 'ncart',\n 'nprim', \n 'ao_start',\n 'cart_start',\n 'prim_start',\n 'atom',\n 'atom_shell',\n )\n P = 0\n for A in range(self.natom):\n for P2 in range(len(self.shells[A])):","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.detail_string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.detail_string#L158-L191","kind":"function","name":"detail_string","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":158,"end_line":191,"context_start_line":138,"context_end_line":211,"code":"\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'AOBasis:\\n';\n s += '%-10s = %6d\\n' % ('natom', self.natom)\n s += '%-10s = %6d\\n' % ('nshell', self.nshell)\n s += '%-10s = %6d\\n' % ('nao', self.nao)\n s += '%-10s = %6d\\n' % ('ncart', self.ncart)\n s += '%-10s = %6d\\n' % ('nprimitive', self.nprimitive)\n s += '%-10s = %6d\\n' % ('max_L', self.max_L)\n s += '%-10s = %6s\\n' % ('is_pure', self.is_pure)\n s += '%-10s = %6s\\n' % ('is_cart', self.is_cart)\n s += '%-10s = %6s\\n' % ('is_mixed', self.is_mixed)\n return s;\n\n @property\n def detail_string(self):\n s = ''\n s += '%-5s : %7s %2s %5s %5s %5s %10s %10s %10s %10s %10s\\n' % (\n 'shell',\n 'is_pure',\n 'L',\n 'nao',\n 'ncart',\n 'nprim', \n 'ao_start',\n 'cart_start',\n 'prim_start',\n 'atom',\n 'atom_shell',\n )\n P = 0\n for A in range(self.natom):\n for P2 in range(len(self.shells[A])):\n shell = self.shells[A][P2]\n s += '%-5d : %7s %2d %5d %5d %5d %10d %10d %10d %10d %10d\\n' % (\n P,\n shell.is_pure,\n shell.L,\n shell.nao,\n shell.ncart,\n shell.nprimitive,\n self.shell_ao_starts[P],\n self.shell_cart_starts[P],\n self.shell_primitive_starts[P],\n self.shell_atoms[P],\n self.shell_atom_shells[P],\n )\n P += 1\n return s\n\n # => GBS File AOBasis Parsing <= #\n \n angular_momentum_table = {\n 'S' : 0, \n 'P' : 1, \n 'D' : 2, \n 'F' : 3, \n 'G' : 4, \n 'H' : 5, \n 'I' : 6, \n 'K' : 7, \n 'L' : 8, \n 'M' : 9, \n 'N' : 10,\n 'O' : 11,\n 'Q' : 12,\n 'R' : 13,\n 'T' : 14,\n 'U' : 15,","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.parse_from_gbs_lines","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.parse_from_gbs_lines#L220-L345","kind":"function","name":"parse_from_gbs_lines","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":220,"end_line":345,"context_start_line":200,"context_end_line":365,"code":" 'G' : 4, \n 'H' : 5, \n 'I' : 6, \n 'K' : 7, \n 'L' : 8, \n 'M' : 9, \n 'N' : 10,\n 'O' : 11,\n 'Q' : 12,\n 'R' : 13,\n 'T' : 14,\n 'U' : 15,\n 'V' : 16,\n 'W' : 17,\n 'X' : 18,\n 'Y' : 19,\n 'Z' : 20,\n }\n\n @staticmethod\n def parse_from_gbs_lines(\n *,\n lines,\n molecule,\n ):\n \n import re\n \n # => Cleaning <= #\n \n # Strip blank lines out\n lines = [_ for _ in lines if len(_.strip())]\n # Strip comment lines out\n re_comment = re.compile(r'\\s*!')\n lines = [_ for _ in lines if not re.match(re_comment, _)]\n # Lines must be nonzero \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n \n # => Spherical / Cartesian Tag Line <= #\n \n mobj = re.match(r'^\\s*(spherical|cartesian)\\s*$', lines[0])\n if mobj is None:\n raise RuntimeError(\"First line of GBS file must be 'spherical' or 'cartesian', instead is: %s\" % lines[0])\n \n if mobj.group(1) == 'spherical':\n is_pure = True\n elif mobj.group(1) == 'cartesian':\n is_pure = False\n else:\n raise RuntimeError('Invalid cartesian/spherical label: %s' % mobj.group(1))\n \n lines = lines[1:]\n \n # => Atom Block Location <= #\n \n re_separator = re.compile(r'\\s*\\*\\*\\*\\*\\s*$')\n separator_indices = [k for k, line in enumerate(lines) if re.match(re_separator, line)]\n if len(separator_indices) == 0: \n raise RuntimeError('No **** separators present')\n if separator_indices[-1] + 1 != len(lines):\n raise RuntimeError('Last line must be ****, instead is: %s' % lines[-1])\n lines = lines[:-1]\n separator_indices = separator_indices[:-1]\n \n if len(lines) == 0: raise RuntimeError('GBS lines are blank')\n if len(separator_indices) == 0: raise RuntimeError('No **** separators present')\n \n # => Atom IDs and corresponding block index <= #\n \n re_atom_id = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s*$')\n atom_id_lines = [lines[_ + 1] for _ in separator_indices]\n N_index_map = {}\n for index, atom_id_line in enumerate(atom_id_lines):\n mobj = re.match(re_atom_id, atom_id_line)\n if mobj is None:\n raise RuntimeError('Malformed atom ID line: %s' % (atom_id_line))\n symbol = mobj.group(1)\n atom_index = int(mobj.group(2))\n if atom_index != 0: \n raise RuntimeError('\"Symbol 0\" is only allowed atom line - multiple basis sets per atom type in GBS files is not supported by this library')\n symbol_upper = symbol.upper()\n if symbol_upper not in PeriodicTable.symbol_upper_to_N_table:\n raise RuntimeError('Unknown atomic in GBS file symbol: %s' % symbol)\n N = PeriodicTable.symbol_upper_to_N_table[symbol_upper]\n if N in N_index_map:\n raise RuntimeError('Duplicate atomic symbol in GBS file: %s' % symbol)\n N_index_map[N] = index\n \n # => Unique atoms in molecule (will parse only these) <= #\n \n unique_N = list(set(molecule.N[...]))\n \n re_shell_type = re.compile(r'^\\s*(\\S+)\\s+(\\d+)\\s+(\\S+)\\s*$')\n re_primitive = re.compile(r'^\\s*(\\S+)\\s+(\\S+)\\s*$')\n \n N_to_shells_map = {}\n for N in unique_N:\n if N not in N_index_map:\n raise RuntimeError('N not in GBS file: %d' % (N))\n block_index = N_index_map[N]\n index1 = separator_indices[block_index + 0]\n index2 = separator_indices[block_index + 1] if block_index + 1 < len(separator_indices) else len(lines)\n \n block_lines = lines[index1+2:index2]\n shell_type_indices = [k for k, line in enumerate(block_lines) if re.match(re_shell_type, line)]\n \n shells = []\n for index in shell_type_indices:\n shell_type_line = block_lines[index]\n mobj = re.match(re_shell_type, shell_type_line)\n am_symbol_upper = mobj.group(1).upper()\n if am_symbol_upper not in AOBasis.angular_momentum_table:\n raise RuntimeError('Unknown angular momentum symbol: %s' % am_symbol_upper)\n L = AOBasis.angular_momentum_table[am_symbol_upper]\n nprimitive = int(mobj.group(2))\n normalization = float(mobj.group(3))\n exponents = []\n coefficients_raw = []\n for K in range(nprimitive):\n primitive_line = block_lines[index + 1 + K]\n # Hack to replace D with E for FORTRAN notation\n primitive_line = primitive_line.replace('D', 'E')\n primitive_line = primitive_line.replace('d', 'e')\n mobj = re.match(re_primitive, primitive_line)\n exponents += [float(mobj.group(1))]\n coefficients_raw += [float(mobj.group(2))]\n exponents = np.array(exponents)\n coefficients_raw = np.array(coefficients_raw)\n shells.append(AOShell.build_from_raw_data(\n is_pure=is_pure,\n L=L,\n exponents=exponents,\n coefficients_raw=coefficients_raw,\n normalization=normalization,\n ))\n N_to_shells_map[N] = shells\n \n # => AOBasis <= #\n \n shells = []\n for N in molecule.N:\n shells.append(N_to_shells_map[N])\n \n return AOBasis(\n shells=shells,\n )\n \n @staticmethod\n def parse_from_gbs_string(\n string,\n *,\n molecule,\n **kwargs):\n \n return AOBasis.parse_from_gbs_lines(lines=string.split('\\n'), molecule=molecule, **kwargs) \n \n @staticmethod\n def parse_from_gbs_file(\n filename,\n *,\n molecule,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n ","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.parse_from_gbs_string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.parse_from_gbs_string#L348-L354","kind":"function","name":"parse_from_gbs_string","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":348,"end_line":354,"context_start_line":328,"context_end_line":369,"code":" shells.append(AOShell.build_from_raw_data(\n is_pure=is_pure,\n L=L,\n exponents=exponents,\n coefficients_raw=coefficients_raw,\n normalization=normalization,\n ))\n N_to_shells_map[N] = shells\n \n # => AOBasis <= #\n \n shells = []\n for N in molecule.N:\n shells.append(N_to_shells_map[N])\n \n return AOBasis(\n shells=shells,\n )\n \n @staticmethod\n def parse_from_gbs_string(\n string,\n *,\n molecule,\n **kwargs):\n \n return AOBasis.parse_from_gbs_lines(lines=string.split('\\n'), molecule=molecule, **kwargs) \n \n @staticmethod\n def parse_from_gbs_file(\n filename,\n *,\n molecule,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return AOBasis.parse_from_gbs_lines(\n lines=lines,\n molecule=molecule,\n **kwargs)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.ao_basis.parse_from_gbs_file","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.ao_basis.parse_from_gbs_file#L357-L369","kind":"function","name":"parse_from_gbs_file","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":357,"end_line":369,"context_start_line":337,"context_end_line":369,"code":" # => AOBasis <= #\n \n shells = []\n for N in molecule.N:\n shells.append(N_to_shells_map[N])\n \n return AOBasis(\n shells=shells,\n )\n \n @staticmethod\n def parse_from_gbs_string(\n string,\n *,\n molecule,\n **kwargs):\n \n return AOBasis.parse_from_gbs_lines(lines=string.split('\\n'), molecule=molecule, **kwargs) \n \n @staticmethod\n def parse_from_gbs_file(\n filename,\n *,\n molecule,\n **kwargs):\n \n with open(filename, 'r') as fh:\n lines = fh.read().splitlines()\n \n return AOBasis.parse_from_gbs_lines(\n lines=lines,\n molecule=molecule,\n **kwargs)","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan#L1-L299","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":1,"end_line":299,"context_start_line":1,"context_end_line":299,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .memoized_property import memoized_property\n\nimport cuest.bindings as ce \n\nfrom .xc_functionals import XCFunctionalInfo\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_molecular_grid import CuestMolecularGrid\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestXCIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n grid : CuestMolecularGrid,\n functional,\n xc_threshold_collocation,\n ):\n\n self.initialized = False\n\n self.handle = handle\n self.functional = functional\n self.xc_threshold_collocation = xc_threshold_collocation\n\n xc_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n )\n\n xc_threshold_collocation_data = ce.data_double(self.xc_threshold_collocation)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xc_int_plan_parameters.parameters,\n attribute=ce.CuestXCIntPlanParametersAttributes.CUEST_XCINTPLAN_PARAMETERS_THRESHOLD_COLLOCATION,\n attributeValue=xc_threshold_collocation_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanConfigure failed')\n\n self.xc_int_plan_handle = ce.cuestXCIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n grid=grid.moleculargrid_handle,\n functional=functional,\n parameters=xc_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestXCIntPlanCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n grid=grid.moleculargrid_handle,\n functional=functional,\n parameters=xc_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestXCIntPlanDestroy(\n handle=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanDestroy failed')\n\n @property\n def engine_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def engine_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @memoized_property\n def functional_name(self):\n return XCFunctionalInfo.enum_to_string(self.functional)\n\n @memoized_property\n def exchange_scale(self):\n exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_EXCHANGE_SCALE,\n attributeValue=exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return exchange_scale.value\n\n @memoized_property\n def lrc_exchange_scale(self):\n lrc_exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_EXCHANGE_SCALE,\n attributeValue=lrc_exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_exchange_scale.value\n\n @memoized_property\n def lrc_omega(self):\n lrc_omega = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_OMEGA,\n attributeValue=lrc_omega,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_omega.value\n\n @memoized_property\n def vv10_scale(self):\n vv10_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_scale.value\n\n @memoized_property\n def vv10_c(self):\n vv10_c = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_C,\n attributeValue=vv10_c,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_c.value\n\n @memoized_property\n def vv10_b(self):\n vv10_b = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_B,\n attributeValue=vv10_b,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_b.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'XCIntPlan:\\n';\n if self.engine_description and self.engine_citation:\n s += '%-10s = %s\\n' % ('engine', self.engine_description)\n s += '%-10s = %s\\n' % ('citation', self.engine_citation)\n s += '%-10s = %s\\n' % ('XC brief', self.functional_description)\n s += '%-10s = %s\\n' % ('citation', self.functional_citation)\n s += '%-10s = %10s\\n' % ('functional', self.functional_name)\n s += '%-10s = %10.3f\\n' % ('hf scale', self.exchange_scale)\n s += '%-10s = %10.3f\\n' % ('lrc scale', self.lrc_exchange_scale)\n if self.lrc_exchange_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('lrc omega', self.lrc_omega)\n s += '%-10s = %10.3f\\n' % ('vv10 scale', self.vv10_scale)\n if self.vv10_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('vv10 b', self.vv10_b)\n s += '%-10s = %10.3f\\n' % ('vv10 c', self.vv10_c)\n return s;\n","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.CuestXCIntPlan","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.CuestXCIntPlan#L31-L298","kind":"class","name":"CuestXCIntPlan","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":31,"end_line":298,"context_start_line":11,"context_end_line":299,"code":"# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .memoized_property import memoized_property\n\nimport cuest.bindings as ce \n\nfrom .xc_functionals import XCFunctionalInfo\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_molecular_grid import CuestMolecularGrid\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestXCIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n grid : CuestMolecularGrid,\n functional,\n xc_threshold_collocation,\n ):\n\n self.initialized = False\n\n self.handle = handle\n self.functional = functional\n self.xc_threshold_collocation = xc_threshold_collocation\n\n xc_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n )\n\n xc_threshold_collocation_data = ce.data_double(self.xc_threshold_collocation)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xc_int_plan_parameters.parameters,\n attribute=ce.CuestXCIntPlanParametersAttributes.CUEST_XCINTPLAN_PARAMETERS_THRESHOLD_COLLOCATION,\n attributeValue=xc_threshold_collocation_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanConfigure failed')\n\n self.xc_int_plan_handle = ce.cuestXCIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n grid=grid.moleculargrid_handle,\n functional=functional,\n parameters=xc_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestXCIntPlanCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n grid=grid.moleculargrid_handle,\n functional=functional,\n parameters=xc_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestXCIntPlanDestroy(\n handle=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanDestroy failed')\n\n @property\n def engine_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def engine_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @memoized_property\n def functional_name(self):\n return XCFunctionalInfo.enum_to_string(self.functional)\n\n @memoized_property\n def exchange_scale(self):\n exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_EXCHANGE_SCALE,\n attributeValue=exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return exchange_scale.value\n\n @memoized_property\n def lrc_exchange_scale(self):\n lrc_exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_EXCHANGE_SCALE,\n attributeValue=lrc_exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_exchange_scale.value\n\n @memoized_property\n def lrc_omega(self):\n lrc_omega = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_OMEGA,\n attributeValue=lrc_omega,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_omega.value\n\n @memoized_property\n def vv10_scale(self):\n vv10_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_scale.value\n\n @memoized_property\n def vv10_c(self):\n vv10_c = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_C,\n attributeValue=vv10_c,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_c.value\n\n @memoized_property\n def vv10_b(self):\n vv10_b = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_B,\n attributeValue=vv10_b,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_b.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'XCIntPlan:\\n';\n if self.engine_description and self.engine_citation:\n s += '%-10s = %s\\n' % ('engine', self.engine_description)\n s += '%-10s = %s\\n' % ('citation', self.engine_citation)\n s += '%-10s = %s\\n' % ('XC brief', self.functional_description)\n s += '%-10s = %s\\n' % ('citation', self.functional_citation)\n s += '%-10s = %10s\\n' % ('functional', self.functional_name)\n s += '%-10s = %10.3f\\n' % ('hf scale', self.exchange_scale)\n s += '%-10s = %10.3f\\n' % ('lrc scale', self.lrc_exchange_scale)\n if self.lrc_exchange_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('lrc omega', self.lrc_omega)\n s += '%-10s = %10.3f\\n' % ('vv10 scale', self.vv10_scale)\n if self.vv10_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('vv10 b', self.vv10_b)\n s += '%-10s = %10.3f\\n' % ('vv10 c', self.vv10_c)\n return s;\n","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.__init__#L33-L106","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":33,"end_line":106,"context_start_line":13,"context_end_line":126,"code":"# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .memoized_property import memoized_property\n\nimport cuest.bindings as ce \n\nfrom .xc_functionals import XCFunctionalInfo\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_ao_basis import CuestAOBasis\nfrom .cuest_molecular_grid import CuestMolecularGrid\n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestXCIntPlan(object):\n\n def __init__(\n self,\n *,\n handle : CuestHandle,\n basis : CuestAOBasis,\n grid : CuestMolecularGrid,\n functional,\n xc_threshold_collocation,\n ):\n\n self.initialized = False\n\n self.handle = handle\n self.functional = functional\n self.xc_threshold_collocation = xc_threshold_collocation\n\n xc_int_plan_parameters = CuestParameters(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n )\n\n xc_threshold_collocation_data = ce.data_double(self.xc_threshold_collocation)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_XCINTPLAN_PARAMETERS,\n parameters=xc_int_plan_parameters.parameters,\n attribute=ce.CuestXCIntPlanParametersAttributes.CUEST_XCINTPLAN_PARAMETERS_THRESHOLD_COLLOCATION,\n attributeValue=xc_threshold_collocation_data,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanConfigure failed')\n\n self.xc_int_plan_handle = ce.cuestXCIntPlanHandle()\n\n # => Workspace Query <= #\n\n persistent_workspace_descriptor = CuestWorkspaceDescriptor()\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCIntPlanCreateWorkspaceQuery(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n grid=grid.moleculargrid_handle,\n functional=functional,\n parameters=xc_int_plan_parameters.parameters,\n persistentWorkspaceDescriptor=persistent_workspace_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outPlan=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanCreateWorkspaceQuery failed')\n\n persistent_workspace = CuestWorkspace(workspaceDescriptor=persistent_workspace_descriptor)\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n # => Creation <= #\n\n status = ce.cuestXCIntPlanCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n grid=grid.moleculargrid_handle,\n functional=functional,\n parameters=xc_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestXCIntPlanDestroy(\n handle=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanDestroy failed')\n\n @property\n def engine_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.__del__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.__del__#L108-L117","kind":"function","name":"__del__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":108,"end_line":117,"context_start_line":88,"context_end_line":137,"code":"\n status = ce.cuestXCIntPlanCreate(\n handle=handle.handle,\n basis=basis.ao_basis_handle,\n grid=grid.moleculargrid_handle,\n functional=functional,\n parameters=xc_int_plan_parameters.parameters,\n persistentWorkspace=persistent_workspace.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n outPlan=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestXCIntPlanDestroy(\n handle=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanDestroy failed')\n\n @property\n def engine_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def engine_description(self):","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.engine_citation","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.engine_citation#L120-L134","kind":"function","name":"engine_citation","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":120,"end_line":134,"context_start_line":100,"context_end_line":154,"code":" if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanCreate failed')\n\n # Bind the lifetime of persistent_workspace to this object\n self.persistent_workspace = persistent_workspace\n\n self.initialized = True\n\n def __del__(self):\n\n if not self.initialized: return\n\n status = ce.cuestXCIntPlanDestroy(\n handle=self.xc_int_plan_handle,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCIntPlanDestroy failed')\n\n @property\n def engine_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def engine_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_citation(self):","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.engine_description","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.engine_description#L137-L151","kind":"function","name":"engine_description","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":137,"end_line":151,"context_start_line":117,"context_end_line":171,"code":" raise RuntimeError('cuestXCIntPlanDestroy failed')\n\n @property\n def engine_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def engine_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_description(self):","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.functional_citation","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.functional_citation#L154-L168","kind":"function","name":"functional_citation","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":154,"end_line":168,"context_start_line":134,"context_end_line":188,"code":" return query.value\n\n @property\n def engine_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_ENGINE_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @memoized_property\n def functional_name(self):","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.functional_description","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.functional_description#L171-L185","kind":"function","name":"functional_description","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":171,"end_line":185,"context_start_line":151,"context_end_line":205,"code":" return query.value\n\n @property\n def functional_citation(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_CITATION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @property\n def functional_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @memoized_property\n def functional_name(self):\n return XCFunctionalInfo.enum_to_string(self.functional)\n\n @memoized_property\n def exchange_scale(self):\n exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_EXCHANGE_SCALE,\n attributeValue=exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return exchange_scale.value\n\n @memoized_property","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.functional_name","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.functional_name#L188-L189","kind":"function","name":"functional_name","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":188,"end_line":189,"context_start_line":168,"context_end_line":209,"code":" return query.value\n\n @property\n def functional_description(self):\n query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @memoized_property\n def functional_name(self):\n return XCFunctionalInfo.enum_to_string(self.functional)\n\n @memoized_property\n def exchange_scale(self):\n exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_EXCHANGE_SCALE,\n attributeValue=exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return exchange_scale.value\n\n @memoized_property\n def lrc_exchange_scale(self):\n lrc_exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.exchange_scale","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.exchange_scale#L192-L203","kind":"function","name":"exchange_scale","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":192,"end_line":203,"context_start_line":172,"context_end_line":223,"code":" query = ce.data_string()\n\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_FUNCTIONAL_DESCRIPTION,\n attributeValue=query,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuest query failed')\n\n return query.value\n\n @memoized_property\n def functional_name(self):\n return XCFunctionalInfo.enum_to_string(self.functional)\n\n @memoized_property\n def exchange_scale(self):\n exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_EXCHANGE_SCALE,\n attributeValue=exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return exchange_scale.value\n\n @memoized_property\n def lrc_exchange_scale(self):\n lrc_exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_EXCHANGE_SCALE,\n attributeValue=lrc_exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_exchange_scale.value\n\n @memoized_property\n def lrc_omega(self):\n lrc_omega = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.lrc_exchange_scale","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.lrc_exchange_scale#L206-L217","kind":"function","name":"lrc_exchange_scale","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":206,"end_line":217,"context_start_line":186,"context_end_line":237,"code":"\n @memoized_property\n def functional_name(self):\n return XCFunctionalInfo.enum_to_string(self.functional)\n\n @memoized_property\n def exchange_scale(self):\n exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_EXCHANGE_SCALE,\n attributeValue=exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return exchange_scale.value\n\n @memoized_property\n def lrc_exchange_scale(self):\n lrc_exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_EXCHANGE_SCALE,\n attributeValue=lrc_exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_exchange_scale.value\n\n @memoized_property\n def lrc_omega(self):\n lrc_omega = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_OMEGA,\n attributeValue=lrc_omega,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_omega.value\n\n @memoized_property\n def vv10_scale(self):\n vv10_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.lrc_omega","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.lrc_omega#L220-L231","kind":"function","name":"lrc_omega","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":220,"end_line":231,"context_start_line":200,"context_end_line":251,"code":" )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return exchange_scale.value\n\n @memoized_property\n def lrc_exchange_scale(self):\n lrc_exchange_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_EXCHANGE_SCALE,\n attributeValue=lrc_exchange_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_exchange_scale.value\n\n @memoized_property\n def lrc_omega(self):\n lrc_omega = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_OMEGA,\n attributeValue=lrc_omega,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_omega.value\n\n @memoized_property\n def vv10_scale(self):\n vv10_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_scale.value\n\n @memoized_property\n def vv10_c(self):\n vv10_c = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.vv10_scale","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.vv10_scale#L234-L245","kind":"function","name":"vv10_scale","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":234,"end_line":245,"context_start_line":214,"context_end_line":265,"code":" )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_exchange_scale.value\n\n @memoized_property\n def lrc_omega(self):\n lrc_omega = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_LRC_OMEGA,\n attributeValue=lrc_omega,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_omega.value\n\n @memoized_property\n def vv10_scale(self):\n vv10_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_scale.value\n\n @memoized_property\n def vv10_c(self):\n vv10_c = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_C,\n attributeValue=vv10_c,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_c.value\n\n @memoized_property\n def vv10_b(self):\n vv10_b = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.vv10_c","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.vv10_c#L248-L259","kind":"function","name":"vv10_c","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":248,"end_line":259,"context_start_line":228,"context_end_line":279,"code":" )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return lrc_omega.value\n\n @memoized_property\n def vv10_scale(self):\n vv10_scale = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_scale.value\n\n @memoized_property\n def vv10_c(self):\n vv10_c = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_C,\n attributeValue=vv10_c,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_c.value\n\n @memoized_property\n def vv10_b(self):\n vv10_b = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_B,\n attributeValue=vv10_b,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_b.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.vv10_b","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.vv10_b#L262-L273","kind":"function","name":"vv10_b","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":262,"end_line":273,"context_start_line":242,"context_end_line":293,"code":" )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_scale.value\n\n @memoized_property\n def vv10_c(self):\n vv10_c = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_C,\n attributeValue=vv10_c,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_c.value\n\n @memoized_property\n def vv10_b(self):\n vv10_b = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_B,\n attributeValue=vv10_b,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_b.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'XCIntPlan:\\n';\n if self.engine_description and self.engine_citation:\n s += '%-10s = %s\\n' % ('engine', self.engine_description)\n s += '%-10s = %s\\n' % ('citation', self.engine_citation)\n s += '%-10s = %s\\n' % ('XC brief', self.functional_description)\n s += '%-10s = %s\\n' % ('citation', self.functional_citation)\n s += '%-10s = %10s\\n' % ('functional', self.functional_name)\n s += '%-10s = %10.3f\\n' % ('hf scale', self.exchange_scale)\n s += '%-10s = %10.3f\\n' % ('lrc scale', self.lrc_exchange_scale)\n if self.lrc_exchange_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('lrc omega', self.lrc_omega)","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.__str__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.__str__#L277-L278","kind":"function","name":"__str__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":277,"end_line":278,"context_start_line":257,"context_end_line":298,"code":" if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_c.value\n\n @memoized_property\n def vv10_b(self):\n vv10_b = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_B,\n attributeValue=vv10_b,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_b.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'XCIntPlan:\\n';\n if self.engine_description and self.engine_citation:\n s += '%-10s = %s\\n' % ('engine', self.engine_description)\n s += '%-10s = %s\\n' % ('citation', self.engine_citation)\n s += '%-10s = %s\\n' % ('XC brief', self.functional_description)\n s += '%-10s = %s\\n' % ('citation', self.functional_citation)\n s += '%-10s = %10s\\n' % ('functional', self.functional_name)\n s += '%-10s = %10.3f\\n' % ('hf scale', self.exchange_scale)\n s += '%-10s = %10.3f\\n' % ('lrc scale', self.lrc_exchange_scale)\n if self.lrc_exchange_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('lrc omega', self.lrc_omega)\n s += '%-10s = %10.3f\\n' % ('vv10 scale', self.vv10_scale)\n if self.vv10_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('vv10 b', self.vv10_b)\n s += '%-10s = %10.3f\\n' % ('vv10 c', self.vv10_c)\n return s;","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.string","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_plan.string#L281-L298","kind":"function","name":"string","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":281,"end_line":298,"context_start_line":261,"context_end_line":299,"code":" @memoized_property\n def vv10_b(self):\n vv10_b = ce.data_double()\n status = ce.cuestQuery(\n handle=self.handle.handle,\n type=ce.CuestType.CUEST_XCINTPLAN,\n object=self.xc_int_plan_handle,\n attribute=ce.CuestXCIntPlanAttributes.CUEST_XCINTPLAN_VV10_B,\n attributeValue=vv10_b,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestQuery failed')\n return vv10_b.value\n\n # => String Details <= #\n\n def __str__(self):\n return self.string\n\n @property\n def string(self):\n s = ''\n s += 'XCIntPlan:\\n';\n if self.engine_description and self.engine_citation:\n s += '%-10s = %s\\n' % ('engine', self.engine_description)\n s += '%-10s = %s\\n' % ('citation', self.engine_citation)\n s += '%-10s = %s\\n' % ('XC brief', self.functional_description)\n s += '%-10s = %s\\n' % ('citation', self.functional_citation)\n s += '%-10s = %10s\\n' % ('functional', self.functional_name)\n s += '%-10s = %10.3f\\n' % ('hf scale', self.exchange_scale)\n s += '%-10s = %10.3f\\n' % ('lrc scale', self.lrc_exchange_scale)\n if self.lrc_exchange_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('lrc omega', self.lrc_omega)\n s += '%-10s = %10.3f\\n' % ('vv10 scale', self.vv10_scale)\n if self.vv10_scale != 0.0:\n s += '%-10s = %10.3f\\n' % ('vv10 b', self.vv10_b)\n s += '%-10s = %10.3f\\n' % ('vv10 c', self.vv10_c)\n return s;\n","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom#L1-L122","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":1,"end_line":122,"context_start_line":1,"context_end_line":122,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .ao_basis import AOBasis\n\nfrom .sad_atom_structure import SADAtomStructure\n\nfrom .sad_overlap import SADOverlap\n\nfrom .memoized_property import memoized_property\n\nclass SADGuessAtom(object):\n\n def __init__(\n self,\n primary : AOBasis,\n minao : AOBasis,\n structure : SADAtomStructure,\n ):\n\n self.primary = primary\n self.minao = minao\n self.structure = structure\n\n if self.primary.natom != 1: raise RuntimeError('primary.natom != 1')\n if self.minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if [shell.L for shell in minao.shells[0]] != structure.Ls:\n raise RuntimeError('minao L structure is not correct for this atom. N = %d' % (structure.N))\n\n if not minao.is_pure: \n raise RuntimeError('minao is not pure')\n\n if minao.nao > primary.nao: \n raise RuntimeError('minao.nao > primary.nao')\n\n @memoized_property\n def Smm(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.minao,\n )\n\n @memoized_property\n def Smp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.primary,\n )\n\n @memoized_property\n def Spp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.primary,\n basis2=self.primary,\n )\n\n @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))\n\n @property\n def overlap_health(self):\n return np.max(np.abs(self.s - 1.0))\n ","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.SADGuessAtom","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.SADGuessAtom#L26-L121","kind":"class","name":"SADGuessAtom","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":26,"end_line":121,"context_start_line":6,"context_end_line":122,"code":"# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .ao_basis import AOBasis\n\nfrom .sad_atom_structure import SADAtomStructure\n\nfrom .sad_overlap import SADOverlap\n\nfrom .memoized_property import memoized_property\n\nclass SADGuessAtom(object):\n\n def __init__(\n self,\n primary : AOBasis,\n minao : AOBasis,\n structure : SADAtomStructure,\n ):\n\n self.primary = primary\n self.minao = minao\n self.structure = structure\n\n if self.primary.natom != 1: raise RuntimeError('primary.natom != 1')\n if self.minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if [shell.L for shell in minao.shells[0]] != structure.Ls:\n raise RuntimeError('minao L structure is not correct for this atom. N = %d' % (structure.N))\n\n if not minao.is_pure: \n raise RuntimeError('minao is not pure')\n\n if minao.nao > primary.nao: \n raise RuntimeError('minao.nao > primary.nao')\n\n @memoized_property\n def Smm(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.minao,\n )\n\n @memoized_property\n def Smp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.primary,\n )\n\n @memoized_property\n def Spp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.primary,\n basis2=self.primary,\n )\n\n @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))\n\n @property\n def overlap_health(self):\n return np.max(np.abs(self.s - 1.0))\n ","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.__init__#L28-L49","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":28,"end_line":49,"context_start_line":8,"context_end_line":69,"code":"# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .ao_basis import AOBasis\n\nfrom .sad_atom_structure import SADAtomStructure\n\nfrom .sad_overlap import SADOverlap\n\nfrom .memoized_property import memoized_property\n\nclass SADGuessAtom(object):\n\n def __init__(\n self,\n primary : AOBasis,\n minao : AOBasis,\n structure : SADAtomStructure,\n ):\n\n self.primary = primary\n self.minao = minao\n self.structure = structure\n\n if self.primary.natom != 1: raise RuntimeError('primary.natom != 1')\n if self.minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if [shell.L for shell in minao.shells[0]] != structure.Ls:\n raise RuntimeError('minao L structure is not correct for this atom. N = %d' % (structure.N))\n\n if not minao.is_pure: \n raise RuntimeError('minao is not pure')\n\n if minao.nao > primary.nao: \n raise RuntimeError('minao.nao > primary.nao')\n\n @memoized_property\n def Smm(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.minao,\n )\n\n @memoized_property\n def Smp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.primary,\n )\n\n @memoized_property\n def Spp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.primary,\n basis2=self.primary,","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Smm","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Smm#L52-L56","kind":"function","name":"Smm","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":52,"end_line":56,"context_start_line":32,"context_end_line":76,"code":" structure : SADAtomStructure,\n ):\n\n self.primary = primary\n self.minao = minao\n self.structure = structure\n\n if self.primary.natom != 1: raise RuntimeError('primary.natom != 1')\n if self.minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if [shell.L for shell in minao.shells[0]] != structure.Ls:\n raise RuntimeError('minao L structure is not correct for this atom. N = %d' % (structure.N))\n\n if not minao.is_pure: \n raise RuntimeError('minao is not pure')\n\n if minao.nao > primary.nao: \n raise RuntimeError('minao.nao > primary.nao')\n\n @memoized_property\n def Smm(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.minao,\n )\n\n @memoized_property\n def Smp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.primary,\n )\n\n @memoized_property\n def Spp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.primary,\n basis2=self.primary,\n )\n\n @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Smp","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Smp#L59-L63","kind":"function","name":"Smp","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":59,"end_line":63,"context_start_line":39,"context_end_line":83,"code":" if self.primary.natom != 1: raise RuntimeError('primary.natom != 1')\n if self.minao.natom != 1: raise RuntimeError('minao.natom != 1')\n\n if [shell.L for shell in minao.shells[0]] != structure.Ls:\n raise RuntimeError('minao L structure is not correct for this atom. N = %d' % (structure.N))\n\n if not minao.is_pure: \n raise RuntimeError('minao is not pure')\n\n if minao.nao > primary.nao: \n raise RuntimeError('minao.nao > primary.nao')\n\n @memoized_property\n def Smm(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.minao,\n )\n\n @memoized_property\n def Smp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.primary,\n )\n\n @memoized_property\n def Spp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.primary,\n basis2=self.primary,\n )\n\n @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Spp","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Spp#L66-L70","kind":"function","name":"Spp","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":66,"end_line":70,"context_start_line":46,"context_end_line":90,"code":" raise RuntimeError('minao is not pure')\n\n if minao.nao > primary.nao: \n raise RuntimeError('minao.nao > primary.nao')\n\n @memoized_property\n def Smm(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.minao,\n )\n\n @memoized_property\n def Smp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.primary,\n )\n\n @memoized_property\n def Spp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.primary,\n basis2=self.primary,\n )\n\n @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Xm","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Xm#L73-L76","kind":"function","name":"Xm","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":73,"end_line":76,"context_start_line":53,"context_end_line":96,"code":" return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.minao,\n )\n\n @memoized_property\n def Smp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.primary,\n )\n\n @memoized_property\n def Spp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.primary,\n basis2=self.primary,\n )\n\n @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Xp","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.Xp#L79-L85","kind":"function","name":"Xp","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":79,"end_line":85,"context_start_line":59,"context_end_line":105,"code":" def Smp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.minao,\n basis2=self.primary,\n )\n\n @memoized_property\n def Spp(self):\n return SADOverlap.compute_atomic_overlap(\n basis1=self.primary,\n basis2=self.primary,\n )\n\n @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.M","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.M#L88-L89","kind":"function","name":"M","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":88,"end_line":89,"context_start_line":68,"context_end_line":109,"code":" basis1=self.primary,\n basis2=self.primary,\n )\n\n @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.U","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.U#L92-L93","kind":"function","name":"U","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":92,"end_line":93,"context_start_line":72,"context_end_line":113,"code":" @memoized_property\n def Xm(self):\n s, U = np.linalg.eigh(self.Smm)\n X = np.einsum('pi,i->pi', U, s**(-0.5))\n return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.s","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.s#L96-L97","kind":"function","name":"s","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":96,"end_line":97,"context_start_line":76,"context_end_line":117,"code":" return np.dot(X, U.T)\n\n @memoized_property\n def Xp(self):\n s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.V","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.V#L100-L101","kind":"function","name":"V","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":100,"end_line":101,"context_start_line":80,"context_end_line":121,"code":" s, U = np.linalg.eigh(self.Spp)\n ind = s > 1.0E-12\n s = s[ind]\n U = U[:, ind]\n X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))\n\n @property\n def overlap_health(self):\n return np.max(np.abs(self.s - 1.0))","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.UsV","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.UsV#L104-L105","kind":"function","name":"UsV","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":104,"end_line":105,"context_start_line":84,"context_end_line":122,"code":" X = np.einsum('pi,i->ip', U, s**(-0.5))\n return X\n\n @memoized_property\n def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))\n\n @property\n def overlap_health(self):\n return np.max(np.abs(self.s - 1.0))\n ","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.P","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.P#L108-L109","kind":"function","name":"P","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":108,"end_line":109,"context_start_line":88,"context_end_line":122,"code":" def M(self):\n return np.dot(np.dot(self.Xm, self.Smp), self.Xp.T)\n\n @memoized_property\n def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))\n\n @property\n def overlap_health(self):\n return np.max(np.abs(self.s - 1.0))\n ","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.C","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.C#L112-L113","kind":"function","name":"C","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":112,"end_line":113,"context_start_line":92,"context_end_line":122,"code":" def U(self):\n return self.UsV[0] \n\n @memoized_property\n def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))\n\n @property\n def overlap_health(self):\n return np.max(np.abs(self.s - 1.0))\n ","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.minao_health","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.minao_health#L116-L117","kind":"function","name":"minao_health","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":116,"end_line":117,"context_start_line":96,"context_end_line":122,"code":" def s(self):\n return self.UsV[1] \n \n @memoized_property\n def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))\n\n @property\n def overlap_health(self):\n return np.max(np.abs(self.s - 1.0))\n ","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.overlap_health","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_guess_atom.overlap_health#L120-L121","kind":"function","name":"overlap_health","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":120,"end_line":121,"context_start_line":100,"context_end_line":122,"code":" def V(self):\n return self.UsV[2] \n \n @memoized_property\n def UsV(self):\n return np.linalg.svd(self.M, full_matrices=False)\n \n @memoized_property\n def P(self):\n return np.dot(self.U, self.V)\n\n @memoized_property\n def C(self):\n return np.dot(self.P, self.Xp)\n\n @property\n def minao_health(self):\n return np.max(np.abs(self.Smm - np.eye(self.Smm.shape[0])))\n\n @property\n def overlap_health(self):\n return np.max(np.abs(self.s - 1.0))\n ","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor#L1-L48","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","language":"python","start_line":1,"end_line":48,"context_start_line":1,"context_end_line":48,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nclass CuestWorkspaceDescriptor():\n\n _dtype = np.dtype([\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n def __init__(\n self,\n *,\n hostBufferSizeInBytes: np.uint64 = 0,\n deviceBufferSizeInBytes: np.uint64 = 0,\n ):\n\n self.struct = np.array(\n (hostBufferSizeInBytes, deviceBufferSizeInBytes),\n dtype=self._dtype,\n )\n\n def __str__(\n self,\n ):\n\n hostsize = self.struct['hostBufferSizeInBytes']\n devicesize = self.struct['deviceBufferSizeInBytes']\n return f'host buffer size = {hostsize} bytes, device buffer size = {devicesize} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"a92f632bb0f1a027de4a7a6d7185add3259bcee4b0508f3535629d645b00e5b5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor.CuestWorkspaceDescriptor","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor.CuestWorkspaceDescriptor#L18-L48","kind":"class","name":"CuestWorkspaceDescriptor","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","language":"python","start_line":18,"end_line":48,"context_start_line":1,"context_end_line":48,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nclass CuestWorkspaceDescriptor():\n\n _dtype = np.dtype([\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n def __init__(\n self,\n *,\n hostBufferSizeInBytes: np.uint64 = 0,\n deviceBufferSizeInBytes: np.uint64 = 0,\n ):\n\n self.struct = np.array(\n (hostBufferSizeInBytes, deviceBufferSizeInBytes),\n dtype=self._dtype,\n )\n\n def __str__(\n self,\n ):\n\n hostsize = self.struct['hostBufferSizeInBytes']\n devicesize = self.struct['deviceBufferSizeInBytes']\n return f'host buffer size = {hostsize} bytes, device buffer size = {devicesize} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"a92f632bb0f1a027de4a7a6d7185add3259bcee4b0508f3535629d645b00e5b5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor.__init__#L26-L36","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","language":"python","start_line":26,"end_line":36,"context_start_line":6,"context_end_line":48,"code":"# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nclass CuestWorkspaceDescriptor():\n\n _dtype = np.dtype([\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n def __init__(\n self,\n *,\n hostBufferSizeInBytes: np.uint64 = 0,\n deviceBufferSizeInBytes: np.uint64 = 0,\n ):\n\n self.struct = np.array(\n (hostBufferSizeInBytes, deviceBufferSizeInBytes),\n dtype=self._dtype,\n )\n\n def __str__(\n self,\n ):\n\n hostsize = self.struct['hostBufferSizeInBytes']\n devicesize = self.struct['deviceBufferSizeInBytes']\n return f'host buffer size = {hostsize} bytes, device buffer size = {devicesize} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"a92f632bb0f1a027de4a7a6d7185add3259bcee4b0508f3535629d645b00e5b5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor.__str__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor.__str__#L38-L44","kind":"function","name":"__str__","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","language":"python","start_line":38,"end_line":44,"context_start_line":18,"context_end_line":48,"code":"class CuestWorkspaceDescriptor():\n\n _dtype = np.dtype([\n (\"hostBufferSizeInBytes\", np.uint64, ),\n (\"deviceBufferSizeInBytes\", np.uint64, ),\n ], align=True\n )\n\n def __init__(\n self,\n *,\n hostBufferSizeInBytes: np.uint64 = 0,\n deviceBufferSizeInBytes: np.uint64 = 0,\n ):\n\n self.struct = np.array(\n (hostBufferSizeInBytes, deviceBufferSizeInBytes),\n dtype=self._dtype,\n )\n\n def __str__(\n self,\n ):\n\n hostsize = self.struct['hostBufferSizeInBytes']\n devicesize = self.struct['deviceBufferSizeInBytes']\n return f'host buffer size = {hostsize} bytes, device buffer size = {devicesize} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"a92f632bb0f1a027de4a7a6d7185add3259bcee4b0508f3535629d645b00e5b5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor.pointer","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_workspace_descriptor.pointer#L47-L48","kind":"function","name":"pointer","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","language":"python","start_line":47,"end_line":48,"context_start_line":27,"context_end_line":48,"code":" self,\n *,\n hostBufferSizeInBytes: np.uint64 = 0,\n deviceBufferSizeInBytes: np.uint64 = 0,\n ):\n\n self.struct = np.array(\n (hostBufferSizeInBytes, deviceBufferSizeInBytes),\n dtype=self._dtype,\n )\n\n def __str__(\n self,\n ):\n\n hostsize = self.struct['hostBufferSizeInBytes']\n devicesize = self.struct['deviceBufferSizeInBytes']\n return f'host buffer size = {hostsize} bytes, device buffer size = {devicesize} bytes'\n\n @property\n def pointer(self):\n return self.struct.ctypes.data","source_hash":"a92f632bb0f1a027de4a7a6d7185add3259bcee4b0508f3535629d645b00e5b5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_solid_harmonics","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.sad_solid_harmonics#L1-L122","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.sad_solid_harmonics","path":"cuEST/cuest_scf_examples/cuest_scf/sad_solid_harmonics.py","language":"python","start_line":1,"end_line":122,"context_start_line":1,"context_end_line":122,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nclass SADSolidHarmonics(object):\n\n def __init__(\n self,\n *,\n max_L : int,\n ):\n\n self.T = {}\n\n if max_L < 0: return\n\n # L = 0\n self.T[0] = np.array([\n [ 1.0000000000000000E+00, ],\n ])\n\n if max_L < 1: return\n\n # L = 1\n self.T[1] = np.array([\n [ 0.0000000000000000E+00, 1.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 2: return\n\n # L = 2\n self.T[2] = np.array([\n [ -5.0000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 8.6602540378443860E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.7320508075688772E+00, ],\n [ 0.0000000000000000E+00, 1.7320508075688774E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, -8.6602540378443860E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 1.7320508075688774E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 3: return\n\n # L = 3\n self.T[3] = np.array([\n [ 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.9056941504209488E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.3717082451262845E+00, ],\n [ -1.5000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.9364916731037085E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.8729833462074170E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 2.4494897427831779E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.9056941504209488E-01, ],\n [ -1.5000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.9364916731037085E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 2.4494897427831779E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 4: return\n\n # L = 4\n self.T[4] = np.array([\n [ 3.7500000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.5901699437494734E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.3950997288745202E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.1180339887498947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.9580398915498081E+00, ],\n [ 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.0916500663351889E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 7.5000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -4.4370598373247123E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 6.2749501990055663E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -3.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.3541019662496847E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.1180339887498947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.9580398915498081E+00, ],\n [ 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -6.2749501990055663E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 6.7082039324993694E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 3.1622776601683782E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 3.7500000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.5901699437494734E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.3950997288745202E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.0916500663351889E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -3.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -3.3541019662496847E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 3.1622776601683782E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 5: return\n\n # L = 5\n self.T[5] = np.array([\n [ 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.2291251658379723E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.0156076002011403E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.5687375497513918E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.5078038001005698E+00, ],\n [ 1.8750000000000002E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.5617376914898995E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.2185299186623562E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 9.6824583655185414E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0458250331675947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.0156076002011396E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797990E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 8.8741196746494246E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 4.1833001326703778E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 9.6824583655185414E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.0458250331675947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.0156076002011396E+00, ],\n [ 3.7500000000000004E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.3311179511974137E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.2549900398011133E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.1234753829797999E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.5687375497513918E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.5078038001005698E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797990E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -8.8741196746494246E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.2549900398011133E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0246950765959600E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 3.8729833462074152E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.2291251658379723E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.0156076002011403E-01, ],\n [ 1.8750000000000002E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.5617376914898995E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.2185299186623562E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -4.1833001326703778E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797999E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 3.8729833462074152E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 6: return\n\n raise RuntimeError('max_L too large: max_L = %d' % max_L)","source_hash":"544c235942e1acad1d86d09eca837cd486863937663ea16a486fab088eafc3e1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_solid_harmonics.SADSolidHarmonics","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.sad_solid_harmonics.SADSolidHarmonics#L18-L122","kind":"class","name":"SADSolidHarmonics","path":"cuEST/cuest_scf_examples/cuest_scf/sad_solid_harmonics.py","language":"python","start_line":18,"end_line":122,"context_start_line":1,"context_end_line":122,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nclass SADSolidHarmonics(object):\n\n def __init__(\n self,\n *,\n max_L : int,\n ):\n\n self.T = {}\n\n if max_L < 0: return\n\n # L = 0\n self.T[0] = np.array([\n [ 1.0000000000000000E+00, ],\n ])\n\n if max_L < 1: return\n\n # L = 1\n self.T[1] = np.array([\n [ 0.0000000000000000E+00, 1.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 2: return\n\n # L = 2\n self.T[2] = np.array([\n [ -5.0000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 8.6602540378443860E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.7320508075688772E+00, ],\n [ 0.0000000000000000E+00, 1.7320508075688774E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, -8.6602540378443860E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 1.7320508075688774E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 3: return\n\n # L = 3\n self.T[3] = np.array([\n [ 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.9056941504209488E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.3717082451262845E+00, ],\n [ -1.5000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.9364916731037085E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.8729833462074170E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 2.4494897427831779E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.9056941504209488E-01, ],\n [ -1.5000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.9364916731037085E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 2.4494897427831779E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 4: return\n\n # L = 4\n self.T[4] = np.array([\n [ 3.7500000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.5901699437494734E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.3950997288745202E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.1180339887498947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.9580398915498081E+00, ],\n [ 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.0916500663351889E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 7.5000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -4.4370598373247123E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 6.2749501990055663E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -3.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.3541019662496847E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.1180339887498947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.9580398915498081E+00, ],\n [ 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -6.2749501990055663E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 6.7082039324993694E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 3.1622776601683782E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 3.7500000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.5901699437494734E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.3950997288745202E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.0916500663351889E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -3.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -3.3541019662496847E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 3.1622776601683782E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 5: return\n\n # L = 5\n self.T[5] = np.array([\n [ 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.2291251658379723E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.0156076002011403E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.5687375497513918E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.5078038001005698E+00, ],\n [ 1.8750000000000002E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.5617376914898995E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.2185299186623562E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 9.6824583655185414E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0458250331675947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.0156076002011396E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797990E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 8.8741196746494246E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 4.1833001326703778E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 9.6824583655185414E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.0458250331675947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.0156076002011396E+00, ],\n [ 3.7500000000000004E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.3311179511974137E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.2549900398011133E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.1234753829797999E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.5687375497513918E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.5078038001005698E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797990E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -8.8741196746494246E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.2549900398011133E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0246950765959600E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 3.8729833462074152E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.2291251658379723E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.0156076002011403E-01, ],\n [ 1.8750000000000002E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.5617376914898995E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.2185299186623562E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -4.1833001326703778E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797999E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 3.8729833462074152E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 6: return\n\n raise RuntimeError('max_L too large: max_L = %d' % max_L)","source_hash":"544c235942e1acad1d86d09eca837cd486863937663ea16a486fab088eafc3e1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_solid_harmonics.__init__","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_solid_harmonics.__init__#L20-L122","kind":"function","name":"__init__","path":"cuEST/cuest_scf_examples/cuest_scf/sad_solid_harmonics.py","language":"python","start_line":20,"end_line":122,"context_start_line":1,"context_end_line":122,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nclass SADSolidHarmonics(object):\n\n def __init__(\n self,\n *,\n max_L : int,\n ):\n\n self.T = {}\n\n if max_L < 0: return\n\n # L = 0\n self.T[0] = np.array([\n [ 1.0000000000000000E+00, ],\n ])\n\n if max_L < 1: return\n\n # L = 1\n self.T[1] = np.array([\n [ 0.0000000000000000E+00, 1.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 2: return\n\n # L = 2\n self.T[2] = np.array([\n [ -5.0000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 8.6602540378443860E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.7320508075688772E+00, ],\n [ 0.0000000000000000E+00, 1.7320508075688774E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, -8.6602540378443860E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 1.7320508075688774E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 3: return\n\n # L = 3\n self.T[3] = np.array([\n [ 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.9056941504209488E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.3717082451262845E+00, ],\n [ -1.5000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.9364916731037085E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.8729833462074170E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 2.4494897427831779E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -6.1237243569579447E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.9056941504209488E-01, ],\n [ -1.5000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.9364916731037085E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 2.4494897427831779E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 4: return\n\n # L = 4\n self.T[4] = np.array([\n [ 3.7500000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.5901699437494734E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.3950997288745202E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.1180339887498947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.9580398915498081E+00, ],\n [ 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.0916500663351889E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 7.5000000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -4.4370598373247123E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 6.2749501990055663E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -3.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.3541019662496847E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.1180339887498947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.9580398915498081E+00, ],\n [ 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -6.2749501990055663E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 6.7082039324993694E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 3.1622776601683782E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 3.7500000000000000E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.5901699437494734E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.3950997288745202E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -2.3717082451262845E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.0916500663351889E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -3.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -3.3541019662496847E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 3.1622776601683782E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 5: return\n\n # L = 5\n self.T[5] = np.array([\n [ 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.2291251658379723E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.0156076002011403E-01, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.5687375497513918E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.5078038001005698E+00, ],\n [ 1.8750000000000002E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -2.5617376914898995E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.2185299186623562E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 9.6824583655185414E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0458250331675947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.0156076002011396E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797990E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 8.8741196746494246E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 4.1833001326703778E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 9.6824583655185414E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.0458250331675947E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -7.0156076002011396E+00, ],\n [ 3.7500000000000004E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.3311179511974137E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.2549900398011133E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.1234753829797999E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.5687375497513918E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 3.5078038001005698E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797990E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -8.8741196746494246E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -1.2549900398011133E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0246950765959600E+01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 3.8729833462074152E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 4.8412291827592707E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 5.2291251658379723E-01, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 7.0156076002011403E-01, ],\n [ 1.8750000000000002E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.5617376914898995E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 2.2185299186623562E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, -5.8094750193111260E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -4.1833001326703778E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ -5.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, -5.1234753829797999E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 0.0000000000000000E+00, 0.0000000000000000E+00, 3.8729833462074152E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n [ 1.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, 0.0000000000000000E+00, ],\n ])\n\n if max_L < 6: return\n\n raise RuntimeError('max_L too large: max_L = %d' % max_L)","source_hash":"544c235942e1acad1d86d09eca837cd486863937663ea16a486fab088eafc3e1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute#L1-L340","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":1,"end_line":340,"context_start_line":1,"context_end_line":340,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_oe_int_plan import CuestOEIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestOEIntCompute(object):\n\n @staticmethod\n def overlap(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Sptr,\n ):\n\n Sptr2 = ce.Pointer()\n Sptr2.value = np.intp(Sptr)\n\n # => Workspace query <= #\n\n overlap_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_OVERLAPCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOverlapComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outSMatrix=Sptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestOverlapCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n outSMatrix=Sptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapCompute failed')\n del overlap_compute_parameters\n\n\n @staticmethod\n def kinetic(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Tptr,\n ):\n\n Tptr2 = ce.Pointer()\n Tptr2.value = np.intp(Tptr)\n\n # => Workspace query <= #\n\n kinetic_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_KINETICCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestKineticComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outTMatrix=Tptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestKineticCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n outTMatrix=Tptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticCompute failed')\n del kinetic_compute_parameters\n\n\n @staticmethod\n def potential(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n ncharge,\n xyz,\n q, \n Vptr,\n ):\n\n Vptr2 = ce.Pointer()\n Vptr2.value = np.intp(Vptr)\n\n xyz2 = ce.Pointer()\n xyz2.value = np.intp(xyz)\n\n q2 = ce.Pointer()\n q2.value = np.intp(q)\n\n # => Workspace query <= #\n\n potential_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_POTENTIALCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPotentialComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n outVMatrix=Vptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPotentialCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n outVMatrix=Vptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialCompute failed')\n del potential_compute_parameters\n\n\n @staticmethod\n def overlap_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Gptr,\n Wptr,\n ):\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n Wptr2 = ce.Pointer()\n Wptr2.value = np.intp(Wptr)\n\n # => Workspace query <= #\n\n overlap_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_OVERLAPDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOverlapDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Wptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestOverlapDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Wptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapDerivativeCompute failed')\n del overlap_compute_parameters\n\n\n @staticmethod\n def kinetic_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Gptr,\n Dptr,\n ):\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n # => Workspace query <= #\n\n kinetic_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_KINETICDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestKineticDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestKineticDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticDerivativeCompute failed')\n del kinetic_compute_parameters\n\n\n @staticmethod\n def potential_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n ncharge,\n xyz,\n q, \n Dptr,\n GptrBasis,\n GptrCharge,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n xyz2 = ce.Pointer()\n xyz2.value = np.intp(xyz)\n\n q2 = ce.Pointer()\n q2.value = np.intp(q)\n\n GptrBasis2 = ce.Pointer()\n GptrBasis2.value = np.intp(GptrBasis)\n\n GptrCharge2 = ce.Pointer()\n GptrCharge2.value = np.intp(GptrCharge)\n\n # => Workspace query <= #\n\n potential_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_POTENTIALDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPotentialDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n densityMatrix=Dptr2,\n outBasisGradient=GptrBasis2,\n outChargeGradient=GptrCharge2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPotentialDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n densityMatrix=Dptr2,\n outBasisGradient=GptrBasis2,\n outChargeGradient=GptrCharge2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialDerivativeCompute failed')\n del potential_compute_parameters\n \n","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.CuestOEIntCompute","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.CuestOEIntCompute#L27-L338","kind":"class","name":"CuestOEIntCompute","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":27,"end_line":338,"context_start_line":7,"context_end_line":340,"code":"#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_oe_int_plan import CuestOEIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestOEIntCompute(object):\n\n @staticmethod\n def overlap(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Sptr,\n ):\n\n Sptr2 = ce.Pointer()\n Sptr2.value = np.intp(Sptr)\n\n # => Workspace query <= #\n\n overlap_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_OVERLAPCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOverlapComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outSMatrix=Sptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestOverlapCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n outSMatrix=Sptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapCompute failed')\n del overlap_compute_parameters\n\n\n @staticmethod\n def kinetic(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Tptr,\n ):\n\n Tptr2 = ce.Pointer()\n Tptr2.value = np.intp(Tptr)\n\n # => Workspace query <= #\n\n kinetic_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_KINETICCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestKineticComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outTMatrix=Tptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestKineticCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n outTMatrix=Tptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticCompute failed')\n del kinetic_compute_parameters\n\n\n @staticmethod\n def potential(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n ncharge,\n xyz,\n q, \n Vptr,\n ):\n\n Vptr2 = ce.Pointer()\n Vptr2.value = np.intp(Vptr)\n\n xyz2 = ce.Pointer()\n xyz2.value = np.intp(xyz)\n\n q2 = ce.Pointer()\n q2.value = np.intp(q)\n\n # => Workspace query <= #\n\n potential_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_POTENTIALCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPotentialComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n outVMatrix=Vptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPotentialCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n outVMatrix=Vptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialCompute failed')\n del potential_compute_parameters\n\n\n @staticmethod\n def overlap_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Gptr,\n Wptr,\n ):\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n Wptr2 = ce.Pointer()\n Wptr2.value = np.intp(Wptr)\n\n # => Workspace query <= #\n\n overlap_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_OVERLAPDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOverlapDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Wptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestOverlapDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Wptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapDerivativeCompute failed')\n del overlap_compute_parameters\n\n\n @staticmethod\n def kinetic_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Gptr,\n Dptr,\n ):\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n # => Workspace query <= #\n\n kinetic_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_KINETICDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestKineticDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestKineticDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticDerivativeCompute failed')\n del kinetic_compute_parameters\n\n\n @staticmethod\n def potential_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n ncharge,\n xyz,\n q, \n Dptr,\n GptrBasis,\n GptrCharge,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n xyz2 = ce.Pointer()\n xyz2.value = np.intp(xyz)\n\n q2 = ce.Pointer()\n q2.value = np.intp(q)\n\n GptrBasis2 = ce.Pointer()\n GptrBasis2.value = np.intp(GptrBasis)\n\n GptrCharge2 = ce.Pointer()\n GptrCharge2.value = np.intp(GptrCharge)\n\n # => Workspace query <= #\n\n potential_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_POTENTIALDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPotentialDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n densityMatrix=Dptr2,\n outBasisGradient=GptrBasis2,\n outChargeGradient=GptrCharge2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPotentialDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n densityMatrix=Dptr2,\n outBasisGradient=GptrBasis2,\n outChargeGradient=GptrCharge2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialDerivativeCompute failed')\n del potential_compute_parameters\n \n","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.overlap","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.overlap#L30-L69","kind":"function","name":"overlap","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":30,"end_line":69,"context_start_line":10,"context_end_line":89,"code":"# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_oe_int_plan import CuestOEIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestOEIntCompute(object):\n\n @staticmethod\n def overlap(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Sptr,\n ):\n\n Sptr2 = ce.Pointer()\n Sptr2.value = np.intp(Sptr)\n\n # => Workspace query <= #\n\n overlap_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_OVERLAPCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOverlapComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outSMatrix=Sptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestOverlapCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n outSMatrix=Sptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapCompute failed')\n del overlap_compute_parameters\n\n\n @staticmethod\n def kinetic(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Tptr,\n ):\n\n Tptr2 = ce.Pointer()\n Tptr2.value = np.intp(Tptr)\n\n # => Workspace query <= #\n\n kinetic_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_KINETICCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestKineticComputeWorkspaceQuery(","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.kinetic","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.kinetic#L73-L112","kind":"function","name":"kinetic","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":73,"end_line":112,"context_start_line":53,"context_end_line":132,"code":"\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestOverlapCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n outSMatrix=Sptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapCompute failed')\n del overlap_compute_parameters\n\n\n @staticmethod\n def kinetic(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Tptr,\n ):\n\n Tptr2 = ce.Pointer()\n Tptr2.value = np.intp(Tptr)\n\n # => Workspace query <= #\n\n kinetic_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_KINETICCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestKineticComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n outTMatrix=Tptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestKineticCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n outTMatrix=Tptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticCompute failed')\n del kinetic_compute_parameters\n\n\n @staticmethod\n def potential(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n ncharge,\n xyz,\n q, \n Vptr,\n ):\n\n Vptr2 = ce.Pointer()\n Vptr2.value = np.intp(Vptr)\n\n xyz2 = ce.Pointer()\n xyz2.value = np.intp(xyz)\n\n q2 = ce.Pointer()","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.potential","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.potential#L116-L170","kind":"function","name":"potential","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":116,"end_line":170,"context_start_line":96,"context_end_line":190,"code":"\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestKineticCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n outTMatrix=Tptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticCompute failed')\n del kinetic_compute_parameters\n\n\n @staticmethod\n def potential(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n ncharge,\n xyz,\n q, \n Vptr,\n ):\n\n Vptr2 = ce.Pointer()\n Vptr2.value = np.intp(Vptr)\n\n xyz2 = ce.Pointer()\n xyz2.value = np.intp(xyz)\n\n q2 = ce.Pointer()\n q2.value = np.intp(q)\n\n # => Workspace query <= #\n\n potential_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_POTENTIALCOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPotentialComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n outVMatrix=Vptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPotentialCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n outVMatrix=Vptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialCompute failed')\n del potential_compute_parameters\n\n\n @staticmethod\n def overlap_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Gptr,\n Wptr,\n ):\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n Wptr2 = ce.Pointer()\n Wptr2.value = np.intp(Wptr)\n\n # => Workspace query <= #\n\n overlap_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_OVERLAPDERIVATIVECOMPUTE_PARAMETERS)","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.overlap_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.overlap_gradient#L174-L219","kind":"function","name":"overlap_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":174,"end_line":219,"context_start_line":154,"context_end_line":239,"code":"\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPotentialCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n outVMatrix=Vptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialCompute failed')\n del potential_compute_parameters\n\n\n @staticmethod\n def overlap_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Gptr,\n Wptr,\n ):\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n Wptr2 = ce.Pointer()\n Wptr2.value = np.intp(Wptr)\n\n # => Workspace query <= #\n\n overlap_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_OVERLAPDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestOverlapDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Wptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestOverlapDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Wptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapDerivativeCompute failed')\n del overlap_compute_parameters\n\n\n @staticmethod\n def kinetic_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Gptr,\n Dptr,\n ):\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n # => Workspace query <= #\n\n kinetic_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_KINETICDERIVATIVECOMPUTE_PARAMETERS)","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.kinetic_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.kinetic_gradient#L223-L268","kind":"function","name":"kinetic_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":223,"end_line":268,"context_start_line":203,"context_end_line":288,"code":" if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestOverlapDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=overlap_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Wptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestOverlapDerivativeCompute failed')\n del overlap_compute_parameters\n\n\n @staticmethod\n def kinetic_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n Gptr,\n Dptr,\n ):\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n # => Workspace query <= #\n\n kinetic_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_KINETICDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestKineticDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestKineticDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticDerivativeCompute failed')\n del kinetic_compute_parameters\n\n\n @staticmethod\n def potential_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n ncharge,\n xyz,\n q, \n Dptr,\n GptrBasis,\n GptrCharge,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n xyz2 = ce.Pointer()\n xyz2.value = np.intp(xyz)","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.potential_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_oe_int_compute.potential_gradient#L272-L338","kind":"function","name":"potential_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":272,"end_line":338,"context_start_line":252,"context_end_line":340,"code":" if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestKineticDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=kinetic_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestKineticDerivativeCompute failed')\n del kinetic_compute_parameters\n\n\n @staticmethod\n def potential_gradient(\n *,\n handle : CuestHandle,\n oe_int_plan : CuestOEIntPlan,\n ncharge,\n xyz,\n q, \n Dptr,\n GptrBasis,\n GptrCharge,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n xyz2 = ce.Pointer()\n xyz2.value = np.intp(xyz)\n\n q2 = ce.Pointer()\n q2.value = np.intp(q)\n\n GptrBasis2 = ce.Pointer()\n GptrBasis2.value = np.intp(GptrBasis)\n\n GptrCharge2 = ce.Pointer()\n GptrCharge2.value = np.intp(GptrCharge)\n\n # => Workspace query <= #\n\n potential_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_POTENTIALDERIVATIVECOMPUTE_PARAMETERS)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPotentialDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n densityMatrix=Dptr2,\n outBasisGradient=GptrBasis2,\n outChargeGradient=GptrCharge2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialDerivativeComputeWorkspaceQuery failed')\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPotentialDerivativeCompute(\n handle=handle.handle,\n plan=oe_int_plan.oe_int_plan_handle,\n parameters=potential_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n numCharges=ncharge,\n xyz=xyz2,\n q=q2,\n densityMatrix=Dptr2,\n outBasisGradient=GptrBasis2,\n outChargeGradient=GptrCharge2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPotentialDerivativeCompute failed')\n del potential_compute_parameters\n \n","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute#L1-L228","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_compute.py","language":"python","start_line":1,"end_line":228,"context_start_line":1,"context_end_line":228,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_pcm_int_plan import CuestPCMIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\nfrom .cuest_results import CuestResults\n\nimport numpy as np\n\nclass CuestPCMIntCompute(object):\n\n @staticmethod\n def compute_pcm_energy_and_potential(\n *,\n handle : CuestHandle,\n pcm_int_plan : CuestPCMIntPlan,\n Dptr,\n inQptr,\n outQptr,\n Vptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n inQptr2 = ce.Pointer()\n inQptr2.value = np.intp(inQptr)\n\n outQptr2 = ce.Pointer()\n outQptr2.value = np.intp(outQptr)\n\n Vptr2 = ce.Pointer()\n Vptr2.value = np.intp(Vptr)\n\n # => Workspace query <= #\n\n pcm_results_handle = CuestResults(resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS, results_handle=ce.cuestPCMResultsHandle())\n # pcm parameters\n pcm_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS)\n\n convergence_threshold = ce.data_double(pcm_int_plan.convergence_tol)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS,\n parameters=pcm_compute_parameters.parameters,\n attribute=ce.CuestPCMPotentialComputeParametersAttributes.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS_CONVERGENCE_THRESHOLD,\n attributeValue=convergence_threshold,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMPotentialComputeWorkspaceQuery(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMPotentialMatrix=Vptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMPotentialComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPCMPotentialCompute(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMPotentialMatrix=Vptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMPotentialCompute failed: %d' % status)\n del pcm_compute_parameters\n\n # get results\n Epcm = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_PCM_DIELECTRIC_ENERGY,\n attributeValue=Epcm,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n converged = ce.data_int32_t()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED,\n attributeValue=converged,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n residual = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED_RESIDUAL,\n attributeValue=residual,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n del pcm_results_handle\n return Epcm.value, converged.value, residual.value\n\n @staticmethod\n def compute_pcm_gradient(\n *,\n handle : CuestHandle,\n pcm_int_plan : CuestPCMIntPlan,\n Dptr,\n inQptr,\n outQptr,\n Gptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n inQptr2 = ce.Pointer()\n inQptr2.value = np.intp(inQptr)\n\n outQptr2 = ce.Pointer()\n outQptr2.value = np.intp(outQptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n pcm_results_handle = CuestResults(resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS, results_handle=ce.cuestPCMResultsHandle())\n # pcm parameters\n pcm_derivative_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS)\n\n convergence_threshold = ce.data_double(pcm_int_plan.convergence_tol)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS,\n parameters=pcm_derivative_compute_parameters.parameters,\n attribute=ce.CuestPCMDerivativeComputeParametersAttributes.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS_CONVERGENCE_THRESHOLD,\n attributeValue=convergence_threshold,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_derivative_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMGradient=Gptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMDerivativeComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPCMDerivativeCompute(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_derivative_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMGradient=Gptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMDerivativeCompute failed: %d' % status)\n del pcm_derivative_compute_parameters\n\n # get results\n converged = ce.data_int32_t()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED,\n attributeValue=converged,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n residual = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED_RESIDUAL,\n attributeValue=residual,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n del pcm_results_handle\n return converged.value, residual.value","source_hash":"fe2ca49e5638b192dc63904be5b534f6693546b6f3446030f9c2dde80d315d9e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute.CuestPCMIntCompute","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute.CuestPCMIntCompute#L28-L228","kind":"class","name":"CuestPCMIntCompute","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_compute.py","language":"python","start_line":28,"end_line":228,"context_start_line":8,"context_end_line":228,"code":"# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_pcm_int_plan import CuestPCMIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\nfrom .cuest_results import CuestResults\n\nimport numpy as np\n\nclass CuestPCMIntCompute(object):\n\n @staticmethod\n def compute_pcm_energy_and_potential(\n *,\n handle : CuestHandle,\n pcm_int_plan : CuestPCMIntPlan,\n Dptr,\n inQptr,\n outQptr,\n Vptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n inQptr2 = ce.Pointer()\n inQptr2.value = np.intp(inQptr)\n\n outQptr2 = ce.Pointer()\n outQptr2.value = np.intp(outQptr)\n\n Vptr2 = ce.Pointer()\n Vptr2.value = np.intp(Vptr)\n\n # => Workspace query <= #\n\n pcm_results_handle = CuestResults(resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS, results_handle=ce.cuestPCMResultsHandle())\n # pcm parameters\n pcm_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS)\n\n convergence_threshold = ce.data_double(pcm_int_plan.convergence_tol)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS,\n parameters=pcm_compute_parameters.parameters,\n attribute=ce.CuestPCMPotentialComputeParametersAttributes.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS_CONVERGENCE_THRESHOLD,\n attributeValue=convergence_threshold,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMPotentialComputeWorkspaceQuery(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMPotentialMatrix=Vptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMPotentialComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPCMPotentialCompute(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMPotentialMatrix=Vptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMPotentialCompute failed: %d' % status)\n del pcm_compute_parameters\n\n # get results\n Epcm = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_PCM_DIELECTRIC_ENERGY,\n attributeValue=Epcm,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n converged = ce.data_int32_t()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED,\n attributeValue=converged,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n residual = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED_RESIDUAL,\n attributeValue=residual,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n del pcm_results_handle\n return Epcm.value, converged.value, residual.value\n\n @staticmethod\n def compute_pcm_gradient(\n *,\n handle : CuestHandle,\n pcm_int_plan : CuestPCMIntPlan,\n Dptr,\n inQptr,\n outQptr,\n Gptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n inQptr2 = ce.Pointer()\n inQptr2.value = np.intp(inQptr)\n\n outQptr2 = ce.Pointer()\n outQptr2.value = np.intp(outQptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n pcm_results_handle = CuestResults(resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS, results_handle=ce.cuestPCMResultsHandle())\n # pcm parameters\n pcm_derivative_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS)\n\n convergence_threshold = ce.data_double(pcm_int_plan.convergence_tol)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS,\n parameters=pcm_derivative_compute_parameters.parameters,\n attribute=ce.CuestPCMDerivativeComputeParametersAttributes.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS_CONVERGENCE_THRESHOLD,\n attributeValue=convergence_threshold,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_derivative_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMGradient=Gptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMDerivativeComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPCMDerivativeCompute(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_derivative_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMGradient=Gptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMDerivativeCompute failed: %d' % status)\n del pcm_derivative_compute_parameters\n\n # get results\n converged = ce.data_int32_t()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED,\n attributeValue=converged,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n residual = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED_RESIDUAL,\n attributeValue=residual,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n del pcm_results_handle\n return converged.value, residual.value","source_hash":"fe2ca49e5638b192dc63904be5b534f6693546b6f3446030f9c2dde80d315d9e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute.compute_pcm_energy_and_potential","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute.compute_pcm_energy_and_potential#L31-L134","kind":"function","name":"compute_pcm_energy_and_potential","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_compute.py","language":"python","start_line":31,"end_line":134,"context_start_line":11,"context_end_line":154,"code":"# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_pcm_int_plan import CuestPCMIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\nfrom .cuest_results import CuestResults\n\nimport numpy as np\n\nclass CuestPCMIntCompute(object):\n\n @staticmethod\n def compute_pcm_energy_and_potential(\n *,\n handle : CuestHandle,\n pcm_int_plan : CuestPCMIntPlan,\n Dptr,\n inQptr,\n outQptr,\n Vptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n inQptr2 = ce.Pointer()\n inQptr2.value = np.intp(inQptr)\n\n outQptr2 = ce.Pointer()\n outQptr2.value = np.intp(outQptr)\n\n Vptr2 = ce.Pointer()\n Vptr2.value = np.intp(Vptr)\n\n # => Workspace query <= #\n\n pcm_results_handle = CuestResults(resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS, results_handle=ce.cuestPCMResultsHandle())\n # pcm parameters\n pcm_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS)\n\n convergence_threshold = ce.data_double(pcm_int_plan.convergence_tol)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS,\n parameters=pcm_compute_parameters.parameters,\n attribute=ce.CuestPCMPotentialComputeParametersAttributes.CUEST_PCMPOTENTIALCOMPUTE_PARAMETERS_CONVERGENCE_THRESHOLD,\n attributeValue=convergence_threshold,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMPotentialComputeWorkspaceQuery(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMPotentialMatrix=Vptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMPotentialComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPCMPotentialCompute(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMPotentialMatrix=Vptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMPotentialCompute failed: %d' % status)\n del pcm_compute_parameters\n\n # get results\n Epcm = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_PCM_DIELECTRIC_ENERGY,\n attributeValue=Epcm,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n converged = ce.data_int32_t()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED,\n attributeValue=converged,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n residual = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED_RESIDUAL,\n attributeValue=residual,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n del pcm_results_handle\n return Epcm.value, converged.value, residual.value\n\n @staticmethod\n def compute_pcm_gradient(\n *,\n handle : CuestHandle,\n pcm_int_plan : CuestPCMIntPlan,\n Dptr,\n inQptr,\n outQptr,\n Gptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n inQptr2 = ce.Pointer()\n inQptr2.value = np.intp(inQptr)\n\n outQptr2 = ce.Pointer()\n outQptr2.value = np.intp(outQptr)","source_hash":"fe2ca49e5638b192dc63904be5b534f6693546b6f3446030f9c2dde80d315d9e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute.compute_pcm_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_pcm_int_compute.compute_pcm_gradient#L137-L228","kind":"function","name":"compute_pcm_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_compute.py","language":"python","start_line":137,"end_line":228,"context_start_line":117,"context_end_line":228,"code":" attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED,\n attributeValue=converged,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n residual = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED_RESIDUAL,\n attributeValue=residual,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n del pcm_results_handle\n return Epcm.value, converged.value, residual.value\n\n @staticmethod\n def compute_pcm_gradient(\n *,\n handle : CuestHandle,\n pcm_int_plan : CuestPCMIntPlan,\n Dptr,\n inQptr,\n outQptr,\n Gptr,\n ):\n\n Dptr2 = ce.Pointer()\n Dptr2.value = np.intp(Dptr)\n\n inQptr2 = ce.Pointer()\n inQptr2.value = np.intp(inQptr)\n\n outQptr2 = ce.Pointer()\n outQptr2.value = np.intp(outQptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n pcm_results_handle = CuestResults(resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS, results_handle=ce.cuestPCMResultsHandle())\n # pcm parameters\n pcm_derivative_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS)\n\n convergence_threshold = ce.data_double(pcm_int_plan.convergence_tol)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS,\n parameters=pcm_derivative_compute_parameters.parameters,\n attribute=ce.CuestPCMDerivativeComputeParametersAttributes.CUEST_PCMDERIVATIVECOMPUTE_PARAMETERS_CONVERGENCE_THRESHOLD,\n attributeValue=convergence_threshold,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestPCMDerivativeComputeWorkspaceQuery(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_derivative_compute_parameters.parameters,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMGradient=Gptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMDerivativeComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestPCMDerivativeCompute(\n handle=handle.handle,\n plan=pcm_int_plan.pcm_int_plan_handle,\n parameters=pcm_derivative_compute_parameters.parameters,\n temporaryWorkspace=temporary_workspace.pointer,\n densityMatrix=Dptr2,\n inQ=inQptr2,\n outQ=outQptr2,\n outPCMResults=pcm_results_handle.results,\n outPCMGradient=Gptr2,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestPCMDerivativeCompute failed: %d' % status)\n del pcm_derivative_compute_parameters\n\n # get results\n converged = ce.data_int32_t()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED,\n attributeValue=converged,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n residual = ce.data_double()\n status = ce.cuestResultsQuery(\n resultsType=ce.CuestResultsType.CUEST_PCM_RESULTS,\n results=pcm_results_handle.results,\n attribute=ce.CuestPCMResultAttributes.CUEST_PCMRESULT_CONVERGED_RESIDUAL,\n attributeValue=residual,\n )\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestResultsQuery failed: %d' % status)\n\n del pcm_results_handle\n return converged.value, residual.value","source_hash":"fe2ca49e5638b192dc63904be5b534f6693546b6f3446030f9c2dde80d315d9e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_overlap","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.sad_overlap#L1-L132","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.sad_overlap","path":"cuEST/cuest_scf_examples/cuest_scf/sad_overlap.py","language":"python","start_line":1,"end_line":132,"context_start_line":1,"context_end_line":132,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .ao_basis import AOBasis\n\nfrom .sad_solid_harmonics import SADSolidHarmonics\n\nclass SADOverlap(object):\n\n @staticmethod\n def compute_atomic_overlap(\n *,\n basis1 : AOBasis,\n basis2 : AOBasis,\n ): \n\n if basis1.natom != 1: raise RuntimeError('basis1.natom != 1')\n if basis2.natom != 1: raise RuntimeError('basis2.natom != 1')\n\n if basis1.is_mixed: raise RuntimeError('basis1 is mixed')\n if basis2.is_mixed: raise RuntimeError('basis2 is mixed')\n\n df = [1.0]\n for L in range(2, basis1.max_L + basis2.max_L + 1, 2):\n df.append(df[L // 2 - 1] * (L - 1.0))\n\n Scc = np.zeros((basis1.ncart, basis2.ncart))\n\n for P1, shell1 in enumerate(basis1.shells[0]):\n L1 = shell1.L\n offset1 = basis1.shell_cart_starts[P1]\n\n for P2, shell2 in enumerate(basis2.shells[0]):\n L2 = shell2.L\n offset2 = basis2.shell_cart_starts[P2]\n\n for e1, c1 in zip(shell1.exponents, shell1.coefficients):\n for e2, c2 in zip(shell2.exponents, shell2.coefficients):\n\n c12 = c1 * c2\n e12 = e1 + e2\n\n S0 = c12 * (np.pi / e12)**(1.5) * (2 * e12)**(-0.5 * (L1 + L2))\n\n index1 = 0\n for i1 in range(L1+1):\n l1 = L1 - i1\n for j1 in range(i1+1):\n m1 = i1 - j1\n n1 = j1 \n\n index2 = 0\n for i2 in range(L2+1):\n l2 = L2 - i2\n for j2 in range(i2+1):\n m2 = i2 - j2\n n2 = j2 \n\n l12 = l1 + l2 \n m12 = m1 + m2 \n n12 = n1 + n2 \n\n if l12 % 2 == 1: \n index2 += 1\n continue\n if m12 % 2 == 1: \n index2 += 1\n continue\n if n12 % 2 == 1: \n index2 += 1\n continue\n\n S = S0 * df[l12 // 2] * df[m12 // 2] * df[n12 // 2]\n\n cart1 = offset1 + index1\n cart2 = offset2 + index2\n \n Scc[cart1, cart2] += S\n\n index2 += 1\n \n index1 += 1\n\n if basis1.is_cart and basis2.is_cart:\n return Scc\n\n max_L = 0\n if basis1.is_pure: max_L = max(max_L, basis1.max_L)\n if basis2.is_pure: max_L = max(max_L, basis2.max_L)\n sh = SADSolidHarmonics(max_L=max_L)\n\n if basis2.is_pure:\n Scs = np.zeros((basis1.ncart, basis2.nao))\n for P2, shell2 in enumerate(basis2.shells[0]):\n L2 = shell2.L\n ncart2 = (L2 + 1) * (L2 + 2) // 2\n npure2 = 2 * L2 + 1\n cart_offset2 = basis2.shell_cart_starts[P2]\n pure_offset2 = basis2.shell_ao_starts[P2]\n T = sh.T[L2]\n Scs[:, pure_offset2:pure_offset2+npure2] = np.dot(Scc[:, cart_offset2:cart_offset2+ncart2], T)\n else:\n Scs = Scc\n\n if basis1.is_pure:\n Sss = np.zeros((basis1.nao, basis2.nao))\n for P1, shell1 in enumerate(basis1.shells[0]):\n L1 = shell1.L\n ncart1 = (L1 + 1) * (L1 + 2) // 2\n npure1 = 2 * L1 + 1\n cart_offset1 = basis1.shell_cart_starts[P1]\n pure_offset1 = basis1.shell_ao_starts[P1]\n T = sh.T[L1]\n Sss[pure_offset1:pure_offset1+npure1, :] = np.dot(T.T, Scs[cart_offset1:cart_offset1+ncart1, :])\n else:\n Sss = Scs\n\n return Sss","source_hash":"0706a9bcb1b232f62d8619e3aff5302f1f616498b9b25b3c4d035c52e8d9b52d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_overlap.SADOverlap","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.sad_overlap.SADOverlap#L22-L132","kind":"class","name":"SADOverlap","path":"cuEST/cuest_scf_examples/cuest_scf/sad_overlap.py","language":"python","start_line":22,"end_line":132,"context_start_line":2,"context_end_line":132,"code":"# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .ao_basis import AOBasis\n\nfrom .sad_solid_harmonics import SADSolidHarmonics\n\nclass SADOverlap(object):\n\n @staticmethod\n def compute_atomic_overlap(\n *,\n basis1 : AOBasis,\n basis2 : AOBasis,\n ): \n\n if basis1.natom != 1: raise RuntimeError('basis1.natom != 1')\n if basis2.natom != 1: raise RuntimeError('basis2.natom != 1')\n\n if basis1.is_mixed: raise RuntimeError('basis1 is mixed')\n if basis2.is_mixed: raise RuntimeError('basis2 is mixed')\n\n df = [1.0]\n for L in range(2, basis1.max_L + basis2.max_L + 1, 2):\n df.append(df[L // 2 - 1] * (L - 1.0))\n\n Scc = np.zeros((basis1.ncart, basis2.ncart))\n\n for P1, shell1 in enumerate(basis1.shells[0]):\n L1 = shell1.L\n offset1 = basis1.shell_cart_starts[P1]\n\n for P2, shell2 in enumerate(basis2.shells[0]):\n L2 = shell2.L\n offset2 = basis2.shell_cart_starts[P2]\n\n for e1, c1 in zip(shell1.exponents, shell1.coefficients):\n for e2, c2 in zip(shell2.exponents, shell2.coefficients):\n\n c12 = c1 * c2\n e12 = e1 + e2\n\n S0 = c12 * (np.pi / e12)**(1.5) * (2 * e12)**(-0.5 * (L1 + L2))\n\n index1 = 0\n for i1 in range(L1+1):\n l1 = L1 - i1\n for j1 in range(i1+1):\n m1 = i1 - j1\n n1 = j1 \n\n index2 = 0\n for i2 in range(L2+1):\n l2 = L2 - i2\n for j2 in range(i2+1):\n m2 = i2 - j2\n n2 = j2 \n\n l12 = l1 + l2 \n m12 = m1 + m2 \n n12 = n1 + n2 \n\n if l12 % 2 == 1: \n index2 += 1\n continue\n if m12 % 2 == 1: \n index2 += 1\n continue\n if n12 % 2 == 1: \n index2 += 1\n continue\n\n S = S0 * df[l12 // 2] * df[m12 // 2] * df[n12 // 2]\n\n cart1 = offset1 + index1\n cart2 = offset2 + index2\n \n Scc[cart1, cart2] += S\n\n index2 += 1\n \n index1 += 1\n\n if basis1.is_cart and basis2.is_cart:\n return Scc\n\n max_L = 0\n if basis1.is_pure: max_L = max(max_L, basis1.max_L)\n if basis2.is_pure: max_L = max(max_L, basis2.max_L)\n sh = SADSolidHarmonics(max_L=max_L)\n\n if basis2.is_pure:\n Scs = np.zeros((basis1.ncart, basis2.nao))\n for P2, shell2 in enumerate(basis2.shells[0]):\n L2 = shell2.L\n ncart2 = (L2 + 1) * (L2 + 2) // 2\n npure2 = 2 * L2 + 1\n cart_offset2 = basis2.shell_cart_starts[P2]\n pure_offset2 = basis2.shell_ao_starts[P2]\n T = sh.T[L2]\n Scs[:, pure_offset2:pure_offset2+npure2] = np.dot(Scc[:, cart_offset2:cart_offset2+ncart2], T)\n else:\n Scs = Scc\n\n if basis1.is_pure:\n Sss = np.zeros((basis1.nao, basis2.nao))\n for P1, shell1 in enumerate(basis1.shells[0]):\n L1 = shell1.L\n ncart1 = (L1 + 1) * (L1 + 2) // 2\n npure1 = 2 * L1 + 1\n cart_offset1 = basis1.shell_cart_starts[P1]\n pure_offset1 = basis1.shell_ao_starts[P1]\n T = sh.T[L1]\n Sss[pure_offset1:pure_offset1+npure1, :] = np.dot(T.T, Scs[cart_offset1:cart_offset1+ncart1, :])\n else:\n Sss = Scs\n\n return Sss","source_hash":"0706a9bcb1b232f62d8619e3aff5302f1f616498b9b25b3c4d035c52e8d9b52d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.sad_overlap.compute_atomic_overlap","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.sad_overlap.compute_atomic_overlap#L25-L132","kind":"function","name":"compute_atomic_overlap","path":"cuEST/cuest_scf_examples/cuest_scf/sad_overlap.py","language":"python","start_line":25,"end_line":132,"context_start_line":5,"context_end_line":132,"code":"# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .ao_basis import AOBasis\n\nfrom .sad_solid_harmonics import SADSolidHarmonics\n\nclass SADOverlap(object):\n\n @staticmethod\n def compute_atomic_overlap(\n *,\n basis1 : AOBasis,\n basis2 : AOBasis,\n ): \n\n if basis1.natom != 1: raise RuntimeError('basis1.natom != 1')\n if basis2.natom != 1: raise RuntimeError('basis2.natom != 1')\n\n if basis1.is_mixed: raise RuntimeError('basis1 is mixed')\n if basis2.is_mixed: raise RuntimeError('basis2 is mixed')\n\n df = [1.0]\n for L in range(2, basis1.max_L + basis2.max_L + 1, 2):\n df.append(df[L // 2 - 1] * (L - 1.0))\n\n Scc = np.zeros((basis1.ncart, basis2.ncart))\n\n for P1, shell1 in enumerate(basis1.shells[0]):\n L1 = shell1.L\n offset1 = basis1.shell_cart_starts[P1]\n\n for P2, shell2 in enumerate(basis2.shells[0]):\n L2 = shell2.L\n offset2 = basis2.shell_cart_starts[P2]\n\n for e1, c1 in zip(shell1.exponents, shell1.coefficients):\n for e2, c2 in zip(shell2.exponents, shell2.coefficients):\n\n c12 = c1 * c2\n e12 = e1 + e2\n\n S0 = c12 * (np.pi / e12)**(1.5) * (2 * e12)**(-0.5 * (L1 + L2))\n\n index1 = 0\n for i1 in range(L1+1):\n l1 = L1 - i1\n for j1 in range(i1+1):\n m1 = i1 - j1\n n1 = j1 \n\n index2 = 0\n for i2 in range(L2+1):\n l2 = L2 - i2\n for j2 in range(i2+1):\n m2 = i2 - j2\n n2 = j2 \n\n l12 = l1 + l2 \n m12 = m1 + m2 \n n12 = n1 + n2 \n\n if l12 % 2 == 1: \n index2 += 1\n continue\n if m12 % 2 == 1: \n index2 += 1\n continue\n if n12 % 2 == 1: \n index2 += 1\n continue\n\n S = S0 * df[l12 // 2] * df[m12 // 2] * df[n12 // 2]\n\n cart1 = offset1 + index1\n cart2 = offset2 + index2\n \n Scc[cart1, cart2] += S\n\n index2 += 1\n \n index1 += 1\n\n if basis1.is_cart and basis2.is_cart:\n return Scc\n\n max_L = 0\n if basis1.is_pure: max_L = max(max_L, basis1.max_L)\n if basis2.is_pure: max_L = max(max_L, basis2.max_L)\n sh = SADSolidHarmonics(max_L=max_L)\n\n if basis2.is_pure:\n Scs = np.zeros((basis1.ncart, basis2.nao))\n for P2, shell2 in enumerate(basis2.shells[0]):\n L2 = shell2.L\n ncart2 = (L2 + 1) * (L2 + 2) // 2\n npure2 = 2 * L2 + 1\n cart_offset2 = basis2.shell_cart_starts[P2]\n pure_offset2 = basis2.shell_ao_starts[P2]\n T = sh.T[L2]\n Scs[:, pure_offset2:pure_offset2+npure2] = np.dot(Scc[:, cart_offset2:cart_offset2+ncart2], T)\n else:\n Scs = Scc\n\n if basis1.is_pure:\n Sss = np.zeros((basis1.nao, basis2.nao))\n for P1, shell1 in enumerate(basis1.shells[0]):\n L1 = shell1.L\n ncart1 = (L1 + 1) * (L1 + 2) // 2\n npure1 = 2 * L1 + 1\n cart_offset1 = basis1.shell_cart_starts[P1]\n pure_offset1 = basis1.shell_ao_starts[P1]\n T = sh.T[L1]\n Sss[pure_offset1:pure_offset1+npure1, :] = np.dot(T.T, Scs[cart_offset1:cart_offset1+ncart1, :])\n else:\n Sss = Scs\n\n return Sss","source_hash":"0706a9bcb1b232f62d8619e3aff5302f1f616498b9b25b3c4d035c52e8d9b52d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute#L1-L348","kind":"module","name":"cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","language":"python","start_line":1,"end_line":348,"context_start_line":1,"context_end_line":348,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_xc_int_plan import CuestXCIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestXCIntCompute(object):\n\n @staticmethod\n def local_exchange_correlation(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Vxcptr,\n ):\n\n Exc = ce.data_double()\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Vxcptr2 = ce.Pointer()\n Vxcptr2.value = np.intp(Vxcptr)\n\n # => Workspace query <= #\n xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCPotentialRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestXCPotentialRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCPotentialRKSCompute failed: %d' % status)\n del xc_compute_parameters\n\n return Exc.value \n\n @staticmethod\n def nonlocal_exchange_correlation(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Vxcptr,\n ):\n\n Exc = ce.data_double()\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Vxcptr2 = ce.Pointer()\n Vxcptr2.value = np.intp(Vxcptr)\n\n # => VV10 parameters <= #\n nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS)\n\n vv10_b = ce.data_double(xc_int_plan.vv10_b)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_C = ce.data_double(xc_int_plan.vv10_c)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_scale = ce.data_double(xc_int_plan.vv10_scale)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n # => Workspace query <= #\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestNonlocalXCPotentialRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestNonlocalXCPotentialRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCPotentialRKSCompute failed: %d' % status)\n del nonlocal_xc_compute_parameters\n\n return Exc.value \n\n @staticmethod\n def local_exchange_correlation_gradient(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Gptr,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => Workspace query <= #\n xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCDerivativeRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestXCDerivativeRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCDerivativeRKSCompute failed: %d' % status)\n del xc_compute_parameters\n\n\n @staticmethod\n def nonlocal_exchange_correlation_gradient(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Gptr,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => VV10 parameters <= #\n nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS)\n\n vv10_b = ce.data_double(xc_int_plan.vv10_b)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_C = ce.data_double(xc_int_plan.vv10_c)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_scale = ce.data_double(xc_int_plan.vv10_scale)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n # => Workspace query <= #\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestNonlocalXCDerivativeRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCDerivativeRKSCompute failed: %d' % status)\n del nonlocal_xc_compute_parameters\n\n","source_hash":"c9ca0cdb43480b5b675a34250bfe5e6dc5ae292136478e7bd6927dc71e672a7d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.CuestXCIntCompute","uri":"program://CUDALibrarySamples/class/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.CuestXCIntCompute#L27-L346","kind":"class","name":"CuestXCIntCompute","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","language":"python","start_line":27,"end_line":346,"context_start_line":7,"context_end_line":348,"code":"#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_xc_int_plan import CuestXCIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestXCIntCompute(object):\n\n @staticmethod\n def local_exchange_correlation(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Vxcptr,\n ):\n\n Exc = ce.data_double()\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Vxcptr2 = ce.Pointer()\n Vxcptr2.value = np.intp(Vxcptr)\n\n # => Workspace query <= #\n xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCPotentialRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestXCPotentialRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCPotentialRKSCompute failed: %d' % status)\n del xc_compute_parameters\n\n return Exc.value \n\n @staticmethod\n def nonlocal_exchange_correlation(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Vxcptr,\n ):\n\n Exc = ce.data_double()\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Vxcptr2 = ce.Pointer()\n Vxcptr2.value = np.intp(Vxcptr)\n\n # => VV10 parameters <= #\n nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS)\n\n vv10_b = ce.data_double(xc_int_plan.vv10_b)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_C = ce.data_double(xc_int_plan.vv10_c)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_scale = ce.data_double(xc_int_plan.vv10_scale)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n # => Workspace query <= #\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestNonlocalXCPotentialRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestNonlocalXCPotentialRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCPotentialRKSCompute failed: %d' % status)\n del nonlocal_xc_compute_parameters\n\n return Exc.value \n\n @staticmethod\n def local_exchange_correlation_gradient(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Gptr,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => Workspace query <= #\n xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCDerivativeRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestXCDerivativeRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCDerivativeRKSCompute failed: %d' % status)\n del xc_compute_parameters\n\n\n @staticmethod\n def nonlocal_exchange_correlation_gradient(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Gptr,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => VV10 parameters <= #\n nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS)\n\n vv10_b = ce.data_double(xc_int_plan.vv10_b)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_C = ce.data_double(xc_int_plan.vv10_c)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_scale = ce.data_double(xc_int_plan.vv10_scale)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n # => Workspace query <= #\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestNonlocalXCDerivativeRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCDerivativeRKSCompute failed: %d' % status)\n del nonlocal_xc_compute_parameters\n\n","source_hash":"c9ca0cdb43480b5b675a34250bfe5e6dc5ae292136478e7bd6927dc71e672a7d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.local_exchange_correlation","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.local_exchange_correlation#L30-L92","kind":"function","name":"local_exchange_correlation","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","language":"python","start_line":30,"end_line":92,"context_start_line":10,"context_end_line":112,"code":"# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_xc_int_plan import CuestXCIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\nfrom .cuest_parameters import CuestParameters\n\nimport numpy as np\n\nclass CuestXCIntCompute(object):\n\n @staticmethod\n def local_exchange_correlation(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Vxcptr,\n ):\n\n Exc = ce.data_double()\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Vxcptr2 = ce.Pointer()\n Vxcptr2.value = np.intp(Vxcptr)\n\n # => Workspace query <= #\n xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCPotentialRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestXCPotentialRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCPotentialRKSCompute failed: %d' % status)\n del xc_compute_parameters\n\n return Exc.value \n\n @staticmethod\n def nonlocal_exchange_correlation(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Vxcptr,\n ):\n\n Exc = ce.data_double()\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Vxcptr2 = ce.Pointer()\n Vxcptr2.value = np.intp(Vxcptr)\n\n # => VV10 parameters <= #","source_hash":"c9ca0cdb43480b5b675a34250bfe5e6dc5ae292136478e7bd6927dc71e672a7d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.nonlocal_exchange_correlation","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.nonlocal_exchange_correlation#L95-L192","kind":"function","name":"nonlocal_exchange_correlation","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","language":"python","start_line":95,"end_line":192,"context_start_line":75,"context_end_line":212,"code":"\n status = ce.cuestXCPotentialRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCPotentialRKSCompute failed: %d' % status)\n del xc_compute_parameters\n\n return Exc.value \n\n @staticmethod\n def nonlocal_exchange_correlation(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Vxcptr,\n ):\n\n Exc = ce.data_double()\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Vxcptr2 = ce.Pointer()\n Vxcptr2.value = np.intp(Vxcptr)\n\n # => VV10 parameters <= #\n nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS)\n\n vv10_b = ce.data_double(xc_int_plan.vv10_b)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_C = ce.data_double(xc_int_plan.vv10_c)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_scale = ce.data_double(xc_int_plan.vv10_scale)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n # => Workspace query <= #\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestNonlocalXCPotentialRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestNonlocalXCPotentialRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCPotentialRKSCompute failed: %d' % status)\n del nonlocal_xc_compute_parameters\n\n return Exc.value \n\n @staticmethod\n def local_exchange_correlation_gradient(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Gptr,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => Workspace query <= #\n xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS)\n","source_hash":"c9ca0cdb43480b5b675a34250bfe5e6dc5ae292136478e7bd6927dc71e672a7d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.local_exchange_correlation_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.local_exchange_correlation_gradient#L195-L251","kind":"function","name":"local_exchange_correlation_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","language":"python","start_line":195,"end_line":251,"context_start_line":175,"context_end_line":271,"code":"\n status = ce.cuestNonlocalXCPotentialRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outXCEnergy=Exc,\n outXCPotentialMatrix=Vxcptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCPotentialRKSCompute failed: %d' % status)\n del nonlocal_xc_compute_parameters\n\n return Exc.value \n\n @staticmethod\n def local_exchange_correlation_gradient(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Gptr,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => Workspace query <= #\n xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS)\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestXCDerivativeRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestXCDerivativeRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCDerivativeRKSCompute failed: %d' % status)\n del xc_compute_parameters\n\n\n @staticmethod\n def nonlocal_exchange_correlation_gradient(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Gptr,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => VV10 parameters <= #\n nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS)","source_hash":"c9ca0cdb43480b5b675a34250bfe5e6dc5ae292136478e7bd6927dc71e672a7d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.nonlocal_exchange_correlation_gradient","uri":"program://CUDALibrarySamples/function/cuEST.cuest_scf_examples.cuest_scf.cuest_xc_int_compute.nonlocal_exchange_correlation_gradient#L255-L346","kind":"function","name":"nonlocal_exchange_correlation_gradient","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","language":"python","start_line":255,"end_line":346,"context_start_line":235,"context_end_line":348,"code":"\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestXCDerivativeRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestXCDerivativeRKSCompute failed: %d' % status)\n del xc_compute_parameters\n\n\n @staticmethod\n def nonlocal_exchange_correlation_gradient(\n *,\n handle : CuestHandle,\n xc_int_plan : CuestXCIntPlan,\n nocc,\n Coccptr,\n Gptr,\n ):\n\n Coccptr2 = ce.Pointer()\n Coccptr2.value = np.intp(Coccptr)\n\n Gptr2 = ce.Pointer()\n Gptr2.value = np.intp(Gptr)\n\n # => VV10 parameters <= #\n nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS)\n\n vv10_b = ce.data_double(xc_int_plan.vv10_b)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_B,\n attributeValue=vv10_b,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_C = ce.data_double(xc_int_plan.vv10_c)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_C,\n attributeValue=vv10_C,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n vv10_scale = ce.data_double(xc_int_plan.vv10_scale)\n status = ce.cuestParametersConfigure(\n parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,\n parameters=nonlocal_xc_compute_parameters.parameters,\n attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_SCALE,\n attributeValue=vv10_scale,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestParametersConfigure failed: %d' % status)\n\n # => Workspace query <= #\n\n # Allow the algorithm to use up to 2GB of DRAM\n # NOTE: Production codes may wish to configure the maximum temporary\n # workspace memory as a user parameter or heuristic\n xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(\n deviceBufferSizeInBytes=2000000000,\n )\n\n temporary_workspace_descriptor = CuestWorkspaceDescriptor()\n\n status = ce.cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)\n\n temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)\n\n status = ce.cuestNonlocalXCDerivativeRKSCompute(\n handle=handle.handle,\n plan=xc_int_plan.xc_int_plan_handle,\n parameters=nonlocal_xc_compute_parameters.parameters,\n variableBufferSize=xcint_variable_buffer_descriptor.pointer,\n temporaryWorkspace=temporary_workspace.pointer,\n numOccupied=nocc,\n coefficientMatrix=Coccptr2,\n outGradient=Gptr2,\n )\n\n if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:\n raise RuntimeError('cuestNonlocalXCDerivativeRKSCompute failed: %d' % status)\n del nonlocal_xc_compute_parameters\n\n","source_hash":"c9ca0cdb43480b5b675a34250bfe5e6dc5ae292136478e7bd6927dc71e672a7d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"py:cuEST.cuest_scf_examples.examples.rhf-1.test","uri":"program://CUDALibrarySamples/module/cuEST.cuest_scf_examples.examples.rhf-1.test#L1-L99","kind":"module","name":"cuEST.cuest_scf_examples.examples.rhf-1.test","path":"cuEST/cuest_scf_examples/examples/rhf-1/test.py","language":"python","start_line":1,"end_line":99,"context_start_line":1,"context_end_line":99,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n\n# Usually you want one CuestHandle for many computations - e.g., do not spin up\n# separate handles for every RHF instance\ncuest_handle = cuest_scf.CuestHandle()\n\n# This will set the cuEST handle so all operations are performed with FP64 arithmetic\n# cuest_handle.set_math_mode(mode=ce.CuestMathMode.CUEST_NATIVE_FP64_MATH_MODE)\n\n# Reasonable default - as coarse as 1.0E-10 yields high-precision results\n# Coarser can save some CoreDF memory and lower runtime\nthreshold_pq = 1.0E-10\n\nmolecule = cuest_scf.Molecule.parse_from_xyz_file('paxlovid.xyz')\n#molecule = cuest_scf.Molecule.parse_from_xyz_file('192atoms_benzene16.xyz')\ncharge = 0\n\nprimary_name = 'def2-tzvp'\nauxiliary_name = 'def2-universal-jkfit'\nminao_name = 'minao-1'\n\nprimary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))\nauxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))\nminao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))\n\nprimary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)\nauxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)\nminao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)\n\nrhf = cuest_scf.RHF(\n cuest_handle=cuest_handle,\n molecule=molecule,\n charge=charge,\n# NOTE: xc_functional_name is used to specify the XC functional.\n# Currently supported functionals are listed below. \n xc_functional_name='HF',\n #xc_functional_name='B3LYP1',\n #xc_functional_name='B3LYP5',\n# xc_functional_name='B97',\n# xc_functional_name='BLYP',\n# xc_functional_name='M06-L',\n# xc_functional_name='PBE',\n# xc_functional_name='PBE0',\n# xc_functional_name='r2SCAN',\n# xc_functional_name='SVWN5',\n #xc_functional_name='B97M-V',\n primary=primary,\n auxiliary=auxiliary,\n minao=minao,\n primary_name=primary_name,\n auxiliary_name=auxiliary_name,\n minao_name=minao_name,\n threshold_pq=threshold_pq,\n df_fitting_eigenvalue_cutoff=1.0e-12,\n # NOTE: Delicate applications or tight comparisons of gradients may require\n # tighter than the working default of g_convergence=1.0E-6\n # g_convergence=1.0E-8,\n xc_grid_family=\"SG\",\n xc_grid_level=1,\n xc_threshold_collocation=1.0e-18, # Collocation threshold for local XC potential\n nlc_threshold_collocation=1.0e-18, # Collocation threshold for nonlocal (VV10) potential\n dfk_int8_modulus_count_start=8,\n dfk_int8_modulus_count_end=8,\n dfk_int8_slice_count_start=5,\n dfk_int8_slice_count_end=5,\n pcm_num_angular_points_per_hydrogen_atom=110,\n pcm_num_angular_points_per_heavy_atom=194,\n pcm_epsilon=1.0,\n pcm_cutoff=1e-10,\n pcm_convergence_tol=1e-10,\n )\n\nrhf.solve()\n\nprint('SCF Energy: %24.16E' % (rhf.compute_energy()))\nprint('')\n\n#print('SCF Gradient:')\n#print(rhf.compute_gradient().to_numpy())","source_hash":"b31c21fa6f0c92c002383e1da4c4dc7374ea972ea1a23a3b2d8a61f3ebc8c478","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:NPP/nppCanny/npp_canny_simple.py","uri":"program://CUDALibrarySamples/file/NPP/nppCanny/npp_canny_simple.py","kind":"file","name":"NPP/nppCanny/npp_canny_simple.py","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nNPP 3-Channel Canny Edge Detection - Simple Example\n====================================================\n\nDetects edges in color images using NVIDIA NPP.\n20x faster than OpenCV, detects 60% more edges.","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:NPP/nppCanny/npp_canny_simple.cpp","uri":"program://CUDALibrarySamples/file/NPP/nppCanny/npp_canny_simple.cpp","kind":"file","name":"NPP/nppCanny/npp_canny_simple.cpp","path":"NPP/nppCanny/npp_canny_simple.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nNPP 3-Channel Canny Edge Detection - Simple Example\n====================================================\n\nDetects edges in color images using NVIDIA NPP.\n20x faster than OpenCV, detects 60% more edges.","source_hash":"2234be4a8099a7fcc45b5174bd10e2eb9716c5692d47ae3a065b92728881be87","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:nvMatmulHeuristics/5_get_configs.py","uri":"program://CUDALibrarySamples/file/nvMatmulHeuristics/5_get_configs.py","kind":"file","name":"nvMatmulHeuristics/5_get_configs.py","path":"nvMatmulHeuristics/5_get_configs.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#!/usr/bin/env python3\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport sys\n\nfrom nvMatmulHeuristics import (","source_hash":"f9a5426507cdbdf27b6825d4b6e2d06daaa200ae8dc67e6e1079307334868cf0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:nvMatmulHeuristics/7_smem_carveout.py","uri":"program://CUDALibrarySamples/file/nvMatmulHeuristics/7_smem_carveout.py","kind":"file","name":"nvMatmulHeuristics/7_smem_carveout.py","path":"nvMatmulHeuristics/7_smem_carveout.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#!/usr/bin/env python3\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport ctypes\nimport sys\n","source_hash":"e98cee2a04a1554e53ded6923a242b33b6613dda9ad7687da4d09302dd6968c1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:nvMatmulHeuristics/6_get_configs_ex.py","uri":"program://CUDALibrarySamples/file/nvMatmulHeuristics/6_get_configs_ex.py","kind":"file","name":"nvMatmulHeuristics/6_get_configs_ex.py","path":"nvMatmulHeuristics/6_get_configs_ex.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#!/usr/bin/env python3\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\nimport sys\n\nfrom nvMatmulHeuristics import (","source_hash":"c8e84920ab1e83cb90e60a289983efb6b6619c65b71586c0e60e1e33e1eac47a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","uri":"program://CUDALibrarySamples/file/NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","kind":"file","name":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","path":"NPP+/cannyEdgeDetectorPython/cannyEdgeDetector.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport os\nimport time\nimport cv2\nimport torch\nimport ctypes\nimport numpy as np","source_hash":"74c58b322283e9979d26a793b915291db457f2a4c33515947e82608c4ee1fe16","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/setup.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/setup.py","kind":"file","name":"cuTENSOR/python/setup.py","path":"cuTENSOR/python/setup.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"40da31ad5e62ed57625f64836a01bb5a6e98b0377bb5157c5c91e3f27f44cd00","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/common.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/common.py","kind":"file","name":"cuTENSOR/python/cutensor/common.py","path":"cuTENSOR/python/cutensor/common.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"39de8aec45a7a7eb78b137c1102e2c3c60468c8ff9fe3fe1b5920ea6e46c3995","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/c_extensions.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/c_extensions.py","kind":"file","name":"cuTENSOR/python/cutensor/c_extensions.py","path":"cuTENSOR/python/cutensor/c_extensions.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"8db515da87f6b15ff4a8c57773c3628cb53e60c4fb6b7b4b4031511e89f26752","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/__init__.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/__init__.py","kind":"file","name":"cuTENSOR/python/cutensor/__init__.py","path":"cuTENSOR/python/cutensor/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"38dcc79f99bf1857d52d0e388b37bf34419e797c72276726519972db7eddd56a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/c_extensions_utils.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/c_extensions_utils.py","kind":"file","name":"cuTENSOR/python/cutensor/c_extensions_utils.py","path":"cuTENSOR/python/cutensor/c_extensions_utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"1a3308912e942fb1c001012f5ace9c67d49ee32e7fad080d516eca679b63f337","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/package_info.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/package_info.py","kind":"file","name":"cuTENSOR/python/cutensor/package_info.py","path":"cuTENSOR/python/cutensor/package_info.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"7d2fb8fe25e907d639b06b534620fd5ac2fe4b1bbe8543faef8000c1d08fdc62","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/torch/einsum_test.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/torch/einsum_test.py","kind":"file","name":"cuTENSOR/python/cutensor/torch/einsum_test.py","path":"cuTENSOR/python/cutensor/torch/einsum_test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"62eb53281ef757a7f0c88017e6fe41e49825ceb7a9bce5ad720479e04a629cf9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/torch/einsum.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/torch/einsum.py","kind":"file","name":"cuTENSOR/python/cutensor/torch/einsum.py","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/torch/__init__.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/torch/__init__.py","kind":"file","name":"cuTENSOR/python/cutensor/torch/__init__.py","path":"cuTENSOR/python/cutensor/torch/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"1cbee08356fc6c5d28a78167079e97bb1f2bf8bddc639756f04e27b1b7011804","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/torch/einsum.cc","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/torch/einsum.cc","kind":"file","name":"cuTENSOR/python/cutensor/torch/einsum.cc","path":"cuTENSOR/python/cutensor/torch/einsum.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"030e0ab60d85a768e5cd84e34e3da941ef60989aa1278d68d607bd07d36ed1a9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/tensorflow/einsum_test.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/tensorflow/einsum_test.py","kind":"file","name":"cuTENSOR/python/cutensor/tensorflow/einsum_test.py","path":"cuTENSOR/python/cutensor/tensorflow/einsum_test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"ca094c2d398702551844cced82d278fc1b53129ea3755fd0ceb0ff4ce267ab9c","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/tensorflow/einsum.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/tensorflow/einsum.py","kind":"file","name":"cuTENSOR/python/cutensor/tensorflow/einsum.py","path":"cuTENSOR/python/cutensor/tensorflow/einsum.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"2dcc95e346f39b8fcadd6ff4acbeff17ef74e0919e634ed7968a4e4edaf34bff","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuTENSOR/python/cutensor/tensorflow/__init__.py","uri":"program://CUDALibrarySamples/file/cuTENSOR/python/cutensor/tensorflow/__init__.py","kind":"file","name":"cuTENSOR/python/cutensor/tensorflow/__init__.py","path":"cuTENSOR/python/cutensor/tensorflow/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# ! /usr/bin/python\n# -*- coding: utf-8 -*-\n#\n# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n#\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions are\n# met:\n# - Redistributions of source code must retain the above copyright\n# notice, this list of conditions and the following disclaimer.\n# - Redistributions in binary form must reproduce the above copyright\n# notice, this list of conditions and the following disclaimer in the\n# documentation and/or other materials provided with the distribution.\n# - Neither the name(s) of the copyright holder(s) nor the names of its\n# contributors may be used to endorse or promote products derived\n# from this software without specific prior written permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n# \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR","source_hash":"e7b141cebe71b7076c9c1b1c0088f782c153abe1ba761851f9a3fcd52807ecfb","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:nvCOMP/benchmarks/text_to_binary.py","uri":"program://CUDALibrarySamples/file/nvCOMP/benchmarks/text_to_binary.py","kind":"file","name":"nvCOMP/benchmarks/text_to_binary.py","path":"nvCOMP/benchmarks/text_to_binary.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#!/usr/bin/env python3\n\n# SPDX-FileCopyrightText: Copyright (c) 2018-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport sys\nimport struct\nimport argparse\nimport numpy","source_hash":"5601fd2b155cd156149175e706737741adf81e7643e979541c6432893becc0d7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/setup.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/setup.py","kind":"file","name":"cuFFTMp/JAX_FFT/setup.py","path":"cuFFTMp/JAX_FFT/setup.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"#!/usr/bin/env python\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nimport codecs\nimport os\nimport subprocess","source_hash":"420ad161261a465b48610d90924220f0db941c0e6c98bdec5c24e32662a59d69","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/tests/helpers.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/tests/helpers.py","kind":"file","name":"cuFFTMp/JAX_FFT/tests/helpers.py","path":"cuFFTMp/JAX_FFT/tests/helpers.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport argparse\n\nimport jax\nfrom jax.experimental.shard_map import shard_map\n\n","source_hash":"ab3d644995e5284831cb6e75ee8c190741cd64350d7d46da446b147ce9a34b13","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/tests/fft_test.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/tests/fft_test.py","kind":"file","name":"cuFFTMp/JAX_FFT/tests/fft_test.py","path":"cuFFTMp/JAX_FFT/tests/fft_test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# -*- coding: utf-8 -*-\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport time\nimport math\nimport numpy as np\nimport sys","source_hash":"bf53d532bb89cda5d80a0d967a3b60583a521c7cb9f5b16660167233177105f2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/src/fft_common/__init__.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/src/fft_common/__init__.py","kind":"file","name":"cuFFTMp/JAX_FFT/src/fft_common/__init__.py","path":"cuFFTMp/JAX_FFT/src/fft_common/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":18,"code":"# -*- coding: utf-8 -*-\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .utils import Dist, Dir","source_hash":"815e9ceec6f738b3780b4736d642b672cc308b85f646bc703c101a5a213fd21b","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/src/fft_common/utils.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/src/fft_common/utils.py","kind":"file","name":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","path":"cuFFTMp/JAX_FFT/src/fft_common/utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom enum import Enum\n\nimport jax\nfrom jax.sharding import PartitionSpec\n\n","source_hash":"ad166e5e934f22a2008903747adc1b42a29d1ee4eb79ef7763a55dcf76f03819","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","kind":"file","name":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/cufftmp_jax.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# -*- coding: utf-8 -*-\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\n__all__ = [\"cufftmp\"]\n\nfrom functools import partial","source_hash":"dc8844d36b3f32db4bbe980b49b06b4d6ea3375dd899e7d1c466d1f58cac7c27","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/src/cufftmp_jax/__init__.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/src/cufftmp_jax/__init__.py","kind":"file","name":"cuFFTMp/JAX_FFT/src/cufftmp_jax/__init__.py","path":"cuFFTMp/JAX_FFT/src/cufftmp_jax/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":18,"code":"# -*- coding: utf-8 -*-\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .cufftmp_jax import cufftmp","source_hash":"488626296179b1aed9a04c4ec67c47167990199b745fa6901cb851dc9c0155e3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/src/xfft/xfft.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/src/xfft/xfft.py","kind":"file","name":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","path":"cuFFTMp/JAX_FFT/src/xfft/xfft.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom functools import partial\n\nimport jax\nfrom jax.sharding import NamedSharding\nfrom jax.experimental.custom_partitioning import custom_partitioning\nfrom fft_common import Dir","source_hash":"7f9383d79ced7caaf82ec47db6c835d93a16da006bc5cca881ce886a6e4df73a","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuFFTMp/JAX_FFT/src/xfft/__init__.py","uri":"program://CUDALibrarySamples/file/cuFFTMp/JAX_FFT/src/xfft/__init__.py","kind":"file","name":"cuFFTMp/JAX_FFT/src/xfft/__init__.py","path":"cuFFTMp/JAX_FFT/src/xfft/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":18,"code":"# -*- coding: utf-8 -*-\n\n# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .xfft import xfft","source_hash":"b1ccda415cb163ee74fcde8602bd40a83967cfb0c1bb9c385851fc9de20b14db","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/3_density_fitting/core_df_jk_gradient_rhf/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/3_density_fitting/core_df_jk_gradient_rhf/run.py","kind":"file","name":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_rhf/run.py","path":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_rhf/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os","source_hash":"5a4b5a74876ebbf1e8d1f4937ac408a03122ac8aeb69a63ddf668f7e8c61d418","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/3_density_fitting/core_df_jk/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/3_density_fitting/core_df_jk/run.py","kind":"file","name":"cuEST/python_examples/3_density_fitting/core_df_jk/run.py","path":"cuEST/python_examples/3_density_fitting/core_df_jk/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os","source_hash":"e311612ddde65956938f50e6c78a06229591757cb91a20564279aa201deebd51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/3_density_fitting/core_df_jk_gradient_uhf/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/3_density_fitting/core_df_jk_gradient_uhf/run.py","kind":"file","name":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_uhf/run.py","path":"cuEST/python_examples/3_density_fitting/core_df_jk_gradient_uhf/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os","source_hash":"136f973ac3516a05d7c54a452d0de8fe3143a6e2cc26ff253b7fa9071d7892e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/4_exchange_correlation/nonlocal_xc_gradient/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/4_exchange_correlation/nonlocal_xc_gradient/run.py","kind":"file","name":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_gradient/run.py","path":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_gradient/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n","source_hash":"e7d03b16d1097dd9b250e3c9f125b3c385813d99794b90b7b22a56f25df174cd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/4_exchange_correlation/local_xc_gradient/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/4_exchange_correlation/local_xc_gradient/run.py","kind":"file","name":"cuEST/python_examples/4_exchange_correlation/local_xc_gradient/run.py","path":"cuEST/python_examples/4_exchange_correlation/local_xc_gradient/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n","source_hash":"662e42c176dd2f694c6eb8ef74c2a4a4c0cd7ed325e60b7df5118bdaaee650fe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/4_exchange_correlation/local_xc_potential/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/4_exchange_correlation/local_xc_potential/run.py","kind":"file","name":"cuEST/python_examples/4_exchange_correlation/local_xc_potential/run.py","path":"cuEST/python_examples/4_exchange_correlation/local_xc_potential/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n","source_hash":"c0010d25780dc5fba49aa065c463efdff41d85959134a25bee23185236112a88","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/4_exchange_correlation/nonlocal_xc_potential/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/4_exchange_correlation/nonlocal_xc_potential/run.py","kind":"file","name":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_potential/run.py","path":"cuEST/python_examples/4_exchange_correlation/nonlocal_xc_potential/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n","source_hash":"a899e219421e4688f87d2a417ff709780b4311c9dd5489c60d316f5fe5f66943","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/1_basic_data_structures/ao_shells/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/1_basic_data_structures/ao_shells/run.py","kind":"file","name":"cuEST/python_examples/1_basic_data_structures/ao_shells/run.py","path":"cuEST/python_examples/1_basic_data_structures/ao_shells/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nimport sys\nfrom pathlib import Path\n\n# Inject the directory where the example helper utilities live","source_hash":"75b5f9cfb024d13901886e0810141bf82f67940d8c4c9bb3389519a7d55a7dcd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/1_basic_data_structures/ao_basis/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/1_basic_data_structures/ao_basis/run.py","kind":"file","name":"cuEST/python_examples/1_basic_data_structures/ao_basis/run.py","path":"cuEST/python_examples/1_basic_data_structures/ao_basis/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nimport sys\nfrom pathlib import Path\n\n# Inject the directory where the example helper utilities live","source_hash":"5cadb3aac5e36032e002edd8bb480ba2c52213de36e896dc8e2ca0e62d7ae3f3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/5_effective_core_potentials/ecp_integrals/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/5_effective_core_potentials/ecp_integrals/run.py","kind":"file","name":"cuEST/python_examples/5_effective_core_potentials/ecp_integrals/run.py","path":"cuEST/python_examples/5_effective_core_potentials/ecp_integrals/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n","source_hash":"6dd7d24f81c24a61d3135896bc72ca59176a48399eb226e9c334fe4fe8b7b1c0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/5_effective_core_potentials/ecp_gradients/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/5_effective_core_potentials/ecp_gradients/run.py","kind":"file","name":"cuEST/python_examples/5_effective_core_potentials/ecp_gradients/run.py","path":"cuEST/python_examples/5_effective_core_potentials/ecp_gradients/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\n","source_hash":"5e2fa4700f905447bbcb64a3be9697e20be8d68a84a78b6e0eea98cbb78a3fc5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/0_context/basic_usage/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/0_context/basic_usage/run.py","kind":"file","name":"cuEST/python_examples/0_context/basic_usage/run.py","path":"cuEST/python_examples/0_context/basic_usage/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\ndef cuest_check(\n title,\n return_code\n ):","source_hash":"c709dc03bbbb1ce8356be36e308ab614aea46163df9729c2fdd5d23cd649a660","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/0_context/user_owned_resources/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/0_context/user_owned_resources/run.py","kind":"file","name":"cuEST/python_examples/0_context/user_owned_resources/run.py","path":"cuEST/python_examples/0_context/user_owned_resources/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport sys\nfrom pathlib import Path\n\n# Inject the directory where the example helper utilities live\nsys.path.insert(0, str(Path(__file__).parent.parent.parent))","source_hash":"efa9f1e09ce986f651f91145b1a62687e5f08684a2570a0a305b1a3df1d67625","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/0_context/basic_multistream_usage/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/0_context/basic_multistream_usage/run.py","kind":"file","name":"cuEST/python_examples/0_context/basic_multistream_usage/run.py","path":"cuEST/python_examples/0_context/basic_multistream_usage/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\ndef cuest_check(\n title,\n return_code\n ):","source_hash":"b97deb716c4bca03b4bbdd68c79eac79707d1971fe87a14018d07eb98f6e10f3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/helpers/parsers.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/helpers/parsers.py","kind":"file","name":"cuEST/python_examples/helpers/parsers.py","path":"cuEST/python_examples/helpers/parsers.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport re\nfrom collections import namedtuple\n\ndef simple_xyz_parser(\n *,\n filename,","source_hash":"fb6237d80684b6d37dcf31f251d51dd9d0bdf962c40215af137ea203930be0bc","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/helpers/utilities.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/helpers/utilities.py","kind":"file","name":"cuEST/python_examples/helpers/utilities.py","path":"cuEST/python_examples/helpers/utilities.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\ntry:\n import numpy as np\nexcept ImportError:\n raise RuntimeError(\"numpy could not be imported. It is available via\\n\\tpip install numpy\")\n\ndef normalize_shell_coefficients(","source_hash":"21c23fc5fe09b1c858a5c595363ec9db306f6cc7848bf55e86948079a44797ef","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/helpers/grid_utils.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/helpers/grid_utils.py","kind":"file","name":"cuEST/python_examples/helpers/grid_utils.py","path":"cuEST/python_examples/helpers/grid_utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\ndef symbol_to_ahlrichs_radius(\n *,\n symbol,\n ):","source_hash":"f8ef3d463fa70bf20d789fb2f925e577ce39a278cbd3340e527f47b2f1125205","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/helpers/cuda_utils.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/helpers/cuda_utils.py","kind":"file","name":"cuEST/python_examples/helpers/cuda_utils.py","path":"cuEST/python_examples/helpers/cuda_utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# There are numerous way to access GPU resources from Python. High level\n# packages such as CuPy, TensorFlow and Pytorch can simplify allocations and\n# transfers between host and device. Here we demonstrate two lower level\n# approaches to accessing CUDA functions to provide these utilities: 1) using\n# the cuda-bindings package to access native CUDA in Pythonic way, and 2) using\n# the ctypes module to directly access these functions from the CUDA runtime","source_hash":"f77c3a2b031ea4af827908181874641d0852d86e7157189980ed6074944c86d1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/2_one_electron_integrals/one_electron_gradients/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/2_one_electron_integrals/one_electron_gradients/run.py","kind":"file","name":"cuEST/python_examples/2_one_electron_integrals/one_electron_gradients/run.py","path":"cuEST/python_examples/2_one_electron_integrals/one_electron_gradients/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os","source_hash":"f8cbbc25effd43edf23493bb76f0d9961372dd0a996ff00617ff32b81bcd3664","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/python_examples/2_one_electron_integrals/one_electron_integrals/run.py","uri":"program://CUDALibrarySamples/file/cuEST/python_examples/2_one_electron_integrals/one_electron_integrals/run.py","kind":"file","name":"cuEST/python_examples/2_one_electron_integrals/one_electron_integrals/run.py","path":"cuEST/python_examples/2_one_electron_integrals/one_electron_integrals/run.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport numpy as np\nimport argparse\nfrom pathlib import Path\nimport sys\nimport os","source_hash":"7ec86e183dd48e9b686e1b68eb31372fa264804b170af9647e1dcb4b621914e7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/b3lyp1_grad_1/__init__.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/b3lyp1_grad_1/__init__.py","kind":"file","name":"cuEST/cuest_scf_examples/test/b3lyp1_grad_1/__init__.py","path":"cuEST/cuest_scf_examples/test/b3lyp1_grad_1/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":15,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n","source_hash":"bc20d584c3048d1f18f9fe62b25a2213b56f3dcd9952b196ef22110defa246ec","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/b3lyp1_grad_1/test.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/b3lyp1_grad_1/test.py","kind":"file","name":"cuEST/cuest_scf_examples/test/b3lyp1_grad_1/test.py","path":"cuEST/cuest_scf_examples/test/b3lyp1_grad_1/test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n","source_hash":"c29d425d6cdea49aaf24a459228d531f24b6f0d787b9654f57a4e96f555f444d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/rhf_pcm/__init__.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/rhf_pcm/__init__.py","kind":"file","name":"cuEST/cuest_scf_examples/test/rhf_pcm/__init__.py","path":"cuEST/cuest_scf_examples/test/rhf_pcm/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":15,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n","source_hash":"bc20d584c3048d1f18f9fe62b25a2213b56f3dcd9952b196ef22110defa246ec","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/rhf_pcm/test.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/rhf_pcm/test.py","kind":"file","name":"cuEST/cuest_scf_examples/test/rhf_pcm/test.py","path":"cuEST/cuest_scf_examples/test/rhf_pcm/test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n","source_hash":"ae1122b9eae7c75ba0c9754e19de58c596734ebfcd8f21269400171f7cfd42d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/rhf_1/__init__.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/rhf_1/__init__.py","kind":"file","name":"cuEST/cuest_scf_examples/test/rhf_1/__init__.py","path":"cuEST/cuest_scf_examples/test/rhf_1/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":15,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n","source_hash":"bc20d584c3048d1f18f9fe62b25a2213b56f3dcd9952b196ef22110defa246ec","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/rhf_1/test.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/rhf_1/test.py","kind":"file","name":"cuEST/cuest_scf_examples/test/rhf_1/test.py","path":"cuEST/cuest_scf_examples/test/rhf_1/test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n","source_hash":"15e06e9f0176e175dc27f288e0edcdaa1193dba5e9abd5625fafe18c13140764","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/b97mv_grad_1/__init__.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/b97mv_grad_1/__init__.py","kind":"file","name":"cuEST/cuest_scf_examples/test/b97mv_grad_1/__init__.py","path":"cuEST/cuest_scf_examples/test/b97mv_grad_1/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":15,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n","source_hash":"bc20d584c3048d1f18f9fe62b25a2213b56f3dcd9952b196ef22110defa246ec","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/b97mv_grad_1/test.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/b97mv_grad_1/test.py","kind":"file","name":"cuEST/cuest_scf_examples/test/b97mv_grad_1/test.py","path":"cuEST/cuest_scf_examples/test/b97mv_grad_1/test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n","source_hash":"80f6753bdd9b8c566ecf03a80897216f535056bde1d62e200955f9f3db8eebdd","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/rhf_grad_1/test.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/rhf_grad_1/test.py","kind":"file","name":"cuEST/cuest_scf_examples/test/rhf_grad_1/test.py","path":"cuEST/cuest_scf_examples/test/rhf_grad_1/test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n","source_hash":"744ef1bc9ee5fa9bb64090ea994a9b1dcc8f6a4c9f0a08017f3d46afb582ffa7","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/blyp_grad_grids_1/__init__.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/blyp_grad_grids_1/__init__.py","kind":"file","name":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/__init__.py","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":15,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n","source_hash":"bc20d584c3048d1f18f9fe62b25a2213b56f3dcd9952b196ef22110defa246ec","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","kind":"file","name":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","path":"cuEST/cuest_scf_examples/test/blyp_grad_grids_1/test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest_scf\nimport numpy as np\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')\n","source_hash":"616036c58f3f0376542f9c4ba1c297ddbc3bdbbe99988a6efac60807bca3e209","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","path":"cuEST/cuest_scf_examples/cuest_scf/sad_atom_structure.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n \nclass SADAtomStructure(object):\n\n def __init__(\n self,","source_hash":"33e92de23e67c15a9cf313d14b21962f0f0ed406b9bea3a2e967eba86d5a1264","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/xc_functionals.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/xc_functionals.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/xc_functionals.py","path":"cuEST/cuest_scf_examples/cuest_scf/xc_functionals.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nclass XCFunctionalInfo(object):\n\n @staticmethod\n def string_to_enum(","source_hash":"467544ce3291f2b7cec35b4285dc8b18da71b433c161a763e1843d8127212dd0","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_molecular_grid.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .memoized_property import memoized_property\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace","source_hash":"5dda1931db20fab83743da0b35561fbd12fc395147bcb3e9f8da8e29ad8eddfe","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/diis.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/diis.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/diis.py","path":"cuEST/cuest_scf_examples/cuest_scf/diis.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nfrom .gpu_matrix import GPUMatrix\nfrom .gpu_matrix_utility import GPUMatrixUtility\n \nclass DIIS(object):\n","source_hash":"ca94912fbf6c1ddae85a8d8987d438cd293e455753b97cc5d30943db8db3c594","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/periodic_table.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/periodic_table.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/periodic_table.py","path":"cuEST/cuest_scf_examples/cuest_scf/periodic_table.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nclass PeriodicTable(object):\n\n symbol_to_N_table = {\n 'X' : 0,\n 'H' : 1,\n 'He' : 2,","source_hash":"0342e41060e0eb94cf40568a90cf72bdec3a731c1ec4d4376fa4a407c9762737","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .cuda_utility import CudaUtility\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\n","source_hash":"6c76bb1163d31d7e4a773c3eff26bda2eb75e70c06244c3de4266f9457843436","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_plan.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .memoized_property import memoized_property\n\nimport cuest.bindings as ce \nimport numpy as np\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor","source_hash":"e43300c654f12dbe3d6f1c7cf0ad6632e8673862a6e4976822ab98aa2db03781","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_ao_pair_list.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_ao_pair_list.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_pair_list.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_pair_list.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle","source_hash":"a8dcbaa3ab7ed6482989f99ab9f840dea2849f66fae5b39667d03834f7cc5220","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_parameters.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_parameters.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_parameters.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_parameters.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nclass CuestParameters(object):\n \n def __init__(\n self,","source_hash":"272380704cd2c9b18a5c4ff67763b1dd09a89966320e489794fda600df422022","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_handle.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_parameters import CuestParameters\n\nclass CuestHandle(object):\n","source_hash":"214b0f20a2e7b55eca82236111bed8fcd47bd2856fb979521af24cee6fe6704d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/memoized_property.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/memoized_property.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/memoized_property.py","path":"cuEST/cuest_scf_examples/cuest_scf/memoized_property.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom functools import wraps\n\ndef memoized_property(fget):\n \"\"\"\n Return a property attribute for new-style classes that only calls its getter on the first\n access. The result is stored and on subsequent accesses is returned, preventing the need to","source_hash":"8069164d32bdbb2b7232c2fcfcb30de43b98007308880408a70961160d436d7b","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/rhf.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/rhf.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","path":"cuEST/cuest_scf_examples/cuest_scf/rhf.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .memoized_property import memoized_property\n\nfrom .molecule import Molecule\nfrom .ao_basis import AOBasis","source_hash":"44b5ce9a5a14b305bfa132755005454124a22b55b47a47731169396442b03487","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuda_utility.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nimport cuda.bindings.runtime as cuda\n\nclass CudaUtility(object):\n\n @staticmethod","source_hash":"25dee6b14e00174a0b7f7a995d0652957ab341cf4649232020dd3dd96d3999ce","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_basis.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .ao_basis import AOBasis\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace","source_hash":"f80a8e31b99780fe91a882a797ce1fc56e202dfc86ef542d79c9169e108779a5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix_utility.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\nimport atexit\n\nimport nvmath.bindings.cublas as cublas\nimport nvmath.bindings.cusolverDn as cusolver\nimport nvmath.bindings.cusolver as cusolver_base","source_hash":"8c3660ab18b85243b1b3adab38a2db94f905edd4f761792ec443a396720268ab","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_plan.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_plan.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_plan.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_plan.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle","source_hash":"8bc734a7656d5f831b2d5261d6a91e8fbc335123560308a94d58feb644452508","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_compute.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_df_int_plan import CuestDFIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor","source_hash":"f5273739ec00a0245d5d47bd329c3fe5906be55be378ab13511174c0bcf324e4","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_results.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_results.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_results.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_results.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# Copyright 2025-2026 NVIDIA CORPORATION & AFFILIATES.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\n\nclass CuestResults(object):\n\n def __init__(\n self,\n *,","source_hash":"4a4ab48383fcac003a7f438e1e21b20a24cdedca881929d29d74e2dcb07502d9","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_plan.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_plan.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_plan.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_df_int_plan.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor\nfrom .cuest_workspace import CuestWorkspace\n\nfrom .cuest_handle import CuestHandle","source_hash":"01290eddc89b5cac743575d81129c5e3d86030bbfb3ebf23d3d1695de7691181","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/unit_conversions.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/unit_conversions.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/unit_conversions.py","path":"cuEST/cuest_scf_examples/cuest_scf/unit_conversions.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nclass UnitConversions(object):\n\n conversions = {\n 'ang_per_bohr' : 0.52917720859, # PSI4\n }\n","source_hash":"b759427172fc1cbfb09dfc49dd310cc635a9d82b4e58585731cbf7c32170838e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/__init__.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/__init__.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/__init__.py","path":"cuEST/cuest_scf_examples/cuest_scf/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .unit_conversions import UnitConversions\n\nfrom .periodic_table import PeriodicTable\n \nfrom .molecule import Molecule\n","source_hash":"e626f5dffa81b0a06aaa67111e1d2062fe68dbf388adf4e74a17a06ccfe04b95","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/molecule.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/molecule.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","path":"cuEST/cuest_scf_examples/cuest_scf/molecule.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .unit_conversions import UnitConversions\nfrom .periodic_table import PeriodicTable\n\nclass Molecule(object):","source_hash":"4c1269623d592f1aadae94551dbd607d3533a30782b7f635b6ef29821fcb8628","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_ao_shell.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_ao_shell.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_shell.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_ao_shell.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .ao_shell import AOShell\n\nfrom .cuest_handle import CuestHandle\n","source_hash":"79122d931dbe4de7158ffeea2c9eb72cbe0873a47401a8d5b01a7be68af57798","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","path":"cuEST/cuest_scf_examples/cuest_scf/gpu_matrix.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .cuda_utility import CudaUtility\n\nclass GPUMatrix(object):\n","source_hash":"6a1c5a6083ae49c65e5f23840967863293d1505dca86b989dcf0e0ba38cbe0a2","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np \n\nfrom .molecule import Molecule \nfrom .ao_basis import AOBasis\nfrom .sad_atom_structure import SADAtomStructure\nfrom .sad_guess_atom import SADGuessAtom","source_hash":"87d9a1a8d63e3c3cd6ebec27db00dd2c77d30c5d77074cb63a441550e337198e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","path":"cuEST/cuest_scf_examples/cuest_scf/ao_shell.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n \nclass AOShell(object):\n\n def __init__(\n self,","source_hash":"414e4a833a343a7d169a94a1f32c38fcf4fd2b0304252d10536e0a1b5fb21644","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","path":"cuEST/cuest_scf_examples/cuest_scf/ao_basis.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .periodic_table import PeriodicTable\n\nfrom .ao_shell import AOShell\n","source_hash":"6592c6e9ce3c2298d3a8291b3b5550cfe4d9c50ad45a7197689e35f9958fe1d3","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_plan.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom .memoized_property import memoized_property\n\nimport cuest.bindings as ce \n\nfrom .xc_functionals import XCFunctionalInfo\n","source_hash":"a7945888127531fcbbb78457886dc5914abfaeec0b25fe93ad3f84bee07cbdfa","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","path":"cuEST/cuest_scf_examples/cuest_scf/sad_guess_atom.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .ao_basis import AOBasis\n\nfrom .sad_atom_structure import SADAtomStructure\n","source_hash":"9f81d478a4fb174a38d15368057fe9d40f81c37146f9f7d7290833504b7a9e51","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_workspace_descriptor.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nclass CuestWorkspaceDescriptor():\n\n _dtype = np.dtype([\n (\"hostBufferSizeInBytes\", np.uint64, ),","source_hash":"a92f632bb0f1a027de4a7a6d7185add3259bcee4b0508f3535629d645b00e5b5","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/sad_solid_harmonics.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/sad_solid_harmonics.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/sad_solid_harmonics.py","path":"cuEST/cuest_scf_examples/cuest_scf/sad_solid_harmonics.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nclass SADSolidHarmonics(object):\n\n def __init__(\n self,","source_hash":"544c235942e1acad1d86d09eca837cd486863937663ea16a486fab088eafc3e1","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_oe_int_compute.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_oe_int_plan import CuestOEIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor","source_hash":"c6d29df02b473cf49c499571d72f258660b9f39f2a35e548360c019505e5d225","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_compute.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_compute.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_compute.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_pcm_int_compute.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_pcm_int_plan import CuestPCMIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor","source_hash":"fe2ca49e5638b192dc63904be5b534f6693546b6f3446030f9c2dde80d315d9e","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/sad_overlap.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/sad_overlap.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/sad_overlap.py","path":"cuEST/cuest_scf_examples/cuest_scf/sad_overlap.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport numpy as np\n\nfrom .ao_basis import AOBasis\n\nfrom .sad_solid_harmonics import SADSolidHarmonics\n","source_hash":"0706a9bcb1b232f62d8619e3aff5302f1f616498b9b25b3c4d035c52e8d9b52d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","kind":"file","name":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","path":"cuEST/cuest_scf_examples/cuest_scf/cuest_xc_int_compute.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce \n\nfrom .cuest_handle import CuestHandle\nfrom .cuest_xc_int_plan import CuestXCIntPlan\n\nfrom .cuest_workspace_descriptor import CuestWorkspaceDescriptor","source_hash":"c9ca0cdb43480b5b675a34250bfe5e6dc5ae292136478e7bd6927dc71e672a7d","truncated":false} {"repo_id":"CUDALibrarySamples","entity_id":"file:cuEST/cuest_scf_examples/examples/rhf-1/test.py","uri":"program://CUDALibrarySamples/file/cuEST/cuest_scf_examples/examples/rhf-1/test.py","kind":"file","name":"cuEST/cuest_scf_examples/examples/rhf-1/test.py","path":"cuEST/cuest_scf_examples/examples/rhf-1/test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n# SPDX-License-Identifier: Apache-2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport cuest.bindings as ce\nimport cuest_scf\n\nimport os\nfiledir = os.path.dirname(os.path.realpath(__file__)) \nbasisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')","source_hash":"b31c21fa6f0c92c002383e1da4c4dc7374ea972ea1a23a3b2d8a61f3ebc8c478","truncated":false}