Hello,
Sorry to ask another question so soon. I am trying to print out the =20 groundstate eigenvector to study entanglement by modifying the =20 sparsediag program. I put a simple For loop in the sparsediag.h file =20 as shown below,
template <class T> void SparseDiagMatrix<T>::do_subspace() { typedef ietl::vectorspace<vector_type> vectorspace_type; boost::lagged_fibonacci607 generator; mag_vector_type ev; this->build(); if (this->dimension()=3D=3D0) return;
vectorspace_type vec(this->dimension()); ietl::lanczos<matrix_type,vectorspace_type> lanczos(this->matrix(),vec); int n;
if (this->dimension()>1) { int max_iter =3D =20 this->parms.value_or_default("MAX_ITERATIONS",std::min(int(10*this->dimensio= n()),1000)); int num_eigenvalues =3D =20 this->parms.value_or_default("NUMBER_EIGENVALUES",1); ietl::lanczos_iteration_nlowest<double> iter(max_iter,num_eigenvalues); std::cerr << "Starting Lanczos \n"; lanczos.calculate_eigenvalues(iter,generator); std::cerr << "Finished Lanczos\n"; n=3Dstd::min(num_eigenvalues,int(lanczos.eigenvalues().size())); ev.resize(n); for (int i=3D0;i<n;++i) ev[i]=3Dlanczos.eigenvalues()[i]; } else { ev.resize(1); ev[0]=3Dalps::real(value_type(this->matrix()(0,0))); } if (this->calc_averages()) { if (this->dimension()>1) { // calculate eigen vectors ietl::Info<magnitude_type> info; // (m1, m2, ma, eigenvalue, =20 residualm, status).
try { eigenvectors.clear(); =20 lanczos.eigenvectors(lanczos.eigenvalues().begin(),lanczos.eigenvalues().beg= in()+n, std::back_inserter(eigenvectors),info,generato= r);
=09=09 //code to print eigenvectors =09=09 for (int i=3D0;i<eigenvectors.size();++i) =09=09 { =09=09=09 std::cout << eigenvectors[i] << "\n";
=09=09 }
} catch (std::runtime_error& e) { std::cout <<"Exception during eigenvector calculation: " << =20 e.what() << "\n";
} } =09 else { vector_type v(1); v[0]=3D1.; eigenvectors.push_back(v);
}
}
this->perform_measurements(); eigenvectors.clear(); =20 std::copy(ev.begin(),ev.end(),std::back_inserter(this->measurements_.rbegin(= )->average_values["Energy"])); this->eigenvalues_.push_back(ev);
}
the following output is given for a 4 site spin 1/2 chain with J=3D1,
Starting task 1. Quantumnumber Sz going from -2 to 2 with increment 1 Starting Lanczos Finished Lanczos [2]((-0.57735,0),(0.816497,0)) Starting Lanczos Finished Lanczos [2]((1.11022e-16,-8.65927e-17),(1,-4.98226e-17))
The problem is these numbers don't make sense at all, and when I try =20 to get the size of the eigenvector with eigenvector.size() it gives 1. =20 Any help or hints would be gratefully appreciated. Also any help or =20 hints about my other question about combining print_numeric and =20 sparsediag to get the ground state vector would be much appreciated.
Thanks
eigenvectors.size() gives the number of eigenvectors that were calculated, not the size of one. To print the size, print e.g. eigenvectors[0].size(). I hope this helps.
Matthias
Sent from my iPad
On Sep 2, 2010, at 4:51, rexlundgren@mail.utexas.edu wrote:
Hello,
Sorry to ask another question so soon. I am trying to print out the =20 groundstate eigenvector to study entanglement by modifying the =20 sparsediag program. I put a simple For loop in the sparsediag.h file =20 as shown below,
template <class T> void SparseDiagMatrix<T>::do_subspace() { typedef ietl::vectorspace<vector_type> vectorspace_type; boost::lagged_fibonacci607 generator; mag_vector_type ev; this->build(); if (this->dimension()=3D=3D0) return;
vectorspace_type vec(this->dimension()); ietl::lanczos<matrix_type,vectorspace_type> lanczos(this->matrix(),vec); int n;
if (this->dimension()>1) { int max_iter =3D =20 this->parms.value_or_default("MAX_ITERATIONS",std::min(int(10*this->dimensio= n()),1000)); int num_eigenvalues =3D =20 this->parms.value_or_default("NUMBER_EIGENVALUES",1); ietl::lanczos_iteration_nlowest<double> iter(max_iter,num_eigenvalues); std::cerr << "Starting Lanczos \n"; lanczos.calculate_eigenvalues(iter,generator); std::cerr << "Finished Lanczos\n"; n=3Dstd::min(num_eigenvalues,int(lanczos.eigenvalues().size())); ev.resize(n); for (int i=3D0;i<n;++i) ev[i]=3Dlanczos.eigenvalues()[i]; } else { ev.resize(1); ev[0]=3Dalps::real(value_type(this->matrix()(0,0))); } if (this->calc_averages()) { if (this->dimension()>1) { // calculate eigen vectors ietl::Info<magnitude_type> info; // (m1, m2, ma, eigenvalue, =20 residualm, status).
try { eigenvectors.clear(); =20
lanczos.eigenvectors(lanczos.eigenvalues().begin(),lanczos.eigenvalues().beg= in()+n, std::back_inserter(eigenvectors),info,generato= r);
=09=09 //code to print eigenvectors =09=09 for (int i=3D0;i<eigenvectors.size();++i) =09=09 { =09=09=09 std::cout << eigenvectors[i] << "\n";
=09=09 }
} catch (std::runtime_error& e) { std::cout <<"Exception during eigenvector calculation: " << =20
e.what() << "\n";
} }
=09 else { vector_type v(1); v[0]=3D1.; eigenvectors.push_back(v);
}
}
this->perform_measurements(); eigenvectors.clear(); =20 std::copy(ev.begin(),ev.end(),std::back_inserter(this->measurements_.rbegin(= )->average_values["Energy"])); this->eigenvalues_.push_back(ev);
}
the following output is given for a 4 site spin 1/2 chain with J=3D1,
Starting task 1. Quantumnumber Sz going from -2 to 2 with increment 1 Starting Lanczos Finished Lanczos [2]((-0.57735,0),(0.816497,0)) Starting Lanczos Finished Lanczos [2]((1.11022e-16,-8.65927e-17),(1,-4.98226e-17))
The problem is these numbers don't make sense at all, and when I try =20 to get the size of the eigenvector with eigenvector.size() it gives 1. =20 Any help or hints would be gratefully appreciated. Also any help or =20 hints about my other question about combining print_numeric and =20 sparsediag to get the ground state vector would be much appreciated.
Thanks
Hi, Thanks for the reply. When I try that with the following code inserted in the sparsediag.h file :
//orignal code
// calculate eigen vectors ietl::Info<magnitude_type> info; // (m1, m2, ma, eigenvalue, residualm, status).
try { eigenvectors.clear();
lanczos.eigenvectors(lanczos.eigenvalues().begin(),lanczos.eigenvalues().begin()+n, std::back_inserter(eigenvectors),info,generator);
} catch (std::runtime_error& e) { std::cout <<"Exception during eigenvector calculation: " << e.what() << "\n";
} } else { vector_type v(1); v[0]=1.; eigenvectors.push_back(v);
//new code to print out eigenvectors std::cout << eigenvectors[0].size() << " Size \n"; std::cout << eigenvectors[0] << "\n";
}
} // rest of code
The output is the following for a spin chain with L=4.
1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) Starting Lanczos Finished Lanczos 1 Size [1]((1,0)) Starting Lanczos Finished Lanczos 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0))
The problem is I don't know how to interpret this in terms of the original basis that is not within the subspace, or if there is still some problem in my code(maybe its in the wrong spot).
Thanks for the help
Rex
Quoting Matthias Troyer troyer@phys.ethz.ch:
eigenvectors.size() gives the number of eigenvectors that were calculated, not the size of one. To print the size, print e.g. eigenvectors[0].size(). I hope this helps.
Matthias
Sent from my iPad
On Sep 2, 2010, at 4:51, rexlundgren@mail.utexas.edu wrote:
Hello,
Sorry to ask another question so soon. I am trying to print out the =20 groundstate eigenvector to study entanglement by modifying the =20 sparsediag program. I put a simple For loop in the sparsediag.h file =20 as shown below,
template <class T> void SparseDiagMatrix<T>::do_subspace() { typedef ietl::vectorspace<vector_type> vectorspace_type; boost::lagged_fibonacci607 generator; mag_vector_type ev; this->build(); if (this->dimension()=3D=3D0) return;
vectorspace_type vec(this->dimension()); ietl::lanczos<matrix_type,vectorspace_type> lanczos(this->matrix(),vec); int n;
if (this->dimension()>1) { int max_iter =3D =20 this->parms.value_or_default("MAX_ITERATIONS",std::min(int(10*this->dimensio= n()),1000)); int num_eigenvalues =3D =20 this->parms.value_or_default("NUMBER_EIGENVALUES",1); ietl::lanczos_iteration_nlowest<double> iter(max_iter,num_eigenvalues); std::cerr << "Starting Lanczos \n"; lanczos.calculate_eigenvalues(iter,generator); std::cerr << "Finished Lanczos\n"; n=3Dstd::min(num_eigenvalues,int(lanczos.eigenvalues().size())); ev.resize(n); for (int i=3D0;i<n;++i) ev[i]=3Dlanczos.eigenvalues()[i]; } else { ev.resize(1); ev[0]=3Dalps::real(value_type(this->matrix()(0,0))); } if (this->calc_averages()) { if (this->dimension()>1) { // calculate eigen vectors ietl::Info<magnitude_type> info; // (m1, m2, ma, eigenvalue, =20 residualm, status).
try { eigenvectors.clear(); =20
lanczos.eigenvectors(lanczos.eigenvalues().begin(),lanczos.eigenvalues().beg= in()+n, std::back_inserter(eigenvectors),info,generato= r);
=09=09 //code to print eigenvectors =09=09 for (int i=3D0;i<eigenvectors.size();++i) =09=09 { =09=09=09 std::cout << eigenvectors[i] << "\n";
=09=09 }
} catch (std::runtime_error& e) { std::cout <<"Exception during eigenvector calculation: " << =20
e.what() << "\n";
} }
=09 else { vector_type v(1); v[0]=3D1.; eigenvectors.push_back(v);
}
}
this->perform_measurements(); eigenvectors.clear(); =20 std::copy(ev.begin(),ev.end(),std::back_inserter(this->measurements_.rbegin(= )->average_values["Energy"])); this->eigenvalues_.push_back(ev);
}
the following output is given for a 4 site spin 1/2 chain with J=3D1,
Starting task 1. Quantumnumber Sz going from -2 to 2 with increment 1 Starting Lanczos Finished Lanczos [2]((-0.57735,0),(0.816497,0)) Starting Lanczos Finished Lanczos [2]((1.11022e-16,-8.65927e-17),(1,-4.98226e-17))
The problem is these numbers don't make sense at all, and when I try =20 to get the size of the eigenvector with eigenvector.size() it gives 1. =20 Any help or hints would be gratefully appreciated. Also any help or =20 hints about my other question about combining print_numeric and =20 sparsediag to get the ground state vector would be much appreciated.
Thanks
On 3 Sep 2010, at 03:23, rexlundgren@mail.utexas.edu wrote:
Hi, Thanks for the reply. When I try that with the following code inserted in the sparsediag.h file :
//orignal code
// calculate eigen vectors ietl::Info<magnitude_type> info; // (m1, m2, ma, eigenvalue, residualm, status). try { eigenvectors.clear(); lanczos.eigenvectors(lanczos.eigenvalues().begin(),lanczos.eigenvalues().begin()+n, std::back_inserter(eigenvectors),info,generator); } catch (std::runtime_error& e) { std::cout <<"Exception during eigenvector calculation: " << e.what() << "\n"; }
} else { vector_type v(1); v[0]=1.; eigenvectors.push_back(v);
//new code to print out eigenvectors std::cout << eigenvectors[0].size() << " Size \n"; std::cout << eigenvectors[0] << "\n";
}
} // rest of code
The output is the following for a spin chain with L=4.
1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) Starting Lanczos Finished Lanczos 1 Size [1]((1,0)) Starting Lanczos Finished Lanczos 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0)) 1 Size [1]((1,0))
The problem is I don't know how to interpret this in terms of the original basis that is not within the subspace, or if there is still some problem in my code(maybe its in the wrong spot).
Thanks for the help
Rex
You should print the parameters (from the variable parms) as well - they give the quantum numbers, such as Sz and the TOTAL_MOMENTUM. For the small system you looked at most subspaces are of size 1, that's why you just get 1-dimensional eigenvectors.
Matthias
comp-phys-alps-users@lists.phys.ethz.ch