# pyerrors

# What is pyerrors?

`pyerrors` is a python package for error computation and propagation of Markov chain Monte Carlo data. It is based on the gamma method arXiv:hep-lat/0306017. Some of its features are:

- automatic differentiation for exact liner error propagation as suggested in arXiv:1809.01289 (partly based on the autograd package).
- treatment of slow modes in the simulation as suggested in arXiv:1009.5228.
- coherent error propagation for data from different Markov chains.
- non-linear fits with x- and y-errors and exact linear error propagation based on automatic differentiation as introduced in arXiv:1809.01289.
- real and complex matrix operations and their error propagation based on automatic differentiation (Matrix inverse, Cholesky decomposition, calculation of eigenvalues and eigenvectors, singular value decomposition...).

There exist similar publicly available implementations of gamma method error analysis suites in Fortran, Julia and Python.

## Basic example

    import numpy as np
    import pyerrors as pe

    my_obs = pe.Obs([samples], ['ensemble_name']) # Initialize an Obs object
    my_new_obs = 2 * np.log(my_obs) / my_obs ** 2 # Construct derived Obs object
    my_new_obs.gamma_method()                     # Estimate the statistical error
    print(my_new_obs)                             # Print the result to stdout
    > 0.31498(72)

# The `Obs` class

`pyerrors` introduces a new datatype, `Obs`, which simplifies error propagation and estimation for auto- and cross-correlated data. An `Obs` object can be initialized with two arguments, the first is a list containing the samples for an observable from a Monte Carlo chain. The samples can either be provided as python list or as numpy array. The second argument is a list containing the names of the respective Monte Carlo chains as strings. These strings uniquely identify a Monte Carlo chain/ensemble.

    import pyerrors as pe

    my_obs = pe.Obs([samples], ['ensemble_name'])

## Error propagation

When performing mathematical operations on `Obs` objects the correct error propagation is intrinsically taken care of using a first order Taylor expansion $$\delta_f^i=\sum_\alpha \bar{f}_\alpha \delta_\alpha^i\,,\quad \delta_\alpha^i=a_\alpha^i-\bar{a}_\alpha\,,$$ as introduced in arXiv:hep-lat/0306017. The required derivatives $\bar{f}_\alpha$ are evaluated up to machine precision via automatic differentiation as suggested in arXiv:1809.01289.

The `Obs` class is designed such that mathematical numpy functions can be used on `Obs` just as for regular floats.

    import numpy as np
    import pyerrors as pe

    my_obs1 = pe.Obs([samples1], ['ensemble_name'])
    my_obs2 = pe.Obs([samples2], ['ensemble_name'])

    my_sum = my_obs1 + my_obs2

    my_m_eff = np.log(my_obs1 / my_obs2)

    iamzero = my_m_eff - my_m_eff
    # Check that value and fluctuations are zero within machine precision
    print(iamzero == 0.0)
    > True

## Error estimation

The error estimation within `pyerrors` is based on the gamma method introduced in arXiv:hep-lat/0306017. After having arrived at the derived quantity of interest the `gamma_method` can be called as detailed in the following example.

    my_sum.gamma_method()
    print(my_sum)
    > 1.70(57)
    my_sum.details()
    > Result         1.70000000e+00 +/- 5.72046658e-01 +/- 7.56746598e-02 (33.650%)
    >  t_int         2.71422900e+00 +/- 6.40320983e-01 S = 2.00
    > 1000 samples in 1 ensemble:
    >   · Ensemble 'ensemble_name' : 1000 configurations (from 1 to 1000)

We use the following definition of the integrated autocorrelation time established in Madras & Sokal 1988 $$\tau_\mathrm{int}=\frac{1}{2}+\sum_{t=1}^{W}\rho(t)\geq \frac{1}{2}\,.$$ The window $W$ is determined via the automatic windowing procedure described in arXiv:hep-lat/0306017. The standard value for the parameter $S$ of this automatic windowing procedure is $S=2$. Other values for $S$ can be passed to the `gamma_method` as parameter.

    my_sum.gamma_method(S=3.0)
    my_sum.details()
    > Result         1.70000000e+00 +/- 6.30675201e-01 +/- 1.04585650e-01 (37.099%)
    >  t_int         3.29909703e+00 +/- 9.77310102e-01 S = 3.00
    > 1000 samples in 1 ensemble:
    >   · Ensemble 'ensemble_name' : 1000 configurations (from 1 to 1000)

The integrated autocorrelation time $\tau_\mathrm{int}$ and the autocorrelation function $\rho(W)$ can be monitored via the methods `pyerrors.obs.Obs.plot_tauint` and `pyerrors.obs.Obs.plot_tauint`.

If the parameter $S$ is set to zero it is assumed that the dataset does not exhibit any autocorrelation and the windowsize is chosen to be zero. In this case the error estimate is identical to the sample standard error.

### Exponential tails

Slow modes in the Monte Carlo history can be accounted for by attaching an exponential tail to the autocorrelation function $\rho$ as suggested in arXiv:1009.5228. The longest autocorrelation time in the history, $\tau_\mathrm{exp}$, can be passed to the `gamma_method` as parameter. In this case the automatic windowing procedure is vacated and the parameter $S$ does not affect the error estimate.

    my_sum.gamma_method(tau_exp=7.2)
    my_sum.details()
    > Result         1.70000000e+00 +/- 6.28097762e-01 +/- 5.79077524e-02 (36.947%)
    >  t_int         3.27218667e+00 +/- 7.99583654e-01 tau_exp = 7.20,  N_sigma = 1
    > 1000 samples in 1 ensemble:
    >   · Ensemble 'ensemble_name' : 1000 configurations (from 1 to 1000)

For the full API see `pyerrors.obs.Obs.gamma_method`.

## Multiple ensembles/replica

Error propagation for multiple ensembles (Markov chains with different simulation parameters) is handled automatically. Ensembles are uniquely identified by their `name`.

    obs1 = pe.Obs([samples1], ['ensemble1'])
    obs2 = pe.Obs([samples2], ['ensemble2'])

    my_sum = obs1 + obs2
    my_sum.details()
    > Result   2.00697958e+00
    > 1500 samples in 2 ensembles:
    >   · Ensemble 'ensemble1' : 1000 configurations (from 1 to 1000)
    >   · Ensemble 'ensemble2' : 500 configurations (from 1 to 500)

`pyerrors` identifies multiple replica (independent Markov chains with identical simulation parameters) by the vertical bar `|` in the name of the data set.

    obs1 = pe.Obs([samples1], ['ensemble1|r01'])
    obs2 = pe.Obs([samples2], ['ensemble1|r02'])

    > my_sum = obs1 + obs2
    > my_sum.details()
    > Result   2.00697958e+00
    > 1500 samples in 1 ensemble:
    >   · Ensemble 'ensemble1'
    >     · Replicum 'r01' : 1000 configurations (from 1 to 1000)
    >     · Replicum 'r02' : 500 configurations (from 1 to 500)

### Error estimation for multiple ensembles

In order to keep track of different error analysis parameters for different ensembles one can make use of global dictionaries as detailed in the following example.

    pe.Obs.S_dict['ensemble1'] = 2.5
    pe.Obs.tau_exp_dict['ensemble2'] = 8.0
    pe.Obs.tau_exp_dict['ensemble3'] = 2.0

In case the `gamma_method` is called without any parameters it will use the values specified in the dictionaries for the respective ensembles. Passing arguments to the `gamma_method` still dominates over the dictionaries.

## Irregular Monte Carlo chains

`Obs` objects defined on irregular Monte Carlo chains can be initialized with the parameter `idl`.

    # Observable defined on configurations 20 to 519
    obs1 = pe.Obs([samples1], ['ensemble1'], idl=[range(20, 520)])
    obs1.details()
    > Result         9.98319881e-01
    > 500 samples in 1 ensemble:
    >   · Ensemble 'ensemble1' : 500 configurations (from 20 to 519)

    # Observable defined on every second configuration between 5 and 1003
    obs2 = pe.Obs([samples2], ['ensemble1'], idl=[range(5, 1005, 2)])
    obs2.details()
    > Result         9.99100712e-01
    > 500 samples in 1 ensemble:
    >   · Ensemble 'ensemble1' : 500 configurations (from 5 to 1003 in steps of 2)

    # Observable defined on configurations 2, 9, 28, 29 and 501
    obs3 = pe.Obs([samples3], ['ensemble1'], idl=[[2, 9, 28, 29, 501]])
    obs3.details()
    > Result         1.01718064e+00
    > 5 samples in 1 ensemble:
    >   · Ensemble 'ensemble1' : 5 configurations (irregular range)

`Obs` objects defined on regular and irregular histories of the same ensemble can be combined with each other and the correct error propagation and estimation is automatically taken care of.

Warning: Irregular Monte Carlo chains can result in odd patterns in the autocorrelation functions. Make sure to check the autocorrelation time with e.g. `pyerrors.obs.Obs.plot_rho` or `pyerrors.obs.Obs.plot_tauint`.

For the full API see `pyerrors.obs.Obs`.

# Correlators

When one is not interested in single observables but correlation functions, `pyerrors` offers the `Corr` class which simplifies the corresponding error propagation and provides the user with a set of standard methods. In order to initialize a `Corr` objects one needs to arrange the data as a list of `Obs`

    my_corr = pe.Corr([obs_0, obs_1, obs_2, obs_3])
    print(my_corr)
    > x0/a  Corr(x0/a)
    > ------------------
    > 0      0.7957(80)
    > 1      0.5156(51)
    > 2      0.3227(33)
    > 3      0.2041(21)

In case the correlation functions are not defined on the outermost timeslices, for example because of fixed boundary conditions, a padding can be introduced.

    my_corr = pe.Corr([obs_0, obs_1, obs_2, obs_3], padding=[1, 1])
    print(my_corr)
    > x0/a  Corr(x0/a)
    > ------------------
    > 0
    > 1      0.7957(80)
    > 2      0.5156(51)
    > 3      0.3227(33)
    > 4      0.2041(21)
    > 5

The individual entries of a correlator can be accessed via slicing

    print(my_corr[3])
    > 0.3227(33)

Error propagation with the `Corr` class works very similar to `Obs` objects. Mathematical operations are overloaded and `Corr` objects can be computed together with other `Corr` objects, `Obs` objects or real numbers and integers.

    my_new_corr = 0.3 * my_corr[2] * my_corr * my_corr + 12 / my_corr

`pyerrors` provides the user with a set of regularly used methods for the manipulation of correlator objects:

- `Corr.gamma_method` applies the gamma method to all entries of the correlator.
- `Corr.m_eff` to construct effective masses. Various variants for periodic and fixed temporal boundary conditions are available.
- `Corr.deriv` returns the first derivative of the correlator as `Corr`. Different discretizations of the numerical derivative are available.
- `Corr.second_deriv` returns the second derivative of the correlator as `Corr`. Different discretizations of the numerical derivative are available.
- `Corr.symmetric` symmetrizes parity even correlations functions, assuming periodic boundary conditions.
- `Corr.anti_symmetric` anti-symmetrizes parity odd correlations functions, assuming periodic boundary conditions.
- `Corr.T_symmetry` averages a correlator with its time symmetry partner, assuming fixed boundary conditions.
- `Corr.plateau` extracts a plateau value from the correlator in a given range.
- `Corr.roll` periodically shifts the correlator.
- `Corr.reverse` reverses the time ordering of the correlator.
- `Corr.correlate` constructs a disconnected correlation function from the correlator and another `Corr` or `Obs` object.
- `Corr.reweight` reweights the correlator.

`pyerrors` can also handle matrices of correlation functions and extract energy states from these matrices via a generalized eigenvalue problem (see `pyerrors.correlators.Corr.GEVP`).

For the full API see `pyerrors.correlators.Corr`.

# Complex valued observables

`pyerrors` can handle complex valued observables via the class `pyerrors.obs.CObs`. `CObs` are initialized with a real and an imaginary part which both can be `Obs` valued.

    my_real_part = pe.Obs([samples1], ['ensemble1'])
    my_imag_part = pe.Obs([samples2], ['ensemble1'])

    my_cobs = pe.CObs(my_real_part, my_imag_part)
    my_cobs.gamma_method()
    print(my_cobs)
    > (0.9959(91)+0.659(28)j)

Elementary mathematical operations are overloaded and samples are properly propagated as for the `Obs` class.

    my_derived_cobs = (my_cobs + my_cobs.conjugate()) / np.abs(my_cobs)
    my_derived_cobs.gamma_method()
    print(my_derived_cobs)
    > (1.668(23)+0.0j)

# The `Covobs` class

In many projects, auxiliary data that is not based on Monte Carlo chains enters. Examples are experimentally determined mesons masses which are used to set the scale or renormalization constants. These numbers come with an error that has to be propagated through the analysis. The `Covobs` class allows to define such quantities in `pyerrors`. Furthermore, external input might consist of correlated quantities. An example are the parameters of an interpolation formula, which are defined via mean values and a covariance matrix between all parameters. The contribution of the interpolation formula to the error of a derived quantity therefore might depend on the complete covariance matrix.

This concept is built into the definition of `Covobs`. In `pyerrors`, external input is defined by $M$ mean values, a $M\times M$ covariance matrix, where $M=1$ is permissible, and a name that uniquely identifies the covariance matrix. Below, we define the pion mass, based on its mean value and error, 134.9768(5). Note, that the square of the error enters `cov_Obs`, since the second argument of this function is the covariance matrix of the `Covobs`.

    import pyerrors.obs as pe

    mpi = pe.cov_Obs(134.9768, 0.0005**2, 'pi^0 mass')
    mpi.gamma_method()
    mpi.details()
    > Result         1.34976800e+02 +/- 5.00000000e-04 +/- 0.00000000e+00 (0.000%)
    >  pi^0 mass     5.00000000e-04
    > 0 samples in 1 ensemble:
    >   · Covobs   'pi^0 mass'

The resulting object `mpi` is an `Obs` that contains a `Covobs`. In the following, it may be handled as any other `Obs`. The contribution of the covariance matrix to the error of an `Obs` is determined from the $M \times M$ covariance matrix $\Sigma$ and the gradient of the `Obs` with respect to the external quantities, which is the $1\times M$ Jacobian matrix $J$, via $$s = \sqrt{J^T \Sigma J}\,,$$ where the Jacobian is computed for each derived quantity via automatic differentiation.

Correlated auxiliary data is defined similarly to above, e.g., via

    RAP = pe.cov_Obs([16.7457, -19.0475], [[3.49591, -6.07560], [-6.07560, 10.5834]], 'R_AP, 1906.03445, (5.3a)')
    print(RAP)
    > [Obs[16.7(1.9)], Obs[-19.0(3.3)]]

where `RAP` now is a list of two `Obs` that contains the two correlated parameters.

Since the gradient of a derived observable with respect to an external covariance matrix is propagated through the entire analysis, the `Covobs` class allows to quote the derivative of a result with respect to the external quantities. If these derivatives are published together with the result, small shifts in the definition of external quantities, e.g., the definition of the physical point, can be performed a posteriori based on the published information. This may help to compare results of different groups. The gradient of an `Obs` `o` with respect to a covariance matrix with the identifying string `k` may be accessed via

    o.covobs[k].grad

# Error propagation in iterative algorithms

`pyerrors` supports exact linear error propagation for iterative algorithms like various variants of non-linear least sqaures fits or root finding. The derivatives required for the error propagation are calculated as described in arXiv:1809.01289.

## Least squares fits

Standard non-linear least square fits with errors on the dependent but not the independent variables can be performed with `pyerrors.fits.least_squares`. As default solver the Levenberg-Marquardt algorithm implemented in scipy is used.

Fit functions have to be of the following form

    import autograd.numpy as anp

    def func(a, x):
        return a[1] * anp.exp(-a[0] * x)

It is important that numerical functions refer to `autograd.numpy` instead of `numpy` for the automatic differentiation in iterative algorithms to work properly.

Fits can then be performed via

    fit_result = pe.fits.least_squares(x, y, func)
    print("\n", fit_result)
    > Fit with 2 parameters
    > Method: Levenberg-Marquardt
    > `ftol` termination condition is satisfied.
    > chisquare/d.o.f.: 0.9593035785160936

    >  Goodness of fit:
    > χ²/d.o.f. = 0.959304
    > p-value   = 0.5673
    > Fit parameters:
    > 0      0.0548(28)
    > 1      1.933(64)

where x is a `list` or `numpy.array` of `floats` and y is a `list` or `numpy.array` of `Obs`.

Data stored in `Corr` objects can be fitted directly using the `Corr.fit` method.

    my_corr = pe.Corr(y)
    fit_result = my_corr.fit(func, fitrange=[12, 25])

this can simplify working with absolute fit ranges and takes care of gaps in the data automatically.

For fit functions with multiple independent variables the fit function can be of the form

    def func(a, x):
        (x1, x2) = x
        return a[0] * x1 ** 2 + a[1] * x2

`pyerrors` also supports correlated fits which can be triggered via the parameter `correlated_fit=True`. Details about how the required covariance matrix is estimated can be found in `pyerrors.obs.covariance`.

Direct visualizations of the performed fits can be triggered via `resplot=True` or `qqplot=True`. For all available options see `pyerrors.fits.least_squares`.

## Total least squares fits

`pyerrors` can also fit data with errors on both the dependent and independent variables using the total least squares method also referred to orthogonal distance regression as implemented in scipy, see `pyerrors.fits.least_squares`. The syntax is identical to the standard least squares case, the only diffrence being that `x` also has to be a `list` or `numpy.array` of `Obs`.

For the full API see `pyerrors.fits` for fits and `pyerrors.roots` for finding roots of functions.

# Matrix operations

`pyerrors` provides wrappers for `Obs`- and `CObs`-valued matrix operations based on `numpy.linalg`. The supported functions include:

- `inv` for the matrix inverse.
- `cholseky` for the Cholesky decomposition.
- `det` for the matrix determinant.
- `eigh` for eigenvalues and eigenvectors of hermitean matrices.
- `eig` for eigenvalues of general matrices.
- `pinv` for the Moore-Penrose pseudoinverse.
- `svd` for the singular-value-decomposition.

For the full API see `pyerrors.linalg`.

# Export data

The preferred exported file format within `pyerrors` is json.gz. Files written to this format are valid JSON files that have been compressed using gzip. The structure of the content is inspired by the dobs format of the ALPHA collaboration. The aim of the format is to facilitate the storage of data in a self-contained way such that, even years after the creation of the file, it is possible to extract all necessary information:

- What observables are stored? Possibly: How exactly are they defined.
- How does each single ensemble or external quantity contribute to the error of the observable?
- Who did write the file when and on which machine?

This can be achieved by storing all information in one single file. The export routines of `pyerrors` are written such that as much information as possible is written automatically as described in the following example

    my_obs = pe.Obs([samples], ["test_ensemble"])
    my_obs.tag = "My observable"

    pe.input.json.dump_to_json(my_obs, "test_output_file", description="This file contains a test observable")
    # For a single observable one can equivalently use the class method dump
    my_obs.dump("test_output_file", description="This file contains a test observable")

    check = pe.input.json.load_json("test_output_file")

    print(my_obs == check)
    > True

The format also allows to directly write out the content of `Corr` objects or lists and arrays of `Obs` objects by passing the desired data to `pyerrors.input.json.dump_to_json`.

## json.gz format specification

The first entries of the file provide optional auxiliary information:

- `program` is a string that indicates which program was used to write the file.
- `version` is a string that specifies the version of the format.
- `who` is a string that specifies the user name of the creator of the file.
- `date` is a string and contains the creation date of the file.
- `host` is a string and contains the hostname of the machine where the file has been written.
- `description` contains information on the content of the file. This field is not filled automatically in `pyerrors`. The user is advised to provide as detailed information as possible in this field. Examples are: Input files of measurements or simulations, LaTeX formulae or references to publications to specify how the observables have been computed, details on the analysis strategy, ... This field may be any valid JSON type. Strings, arrays or objects (equivalent to dicts in python) are well suited to provide information.

The only necessary entry of the file is the field -`obsdata`, an array that contains the actual data.

Each entry of the array belongs to a single structure of observables. Currently, these structures can be either of `Obs`, `list`, `numpy.ndarray`, `Corr`. All `Obs` inside a structure (with dimension > 0) have to be defined on the same set of configurations. Different structures, that are represented by entries of the array `obsdata`, are treated independently. Each entry of the array `obsdata` has the following required entries:

- `type` is a string that specifies the type of the structure. This allows to parse the content to the correct form after reading the file. It is always possible to interpret the content as list of Obs.
- `value` is an array that contains the mean values of the Obs inside the structure. The following entries are optional:
- `layout` is a string that specifies the layout of multi-dimensional structures. Examples are "2, 2" for a 2x2 dimensional matrix or "64, 4, 4" for a Corr with $T=64$ and 4x4 matrices on each time slices. "1" denotes a single Obs. Multi-dimensional structures are stored in row-major format (see below).
- `tag` is any JSON type. It contains additional information concerning the structure. The `tag` of an `Obs` in `pyerrors` is written here.
- `reweighted` is a Bool that may be used to specify, whether the `Obs` in the structure have been reweighted.
- `data` is an array that contains the data from MC chains. We will define it below.
- `cdata` is an array that contains the data from external quantities with an error (`Covobs` in `pyerrors`). We will define it below.

The array `data` contains the data from MC chains. Each entry of the array corresponds to one ensemble and contains:

- `id`, a string that contains the name of the ensemble
- `replica`, an array that contains an entry per replica of the ensemble.

Each entry of `replica` contains `name`, a string that contains the name of the replica `deltas`, an array that contains the actual data.

Each entry in `deltas` corresponds to one configuration of the replica and has $1+N$ many entries. The first entry is an integer that specifies the configuration number that, together with ensemble and replica name, may be used to uniquely identify the configuration on which the data has been obtained. The following N entries specify the deltas, i.e., the deviation of the observable from the mean value on this configuration, of each `Obs` inside the structure. Multi-dimensional structures are stored in a row-major format. For primary observables, such as correlation functions, $value + delta_i$ matches the primary data obtained on the configuration.

The array `cdata` contains information about the contribution of auxiliary observables, represented by `Covobs` in `pyerrors`, to the total error of the observables. Each entry of the array belongs to one auxiliary covariance matrix and contains:

- `id`, a string that identifies the covariance matrix
- `layout`, a string that defines the dimensions of the $M\times M$ covariance matrix (has to be "M, M" or "1").
- `cov`, an array that contains the $M\times M$ many entries of the covariance matrix, stored in row-major format.
- `grad`, an array that contains N entries, one for each `Obs` inside the structure. Each entry itself is an array, that contains the M gradients of the Nth observable with respect to the quantity that corresponds to the Mth diagonal entry of the covariance matrix.

A JSON schema that may be used to verify the correctness of a file with respect to the format definition is stored in ./examples/json_schema.json. The schema is a self-descriptive format definition and contains an exemplary file.

Julia I/O routines for the json.gz format, compatible with ADerrors.jl, can be found here.

# Citing

If you use `pyerrors` for research that leads to a publication please consider citing:

- Ulli Wolff, Monte Carlo errors with less errors. Comput.Phys.Commun. 156 (2004) 143-153, Comput.Phys.Commun. 176 (2007) 383 (erratum).
- Stefan Schaefer, Rainer Sommer, Francesco Virotta, Critical slowing down and error analysis in lattice QCD simulations. Nucl.Phys.B 845 (2011) 93-119.
- Alberto Ramos, Automatic differentiation for error analysis of Monte Carlo data. Comput.Phys.Commun. 238 (2019) 19-35.

View Source

      0r'''
      1# What is pyerrors?
      2`pyerrors` is a python package for error computation and propagation of Markov chain Monte Carlo data.
      3It is based on the gamma method [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017). Some of its features are:
      4- automatic differentiation for exact liner error propagation as suggested in [arXiv:1809.01289](https://arxiv.org/abs/1809.01289) (partly based on the [autograd](https://github.com/HIPS/autograd) package).
      5- treatment of slow modes in the simulation as suggested in [arXiv:1009.5228](https://arxiv.org/abs/1009.5228).
      6- coherent error propagation for data from different Markov chains.
      7- non-linear fits with x- and y-errors and exact linear error propagation based on automatic differentiation as introduced in [arXiv:1809.01289](https://arxiv.org/abs/1809.01289).
      8- real and complex matrix operations and their error propagation based on automatic differentiation (Matrix inverse, Cholesky decomposition, calculation of eigenvalues and eigenvectors, singular value decomposition...).
      9
     10There exist similar publicly available implementations of gamma method error analysis suites in [Fortran](https://gitlab.ift.uam-csic.es/alberto/aderrors), [Julia](https://gitlab.ift.uam-csic.es/alberto/aderrors.jl) and [Python](https://github.com/mbruno46/pyobs).
     11
     12## Basic example
     13
     14```python
     15import numpy as np
     16import pyerrors as pe
     17
     18my_obs = pe.Obs([samples], ['ensemble_name']) # Initialize an Obs object
     19my_new_obs = 2 * np.log(my_obs) / my_obs ** 2 # Construct derived Obs object
     20my_new_obs.gamma_method()                     # Estimate the statistical error
     21print(my_new_obs)                             # Print the result to stdout
     22> 0.31498(72)
     23```
     24
     25# The `Obs` class
     26
     27`pyerrors` introduces a new datatype, `Obs`, which simplifies error propagation and estimation for auto- and cross-correlated data.
     28An `Obs` object can be initialized with two arguments, the first is a list containing the samples for an observable from a Monte Carlo chain.
     29The samples can either be provided as python list or as numpy array.
     30The second argument is a list containing the names of the respective Monte Carlo chains as strings. These strings uniquely identify a Monte Carlo chain/ensemble.
     31
     32```python
     33import pyerrors as pe
     34
     35my_obs = pe.Obs([samples], ['ensemble_name'])
     36```
     37
     38## Error propagation
     39
     40When performing mathematical operations on `Obs` objects the correct error propagation is intrinsically taken care of using a first order Taylor expansion
     41$$\delta_f^i=\sum_\alpha \bar{f}_\alpha \delta_\alpha^i\,,\quad \delta_\alpha^i=a_\alpha^i-\bar{a}_\alpha\,,$$
     42as introduced in [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017).
     43The required derivatives $\bar{f}_\alpha$ are evaluated up to machine precision via automatic differentiation as suggested in [arXiv:1809.01289](https://arxiv.org/abs/1809.01289).
     44
     45The `Obs` class is designed such that mathematical numpy functions can be used on `Obs` just as for regular floats.
     46
     47```python
     48import numpy as np
     49import pyerrors as pe
     50
     51my_obs1 = pe.Obs([samples1], ['ensemble_name'])
     52my_obs2 = pe.Obs([samples2], ['ensemble_name'])
     53
     54my_sum = my_obs1 + my_obs2
     55
     56my_m_eff = np.log(my_obs1 / my_obs2)
     57
     58iamzero = my_m_eff - my_m_eff
     59# Check that value and fluctuations are zero within machine precision
     60print(iamzero == 0.0)
     61> True
     62```
     63
     64## Error estimation
     65
     66The error estimation within `pyerrors` is based on the gamma method introduced in [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017).
     67After having arrived at the derived quantity of interest the `gamma_method` can be called as detailed in the following example.
     68
     69```python
     70my_sum.gamma_method()
     71print(my_sum)
     72> 1.70(57)
     73my_sum.details()
     74> Result	 1.70000000e+00 +/- 5.72046658e-01 +/- 7.56746598e-02 (33.650%)
     75>  t_int	 2.71422900e+00 +/- 6.40320983e-01 S = 2.00
     76> 1000 samples in 1 ensemble:
     77>   · Ensemble 'ensemble_name' : 1000 configurations (from 1 to 1000)
     78
     79```
     80
     81We use the following definition of the integrated autocorrelation time established in [Madras & Sokal 1988](https://link.springer.com/article/10.1007/BF01022990)
     82$$\tau_\mathrm{int}=\frac{1}{2}+\sum_{t=1}^{W}\rho(t)\geq \frac{1}{2}\,.$$
     83The window $W$ is determined via the automatic windowing procedure described in [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017).
     84The standard value for the parameter $S$ of this automatic windowing procedure is $S=2$. Other values for $S$ can be passed to the `gamma_method` as parameter.
     85
     86```python
     87my_sum.gamma_method(S=3.0)
     88my_sum.details()
     89> Result	 1.70000000e+00 +/- 6.30675201e-01 +/- 1.04585650e-01 (37.099%)
     90>  t_int	 3.29909703e+00 +/- 9.77310102e-01 S = 3.00
     91> 1000 samples in 1 ensemble:
     92>   · Ensemble 'ensemble_name' : 1000 configurations (from 1 to 1000)
     93
     94```
     95
     96The integrated autocorrelation time $\tau_\mathrm{int}$ and the autocorrelation function $\rho(W)$ can be monitored via the methods `pyerrors.obs.Obs.plot_tauint` and `pyerrors.obs.Obs.plot_tauint`.
     97
     98If the parameter $S$ is set to zero it is assumed that the dataset does not exhibit any autocorrelation and the windowsize is chosen to be zero.
     99In this case the error estimate is identical to the sample standard error.
    100
    101### Exponential tails
    102
    103Slow modes in the Monte Carlo history can be accounted for by attaching an exponential tail to the autocorrelation function $\rho$ as suggested in [arXiv:1009.5228](https://arxiv.org/abs/1009.5228). The longest autocorrelation time in the history, $\tau_\mathrm{exp}$, can be passed to the `gamma_method` as parameter. In this case the automatic windowing procedure is vacated and the parameter $S$ does not affect the error estimate.
    104
    105```python
    106my_sum.gamma_method(tau_exp=7.2)
    107my_sum.details()
    108> Result	 1.70000000e+00 +/- 6.28097762e-01 +/- 5.79077524e-02 (36.947%)
    109>  t_int	 3.27218667e+00 +/- 7.99583654e-01 tau_exp = 7.20,  N_sigma = 1
    110> 1000 samples in 1 ensemble:
    111>   · Ensemble 'ensemble_name' : 1000 configurations (from 1 to 1000)
    112```
    113
    114For the full API see `pyerrors.obs.Obs.gamma_method`.
    115
    116## Multiple ensembles/replica
    117
    118Error propagation for multiple ensembles (Markov chains with different simulation parameters) is handled automatically. Ensembles are uniquely identified by their `name`.
    119
    120```python
    121obs1 = pe.Obs([samples1], ['ensemble1'])
    122obs2 = pe.Obs([samples2], ['ensemble2'])
    123
    124my_sum = obs1 + obs2
    125my_sum.details()
    126> Result   2.00697958e+00
    127> 1500 samples in 2 ensembles:
    128>   · Ensemble 'ensemble1' : 1000 configurations (from 1 to 1000)
    129>   · Ensemble 'ensemble2' : 500 configurations (from 1 to 500)
    130```
    131
    132`pyerrors` identifies multiple replica (independent Markov chains with identical simulation parameters) by the vertical bar `|` in the name of the data set.
    133
    134```python
    135obs1 = pe.Obs([samples1], ['ensemble1|r01'])
    136obs2 = pe.Obs([samples2], ['ensemble1|r02'])
    137
    138> my_sum = obs1 + obs2
    139> my_sum.details()
    140> Result   2.00697958e+00
    141> 1500 samples in 1 ensemble:
    142>   · Ensemble 'ensemble1'
    143>     · Replicum 'r01' : 1000 configurations (from 1 to 1000)
    144>     · Replicum 'r02' : 500 configurations (from 1 to 500)
    145```
    146
    147### Error estimation for multiple ensembles
    148
    149In order to keep track of different error analysis parameters for different ensembles one can make use of global dictionaries as detailed in the following example.
    150
    151```python
    152pe.Obs.S_dict['ensemble1'] = 2.5
    153pe.Obs.tau_exp_dict['ensemble2'] = 8.0
    154pe.Obs.tau_exp_dict['ensemble3'] = 2.0
    155```
    156
    157In case the `gamma_method` is called without any parameters it will use the values specified in the dictionaries for the respective ensembles.
    158Passing arguments to the `gamma_method` still dominates over the dictionaries.
    159
    160
    161## Irregular Monte Carlo chains
    162
    163`Obs` objects defined on irregular Monte Carlo chains can be initialized with the parameter `idl`.
    164
    165```python
    166# Observable defined on configurations 20 to 519
    167obs1 = pe.Obs([samples1], ['ensemble1'], idl=[range(20, 520)])
    168obs1.details()
    169> Result	 9.98319881e-01
    170> 500 samples in 1 ensemble:
    171>   · Ensemble 'ensemble1' : 500 configurations (from 20 to 519)
    172
    173# Observable defined on every second configuration between 5 and 1003
    174obs2 = pe.Obs([samples2], ['ensemble1'], idl=[range(5, 1005, 2)])
    175obs2.details()
    176> Result	 9.99100712e-01
    177> 500 samples in 1 ensemble:
    178>   · Ensemble 'ensemble1' : 500 configurations (from 5 to 1003 in steps of 2)
    179
    180# Observable defined on configurations 2, 9, 28, 29 and 501
    181obs3 = pe.Obs([samples3], ['ensemble1'], idl=[[2, 9, 28, 29, 501]])
    182obs3.details()
    183> Result	 1.01718064e+00
    184> 5 samples in 1 ensemble:
    185>   · Ensemble 'ensemble1' : 5 configurations (irregular range)
    186
    187```
    188
    189`Obs` objects defined on regular and irregular histories of the same ensemble can be combined with each other and the correct error propagation and estimation is automatically taken care of.
    190
    191**Warning:** Irregular Monte Carlo chains can result in odd patterns in the autocorrelation functions.
    192Make sure to check the autocorrelation time with e.g. `pyerrors.obs.Obs.plot_rho` or `pyerrors.obs.Obs.plot_tauint`.
    193
    194For the full API see `pyerrors.obs.Obs`.
    195
    196# Correlators
    197When one is not interested in single observables but correlation functions, `pyerrors` offers the `Corr` class which simplifies the corresponding error propagation and provides the user with a set of standard methods. In order to initialize a `Corr` objects one needs to arrange the data as a list of `Obs`
    198```python
    199my_corr = pe.Corr([obs_0, obs_1, obs_2, obs_3])
    200print(my_corr)
    201> x0/a	Corr(x0/a)
    202> ------------------
    203> 0	 0.7957(80)
    204> 1	 0.5156(51)
    205> 2	 0.3227(33)
    206> 3	 0.2041(21)
    207```
    208In case the correlation functions are not defined on the outermost timeslices, for example because of fixed boundary conditions, a padding can be introduced.
    209```python
    210my_corr = pe.Corr([obs_0, obs_1, obs_2, obs_3], padding=[1, 1])
    211print(my_corr)
    212> x0/a	Corr(x0/a)
    213> ------------------
    214> 0
    215> 1	 0.7957(80)
    216> 2	 0.5156(51)
    217> 3	 0.3227(33)
    218> 4	 0.2041(21)
    219> 5
    220```
    221The individual entries of a correlator can be accessed via slicing
    222```python
    223print(my_corr[3])
    224> 0.3227(33)
    225```
    226Error propagation with the `Corr` class works very similar to `Obs` objects. Mathematical operations are overloaded and `Corr` objects can be computed together with other `Corr` objects, `Obs` objects or real numbers and integers.
    227```python
    228my_new_corr = 0.3 * my_corr[2] * my_corr * my_corr + 12 / my_corr
    229```
    230
    231`pyerrors` provides the user with a set of regularly used methods for the manipulation of correlator objects:
    232- `Corr.gamma_method` applies the gamma method to all entries of the correlator.
    233- `Corr.m_eff` to construct effective masses. Various variants for periodic and fixed temporal boundary conditions are available.
    234- `Corr.deriv` returns the first derivative of the correlator as `Corr`. Different discretizations of the numerical derivative are available.
    235- `Corr.second_deriv` returns the second derivative of the correlator as `Corr`. Different discretizations of the numerical derivative are available.
    236- `Corr.symmetric` symmetrizes parity even correlations functions, assuming periodic boundary conditions.
    237- `Corr.anti_symmetric` anti-symmetrizes parity odd correlations functions, assuming periodic boundary conditions.
    238- `Corr.T_symmetry` averages a correlator with its time symmetry partner, assuming fixed boundary conditions.
    239- `Corr.plateau` extracts a plateau value from the correlator in a given range.
    240- `Corr.roll` periodically shifts the correlator.
    241- `Corr.reverse` reverses the time ordering of the correlator.
    242- `Corr.correlate` constructs a disconnected correlation function from the correlator and another `Corr` or `Obs` object.
    243- `Corr.reweight` reweights the correlator.
    244
    245`pyerrors` can also handle matrices of correlation functions and extract energy states from these matrices via a generalized eigenvalue problem (see `pyerrors.correlators.Corr.GEVP`).
    246
    247For the full API see `pyerrors.correlators.Corr`.
    248
    249# Complex valued observables
    250
    251`pyerrors` can handle complex valued observables via the class `pyerrors.obs.CObs`.
    252`CObs` are initialized with a real and an imaginary part which both can be `Obs` valued.
    253
    254```python
    255my_real_part = pe.Obs([samples1], ['ensemble1'])
    256my_imag_part = pe.Obs([samples2], ['ensemble1'])
    257
    258my_cobs = pe.CObs(my_real_part, my_imag_part)
    259my_cobs.gamma_method()
    260print(my_cobs)
    261> (0.9959(91)+0.659(28)j)
    262```
    263
    264Elementary mathematical operations are overloaded and samples are properly propagated as for the `Obs` class.
    265```python
    266my_derived_cobs = (my_cobs + my_cobs.conjugate()) / np.abs(my_cobs)
    267my_derived_cobs.gamma_method()
    268print(my_derived_cobs)
    269> (1.668(23)+0.0j)
    270```
    271
    272# The `Covobs` class
    273In many projects, auxiliary data that is not based on Monte Carlo chains enters. Examples are experimentally determined mesons masses which are used to set the scale or renormalization constants. These numbers come with an error that has to be propagated through the analysis. The `Covobs` class allows to define such quantities in `pyerrors`. Furthermore, external input might consist of correlated quantities. An example are the parameters of an interpolation formula, which are defined via mean values and a covariance matrix between all parameters. The contribution of the interpolation formula to the error of a derived quantity therefore might depend on the complete covariance matrix.
    274
    275This concept is built into the definition of `Covobs`. In `pyerrors`, external input is defined by $M$ mean values, a $M\times M$ covariance matrix, where $M=1$ is permissible, and a name that uniquely identifies the covariance matrix. Below, we define the pion mass, based on its mean value and error, 134.9768(5). Note, that the square of the error enters `cov_Obs`, since the second argument of this function is the covariance matrix of the `Covobs`.
    276
    277```python
    278import pyerrors.obs as pe
    279
    280mpi = pe.cov_Obs(134.9768, 0.0005**2, 'pi^0 mass')
    281mpi.gamma_method()
    282mpi.details()
    283> Result	 1.34976800e+02 +/- 5.00000000e-04 +/- 0.00000000e+00 (0.000%)
    284>  pi^0 mass 	 5.00000000e-04
    285> 0 samples in 1 ensemble:
    286>   · Covobs   'pi^0 mass'
    287```
    288The resulting object `mpi` is an `Obs` that contains a `Covobs`. In the following, it may be handled as any other `Obs`. The contribution of the covariance matrix to the error of an `Obs` is determined from the $M \times M$ covariance matrix $\Sigma$ and the gradient of the `Obs` with respect to the external quantities, which is the $1\times M$ Jacobian matrix $J$, via
    289$$s = \sqrt{J^T \Sigma J}\,,$$
    290where the Jacobian is computed for each derived quantity via automatic differentiation.
    291
    292Correlated auxiliary data is defined similarly to above, e.g., via
    293```python
    294RAP = pe.cov_Obs([16.7457, -19.0475], [[3.49591, -6.07560], [-6.07560, 10.5834]], 'R_AP, 1906.03445, (5.3a)')
    295print(RAP)
    296> [Obs[16.7(1.9)], Obs[-19.0(3.3)]]
    297```
    298where `RAP` now is a list of two `Obs` that contains the two correlated parameters.
    299
    300Since the gradient of a derived observable with respect to an external covariance matrix is propagated through the entire analysis, the `Covobs` class allows to quote the derivative of a result with respect to the external quantities. If these derivatives are published together with the result, small shifts in the definition of external quantities, e.g., the definition of the physical point, can be performed a posteriori based on the published information. This may help to compare results of different groups. The gradient of an `Obs` `o` with respect to a covariance matrix with the identifying string `k` may be accessed via
    301```python
    302o.covobs[k].grad
    303```
    304
    305# Error propagation in iterative algorithms
    306
    307`pyerrors` supports exact linear error propagation for iterative algorithms like various variants of non-linear least sqaures fits or root finding. The derivatives required for the error propagation are calculated as described in [arXiv:1809.01289](https://arxiv.org/abs/1809.01289).
    308
    309## Least squares fits
    310
    311Standard non-linear least square fits with errors on the dependent but not the independent variables can be performed with `pyerrors.fits.least_squares`. As default solver the Levenberg-Marquardt algorithm implemented in [scipy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html) is used.
    312
    313Fit functions have to be of the following form
    314```python
    315import autograd.numpy as anp
    316
    317def func(a, x):
    318    return a[1] * anp.exp(-a[0] * x)
    319```
    320**It is important that numerical functions refer to `autograd.numpy` instead of `numpy` for the automatic differentiation in iterative algorithms to work properly.**
    321
    322Fits can then be performed via
    323```python
    324fit_result = pe.fits.least_squares(x, y, func)
    325print("\n", fit_result)
    326> Fit with 2 parameters
    327> Method: Levenberg-Marquardt
    328> `ftol` termination condition is satisfied.
    329> chisquare/d.o.f.: 0.9593035785160936
    330
    331>  Goodness of fit:
    332> χ²/d.o.f. = 0.959304
    333> p-value   = 0.5673
    334> Fit parameters:
    335> 0	 0.0548(28)
    336> 1	 1.933(64)
    337```
    338where x is a `list` or `numpy.array` of `floats` and y is a `list` or `numpy.array` of `Obs`.
    339
    340Data stored in `Corr` objects can be fitted directly using the `Corr.fit` method.
    341```python
    342my_corr = pe.Corr(y)
    343fit_result = my_corr.fit(func, fitrange=[12, 25])
    344```
    345this can simplify working with absolute fit ranges and takes care of gaps in the data automatically.
    346
    347For fit functions with multiple independent variables the fit function can be of the form
    348
    349```python
    350def func(a, x):
    351    (x1, x2) = x
    352    return a[0] * x1 ** 2 + a[1] * x2
    353```
    354
    355`pyerrors` also supports correlated fits which can be triggered via the parameter `correlated_fit=True`.
    356Details about how the required covariance matrix is estimated can be found in `pyerrors.obs.covariance`.
    357
    358Direct visualizations of the performed fits can be triggered via `resplot=True` or `qqplot=True`. For all available options see `pyerrors.fits.least_squares`.
    359
    360## Total least squares fits
    361`pyerrors` can also fit data with errors on both the dependent and independent variables using the total least squares method also referred to orthogonal distance regression as implemented in [scipy](https://docs.scipy.org/doc/scipy/reference/odr.html), see `pyerrors.fits.least_squares`. The syntax is identical to the standard least squares case, the only diffrence being that `x` also has to be a `list` or `numpy.array` of `Obs`.
    362
    363For the full API see `pyerrors.fits` for fits and `pyerrors.roots` for finding roots of functions.
    364
    365# Matrix operations
    366`pyerrors` provides wrappers for `Obs`- and `CObs`-valued matrix operations based on `numpy.linalg`. The supported functions include:
    367- `inv` for the matrix inverse.
    368- `cholseky` for the Cholesky decomposition.
    369- `det` for the matrix determinant.
    370- `eigh` for eigenvalues and eigenvectors of hermitean matrices.
    371- `eig` for eigenvalues of general matrices.
    372- `pinv` for the Moore-Penrose pseudoinverse.
    373- `svd` for the singular-value-decomposition.
    374
    375For the full API see `pyerrors.linalg`.
    376
    377# Export data
    378
    379The preferred exported file format within `pyerrors` is json.gz. Files written to this format are valid JSON files that have been compressed using gzip. The structure of the content is inspired by the dobs format of the ALPHA collaboration. The aim of the format is to facilitate the storage of data in a self-contained way such that, even years after the creation of the file, it is possible to extract all necessary information:
    380- What observables are stored? Possibly: How exactly are they defined.
    381- How does each single ensemble or external quantity contribute to the error of the observable?
    382- Who did write the file when and on which machine?
    383
    384This can be achieved by storing all information in one single file. The export routines of `pyerrors` are written such that as much information as possible is written automatically as described in the following example
    385```python
    386my_obs = pe.Obs([samples], ["test_ensemble"])
    387my_obs.tag = "My observable"
    388
    389pe.input.json.dump_to_json(my_obs, "test_output_file", description="This file contains a test observable")
    390# For a single observable one can equivalently use the class method dump
    391my_obs.dump("test_output_file", description="This file contains a test observable")
    392
    393check = pe.input.json.load_json("test_output_file")
    394
    395print(my_obs == check)
    396> True
    397```
    398The format also allows to directly write out the content of `Corr` objects or lists and arrays of `Obs` objects by passing the desired data to `pyerrors.input.json.dump_to_json`.
    399
    400## json.gz format specification
    401The first entries of the file provide optional auxiliary information:
    402- `program` is a string that indicates which program was used to write the file.
    403- `version` is a string that specifies the version of the format.
    404- `who` is a string that specifies the user name of the creator of the file.
    405- `date` is a string and contains the creation date of the file.
    406- `host` is a string and contains the hostname of the machine where the file has been written.
    407- `description` contains information on the content of the file. This field is not filled automatically in `pyerrors`. The user is advised to provide as detailed information as possible in this field. Examples are: Input files of measurements or simulations, LaTeX formulae or references to publications to specify how the observables have been computed, details on the analysis strategy, ... This field may be any valid JSON type. Strings, arrays or objects (equivalent to dicts in python) are well suited to provide information.
    408
    409The only necessary entry of the file is the field
    410-`obsdata`, an array that contains the actual data.
    411
    412Each entry of the array belongs to a single structure of observables. Currently, these structures can be either of `Obs`, `list`, `numpy.ndarray`, `Corr`. All `Obs` inside a structure (with dimension > 0) have to be defined on the same set of configurations. Different structures, that are represented by entries of the array `obsdata`, are treated independently. Each entry of the array `obsdata` has the following required entries:
    413- `type` is a string that specifies the type of the structure. This allows to parse the content to the correct form after reading the file. It is always possible to interpret the content as list of Obs.
    414- `value` is an array that contains the mean values of the Obs inside the structure.
    415The following entries are optional:
    416- `layout` is a string that specifies the layout of multi-dimensional structures. Examples are "2, 2" for a 2x2 dimensional matrix or  "64, 4, 4" for a Corr with $T=64$ and 4x4 matrices on each time slices. "1" denotes a single Obs. Multi-dimensional structures are stored in row-major format (see below).
    417- `tag` is any JSON type. It contains additional information concerning the structure. The `tag` of an `Obs` in `pyerrors` is written here.
    418- `reweighted` is a Bool that may be used to specify, whether the `Obs` in the structure have been reweighted.
    419- `data` is an array that contains the data from MC chains. We will define it below.
    420- `cdata` is an array that contains the data from external quantities with an error (`Covobs` in `pyerrors`). We will define it below.
    421
    422The array `data` contains the data from MC chains. Each entry of the array corresponds to one ensemble and contains:
    423- `id`, a string that contains the name of the ensemble
    424- `replica`, an array that contains an entry per replica of the ensemble.
    425
    426Each entry of `replica` contains
    427`name`, a string that contains the name of the replica
    428`deltas`, an array that contains the actual data.
    429
    430Each entry in `deltas` corresponds to one configuration of the replica and has $1+N$ many entries. The first entry is an integer that specifies the configuration number that, together with ensemble and replica name, may be used to uniquely identify the configuration on which the data has been obtained. The following N entries specify the deltas, i.e., the deviation of the observable from the mean value on this configuration, of each `Obs` inside the structure. Multi-dimensional structures are stored in a row-major format. For primary observables, such as correlation functions, $value + delta_i$ matches the primary data obtained on the configuration.
    431
    432The array `cdata` contains information about the contribution of auxiliary observables, represented by `Covobs` in `pyerrors`, to the total error of the observables. Each entry of the array belongs to one auxiliary covariance matrix and contains:
    433- `id`, a string that identifies the covariance matrix
    434- `layout`, a string that defines the dimensions of the $M\times M$ covariance matrix (has to be "M, M" or "1").
    435- `cov`, an array that contains the $M\times M$ many entries of the covariance matrix, stored in row-major format.
    436- `grad`, an array that contains N entries, one for each `Obs` inside the structure. Each entry itself is an array, that contains the M gradients of the Nth observable  with respect to the quantity that corresponds to the Mth diagonal entry of the covariance matrix.
    437
    438A JSON schema that may be used to verify the correctness of a file with respect to the format definition is stored in ./examples/json_schema.json. The schema is a self-descriptive format definition and contains an exemplary file.
    439
    440Julia I/O routines for the json.gz format, compatible with [ADerrors.jl](https://gitlab.ift.uam-csic.es/alberto/aderrors.jl), can be found [here](https://github.com/fjosw/ADjson.jl).
    441
    442# Citing
    443If you use `pyerrors` for research that leads to a publication please consider citing:
    444- Ulli Wolff, *Monte Carlo errors with less errors*. Comput.Phys.Commun. 156 (2004) 143-153, Comput.Phys.Commun. 176 (2007) 383 (erratum).
    445- Stefan Schaefer, Rainer Sommer, Francesco Virotta, *Critical slowing down and error analysis in lattice QCD simulations*. Nucl.Phys.B 845 (2011) 93-119.
    446- Alberto Ramos, *Automatic differentiation for error analysis of Monte Carlo data*. Comput.Phys.Commun. 238 (2019) 19-35.
    447'''
    448from .obs import *
    449from .correlators import *
    450from .fits import *
    451from .misc import *
    452from . import dirac
    453from . import input
    454from . import linalg
    455from . import mpm
    456from . import roots
    457
    458from .version import __version__