# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np

from .ao_basis import AOBasis

from .sad_solid_harmonics import SADSolidHarmonics

class SADOverlap(object):

    @staticmethod
    def compute_atomic_overlap(
        *,
        basis1 : AOBasis,
        basis2 : AOBasis,
        ):

        if basis1.natom != 1: raise RuntimeError('basis1.natom != 1')
        if basis2.natom != 1: raise RuntimeError('basis2.natom != 1')

        if basis1.is_mixed: raise RuntimeError('basis1 is mixed')
        if basis2.is_mixed: raise RuntimeError('basis2 is mixed')

        df = [1.0]
        for L in range(2, basis1.max_L + basis2.max_L + 1, 2):
            df.append(df[L // 2 - 1] * (L - 1.0))

        Scc = np.zeros((basis1.ncart, basis2.ncart))

        for P1, shell1 in enumerate(basis1.shells[0]):
            L1 = shell1.L
            offset1 = basis1.shell_cart_starts[P1]

            for P2, shell2 in enumerate(basis2.shells[0]):
                L2 = shell2.L
                offset2 = basis2.shell_cart_starts[P2]

                for e1, c1 in zip(shell1.exponents, shell1.coefficients):
                    for e2, c2 in zip(shell2.exponents, shell2.coefficients):

                        c12 = c1 * c2
                        e12 = e1 + e2

                        S0 = c12 * (np.pi / e12)**(1.5) * (2 * e12)**(-0.5 * (L1 + L2))

                        index1 = 0
                        for i1 in range(L1+1):
                            l1 = L1 - i1
                            for j1 in range(i1+1):
                                m1 = i1 - j1
                                n1 = j1

                                index2 = 0
                                for i2 in range(L2+1):
                                    l2 = L2 - i2
                                    for j2 in range(i2+1):
                                        m2 = i2 - j2
                                        n2 = j2

                                        l12 = l1 + l2
                                        m12 = m1 + m2
                                        n12 = n1 + n2

                                        if l12 % 2 == 1:
                                            index2 += 1
                                            continue
                                        if m12 % 2 == 1:
                                            index2 += 1
                                            continue
                                        if n12 % 2 == 1:
                                            index2 += 1
                                            continue

                                        S = S0 * df[l12 // 2] * df[m12 // 2] * df[n12 // 2]

                                        cart1 = offset1 + index1
                                        cart2 = offset2 + index2

                                        Scc[cart1, cart2] += S

                                        index2 += 1

                                index1 += 1

        if basis1.is_cart and basis2.is_cart:
            return Scc

        max_L = 0
        if basis1.is_pure: max_L = max(max_L, basis1.max_L)
        if basis2.is_pure: max_L = max(max_L, basis2.max_L)
        sh = SADSolidHarmonics(max_L=max_L)

        if basis2.is_pure:
            Scs = np.zeros((basis1.ncart, basis2.nao))
            for P2, shell2 in enumerate(basis2.shells[0]):
                L2 = shell2.L
                ncart2 = (L2 + 1) * (L2 + 2) // 2
                npure2 = 2 * L2 + 1
                cart_offset2 = basis2.shell_cart_starts[P2]
                pure_offset2 = basis2.shell_ao_starts[P2]
                T = sh.T[L2]
                Scs[:, pure_offset2:pure_offset2+npure2] = np.dot(Scc[:, cart_offset2:cart_offset2+ncart2], T)
        else:
            Scs = Scc

        if basis1.is_pure:
            Sss = np.zeros((basis1.nao, basis2.nao))
            for P1, shell1 in enumerate(basis1.shells[0]):
                L1 = shell1.L
                ncart1 = (L1 + 1) * (L1 + 2) // 2
                npure1 = 2 * L1 + 1
                cart_offset1 = basis1.shell_cart_starts[P1]
                pure_offset1 = basis1.shell_ao_starts[P1]
                T = sh.T[L1]
                Sss[pure_offset1:pure_offset1+npure1, :] = np.dot(T.T, Scs[cart_offset1:cart_offset1+ncart1, :])
        else:
            Sss = Scs

        return Sss


SADOverlap

# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np

from .ao_basis import AOBasis

from .sad_solid_harmonics import SADSolidHarmonics

class SADOverlap(object):

    @staticmethod
    def compute_atomic_overlap(
        *,
        basis1 : AOBasis,
        basis2 : AOBasis,
        ):

        if basis1.natom != 1: raise RuntimeError('basis1.natom != 1')
        if basis2.natom != 1: raise RuntimeError('basis2.natom != 1')

        if basis1.is_mixed: raise RuntimeError('basis1 is mixed')
        if basis2.is_mixed: raise RuntimeError('basis2 is mixed')

        df = [1.0]
        for L in range(2, basis1.max_L + basis2.max_L + 1, 2):
            df.append(df[L // 2 - 1] * (L - 1.0))

        Scc = np.zeros((basis1.ncart, basis2.ncart))

        for P1, shell1 in enumerate(basis1.shells[0]):
            L1 = shell1.L
            offset1 = basis1.shell_cart_starts[P1]

            for P2, shell2 in enumerate(basis2.shells[0]):
                L2 = shell2.L
                offset2 = basis2.shell_cart_starts[P2]

                for e1, c1 in zip(shell1.exponents, shell1.coefficients):
                    for e2, c2 in zip(shell2.exponents, shell2.coefficients):

                        c12 = c1 * c2
                        e12 = e1 + e2

                        S0 = c12 * (np.pi / e12)**(1.5) * (2 * e12)**(-0.5 * (L1 + L2))

                        index1 = 0
                        for i1 in range(L1+1):
                            l1 = L1 - i1
                            for j1 in range(i1+1):
                                m1 = i1 - j1
                                n1 = j1

                                index2 = 0
                                for i2 in range(L2+1):
                                    l2 = L2 - i2
                                    for j2 in range(i2+1):
                                        m2 = i2 - j2
                                        n2 = j2

                                        l12 = l1 + l2
                                        m12 = m1 + m2
                                        n12 = n1 + n2

                                        if l12 % 2 == 1:
                                            index2 += 1
                                            continue
                                        if m12 % 2 == 1:
                                            index2 += 1
                                            continue
                                        if n12 % 2 == 1:
                                            index2 += 1
                                            continue

                                        S = S0 * df[l12 // 2] * df[m12 // 2] * df[n12 // 2]

                                        cart1 = offset1 + index1
                                        cart2 = offset2 + index2

                                        Scc[cart1, cart2] += S

                                        index2 += 1

                                index1 += 1

        if basis1.is_cart and basis2.is_cart:
            return Scc

        max_L = 0
        if basis1.is_pure: max_L = max(max_L, basis1.max_L)
        if basis2.is_pure: max_L = max(max_L, basis2.max_L)
        sh = SADSolidHarmonics(max_L=max_L)

        if basis2.is_pure:
            Scs = np.zeros((basis1.ncart, basis2.nao))
            for P2, shell2 in enumerate(basis2.shells[0]):
                L2 = shell2.L
                ncart2 = (L2 + 1) * (L2 + 2) // 2
                npure2 = 2 * L2 + 1
                cart_offset2 = basis2.shell_cart_starts[P2]
                pure_offset2 = basis2.shell_ao_starts[P2]
                T = sh.T[L2]
                Scs[:, pure_offset2:pure_offset2+npure2] = np.dot(Scc[:, cart_offset2:cart_offset2+ncart2], T)
        else:
            Scs = Scc

        if basis1.is_pure:
            Sss = np.zeros((basis1.nao, basis2.nao))
            for P1, shell1 in enumerate(basis1.shells[0]):
                L1 = shell1.L
                ncart1 = (L1 + 1) * (L1 + 2) // 2
                npure1 = 2 * L1 + 1
                cart_offset1 = basis1.shell_cart_starts[P1]
                pure_offset1 = basis1.shell_ao_starts[P1]
                T = sh.T[L1]
                Sss[pure_offset1:pure_offset1+npure1, :] = np.dot(T.T, Scs[cart_offset1:cart_offset1+ncart1, :])
        else:
            Sss = Scs

        return Sss


# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np

from .ao_basis import AOBasis

from .sad_solid_harmonics import SADSolidHarmonics

class SADOverlap(object):

    @staticmethod
    def compute_atomic_overlap(
        *,
        basis1 : AOBasis,
        basis2 : AOBasis,
        ):

        if basis1.natom != 1: raise RuntimeError('basis1.natom != 1')
        if basis2.natom != 1: raise RuntimeError('basis2.natom != 1')

        if basis1.is_mixed: raise RuntimeError('basis1 is mixed')
        if basis2.is_mixed: raise RuntimeError('basis2 is mixed')

        df = [1.0]
        for L in range(2, basis1.max_L + basis2.max_L + 1, 2):
            df.append(df[L // 2 - 1] * (L - 1.0))

        Scc = np.zeros((basis1.ncart, basis2.ncart))

        for P1, shell1 in enumerate(basis1.shells[0]):
            L1 = shell1.L
            offset1 = basis1.shell_cart_starts[P1]

            for P2, shell2 in enumerate(basis2.shells[0]):
                L2 = shell2.L
                offset2 = basis2.shell_cart_starts[P2]

                for e1, c1 in zip(shell1.exponents, shell1.coefficients):
                    for e2, c2 in zip(shell2.exponents, shell2.coefficients):

                        c12 = c1 * c2
                        e12 = e1 + e2

                        S0 = c12 * (np.pi / e12)**(1.5) * (2 * e12)**(-0.5 * (L1 + L2))

                        index1 = 0
                        for i1 in range(L1+1):
                            l1 = L1 - i1
                            for j1 in range(i1+1):
                                m1 = i1 - j1
                                n1 = j1

                                index2 = 0
                                for i2 in range(L2+1):
                                    l2 = L2 - i2
                                    for j2 in range(i2+1):
                                        m2 = i2 - j2
                                        n2 = j2

                                        l12 = l1 + l2
                                        m12 = m1 + m2
                                        n12 = n1 + n2

                                        if l12 % 2 == 1:
                                            index2 += 1
                                            continue
                                        if m12 % 2 == 1:
                                            index2 += 1
                                            continue
                                        if n12 % 2 == 1:
                                            index2 += 1
                                            continue

                                        S = S0 * df[l12 // 2] * df[m12 // 2] * df[n12 // 2]

                                        cart1 = offset1 + index1
                                        cart2 = offset2 + index2

                                        Scc[cart1, cart2] += S

                                        index2 += 1

                                index1 += 1

        if basis1.is_cart and basis2.is_cart:
            return Scc

        max_L = 0
        if basis1.is_pure: max_L = max(max_L, basis1.max_L)
        if basis2.is_pure: max_L = max(max_L, basis2.max_L)
        sh = SADSolidHarmonics(max_L=max_L)

        if basis2.is_pure:
            Scs = np.zeros((basis1.ncart, basis2.nao))
            for P2, shell2 in enumerate(basis2.shells[0]):
                L2 = shell2.L
                ncart2 = (L2 + 1) * (L2 + 2) // 2
                npure2 = 2 * L2 + 1
                cart_offset2 = basis2.shell_cart_starts[P2]
                pure_offset2 = basis2.shell_ao_starts[P2]
                T = sh.T[L2]
                Scs[:, pure_offset2:pure_offset2+npure2] = np.dot(Scc[:, cart_offset2:cart_offset2+ncart2], T)
        else:
            Scs = Scc

        if basis1.is_pure:
            Sss = np.zeros((basis1.nao, basis2.nao))
            for P1, shell1 in enumerate(basis1.shells[0]):
                L1 = shell1.L
                ncart1 = (L1 + 1) * (L1 + 2) // 2
                npure1 = 2 * L1 + 1
                cart_offset1 = basis1.shell_cart_starts[P1]
                pure_offset1 = basis1.shell_ao_starts[P1]
                T = sh.T[L1]
                Sss[pure_offset1:pure_offset1+npure1, :] = np.dot(T.T, Scs[cart_offset1:cart_offset1+ncart1, :])
        else:
            Sss = Scs

        return Sss


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

from .cuest_handle import CuestHandle
from .cuest_xc_int_plan import CuestXCIntPlan

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor
from .cuest_workspace import CuestWorkspace
from .cuest_parameters import CuestParameters

import numpy as np

class CuestXCIntCompute(object):

    @staticmethod
    def local_exchange_correlation(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Vxcptr,
        ):

        Exc = ce.data_double()

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Vxcptr2 = ce.Pointer()
        Vxcptr2.value = np.intp(Vxcptr)

        # => Workspace query <= #
        xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS)

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestXCPotentialRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestXCPotentialRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCPotentialRKSCompute failed: %d' % status)
        del xc_compute_parameters

        return Exc.value

    @staticmethod
    def nonlocal_exchange_correlation(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Vxcptr,
        ):

        Exc = ce.data_double()

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Vxcptr2 = ce.Pointer()
        Vxcptr2.value = np.intp(Vxcptr)

        # => VV10 parameters <= #
        nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS)

        vv10_b = ce.data_double(xc_int_plan.vv10_b)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_B,
            attributeValue=vv10_b,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_C = ce.data_double(xc_int_plan.vv10_c)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_C,
            attributeValue=vv10_C,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_scale = ce.data_double(xc_int_plan.vv10_scale)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_SCALE,
            attributeValue=vv10_scale,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        # => Workspace query <= #

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestNonlocalXCPotentialRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestNonlocalXCPotentialRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCPotentialRKSCompute failed: %d' % status)
        del nonlocal_xc_compute_parameters

        return Exc.value

    @staticmethod
    def local_exchange_correlation_gradient(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Gptr,
        ):

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Gptr2 = ce.Pointer()
        Gptr2.value = np.intp(Gptr)

        # => Workspace query <= #
        xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS)

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestXCDerivativeRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestXCDerivativeRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCDerivativeRKSCompute failed: %d' % status)
        del xc_compute_parameters

    @staticmethod
    def nonlocal_exchange_correlation_gradient(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Gptr,
        ):

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Gptr2 = ce.Pointer()
        Gptr2.value = np.intp(Gptr)

        # => VV10 parameters <= #
        nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS)

        vv10_b = ce.data_double(xc_int_plan.vv10_b)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_B,
            attributeValue=vv10_b,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_C = ce.data_double(xc_int_plan.vv10_c)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_C,
            attributeValue=vv10_C,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_scale = ce.data_double(xc_int_plan.vv10_scale)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_SCALE,
            attributeValue=vv10_scale,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        # => Workspace query <= #

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestNonlocalXCDerivativeRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCDerivativeRKSCompute failed: %d' % status)
        del nonlocal_xc_compute_parameters


CuestXCIntCompute

#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

from .cuest_handle import CuestHandle
from .cuest_xc_int_plan import CuestXCIntPlan

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor
from .cuest_workspace import CuestWorkspace
from .cuest_parameters import CuestParameters

import numpy as np

class CuestXCIntCompute(object):

    @staticmethod
    def local_exchange_correlation(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Vxcptr,
        ):

        Exc = ce.data_double()

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Vxcptr2 = ce.Pointer()
        Vxcptr2.value = np.intp(Vxcptr)

        # => Workspace query <= #
        xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS)

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestXCPotentialRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestXCPotentialRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCPotentialRKSCompute failed: %d' % status)
        del xc_compute_parameters

        return Exc.value

    @staticmethod
    def nonlocal_exchange_correlation(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Vxcptr,
        ):

        Exc = ce.data_double()

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Vxcptr2 = ce.Pointer()
        Vxcptr2.value = np.intp(Vxcptr)

        # => VV10 parameters <= #
        nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS)

        vv10_b = ce.data_double(xc_int_plan.vv10_b)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_B,
            attributeValue=vv10_b,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_C = ce.data_double(xc_int_plan.vv10_c)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_C,
            attributeValue=vv10_C,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_scale = ce.data_double(xc_int_plan.vv10_scale)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_SCALE,
            attributeValue=vv10_scale,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        # => Workspace query <= #

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestNonlocalXCPotentialRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestNonlocalXCPotentialRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCPotentialRKSCompute failed: %d' % status)
        del nonlocal_xc_compute_parameters

        return Exc.value

    @staticmethod
    def local_exchange_correlation_gradient(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Gptr,
        ):

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Gptr2 = ce.Pointer()
        Gptr2.value = np.intp(Gptr)

        # => Workspace query <= #
        xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS)

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestXCDerivativeRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestXCDerivativeRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCDerivativeRKSCompute failed: %d' % status)
        del xc_compute_parameters

    @staticmethod
    def nonlocal_exchange_correlation_gradient(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Gptr,
        ):

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Gptr2 = ce.Pointer()
        Gptr2.value = np.intp(Gptr)

        # => VV10 parameters <= #
        nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS)

        vv10_b = ce.data_double(xc_int_plan.vv10_b)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_B,
            attributeValue=vv10_b,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_C = ce.data_double(xc_int_plan.vv10_c)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_C,
            attributeValue=vv10_C,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_scale = ce.data_double(xc_int_plan.vv10_scale)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_SCALE,
            attributeValue=vv10_scale,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        # => Workspace query <= #

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestNonlocalXCDerivativeRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCDerivativeRKSCompute failed: %d' % status)
        del nonlocal_xc_compute_parameters


# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

from .cuest_handle import CuestHandle
from .cuest_xc_int_plan import CuestXCIntPlan

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor
from .cuest_workspace import CuestWorkspace
from .cuest_parameters import CuestParameters

import numpy as np

class CuestXCIntCompute(object):

    @staticmethod
    def local_exchange_correlation(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Vxcptr,
        ):

        Exc = ce.data_double()

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Vxcptr2 = ce.Pointer()
        Vxcptr2.value = np.intp(Vxcptr)

        # => Workspace query <= #
        xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCPOTENTIALRKSCOMPUTE_PARAMETERS)

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestXCPotentialRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestXCPotentialRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCPotentialRKSCompute failed: %d' % status)
        del xc_compute_parameters

        return Exc.value

    @staticmethod
    def nonlocal_exchange_correlation(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Vxcptr,
        ):

        Exc = ce.data_double()

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Vxcptr2 = ce.Pointer()
        Vxcptr2.value = np.intp(Vxcptr)

        # => VV10 parameters <= #


        status = ce.cuestXCPotentialRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCPotentialRKSCompute failed: %d' % status)
        del xc_compute_parameters

        return Exc.value

    @staticmethod
    def nonlocal_exchange_correlation(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Vxcptr,
        ):

        Exc = ce.data_double()

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Vxcptr2 = ce.Pointer()
        Vxcptr2.value = np.intp(Vxcptr)

        # => VV10 parameters <= #
        nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS)

        vv10_b = ce.data_double(xc_int_plan.vv10_b)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_B,
            attributeValue=vv10_b,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_C = ce.data_double(xc_int_plan.vv10_c)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_C,
            attributeValue=vv10_C,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_scale = ce.data_double(xc_int_plan.vv10_scale)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCPotentialRKSComputeParametersAttributes.CUEST_NONLOCALXCPOTENTIALRKSCOMPUTE_PARAMETERS_VV10_SCALE,
            attributeValue=vv10_scale,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        # => Workspace query <= #

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestNonlocalXCPotentialRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCPotentialRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestNonlocalXCPotentialRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCPotentialRKSCompute failed: %d' % status)
        del nonlocal_xc_compute_parameters

        return Exc.value

    @staticmethod
    def local_exchange_correlation_gradient(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Gptr,
        ):

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Gptr2 = ce.Pointer()
        Gptr2.value = np.intp(Gptr)

        # => Workspace query <= #
        xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS)


        status = ce.cuestNonlocalXCPotentialRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outXCEnergy=Exc,
            outXCPotentialMatrix=Vxcptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCPotentialRKSCompute failed: %d' % status)
        del nonlocal_xc_compute_parameters

        return Exc.value

    @staticmethod
    def local_exchange_correlation_gradient(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Gptr,
        ):

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Gptr2 = ce.Pointer()
        Gptr2.value = np.intp(Gptr)

        # => Workspace query <= #
        xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_XCDERIVATIVERKSCOMPUTE_PARAMETERS)

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestXCDerivativeRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestXCDerivativeRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCDerivativeRKSCompute failed: %d' % status)
        del xc_compute_parameters

    @staticmethod
    def nonlocal_exchange_correlation_gradient(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Gptr,
        ):

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Gptr2 = ce.Pointer()
        Gptr2.value = np.intp(Gptr)

        # => VV10 parameters <= #
        nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS)


        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestXCDerivativeRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestXCDerivativeRKSCompute failed: %d' % status)
        del xc_compute_parameters

    @staticmethod
    def nonlocal_exchange_correlation_gradient(
        *,
        handle : CuestHandle,
        xc_int_plan : CuestXCIntPlan,
        nocc,
        Coccptr,
        Gptr,
        ):

        Coccptr2 = ce.Pointer()
        Coccptr2.value = np.intp(Coccptr)

        Gptr2 = ce.Pointer()
        Gptr2.value = np.intp(Gptr)

        # => VV10 parameters <= #
        nonlocal_xc_compute_parameters = CuestParameters(parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS)

        vv10_b = ce.data_double(xc_int_plan.vv10_b)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_B,
            attributeValue=vv10_b,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_C = ce.data_double(xc_int_plan.vv10_c)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_C,
            attributeValue=vv10_C,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        vv10_scale = ce.data_double(xc_int_plan.vv10_scale)
        status = ce.cuestParametersConfigure(
            parametersType=ce.CuestParametersType.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS,
            parameters=nonlocal_xc_compute_parameters.parameters,
            attribute=ce.CuestNonlocalXCDerivativeRKSComputeParametersAttributes.CUEST_NONLOCALXCDERIVATIVERKSCOMPUTE_PARAMETERS_VV10_SCALE,
            attributeValue=vv10_scale,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestParametersConfigure failed: %d' % status)

        # => Workspace query <= #

        # Allow the algorithm to use up to 2GB of DRAM
        # NOTE: Production codes may wish to configure the maximum temporary
        # workspace memory as a user parameter or heuristic
        xcint_variable_buffer_descriptor = CuestWorkspaceDescriptor(
            deviceBufferSizeInBytes=2000000000,
            )

        temporary_workspace_descriptor = CuestWorkspaceDescriptor()

        status = ce.cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspaceDescriptor=temporary_workspace_descriptor.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCDerivativeRKSComputeWorkspaceQuery failed: %d' % status)

        temporary_workspace = CuestWorkspace(workspaceDescriptor=temporary_workspace_descriptor)

        status = ce.cuestNonlocalXCDerivativeRKSCompute(
            handle=handle.handle,
            plan=xc_int_plan.xc_int_plan_handle,
            parameters=nonlocal_xc_compute_parameters.parameters,
            variableBufferSize=xcint_variable_buffer_descriptor.pointer,
            temporaryWorkspace=temporary_workspace.pointer,
            numOccupied=nocc,
            coefficientMatrix=Coccptr2,
            outGradient=Gptr2,
            )

        if status != ce.CuestStatus.CUEST_STATUS_SUCCESS:
            raise RuntimeError('cuestNonlocalXCDerivativeRKSCompute failed: %d' % status)
        del nonlocal_xc_compute_parameters


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce
import cuest_scf

import os
filedir = os.path.dirname(os.path.realpath(__file__))
basisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')

# Usually you want one CuestHandle for many computations - e.g., do not spin up
# separate handles for every RHF instance
cuest_handle = cuest_scf.CuestHandle()

# This will set the cuEST handle so all operations are performed with FP64 arithmetic
# cuest_handle.set_math_mode(mode=ce.CuestMathMode.CUEST_NATIVE_FP64_MATH_MODE)

# Reasonable default - as coarse as 1.0E-10 yields high-precision results
# Coarser can save some CoreDF memory and lower runtime
threshold_pq = 1.0E-10

molecule = cuest_scf.Molecule.parse_from_xyz_file('paxlovid.xyz')
#molecule = cuest_scf.Molecule.parse_from_xyz_file('192atoms_benzene16.xyz')
charge = 0

primary_name = 'def2-tzvp'
auxiliary_name = 'def2-universal-jkfit'
minao_name = 'minao-1'

primary_filename = os.path.join(basisdir, '%s.gbs' % (primary_name))
auxiliary_filename = os.path.join(basisdir, '%s.gbs' % (auxiliary_name))
minao_filename = os.path.join(basisdir, '%s.gbs' % (minao_name))

primary = cuest_scf.AOBasis.parse_from_gbs_file(primary_filename, molecule=molecule)
auxiliary = cuest_scf.AOBasis.parse_from_gbs_file(auxiliary_filename, molecule=molecule)
minao = cuest_scf.AOBasis.parse_from_gbs_file(minao_filename, molecule=molecule)

rhf = cuest_scf.RHF(
    cuest_handle=cuest_handle,
    molecule=molecule,
    charge=charge,
# NOTE: xc_functional_name is used to specify the XC functional.
# Currently supported functionals are listed below.
    xc_functional_name='HF',
    #xc_functional_name='B3LYP1',
    #xc_functional_name='B3LYP5',
#    xc_functional_name='B97',
#    xc_functional_name='BLYP',
#    xc_functional_name='M06-L',
#    xc_functional_name='PBE',
#    xc_functional_name='PBE0',
#    xc_functional_name='r2SCAN',
#    xc_functional_name='SVWN5',
    #xc_functional_name='B97M-V',
    primary=primary,
    auxiliary=auxiliary,
    minao=minao,
    primary_name=primary_name,
    auxiliary_name=auxiliary_name,
    minao_name=minao_name,
    threshold_pq=threshold_pq,
    df_fitting_eigenvalue_cutoff=1.0e-12,
    # NOTE: Delicate applications or tight comparisons of gradients may require
    # tighter than the working default of g_convergence=1.0E-6
    # g_convergence=1.0E-8,
    xc_grid_family="SG",
    xc_grid_level=1,
    xc_threshold_collocation=1.0e-18,  # Collocation threshold for local XC potential
    nlc_threshold_collocation=1.0e-18, # Collocation threshold for nonlocal (VV10) potential
    dfk_int8_modulus_count_start=8,
    dfk_int8_modulus_count_end=8,
    dfk_int8_slice_count_start=5,
    dfk_int8_slice_count_end=5,
    pcm_num_angular_points_per_hydrogen_atom=110,
    pcm_num_angular_points_per_heavy_atom=194,
    pcm_epsilon=1.0,
    pcm_cutoff=1e-10,
    pcm_convergence_tol=1e-10,
    )

rhf.solve()

print('SCF Energy: %24.16E' % (rhf.compute_energy()))
print('')

#print('SCF Gradient:')
#print(rhf.compute_gradient().to_numpy())


# SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
NPP 3-Channel Canny Edge Detection - Simple Example
====================================================

Detects edges in color images using NVIDIA NPP.
20x faster than OpenCV, detects 60% more edges.


#!/usr/bin/env python3

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import sys

from nvMatmulHeuristics import (


#!/usr/bin/env python3

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import ctypes
import sys


# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import time
import cv2
import torch
import ctypes
import numpy as np


#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES.  All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#  - Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  - Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#  - Neither the name(s) of the copyright holder(s) nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR


# ! /usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES.  All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#  - Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  - Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#  - Neither the name(s) of the copyright holder(s) nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR


#!/usr/bin/env python3

# SPDX-FileCopyrightText: Copyright (c) 2018-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import struct
import argparse
import numpy


#!/usr/bin/env python

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import codecs
import os
import subprocess


# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse

import jax
from jax.experimental.shard_map import shard_map


# -*- coding: utf-8 -*-

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import time
import math
import numpy as np
import sys


# -*- coding: utf-8 -*-

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .utils import Dist, Dir


# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from enum import Enum

import jax
from jax.sharding import PartitionSpec


# -*- coding: utf-8 -*-

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = ["cufftmp"]

from functools import partial


# -*- coding: utf-8 -*-

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .cufftmp_jax import cufftmp


# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from functools import partial

import jax
from jax.sharding import NamedSharding
from jax.experimental.custom_partitioning import custom_partitioning
from fft_common import Dir


# -*- coding: utf-8 -*-

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .xfft import xfft


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce
import numpy as np
import argparse
from pathlib import Path
import sys
import os


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce
import numpy as np
import argparse
from pathlib import Path
import sys


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

import sys
from pathlib import Path

# Inject the directory where the example helper utilities live


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

def cuest_check(
    title,
    return_code
    ):


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce
import sys
from pathlib import Path

# Inject the directory where the example helper utilities live
sys.path.insert(0, str(Path(__file__).parent.parent.parent))


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from collections import namedtuple

def simple_xyz_parser(
    *,
    filename,


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

try:
    import numpy as np
except ImportError:
    raise RuntimeError("numpy could not be imported. It is available via\n\tpip install numpy")

def normalize_shell_coefficients(


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np

def symbol_to_ahlrichs_radius(
    *,
    symbol,
    ):


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# There are numerous way to access GPU resources from Python.  High level
# packages such as CuPy, TensorFlow and Pytorch can simplify allocations and
# transfers between host and device.  Here we demonstrate two lower level
# approaches to accessing CUDA functions to provide these utilities: 1) using
# the cuda-bindings package to access native CUDA in Pythonic way, and 2) using
# the ctypes module to directly access these functions from the CUDA runtime


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest_scf

import os
filedir = os.path.dirname(os.path.realpath(__file__))
basisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest_scf
import numpy as np
import os
filedir = os.path.dirname(os.path.realpath(__file__))
basisdir = os.path.join(filedir, '..', '..', 'data', 'gbs')


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np

class SADAtomStructure(object):

    def __init__(
        self,


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

class XCFunctionalInfo(object):

    @staticmethod
    def string_to_enum(


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .memoized_property import memoized_property

import cuest.bindings as ce

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor
from .cuest_workspace import CuestWorkspace


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
from .gpu_matrix import GPUMatrix
from .gpu_matrix_utility import GPUMatrixUtility

class DIIS(object):


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class PeriodicTable(object):

    symbol_to_N_table = {
        'X'  :   0,
        'H'  :   1,
        'He' :   2,


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np

from .cuda_utility import CudaUtility

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .memoized_property import memoized_property

import cuest.bindings as ce
import numpy as np

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor
from .cuest_workspace import CuestWorkspace

from .cuest_handle import CuestHandle


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

class CuestParameters(object):

    def __init__(
        self,


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

from .cuest_parameters import CuestParameters

class CuestHandle(object):


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from functools import wraps

def memoized_property(fget):
    """
    Return a property attribute for new-style classes that only calls its getter on the first
    access. The result is stored and on subsequent accesses is returned, preventing the need to


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np

from .memoized_property import memoized_property

from .molecule import Molecule
from .ao_basis import AOBasis


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import cuda.bindings.runtime as cuda

class CudaUtility(object):

    @staticmethod


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

from .ao_basis import AOBasis

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor
from .cuest_workspace import CuestWorkspace


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import atexit

import nvmath.bindings.cublas as cublas
import nvmath.bindings.cusolverDn as cusolver
import nvmath.bindings.cusolver as cusolver_base


# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

from .cuest_handle import CuestHandle
from .cuest_df_int_plan import CuestDFIntPlan

from .cuest_workspace_descriptor import CuestWorkspaceDescriptor


# Copyright 2025-2026 NVIDIA CORPORATION & AFFILIATES.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import cuest.bindings as ce

class CuestResults(object):

    def __init__(
        self,
        *,