afqmctools.analysis package#

Submodules#

afqmctools.analysis.average module#

Simple extraction of afqmc rdms.

afqmctools.analysis.average.analyse_ekt(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, nsamp=20, screen_factor=1, cutoff=1e-14, to_file=None, kappa=None)#

Perform extended Koopman’s Theorem (EKT) analysis.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

  • nsamp (int) – Number of perturbed RDMs to construct to estimate of error bar. Optional. Default: 20.

  • screen_factor (int) – Zero RDM elements with abs(P[i,j]) < screen_factor*Perr[i,j]. Optional Default: 1.

Returns:

  • [eip, eip_err] (list) – Ionisation potentials and estimates of their errors.

  • [eea, eea_err] (list) – Electron affinities and estimates of their errors.

afqmctools.analysis.average.average_atom_correlations(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Average atom centered correlations.

Returns <C(I)>, <S(I)>, <C(I)C(J)> and <S(I)S(J)> for a given set of atomic sites. C = (nup + ndown), S = (nup - ndown)

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • c_mean (numpy.ndarray) – Averaged charge.

  • c_err (numpy.ndarray) – Error bars for charge.

  • s_mean (numpy.ndarray) – Averaged spin.

  • s_err (numpy.ndarray) – Error bars for spin.

  • cc_mean (numpy.ndarray) – Averaged charge-charge correlation function.

  • cc_err (numpy.ndarray) – Error bars for charge-charge correlation function.

  • ss_mean (numpy.ndarray) – Averaged spin-spin correlation function.

  • ss_err (numpy.ndarray) – Error bars for spin-spin correlation function.

afqmctools.analysis.average.average_diag_two_rdm(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Average diagonal part of 2RDM.

Returns <c_{is}^+ c_{jt}^+ c_{jt} c_{is}> as a (2M,2M) dimensional array.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • two_rdm (numpy.ndarray) – Averaged diagonal 2RDM.

  • two_rdm_err (numpy.ndarray) – Error bars for diagonal 2RDM elements.

afqmctools.analysis.average.average_gen_fock(filename, fock_type='plus', estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Average AFQMC generalised Fock matrix.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • fock_type (string) – Which generalised Fock matrix to extract. Optional (plus/minus). Default: plus.

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • gfock (numpy.ndarray) – Averaged 1RDM.

  • gfock_err (numpy.ndarray) – Error bars for 1RDM elements.

afqmctools.analysis.average.average_observable(filename, name, eqlb=1, estimator='back_propagated', ix=None, blocksize=1, dataset_name=None, transform=None, batch_size=None, remove_auto_correlation=True, kappa=None)#

Compute mean and error bar for AFQMC HDF5 observable.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • name (string) – Name of observable (see estimates.py for list).

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • blocksize (int) – the number of blocks to average over while reblocking. Reblocking is faster if the number of samples is evenly divisible by the blocksize. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

  • transform (callable) – Function to transform the data before averaging. Optional. See Notes for details.

  • batch_size (int) – Size of batch to load data. Optional. Default None (load all data at once).

  • dataset_name (string) – Name of dataset to extract. Optional. Default None (uses name).

  • remove_auto_correlation (bool) – If True, remove auto-correlation from the data. Default True.

  • kappa (float) – Auto-correlation time. Optional. Default None (recalculate).

Returns:

  • mean (numpy.ndarray) – Averaged quantity.

  • err (numpy.ndarray) – Error bars for quantity.

Notes

Transform Function Guidelines

  • Takes a single argument (data of shape (nsamples,…)) and return transformed data

  • assume the leading dimension is nsamples

Do

Don’t

Return a new array

Modify the data in place.

Return the transformed data.

Return a tuple — return a single array instead.

Return None if data is invalid.

Raise an exception

afqmctools.analysis.average.average_on_top_pdm(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Average on-top pair density matrix.

Returns n2(r,r) for a given real space grid.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • opdm (numpy.ndarray) – Averaged diagonal on-top pair density matrix.

  • opdm_err (numpy.ndarray) – Error bars for diagonal on-top pair density matrix elements.

afqmctools.analysis.average.average_one_rdm(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Get average AFQMC 1RDM.

Returns P_{sij} = <c_{is}^+ c_{js}^> as a (nspin, M, M) dimensional array.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • one_rdm (numpy.ndarray) – Averaged 1RDM.

  • one_rdm_err (numpy.ndarray) – Error bars for 1RDM elements.

afqmctools.analysis.average.average_pair_correlation(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Get average AFQMC pair correlation functions.

Returns the average of the pair correlation function defined as:

\[P^{\alpha \beta}_{ij} ≡ \frac{1}{2} ⟨ \left(c^{\dagger}_{i⇑} c^{†}_{\bar{i}_α ⇓} - c^{\dagger}_{i⇓} c^{†}_{\bar{i}_α ⇑} \right) \left( c_{\bar{j}_\beta⇓} c_{j ⇑} - c_{\bar{j}_\beta ⇑} c_{j ⇓} \right) ⟩.\]

where \(\bar{i}_α\) and \(\bar{j}_\beta\) are indices corresponding to spatial offsets (i.e. s, +x, -x, etc,)

The mapping from the \(\alpha\) and \(\beta\) indices to the spin indices is also returned as a list.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • P_ab_ij (numpy.ndarray) – Averaged pair correlation function.

  • dP_ab_ij (numpy.ndarray) – Stochastic uncertainty for the pair correlation function.

  • correlator_names (list) – List of correlator names corresponding to the indices of the pair correlation function.

afqmctools.analysis.average.average_realspace_correlations(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Average on-top pair density matrix.

Returns <C(r1)C(r2)> and <S(r1)S(r2)> for a given set of points in real space. C = (nup + ndown), S = (nup - ndown)

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • cc_mean (numpy.ndarray) – Averaged charge-charge correlation function.

  • cc_err (numpy.ndarray) – Error bars for charge-charge correlation function.

  • ss_mean (numpy.ndarray) – Averaged spin-spin correlation function.

  • ss_err (numpy.ndarray) – Error bars for spin-spin correlation function.

afqmctools.analysis.average.average_spinspin(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Get average AFQMC SpinSpin correlation.

Returns (<(X_i X_j)+(Y_i Y_j)> , <Z_i Z_j>) as a (2,M,M) dimensional array, resolving XX+YY and ZZ separately

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • SS (numpy.ndarray) – Averaged Spin-Spin correlator.

  • SS_err (numpy.ndarray) – Error bars for the SS elements.

afqmctools.analysis.average.average_two_rdm(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, kappa=None)#

Average AFQMC 2RDM.

Returns a list of 2RDMS, where

2RDM[s1s2,i,k,j,l] = <c_{i}^+ c_{j}^+ c_{l} c_{k}>. For closed shell systems, returns [(a,a,a,a),(a,a,b,b)] For collinear systems, returns [(a,a,a,a),(a,a,b,b),(b,b,b,b)]

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

Returns:

  • two_rdm (numpy.ndarray) – List of averaged 2RDM.

  • two_rdm_err (numpy.ndarray) – List of error bars for 2RDM elements.

afqmctools.analysis.average.estimate_error_eig(gamma, gamma_err, fock=None, fock_err=None, nsamp=20, cutoff=1e-14)#

Bootstrap estimate of error in eigenvalues.

afqmctools.analysis.average.gen_sample_matrix(mat, err, herm=True)#

Perturb matrix by error bar.

afqmctools.analysis.average.get_noons(filename, estimator='back_propagated', eqlb=1, blocksize=1, ix=None, nsamp=20, screen_factor=1, cutoff=1e-14, kappa=None)#

Get NOONs from averaged AFQMC RDM.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • eqlb (int) – Number of blocks for equilibration. Default 1.

  • blocksize (int) – the number of blocks to average over while reblocking. Default 1 (i.e. don’t reblock).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

  • nsamp (int) – Number of perturbed RDMs to construct to estimate of error bar. Optional. Default: 20.

  • screen_factor (int) – Zero RDM elements with abs(P[i,j]) < screen_factor*Perr[i,j]. Optional Default: 1.

Returns:

  • noons (numpy.ndarray) – NOONS.

  • noons_err (numpy.ndarray) – Estimate of error bar on NOONs.

afqmctools.analysis.average.regularised_ortho(S, cutoff=1e-14)#

Get orthogonalisation matrix.

afqmctools.analysis.average.solve_gen_eig(gamma, fock, cutoff=1e-14)#

Solve generalised eigenvalue problem.

Parameters:
  • gamma (numpy.ndarray) – Generalised density matrix.

  • fock (numpy.ndarray) – Generalised Fock matrix.

  • cutoff (float) – Cutoff for singular values. Optional.

Returns:

  • eig (numpy.ndarray) – Eigenvalues.

  • eigv (numpy.ndarray) – Eigenvectors.

afqmctools.analysis.average.spectral_function(eig_p, eig_m, eigv_p, eigv_m, rdm, i, j, window, num_omega, mu=0.0, eta=0.05)#

afqmctools.analysis.common module#

afqmctools.analysis.common.batched(iterable, n, *, strict=False)#
afqmctools.analysis.common.batched_np_array(data, batchsize=1)#

Generator to batch data into chunks of size blocksize.

Parameters:
  • iterable (iterable) – The data to be batched.

  • batchsize (int) – The size of each batch.

Returns:

A list of batches, each of size batchsize.

Return type:

generator

afqmctools.analysis.common.get_bp_taus(fstat)#
afqmctools.analysis.common.get_metadata(fstat, path='Metadata')#

Extract estimator metadata from h5 file.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • path (string) – Path to metadata in filename.

Returns:

meta – Estimator metadata.

Return type:

dict

afqmctools.analysis.common.reblock(data, blocksize)#

Reblock data along first axis.

Parameters:
  • data (array) – The data to be reblocked.

  • blocksize (int) – The size of each block. Recommended that the leading dimension of the data is evenly divisible by the blocksize. If not, the last block will be smaller than the others.

Returns:

Reblocked data. The first axis is the number of new blocks. The remaining axes are unchanged.

Return type:

np.array

Notes

This function executes faster when the data is evenly divisible by the blocksize; if the data is not evenly divisible, the output will be correct, but the function will be slower.

Warning

Will run slower if the data is not evenly divisible by the blocksize. Recommended to ensure that the data is evenly divisible by the blocksize.

afqmctools.analysis.extraction module#

afqmctools.analysis.extraction.extract_data(filename, group, estimator, sample=None, transform=None, batch_size=None)#

Extract data from HDF5 file.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • group (string) – Path to estimator.

  • estimator (string) – Estimator to analyse.

  • sample (int) – Sample to extract. A single sample of data will be extracted, with 0-based indexing starting from the first sample found in the HDF5 file. This is different than how samples are indexed in the HDF5 file where “measurement block index is used”. In HDF5, if equilibration is used, the measurement block index will not start at 0. Optional. Default None (return everything).

  • transform (callable) – Function to transform data. Optional. See Notes for details.

  • batch_size (int) – Size of batch to load data. Optional. Default None (load all data at once).

Returns:

  • numer (numpy.ndarray) – Numerator of estimator.

  • denom (numpy.ndarray) – Denominator of estimator.

Notes

Transform Function Guidelines

  • Takes a single argument (data of shape (nsamples,…)) and return transformed data

  • assume the leading dimension is nsamples

Do

Don’t

Return a new array

Modify the data in place.

Return the transformed data.

Return a tuple — return a single array instead.

Return None if data is invalid.

Raise an exception

afqmctools.analysis.extraction.extract_observable(filename, estimator='back_propagated', name='one_rdm', ix=None, dataset_name=None, transform=None, batch_size=None)#

Extract observable from HDF5 file.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • estimator (string) – Estimator type to analyse. Options: back_propagated or mixed. Default: back_propagated.

  • name (string) – Name of observable (see estimates.py for list).

  • ix (int) – Back propagation path length to average. Optional. Default: None (chooses longest path).

  • sample (int) – Sample to extract. Optional. Default None (return everything).

  • dataset_name (string) – Name of dataset to extract. Optional. Default None (uses name).

  • transform (callable) – Function to transform data. Optional. See Notes for details.

  • batch_size (int) – Size of batch to load data. Optional. Default None (load all data at once).

Returns:

obs – Observable for a single sample or the full set of samples. Note if using free projection the numerator and denominator are returned separately.

Return type:

numpy.ndarray

Notes

Transform Function Guidelines

  • Takes a single argument (data of shape (nsamples,…)) and return transformed data

  • assume the leading dimension is nsamples

Do

Don’t

Return a new array

Modify the data in place.

Return the transformed data.

Return a tuple — return a single array instead.

Return None if data is invalid.

Raise an exception

afqmctools.analysis.extraction.get_estimator_len(filename, name='Mixed')#

Get number of samples of 1RDM from file.

Parameters:

filename (string) – output file containing density matrix (*.h5 file).

Returns:

len_rdm – Number of samples of 1RDM.

Return type:

int

afqmctools.analysis.new_rdm module#

Simple extraction of afqmc rdms.

afqmctools.analysis.new_rdm.extract_qmc_dm(filename, dm_name='Mixed')#

Extract AFQMC 1RDM from file.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • dm_name (string) – Estimator type. Mixed or BackPropagated. Default: Mixed.

Returns:

  • dm (numpy.ndarray) – QMC 1RDM. shape = (ntau, 2, norb, norb).

  • weights (numpy.ndarray) – Walker weights. shape = (ntau,).

afqmctools.analysis.new_rdm.extract_rdm_single(filename, indx, dm_name='Mixed')#

Extract single sample of QMC 1RDM.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • indx (int) – Index of sample of RDM to extract.

  • dm_name (string) – Estimator type. Mixed or BackPropagated. Default: Mixed.

Returns:

  • dm (numpy.ndarray) – QMC 1RDM. shape = (2, norb, norb).

  • weight (numpy.ndarray) – Sum of walker weights at this sample.

afqmctools.analysis.new_rdm.get_metadata(filename)#

Extract QMC estimator metadata from h5 file.

Parameters:

filename (string) – output file containing density matrix (*.h5 file).

Returns:

md – Estimator metadata.

Return type:

dict

afqmctools.analysis.new_rdm.get_one_rdm_av(filename, skip, name='Mixed')#

Helper routine to compute averaged qmc density matrix.

TODO: May want to use extract single if DM gets too big.

Parameters:
  • filename (string) – output file containing density matrix (*.scalar.out file).

  • skip (float) – Percentage of data to skip at the beginning of the simulation to account for equilibration.

  • name (string) – Estimator type. Mixed or BackPropagated. Default: Mixed.

Returns:

  • dm (numpy.ndarray) – Averaged QMC density matrix.

  • dm_err (numpy.array) – Associated matrix of estimates for errors.

Notes

afqmctools.analysis.new_rdm.get_qmc_dm_trace(filename, dm_name)#

Get trace of spin up and down 1RDM as function tau. Useful for debugging.

Parameters:
  • filename (string) – output file containing density matrix (*.h5 file).

  • dm_name (string) – Estimator type. Mixed or BackPropagated. Default: Mixed.

Returns:

  • dmu (numpy.ndarray) – Trace of spin up QMC 1RDM as function of sample block.

  • dmd (numpy.ndarray) – Trace of spin down QMC 1RDM as function of sample block.

afqmctools.analysis.new_rdm.get_rdm_len(filename, dm_name='Mixed')#

Get number of samples of 1RDM from file.

Parameters:

filename (string) – output file containing density matrix (*.h5 file).

Returns:

len_rdm – Number of samples of 1RDM.

Return type:

int

afqmctools.analysis.rdm module#

AFQMCTOOLs

analysis of the 1-rdm

author: Kyle Eskridge date: 1/29/2024

afqmctools.analysis.rdm.average_afqmc_rdm(rdm_file='qmc.s000.stat.h5', dm_map=None, kappa=None, Neq=None, Teq=None, group='BackPropagated')#

Average the AFQMC rdms

Parameters:
  • rdm_file (str) – path to the AFQMC 1-rdm file

  • dm_map (dict, optional) – dictionary containing the 1-rdm samples. If not given, the samples are read from rdm_file.

  • kappa (float, optional) – autocorrelation length in units of blocks. If not given, the autocorrelation length is automatically computed from the samples.

  • Neq (int, optional) – number of blocks in equilibration. If not given, it is computed from Teq.

  • Teq (float, optional) –

    equilibration time. If only Teq is given, then Neq is computed

    as Neq = Teq / (dT/block). If neither Teq nor Neq given, Neq is set to 0.

Returns:

  • dm_means (np.array with shape (Navgs,Nspins,Nbasis,Nbasis))

  • dm_errors (np.array with shape (Navgs,Nspins,Nbasis,Nbasis))

Notes

For solids, the basis includes k-point dependence implicitly. (i.e. Nbasis = Nbands * Nkpts)

afqmctools.analysis.rdm.check_1rdm_convergence(dm_means, dm_errors, sigma=2)#

Check the convergence of the 1-rdm.

The 1-rdms are considered converged if the difference between the last two samples is within the maximum (over spin and orbitals) joint error of the two samples.

Parameters:
  • dm_means (np.array with shape (Navgs,Nspins,Nbasis,Nbasis))

  • dm_errors (np.array with shape (Navgs,Nspins,Nbasis,Nbasis))

Returns:

converged – True if the 1-rdm is converged

Return type:

bool

afqmctools.analysis.rdm.get_afqmc_rdm_samples(rdm_fname, kappa=None, nequil=0, group='BackPropagated')#

Read 1-rdm from AFQMC format

afqmctools.analysis.rdm.get_natural_orbs(dm_mean, dm_error, bootstrap=True, Nbootstraps=100, force_hermitian=True, rtol=0.001)#

Get the natural orbitals from the 1-rdm.

Uses bootstrapping to estimate the error in the natural occupancies. The natural orbitals are the eigenvectors of the 1-rdm with no error propagation.

Parameters:
  • dm_mean (np.array with shape (Nbasis,Nbasis))

  • dm_error (np.array with shape (Nbasis,Nbasis))

  • bootstrap (bool, optional) – whether to use bootstrapping to estimate the error

  • Nbootstraps (int, optional) – number of bootstraps to use

  • force_hermitian (bool, optional) – whether to force the 1-rdm to be hermitian

  • rtol (float, optional) – relative tolerance for checking hermiticity

Returns:

  • natural_orbs (np.array with shape (Nbasis,Nbasis))

  • natural_occs (np.array with shape (Nbasis))

  • natural_occs_errs (np.array with shape (Nbasis))

afqmctools.analysis.rdm.plot_1rdm_convergence(dm_means, dm_errors, spin_trace=False, force_hermitian=False)#

Plot the convergence of the 1-rdm.

Parameters:
  • dm_means (np.array with shape (Navgs,Nspins,Nbasis,Nbasis))

  • dm_errors (np.array with shape (Navgs,Nspins,Nbasis,Nbasis))

afqmctools.analysis.rdm.plot_rdm_diagonal(dm_means, dm_errors, ax, spin=None, **kwargs)#

plot the diagonal of the 1-RDM vs basis set index with errorbars

Parameters:
  • rdm (np.array with shape (Nspins,Nbasis,Nbasis)) – 1-RDM matrix

  • delta_rdm (np.array with shape (Nspins,Nbasis,Nbasis)) – error in the 1-RDM matrix

  • ax (matplotlib.pyplot.axis) – axis to plot the diagonal

  • spin (int, optional) – spin index to plot. If None, sum over spins.

  • **kwargs (dict) – keyword arguments to pass to plt.errorbar

Notes

This function is useful for checking convergence of the 1-RDM.

It may be useful to pass a label to the errorbar for the legend.

afqmctools.analysis.rdm.resample(marr, earr, nsample)#

Resample the mean reduced density matrix (RDM).

Parameters:
  • marr (numpy.ndarray) – The mean reduced density matrix to be resampled. It should be a square matrix.

  • earr (numpy.ndarray) – The error array corresponding to the mean RDM. It should have the same shape as marr.

  • nsample (int) – The number of samples to generate.

Returns:

A new array of shape (nsample, *marr.shape) containing the resampled RDMs.

Return type:

numpy.ndarray

Notes

to set the random seed, use numpy.random.seed(seed) immediately before calling this function.

afqmctools.analysis.transform module#

afqmctools.analysis.transform.check_integer(value, name=None)#
afqmctools.analysis.transform.eval_hubbard_from_diag_two_rdm_factory(U, walker_type)#

Factory function to generate a Hubbard U energy transform function from diagonal two-rdm.

The transform computes the Hubbard U energy from the diagonal of the two-body density matrix.

\[E_{U} = U \sum_{i} \rho_{i,\uparrow i,\uparrow; i,\downarrow i,\downarrow}\]

where ‘i’ is the number of sites.

For closed shell, a factor of 2 is applied to the result to account for the two spin channels. for collinear, both spin channels are evaluated separately, and the result is summed. For non-collinear, the spin channels are evaluated separately, and the result is summed.

Parameters:
  • U (float) – The Hubbard U parameter.

  • walker_type (str) – The type of walker (‘closed’, ‘collinear’, ‘non_collinear’).

Returns:

A function hubbard_energy(diag2rdm), where diag2rdm is a two-rdm of shape (n_samples, M, M) - i.e. expressed as the full array versus the upper-triangular form - Where M is the number of basis functions. M is the number of spin orbitals for all cases except closed shell, where M is the number of spatial orbitals.

Return type:

callable

afqmctools.analysis.transform.eval_one_body_obs_factory(one_body_operator=None, walker_type=None)#

Factory function to generate a one-body energy transform function.

The transform computes a one body observable from the one-body operator and the density matrix.

\[O_{1} = \sum_{pq} \rho_{pq} O_{pq}\]

where ‘p’ and ‘q’ are the matrix dimensions, and ‘h’ is the one-body operator.

For closed shell, a factor of 2 is applied to the result to account for the two spin channels. for collinear, both spin channels are evaluated separately, and the result is summed. For non-collinear, the spin channels are evaluated separately, and the result is summed.

afqmctools.analysis.transform.eval_two_body_obs_factory(cholesky=None, two_body_operator=None, walker_type=None)#

Factory function to generate a two-body energy transform function.

The transform computes a two body observable from the two-body operator and the density matrix.

\[O_{2} = \frac{1}{2} \sum_{pqrs} \rho_{pqrs} ( pq | rs )\]

where ‘p’ and ‘q’ are the matrix dimensions, and ‘h’ is the two-body operator.

For closed shell, a factor of 2 is applied to the result to account for the two spin channels. for collinear, both spin channels are evaluated separately, and the result is summed. For non-collinear, the spin channels are evaluated separately, and the result is summed.

afqmctools.analysis.transform.hermitize_factory(walker_type)#

Factory function to generate a hermitian transform function.

The transform makes a matrix hermitian by averaging with its conjugate transpose.

\[\begin{split}M_{nij} = \\frac{1}{2} (M_{nij} + M_{nji}^{*})\end{split}\]

where ‘n’ is the sample dimension, and ‘i’ and ‘j’ are the matrix dimensions.

Notes

Only works for 2D matrices, where the first dimension is the sample dimension, and the second dimension is the square of a the matrix dimension.

Return type:

callable

afqmctools.analysis.transform.upper_triangle_factory(walker_type)#

Factory function to generate an upper triangle transform function.

The transform extracts the upper triangle of a matrix.

\[\begin{split}M_{nij} = M_{nij} \\quad i \\leq j\end{split}\]

where ‘n’ is the sample dimension, and ‘i’ and ‘j’ are the matrix dimensions.

Notes

Only works for 2D matrices, where the first dimension is the sample dimension, and the second dimension is the square of a the matrix dimension.

Return type:

callable

Module contents#