Skip to content

OpSum

A sum of local operators acting on several lattice sites.

Source opsum.hpp

Constructor

OpSum()
OpSum(ops::Vector{Op})
OpSum() = default;
OpSum(std::vector<Op> const &ops);
Parameter Description
ops a vector of Op objects describing the operators summed over

Methods

size

Returns the number of local Op operators.

size(ops::OpSum)
int64_t size() const;

defined

Returns bool whether a coupling (of type string) is defined

defined(ops::OpSum, name::String)
bool defined(std::string name) const;

setindex! / operator[]

Sets a coupling given as a string to a certain numerical value or matrix

Base.setindex!(ops::OpSum, cpl, name::String)
Coupling &operator[](std::string name);

getindex / operator[]

Returns the value of a Coupling defined as a string.

getindex(ops::OpSum, name::String)
Coupling const &operator[](std::string name) const;

couplings

Returns all the possible names of Coupling as a vector of strings

couplings(ops::OpSum)
std::vector<std::string> couplings() const;

isreal

Returns whether or not the OpSum is real. This will throw an error if some Coupling are only defined as a string.

isreal(ops::OpSum)
bool isreal() const;

isexplicit

Returns false if there exist a Coupling which is defined as a string, otherwise true.

isexplicit(ops::OpSum)
bool isexplicit() const;

operator +

Adds a single Op or a full OpSum

+(ops::OpSum, op2::Op) = OpSum(ops.cxx_opsum + op2.cxx_op)
+(ops::OpSum, ops2::OpSum) = OpSum(ops.cxx_opsum + ops2.cxx_opsum)
void operator+=(Op const &op);
void operator+=(OpSum const &ops);
OpSum operator+(Op const &op) const;
OpSum operator+(OpSum const &ops) const;

Usage Example

# Define the 1D transverse-field Ising chain
let 
    N = 12
    J = 1.0
    h = 0.5
    Sx = [0 1; 1 0]

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

    ops["J"] = 1.0;
    @show ops
    @show defined(ops, "J")
    @show isreal(ops)
    @show isexplicit(ops)
end
// Define the 1D transverse-field Ising chain
int N = 12;
double J = 1.0;
double h = 0.5;
auto Sx = arma::mat("0 1; 1 0");

auto ops = OpSum();
for (int i = 0; i<N; ++i) {
  ops += Op("ISING", "J", {i, (i+1)%N});
  ops += Op("SX", arma::mat(h*Sx), i);
}
ops["J"] = 1.0;
XDIAG_SHOW(ops);
XDIAG_SHOW(ops.defined("J"));
XDIAG_SHOW(ops.isreal());
XDIAG_SHOW(ops.isexplicit());