From f82266e979eb8739825c4fce461674bef235c721 Mon Sep 17 00:00:00 2001 From: zengqg Date: Tue, 1 Apr 2025 15:36:07 +0800 Subject: [PATCH 1/2] eliminate redundant computations --- mindquantum/algorithm/qaia/LQA.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mindquantum/algorithm/qaia/LQA.py b/mindquantum/algorithm/qaia/LQA.py index 7cc229105..9e90b2906 100644 --- a/mindquantum/algorithm/qaia/LQA.py +++ b/mindquantum/algorithm/qaia/LQA.py @@ -113,17 +113,18 @@ class LQA(QAIA): for i in range(1, self.n_iter): t = i / self.n_iter - tmp = np.pi / 2 * np.tanh(self.x) + tanh_x = np.tanh(self.x) + tmp = np.pi / 2 * np.tanh(tanh_x) z = np.sin(tmp) y = np.cos(tmp) if self.h is None: - dx = np.pi / 2 * (-t * self.gamma * self.J.dot(z) * y + (1 - t) * z) * (1 - np.tanh(self.x) ** 2) + dx = np.pi / 2 * (-t * self.gamma * self.J.dot(z) * y + (1 - t) * z) * (1 - tanh_x ** 2) else: dx = ( np.pi / 2 * (-t * self.gamma * (self.J.dot(z) + self.h) * y + (1 - t) * z) - * (1 - np.tanh(self.x) ** 2) + * (1 - tanh_x ** 2) ) # momentum beta1 -- Gitee From 8794cafd4483450da6dae604931d0865408a0fd5 Mon Sep 17 00:00:00 2001 From: zengqg Date: Tue, 1 Apr 2025 16:18:28 +0800 Subject: [PATCH 2/2] eliminate redundant computations --- mindquantum/algorithm/qaia/LQA.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mindquantum/algorithm/qaia/LQA.py b/mindquantum/algorithm/qaia/LQA.py index 9e90b2906..45c2b1188 100644 --- a/mindquantum/algorithm/qaia/LQA.py +++ b/mindquantum/algorithm/qaia/LQA.py @@ -114,7 +114,7 @@ class LQA(QAIA): for i in range(1, self.n_iter): t = i / self.n_iter tanh_x = np.tanh(self.x) - tmp = np.pi / 2 * np.tanh(tanh_x) + tmp = np.pi / 2 * tanh_x z = np.sin(tmp) y = np.cos(tmp) if self.h is None: -- Gitee