Skip to content

Commit 2286ad8

Browse files
committed
A few changes 1. Heisenberg model has been added, 2. btas library has been added 3. USE_BTAS flas is added to makefile to disable btas library
1 parent b5dbbfe commit 2286ad8

39 files changed

+1359
-139
lines changed

Operators.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ void SpinAdapted::CreCreDesComp::build(const SpinBlock& b)
739739
SpinAdapted::operatorfunctions::TensorTrace(rightBlock, *op, &b, &(b.get_stateInfo()), *this, 1.0);
740740
}
741741

742-
if (dmrginp.hamiltonian() == QUANTUM_CHEMISTRY){
742+
if (dmrginp.hamiltonian() != HUBBARD){
743743
if (loopBlock->has(CRE_DESCOMP))
744744
{
745745

@@ -904,7 +904,7 @@ void SpinAdapted::Ham::build(const SpinBlock& b)
904904
f = boost::bind(&opxop::cxcddcomp, rightBlock, _1, &b, op_add);
905905
for_all_multithread(leftBlock->get_op_array(CRE), f);
906906

907-
if (dmrginp.hamiltonian() == QUANTUM_CHEMISTRY) {
907+
if (dmrginp.hamiltonian() != HUBBARD) {
908908
op_add = (otherBlock->get_op_array(CRE_DESCOMP).is_local() && loopBlock->get_op_array(CRE_DES).is_local())? op_array : op_distributed;
909909
f = boost::bind(&opxop::cdxcdcomp, otherBlock, _1, &b, op_add);
910910
for_all_multithread(loopBlock->get_op_array(CRE_DES), f);

StateInfo.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,20 @@ class StateInfo
6262

6363
std::vector<SpinQuantum> quanta; //the quantas present
6464
std::vector<int> quantaStates; //the number of each quanta
65-
ObjectMatrix<char> allowedQuanta; //
66-
ObjectMatrix< std::vector<int> > quantaMap;
67-
std::vector<int> leftUnMapQuanta;
65+
ObjectMatrix<char> allowedQuanta; //tensor product of left and right stateinfo states
66+
67+
//takes i and j quanta of the left and the right state and gives a vector of all resulting quantas. (for abelian symmetry the vector would be of length 1)
68+
ObjectMatrix< std::vector<int> > quantaMap;
69+
70+
//for the uncollectedstateinfo each quanta is made up of a left and a right quanta, these two vectors unmap an uncollected quata back to the left and the right quanta.
71+
std::vector<int> leftUnMapQuanta;
6872
std::vector<int> rightUnMapQuanta;
6973

7074
int totalStates;
75+
76+
//the next three are concerned with blocking and unblocking the states
7177
std::vector<int> unBlockedIndex;
72-
std::vector< std::vector<int> > oldToNewState;
78+
std::vector< std::vector<int> > oldToNewState; //quanta[I] is the same as quanta[Ij] where Ij are the indices inside the Ith vector.
7379
std::vector<int> newQuantaMap;
7480
bool initialised;
7581
public:

btas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 41f057fc97409503653d19abb60853c33a599a94

csf.C

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,21 @@ std::vector<SpinAdapted::Csf > SpinAdapted::CSFUTIL::spinfockstrings(const std::
336336
occ_rep2[dmrginp.spatial_to_spin()[I]+2*irrepsize-2] = 1;
337337
Slater s1(occ_rep1, 1), s2(occ_rep2, 1); map<Slater, double > m1, m2;
338338
m1[s1]= 1.0; m2[s2] = 1.0;
339+
340+
if(dmrginp.hamiltonian() == HEISENBERG) {
341+
thisSiteCsf.push_back( Csf(m2, 1, SpinSpace(1), 1, IrrepVector(Irrep.getirrep(), irrepsize-1))); //1,1,L
342+
for (int i=tensorops[0].Szops.size(); i> 0; i--)
343+
ladderentry.push_back(applyTensorOp(tensorops[0], i-1));
344+
singleSiteLadder.push_back(ladderentry);
345+
346+
numcsfs.push_back(thisSiteCsf.size());
347+
for (int i=0; i<thisSiteCsf.size(); i++)
348+
singleSiteCsf.push_back( thisSiteCsf[i]);
349+
continue;
350+
}
351+
339352
thisSiteCsf.push_back( Csf(m1, 0, SpinSpace(0), 0, IrrepVector(0,0))); //0,0,0
340-
thisSiteCsf.push_back( Csf(m2, 1, SpinSpace(1), 1, IrrepVector(Irrep.getirrep(), irrepsize-1))); //1,1,L
341-
353+
thisSiteCsf.push_back( Csf(m2, 1, SpinSpace(1), 1, IrrepVector(Irrep.getirrep(), irrepsize-1))); //1,1,L
342354
ladderentry.push_back(Csf(m1, 0, SpinSpace(0), 0, IrrepVector(0,0))); singleSiteLadder.push_back(ladderentry);
343355
ladderentry.clear();
344356

@@ -525,13 +537,15 @@ std::vector< SpinAdapted::Csf > SpinAdapted::Csf::distribute (const int n, const
525537
na = (n + sp) / 2;
526538
nb = (n - sp) / 2;
527539

540+
if(dmrginp.hamiltonian() == HEISENBERG && nb != 0) return s;
528541
// let's count how many left and right orbitals there actually are
529542
int actualOrbs = dmrginp.spatial_to_spin()[right] - dmrginp.spatial_to_spin()[left];
530543
int actualNA, actualNB;
531544
actualNA = actualOrbs/2;
532545
actualNB = actualOrbs/2;
533546

534-
// cannot form this combination
547+
// cannot form this combination
548+
535549
if (na > actualNA || nb > actualNB || na < 0 || nb < 0)
536550
{
537551
return s;

density.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void DensityMatrix::add_onedot_noise(const std::vector<Wavefunction>& wave_solut
256256
for_all_multithread(leftBlock->get_op_array(CRE), onedot_noise);
257257
}
258258

259-
if (dmrginp.hamiltonian() == QUANTUM_CHEMISTRY) {
259+
if (dmrginp.hamiltonian() != HUBBARD) {
260260
if (leftBlock->has(CRE_CRE))
261261
{
262262
onedot_noise.set_opType(CRE_CRE);

dmrg.C

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Sandeep Sharma and Garnet K.-L. Chan
5050

5151
void dmrg(double sweep_tol);
5252
void restart(double sweep_tol, bool reset_iter);
53+
void dmrg_stateSpecific(double sweep_tol, int targetState);
5354
void ReadInput(char* conf);
5455
void fullrestartGenblock();
5556
void license() {
@@ -107,8 +108,15 @@ int calldmrg(char* input, char* output)
107108

108109
SweepParams sweep_copy;
109110
bool direction_copy; int restartsize_copy;
110-
111-
111+
112+
/*
113+
{
114+
SweepParams sweepParams;
115+
sweepParams.ls_dw.resize(0);
116+
sweepParams.ls_energy.resize(0);
117+
Sweep::do_overlap(sweepParams, false, true, false, 0);
118+
}
119+
*/
112120
switch(dmrginp.calc_type()) {
113121

114122
case (DMRG):
@@ -292,6 +300,7 @@ int calldmrg(char* input, char* output)
292300

293301
break;
294302
}
303+
//case (EXCITEDDMRG) :
295304

296305
return 0;
297306

@@ -339,6 +348,7 @@ void restart(double sweep_tol, bool reset_iter)
339348
int domoreIter = 2;
340349

341350
sweepParams.restorestate(direction, restartsize);
351+
342352
if(reset_iter) { //this is when you restart from the start of the sweep
343353
sweepParams.set_sweep_iter() = 0;
344354
sweepParams.set_restart_iter() = 0;
@@ -422,11 +432,12 @@ void dmrg(double sweep_tol)
422432
bool dodiis = false;
423433

424434
int domoreIter = 0;
435+
bool direction;
425436

426437
//initialize array of size m_maxiter or dmrginp.max_iter() for dw and energy
427-
428-
438+
sweepParams.current_root() = 0;
429439
last_fe = Sweep::do_one(sweepParams, true, true, false, 0);
440+
direction = false;
430441
while ((fabs(last_fe - old_fe) > sweep_tol) || (fabs(last_be - old_be) > sweep_tol) ||
431442
(dmrginp.algorithm_method() == TWODOT_TO_ONEDOT && dmrginp.twodot_to_onedot_iter()+1 >= sweepParams.get_sweep_iter()) )
432443
{
@@ -435,6 +446,7 @@ void dmrg(double sweep_tol)
435446
if(dmrginp.max_iter() <= sweepParams.get_sweep_iter())
436447
break;
437448
last_be = Sweep::do_one(sweepParams, false, false, false, 0);
449+
direction = true;
438450
if (dmrginp.outputlevel() > 0)
439451
pout << "Finished Sweep Iteration "<<sweepParams.get_sweep_iter()<<endl;
440452

@@ -458,6 +470,7 @@ void dmrg(double sweep_tol)
458470
}
459471

460472
last_fe = Sweep::do_one(sweepParams, false, true, false, 0);
473+
direction = false;
461474

462475
new_states=sweepParams.get_keep_states();
463476

@@ -486,5 +499,73 @@ void dmrg(double sweep_tol)
486499
}
487500

488501
const int nroots = dmrginp.nroots(sweepParams.get_sweep_iter());
502+
503+
if(nroots > 1 && dmrginp.doStateSpecific()) {
504+
dmrginp.setStateSpecific() = true;
505+
for (int i=0; i<nroots; i++) {
506+
if (i != 0)
507+
SweepGenblock::do_one(sweepParams, false, direction, false, 0, i);
508+
dmrg_stateSpecific(sweep_tol, i);
509+
}
510+
}
511+
}
512+
513+
void dmrg_stateSpecific(double sweep_tol, int targetState)
514+
{
515+
double last_fe = 10.e6;
516+
double last_be = 10.e6;
517+
double old_fe = 0.;
518+
double old_be = 0.;
519+
int ls_count=0;
520+
SweepParams sweepParams;
521+
int old_states=sweepParams.get_keep_states();
522+
int new_states;
523+
double old_error=0.0;
524+
double old_energy=0.0;
525+
// warm up sweep ...
526+
527+
bool direction;
528+
int restartsize;
529+
sweepParams.restorestate(direction, restartsize);
530+
531+
//initialize array of size m_maxiter or dmrginp.max_iter() for dw and energy
532+
sweepParams.current_root() = targetState;
533+
534+
sweepParams.set_sweep_iter() = 0;
535+
sweepParams.set_restart_iter() = 0;
536+
537+
last_fe = Sweep::do_one(sweepParams, false, direction, true, 0);
538+
539+
while ((fabs(last_fe - old_fe) > sweep_tol) || (fabs(last_be - old_be) > sweep_tol) )
540+
{
541+
old_fe = last_fe;
542+
old_be = last_be;
543+
if(dmrginp.max_iter() <= 10) //CHANGE THIS TO SOME INPUT PARAMETER
544+
break;
545+
last_be = Sweep::do_one(sweepParams, false, !direction, false, 0);
546+
if (dmrginp.outputlevel() > 0)
547+
pout << "Finished Sweep Iteration "<<sweepParams.get_sweep_iter()<<endl;
548+
549+
if(dmrginp.max_iter() <= sweepParams.get_sweep_iter())
550+
break;
551+
552+
553+
last_fe = Sweep::do_one(sweepParams, false, direction, false, 0);
554+
555+
new_states=sweepParams.get_keep_states();
556+
557+
558+
if (dmrginp.outputlevel() > 0)
559+
pout << "Finished Sweep Iteration "<<sweepParams.get_sweep_iter()<<endl;
560+
561+
}
562+
if(dmrginp.max_iter() <= sweepParams.get_sweep_iter()) {
563+
564+
pout << "Maximum sweep iterations achieved " << std::endl;
565+
}
566+
567+
//SweepGenblock::makeRotationsAndOverlaps(sweepParams, false, !direction, targetState);
568+
//SweepGenblock::makeRotationsAndOverlaps(sweepParams, false, direction, targetState);
569+
const int nroots = dmrginp.nroots(sweepParams.get_sweep_iter());
489570
}
490571

dmrg_tests/heisenberg_2d/FCIDUMP

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
&FCI NORB= 16,NELEC= 16,MS2= 0,
2+
ORBSYM=1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
3+
ISYM=1
4+
&END
5+
-0.25 1 1 13 13
6+
-0.5 1 13 13 1
7+
-0.25 1 1 5 5
8+
-0.5 1 5 5 1
9+
-0.25 1 1 4 4
10+
-0.5 1 4 4 1
11+
-0.25 1 1 2 2
12+
-0.5 1 2 2 1
13+
-0.25 2 2 14 14
14+
-0.5 2 14 14 2
15+
-0.25 2 2 6 6
16+
-0.5 2 6 6 2
17+
-0.25 2 2 3 3
18+
-0.5 2 3 3 2
19+
-0.25 3 3 15 15
20+
-0.5 3 15 15 3
21+
-0.25 3 3 7 7
22+
-0.5 3 7 7 3
23+
-0.25 3 3 4 4
24+
-0.5 3 4 4 3
25+
-0.25 4 4 16 16
26+
-0.5 4 16 16 4
27+
-0.25 4 4 8 8
28+
-0.5 4 8 8 4
29+
-0.25 5 5 9 9
30+
-0.5 5 9 9 5
31+
-0.25 5 5 8 8
32+
-0.5 5 8 8 5
33+
-0.25 5 5 6 6
34+
-0.5 5 6 6 5
35+
-0.25 6 6 10 10
36+
-0.5 6 10 10 6
37+
-0.25 6 6 7 7
38+
-0.5 6 7 7 6
39+
-0.25 7 7 11 11
40+
-0.5 7 11 11 7
41+
-0.25 7 7 8 8
42+
-0.5 7 8 8 7
43+
-0.25 8 8 12 12
44+
-0.5 8 12 12 8
45+
-0.25 9 9 13 13
46+
-0.5 9 13 13 9
47+
-0.25 9 9 12 12
48+
-0.5 9 12 12 9
49+
-0.25 9 9 10 10
50+
-0.5 9 10 10 9
51+
-0.25 10 10 14 14
52+
-0.5 10 14 14 10
53+
-0.25 10 10 11 11
54+
-0.5 10 11 11 10
55+
-0.25 11 11 15 15
56+
-0.5 11 15 15 11
57+
-0.25 11 11 12 12
58+
-0.5 11 12 12 11
59+
-0.25 12 12 16 16
60+
-0.5 12 16 16 12
61+
-0.25 13 13 16 16
62+
-0.5 13 16 16 13
63+
-0.25 13 13 14 14
64+
-0.5 13 14 14 13
65+
-0.25 14 14 15 15
66+
-0.5 14 15 15 14
67+
-0.25 15 15 16 16
68+
-0.5 15 16 16 15

dmrg_tests/heisenberg_2d/dmrg.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
nelec 16
2+
spin 0
3+
4+
5+
hf_occ integral
6+
schedule
7+
0 100 1.0e-6 1e-05
8+
4 500 1e-6 1.0e-6
9+
end
10+
maxiter 20
11+
twodot_to_onedot 10
12+
sweep_tol 1e-9
13+
14+
orbitals FCIDUMP
15+
16+
heisenberg
17+
18+
outputlevel 2

dmrg_tests/runtest

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ python ../test_energy.py 1 1.0e-6 -6.56819216
3232
python ../test_onepdm.py spatial_onepdm.0.0 spat_onepdm.0.0 1e-7
3333
cd ../
3434

35-
35+
echo "performing heisenberg test..."
36+
cd heisenberg_2d
37+
../../block.spin_adapted dmrg.conf >dmrg.out
38+
python ../test_energy.py 1 1.0e-6 -11.2284830996
39+
cd ../
3640

3741
#this first calculated twopdm with a small M for two lowest states (so the energy is not converged)
3842
#checks if the twopdm traced with integrals matches the energies

fci.C

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ void SpinAdapted::Sweep::fullci(double sweep_tol)
7575
double tol = sweepParams.get_davidson_tol();
7676

7777
pout << "\t\t\t Solving the Wavefunction "<<endl;
78-
Solver::solve_wavefunction(solution, energies, big, tol, BASIC, false, true, false, sweepParams.get_additional_noise());
78+
int currentState = 0;
79+
std::vector<Wavefunction> lowerStates;
80+
Solver::solve_wavefunction(solution, energies, big, tol, BASIC, false, true, false, sweepParams.get_additional_noise(), currentState, lowerStates);
7981
for (int i=0; i<nroots; i++) {
8082
pout << "fullci energy "<< energies[i]+dmrginp.get_coreenergy()<<endl;
8183
}

0 commit comments

Comments
 (0)