XDiag is a C++ library for performing Exact Diagonalizations of quantum many-body systems. Key features include optimized combinatorical algorithms for navigating Hilbert spaces, iterative linear algebra algorithms, shared and distributed memory parallelization.
Using XDiag with C++ is a two-step process. First the xdiag library needs to be compiled and installed. Therafter, application codes are compiled in a second step. Here we explain how to compile the library.
The source files for the documentation can be found in the directory docs. The documentation is built using Material for MKDocs. To work on it locally, it can be served using
mkdocs serve\n
from the xdiag root source directory. A local build of the documentation can then be accessed in a webbrowser at the adress
The function say_hello() prints out a welcome message, which also contains information which exact XDiag version is used. In Julia this is all there is to it.
For the C++ code we need to create two files to compile the program. The first is the actual C++ code. What is maybe a bit unfamiliar is the try / catch block. XDiag implements a traceback mechanism for runtime errors, which is activated by this idiom. While not stricly necessary here, it is a good practice to make use of this.
Now that the application program is written, we next need to set up the compilation instructions using CMake. To do so we create a second file called CMakeLists.txt in the same directory.
You should replace \"/path/to/xdiag/install\" with the appropriate directory where your XDiag library is installed after compilation. This exact CMakeLists.txt file can be used to compile any XDiag application.
Info
For using the distributed XDiag library the last line of the above CMakeLists.txt should be changed to
target_link_libraries(main PUBLIC xdiag::xdiag_distributed)\n
We then compile the application code,
cmake -S . -B build\ncmake --build build\n
and finally run our first xdiag application.
./build/main\n
"},{"location":"quickstart/#computing-the-ground-state-energy-of-a-spin-chain","title":"Computing the ground state energy of a spin chain","text":"
We compute the ground state energy of the \\(S=1/2\\) Heisenberg chain on a periodic chain lattice in one dimension. The Hamiltonian is given by
\\[ H = J\\sum_{\\langle i,j \\rangle} \\mathbf{S}_i \\cdot \\mathbf{S}_j\\]
where \\(\\mathbf{S}_i = (S_i^x, S_i^y, S_i^z)\\) are the spin \\(S=1/2\\) operators and \\(\\langle i,j \\rangle\\) denotes summation over nearest-meighbor sites \\(i\\) and \\(j\\).
The following code, sets up the Hilbert space, defines the Hamiltonian and finally calls an iterative eigenvalue solver to compute the ground state energy.
JuliaC++
using XDiag\n\nlet \n N = 16;\n nup = N \u00f7 2;\n block = Spinhalf(N, nup);\n\n # Define the nearest-neighbor Heisenberg model\n bonds = BondList()\n for i in 1:N\n bonds += Bond(\"HB\", \"J\", [i-1, i % N])\n end\n bonds[\"J\"] = 1.0;\n\n set_verbosity(2); # set verbosity for monitoring progress\n e0 = eigval0(bonds, block); # compute ground state energy\n\n println(\"Ground state energy: $e0\");\nend\n
#include <xdiag/all.hpp>\n\nusing namespace xdiag;\n\nint main() try {\n int N = 16;\n int nup = N / 2;\n Spinhalf block(N, nup);\n\n // Define the nearest-neighbor Heisenberg model\n OpSum ops;\n for (int i = 0; i < N; ++i) {\n ops += Op(\"HB\", \"J\", {i, (i + 1) % N});\n }\n ops[\"J\"] = 1.0;\n\n set_verbosity(2); // set verbosity for monitoring progress\n double e0 = eigval0(ops, block); // compute ground state energy\n\n Log(\"Ground state energy: {:.12f}\", e0);\n\n} catch (Error e) {\n error_trace(e);\n}\n
"},{"location":"documentation/","title":"Documentation","text":""},{"location":"documentation/#algorithms","title":"Algorithms","text":"Name Description Language eigval0 Computes the lowest lying eigenvalue of an operator eig0 Computes the lowest lying eigenvalue and eigenvector of an operator"},{"location":"documentation/#algebra","title":"Algebra","text":"matrix Creates the full matrix representation of an operator on a block"},{"location":"documentation/#blocks","title":"Blocks","text":"Spinhalf Block of a spin \\(S=1/2\\) type Hilbert space tJ Block of a \\(t-J\\) type Hilbert space Electron Block of a Electron type Hilbert space"},{"location":"documentation/#operators","title":"Operators","text":"Op A local operator acting on several lattice sites OpSum Sum of local operators Coupling Describes the coupling of a local operator"},{"location":"documentation/#states","title":"States","text":"State A generic state describing a quantum wave function"},{"location":"documentation/#symmetries","title":"Symmetries","text":"Permutation Permutations of indices or lattice sites PermutationGroup A group of permutations Representation A (1D) irreducible representation of a finite group"},{"location":"documentation/#utilities","title":"Utilities","text":"Logging Controling what is written to standard output Timing Measurng wall time straightforwardly XDIAG_SHOW Macro for printing debugging information"},{"location":"documentation/algebra/matrix/","title":"matrix","text":"
matrix(bondlist, block; force_complex=false)\nmatrixC(bondlist, block) # c++ only\n
Creates the full matrix representation of a given BondList on a block.
In Julia, depending on whether a real/complex matrix is generated also a real/complex matrix is returned. The C++ version has to return a fixed type. If a real matrix is desired, use the function matrix. If a complex matrix is desired, use the function matrixC.
Source matrix.hpp
"},{"location":"documentation/algebra/matrix/#parameters","title":"Parameters","text":"Name Description bondlist BondList defining the bonds of the operator block block on which the operator is defined force_complex flag to determine if returned matrix is forced to be complex (Julia only)"},{"location":"documentation/algebra/matrix/#returns","title":"Returns","text":"Type Description matrix matrix representation of bondlist on block"},{"location":"documentation/algebra/matrix/#definition","title":"Definition","text":"JuliaC++
Computes the groud state energy and the ground state of an operator on a block.
Source sparse_diag.hpp
"},{"location":"documentation/algorithms/eig0/#parameters","title":"Parameters","text":"Name Description Default bondlist BondList defining the bonds of the operator block block on which the operator is defined precision accuracy of the computed ground state 1e-12 max_iterations maximum number of iterations 1000 force_complex whether or not computation should be forced to have complex arithmetic false random_seed random seed for setting up the initial vector 42"},{"location":"documentation/algorithms/eig0/#returns","title":"Returns","text":"Type Description real number lowest lying eigenvalue State groundstate"},{"location":"documentation/algorithms/eig0/#definition","title":"Definition","text":"JuliaC++
Computes the groud state energy of an operator on a block.
Source sparse_diag.hpp
"},{"location":"documentation/algorithms/eigval0/#parameters","title":"Parameters","text":"Name Description Default bondlist BondList defining the bonds of the operator block block on which the operator is defined precision accuracy of the computed ground state 1e-12 max_iterations maximum number of iterations 1000 force_complex whether or not computation should be forced to have complex arithmetic false random_seed random seed for setting up the initial vector 42"},{"location":"documentation/algorithms/eigval0/#returns","title":"Returns","text":"Type Description real number lowest lying eigenvalue"},{"location":"documentation/algorithms/eigval0/#definition","title":"Definition","text":"JuliaC++
Name Description n_sites number of sites (integer) n_up number of \"up\" electrons (integer) n_dn number of \"dn\" electrons (integer) group PermutationGroup defining the permutation symmetries irrep Irreducible Representation of the symmetry group"},{"location":"documentation/blocks/electron/#methods","title":"Methods","text":"
n_sites
Returns the number of sites of the block.
JuliaC++
n_sites(block::Electron)\n
int64_t n_sites() const\n
size
Returns the size of the block, i.e. its dimension.
JuliaC++
size(block::Electron)\n
int64_t size() const;\n
isreal
Returns whether the block can be used with real arithmetic. Complex arithmetic is needed when a Representation is genuinely complex.
Name Description n_sites number of sites (integer) n_up number of \"up\" spin setting spin (integer) group PermutationGroup defining the permutation symmetries irrep Irreducible Representation of the symmetry group"},{"location":"documentation/blocks/spinhalf/#methods","title":"Methods","text":"
n_sites
Returns the number of sites of the block.
JuliaC++
n_sites(block::Spinhalf)\n
int64_t n_sites() const\n
dim
Returns the dimension of the block.
JuliaC++
dim(block::Spinhalf)\n
int64_t dim() const;\n
size
Returns the size of the block locally. Same as \"dim\" for non-distributed Blocks but different for distributed blocks.
JuliaC++
size(block::Spinhalf)\n
int64_t size() const;\n
isreal
Returns whether the block can be used with real arithmetic. Complex arithmetic is needed when a Representation is genuinely complex.
Name Description n_sites number of sites (integer) n_up number of \"up\" electrons (integer) n_dn number of \"dn\" electrons (integer) group PermutationGroup defining the permutation symmetries irrep Irreducible Representation of the symmetry group"},{"location":"documentation/blocks/tJ/#methods","title":"Methods","text":"
n_sites
Returns the number of sites of the block.
JuliaC++
n_sites(block::tJ)\n
int64_t n_sites() const\n
size
Returns the size of the block, i.e. its dimension.
JuliaC++
size(block::tJ)\n
int64_t size() const;\n
isreal
Returns whether the block can be used with real arithmetic. Complex arithmetic is needed when a Representation is genuinely complex.
Describes the coupling of a local operator. A coupling can either be a string, a real/complex number or even a real/complex matrix. It allows for converting to real/complex numbers or matrices as well as strings, whenever this conversion is sensible.
Returns the type of the Coupling, i.e. a string which either reads \"string\", \"double\", \"complex\", \"mat\", or \"cx_mat\"
JuliaC++
type(cpl::Coupling)\n
std::string type() const;\n
isreal
Returns whether or not the coupling is real. Throws an error if the coupling is given as a string, since then it cannot be determined whether the operator is real.
JuliaC++
isreal(cpl::Coupling)\n
bool isreal() const;\n
ismatrix
Returns whether or not the coupling is defined as a matrix. Throws an error if the coupling is given as a string, since then it cannot be determined whether the operator is real.
JuliaC++
ismatrix(cpl::Coupling)\n
bool ismatrix() const;\n
isexplicit
Returns false if the coupling is defined as a string, otherwise true
A Coupling can be converted to the values it represents, so a string, real/complex number or a real/complex matrix. Initially real values can be cast to complex.
Parameter Description type a string which denotes what kind of operator is represented 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.
The coupling can take on several types and allow some flexibility in defining operators.
type Description string the coupling is represented as a string, e.g. \"\\(t\\)\" or \"\\(J\\)\" in a \\(t-J\\) model real/cplx number the actual numerical value of the coupling real/cplx matrix more generic interactions can be specified as matrices"},{"location":"documentation/operators/op/#methods","title":"Methods","text":"
type
Returns the type of the operator
JuliaC++
type(op::Op)\n
std::string type() const;\n
coupling
Returns the coupling of the operator
JuliaC++
coupling(op::Op)\n
Coupling const &coupling() const;\n
This returns an object of type Coupling, which can then be converted to an appropriate type.
size
Returns how many sites the operator is defined on
JuliaC++
size(op::Op)\n
int64_t size() const;\n
getindex / operator[]
Returns the site with the given index.
JuliaC++
getindex(op::Op, idx::Int64)\n
int64_t operator[](int64_t idx) const;\n
sites
Returns all the sites the operator is defined on
JuliaC++
sites(op::Op)\n
std::vector<int64_t> const &sites() const;\n
isreal
Returns whether or not the coupling is real. Throws an error if the coupling is given as a string, since then it cannot be determined whether the operator is real.
JuliaC++
isreal(op::Op)\n
bool isreal() const;\n
ismatrix
Returns whether or not the coupling is defined as a matrix. Throws an error if the coupling is given as a string, since then it cannot be determined whether the operator is real.
JuliaC++
ismatrix(op::Op)\n
bool ismatrix() const;\n
isexplicit
Returns false if the coupling is defined as a string, otherwise true
Parameter Description ops a vector of Op objects describing the operators summed over"},{"location":"documentation/operators/opsum/#methods","title":"Methods","text":"
size
Returns the number of local Op operators.
JuliaC++
size(ops::OpSum)\n
int64_t size() const;\n
defined
Returns bool whether a coupling (of type string) is defined
JuliaC++
defined(ops::OpSum, name::String)\n
bool defined(std::string name) const;\n
setindex! / operator[]
Sets a coupling given as a string to a certain numerical value or matrix
JuliaC++
Base.setindex!(ops::OpSum, cpl, name::String)\n
Coupling &operator[](std::string name);\n
getindex / operator[]
Returns the value of a Coupling defined as a string.
Parameter Description block The block of a Hilbertspace on which the state is defined real Flag whether or not the state has real coefficients n_cols Number of columns of the state (default 1) vector A vector containing the coefficients of the state. Must be same size as block. matrix A matrix containing the coefficients of the state. Number of rows must be same as block size ."},{"location":"documentation/states/state/#methods","title":"Methods","text":"
n_sites
Returns the number of sites of the block the state is defined on.
JuliaC++
n_sites(state::State)\n
int64_t n_sites() const\n
isreal
Returns whether the state is real.
JuliaC++
isreal(state::State)\n
int64_t isreal() const;\n
real
Returns whether the real part of the State.
JuliaC++
real(state::State)\n
State real() const;\n
imag
Returns whether the imaginary part of the State.
JuliaC++
imag(state::State)\n
State imag() const;\n
make_complex! / make_complex
Turns a real State into a complex State. Does nothing if the state is already complex
JuliaC++
make_complex!(state::State)\n
void make_complex();\n
dim
Returns the dimension of the block the state is defined on.
JuliaC++
dim(block::Spinhalf)\n
int64_t dim() const;\n
size
Returns the size of the block the state is defined on. locally. Same as \"dim\" for non-distributed Blocks but different for distributed blocks.
JuliaC++
size(block::Spinhalf)\n
int64_t size() const;\n
n_rows
Returns number of rows of the local storage. Same as \"size\"
JuliaC++
n_rows(block::Spinhalf)\n
int64_t n_rows() const;\n
n_cols
Returns number of columns of the local storage.
JuliaC++
n_cols(block::Spinhalf)\n
int64_t n_cols() const;\n
col
Returns a state created from the n-th column of the storage. Whether or not the storage is copied can be specified by setting the flag \"copy\".
Creates an Permutation out of an array of integers, e.g. [0, 2, 1, 3]. If the input array is of size N then every number between 0 and N-1 must occur exactly once, otherwise the Permutation is invalid.
"},{"location":"documentation/utilities/logging/","title":"Logging","text":""},{"location":"documentation/utilities/logging/#setting-the-verbosity","title":"Setting the verbosity","text":"
Algorithms implemented in XDiag do not output anything during their execution by default. However, it is typically useful to get some information on how the code is performing and even intermediary results at runtime. For this, the verbosity of the internal XDiag logging can be set using the function set_verbosity, which is defined as
JuliaC++
set_verbosity(level::Integer);\n
void set_verbosity(int64_t level);\n
There are several levels of verbosity, defining how much information is shown.
level outputed information 0 no information 1 some information 2 detailed information
For example, when computing a ground state energy using the eigval0 function, we can set a higher verbosity level using
Producing nicely formatted output is unfortunately a bit cumbersome in standard C++. For this, the Log mechanism in XDiag can help. To simply write out a line of information you can call,
Log(\"hello from the logger\");\n
By default, a new line is added. It is also possible to set verbosity by handing the level as the first argument,
Log(2, \"hello from the logger only if global verbosity is set to >= 2\");\n
This message will only appear if the global verbosity level is set to a value \\(\\geq 2\\). Finally, XDiag also supports formatted output by using the fmtlib. For example, numbers can be formated this way
Log(\"pi is around {:.4f} and the answer is {}\", 3.141592, 42);\n
A timing (in second) between two time points can be written to output using
timing(begin, end);\n
This can even be accompanied by a message about what is being timed and a verbosity level (see Logging) can also be set. The full call signature is
timing(begin, end, message, level);\n
Name Description Default begin starting time computed using rightnow() end end time computed using rightnow() message message string to be prepended to timing \"\" level verbosity level at which timing is printed 0"},{"location":"documentation/utilities/xdiag_show/","title":"Debug printing","text":"
For quick debugging in C++, XDiag features a simple macro which outputs the name and content of a variable calles XDIAG_SHOW(x). For example
using XDiag\n\nlet \n N = 16;\n nup = N \u00f7 2;\n block = Spinhalf(N, nup);\n\n # Define the nearest-neighbor Heisenberg model\n bonds = BondList()\n for i in 1:N\n bonds += Bond(\"HB\", \"J\", [i-1, i % N])\n end\n bonds[\"J\"] = 1.0;\n\n set_verbosity(2); # set verbosity for monitoring progress\n e0 = eigval0(bonds, block); # compute ground state energy\n\n println(\"Ground state energy: $e0\");\nend\n
#include <xdiag/all.hpp>\n\nusing namespace xdiag;\n\nint main() try {\n int N = 16;\n int nup = N / 2;\n Spinhalf block(N, nup);\n\n // Define the nearest-neighbor Heisenberg model\n OpSum ops;\n for (int i = 0; i < N; ++i) {\n ops += Op(\"HB\", \"J\", {i, (i + 1) % N});\n }\n ops[\"J\"] = 1.0;\n\n set_verbosity(2); // set verbosity for monitoring progress\n double e0 = eigval0(ops, block); // compute ground state energy\n\n Log(\"Ground state energy: {:.12f}\", e0);\n\n} catch (Error e) {\n error_trace(e);\n}\n
"},{"location":"examples/tj_distributed_time_evolve/","title":"\\(t\\)-\\(J\\) distributed time evolution","text":"
#include <xdiag/all.hpp>\n\nusing namespace xdiag;\n\nvoid measure_density(int n_sites, State const &v) {\n int rank;\n MPI_Comm_rank(MPI_COMM_WORLD, &rank);\n for (int i = 0; i < n_sites; ++i) {\n complex sz = innerC(Bond(\"NUMBER\", i), v);\n if (rank == 0) {\n printf(\"%.6f \", std::real(sz));\n }\n }\n if (rank == 0) {\n printf(\"\\n\");\n }\n}\n\nint main(int argc, char **argv) try {\n MPI_Init(&argc, &argv);\n\n int L = 6;\n int W = 4;\n double t = 1.0;\n double J = 0.1;\n double mu_0 = 10;\n\n int n_sites = L * W;\n double precision = 1e-12;\n\n // Create square lattice t-J model\n OpSum ops;\n for (int x = 0; x < L-1; ++x) {\n for (int y = 0; y < W; ++y) {\n int nx = (x + 1) % L;\n int ny = (y + 1) % W;\n\n int site = x * W + y;\n int right = nx * W + y;\n int top = x * W + ny;\n ops += Op(\"HOP\", \"T\", {site, right});\n ops += Op(\"EXCHANGE\", \"J\", {site, right});\n ops += Op(\"HOP\", \"T\", {site, top});\n ops += Op(\"EXCHANGE\", \"J\", {site, top});\n\n\n\n if (x < L / 2) {\n Log(\"x {} y {} site {} t {} r {} +\", x, y, site, top, right);\n ops += Op(\"NUMBER\", \"MUPLUS\", site);\n } else {\n Log(\"x {} y {} site {} t {} r {} -\", x, y, site, top, right);\n ops += Op(\"NUMBER\", \"MUNEG\", site);\n }\n }\n }\n ops[\"T\"] = t;\n ops[\"J\"] = J;\n ops[\"MUPLUS\"] = mu_0;\n ops[\"MUNEG\"] = mu_0;\n\n auto block = tJDistributed(n_sites, n_sites / 2 - 1, n_sites / 2 - 1);\n\n XDIAG_SHOW(block);\n\n Log.set_verbosity(2);\n tic();\n auto [e0, v] = eig0(ops, block);\n toc(\"gs\");\n\n ops[\"MUPLUS\"] = 0;\n ops[\"MUNEG\"] = 0;\n\n measure_density(n_sites, v);\n\n // Do the time evolution with a step size tau\n double tau = 0.1;\n for (int i = 0; i < 40; ++i) {\n tic();\n v = time_evolve(ops, v, tau, precision);\n toc(\"time evolve\");\n tic();\n measure_density(n_sites, v);\n toc(\"measure\");\n }\n\n MPI_Finalize();\n return EXIT_SUCCESS;\n} catch (std::exception const &e) {\n traceback(e);\n}\n
"}]}
\ No newline at end of file
+{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":"
XDiag is a C++ library for performing Exact Diagonalizations of quantum many-body systems. Key features include optimized combinatorical algorithms for navigating Hilbert spaces, iterative linear algebra algorithms, shared and distributed memory parallelization.
Using XDiag with C++ is a two-step process. First the xdiag library needs to be compiled and installed. Therafter, application codes are compiled in a second step. Here we explain how to compile the library.
The source files for the documentation can be found in the directory docs. The documentation is built using Material for MKDocs. To work on it locally, it can be served using
mkdocs serve\n
from the xdiag root source directory. A local build of the documentation can then be accessed in a webbrowser at the adress
The function say_hello() prints out a welcome message, which also contains information which exact XDiag version is used. In Julia this is all there is to it.
For the C++ code we need to create two files to compile the program. The first is the actual C++ code. What is maybe a bit unfamiliar is the try / catch block. XDiag implements a traceback mechanism for runtime errors, which is activated by this idiom. While not stricly necessary here, it is a good practice to make use of this.
Now that the application program is written, we next need to set up the compilation instructions using CMake. To do so we create a second file called CMakeLists.txt in the same directory.
You should replace \"/path/to/xdiag/install\" with the appropriate directory where your XDiag library is installed after compilation. This exact CMakeLists.txt file can be used to compile any XDiag application.
Info
For using the distributed XDiag library the last line of the above CMakeLists.txt should be changed to
target_link_libraries(main PUBLIC xdiag::xdiag_distributed)\n
We then compile the application code,
cmake -S . -B build\ncmake --build build\n
and finally run our first xdiag application.
./build/main\n
"},{"location":"quickstart/#computing-the-ground-state-energy-of-a-spin-chain","title":"Computing the ground state energy of a spin chain","text":"
We compute the ground state energy of the \\(S=1/2\\) Heisenberg chain on a periodic chain lattice in one dimension. The Hamiltonian is given by
\\[ H = J\\sum_{\\langle i,j \\rangle} \\mathbf{S}_i \\cdot \\mathbf{S}_j\\]
where \\(\\mathbf{S}_i = (S_i^x, S_i^y, S_i^z)\\) are the spin \\(S=1/2\\) operators and \\(\\langle i,j \\rangle\\) denotes summation over nearest-meighbor sites \\(i\\) and \\(j\\).
The following code, sets up the Hilbert space, defines the Hamiltonian and finally calls an iterative eigenvalue solver to compute the ground state energy.
JuliaC++
using XDiag\n\nlet \n N = 16;\n nup = N \u00f7 2;\n block = Spinhalf(N, nup);\n\n # Define the nearest-neighbor Heisenberg model\n bonds = BondList()\n for i in 1:N\n bonds += Bond(\"HB\", \"J\", [i-1, i % N])\n end\n bonds[\"J\"] = 1.0;\n\n set_verbosity(2); # set verbosity for monitoring progress\n e0 = eigval0(bonds, block); # compute ground state energy\n\n println(\"Ground state energy: $e0\");\nend\n
#include <xdiag/all.hpp>\n\nusing namespace xdiag;\n\nint main() try {\n int N = 16;\n int nup = N / 2;\n Spinhalf block(N, nup);\n\n // Define the nearest-neighbor Heisenberg model\n OpSum ops;\n for (int i = 0; i < N; ++i) {\n ops += Op(\"HB\", \"J\", {i, (i + 1) % N});\n }\n ops[\"J\"] = 1.0;\n\n set_verbosity(2); // set verbosity for monitoring progress\n double e0 = eigval0(ops, block); // compute ground state energy\n\n Log(\"Ground state energy: {:.12f}\", e0);\n\n} catch (Error e) {\n error_trace(e);\n}\n
"},{"location":"documentation/","title":"Documentation","text":""},{"location":"documentation/#algorithms","title":"Algorithms","text":"Name Description Language eigval0 Computes the lowest lying eigenvalue of an operator eig0 Computes the lowest lying eigenvalue and eigenvector of an operator"},{"location":"documentation/#algebra","title":"Algebra","text":"matrix Creates the full matrix representation of an operator on a block"},{"location":"documentation/#blocks","title":"Blocks","text":"Spinhalf Block of a spin \\(S=1/2\\) type Hilbert space tJ Block of a \\(t-J\\) type Hilbert space Electron Block of a Electron type Hilbert space"},{"location":"documentation/#operators","title":"Operators","text":"Op A local operator acting on several lattice sites OpSum Sum of local operators Coupling Describes the coupling of a local operator"},{"location":"documentation/#states","title":"States","text":"State A generic state describing a quantum wave function ProductState A product state of local configurations"},{"location":"documentation/#symmetries","title":"Symmetries","text":"Permutation Permutations of indices or lattice sites PermutationGroup A group of permutations Representation A (1D) irreducible representation of a finite group"},{"location":"documentation/#utilities","title":"Utilities","text":"Logging Controling what is written to standard output Timing Measurng wall time straightforwardly XDIAG_SHOW Macro for printing debugging information"},{"location":"documentation/algebra/matrix/","title":"matrix","text":"
matrix(bondlist, block; force_complex=false)\nmatrixC(bondlist, block) # c++ only\n
Creates the full matrix representation of a given BondList on a block.
In Julia, depending on whether a real/complex matrix is generated also a real/complex matrix is returned. The C++ version has to return a fixed type. If a real matrix is desired, use the function matrix. If a complex matrix is desired, use the function matrixC.
Source matrix.hpp
"},{"location":"documentation/algebra/matrix/#parameters","title":"Parameters","text":"Name Description bondlist BondList defining the bonds of the operator block block on which the operator is defined force_complex flag to determine if returned matrix is forced to be complex (Julia only)"},{"location":"documentation/algebra/matrix/#returns","title":"Returns","text":"Type Description matrix matrix representation of bondlist on block"},{"location":"documentation/algebra/matrix/#definition","title":"Definition","text":"JuliaC++
Computes the groud state energy and the ground state of an operator on a block.
Source sparse_diag.hpp
"},{"location":"documentation/algorithms/eig0/#parameters","title":"Parameters","text":"Name Description Default bondlist BondList defining the bonds of the operator block block on which the operator is defined precision accuracy of the computed ground state 1e-12 max_iterations maximum number of iterations 1000 force_complex whether or not computation should be forced to have complex arithmetic false random_seed random seed for setting up the initial vector 42"},{"location":"documentation/algorithms/eig0/#returns","title":"Returns","text":"Type Description real number lowest lying eigenvalue State groundstate"},{"location":"documentation/algorithms/eig0/#definition","title":"Definition","text":"JuliaC++
Computes the groud state energy of an operator on a block.
Source sparse_diag.hpp
"},{"location":"documentation/algorithms/eigval0/#parameters","title":"Parameters","text":"Name Description Default bondlist BondList defining the bonds of the operator block block on which the operator is defined precision accuracy of the computed ground state 1e-12 max_iterations maximum number of iterations 1000 force_complex whether or not computation should be forced to have complex arithmetic false random_seed random seed for setting up the initial vector 42"},{"location":"documentation/algorithms/eigval0/#returns","title":"Returns","text":"Type Description real number lowest lying eigenvalue"},{"location":"documentation/algorithms/eigval0/#definition","title":"Definition","text":"JuliaC++
Name Description n_sites number of sites (integer) n_up number of \"up\" electrons (integer) n_dn number of \"dn\" electrons (integer) group PermutationGroup defining the permutation symmetries irrep Irreducible Representation of the symmetry group"},{"location":"documentation/blocks/electron/#methods","title":"Methods","text":"
n_sites
Returns the number of sites of the block.
JuliaC++
n_sites(block::Electron)\n
int64_t n_sites() const\n
size
Returns the size of the block, i.e. its dimension.
JuliaC++
size(block::Electron)\n
int64_t size() const;\n
isreal
Returns whether the block can be used with real arithmetic. Complex arithmetic is needed when a Representation is genuinely complex.
Name Description n_sites number of sites (integer) n_up number of \"up\" spin setting spin (integer) group PermutationGroup defining the permutation symmetries irrep Irreducible Representation of the symmetry group"},{"location":"documentation/blocks/spinhalf/#methods","title":"Methods","text":"
n_sites
Returns the number of sites of the block.
JuliaC++
n_sites(block::Spinhalf)\n
int64_t n_sites() const\n
dim
Returns the dimension of the block.
JuliaC++
dim(block::Spinhalf)\n
int64_t dim() const;\n
size
Returns the size of the block locally. Same as \"dim\" for non-distributed Blocks but different for distributed blocks.
JuliaC++
size(block::Spinhalf)\n
int64_t size() const;\n
isreal
Returns whether the block can be used with real arithmetic. Complex arithmetic is needed when a Representation is genuinely complex.
Name Description n_sites number of sites (integer) n_up number of \"up\" electrons (integer) n_dn number of \"dn\" electrons (integer) group PermutationGroup defining the permutation symmetries irrep Irreducible Representation of the symmetry group"},{"location":"documentation/blocks/tJ/#methods","title":"Methods","text":"
n_sites
Returns the number of sites of the block.
JuliaC++
n_sites(block::tJ)\n
int64_t n_sites() const\n
size
Returns the size of the block, i.e. its dimension.
JuliaC++
size(block::tJ)\n
int64_t size() const;\n
isreal
Returns whether the block can be used with real arithmetic. Complex arithmetic is needed when a Representation is genuinely complex.
Describes the coupling of a local operator. A coupling can either be a string, a real/complex number or even a real/complex matrix. It allows for converting to real/complex numbers or matrices as well as strings, whenever this conversion is sensible.
Returns the type of the Coupling, i.e. a string which either reads \"string\", \"double\", \"complex\", \"mat\", or \"cx_mat\"
JuliaC++
type(cpl::Coupling)\n
std::string type() const;\n
isreal
Returns whether or not the coupling is real. Throws an error if the coupling is given as a string, since then it cannot be determined whether the operator is real.
JuliaC++
isreal(cpl::Coupling)\n
bool isreal() const;\n
ismatrix
Returns whether or not the coupling is defined as a matrix. Throws an error if the coupling is given as a string, since then it cannot be determined whether the operator is real.
JuliaC++
ismatrix(cpl::Coupling)\n
bool ismatrix() const;\n
isexplicit
Returns false if the coupling is defined as a string, otherwise true
A Coupling can be converted to the values it represents, so a string, real/complex number or a real/complex matrix. Initially real values can be cast to complex.
Parameter Description type a string which denotes what kind of operator is represented 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.
The coupling can take on several types and allow some flexibility in defining operators.
type Description string the coupling is represented as a string, e.g. \"\\(t\\)\" or \"\\(J\\)\" in a \\(t-J\\) model real/cplx number the actual numerical value of the coupling real/cplx matrix more generic interactions can be specified as matrices"},{"location":"documentation/operators/op/#methods","title":"Methods","text":"
type
Returns the type of the operator
JuliaC++
type(op::Op)\n
std::string type() const;\n
coupling
Returns the coupling of the operator
JuliaC++
coupling(op::Op)\n
Coupling const &coupling() const;\n
This returns an object of type Coupling, which can then be converted to an appropriate type.
size
Returns how many sites the operator is defined on
JuliaC++
size(op::Op)\n
int64_t size() const;\n
getindex / operator[]
Returns the site with the given index.
JuliaC++
getindex(op::Op, idx::Int64)\n
int64_t operator[](int64_t idx) const;\n
sites
Returns all the sites the operator is defined on
JuliaC++
sites(op::Op)\n
std::vector<int64_t> const &sites() const;\n
isreal
Returns whether or not the coupling is real. Throws an error if the coupling is given as a string, since then it cannot be determined whether the operator is real.
JuliaC++
isreal(op::Op)\n
bool isreal() const;\n
ismatrix
Returns whether or not the coupling is defined as a matrix. Throws an error if the coupling is given as a string, since then it cannot be determined whether the operator is real.
JuliaC++
ismatrix(op::Op)\n
bool ismatrix() const;\n
isexplicit
Returns false if the coupling is defined as a string, otherwise true
Parameter Description ops a vector of Op objects describing the operators summed over"},{"location":"documentation/operators/opsum/#methods","title":"Methods","text":"
size
Returns the number of local Op operators.
JuliaC++
size(ops::OpSum)\n
int64_t size() const;\n
defined
Returns bool whether a coupling (of type string) is defined
JuliaC++
defined(ops::OpSum, name::String)\n
bool defined(std::string name) const;\n
setindex! / operator[]
Sets a coupling given as a string to a certain numerical value or matrix
JuliaC++
Base.setindex!(ops::OpSum, cpl, name::String)\n
Coupling &operator[](std::string name);\n
getindex / operator[]
Returns the value of a Coupling defined as a string.
Parameter Description n_sites construct a product state on n_sites local_states the local configurations of the product state"},{"location":"documentation/states/product_state/#iteration","title":"Iteration","text":"
A Product state can be iterated over, where at each iteration the string of the local configuration is retured. Here is an example:
JuliaC++
pstate = ProductState([\"Up\", \"Dn\", \"Emp\", \"UpDn\"])\nfor s in pstate\n @show s\nend\n
auto pstate = ProductState({\"Up\", \"Dn\", \"Emp\", \"UpDn\"});\nfor (auto s : pstate) {\n Log(\"{}\", s);\n}\n
Parameter Description block The block of a Hilbertspace on which the state is defined real Flag whether or not the state has real coefficients n_cols Number of columns of the state (default 1) vector A vector containing the coefficients of the state. Must be same size as block. matrix A matrix containing the coefficients of the state. Number of rows must be same as block size ."},{"location":"documentation/states/state/#methods","title":"Methods","text":"
n_sites
Returns the number of sites of the block the state is defined on.
JuliaC++
n_sites(state::State)\n
int64_t n_sites() const\n
isreal
Returns whether the state is real.
JuliaC++
isreal(state::State)\n
int64_t isreal() const;\n
real
Returns whether the real part of the State.
JuliaC++
real(state::State)\n
State real() const;\n
imag
Returns whether the imaginary part of the State.
JuliaC++
imag(state::State)\n
State imag() const;\n
make_complex! / make_complex
Turns a real State into a complex State. Does nothing if the state is already complex
JuliaC++
make_complex!(state::State)\n
void make_complex();\n
dim
Returns the dimension of the block the state is defined on.
JuliaC++
dim(block::Spinhalf)\n
int64_t dim() const;\n
size
Returns the size of the block the state is defined on. locally. Same as \"dim\" for non-distributed Blocks but different for distributed blocks.
JuliaC++
size(block::Spinhalf)\n
int64_t size() const;\n
n_rows
Returns number of rows of the local storage. Same as \"size\"
JuliaC++
n_rows(block::Spinhalf)\n
int64_t n_rows() const;\n
n_cols
Returns number of columns of the local storage.
JuliaC++
n_cols(block::Spinhalf)\n
int64_t n_cols() const;\n
col
Returns a state created from the n-th column of the storage. Whether or not the storage is copied can be specified by setting the flag \"copy\".
Creates an Permutation out of an array of integers, e.g. [0, 2, 1, 3]. If the input array is of size N then every number between 0 and N-1 must occur exactly once, otherwise the Permutation is invalid.
"},{"location":"documentation/utilities/logging/","title":"Logging","text":""},{"location":"documentation/utilities/logging/#setting-the-verbosity","title":"Setting the verbosity","text":"
Algorithms implemented in XDiag do not output anything during their execution by default. However, it is typically useful to get some information on how the code is performing and even intermediary results at runtime. For this, the verbosity of the internal XDiag logging can be set using the function set_verbosity, which is defined as
JuliaC++
set_verbosity(level::Integer);\n
void set_verbosity(int64_t level);\n
There are several levels of verbosity, defining how much information is shown.
level outputed information 0 no information 1 some information 2 detailed information
For example, when computing a ground state energy using the eigval0 function, we can set a higher verbosity level using
Producing nicely formatted output is unfortunately a bit cumbersome in standard C++. For this, the Log mechanism in XDiag can help. To simply write out a line of information you can call,
Log(\"hello from the logger\");\n
By default, a new line is added. It is also possible to set verbosity by handing the level as the first argument,
Log(2, \"hello from the logger only if global verbosity is set to >= 2\");\n
This message will only appear if the global verbosity level is set to a value \\(\\geq 2\\). Finally, XDiag also supports formatted output by using the fmtlib. For example, numbers can be formated this way
Log(\"pi is around {:.4f} and the answer is {}\", 3.141592, 42);\n
A timing (in second) between two time points can be written to output using
timing(begin, end);\n
This can even be accompanied by a message about what is being timed and a verbosity level (see Logging) can also be set. The full call signature is
timing(begin, end, message, level);\n
Name Description Default begin starting time computed using rightnow() end end time computed using rightnow() message message string to be prepended to timing \"\" level verbosity level at which timing is printed 0"},{"location":"documentation/utilities/xdiag_show/","title":"Debug printing","text":"
For quick debugging in C++, XDiag features a simple macro which outputs the name and content of a variable calles XDIAG_SHOW(x). For example
using XDiag\n\nlet \n N = 16;\n nup = N \u00f7 2;\n block = Spinhalf(N, nup);\n\n # Define the nearest-neighbor Heisenberg model\n bonds = BondList()\n for i in 1:N\n bonds += Bond(\"HB\", \"J\", [i-1, i % N])\n end\n bonds[\"J\"] = 1.0;\n\n set_verbosity(2); # set verbosity for monitoring progress\n e0 = eigval0(bonds, block); # compute ground state energy\n\n println(\"Ground state energy: $e0\");\nend\n
#include <xdiag/all.hpp>\n\nusing namespace xdiag;\n\nint main() try {\n int N = 16;\n int nup = N / 2;\n Spinhalf block(N, nup);\n\n // Define the nearest-neighbor Heisenberg model\n OpSum ops;\n for (int i = 0; i < N; ++i) {\n ops += Op(\"HB\", \"J\", {i, (i + 1) % N});\n }\n ops[\"J\"] = 1.0;\n\n set_verbosity(2); // set verbosity for monitoring progress\n double e0 = eigval0(ops, block); // compute ground state energy\n\n Log(\"Ground state energy: {:.12f}\", e0);\n\n} catch (Error e) {\n error_trace(e);\n}\n
"},{"location":"examples/tj_distributed_time_evolve/","title":"\\(t\\)-\\(J\\) distributed time evolution","text":"
#include <xdiag/all.hpp>\n\nusing namespace xdiag;\n\nvoid measure_density(int n_sites, State const &v) {\n int rank;\n MPI_Comm_rank(MPI_COMM_WORLD, &rank);\n for (int i = 0; i < n_sites; ++i) {\n complex sz = innerC(Bond(\"NUMBER\", i), v);\n if (rank == 0) {\n printf(\"%.6f \", std::real(sz));\n }\n }\n if (rank == 0) {\n printf(\"\\n\");\n }\n}\n\nint main(int argc, char **argv) try {\n MPI_Init(&argc, &argv);\n\n int L = 6;\n int W = 4;\n double t = 1.0;\n double J = 0.1;\n double mu_0 = 10;\n\n int n_sites = L * W;\n double precision = 1e-12;\n\n // Create square lattice t-J model\n OpSum ops;\n for (int x = 0; x < L-1; ++x) {\n for (int y = 0; y < W; ++y) {\n int nx = (x + 1) % L;\n int ny = (y + 1) % W;\n\n int site = x * W + y;\n int right = nx * W + y;\n int top = x * W + ny;\n ops += Op(\"HOP\", \"T\", {site, right});\n ops += Op(\"EXCHANGE\", \"J\", {site, right});\n ops += Op(\"HOP\", \"T\", {site, top});\n ops += Op(\"EXCHANGE\", \"J\", {site, top});\n\n\n\n if (x < L / 2) {\n Log(\"x {} y {} site {} t {} r {} +\", x, y, site, top, right);\n ops += Op(\"NUMBER\", \"MUPLUS\", site);\n } else {\n Log(\"x {} y {} site {} t {} r {} -\", x, y, site, top, right);\n ops += Op(\"NUMBER\", \"MUNEG\", site);\n }\n }\n }\n ops[\"T\"] = t;\n ops[\"J\"] = J;\n ops[\"MUPLUS\"] = mu_0;\n ops[\"MUNEG\"] = mu_0;\n\n auto block = tJDistributed(n_sites, n_sites / 2 - 1, n_sites / 2 - 1);\n\n XDIAG_SHOW(block);\n\n Log.set_verbosity(2);\n tic();\n auto [e0, v] = eig0(ops, block);\n toc(\"gs\");\n\n ops[\"MUPLUS\"] = 0;\n ops[\"MUNEG\"] = 0;\n\n measure_density(n_sites, v);\n\n // Do the time evolution with a step size tau\n double tau = 0.1;\n for (int i = 0; i < 40; ++i) {\n tic();\n v = time_evolve(ops, v, tau, precision);\n toc(\"time evolve\");\n tic();\n measure_density(n_sites, v);\n toc(\"measure\");\n }\n\n MPI_Finalize();\n return EXIT_SUCCESS;\n} catch (std::exception const &e) {\n traceback(e);\n}\n
"}]}
\ No newline at end of file
diff --git a/sitemap.xml.gz b/sitemap.xml.gz
index 19983be9..ae42d86f 100644
Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ