Merge branch 'develop' into feature/rwf

This commit is contained in:
Simon Kuberski 2022-02-09 17:57:59 +01:00
commit 78254020f8
6 changed files with 99 additions and 48 deletions

View file

@ -2,30 +2,39 @@
All notable changes to this project will be documented in this file.
## [2.0.0] - 2021-??-??
## [2.0.0] - 2022-??-??
### Added
- The possibility to work with Monte Carlo histories which are evenly or unevenly spaced was added.
- `cov_Obs` added as a possibility to propagate the error of non Monte Carlo data together with Monte Carlo data.
- `CObs` class added which can handle complex valued Markov chain Monte Carlo data and the corresponding error propagation.
- Matrix to matrix operations like the matrix inverse now also work for complex matrices and matrices containing entries that are not `Obs` but `float` or `int`.
- The possibility to work with Monte Carlo histories which are evenly or unevenly spaced was added.
- Support for a new `json.gz` file format was added
- The Corr class now has additional methods like `reverse`, `T_symmetry`, `correlate` and `reweight`.
- `linalg` module now has explicit functions `inv` and `cholesky`.
- `Corr.m_eff` can now cope with periodic and anti-periodic correlation functions
- Forward, backward and improved variants of the first and second derivative were added to the `Corr` class
- The `linalg` module now has explicit functions `inv` and `cholesky`.
- `Obs` objects now have methods `is_zero` and `is_zero_within_error` as well as overloaded comparison operations.
- Functions to convert Obs data to or from jackknife was added.
- Alternative matrix multiplication routine `jack_matmul` was added to `linalg` module which makes use of the jackknife approximation and is much faster for large matrices.
- Additional input routines for npr data added to `input.hadrons`.
- The `sfcf` and `openQCD` input modules can now handle all recent file type versions.
- `extract_t0` can now visualize the extraction on the fly
- Module added which provides the Dirac gamma matrices in the Grid convention.
- Version number added.
### Changed
- The internal bookkeeping system for ensembles/replica was changed. The separator for replica is now `|`.
- The fit functions were renamed to `least_squares` and `total_least_squares`.
- The output of the fit functions is now a dedicated results class which keeps track of all relevant information
- The fit functions can now deal with provided covariance matrices.
- The convention for the fit range in the Corr class has been changed.
- Obs.print was renamed to Obs.details and the output was improved.
- Various method of the `Corr` class were renamed
- `Obs.print` was renamed to `Obs.details` and the output was improved.
- The default value for `Corr.prange` is now `None`.
- The `input` module was restructured to contain one submodule per data source.
- Performance of Obs.__init__ improved.
### Deprecated
### Removed
- The function `plot_corrs` was deprecated as all its functionality is now contained within `Corr.show`
- The kwarg `bias_correction` in `derived_observable` was removed
- Obs no longer have an attribute `e_Q`

View file

@ -376,6 +376,24 @@ class Corr:
"""Reverse the time ordering of the Corr"""
return Corr(self.content[:: -1])
def thin(self, spacing=2, offset=0):
"""Thin out a correlator to suppress correlations
Parameters
----------
spacing : int
Keep only every 'spacing'th entry of the correlator
offset : int
Offset the equal spacing
"""
new_content = []
for t in range(self.T):
if (offset + t) % spacing != 0:
new_content.append(None)
else:
new_content.append(self.content[t])
return Corr(new_content)
def correlate(self, partner):
"""Correlate the correlator with another correlator or Obs

View file

@ -171,6 +171,9 @@ def create_json_string(ol, description='', indent=1):
names.append(key)
idl.append(value)
my_obs = Obs(samples, names, idl)
my_obs._covobs = obs._covobs
for name in obs._covobs:
my_obs.names.append(name)
my_obs.reweighted = obs.reweighted
my_obs.is_merged = obs.is_merged
return my_obs

View file

@ -283,3 +283,11 @@ def test_hankel():
corr.Hankel(2)
corr.Hankel(6, periodic=True)
def test_thin():
c = pe.Corr([pe.pseudo_Obs(i, .1, 'test') for i in range(10)])
c *= pe.cov_Obs(1., .1, '#ren')
thin = c.thin()
thin.fit(lambda a, x: a[0] * x)
c.thin(offset=1)
c.thin(3, offset=1)

View file

@ -244,46 +244,10 @@ def test_json_dict_io():
os.remove(fname + '.json.gz')
def test_openqcd():
path = './tests//data/openqcd_test/'
prefix = 'sfqcd'
postfix = '.rwms'
# sfqcd-1.6: Trajectories instead of confignumbers are printed to file.
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix)
repname = list(rwfo[0].idl.keys())[0]
assert(rwfo[0].idl[repname] == range(1, 13))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[1], r_stop=[12])
assert(rwfo[0].idl[repname] == range(1, 13))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[3], r_stop=[8])
assert(rwfo[0].idl[repname] == range(3, 9))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[2], r_stop=[6])
assert(rwfo[0].idl[repname] == range(2, 7))
rwfs = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[1], r_stop=[12], r_step=2)
assert(rwfs[0].idl[repname] == range(1, 12, 2))
rwfs = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[2], r_stop=[12], r_step=2)
assert(rwfs[0].idl[repname] == range(2, 13, 2))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix)
assert((rwfo[0].r_values[repname] + rwfo[0].deltas[repname][1]) == (rwfs[0].r_values[repname] + rwfs[0].deltas[repname][0]))
o = pe.pseudo_Obs(1., .01, repname, samples=12)
pe.reweight(rwfo[0], [o])
o = pe.pseudo_Obs(1., .01, repname, samples=6)
pe.reweight(rwfo[0], [o])
o.idl[repname] = range(2, 13, 2)
pe.reweight(rwfo[0], [o])
pe.reweight(rwfs[0], [o])
files = ['openqcd2r1.ms1.dat']
names = ['openqcd2|r1']
# TM with 2 Hasenbusch factors and 2 sources each + RHMC with one source, openQCD 2.0
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='2.0', files=files, names=names)
assert(len(rwfo) == 2)
assert(rwfo[0].value == 0.9999974970236312)
assert(rwfo[1].value == 1.184681251089919)
repname = list(rwfo[0].idl.keys())[0]
assert(rwfo[0].idl[repname] == range(1, 10))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='2.0', files=files, names=names, r_start=[1], r_stop=[8])
assert(rwfo[0].idl[repname] == range(1, 9))
def test_renorm_deriv_of_corr(tmp_path):
c = pe.Corr([pe.pseudo_Obs(i, .1, 'test') for i in range(10)])
c *= pe.cov_Obs(1., .1, '#ren')
c = c.deriv()
pe.input.json.dump_to_json(c, (tmp_path / 'test').as_posix())
recover = pe.input.json.load_json((tmp_path / 'test').as_posix())
assert np.all([o == 0 for o in (c - recover)[1:-1]])

49
tests/openQCD_in_test.py Normal file
View file

@ -0,0 +1,49 @@
import os
import numpy as np
import pyerrors as pe
import pytest
def test_openqcd():
path = './tests//data/openqcd_test/'
prefix = 'sfqcd'
postfix = '.rwms'
# sfqcd-1.6: Trajectories instead of confignumbers are printed to file.
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix)
repname = list(rwfo[0].idl.keys())[0]
assert(rwfo[0].idl[repname] == range(1, 13))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[1], r_stop=[12])
assert(rwfo[0].idl[repname] == range(1, 13))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[3], r_stop=[8])
assert(rwfo[0].idl[repname] == range(3, 9))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[2], r_stop=[6])
assert(rwfo[0].idl[repname] == range(2, 7))
rwfs = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[1], r_stop=[12], r_step=2)
assert(rwfs[0].idl[repname] == range(1, 12, 2))
rwfs = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[2], r_stop=[12], r_step=2)
assert(rwfs[0].idl[repname] == range(2, 13, 2))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix)
assert((rwfo[0].r_values[repname] + rwfo[0].deltas[repname][1]) == (rwfs[0].r_values[repname] + rwfs[0].deltas[repname][0]))
o = pe.pseudo_Obs(1., .01, repname, samples=12)
pe.reweight(rwfo[0], [o])
o = pe.pseudo_Obs(1., .01, repname, samples=6)
pe.reweight(rwfo[0], [o])
o.idl[repname] = range(2, 13, 2)
pe.reweight(rwfo[0], [o])
pe.reweight(rwfs[0], [o])
files = ['openqcd2r1.ms1.dat']
names = ['openqcd2|r1']
# TM with 2 Hasenbusch factors and 2 sources each + RHMC with one source, openQCD 2.0
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='2.0', files=files, names=names)
assert(len(rwfo) == 2)
assert(rwfo[0].value == 0.9999974970236312)
assert(rwfo[1].value == 1.184681251089919)
repname = list(rwfo[0].idl.keys())[0]
assert(rwfo[0].idl[repname] == range(1, 10))
rwfo = pe.input.openQCD.read_rwms(path, prefix, version='2.0', files=files, names=names, r_start=[1], r_stop=[8])
assert(rwfo[0].idl[repname] == range(1, 9))