Skip to content

Commit

Permalink
Merge pull request #3588 from GreatRSingh/deep-1
Browse files Browse the repository at this point in the history
DFT Utilities [PR-1] [Config | Ztypes]
  • Loading branch information
rbharath committed Oct 2, 2023
2 parents 8955074 + a22b583 commit 422e747
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
15 changes: 15 additions & 0 deletions deepchem/utils/dft_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Density Functional Theory utilities.
"""
# flake8: noqa
import logging

logger_ = logging.getLogger(__name__)

from deepchem.utils.dft_utils.config import config

try:
from deepchem.utils.dft_utils.datastruct import ZType
except ModuleNotFoundError as e:
logger_.warning(
f'Skipped loading some Pytorch utilities, missing a dependency. {e}')
42 changes: 42 additions & 0 deletions deepchem/utils/dft_utils/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Density Function Theory Configuration Utilities.
"""

from dataclasses import dataclass

__all__ = ["config"]


@dataclass
class _Config(object):
"""Contains the configuration for the DFT module
Examples
--------
>>> from deepchem.utils.dft_utils.config import config
>>> Memory_usage = 1024**4 # Sample Memory usage by some Object/Matrix
>>> if Memory_usage > config.THRESHOLD_MEMORY :
... print("Overload")
Overload
Attributes
----------
THRESHOLD_MEMORY: int (default=10*1024**3)
Threshold memory (matrix above this size should not be constructed)
CHUNK_MEMORY: int (default=16*1024**2)
The memory for splitting big tensors into chunks.
VERBOSE: int (default=0)
Allowed Verbosity level (Defines the level of detail)
Used by Looger for maintaining Logs.
Usage
-----
1. HamiltonCGTO: Usage it for splitting big tensors into chunks.
"""
THRESHOLD_MEMORY: int = 10 * 1024**3 # in Bytes
CHUNK_MEMORY: int = 16 * 1024**2 # in Bytes
VERBOSE: int = 0


config = _Config()
14 changes: 14 additions & 0 deletions deepchem/utils/dft_utils/datastruct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Density Functional Theory Data Structure Utilities
"""
from typing import Union, TypeVar

import torch

__all__ = ["ZType"]

T = TypeVar('T')
P = TypeVar('P')

# type of the atom Z
ZType = Union[int, float, torch.Tensor]
12 changes: 12 additions & 0 deletions deepchem/utils/dft_utils/test/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Test for DFT Config Utilities
"""

from deepchem.utils.dft_utils.config import config


def test_config():
conf = config
assert conf.THRESHOLD_MEMORY == 10 * 1024**3
assert conf.CHUNK_MEMORY == 16 * 1024**2
assert conf.VERBOSE == 0
4 changes: 4 additions & 0 deletions docs/source/api_reference/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ The utilites here are used to create an object that contains information about a
.. autoclass:: deepchem.utils.dftutils.SpinParam
:members:

.. autoclass:: deepchem.utils.dft_utils.config._Config
:members:


Pytorch Utilities
-----------------

Expand Down

0 comments on commit 422e747

Please sign in to comment.