Skip to content

Commit

Permalink
feat: add TRIQS gf helpers (#39)
Browse files Browse the repository at this point in the history
* fix: make get_h_qp helper only return the matrix

* docs: reflect change to h_qp helper

* feat: helper functions to construct triqs green's functions

* chore: added green's function to example

* fix: actions and pytest strictness (#37)

* fix: make get_h_qp helper only return the matrix

* docs: reflect change to h_qp helper

* feat: helper functions to construct triqs green's functions

* chore: added green's function to example

* chore: ignore version file

* fix: update actions, use dependabot

* fix: typo in gcc-version

* fix: ignore triqs errors in pytest

* check if ignore warnings works on github

* only filter triqs warnings

* fix: only make warnings errors in risb, ignore third party

* Bump the actions group with 7 updates (#38)

Bumps the actions group with 7 updates:

| Package | From | To |
| --- | --- | --- |
| [mathieudutour/github-tag-action](https://github.com/mathieudutour/github-tag-action) | `6.1` | `6.2` |
| [actions/upload-artifact](https://github.com/actions/upload-artifact) | `3` | `4` |
| [actions/configure-pages](https://github.com/actions/configure-pages) | `3` | `5` |
| [actions/download-artifact](https://github.com/actions/download-artifact) | `3` | `4` |
| [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) | `2` | `3` |
| [actions/deploy-pages](https://github.com/actions/deploy-pages) | `2` | `4` |
| [hynek/build-and-inspect-python-package](https://github.com/hynek/build-and-inspect-python-package) | `1` | `2` |


Updates `mathieudutour/github-tag-action` from 6.1 to 6.2
- [Release notes](https://github.com/mathieudutour/github-tag-action/releases)
- [Commits](mathieudutour/github-tag-action@v6.1...v6.2)

Updates `actions/upload-artifact` from 3 to 4
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v3...v4)

Updates `actions/configure-pages` from 3 to 5
- [Release notes](https://github.com/actions/configure-pages/releases)
- [Commits](actions/configure-pages@v3...v5)

Updates `actions/download-artifact` from 3 to 4
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](actions/download-artifact@v3...v4)

Updates `actions/upload-pages-artifact` from 2 to 3
- [Release notes](https://github.com/actions/upload-pages-artifact/releases)
- [Commits](actions/upload-pages-artifact@v2...v3)

Updates `actions/deploy-pages` from 2 to 4
- [Release notes](https://github.com/actions/deploy-pages/releases)
- [Commits](actions/deploy-pages@v2...v4)

Updates `hynek/build-and-inspect-python-package` from 1 to 2
- [Release notes](https://github.com/hynek/build-and-inspect-python-package/releases)
- [Changelog](https://github.com/hynek/build-and-inspect-python-package/blob/main/CHANGELOG.md)
- [Commits](hynek/build-and-inspect-python-package@v1...v2)

---
updated-dependencies:
- dependency-name: mathieudutour/github-tag-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/configure-pages
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/download-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/upload-pages-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/deploy-pages
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: hynek/build-and-inspect-python-package
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* docs: docstrings for green's functions

* feat: calculate triqs gf as numpy arrays

* chore: update todo

* chore: add helper function make g0

* chore: update examples to show gf usage

* Revert "Merge branch 'main' into gf_helpers"

This reverts commit a44feb7, reversing
changes made to d6345d1.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
thenoursehorse and dependabot[bot] committed May 16, 2024
1 parent d6a1e8c commit a2e7aee
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 51 deletions.
5 changes: 4 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Rotationally invariant slave-bosons.
- Add kweights tests, DIIS tests, multiple cluster tests, complex SOC tests,
all helpers functions (make random inputs and store, because current tests
have too much structure)
- Add helpers_triqs tests
- Fix sensitive to initial R, Lambda guess, make more robust
- Implement initial guess as R, pdensity, as this will likely be more robust.
- Get static type hints working for mypy
- Add verbose output to `LatticeSolver`
- Add verbose output to `DIIS`
Expand All @@ -32,4 +34,5 @@ version 3.2.0
- Setup github actions
- single-orbital Hubbard tutorial
- action for hatchling version bump (done with tag update action)
- pipy packaging
- pipy packaging
- Green's function helper functions
32 changes: 31 additions & 1 deletion examples/bilayer_hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from triqs.operators import Operator, c_dag, c, n
from triqs.operators.util.op_struct import set_operator_structure
from triqs.operators.util.observables import S2_op, N_op
from triqs.gf import BlockGf, MeshImFreq, MeshProduct

from risb import LatticeSolver
from risb.kweight import SmearingKWeight
from risb.embedding import EmbeddingAtomDiag
from risb.helpers_triqs import get_g0_k_w, get_sigma_w, get_g_qp_k_w, get_g_k_w, get_g_w_loc

# Number of orbitals and spin structure
n_orb = 2
Expand Down Expand Up @@ -82,9 +84,37 @@
# Effective total spin of a cluster
total_spin_Op = S2_op(spin_names, n_orb, off_diag=True)
total_spin = embedding.overlap(total_spin_Op)

# Some different ways to construct some Green's functions

# The k-space and frequency mesh of the problem
iw_mesh = MeshImFreq(beta=beta, S='Fermion', n_max=64)
k_iw_mesh = MeshProduct(mk, iw_mesh)

mu = kweight.mu

# Gf constructed from local self-energy
G0_k_iw = get_g0_k_w(gf_struct=gf_struct, mesh=k_iw_mesh, h0_k=h0_k, mu=mu)
Sigma_iw = get_sigma_w(mesh=iw_mesh, gf_struct=gf_struct, Lambda=S.Lambda[0], R=S.R[0], h0_loc=S.h0_loc_matrix[0], mu=mu)
G_k_iw = get_g_k_w(g0_k_w=G0_k_iw, sigma_w=Sigma_iw)

# Gf constructed from quasiparticle Gf
G_qp_k_iw = get_g_qp_k_w(gf_struct=gf_struct, mesh=k_iw_mesh, h0_kin_k=S.h0_kin_k, Lambda=S.Lambda[0], R=S.R[0], mu=mu)
G_k_iw2 = get_g_k_w(g_qp_k_w=G_qp_k_iw, R=S.R[0])

# Local Green's functions integrated over k
G0_iw_loc = get_g_w_loc(G0_k_iw) # this is using the correlated chemical potential, so will not have right filling
G_qp_iw_loc = get_g_w_loc(G_qp_k_iw)
G_iw_loc = get_g_w_loc(G_k_iw)
G_iw_loc2 = get_g_w_loc(G_k_iw2)

# Print out some interesting observables
with np.printoptions(formatter={'float': '{: 0.4f}'.format}):
#with np.printoptions(formatter={'float': '{: 0.4f}'.format}):
with np.printoptions(precision=4, suppress=True):
print(f"Filling G0: {G0_iw_loc.total_density().real:.4f}")
print(f"Filling G_qp: {G_qp_iw_loc.total_density().real:.4f}")
print(f"Filling G: {G_iw_loc.total_density().real:.4f}")
print(f"Filling G2: {G_iw_loc2.total_density().real:.4f}")
for i in range(S.n_clusters):
for bl, Z in S.Z[i].items():
print(f"Quasiaprticle weight Z[{bl}] = \n{Z}")
Expand Down
45 changes: 24 additions & 21 deletions examples/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from triqs.operators import Operator, n
from triqs.operators.util.op_struct import set_operator_structure
from triqs.operators.util.observables import S2_op, N_op
from triqs.gf import BlockGf, MeshImFreq, MeshProduct
from triqs.gf import MeshImFreq, MeshProduct

from risb import LatticeSolver
from risb.kweight import SmearingKWeight
from risb.embedding import EmbeddingAtomDiag
from risb.helpers_triqs import get_sigma_w, get_g_qp_k_w, get_g_k_w, get_g_w_loc
from risb.helpers_triqs import get_g0_k_w, get_sigma_w, get_g_qp_k_w, get_g_k_w, get_g_w_loc

import matplotlib.pyplot as plt

Expand Down Expand Up @@ -89,36 +89,39 @@ def force_paramagnetic(A):
# Some different ways to construct some Green's functions
mu = kweight.mu

# Non-interacting lattice Green's function
# The k-space and frequency mesh of the problem
iw_mesh = MeshImFreq(beta=beta, S='Fermion', n_max=64)
k_iw_mesh = MeshProduct(mk, iw_mesh)
G0_k_iw = BlockGf(mesh=k_iw_mesh, gf_struct=gf_struct)
for bl, gf in G0_k_iw:
e_k = tbl.fourier(mk)
for k, iw in gf.mesh:
gf[k,iw] = 1 / (iw - e_k[k] + mu)

# Quasiparticle lattice Green's function, local self-energy, lattice Green's function
G_qp_k_iw = get_g_qp_k_w(gf_struct=gf_struct, mesh=k_iw_mesh, h0_kin_k=S.h0_kin_k, Lambda=S.Lambda[0], R=S.R[0], mu=mu)
Sigma_iw = get_sigma_w(mesh=iw_mesh, gf_struct=gf_struct, Lambda=S.Lambda[0], R=S.R[0], mu=mu)
mu = kweight.mu

# Gf constructed from local self-energy
G0_k_iw = get_g0_k_w(gf_struct=gf_struct, mesh=k_iw_mesh, h0_k=h0_k, mu=mu)
Sigma_iw = get_sigma_w(mesh=iw_mesh, gf_struct=gf_struct, Lambda=S.Lambda[0], R=S.R[0], h0_loc=S.h0_loc_matrix[0], mu=mu)
G_k_iw = get_g_k_w(g0_k_w=G0_k_iw, sigma_w=Sigma_iw)

# Gf constructed from quasiparticle Gf
G_qp_k_iw = get_g_qp_k_w(gf_struct=gf_struct, mesh=k_iw_mesh, h0_kin_k=S.h0_kin_k, Lambda=S.Lambda[0], R=S.R[0], mu=mu)
G_k_iw2 = get_g_k_w(g_qp_k_w=G_qp_k_iw, R=S.R[0])

# Local Green's functions integrated over k
G0_iw_loc = get_g_w_loc(G0_k_iw)
# Local Gf integrated over k
G0_iw_loc = get_g_w_loc(G0_k_iw) # this is using the correlated chemical potential, so will not have right filling
G_qp_iw_loc = get_g_w_loc(G_qp_k_iw)
G_iw_loc = get_g_w_loc(G_k_iw)
G_iw_loc2 = get_g_w_loc(G_k_iw2)

# Filling of physical electron scales with Z
print("G0:", G0_iw_loc.total_density().real)
print("G_qp:", G_qp_iw_loc.total_density().real)
print("G:", G_iw_loc.total_density().real)
print("G2:", G_iw_loc2.total_density().real)
print("Z:", S.Z[0]['up'][0,0])
print()
print(f"Filling G0: {G0_iw_loc.total_density().real:.4f}")
print(f"Filling G_qp: {G_qp_iw_loc.total_density().real:.4f}")
print(f"Filling G: {G_iw_loc.total_density().real:.4f}")
print(f"Filling G2: {G_iw_loc2.total_density().real:.4f}")
print(f"Filling Z:: {S.Z[0]['up'][0,0]:.4f}")

fig, axis = plt.subplots(1,2)
axis[0].plot(U_arr, Z, '-ok')
axis[0].plot(U_arr, -0.5 + 0.5 * np.sqrt( 1 + 4*np.array(total_spin) ), '-ok')
axis[0].set_xlabel(r'$U$')
axis[0].set_ylabel(r'$Z$')
axis[1].plot(U_arr, -0.5 + 0.5 * np.sqrt( 1 + 4*np.array(total_spin) ), '-ok')
axis[1].set_xlabel(r'$U$')
axis[1].set_ylabel(r'$\mathcal{S}$')
plt.show()
Loading

0 comments on commit a2e7aee

Please sign in to comment.