def precompute_redfield_tensor_finegrid(self, t_init, t_final, dt, integrator): if self.is_verbose: print("\n--- Precomputing the Redfield tensor on a fine RK4 grid") int_order = integrator.order c = integrator.c n_timesteps = int((t_final - t_init) / dt + 1) self.redfield_tensor_ni = [] cost = [] rate_file = open('rate_%s.dat' % (self.method), 'w') for n in range(n_timesteps): self.redfield_tensor_ni.append([]) for i in range(int_order): t = t_init + n * dt + c[i] * dt self.make_redfield_tensor(t) self.redfield_tensor_ni[n].append(self.redfield_tensor) cost.append( utils.tensor_diff(self.redfield_tensor, self.redfield_tensor_ni[n - 1][i])) if n > 0 and cost[n] < self.markov_tol * np.std(cost): if self.is_verbose: print("\n--- Tensor has stopped changing at t ="), t self.n_markov = n rate_file.close() break if n > 0 and t >= self.markov_time: if self.is_verbose: print("\n--- Tensor calculation stopped at t ="), t self.n_markov = n rate_file.close() break rate_file.write('%0.6f ' % (t)) for row in self.redfield_tensor: for R in row: rate_file.write('%0.6f %0.6f ' % (R.real, R.imag)) rate_file.write('\n') self.n_markov = n rate_file.close() if self.is_verbose: print("\n--- Done precomputing the Redfield tensor")
def precompute_redfield_tensor_finegrid(self, t_init, t_final, dt, integrator): if self.is_verbose: print "\n--- Precomputing the Redfield tensor on a fine RK4 grid" int_order = integrator.order c = integrator.c n_timesteps = int( (t_final-t_init)/dt + 1 ) self.redfield_tensor_ni = [] cost = [] rate_file = open('rate_%s.dat'%(self.method),'w') for n in range(n_timesteps): self.redfield_tensor_ni.append([]) for i in range(int_order): t = t_init + n*dt + c[i]*dt self.make_redfield_tensor(t) self.redfield_tensor_ni[n].append(self.redfield_tensor) cost.append( utils.tensor_diff( self.redfield_tensor, self.redfield_tensor_ni[n-1][i] ) ) if n > 0 and cost[n] < self.markov_tol*np.std(cost): if self.is_verbose: print "\n--- Tensor has stopped changing at t =", t self.n_markov = n rate_file.close() break if n > 0 and t >= self.markov_time: if self.is_verbose: print "\n--- Tensor calculation stopped at t =", t self.n_markov = n rate_file.close() break rate_file.write('%0.6f '%(t)) for row in self.redfield_tensor: for R in row: rate_file.write('%0.6f %0.6f '%(R.real, R.imag)) rate_file.write('\n') self.n_markov = n rate_file.close() if self.is_verbose: print "\n--- Done precomputing the Redfield tensor"
def precompute_redfield_tensor(self, t_init, t_final, dt): """Precompute the time-dependent Redfield-like tensor, store in array. Parameters ---------- t_init : float Initial time at which to start precomputing. f_final : float Final time at which to stop precomputing. dt : float Timestep for precomputing. integrator : Integrator An instance of the pyrho Integrator class. Notes ----- The tensor is stored on a coarse grid which is ignorant to the Integrator grid (e.g. RK4). """ if self.is_verbose: print "\n--- Precomputing the Redfield tensor" n_timesteps = int( (t_final-t_init)/dt + 1 ) self.redfield_tensor_n = [] redfield_tensor_integral_n = [] cost = [] if self.method == 'TCL2': redfield_tensor_n = [] for time in np.arange(0.0, t_init, dt): self.make_redfield_tensor(time) redfield_tensor_n.append(self.redfield_tensor) redfield_tensor_integral_0_t_init = np.trapz(redfield_tensor_n, dx=dt, axis=0) for n in range(n_timesteps): time = t_init + n*dt self.make_redfield_tensor(time) self.redfield_tensor_n.append(self.redfield_tensor) # Collect running integral for TCL2 if self.method == 'TCL2': redfield_tensor_integral_n.append(redfield_tensor_integral_0_t_init + np.trapz(self.redfield_tensor_n[:n+1], dx=dt, axis=0) ) cost.append( utils.tensor_diff( self.redfield_tensor, self.redfield_tensor_n[n-1] ) ) if n > 0 and cost[n] < self.markov_tol*np.std(cost): if self.is_verbose: print "\n--- Tensor has stopped changing at t =", time self.n_markov = n break if n > 0 and time >= self.markov_time: if self.is_verbose: print "\n--- Tensor calculation stopped at t =", time self.n_markov = n break self.n_markov = n if self.method == 'TCL2': self.redfield_tensor_n = redfield_tensor_integral_n if self.is_verbose: print "\n--- Done precomputing the Redfield tensor" cost_file = open('cost_%s.dat'%(self.method),'w') rate_file = open('rate_%s.dat'%(self.method),'w') for n in range(self.n_markov): time = t_init + n*dt cost_file.write('%0.6f %0.6f %0.6f %0.6f\n' %(time, cost[n], np.std(cost[:n+1]), self.markov_tol)) rate_file.write('%0.6f '%(time)) for row in self.redfield_tensor_n[n]: for R in row: rate_file.write('%0.6f %0.6f '%(R.real, R.imag)) rate_file.write('\n') cost_file.close() rate_file.close()
def precompute_redfield_tensor(self, t_init, t_final, dt): """Precompute the time-dependent Redfield-like tensor, store in array. Parameters ---------- t_init : float Initial time at which to start precomputing. f_final : float Final time at which to stop precomputing. dt : float Timestep for precomputing. integrator : Integrator An instance of the pyrho Integrator class. Notes ----- The tensor is stored on a coarse grid which is ignorant to the Integrator grid (e.g. RK4). """ if self.is_verbose: print "\n--- Precomputing the Redfield tensor" n_timesteps = int( (t_final-t_init)/dt + 1 ) self.redfield_tensor_n = [] redfield_tensor_integral_n = [] cost = [] for n in range(n_timesteps): t = t_init + n*dt self.make_redfield_tensor(t) self.redfield_tensor_n.append(self.redfield_tensor) # Collect running integral for TCL2 if self.method == 'TCL2': redfield_tensor_integral_n.append( np.trapz(self.redfield_tensor_n[:n+1], dx=dt, axis=0) ) cost.append( utils.tensor_diff( self.redfield_tensor, self.redfield_tensor_n[n-1] ) ) if n > 0 and cost[n] < self.markov_tol*np.std(cost): if self.is_verbose: print "\n--- Tensor has stopped changing at t =", t self.n_markov = n break if n > 0 and t >= self.markov_time: if self.is_verbose: print "\n--- Tensor calculation stopped at t =", t self.n_markov = n break self.n_markov = n if self.method == 'TCL2': self.redfield_tensor_n = redfield_tensor_integral_n if self.is_verbose: print "\n--- Done precomputing the Redfield tensor" cost_file = open('cost_%s.dat'%(self.method),'w') rate_file = open('rate_%s.dat'%(self.method),'w') for n in range(self.n_markov): t = t_init + n*dt cost_file.write('%0.6f %0.6f %0.6f %0.6f\n' %(t, cost[n], np.std(cost[:n+1]), self.markov_tol)) rate_file.write('%0.6f '%(t)) for row in self.redfield_tensor_n[n]: for R in row: rate_file.write('%0.6f %0.6f '%(R.real, R.imag)) rate_file.write('\n') cost_file.close() rate_file.close()