void responseSweep(double sweep_tol, int targetState, vector<int>& projectors, vector<int>& baseStates) { double last_fe = 1.e6; double last_be = 1.e6; double old_fe = 0.; double old_be = 0.; SweepParams sweepParams; bool direction, warmUp, restart; int restartSize=0; direction = true; //forward warmUp = true; //startup sweep restart = false; //not a restart sweepParams.current_root() = -1; algorithmTypes atype = dmrginp.algorithm_method(); dmrginp.set_algorithm_method() = ONEDOT; //the baseState is the initial guess for the targetState if (FULLRESTART) { sweepParams.restorestate(direction, restartSize); direction = !direction; dmrginp.setGuessState() = targetState; last_fe = SweepResponse::do_one(sweepParams, warmUp, direction, restart, restartSize, targetState, projectors, baseStates); bool tempdirection; sweepParams.restorestate(tempdirection, restartSize); sweepParams.calc_niter(); sweepParams.set_sweep_iter() = 0; sweepParams.set_restart_iter() = 0; sweepParams.savestate(tempdirection, restartSize); } else if (RESTART) { dmrginp.set_algorithm_method() = atype; warmUp = false; restart = true; sweepParams.restorestate(direction, restartSize); last_fe = SweepResponse::do_one(sweepParams, warmUp, direction, restart, restartSize, targetState, projectors, baseStates); } else last_fe = SweepResponse::do_one(sweepParams, warmUp, direction, restart, restartSize, targetState, projectors, baseStates); dmrginp.set_algorithm_method() = atype; restart = false; restartSize = 0; warmUp = false; while ( true) { old_fe = last_fe; old_be = last_be; if(dmrginp.max_iter() <= sweepParams.get_sweep_iter()) break; last_be = SweepResponse::do_one(sweepParams, warmUp, !direction, restart, restartSize, targetState, projectors, baseStates); p1out << "\t\t\t Finished Sweep Iteration "<<sweepParams.get_sweep_iter()<<endl; if(dmrginp.max_iter() <= sweepParams.get_sweep_iter()) break; last_fe = SweepResponse::do_one(sweepParams, warmUp, direction, restart, restartSize, targetState, projectors, baseStates); pout << "\t\t\t Finished Sweep Iteration "<<sweepParams.get_sweep_iter()<<endl; } }
int calldmrg(char* input, char* output) { //sleep(15); streambuf *backup; backup = cout.rdbuf(); ofstream file; if (output != 0) { file.open(output); pout.rdbuf(file.rdbuf()); } license(); ReadInput(input); MAX_THRD = dmrginp.thrds_per_node()[mpigetrank()]; #ifdef _OPENMP omp_set_num_threads(MAX_THRD); #endif pout.precision (12); //Initializing timer calls dmrginp.initCumulTimer(); double sweep_tol = 1e-7; sweep_tol = dmrginp.get_sweep_tol(); bool direction; int restartsize; SweepParams sweepParams; SweepParams sweep_copy; bool direction_copy; int restartsize_copy; Matrix O, H; switch(dmrginp.calc_type()) { case (COMPRESS): { bool direction; int restartsize; //sweepParams.restorestate(direction, restartsize); //sweepParams.set_sweep_iter() = 0; restartsize = 0; int targetState, baseState, correctionVector, firstorderstate; { direction = true; //base state is always defined baseState = dmrginp.baseStates()[0]; //if targetstate is given use it otherwise use basestate+1 if(dmrginp.targetState() == -1) targetState = dmrginp.baseStates()[0]+1; else targetState = dmrginp.targetState(); algorithmTypes atype = dmrginp.algorithm_method(); dmrginp.set_algorithm_method() = ONEDOT; //initialize state info and canonicalize wavefunction is always done using onedot algorithm if (mpigetrank()==0) { Sweep::InitializeStateInfo(sweepParams, direction, baseState); Sweep::InitializeStateInfo(sweepParams, !direction, baseState); Sweep::CanonicalizeWavefunction(sweepParams, direction, baseState); Sweep::CanonicalizeWavefunction(sweepParams, !direction, baseState); Sweep::CanonicalizeWavefunction(sweepParams, direction, baseState); } dmrginp.set_algorithm_method() = atype; } //this genblock is required to generate all the nontranspose operators dmrginp.setimplicitTranspose() = false; SweepGenblock::do_one(sweepParams, false, false, false, restartsize, baseState, baseState); compress(sweep_tol, targetState, baseState); break; } case (RESPONSEBW): { //compressing the V|\Psi_0>, here \Psi_0 is the basestate and //its product with V will have a larger bond dimension and is being compressed //it is called the target state dmrginp.setimplicitTranspose() = false; sweepParams.restorestate(direction, restartsize); algorithmTypes atype = dmrginp.algorithm_method(); dmrginp.set_algorithm_method() = ONEDOT; if (mpigetrank()==0 && !RESTART && !FULLRESTART) { for (int l=0; l<dmrginp.projectorStates().size(); l++) { Sweep::InitializeStateInfo(sweepParams, direction, dmrginp.projectorStates()[l]); Sweep::InitializeStateInfo(sweepParams, !direction, dmrginp.projectorStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, direction, dmrginp.projectorStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, !direction, dmrginp.projectorStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, direction, dmrginp.projectorStates()[l]); } for (int l=0; l<dmrginp.baseStates().size(); l++) { Sweep::InitializeStateInfo(sweepParams, direction, dmrginp.baseStates()[l]); Sweep::InitializeStateInfo(sweepParams, !direction, dmrginp.baseStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, direction, dmrginp.baseStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, !direction, dmrginp.baseStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, direction, dmrginp.baseStates()[l]); } } dmrginp.set_algorithm_method() = atype; pout << "DONE COMPRESSING THE CORRECTION VECTOR"<<endl; pout << "NOW WE WILL OPTIMIZE THE RESPONSE WAVEFUNCTION"<<endl; //finally now calculate the response state responseSweep(sweep_tol, dmrginp.targetState(), dmrginp.projectorStates(), dmrginp.baseStates()); break; } case (RESPONSE): { //compressing the V|\Psi_0>, here \Psi_0 is the basestate and //its product with V will have a larger bond dimension and is being compressed //it is called the target state dmrginp.setimplicitTranspose() = false; sweepParams.restorestate(direction, restartsize); algorithmTypes atype = dmrginp.algorithm_method(); dmrginp.set_algorithm_method() = ONEDOT; if (mpigetrank()==0 && !RESTART && !FULLRESTART) { for (int l=0; l<dmrginp.projectorStates().size(); l++) { Sweep::InitializeStateInfo(sweepParams, direction, dmrginp.projectorStates()[l]); Sweep::InitializeStateInfo(sweepParams, !direction, dmrginp.projectorStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, direction, dmrginp.projectorStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, !direction, dmrginp.projectorStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, direction, dmrginp.projectorStates()[l]); } for (int l=0; l<dmrginp.baseStates().size(); l++) { Sweep::InitializeStateInfo(sweepParams, direction, dmrginp.baseStates()[l]); Sweep::InitializeStateInfo(sweepParams, !direction, dmrginp.baseStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, direction, dmrginp.baseStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, !direction, dmrginp.baseStates()[l]); Sweep::CanonicalizeWavefunction(sweepParams, direction, dmrginp.baseStates()[l]); } } dmrginp.set_algorithm_method() = atype; pout << "DONE COMPRESSING THE CORRECTION VECTOR"<<endl; pout << "NOW WE WILL OPTIMIZE THE RESPONSE WAVEFUNCTION"<<endl; //finally now calculate the response state responseSweep(sweep_tol, dmrginp.targetState(), dmrginp.projectorStates(), dmrginp.baseStates()); break; } case (CALCOVERLAP): { pout.precision(12); if (mpigetrank() == 0) { for (int istate = 0; istate<dmrginp.nroots(); istate++) { bool direction; int restartsize; sweepParams.restorestate(direction, restartsize); Sweep::InitializeStateInfo(sweepParams, !direction, istate); Sweep::InitializeStateInfo(sweepParams, direction, istate); Sweep::CanonicalizeWavefunction(sweepParams, direction, istate); Sweep::CanonicalizeWavefunction(sweepParams, !direction, istate); Sweep::CanonicalizeWavefunction(sweepParams, direction, istate); } for (int istate = 0; istate<dmrginp.nroots(); istate++) for (int j=istate; j<dmrginp.nroots() ; j++) { int integralIndex = 0; Sweep::InitializeOverlapSpinBlocks(sweepParams, !direction, j, istate, integralIndex); Sweep::InitializeOverlapSpinBlocks(sweepParams, direction, j, istate, integralIndex); } //Sweep::calculateAllOverlap(O); } break; } case (CALCHAMILTONIAN): { pout.precision(12); for (int istate = 0; istate<dmrginp.nroots(); istate++) { bool direction; int restartsize; sweepParams.restorestate(direction, restartsize); if (mpigetrank() == 0) { Sweep::InitializeStateInfo(sweepParams, !direction, istate); Sweep::InitializeStateInfo(sweepParams, direction, istate); Sweep::CanonicalizeWavefunction(sweepParams, !direction, istate); Sweep::CanonicalizeWavefunction(sweepParams, direction, istate); Sweep::CanonicalizeWavefunction(sweepParams, !direction, istate); } } //Sweep::calculateHMatrixElements(H); pout << "overlap "<<endl<<O<<endl; pout << "hamiltonian "<<endl<<H<<endl; break; } case (DMRG): { if (RESTART && !FULLRESTART) restart(sweep_tol, reset_iter); else if (FULLRESTART) { fullrestartGenblock(); reset_iter = true; sweepParams.restorestate(direction, restartsize); sweepParams.calc_niter(); sweepParams.savestate(direction, restartsize); restart(sweep_tol, reset_iter); } else if (BACKWARD) { fullrestartGenblock(); reset_iter = true; sweepParams.restorestate(direction, restartsize); sweepParams.calc_niter(); sweepParams.savestate(direction, restartsize); restart(sweep_tol, reset_iter); } else { dmrg(sweep_tol); } break; } case (FCI): Sweep::fullci(sweep_tol); break; case (TINYCALC): Sweep::tiny(sweep_tol); break; case (ONEPDM): Npdm::npdm(NPDM_ONEPDM); if (dmrginp.hamiltonian() == BCS) { Npdm::npdm(NPDM_PAIRMATRIX,true); } break; case (TWOPDM): Npdm::npdm(NPDM_TWOPDM); break; case (THREEPDM): Npdm::npdm(NPDM_THREEPDM); break; case (FOURPDM): Npdm::npdm(NPDM_FOURPDM); break; case (NEVPT2PDM): Npdm::npdm(NPDM_NEVPT2); break; case(NEVPT2): nevpt2::nevpt2(); break; case(MPS_NEVPT): mps_nevpt::mps_nevpt(sweep_tol); break; case(RESTART_MPS_NEVPT): mps_nevpt::mps_nevpt(sweep_tol); break; case (RESTART_ONEPDM): Npdm::npdm(NPDM_ONEPDM,true); if (dmrginp.hamiltonian() == BCS) { Npdm::npdm(NPDM_PAIRMATRIX,true); } break; case (RESTART_TWOPDM): Npdm::npdm(NPDM_TWOPDM,true); break; case (RESTART_THREEPDM): Npdm::npdm(NPDM_THREEPDM,true); break; case (RESTART_FOURPDM): Npdm::npdm(NPDM_FOURPDM,true); break; case (RESTART_NEVPT2PDM): Npdm::npdm(NPDM_NEVPT2,true); break; case (TRANSITION_ONEPDM): Npdm::npdm(NPDM_ONEPDM,false,true); if (dmrginp.hamiltonian() == BCS) { Npdm::npdm(NPDM_PAIRMATRIX,true,true); } break; case (TRANSITION_TWOPDM): Npdm::npdm(NPDM_TWOPDM,false,true); break; case (TRANSITION_THREEPDM): Npdm::npdm(NPDM_THREEPDM,false,true); break; case (RESTART_T_ONEPDM): Npdm::npdm(NPDM_ONEPDM,true,true); if (dmrginp.hamiltonian() == BCS) { Npdm::npdm(NPDM_PAIRMATRIX,true,true); } break; case (RESTART_T_TWOPDM): Npdm::npdm(NPDM_TWOPDM,true,true); break; case (RESTART_T_THREEPDM): Npdm::npdm(NPDM_THREEPDM,true,true); break; case(RESTART_NEVPT2): nevpt2::nevpt2_restart(); break; //EL case (DS1_ONEPDM): Npdm::npdm(NPDM_DS1,false,true,true); break; case (RESTART_DS1_ONEPDM): Npdm::npdm(NPDM_DS1,true,true,true); break; case (DS0_ONEPDM): Npdm::npdm(NPDM_DS0,false,true,true); break; case (RESTART_DS0_ONEPDM): Npdm::npdm(NPDM_DS0,true,true,true); break; //EL default: pout << "Invalid calculation types" << endl; abort(); } cout.rdbuf(backup); tcpu=globaltimer.totalcputime();twall=globaltimer.totalwalltime(); pout << setprecision(3) <<"\n\n\t\t\t BLOCK CPU Time (seconds): " << tcpu << endl; pout << setprecision(3) <<"\t\t\t BLOCK Wall Time (seconds): " << twall << endl; return 0; }