Skip to main content

Quick Uncertainty and Entropy from STructural Similarity

Project description

QUESTS: Quick Uncertainty and Entropy via STructural Similarity

QUESTS provides model-free uncertainty and entropy estimation methods for interatomic potentials. Among the methods, we propose a structural descriptor based on k-nearest neighbors that:

  1. Is fast to compute, as it uses only distances between atoms within an environment. Because the computation of descriptors is efficiently parallelized, generation of descriptors for 1.5M environments takes about 3 seconds on 56 threads (tested against Intel Xeon CLX-8276L CPUs).
  2. Can be used to analyze datasets for atomistic machine learning, providing quantities such as dataset entropy, diversity, information gap, and others.
  3. Is shown to recover many useful properties of information theory, and can be used to inform dataset compression

This package also contains tools to interface with other representations and packages.

Installation

From pip

pip install quests

From repository

To install the quests package directly from the repository, clone it from GitHub and use pip to install it into your virtual environment:

git clone https://github.com/dskoda/quests.git
cd quests
pip install .

Typical installation times are on the order of a minute, and depend mostly on the internet connection to download the dependencies and on conflict resolution by the package manager (if applicable).

Usage

Command line

Once installed, you can use the quests command to perform different analyses. For example, to compute the entropy of any dataset (the input can be anything that ASE reads, including xyz files), you can use the quests entropy command:

quests entropy dump.lammpstrj --bandwidth 0.015

For subsampling the dataset and avoiding using the entire dataset, use the entropy_sampler example:

quests entropy_sampler dataset.xyz --batch_size 20000 -s 100000 -n 3

-s specifies the number of sampled environments, -n specifies how many runs will be computed (for statistics).

For additional help with these commands, please use quests --help, quests entropy --help, and others.

API

Computing descriptors and dataset entropy

To use the QUESTS package to create descriptors and compute entropies, you can use the descriptor and entropy submodules:

from ase.io import read
from quests.descriptor import get_descriptors
from quests.entropy import perfect_entropy, diversity

dset = read("dataset.xyz", index=":")
x = get_descriptors(dset, k=32, cutoff=5.0)
h = 0.015
batch_size = 10000
H = perfect_entropy(x, h=h, batch_size=batch_size)
D = diversity(x, h=h, batch_size=batch_size)

In this example, descriptors are being created using 32 nearest neighbors and a 5.0 Å cutoff. The entropy and diversity are being computed using a Gaussian kernel (default) with bandwidth of 0.015 1/Å and batch size of 10,000.

Computing differential entropies

from ase.io import read
from quests.descriptor import get_descriptors
from quests.entropy import delta_entropy

dset_x = read("reference.xyz", index=":")
dset_y = read("test.xyz", index=":")

k, cutoff = 32, 5.0
x = get_descriptors(dset_x, k=k, cutoff=cutoff)
y = get_descriptors(dset_y, k=k, cutoff=cutoff)

# computes dH (Y | X)
dH = delta_entropy(y, x, h=0.015)

Computing approximate differential entropies

from ase.io import read
from quests.descriptor import get_descriptors
from quests.entropy import approx_delta_entropy

dset_x = read("reference.xyz", index=":")
dset_y = read("test.xyz", index=":")

k, cutoff = 32, 5.0
x = get_descriptors(dset_x, k=k, cutoff=cutoff)
y = get_descriptors(dset_y, k=k, cutoff=cutoff)

# approximates dH (Y | X)
# n = 5 and graph_neighbors = 10 are arguments for
# pynndescent, which performs an approximate nearest
# neighbor search for dH
dH = approx_delta_entropy(y, x, h=0.015, n=5, graph_neighbors=10)

Computing the dataset entropy using PyTorch

To accelerate the computation of entropy of datasets, one can use PyTorch to compute the entropy of a system. This can be done by first installing the optional dependencies for this repository:

pip install quests[gpu]

The syntax of the entropy, as computed with PyTorch, is identical to the one above. Instead of loading the functions from quests.entropy, however, you should load them from quests.gpu.entropy. The descriptors remain the same - as of now, creating descriptors using GPUs is not supported. Note that this constraint requires the descriptors to be generated using the traditional routes, and later converted into a torch.tensor.

import torch
from ase.io import read
from quests.descriptor import get_descriptors
from quests.gpu.entropy import perfect_entropy

dset = read("dataset.xyz", index=":")
x = get_descriptors(dset, k=32, cutoff=5.0)
x = torch.tensor(x, device="cuda")
h = 0.015
batch_size = 10000
H = perfect_entropy(x, h=h, batch_size=batch_size)

Computing overlap between datasets

To compute the overlap between two datasets, you can use the overlap command-line interface or the API:

quests overlap test.xyz ref.xyz -o results.json

This command will compute the overlap between the environments in test.xyz and ref.xyz, and save the results to results.json.

Using the API:

from ase.io import read
from quests.descriptor import get_descriptors
from quests.entropy import delta_entropy

test = read("test.xyz", index=":")
ref = read("ref.xyz", index=":")

k, cutoff = 32, 5.0
x1 = get_descriptors(test, k=k, cutoff=cutoff)
x2 = get_descriptors(ref, k=k, cutoff=cutoff)

h = 0.015  # bandwidth
eps = 1e-5  # threshold for overlap
delta = delta_entropy(x1, x2, h=h)
overlap = (delta < eps).mean()

print(f"Overlap value: {overlap:.4f}")

This example computes the overlap between two datasets using a bandwidth of 0.015 and an overlap threshold of 1e-3. The overlap is defined as the fraction of environments where the delta entropy is below the threshold.

Obtaining a Learning Curve

To generate a learning curve using the command line interface, you can use the learning_curve command. This command computes the entropy at different dataset fractions, allowing you to see how the entropy changes as you include more data:

quests learning_curve dataset.xyz -o learning_curve_results.json

This command will:

  1. Use the default fractions (0.1 to 0.9 in steps of 0.1)
  2. Compute the entropy for each fraction
  3. Run the computation 3 times for each fraction (default value)
  4. Save the results in a JSON file named learning_curve_results.json

You can customize the command with various options:

  • -f or --fractions: Specify custom fractions (e.g., -f 0.2,0.4,0.6,0.8)
  • -n or --num_runs: Set the number of runs for each fraction (e.g., -n 5)
  • -b or --bandwidth: Set the bandwidth for entropy calculation (e.g., -b 0.015)

A more customized command might look like this:

quests learning_curve dataset.xyz -f 0.2,0.4,0.6,0.8 -n 5 -c 5.0 -k 32 -b 0.015 -o custom_learning_curve.json

This will compute the learning curve for fractions 0.2, 0.4, 0.6, and 0.8, running each fraction 5 times, with a cutoff of 5.0 Å, 32 neighbors, and a bandwidth of 0.015.

The resulting JSON file will contain detailed information about the learning curve, including the entropy values for each fraction and run, as well as the mean and standard deviation of the entropy for each fraction.

Demonstration

One example demonstrating the use of QUESTS for computing the entropy of the Carbon GAP-20 dataset is provided under the folder examples. The script automatically downloads the dataset and shows how to compute the entropy. Please run this script only after following the installation instructions.

This first example reproduces the first part of Fig. 2c of the manuscript. Computing the entropies takes a few minutes on a MacBook Pro M3 with 16 threads (default used by numba).

Citing

If you use QUESTS in a publication, please cite the following paper:

@article{schwalbekoda2024information,
    title = {Model-free quantification of completeness, uncertainties, and outliers in atomistic machine learning using information theory},
    author = {Schwalbe-Koda, Daniel and Hamel, Sebastien and Sadigh, Babak and Zhou, Fei and Lordi, Vincenzo},
    year = {2024},
    journal = {arXiv:2404.12367},
    url = {https://arxiv.org/abs/2404.12367},
}

License

The QUESTS software is distributed under the following license: BSD-3

All new contributions must be made under this license.

SPDX: BSD-3-Clause

Acknowledgements

This work was initially produced under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344, with support from LLNL's LDRD program under tracking codes 22-ERD-055 and 23-SI-006.

Code released as LLNL-CODE-858914

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quests-2025.3.14.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quests-2025.3.14-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

Details for the file quests-2025.3.14.tar.gz.

File metadata

  • Download URL: quests-2025.3.14.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for quests-2025.3.14.tar.gz
Algorithm Hash digest
SHA256 76f7b1890353de6cd9b739bd1d8eed67d3e5fa2d48f8882fd290ac7f6be8ae7d
MD5 6f7684b12f94d8e152c6763d4a100b0a
BLAKE2b-256 fd7ae7079a4e5688cbeee3c3d3c41d42cc40895a53ae1e57508bcd3d8ff511a5

See more details on using hashes here.

File details

Details for the file quests-2025.3.14-py3-none-any.whl.

File metadata

  • Download URL: quests-2025.3.14-py3-none-any.whl
  • Upload date:
  • Size: 37.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for quests-2025.3.14-py3-none-any.whl
Algorithm Hash digest
SHA256 8e4dcd5df4178d20dfbd318b38ab95e34250475aea4afeee1d22f35bd08f20ae
MD5 00dc4ae39858891ac1755199e13d1f3a
BLAKE2b-256 4b949097c6c52d0cbd5f441e37df4a9f27e1b488fc00fe32ad05c52281ef3ff8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page