Пример #1
0
void exercise_assignment(SU_vector& source, SU_vector& dest, double expectedVal){
	try{
		alloc_counting::reset_allocation_counters();
		dest=std::move(source);
		auto allocated=alloc_counting::mem_allocated;
		std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
		//check the number of components
		auto components=dest.GetComponents();
		std::cout << components.size() << " components stored" << '\n';
		//check that all components are initialized to the correct value
		std::cout << "components " <<
		(std::all_of(components.begin(),components.end(),[=](double c){ return(c==expectedVal); })?
		 "are":"are not") << " correctly set\n";
		std::cout << "source dimension: " << source.Dim() << '\n';
		//check that memory is not aliased
		if(source.Dim()){
			source[0]=5;
			std::cout << "Memory aliasing: " << (dest[0]==source[0]) << '\n';
		}
	}catch(std::runtime_error& e){
		std::cout << "Assignment failed: " << e.what() << '\n';
	}
}
int main(){
	using namespace squids;

	const double pi=4*atan(1);
	const double base_tol=2e-16; //~machine epsilon
	Const transform;

	for(unsigned int dim=2; dim<=SQUIDS_MAX_HILBERT_DIM; dim++){
		//make sure the transformation between bases is full of non-trivial angles
		for(unsigned int i=0; i<dim-1; i++){
			double angle=2.*pi*(i+1.)/(dim+1.);
			transform.SetMixingAngle(i,dim-1,angle);
			transform.SetPhase(i,dim-1,-angle);
		}
		//test transformation for every generator
		for(unsigned int g=0; g<(dim*dim); g++){
			//get the next generator and make a copy
			SU_vector s=SU_vector::Generator(dim,g);
			SU_vector to=s;
			// rotate s using RotateToB1
			s.RotateToB1(transform);
			// rotate t using gsl_unitary_rotation
			auto U = transform.GetTransformationMatrix(dim);
			SU_vector tr = to.Rotate(U.get());
			//check that the result matches the original closely
			auto sc=s.GetComponents();
			auto tc=tr.GetComponents();
			//as the dimension increases more operations are necessary in the
			//rotation, so we allow for a slightly more error to accumulate
			for(unsigned int i=0; i<(dim*dim); i++){
				if(std::abs(sc[i]-tc[i])>2*dim*base_tol)
					std::cout << "Dimension " << dim << " generator " << g <<
					" component " << i << " has error " << (sc[i]-tc[i]) << std::endl;
			}
		}
	}
}
Пример #3
0
void test_fused_assign_add(unsigned int dim, SU_vector& dest, const std::string& dStoreType){
	const double d1=4.97, d2=2.14, sum=d1+d2;
	SU_vector v1(dim), v2(dim);
	std::cout << "Assigning sum of vectors with sizes " << v1.Dim() << " and " << v2.Dim()
		<< " to vector with size " << dest.Dim() << " (" << dStoreType << ")\n";
	v1.SetAllComponents(d1);
	v2.SetAllComponents(d2);
	try{
		alloc_counting::reset_allocation_counters();
		dest=v1+v2;
		auto allocated=alloc_counting::mem_allocated;
		std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
		check_all_components_equal(dest,sum);
	} catch(std::runtime_error& err){
		std::cout << "Exception: " << err.what() << '\n';
	}
}
Пример #4
0
double SQuIDS::GetExpectationValueD(const SU_vector& op, unsigned int nrh, double xi,
                                    SQuIDS::expectationValueDBuffer& buf) const{
  //find bracketing state entries
  auto xit=std::lower_bound(x.begin(),x.end(),xi);
  if(xit==x.end())
    throw std::runtime_error("SQUIDS::GetExpectationValueD : x value not in the array.");
  if(xit!=x.begin())
    xit--;
  size_t xid=std::distance(x.begin(),xit);

  //linearly interpolate between the two states
  double f2=((xi-x[xid])/(x[xid+1]-x[xid]));
  double f1=1-f2;
  buf.state =f1*state[xid].rho[nrh];
  buf.state+=f2*state[xid+1].rho[nrh];
  //compute the evolved operator
  buf.op=op.Evolve(H0(xi,nrh),t-t_ini);
  //apply operator to state
  return buf.state*buf.op;
}
Пример #5
0
double SQuIDS::GetExpectationValueD(const SU_vector& op, unsigned int nrh, double xi,
                                    SQuIDS::expectationValueDBuffer& buf,
                                    double scale, std::vector<bool>& avr) const{
  //find bracketing state entries
  auto xit=std::lower_bound(x.begin(),x.end(),xi);
  if(xit==x.end())
    throw std::runtime_error("SQUIDS::GetExpectationValueD : x value not in the array.");
  if(xit!=x.begin())
    xit--;
  size_t xid=std::distance(x.begin(),xit);

  //linearly interpolate between the two states
  double f2=((xi-x[xid])/(x[xid+1]-x[xid]));
  double f1=1-f2;
  buf.state =f1*state[xid].rho[nrh];
  buf.state+=f2*state[xid+1].rho[nrh];
  //compute the evolved operator
  std::unique_ptr<double[]> evol_buf(new double[H0(xi,nrh).GetEvolveBufferSize()]);
  H0(xi,nrh).PrepareEvolve(evol_buf.get(),t-t_ini,scale,avr);
  buf.op=op.Evolve(evol_buf.get());
  //apply operator to state
  return (buf.op*state[xid].rho[nrh])*f1 + (buf.op*state[xid+1].rho[nrh])*f2;
  //return buf.state*buf.op;
}
Пример #6
0
void check_all_components_equal(const SU_vector& v, double expected){
	const auto& components=v.GetComponents();
	if(!std::all_of(components.begin(),components.end(),[=](double c){ return(c==expected); }))
		std::cout << "components are not correctly set \n";
}
Пример #7
0
void check_all_components_equal(const SU_vector& v, double expected){
	auto components=v.GetComponents();
	std::cout << "components " <<
	(std::all_of(components.begin(),components.end(),[=](double c){ return(c==expected); })?
	 "are":"are not") << " correctly set\n";
}
Пример #8
0
double SQuIDS::GetExpectationValue(SU_vector op, unsigned int nrh, unsigned int i, double scale, std::vector<bool>& avr) const {
  SU_vector h0=H0(x[i],nrh);
  std::unique_ptr<double[]> evol_buf(new double[h0.GetEvolveBufferSize()]);
  h0.PrepareEvolve(evol_buf.get(),t-t_ini,scale,avr);
  return state[i].rho[nrh]*op.Evolve(evol_buf.get());
}
Пример #9
0
double SQuIDS::GetExpectationValue(SU_vector op, unsigned int nrh, unsigned int i) const{
  SU_vector h0=H0(x[i],nrh);
  return state[i].rho[nrh]*op.Evolve(h0,t-t_ini);
}