State
The State class provides a primitive container to store and manipulate a product state of qudits:
Each site is represented by a local Hilbert space \(\vert\sigma_i\rangle=\vert 0\rangle,\,\vert 1\rangle\dots\vert Q-1\rangle\) of dimension \(Q\). If you think about spins: \(Q=2S+1\) for \(S=\frac{1}{2},1,\frac{3}{2},\dots\)
Basic structure
The State uses bitwise compressed storage of the state as an array of integers, std::array<IntType,NInt>, with a predefined number of used integers NInt, and predefined integer type, IntType. This is the only data field. The local state \(\vert\sigma_i\rangle\) of site \(i\) is represented using Nbits bits. There are two important template parameters that have to be adjusted:
uint64_t MaxSites: The maximal number of sites of the system (Default: 128)
uint64_t Q: The dimension of the local Hilbert space, \(Q\) (Default: 2)
Further template parameters are class IntType that defines the primitive integer used by std::array (Default: uint64_t), uint64_t Nbits defines the number of bits necessary to encode a single qudit \(\vert\sigma_i\rangle\) (Default: minimal number required by Q), and uint64_t NInt which is the length of the array (Default: minimal number required by Nbits and MaxSites).
Basic usage
using enables an easy handling of the class within its namespace state_space:
1 /* Defining the State with std::array<uint64_t, 8> */
2 using danceq::internal::State<256,4>; // MaxSites=256, Q=4
3
4 /* Default constructor which initiates all sites with zeros: |0> */
5 State state;
In that case, State encodes up to 256 qudits with a local Hilbert space dimension of 4 using an array of uint64_t of length 8: std::array<uint64_t, 8>
The State class provides simple read and write functions to target individual sites:
1 /* Reading site 100 which is |0> */
2 auto local_state = state[100]; //
3 std::cout << "local_state = " << local_state << std::endl;
4
5 /* Setting site 100 to |1> */
6 state.set_state(1,100);
7
8 /* Reading site 100 which is |1> */
9 local_state = state[100];
10 std::cout << "local_state = " << local_state << std::endl;
Fixing the array length allows not only high-performance computations but also an easy handling using MPI. A MPI_Datatype can be defined by:
1 MPI_Datatype MPI_State;
2 MPI_Type_contiguous(static_cast<int32_t>(State::template_struct::template_NInt), MPI_UNSIGNED_LONG, &MPI_State);
3 MPI_Type_commit(&MPI_State);
Furthermore, the State class comes with a broad class of functions supporting the use of ordered sets , ordered maps, unordered sets , and unordered maps:
1 std::set<State> mySet;
2 std::map<State, uint64_t> myMap;
3 std::unordered_set<State, typename State::HashFunction> myuSet;
4 std::unordered_map<State, uint64_t, typename State::HashFunction> myuMap;
Detailed documentations
The most important constructors and functions are listed in Constructors and Functions. Please follow the Autodocs for the full documentation.