Skip to content

State

A generic state describing a quantum wave function \(|\psi \rangle\).

Sources: state.hpp ยท state.cpp

Constructors

A state can be constructed in three ways:

  1. By only specifying the block. In this case the state is initialized with all coefficients zero.

    State(block::Block; real::Bool = true, n_cols::Int64 = 1)
    
    State(Block const &block, bool real = true, int64_t n_cols = 1);
    
  2. By handing a vector of coefficients.

    State(block::Block, vec::Vector{Float64})
    State(block::Block, vec::Vector{ComplexF64})
    
    State(Block const &block, arma::vec const &vector);
    State(Block const &block, arma::cx_vec const &vector);
    
  3. By handing a matrix whose columns describe several states at once.

    State(block::Block, mat::Matrix{Float64})
    State(block::Block, mat::Matrix{ComplexF64})
    
    State(Block const &block, arma::mat const &matrix);
    State(Block const &block, arma::cx_mat const &matrix);
    

The number of rows of the vector and matrix needs do agree with the size of the block.

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 .

Methods

nsites

Returns the number of sites of the block the state is defined on.

nsites(state::State)::Int64
int64_t nsites(State const &s) const

isapprox

Returns whether two states are approximately equal.

isapprox(v::State, w::State, rtol::Float64, atol::Float64)::Bool
bool isapprox(State const &v, State const &w, double rtol = 1e-12,
              double atol = 1e-12);

isreal

Returns whether the state is real.

isreal(state::State)::Bool
int64_t isreal(State const &s) const;

real

Returns the real part of the State.

real(state::State)::State
State real(State const &s) const;

imag

Returns the imaginary part of the State.

imag(state::State)::State
State imag(State const &s) const;

make_complex! / make_complex

Turns a real State into a complex State. Does nothing if the state is already complex

make_complex!(state::State)
void make_complex(State &s);

dim

Returns the dimension of the block the state is defined on.

dim(block::Spinhalf)::Int64
int64_t dim(State const &s) const;

size

Returns the size of the block (also equal to nrows) times the number of columns ncols. For distributed blocks the local size of a Block is not the same as the dimension dim, which is the overall dimension of the block across all processes.

size(s::State)::Int64
int64_t size(State const &s);

nrows

Returns number of rows of the local storage.

nrows(s::State)::Int64
int64_t nrows(State const &s);

ncols

Returns number of columns.

ncols(s::State)::Int64
int64_t ncols(State const &s);

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".

col(s::State, n::Int64 = 1; copy::Bool = true)::State
State col(State const &s, int64_t n, bool copy = true);

vector/vectorC

Returns a vector from the n-th column of the storage. In C++ use "vector"/"vectorC" to either get a real or complex vector.

vector(state::State; n::Int64 = 1, copy::Bool=true)
# no vectorC method in julia
arma::vec vector(State const &s, int64_t n = 0, bool copy = true);
arma::cx_vec vectorC(State const &s, int64_t n = 0, bool copy = true);

matrix/matrixC

Returns matrix representing the storage. In C++ use "matrix"/"matrixC" to either get a real or complex matrix.

matrix(state::State, copy::Bool=true)
# no matrixC method in julia
arma::vec matrix(State const &s, bool copy = true);
arma::cx_vec matrixC(State const &s, bool copy = true);

Usage Example

block = Spinhalf(2)
psi1 = State(block, [1.0, 2.0, 3.0, 4.0])
@show psi1
display(vector(psi1))
make_complex!(psi1)
display(vector(psi1))

psi2 = State(block, real=false, ncols=3)
@show psi2
display(matrix(psi2))

psi3 = State(block, [1.0+4.0im, 2.0+3.0im, 3.0+2.0im, 4.0+1.0im])
display(vector(psi3))
display(vector(real(psi3)))
display(vector(imag(psi3)))
auto block = Spinhalf(2);
auto psi1 = State(block, arma::vec("1.0 2.0 3.0 4.0"));
XDIAG_SHOW(psi1);
XDIAG_SHOW(vector(psi1));
make_complex(psi1);
XDIAG_SHOW(vectorC(psi1));

auto psi2 = State(block, false, 3);
XDIAG_SHOW(psi2);
XDIAG_SHOW(matrixC(psi2));

auto psi3 = State(block, arma::cx_vec(arma::vec("1.0 2.0 3.0 4.0"),
                      arma::vec("4.0 3.0 2.0 1.0")));
XDIAG_SHOW(vectorC(psi3));
XDIAG_SHOW(vector(real(psi3)));
XDIAG_SHOW(vector(imag(psi3)));