Cytnx v0.9.5
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cytnx::Bond Class Reference

the object contains auxiliary properties for each Tensor rank (bond) More...

#include <Bond.hpp>

Public Member Functions

 Bond (const cytnx_uint64 &dim, const bondType &bd_type=bondType::BD_REG)
 The constructor of the Bond object.
 
 Bond (const bondType &bd_type, const std::vector< std::vector< cytnx_int64 > > &in_qnums, const std::vector< cytnx_uint64 > &degs, const std::vector< Symmetry > &in_syms={})
 The constructor of the Bond object.
 
 Bond (const bondType &bd_type, const std::initializer_list< std::vector< cytnx_int64 > > &in_qnums, const std::vector< cytnx_uint64 > &degs, const std::vector< Symmetry > &in_syms={})
 
 Bond (const bondType &bd_type, const std::vector< cytnx::Qs > &in_qnums, const std::vector< cytnx_uint64 > &degs, const std::vector< Symmetry > &in_syms={})
 
 Bond (const bondType &bd_type, const std::vector< std::pair< std::vector< cytnx_int64 >, cytnx_uint64 > > &in_qnums_dims, const std::vector< Symmetry > &in_syms={})
 
void Init (const cytnx_uint64 &dim, const bondType &bd_type=bondType::BD_REG)
 init a bond object
 
void Init (const bondType &bd_type, const std::vector< std::vector< cytnx_int64 > > &in_qnums, const std::vector< cytnx_uint64 > &degs, const std::vector< Symmetry > &in_syms={})
 init a bond object
 
void Init (const bondType &bd_type, const std::vector< std::pair< std::vector< cytnx_int64 >, cytnx_uint64 > > &in_qnums_dims, const std::vector< Symmetry > &in_syms={})
 
bondType type () const
 return the current bond type (see cytnx::bondType).
 
const std::vector< std::vector< cytnx_int64 > > & qnums () const
 return the current quantum number set(s) by reference
 
std::vector< std::vector< cytnx_int64 > > & qnums ()
 
std::vector< std::vector< cytnx_int64 > > qnums_clone () const
 return the clone (deep copy) of the current quantum number set(s)
 
cytnx_uint64 dim () const
 return the dimension of the bond
 
cytnx_uint32 Nsym () const
 return the number of the symmetries
 
const std::vector< Symmetry > & syms () const
 return the vector of symmetry objects by reference.
 
std::vector< Symmetry > & syms ()
 
std::vector< Symmetrysyms_clone () const
 return copy of the vector of symmetry objects.
 
Bondset_type (const bondType &new_bondType)
 change the tag-type of the instance Bond
 
Bond retype (const bondType &new_bondType)
 create a new instance of Bond with type changed to the new tag-type.
 
Bond redirect () const
 create a new instance of Bond with type changed in between bondType.BD_BRA / bondType.BD_KET.
 
Bondredirect_ ()
 Change the bond type between bondType.BD_BRA and bondType.BD_KET in the Bond.
 
void clear_type ()
 change the tag-type to the default value bondType.BD_REG.
 
Bond clone () const
 return a copy of the instance Bond
 
void combineBond_ (const Bond &bd_in, const bool &is_grp=true)
 Combine the input bond with self, inplacely.
 
Bond combineBond (const Bond &bd_in, const bool &is_grp=true) const
 combine the input bond with self, and return a new combined Bond instance.
 
Bond combineBonds (const std::vector< Bond > &bds, const bool &is_grp=true)
 combine multiple input bonds with self, and return a new combined Bond instance.
 
void combineBonds_ (const std::vector< Bond > &bds, const bool &is_grp=true)
 combine multiple input bonds with self, inplacely
 
std::vector< std::vector< cytnx_int64 > > getUniqueQnums (std::vector< cytnx_uint64 > &counts)
 return a sorted qnum sets by removing all the duplicate qnum sets.
 
std::vector< std::vector< cytnx_int64 > > getUniqueQnums ()
 return a sorted qnum sets by removing all the duplicate qnum sets.
 
cytnx_uint64 getDegeneracy (const std::vector< cytnx_int64 > &qnum) const
 return the degeneracy of specify qnum set.
 
cytnx_uint64 getDegeneracy (const std::vector< cytnx_int64 > &qnum, std::vector< cytnx_uint64 > &indices) const
 return the degeneracy of specify qnum set.
 
std::vector< cytnx_uint64 > & getDegeneracies ()
 return all degeneracies.
 
const std::vector< cytnx_uint64 > & getDegeneracies () const
 
std::vector< cytnx_uint64group_duplicates_ ()
 Group the duplicated quantum number, inplacely.
 
Bond group_duplicates (std::vector< cytnx_uint64 > &mapper) const
 Group the duplicated quantum number and return the new instance of the Bond ojbect.
 
bool has_duplicate_qnums () const
 Check whether there is duplicated quantum numbers in the Bond.
 
std::vector< std::vector< cytnx_int64 > > calc_reverse_qnums ()
 Calculate the reverse of the quantum numbers.
 
void Save (const std::string &fname) const
 Save the Bond object to the file.
 
void Save (const char *fname) const
 
bool operator== (const Bond &rhs) const
 The comparison operator 'equal to'.
 
bool operator!= (const Bond &rhs) const
 The comparison operator 'not equal to'.
 
Bond operator* (const Bond &rhs) const
 The multiplication operator of the Bond object.
 
Bondoperator*= (const Bond &rhs)
 The multiplication assignment operator of the Bond object.
 

Static Public Member Functions

static cytnx::Bond Load (const std::string &fname)
 Load the Bond object from the file.
 
static cytnx::Bond Load (const char *fname)
 

Detailed Description

the object contains auxiliary properties for each Tensor rank (bond)

The Bond object is used to construct the bond of the UniTensor.

  1. For non-symmetric UniTensor (regular UniTensor, that means cytnx::UTenType.Dense, see cytnx::UTenType), the bond type need will be set as bondType.BD_REG defaultly. And you can set the bond type as bondType.BD_KET or bondType.BD_BRA if you want to describe the it as ket or bra basis. For non-symmetric case, you cannot input the quantum numbers and Symmetry object.
  2. For symmteric UniTensor (cytnx::UTenType.Block, see cytnx::UTenType), the bond type need to be set as bondType.BD_KET or bondType.BD_BRA depend on what physical system you describe. And you should input the quantum numbers and Symmetry objects.

Constructor & Destructor Documentation

◆ Bond() [1/5]

cytnx::Bond::Bond ( const cytnx_uint64 dim,
const bondType bd_type = bondType::BD_REG 
)
inline

The constructor of the Bond object.

This function will call Init to do initialization.

Parameters
[in]dimthe dimenstion of the Bond
[in]bd_typethe type (see bondType) of the bond
See also
Init(const cytnx_uint64 &dim, const bondType &bd_type)

◆ Bond() [2/5]

cytnx::Bond::Bond ( const bondType bd_type,
const std::vector< std::vector< cytnx_int64 > > &  in_qnums,
const std::vector< cytnx_uint64 > &  degs,
const std::vector< Symmetry > &  in_syms = {} 
)
inline

The constructor of the Bond object.

This function will call Init to do initialization.

Parameters
[in]bd_typethe type (see bondType) of the bond
[in]in_qnumsinput the quantum numbers of the bond (for symmetry case)
[in]degsthe degrees of freedom of the bond.
[in]in_symsinput the symmetries of the bond (for symmetry case)
Attention
This function is can only use for symmetry case.
See also
Init(const bondType &bd_type, const std::vector<std::vector<cytnx_int64>> &in_qnums, const std::vector<cytnx_uint64> &degs, const std::vector<Symmetry> &in_syms)

◆ Bond() [3/5]

cytnx::Bond::Bond ( const bondType bd_type,
const std::initializer_list< std::vector< cytnx_int64 > > &  in_qnums,
const std::vector< cytnx_uint64 > &  degs,
const std::vector< Symmetry > &  in_syms = {} 
)
inline

◆ Bond() [4/5]

cytnx::Bond::Bond ( const bondType bd_type,
const std::vector< cytnx::Qs > &  in_qnums,
const std::vector< cytnx_uint64 > &  degs,
const std::vector< Symmetry > &  in_syms = {} 
)
inline

◆ Bond() [5/5]

cytnx::Bond::Bond ( const bondType bd_type,
const std::vector< std::pair< std::vector< cytnx_int64 >, cytnx_uint64 > > &  in_qnums_dims,
const std::vector< Symmetry > &  in_syms = {} 
)
inline

Member Function Documentation

◆ calc_reverse_qnums()

std::vector< std::vector< cytnx_int64 > > cytnx::Bond::calc_reverse_qnums ( )
inline

Calculate the reverse of the quantum numbers.

This function will calculate the reverse of the qunatum numbers by the reverse rule of the Symmetry. See Symmetry.reverse_rule().

Note
You may use this function if the Bra-Ket mismatch.
See also
Symmetry.reverse_rule()
Returns
std::vector<std::vector<cytnx_int64>>

◆ clear_type()

void cytnx::Bond::clear_type ( )
inline

change the tag-type to the default value bondType.BD_REG.

Precondition
The size of quantum number should be 0. Namely, you cannot clear the symmetric bond.

◆ clone()

Bond cytnx::Bond::clone ( ) const
inline

return a copy of the instance Bond

Returns
[Bond] a new instance of Bond that have the same contents

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace std;
using namespace cytnx;
int main() {
/* 1.
create a non-symmetry, regular bond (BD_REG)
with dimension 10
*/
Bond bd_a = Bond(10);
cout << bd_a << endl;
Bond bd_b = bd_a;
Bond bd_c = bd_a.clone();
cout << is(bd_b, bd_a) << endl; // true, the same instance
cout << is(bd_c, bd_a) << endl; // false, different instance
cout << (bd_b == bd_a) << endl; // true, same content
cout << (bd_c == bd_a) << endl; // true, same content
return 0;
}
the object contains auxiliary properties for each Tensor rank (bond)
Definition Bond.hpp:178
Bond clone() const
return a copy of the instance Bond
Definition Bond.hpp:490
Helper function to print vector with ODT:
Definition Accessor.hpp:12

output>

Dim = 10 |type: REGULAR

1
0
1
1

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
bd_a = Bond(10)
print(bd_a)
bd_b = bd_a;
bd_c = bd_a.clone();
print(bd_b is bd_a) #true
print(bd_c is bd_a) #false
print(bd_b == bd_a) #true
print(bd_c == bd_a) #true

output>

Dim = 10 |type: REGULAR


True
False
True
True

◆ combineBond()

Bond cytnx::Bond::combineBond ( const Bond bd_in,
const bool &  is_grp = true 
) const
inline

combine the input bond with self, and return a new combined Bond instance.

Parameters
[in]bd_inthe bond that to be combined.
[in]is_grpthis parameter is only used when the bond is symmetric bond (bondType.BD_BRA or bondType.BD_KET). If is_grp is true, the basis with duplicated quantum number will be grouped together as a single basis. See group_duplicates(std::vector<cytnx_uint64> &mapper) const.
Returns
[Bond] a new combined bond instance.
Precondition
  1. The type of two bonds (see cytnx::bondType) need to be same.
  2. The Symmetry of two bonds should be same.
Note
Compare to
combineBond_(const Bond &bd_in, const bool &is_grp),
this function will create a new Bond object.
See also
combineBond_(const Bond &bd_in, const bool &is_grp)

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/* 1.
create a non-symmetry, regular bond (BD_REG)
with dimension 10
*/
Bond bd_a = Bond(10, BD_KET);
Bond bd_b = Bond(15, BD_KET);
Bond bd_c = bd_a.combineBond(bd_b);
cout << bd_c << endl;
cout << bd_a << endl;
cout << bd_b << endl;
/* 2.
combine symmetry bonds,
with U1 x Z2 multiple symmetry
*/
Bond bd_d =
Bond(BD_BRA, {Qs(0, 1) >> 1, Qs(2, 0) >> 1, Qs(-4, 1) >> 1}, {Symmetry::U1(), Symmetry::Zn(2)});
Bond bd_e = Bond(BD_BRA, {Qs(0, 0) >> 1, Qs(2, 1) >> 1, Qs(-1, 1) >> 1, Qs(3, 0) >> 1},
Bond bd_f = bd_d.combineBond(bd_e);
cout << bd_f << endl;
cout << bd_d << endl;
cout << bd_e << endl;
return 0;
}
Bond combineBond(const Bond &bd_in, const bool &is_grp=true) const
combine the input bond with self, and return a new combined Bond instance.
Definition Bond.hpp:553
Definition Symmetry.hpp:47
static Symmetry Zn(const int &n)
create a Zn descrete symmetry object with
Definition Symmetry.hpp:241
static Symmetry U1()
create a U1 symmetry object
Definition Symmetry.hpp:210
@ BD_BRA
Definition Bond.hpp:35
@ BD_KET
Definition Bond.hpp:34

output>

Dim = 150 |type: KET>

Dim = 10 |type: KET>

Dim = 15 |type: KET>

Dim = 12 |type: <BRA
 U1::   -5  -4  -2  -1  -1  +0  +1  +2  +3  +4  +5
 Z2::   +0  +1  +0  +0  +1  +1  +1  +0  +1  +1  +0
Deg>>    1   1   1   1   1   1   1   2   1   1   1

Dim = 3 |type: <BRA
 U1::   +0  +2  -4
 Z2::   +1  +0  +1
Deg>>    1   1   1

Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
bd_a = Bond(10,BD_KET)
bd_b = Bond(15,BD_KET)
bd_c = bd_a.combineBond(bd_b)
print(bd_a)
print(bd_b)
print(bd_c)
bd_d = Bond(BD_BRA,[Qs(0,1)>>1,Qs(2,0)>>1,Qs(-4,1)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)])
bd_e = Bond(BD_BRA,[Qs(0,0)>>1,Qs(2,1)>>1,Qs(-1,1)>>1,Qs(3,0)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)])
bd_f = bd_d.combineBond(bd_e)
print(bd_f)
print(bd_d)
print(bd_e)

output>

Dim = 10 |type: KET>


Dim = 15 |type: KET>


Dim = 150 |type: KET>


Dim = 12 |type: <BRA
 U1::   -5  -4  -2  -1  -1  +0  +1  +2  +3  +4  +5
 Z2::   +0  +1  +0  +0  +1  +1  +1  +0  +1  +1  +0
Deg>>    1   1   1   1   1   1   1   2   1   1   1


Dim = 3 |type: <BRA
 U1::   +0  +2  -4
 Z2::   +1  +0  +1
Deg>>    1   1   1


Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1

◆ combineBond_()

void cytnx::Bond::combineBond_ ( const Bond bd_in,
const bool &  is_grp = true 
)
inline

Combine the input bond with self, inplacely.

Parameters
[in]bd_inthe bond that to be combined with self.
[in]is_grpthis parameter is only used when the bond is symmetric bond (bondType.BD_BRA or bondType.BD_KET). If is_grp is true, the basis with duplicated quantum number will be grouped together as a single basis. See group_duplicates(std::vector<cytnx_uint64> &mapper) const.
Precondition
  1. The type of two bonds (see cytnx::bondType) need to be same.
  2. The Symmetry of two bonds should be same.
Note
Compare to
combineBond(const Bond &bd_in, const bool &is_grp) const,
this function in inplace function.
See also
combineBond(const Bond &bd_in, const bool &is_grp)const

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/* 1.
create a non-symmetry, regular bond (BD_REG)
with dimension 10
*/
Bond bd_a = Bond(10);
cout << bd_a << endl;
Bond bd_b = Bond(5);
cout << bd_b << endl;
bd_a.combineBond_(bd_b);
cout << bd_a << endl;
/* 2.
combine symmetry bonds,
with U1 x Z2 multiple symmetry
*/
Bond bd_c =
Bond(BD_BRA, {Qs(0, 1) >> 1, Qs(2, 0) >> 1, Qs(-4, 1) >> 1}, {Symmetry::U1(), Symmetry::Zn(2)});
cout << bd_c << endl;
Bond bd_d = Bond(BD_BRA, {Qs(0, 0) >> 1, Qs(2, 1) >> 1, Qs(-1, 1) >> 1, Qs(3, 0) >> 1},
cout << bd_d << endl;
bd_c.combineBond_(bd_d);
cout << bd_c << endl;
return 0;
}
void combineBond_(const Bond &bd_in, const bool &is_grp=true)
Combine the input bond with self, inplacely.
Definition Bond.hpp:522

output>

Dim = 10 |type: REGULAR

Dim = 5 |type: REGULAR

Dim = 50 |type: REGULAR

Dim = 3 |type: <BRA
 U1::   +0  +2  -4
 Z2::   +1  +0  +1
Deg>>    1   1   1

Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1

Dim = 12 |type: <BRA
 U1::   -5  -4  -2  -1  -1  +0  +1  +2  +3  +4  +5
 Z2::   +0  +1  +0  +0  +1  +1  +1  +0  +1  +1  +0
Deg>>    1   1   1   1   1   1   1   2   1   1   1

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
bd_a = Bond(10)
print(bd_a)
bd_b = Bond(5)
print(bd_b)
bd_a.combineBond_(bd_b)
print(bd_a)
bd_c = Bond(BD_BRA,[Qs(0,1)>>1,Qs(2,0)>>1,Qs(-4,1)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)])
print(bd_c)
bd_d = Bond(BD_BRA,[Qs(0,0)>>1,Qs(2,1)>>1,Qs(-1,1)>>1,Qs(3,0)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)])
print(bd_d)
bd_c.combineBond_(bd_d)
print(bd_c)

output>

Dim = 10 |type: REGULAR


Dim = 5 |type: REGULAR


Dim = 50 |type: REGULAR


Dim = 3 |type: <BRA
 U1::   +0  +2  -4
 Z2::   +1  +0  +1
Deg>>    1   1   1


Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1


Dim = 12 |type: <BRA
 U1::   -5  -4  -2  -1  -1  +0  +1  +2  +3  +4  +5
 Z2::   +0  +1  +0  +0  +1  +1  +1  +0  +1  +1  +0
Deg>>    1   1   1   1   1   1   1   2   1   1   1

◆ combineBonds()

Bond cytnx::Bond::combineBonds ( const std::vector< Bond > &  bds,
const bool &  is_grp = true 
)
inline

combine multiple input bonds with self, and return a new combined Bond instance.

Parameters
[in]bdsthe bonds that to be combined with self.
[in]is_grpthis parameter is only used when the bond is symmetric bond (bondType.BD_BRA or bondType.BD_KET). If is_grp is true, the basis with duplicated quantum number will be grouped together as a single basis. See group_duplicates(std::vector<cytnx_uint64> &mapper) const.
Returns
[Bond] a new combined bond instance.
Precondition
  1. The type of all bonds (see cytnx::bondType) need to be same.
  2. The Symmetry of all bonds should be same.
Note
Compare to
combineBonds_(const std::vector<Bond> &bds, const bool &is_grp),
this function will create a new Bond object.
See also
combineBonds_(const std::vector<Bond> &bds, const bool &is_grp)

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/* 1.
combine multiple KET bonds
*/
Bond bd_a = Bond(10, BD_KET);
Bond bd_b = Bond(4, BD_KET);
Bond bd_c = Bond(5, BD_KET);
Bond bd_d = Bond(2, BD_KET);
// note that this will not create copy instances for each Bond elements.
// so it is both memory efficient and fast!
Bond bd_all = bd_a.combineBonds({bd_b, bd_c, bd_d});
cout << bd_a << endl;
cout << bd_b << endl;
cout << bd_c << endl;
cout << bd_d << endl;
cout << bd_all << endl;
/* 2.
combine symmetry bonds,
with U1 x Z2 multiple symmetry
*/
Bond bd_sym_a =
Bond(BD_BRA, {Qs(0, 1) >> 1, Qs(2, 0) >> 1, Qs(-4, 1) >> 1}, {Symmetry::U1(), Symmetry::Zn(2)});
Bond bd_sym_b = Bond(BD_BRA, {Qs(0, 0) >> 1, Qs(2, 1) >> 1, Qs(-1, 1) >> 1, Qs(3, 0) >> 1},
Bond bd_sym_c = Bond(BD_BRA, {Qs(1, 1) >> 2, Qs(-1, 1) >> 1, Qs(-2, 0) >> 1, Qs(0, 0) >> 1},
Bond bd_sym_d = bd_sym_a.combineBonds({bd_sym_b, bd_sym_c});
cout << bd_sym_a << endl;
cout << bd_sym_b << endl;
cout << bd_sym_c << endl;
cout << bd_sym_d << endl;
return 0;
}
Bond combineBonds(const std::vector< Bond > &bds, const bool &is_grp=true)
combine multiple input bonds with self, and return a new combined Bond instance.
Definition Bond.hpp:586

output>

Dim = 10 |type: KET>

Dim = 4 |type: KET>

Dim = 5 |type: KET>

Dim = 2 |type: KET>

Dim = 400 |type: KET>

Dim = 3 |type: <BRA
 U1::   +0  +2  -4
 Z2::   +1  +0  +1
Deg>>    1   1   1

Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1

Dim = 5 |type: <BRA
 U1::   +1  -1  -2  +0
 Z2::   +1  +1  +0  +0
Deg>>    2   1   1   1

Dim = 60 |type: <BRA
 U1::   -7  -6  -5  -4  -4  -3  -3  -2  -2  -1  -1  +0  +0  +1  +1  +2  +2  +3  +3  +4  +4  +5  +6
 Z2::   +0  +1  +0  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1
Deg>>    1   2   2   1   3   3   2   2   2   2   4   5   3   2   4   5   1   2   5   2   2   3   2

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
bd_a = Bond(10,BD_KET);
bd_b = Bond(4,BD_KET);
bd_c = Bond(5,BD_KET);
bd_d = Bond(2,BD_KET);
bd_all = bd_a.combineBonds([bd_b,bd_c,bd_d]);
print( bd_a )
print( bd_b )
print( bd_c )
print( bd_d )
print( bd_all )
bd_sym_a = Bond(BD_BRA,[Qs(0,1)>>1,
Qs(2,0)>>1,
Qs(-4,1)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)]);
bd_sym_b = Bond(BD_BRA,[Qs(0 ,0)>>1,
Qs(2 ,1)>>1,
Qs(-1,1)>>1,
Qs(3 ,0)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)]);
bd_sym_c = Bond(BD_BRA,[Qs(1 ,1)>>2,
Qs(-1,1)>>1,
Qs(-2,0)>>1,
Qs(0 ,0)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)]);
bd_sym_d = bd_sym_a.combineBonds([bd_sym_b,bd_sym_c]);
print( bd_sym_a )
print( bd_sym_b )
print( bd_sym_c )
print( bd_sym_d )

output>

Dim = 10 |type: KET>


Dim = 4 |type: KET>


Dim = 5 |type: KET>


Dim = 2 |type: KET>


Dim = 400 |type: KET>


Dim = 3 |type: <BRA
 U1::   +0  +2  -4
 Z2::   +1  +0  +1
Deg>>    1   1   1


Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1


Dim = 5 |type: <BRA
 U1::   +1  -1  -2  +0
 Z2::   +1  +1  +0  +0
Deg>>    2   1   1   1


Dim = 60 |type: <BRA
 U1::   -7  -6  -5  -4  -4  -3  -3  -2  -2  -1  -1  +0  +0  +1  +1  +2  +2  +3  +3  +4  +4  +5  +6
 Z2::   +0  +1  +0  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1
Deg>>    1   2   2   1   3   3   2   2   2   2   4   5   3   2   4   5   1   2   5   2   2   3   2

◆ combineBonds_()

void cytnx::Bond::combineBonds_ ( const std::vector< Bond > &  bds,
const bool &  is_grp = true 
)
inline

combine multiple input bonds with self, inplacely

Parameters
[in]bdsthe bonds that to be combined with self.
[in]is_grpthis parameter is only used when the bond is symmetric bond (bondType.BD_BRA or bondType.BD_KET). If is_grp is true, the basis with duplicated quantum number will be grouped together as a single basis. See group_duplicates(std::vector<cytnx_uint64> &mapper) const.
Precondition
  1. The type of all bonds (see cytnx::bondType) need to be same.
  2. The Symmetry of all bonds should be same.
Note
Compare to
combineBonds(const std::vector<Bond> &bds, const bool &is_grp),
this function will create a new Bond object.
See also
combineBonds(const std::vector<Bond> &bds, const bool &is_grp)

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/* 1.
combine multiple KET bonds
*/
Bond bd_a = Bond(10, BD_KET);
Bond bd_b = Bond(4, BD_KET);
Bond bd_c = Bond(5, BD_KET);
Bond bd_d = Bond(2, BD_KET);
cout << bd_a << endl;
cout << bd_b << endl;
cout << bd_c << endl;
cout << bd_d << endl;
bd_a.combineBonds_({bd_b, bd_c, bd_d});
cout << bd_a << endl;
/* 2.
combine symmetry bonds,
with U1 x Z2 multiple symmetry
*/
Bond bd_sym_a =
Bond(BD_BRA, {Qs(0, 1) >> 1, Qs(2, 0) >> 1, Qs(-4, 1) >> 1}, {Symmetry::U1(), Symmetry::Zn(2)});
Bond bd_sym_b = Bond(BD_BRA, {Qs(0, 0) >> 1, Qs(2, 1) >> 1, Qs(-1, 1) >> 1, Qs(3, 0) >> 1},
Bond bd_sym_c = Bond(BD_BRA, {Qs(1, 1) >> 2, Qs(-1, 1) >> 1, Qs(-2, 0) >> 1, Qs(0, 0) >> 1},
cout << bd_sym_a << endl;
cout << bd_sym_b << endl;
cout << bd_sym_c << endl;
bd_sym_a.combineBonds_({bd_sym_b, bd_sym_c});
cout << bd_sym_a << endl;
return 0;
}
void combineBonds_(const std::vector< Bond > &bds, const bool &is_grp=true)
combine multiple input bonds with self, inplacely
Definition Bond.hpp:620

output>

Dim = 10 |type: KET>

Dim = 4 |type: KET>

Dim = 5 |type: KET>

Dim = 2 |type: KET>

Dim = 400 |type: KET>

Dim = 3 |type: <BRA
 U1::   +0  +2  -4
 Z2::   +1  +0  +1
Deg>>    1   1   1

Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1

Dim = 5 |type: <BRA
 U1::   +1  -1  -2  +0
 Z2::   +1  +1  +0  +0
Deg>>    2   1   1   1

Dim = 60 |type: <BRA
 U1::   -7  -6  -5  -4  -4  -3  -3  -2  -2  -1  -1  +0  +0  +1  +1  +2  +2  +3  +3  +4  +4  +5  +6
 Z2::   +0  +1  +0  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1
Deg>>    1   2   2   1   3   3   2   2   2   2   4   5   3   2   4   5   1   2   5   2   2   3   2

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
bd_a = Bond(10,BD_KET);
bd_b = Bond(4,BD_KET);
bd_c = Bond(5,BD_KET);
bd_d = Bond(2,BD_KET);
print( bd_a )
print( bd_b )
print( bd_c )
print( bd_d )
bd_a.combineBonds_([bd_b,bd_c,bd_d]);
print( bd_a )
bd_sym_a = Bond(BD_BRA,[Qs(0,1)>>1,
Qs(2,0)>>1,
Qs(-4,1)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)]);
bd_sym_b = Bond(BD_BRA,[Qs(0 ,0)>>1,
Qs(2 ,1)>>1,
Qs(-1,1)>>1,
Qs(3 ,0)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)]);
bd_sym_c = Bond(BD_BRA,[Qs(1 ,1)>>2,
Qs(-1,1)>>1,
Qs(-2,0)>>1,
Qs(0 ,0)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)]);
print( bd_sym_a )
print( bd_sym_b )
print( bd_sym_c )
bd_sym_a.combineBonds_([bd_sym_b,bd_sym_c]);
print( bd_sym_a )

output>

Dim = 10 |type: KET>


Dim = 4 |type: KET>


Dim = 5 |type: KET>


Dim = 2 |type: KET>


Dim = 400 |type: KET>


Dim = 3 |type: <BRA
 U1::   +0  +2  -4
 Z2::   +1  +0  +1
Deg>>    1   1   1


Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1


Dim = 5 |type: <BRA
 U1::   +1  -1  -2  +0
 Z2::   +1  +1  +0  +0
Deg>>    2   1   1   1


Dim = 60 |type: <BRA
 U1::   -7  -6  -5  -4  -4  -3  -3  -2  -2  -1  -1  +0  +0  +1  +1  +2  +2  +3  +3  +4  +4  +5  +6
 Z2::   +0  +1  +0  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1  +0  +1
Deg>>    1   2   2   1   3   3   2   2   2   2   4   5   3   2   4   5   1   2   5   2   2   3   2

◆ dim()

cytnx_uint64 cytnx::Bond::dim ( ) const
inline

return the dimension of the bond

Returns
[cytnx_uint64]

◆ getDegeneracies() [1/2]

std::vector< cytnx_uint64 > & cytnx::Bond::getDegeneracies ( )
inline

◆ getDegeneracies() [2/2]

const std::vector< cytnx_uint64 > & cytnx::Bond::getDegeneracies ( ) const
inline

◆ getDegeneracy() [1/2]

cytnx_uint64 cytnx::Bond::getDegeneracy ( const std::vector< cytnx_int64 > &  qnum) const
inline

return the degeneracy of specify qnum set.

Parameters
[in]qnuminput the quantum number you want to get the degeneracy.
Precondition
the input qnum should match the number of the Symmetry. (see Nsym())
Returns
cytnx_uint64 degeneracy
@note
if the bond has no symmetries, return 0.
if the degeneracy queried does not exist, return 0, and the indicies is empty
@see
 getDegeneracy(const std::vector<cytnx_int64> &qnum,
               std::vector<cytnx_uint64> &indices) const.

◆ getDegeneracy() [2/2]

cytnx_uint64 cytnx::Bond::getDegeneracy ( const std::vector< cytnx_int64 > &  qnum,
std::vector< cytnx_uint64 > &  indices 
) const
inline

return the degeneracy of specify qnum set.

Parameters
[in]qnuminput the quantum number you want to get the degeneracy.
[out]indicesoutput the indices location of the quantum number qnum.
Precondition
the input qnum should match the number of the Symmetry. (see Nsym())
Returns
cytnx_uint64 degeneracy
@note
If the bond has no symmetries, return 0.
If the degeneracy queried does not exist, return 0, and the indicies is empty.
@see
 getDegeneracy(const std::vector<cytnx_int64> &qnum) const.

◆ getUniqueQnums() [1/2]

std::vector< std::vector< cytnx_int64 > > cytnx::Bond::getUniqueQnums ( )
inline

return a sorted qnum sets by removing all the duplicate qnum sets.

Precondition
The bond cannot be regular type (namely, bondType.BD_REG)
Returns
std::vector<std::vector<cytnx_int64>> unique_qnums
See also
getUniqueQnums(std::vector<cytnx_uint64> &counts)

◆ getUniqueQnums() [2/2]

std::vector< std::vector< cytnx_int64 > > cytnx::Bond::getUniqueQnums ( std::vector< cytnx_uint64 > &  counts)
inline

return a sorted qnum sets by removing all the duplicate qnum sets.

Parameters
[out]countsoutput the counts of the unique quantum numbers.
Precondition
The bond cannot be regular type (namely, bondType.BD_REG)
Returns
std::vector<std::vector<cytnx_int64>> unique_qnums
See also
getUniqueQnums()

◆ group_duplicates()

Bond cytnx::Bond::group_duplicates ( std::vector< cytnx_uint64 > &  mapper) const
inline

Group the duplicated quantum number and return the new instance of the Bond ojbect.

This function will group the duplicated quantum number and return the new instance of the Bond object. It will also the mapper, where mapper is about the new index from old index via
new_index = return<cytnx_uint64>[old_index].

Parameters
[out]mapperthe new index from old index via
new_index = return<cytnx_uint64>[old_index].
Precondition
The Bond need to be symmetric type (namely, bondType should be bondType.BD_BRA or bondType.BD_DET, see bondType.)
Note
  1. Compare to the function group_duplicates_(), this function will create the new instance of Bond object.
    1. This function will sort ascending of the quantum number.
See also
group_duplicates_(std::vector<cytnx_uint64> &mapper), has_duplicate_qnums() const.
Returns
Bond

◆ group_duplicates_()

std::vector< cytnx_uint64 > cytnx::Bond::group_duplicates_ ( )
inline

Group the duplicated quantum number, inplacely.

This function will group the duplicated quantum number and return the mapper, where mapper is about the new index from old index via
new_index = return<cytnx_uint64>[old_index].

Precondition
The Bond need to be symmetric type (namely, bondType should be bondType.BD_BRA or bondType.BD_DET, see bondType.)
Note
  1. Compare to the function group_duplicates(std::vector<cytnx_uint64> &mapper) const, this function is inplace function.
    1. This function will sort ascending of the quantum number.
See also
group_duplicates(std::vector<cytnx_uint64> &mapper) const, has_duplicate_qnums() const.
Returns
std::vector<cytnx_uint64> mapper

◆ has_duplicate_qnums()

bool cytnx::Bond::has_duplicate_qnums ( ) const
inline

Check whether there is duplicated quantum numbers in the Bond.

This function will check whether there is any duplicated quantum number is the Bond. If yes, return ture. Otherwise, return false.

Note
For the regular bond (bondType.BD_REG), it will always return false.
See also
group_duplicates_(std::vector<cytnx_uint64> &mapper) group_duplicates(std::vector<cytnx_uint64> &mapper) const
Returns
bool

◆ Init() [1/3]

void cytnx::Bond::Init ( const bondType bd_type,
const std::vector< std::pair< std::vector< cytnx_int64 >, cytnx_uint64 > > &  in_qnums_dims,
const std::vector< Symmetry > &  in_syms = {} 
)
inline

◆ Init() [2/3]

void cytnx::Bond::Init ( const bondType bd_type,
const std::vector< std::vector< cytnx_int64 > > &  in_qnums,
const std::vector< cytnx_uint64 > &  degs,
const std::vector< Symmetry > &  in_syms = {} 
)
inline

init a bond object

This function is initialization for symmetry bond case.

  1. each bond can be tagged with BD_BRA or BD_KET that represent the bond is defined in Bra space or Ket space.
  2. the bond can have arbitrary multiple symmetries, with the type of each symmetry associate to the qnums are provided with the in_syms.
Parameters
[in]bd_typethe tag of the bond, it can be bondType.BD_BRA, bondType.BD_KET as physical tagged and cannot be bondType.BD_REG (regular bond).
[in]in_qnumsthe quantum number(s) of the bond. it should be a 2d vector with shape (# of unique qnum labels, # of symmetry).
[in]degsthe degeneracy correspond to each qunatum number sets specified in the qnums, the size should match the # of rows of passed-in qnums.
[in]in_symsa vector of symmetry objects of the bond, the size should match the # of cols of passed-in qnums. [Note] if qnums are provided, the default symmetry type is Symmetry::U1
Precondition
  1. The size of degs need to same as the size of in_qnums.
    1. in_qnums and degs cannot be empty.
    2. All sub-vector in in_qnums MUST have the same size.
    3. If in_syms is provided, the size of in_syms MUST same as the size of the sub-vector in in_qnums.
    4. bd_type cannot be bondType.BD_REG.
    5. The quantum numbers in in_qnums and in_syms need to be consistent. For example, you cannot set the quntum number 2 in Z(2) symmetry.
Note
  1. If quantum number(s) are provided (which means the bond is with symmetry) then the bond MUST be tagged with either bondType.BD_BRA or bondType.BD_KET.
  1. If the bond is non-symmetry, then it can be tagged with bondType.BD_BRA or bondType.BD_KET, or bondType.BD_REG depending on the usage.
  2. The "bond dimension" is the sum over all numbers specified in degs.

◆ Init() [3/3]

void cytnx::Bond::Init ( const cytnx_uint64 dim,
const bondType bd_type = bondType::BD_REG 
)
inline

init a bond object

Parameters
[in]dimthe dimension of the bond (rank)
[in]bd_typethe tag of the bond, it can be BD_BRA, BD_KET as physical tagged; or BD_REG as regular bond (rank)

details:

  1. each bond can be tagged with BD_BRA or BD_KET that represent the bond is defined in Bra space or Ket space.
    @pre
        1. \p dim cannot be 0.
    

The bond can be tagged with bondType.BD_BRA or bondType.BD_KET, or bondType.BD_REG depending on the usage.

Example:

c++ API:

#include "cytnx.hpp"
#include <iostream>
using namespace cytnx;
using namespace std;
int main() {
/* 1.
create a non-symmetry, regular bond (BD_REG)
with dimension 10
*/
Bond bd_a = Bond(10);
cout << bd_a << endl;
/* 2.
create a non-symmetry bond tagged with BD_IN
with dimension 10
*/
Bond bd_b = Bond(10, BD_IN);
cout << bd_b << endl;
/* 3.
crate a symmetry bond,
with single U1 (default) symmetry and qnums = (0,2,-1,3)
*/
Bond bd_c = Bond(BD_IN, {Qs(0) >> 1, Qs(2) >> 1, Qs(-1) >> 1, Qs(3) >> 1});
cout << bd_c << endl;
/* 3.
crate a symmetry bond,
with U1 x Z2 multiple symmetry
and qnums = U1:(0,2,-1,3) x Z2:(0,1,1,0)
*/
Bond bd_d = Bond(BD_OUT, {Qs(0, 0) >> 1, Qs(2, 1) >> 1, Qs(-1, 1) >> 1, Qs(3, 0) >> 1},
cout << bd_d << endl;
}
@ BD_IN
Definition Bond.hpp:38
@ BD_OUT
Definition Bond.hpp:39

output>

Dim = 10 |type: REGULAR

Dim = 10 |type: KET>

Dim = 4 |type: KET>
 U1::   +0  +2  -1  +3
Deg>>    1   1   1   1

Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1

python API:

import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *
bd_a = Bond(10)
print(bd_a)
bd_b = Bond(10,BD_KET)
print(bd_b)
bd_c = Bond(BD_IN,[Qs(0)>>1,Qs(2)>>1,Qs(-1)>>1,Qs(3)>>1])
print(bd_c)
bd_d = Bond(BD_OUT,[Qs(0 ,0)>>1,
Qs(2 ,1)>>1,
Qs(-1,1)>>1,
Qs(3 ,0)>>1],
[Symmetry.U1(),
Symmetry.Zn(2)])
print(bd_d)

output>

Dim = 10 |type: REGULAR


Dim = 10 |type: KET>


Dim = 4 |type: KET>
 U1::   +0  +2  -1  +3
Deg>>    1   1   1   1


Dim = 4 |type: <BRA
 U1::   +0  +2  -1  +3
 Z2::   +0  +1  +1  +0
Deg>>    1   1   1   1

◆ Load() [1/2]

static cytnx::Bond cytnx::Bond::Load ( const char *  fname)
static

◆ Load() [2/2]

static cytnx::Bond cytnx::Bond::Load ( const std::string &  fname)
static

Load the Bond object from the file.

Parameters
[in]fnamethe file name of the Bond object.
Precondition
The file need to be the file of Bond object, which is saved by the function Bond::Save(const std::string &fname) const.

◆ Nsym()

cytnx_uint32 cytnx::Bond::Nsym ( ) const
inline

return the number of the symmetries

Returns
[cytnx_uint32]

◆ operator!=()

bool cytnx::Bond::operator!= ( const Bond rhs) const

The comparison operator 'not equal to'.

The comparison operators to compare two Bonds. More precisely, it is the opposite result of the operator==(const Bond &rhs) const.

See also
operator==(const Bond &rhs) const

◆ operator*()

Bond cytnx::Bond::operator* ( const Bond rhs) const
inline

The multiplication operator of the Bond object.

The multiplication operator of the Bond means that Combine two Bond. So this operator is same as combineBond. The following code are same result:

// bd1, bd2 and bd3 are Bond objects.
bd3 = bd1.combineBond(bd2);
// bd1, bd2 and bd3 are Bond objects.
bd3 = bd1 * bd2;
See also
operator*=(const Bond &rhs), combineBond(const Bond &bd_in, const bool &is_grp) const

◆ operator*=()

Bond & cytnx::Bond::operator*= ( const Bond rhs)
inline

The multiplication assignment operator of the Bond object.

The multiplication assignment operator of the Bond means that Combine two Bond inplacely, So this operator is same as combineBond_. The following code are same result:

// bd1 and bd2 are Bond objects.
bd1.combineBond_(bd2);
// bd1 and bd2 are Bond objects.
bd1 *= bd2;
See also
operator*(const Bond &rhs) const, combineBond_(const Bond &bd_in, const bool &is_grp)

◆ operator==()

bool cytnx::Bond::operator== ( const Bond rhs) const

The comparison operator 'equal to'.

The comparison operators to compare two Bonds. If two Bond object are same, return true. Otherwise, return false. This equal to operator will compare all the "value" of the Bond object. Even the Bond object are different object (different address), but they are same "value", it will return true.

See also
operator!=(const Bond &rhs) const

◆ qnums() [1/2]

std::vector< std::vector< cytnx_int64 > > & cytnx::Bond::qnums ( )
inline
See also
qnums() const

◆ qnums() [2/2]

const std::vector< std::vector< cytnx_int64 > > & cytnx::Bond::qnums ( ) const
inline

return the current quantum number set(s) by reference

Returns
[2d vector] with shape: (dim, # of Symmetry)
Note
Compare to qnums_clone(), this function return reference.

◆ qnums_clone()

std::vector< std::vector< cytnx_int64 > > cytnx::Bond::qnums_clone ( ) const
inline

return the clone (deep copy) of the current quantum number set(s)

Returns
[2d vector] with shape: (dim, # of Symmetry)
Note
Compare to qnums(), this function return the clone (deep copy).

◆ redirect()

Bond cytnx::Bond::redirect ( ) const
inline

create a new instance of Bond with type changed in between bondType.BD_BRA / bondType.BD_KET.

◆ redirect_()

Bond & cytnx::Bond::redirect_ ( )
inline

Change the bond type between bondType.BD_BRA and bondType.BD_KET in the Bond.

◆ retype()

Bond cytnx::Bond::retype ( const bondType new_bondType)
inline

create a new instance of Bond with type changed to the new tag-type.

Parameters
[in]new_bondTypethe new tag-type, it can be bondType.BD_BRA, bondType.BD_KET or bondType.BD_REG. See cytnx::bondType.
Note
This is equivalent to Bond.clone().set_type()
Attention
You cannot change the symmetry bond (bondType.BD_BRA or bondType.BD_KET to regular type (bondType.BD_REG) except the size of the quantum number is 0.
See also
clone(), set_type(const bondType & new_bondType)

◆ Save() [1/2]

void cytnx::Bond::Save ( const char *  fname) const

◆ Save() [2/2]

void cytnx::Bond::Save ( const std::string &  fname) const

Save the Bond object to the file.

Save the Bond object to the file. The file extension will be automatically added as ".cybd".

Parameters
[in]fnamethe file name of the Bond object (exclude the file extension).
See also
Load(const std::string &fname)

◆ set_type()

Bond & cytnx::Bond::set_type ( const bondType new_bondType)
inline

change the tag-type of the instance Bond

Parameters
[in]new_bondTypethe new tag-type, it can be bondType.BD_BRA, boncType.BD_KET or bondType.BD_REG. See cytnx::bondType.
Attention
You cannot change the symmetry bond (bondType.BD_BRA or bondType.BD_KET to regular type (bondType.BD_REG) except the size of the quantum number is 0.

◆ syms() [1/2]

std::vector< Symmetry > & cytnx::Bond::syms ( )
inline
See also
syms() const

◆ syms() [2/2]

const std::vector< Symmetry > & cytnx::Bond::syms ( ) const
inline

return the vector of symmetry objects by reference.

Note
Compare to syms_clone() const, this function return by reference.
Returns
[vector of Symmetry]

◆ syms_clone()

std::vector< Symmetry > cytnx::Bond::syms_clone ( ) const
inline

return copy of the vector of symmetry objects.

Note
Compare to syms() const, this function return the clone (deep copy).
Returns
[vector of Symmetry]

◆ type()

bondType cytnx::Bond::type ( ) const
inline

return the current bond type (see cytnx::bondType).

Returns
cytnx::bondType

The documentation for this class was generated from the following file: