Skip to content

Commit

Permalink
Introduced 1-indexing in Julia, updating documentation and usage exam…
Browse files Browse the repository at this point in the history
…ples
  • Loading branch information
Alexander Wietek committed Sep 9, 2024
1 parent 9f3b148 commit 81cb899
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 44 deletions.
4 changes: 4 additions & 0 deletions docs/documentation/operators/op.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ A local operator acting on several lattice sites.
| coupling | sets the coefficients neded to specify the coupling. Further details below | |
| sites | defines on which site(s) of the lattice the operator acts on. | |

!!! warning "1-indexing in Julia / 0-indexing in C++"

To enumerate the sites of an Op, we start counting at 1 in Julia and 0 in C++.

The coupling can take on several types and allow some flexibility in defining operators.

| type | Description | |
Expand Down
4 changes: 4 additions & 0 deletions docs/documentation/symmetries/permutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Creates an Permutation out of an array of integers, e.g. `[0, 2, 1, 3]`. If the
```c++
Permutation(std::vector<int64_t> const &array);
```

!!! warning "1-indexing in Julia / 0-indexing in C++"

To enumerate the sites of a Permutation, we start counting at 1 in Julia and 0 in C++.

## Methods

Expand Down
11 changes: 11 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
title: Releases
---

## v0.2.3

**Sep. 9, 2024**

Introduced 1-indexing everywhere in Julia version

* only changes to XDiag.jl, C++ untouched
* XDiag_jll.jl remains at v0.2.2

---

## v0.2.2

**Aug. 27, 2024**
Expand Down
14 changes: 7 additions & 7 deletions examples/spectrum/spinhalf_chain_e0/main.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using XDiag

let
N = 16;
nup = N ÷ 2;
block = Spinhalf(N, nup);
N = 16
nup = N ÷ 2
block = Spinhalf(N, nup)

# Define the nearest-neighbor Heisenberg model
ops = OpSum()
for i in 1:N
ops += Op("HB", "J", [i-1, i % N])
end
ops["J"] = 1.0;
ops["J"] = 1.0

# set_verbosity(2); # set verbosity for monitoring progress
e0 = eigval0(ops, block); # compute ground state energy
set_verbosity(2) # set verbosity for monitoring progress
e0 = eigval0(ops, block) # compute ground state energy

println("Ground state energy: $e0");
println("Ground state energy: $e0")
end


6 changes: 3 additions & 3 deletions examples/usage_examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ auto [e0, gs] = eig0(ops, block);

{
// --8<-- [start:op]
auto op = Op("HOP", "T", {1, 2});
auto op = Op("HOP", "T", {0, 1});
XDIAG_SHOW(op);
XDIAG_SHOW(op.type());
XDIAG_SHOW(op.coupling().as<std::string>());
Expand All @@ -225,14 +225,14 @@ XDIAG_SHOW(op[0]);
XDIAG_SHOW(op[1]);
XDIAG_SHOW(op.isexplicit());

op = Op("HOP", 1.23, {1, 2});
op = Op("HOP", 1.23, {0, 1});
XDIAG_SHOW(op);
XDIAG_SHOW(op.isreal());
XDIAG_SHOW(op.ismatrix());
XDIAG_SHOW(op.isexplicit());

arma::cx_mat m(arma::mat("0 0; 0 0"), arma::mat("0 -1; 1 0"));
op = Op("SY", m, 1);
op = Op("SY", m, 0);
XDIAG_SHOW(op);
XDIAG_SHOW(op.isreal());
XDIAG_SHOW(op.ismatrix());
Expand Down
68 changes: 34 additions & 34 deletions examples/usage_examples/main.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using XDiag

# --8<-- [start:Permutation]
p1 = Permutation([0, 2, 1, 3])
p2 = Permutation([2, 0, 1, 3])
p1 = Permutation([1, 3, 2, 4])
p2 = Permutation([3, 1, 2, 4])

@show inverse(p1)
@show p1 * p2
# --8<-- [end:Permutation]

# --8<-- [start:PermutationGroup]
# Define a cyclic group of order 3
p1 = Permutation([0, 1, 2])
p2 = Permutation([1, 2, 0])
p3 = Permutation([2, 0, 1])
p1 = Permutation([1, 2, 3])
p2 = Permutation([2, 3, 1])
p3 = Permutation([3, 1, 2])
C3 = PermutationGroup([p1, p2, p3])

@show size(C3)
Expand Down Expand Up @@ -42,10 +42,10 @@ block_sz = Spinhalf(N, nup)
@show block_sz

# with symmetries, without Sz
p1 = Permutation([0, 1, 2, 3])
p2 = Permutation([1, 2, 3, 0])
p3 = Permutation([2, 3, 0, 1])
p4 = Permutation([3, 0, 1, 2])
p1 = Permutation([1, 2, 3, 4])
p2 = Permutation([2, 3, 4, 1])
p3 = Permutation([3, 4, 1, 2])
p4 = Permutation([4, 1, 2, 3])
group = PermutationGroup([p1, p2, p3, p4])
rep = Representation([1, -1, 1, -1])
block_sym = Spinhalf(N, group, rep)
Expand Down Expand Up @@ -76,10 +76,10 @@ block = tJ(N, nup, ndn)
@show block

# with permutation symmetries
p1 = Permutation([0, 1, 2, 3])
p2 = Permutation([1, 2, 3, 0])
p3 = Permutation([2, 3, 0, 1])
p4 = Permutation([3, 0, 1, 2])
p1 = Permutation([1, 2, 3, 4])
p2 = Permutation([2, 3, 4, 1])
p3 = Permutation([3, 4, 1, 2])
p4 = Permutation([4, 1, 2, 3])
group = PermutationGroup([p1, p2, p3, p4])
rep = Representation([1, -1, 1, -1])
block_sym = tJ(N, nup, ndn, group, rep)
Expand Down Expand Up @@ -111,10 +111,10 @@ block_np = Electron(N, nup, ndn)
@show block_np

# with symmetries, without number conservation
p1 = Permutation([0, 1, 2, 3])
p2 = Permutation([1, 2, 3, 0])
p3 = Permutation([2, 3, 0, 1])
p4 = Permutation([3, 0, 1, 2])
p1 = Permutation([1, 2, 3, 4])
p2 = Permutation([2, 3, 4, 1])
p3 = Permutation([3, 4, 1, 2])
p4 = Permutation([4, 1, 2, 3])
group = PermutationGroup([p1, p2, p3, p4])
rep = Representation([1, -1, 1, -1])
block_sym = Electron(N, group, rep)
Expand Down Expand Up @@ -146,16 +146,16 @@ let
# Define a Hubbard chain model
ops = OpSum()
for i in 1:N
ops += Op("HOP", "T", [i-1, i % N])
ops += Op("HOP", "T", [i, mod1(i+1, N)])
end
ops["T"] = 1.0;
ops["U"] = 5.0;

# Create the a permutation group
p1 = Permutation([0, 1, 2, 3])
p2 = Permutation([1, 2, 3, 0])
p3 = Permutation([2, 3, 0, 1])
p4 = Permutation([3, 0, 1, 2])
p1 = Permutation([1, 2, 3, 4])
p2 = Permutation([2, 3, 4, 1])
p3 = Permutation([3, 4, 1, 2])
p4 = Permutation([4, 1, 2, 3])
group = PermutationGroup([p1, p2, p3, p4])
irrep = Representation([1, -1, 1, -1])
block = Electron(N, nup, ndn, group, irrep)
Expand All @@ -174,7 +174,7 @@ let
# Define the nearest-neighbor Heisenberg model
ops = OpSum()
for i in 1:N
ops += Op("HB", "J", [i-1, i % N])
ops += Op("HB", "J", [i, mod1(i+1, N)])
end
ops["J"] = 1.0

Expand All @@ -191,7 +191,7 @@ let
# Define the nearest-neighbor Heisenberg model
ops = OpSum()
for i in 1:N
ops += Op("HB", "J", [i-1, i % N])
ops += Op("HB", "J", [i, mod1(i+1, N)])
end
ops["J"] = 1.0;

Expand Down Expand Up @@ -233,8 +233,8 @@ let

ops = OpSum()
for i in 1:N
ops += Op("ISING", "J", [i-1, i % N])
ops += Op("SX", h * Sx, i-1)
ops += Op("ISING", "J", [i, mod1(i+1, N)])
ops += Op("SX", h * Sx, i)
end

ops["J"] = 1.0;
Expand Down Expand Up @@ -350,7 +350,7 @@ let
block = Spinhalf(N, N ÷ 2)
ops = OpSum()
for i in 1:N
ops += Op("HB", 1.0, [i-1, i % N])
ops += Op("HB", 1.0, [i, mod1(i+1, N)])
end
e0, psi = eig0(ops, block);

Expand All @@ -375,7 +375,7 @@ let
block = Spinhalf(N, N ÷ 2)
ops = OpSum()
for i in 1:N
ops += Op("HB", 1.0, [i-1, i % N])
ops += Op("HB", 1.0, [i, mod1(i+1, N)])
end
e0, psi = eig0(ops, block);

Expand All @@ -392,23 +392,23 @@ let
N = 4
nup = 2
block = Spinhalf(N, nup)
p1 = Permutation([0, 1, 2, 3])
p2 = Permutation([1, 2, 3, 0])
p3 = Permutation([2, 3, 0, 1])
p4 = Permutation([3, 0, 1, 2])
p1 = Permutation([1, 2, 3, 4])
p2 = Permutation([2, 3, 4, 1])
p3 = Permutation([3, 4, 1, 2])
p4 = Permutation([4, 1, 2, 3])
group = PermutationGroup([p1, p2, p3, p4])
rep = Representation([1, 1, 1, 1])
block_sym = Spinhalf(N, group, rep)

ops = OpSum()
for i in 1:N
ops += Op("HB", 1.0, [i-1, i % N])
ops += Op("HB", 1.0, [i, mod1(i+1, N)])
end

e0, psi = eig0(ops, block);
e0, psi_sym = eig0(ops, block_sym);

corr = Op("HB", 1.0, [0, 1])
corr = Op("HB", 1.0, [1, 2])
nn_corr = inner(corr, psi)
corr_sym = symmetrize(corr, group)
nn_corr_sym = inner(corr_sym, psi_sym)
Expand Down

0 comments on commit 81cb899

Please sign in to comment.