Skip to content

Commit

Permalink
Merge pull request #7 from tanlin2013/main
Browse files Browse the repository at this point in the history
Test: dmrg in hybrid basis
  • Loading branch information
tanlin2013 authored Dec 1, 2022
2 parents 08f4816 + 27c49d0 commit 1b3a250
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
ColumnLimit: 88
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ jobs:
submodules: 'true'

- name: Log in to the Container registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
context: .
push: true
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
path = ext/catch2
url = https://github.com/catchorg/Catch2.git
branch = v3.2.0
[submodule "ext/armadillo"]
path = ext/armadillo
url = https://gitlab.com/conradsnicta/armadillo-code.git
branch = 11.4.x
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
rev: v1.3.5
hooks:
- id: clang-format
args: [--style=Google]
args: [--style=Google, -i]
# - id: clang-tidy
# - id: oclint
# - id: uncrustify
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ RUN cd $PKGDIR/itensor && \
cp options.mk.sample options.mk && \
make -e

# Install armadillo
RUN cd $PKGDIR/armadillo && \
cmake . && \
make install

# Install Catch2 framework for unit test
RUN cd $PKGDIR/catch2 && \
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ Installation

* Pull the image:
```
docker pull ghcr.io/chiamin/hybridleads:main
docker pull ghcr.io/chiamin/hybridleads:latest
```
* Build the image by yourself:
```
docker build --no-cache --force-rm -t hybridleads .
```
* Run the container:
```
docker run --rm -it -v $(pwd)/tests:/home/tests ghcr.io/chiamin/hybridleads:main
docker run --rm -it -v $(pwd)/tests:/home/tests ghcr.io/chiamin/hybridleads:latest
```
**Note**: replace the image name `ghcr.io/chiamin/hybridleads:main` by `hybridleads` if you're building the image by yourself.
**Note**: replace the image name `ghcr.io/chiamin/hybridleads:latest` by `hybridleads` if you're building the image by yourself.
* Package version:
* `gcc 12.2.0`
* `c++17`
* `cmake 3.10^`
* `ITensor v3.1.11`
* `armadillo 11.4.x`
* `Catch2 v3.2.0`
* Environment variables:
The compiling flags for ITensor,
Expand All @@ -38,6 +39,7 @@ Installation
* lapack, blas
* [ITensor](https://itensor.org/)
* [itensor.utility](https://github.com/chiamin/itensor.utility)
* [armadillo](https://arma.sourceforge.net/)
Run the tests
Expand Down
1 change: 1 addition & 0 deletions ext/armadillo
Submodule armadillo added at f6f603
174 changes: 83 additions & 91 deletions kbasis/OneParticleBasis.h
Original file line number Diff line number Diff line change
@@ -1,122 +1,114 @@
#ifndef __ONEPARTICLEBASIS_H_CMC__
#define __ONEPARTICLEBASIS_H_CMC__
#include "itensor/all.h"
#include "GeneralUtility.h"
#include "itensor/all.h"
using namespace itensor;
using namespace std;


/**
* @brief Generate the tight-binding Hamiltonian.
*
* @brief Generate the tight-binding Hamiltonian in single particle basis.
*
* @param L The size of matrix, L x L.
* @param t The hopping strength.
* @param mu On-site energy.
* @param damp_fac
* @param damp_from_right
* @param verbose
* @param damp_fac
* @param damp_from_right
* @param verbose
* @return Matrix The Hamiltonian.
*/
Matrix tight_binding_Hamilt (int L, Real t, Real mu, Real damp_fac=1., bool damp_from_right=true, bool verbose=false)
{
cout << "L = " << L << endl;
Matrix H (L,L);
for(int i = 0; i < L; i++)
{
H(i,i) = -mu;
if (i != L-1)
{
int damp_dist = (damp_from_right ? L-2-i : i);
Real ti = t * pow (damp_fac, damp_dist);
H(i,i+1) = -ti;
H(i+1,i) = -ti;
if (verbose)
cout << "Hk, t " << i << " = " << ti << endl;
}
Matrix tight_binding_Hamilt(int L, Real t, Real mu, Real damp_fac = 1.,
bool damp_from_right = true, bool verbose = false) {
cout << "L = " << L << endl;
Matrix H(L, L);
for (int i = 0; i < L; i++) {
H(i, i) = -mu;
if (i != L - 1) {
int damp_dist = (damp_from_right ? L - 2 - i : i);
Real ti = t * pow(damp_fac, damp_dist);
H(i, i + 1) = -ti;
H(i + 1, i) = -ti;
if (verbose) cout << "Hk, t " << i << " = " << ti << endl;
}
return H;
}
return H;
}

class OneParticleBasis {
public:
OneParticleBasis() {}
OneParticleBasis(const string& name, const Matrix& H) : _name(name), _H(H) {
diagHermitian(H, _Uik, _ens);
}
OneParticleBasis(const string& name, int L, Real t, Real mu,
Real damp_fac = 1., bool damp_from_right = true,
bool verbose = false)
: _name(name) {
_H = tight_binding_Hamilt(L, t, mu, damp_fac, damp_from_right, verbose);
diagHermitian(_H, _Uik, _ens);
}
OneParticleBasis(const string& name, int L) : _name(name) {
_H = Matrix(L, L);
diagHermitian(_H, _Uik, _ens);
}

class OneParticleBasis
{
public:
OneParticleBasis () {}
OneParticleBasis (const string& name, const Matrix& H)
: _name (name)
, _H (H)
{
diagHermitian (H, _Uik, _ens);
}
OneParticleBasis (const string& name, int L, Real t, Real mu, Real damp_fac=1., bool damp_from_right=true, bool verbose=false)
: _name (name)
{
_H = tight_binding_Hamilt (L, t, mu, damp_fac, damp_from_right, verbose);
diagHermitian (_H, _Uik, _ens);
}
OneParticleBasis (const string& name, int L)
: _name (name)
{
_H = Matrix(L,L);
diagHermitian (_H, _Uik, _ens);
}
// Functions that every basis class must have
const string& name() const { return _name; }
vector<tuple<int, auto, bool>> C_op(int i, bool dag) const;
Real en(int k) const {
mycheck(k > 0 and k <= _ens.size(), "out of range");
return _ens(k - 1);
}
Real mu(int k) const {
mycheck(k > 0 and k <= _ens.size(), "out of range");
return -_H(k - 1, k - 1);
}
int size() const { return _ens.size(); }

// Functions that every basis class must have
const string& name () const { return _name; }
vector<tuple<int,auto,bool>> C_op (int i, bool dag) const;
Real en (int k) const { mycheck (k > 0 and k <= _ens.size(), "out of range"); return _ens(k-1); }
Real mu (int k) const { mycheck (k > 0 and k <= _ens.size(), "out of range"); return -_H(k-1,k-1); }
int size () const { return _ens.size(); }
void write(ostream& s) const {
itensor::write(s, _name);
itensor::write(s, _Uik);
itensor::write(s, _ens);
}
void read(istream& s) {
itensor::read(s, _name);
itensor::read(s, _Uik);
itensor::read(s, _ens);
}

void write (ostream& s) const
{
itensor::write(s,_name);
itensor::write(s,_Uik);
itensor::write(s,_ens);
}
void read (istream& s)
{
itensor::read(s,_name);
itensor::read(s,_Uik);
itensor::read(s,_ens);
}

private:
string _name;
Matrix _Uik, _H;
Vector _ens;
private:
string _name;
Matrix _Uik, _H;
Vector _ens;
};

/**
* @brief Get the operator information in this basis for the operator Cdag_i,
* C_i = \sum_k coef_ik C_k
* Cdag_i = \sum_k coef_ik Cdag_k
*
* C_i = \sum_k U_ik C_k
* Cdag_i = \sum_k U_ik^* Cdag_k
*
* @param i The real-space site index, 1-index.
* @param dag Whether the operator has a dagger or not.
* @return vector<tuple<int,auto,bool>> The basis index (k) in ascending order, coefficient,
* and whether the operator has a dagger or not.
* @return vector<tuple<int,auto,bool>> The basis index (k, 0-index) in
* ascending order, coefficient U_ik, and whether the operator has a dagger or
* not.
*/
vector<tuple<int,auto,bool>> OneParticleBasis :: C_op (int i, bool dag) const
{
mycheck (i > 0 and i <= nrows(_Uik), "out of range");
vector<tuple<int, auto, bool>> OneParticleBasis ::C_op(int i, bool dag) const {
mycheck(i > 0 and i <= nrows(_Uik), "out of range");

auto tmp = _Uik(0,0);
vector<tuple<int,decltype(tmp),bool>> k_coef_dag;
auto tmp = _Uik(0, 0);
vector<tuple<int, decltype(tmp), bool>> k_coef_dag;

for(int k = 0; k < this->size(); k++) // Here k is zero-index
{
k_coef_dag.emplace_back (k+1, iut::conj(_Uik(i-1,k)), dag);
for (int k = 0; k < this->size(); k++) // Here k is zero-index
{
if (dag) {
k_coef_dag.emplace_back(k + 1, iut::conj(_Uik(i - 1, k)), dag);
} else {
k_coef_dag.emplace_back(k + 1, _Uik(i - 1, k), dag);
}
return k_coef_dag;
}
return k_coef_dag;
}

auto write (ostream& s, const OneParticleBasis& t)
{
t.write (s);
}
auto read (istream& s, OneParticleBasis& t)
{
t.read (s);
}
auto write(ostream& s, const OneParticleBasis& t) { t.write(s); }
auto read(istream& s, OneParticleBasis& t) { t.read(s); }
#endif
Loading

0 comments on commit 1b3a250

Please sign in to comment.