Skip to main content

lsdensities: Lattice spectral densities

Project description

LSDensities: Lattice Spectral Densities

lsdensities is a Python library for the calculation of smeared spectral densities from lattice correlators.

Solutions can be obtained with the Hansen Lupo Tantalo method and Bayesian inference with Gaussian Processes, or combinations of the two.

This library is based on mpmath for performing the high-precision arithmetic operations that are necessary for the solution of the inverse problem.

Authors

Niccolò Forzano, Alessandro Lupo.

Installation

One can download, build and install the package

pip install https://github.com/LupoA/lsdensities

Usage

Preliminary tests can be found in the tests folder, and tested using the pytest command.

Usage examples can be found in the examples folder.

The most basic workflow is illustrated in examples/runExact.py, which generates a high-precision correlator, and computes the corresponding spectral density smeared with one of the available kernels.

A realistic example is shown in examples/runInverseProblem.py, where input data for the correlator needs to be provided.

The most complete class is src/lsdensities/InverseProblemWrapper.py, which provides utilities for estimating errors and treating the bias both in the HLT and in the Bayesian framework.

Function call example:

from lsdensities.utils.rhoUtils import (init_precision, Inputs)
from mpmath import mp, mpf
from lsdensities.core import Smatrix_mp
from lsdensities.transform import h_Et_mp_Eslice, y_combine_central_Eslice_mp
from lsdensities.utils.rhoMath import gauss_fp

# compute the smeared spectral density at some energy,
# from a lattice correlator

init_precision(128)
parameters = Inputs()
parameters.time_extent = 32
parameters.kerneltype = 'FULLNORMGAUSS'  # Kernel smearing spectral density
parameters.periodicity = 'EXP'  # EXP / COSH for open / periodic boundary conditions
parameters.sigma = 0.25  # smearing radius in given energy units
peak = 1    #   energy level in the correlator
energy = 0.5     # energy at which the smeared spectral density
                 # is evaluated in given energy units
parameters.assign_values()  # assigns internal variables
                            # based on given inputs
                            # such as tmax = number of data points,
                            # which is inferred from time_extent and periodicity,
                            # if not specified

lattice_correlator = mp.matrix(parameters.tmax, 1)  #  vector; fill with lattice data
lattice_covariance = mp.matrix(parameters.tmax)     #  matrix; fill with data covariance

for t in range(parameters.tmax):    # mock data
    lattice_correlator[t] = mp.exp(-mpf(t + 1) * mpf(str(peak)))
    lattice_covariance[t,t] = lattice_correlator[t] * 0.02


regularising_parameter = mpf(str(1e-6))   # regularising parameters; must be tuned.
                                          # Automatic tuning is provided in InverseProblemWrapper.py
                                          # this example has exact data, so the parameters
                                          # can be made as small as zero,
                                          # in which case the result will be exact in
                                          # the limit of infinite tmax

regularised_matrix = Smatrix_mp(parameters.tmax, alpha_=0) + (regularising_parameter * lattice_covariance)
matrix_inverse = regularised_matrix**(-1)

coeff = h_Et_mp_Eslice(matrix_inverse,   # linear coefficients
                       parameters,
                       energy,
                       alpha_=0)

result = y_combine_central_Eslice_mp(coeff,     # linear combination of data
                                     lattice_correlator,
                                     parameters)

true_value = gauss_fp(peak, energy, parameters.sigma, norm="full")

print("Result: ", float(result))   # reconstructed smeared spectral density at E = energy
print("Exact results :", true_value)  # exact smeared spectral density at E = energy

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Development requirements can be installed by using pip install -r requirements.txt, and they are listed in requirements.txt.

References

For the mean ideas: https://arxiv.org/pdf/1903.06476.pdf

For the Bayesian setup and the general treatment of the bias: https://arxiv.org/pdf/2311.18125.pdf

License

GPL

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

lsdensities-0.0.1.tar.gz (58.4 kB view details)

Uploaded Source

Built Distribution

lsdensities-0.0.1-py3-none-any.whl (60.7 kB view details)

Uploaded Python 3

File details

Details for the file lsdensities-0.0.1.tar.gz.

File metadata

  • Download URL: lsdensities-0.0.1.tar.gz
  • Upload date:
  • Size: 58.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.8

File hashes

Hashes for lsdensities-0.0.1.tar.gz
Algorithm Hash digest
SHA256 da61cd078d4972e4924e89a97f1984e28f297e241e5ebc1fa4112a3808444cda
MD5 c68400eebb0b07bfe500e111cc41c47b
BLAKE2b-256 1a3775d76f916837b20f189c8f4cb1d13376243d82120623f2feaa3e177564f7

See more details on using hashes here.

File details

Details for the file lsdensities-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: lsdensities-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 60.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.8

File hashes

Hashes for lsdensities-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bc71bc58fb11cac3a8dbd0c7903e1312163b5f7ce698db6e24be270a0712ef54
MD5 77ea0accb881c10b137eec2eb846a684
BLAKE2b-256 2b0e5862cc138cf2d5ef5e068419094ebc9b335f3beae69d14105e0ce18ecb49

See more details on using hashes here.

Supported by

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