def test_trapezoidal_rule(self): """test for trapezoidal rule""" # compute numerical solution of the ODE operator = mdl.two_step_destruction(1, 2, 1, 2) initial_value = tt.zeros([2 ** 2, 2 ** (2 + 1), 2 ** 2, 2 ** 2], [1] * 4) initial_value.cores[0][0, -1, 0, 0] = 1 initial_value.cores[1][0, -2, 0, 0] = 1 initial_value.cores[2][0, 0, 0, 0] = 1 initial_value.cores[3][0, 0, 0, 0] = 1 initial_guess = tt.ones(operator.row_dims, [1] * operator.order, ranks=self.rank).ortho_right() step_sizes = [0.001] * 100 + [0.1] * 9 + [1] * 19 solution_als = ode.trapezoidal_rule(operator, initial_value, initial_guess, step_sizes, tt_solver='als', progress=False) solution_mals = ode.trapezoidal_rule(operator, initial_value, initial_guess, step_sizes, tt_solver='mals', max_rank=self.rank, progress=False) # compute norm of the derivatives at the final 10 time steps derivatives_als = [] derivatives_mals = [] for i in range(10): derivatives_als.append((operator.dot(solution_als[-i - 1])).norm()) derivatives_mals.append((operator.dot(solution_mals[-i - 1])).norm()) # check if trapezoidal rule converged to stationary distribution for i in range(10): self.assertLess(derivatives_als[i], self.tol) self.assertLess(derivatives_mals[i], self.tol)
def test_zeros(self): """test tensor train of all zeros""" # construct tensor train of all zeros t_zeros = tt.zeros(self.t.row_dims, self.t.col_dims) # compute norm t_norm = np.linalg.norm(t_zeros.full().flatten()) # check if norm is 0 self.assertEqual(t_norm, 0)
order = 20 tt_rank = 4 qtt_rank = 12 step_sizes = [1] * 300 qtt_modes = [[2] * 6] * order threshold = 1e-14 # operator in TT format # --------------------- operator = mdl.signaling_cascade(order) # initial distribution in TT format # --------------------------------- initial_distribution = tt.zeros(operator.col_dims, [1] * order) for p in range(initial_distribution.order): initial_distribution.cores[p][0, 0, 0, 0] = 1 # initial guess in TT format # -------------------------- initial_guess = tt.ones(operator.col_dims, [1] * order, ranks=tt_rank).ortho_right() # solve Markovian master equation in TT format # -------------------------------------------- print('TT approach:\n') solution = ode.trapezoidal_rule(operator, initial_distribution, initial_guess, step_sizes)
step_sizes = [0.001] * 100 + [0.1] * 9 + [1] * 9 qtt_rank = 10 max_rank = 25 # construct operator in TT format and convert to QTT format # --------------------------------------------------------- operator = mdl.two_step_destruction( 1, 2, 1, m).tt2qtt([[2] * m] + [[2] * (m + 1)] + [[2] * m] + [[2] * m], [[2] * m] + [[2] * (m + 1)] + [[2] * m] + [[2] * m], threshold=10**-14) # initial distribution in TT format and convert to QTT format # ----------------------------------------------------------- initial_distribution = tt.zeros([2**m, 2**(m + 1), 2**m, 2**m], [1] * 4) initial_distribution.cores[0][0, -1, 0, 0] = 1 initial_distribution.cores[1][0, -2, 0, 0] = 1 initial_distribution.cores[2][0, 0, 0, 0] = 1 initial_distribution.cores[3][0, 0, 0, 0] = 1 initial_distribution = TT.tt2qtt( initial_distribution, [[2] * m] + [[2] * (m + 1)] + [[2] * m] + [[2] * m], [[1] * m] + [[1] * (m + 1)] + [[1] * m] + [[1] * m], threshold=0) # initial guess in QTT format # --------------------------- initial_guess = tt.uniform([2] * (4 * m + 1), ranks=qtt_rank).ortho_right() # solve Markovian master equation in QTT format