From ba36dc4d8c066a6c56590ad5552bb609b269db2c Mon Sep 17 00:00:00 2001 From: yangguohao <70266361+yangguohao@users.noreply.github.com> Date: Wed, 3 Nov 2021 17:23:39 +0800 Subject: [PATCH] Update trotter.py --- paddle_quantum/trotter.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/paddle_quantum/trotter.py b/paddle_quantum/trotter.py index ef68ec3..bb90a22 100644 --- a/paddle_quantum/trotter.py +++ b/paddle_quantum/trotter.py @@ -306,6 +306,33 @@ def __add_higher_order_trotter_block(circuit, tau, grouped_hamiltonian, order): for p in p_values: __add_second_order_trotter_block(circuit, p * tau, grouped_hamiltonian) +def add_optimize_circuit_gate(gate,theta,pauli_word,which_qubits): + r""" 添加一个优化后的门电路,其pauli_word的形式主要为: 'XXYYZZ'的优化电路 + Args: + circuit (UAnsatz): 需要添加门的电路 + theta (tensor or float): 旋转角度 + pauli_word (str): 泡利算符组成的字符串,例如 ``"XXZ"`` + which_qubits (list or np.ndarray): ``pauli_word`` 中的每个算符所作用的量子比特编号 + """ + theta = np.pi/2 + x,y,z = 1,1,1 + g, a, b =z,(2*x-1)*np.pi/2-x,(2*y-1)*np.pi/2-y + alpha = paddle.to_tensor(theta-2*a,dtype='float64') + beta = paddle.to_tensor(2*b-theta,dtype='float64') + gamma = paddle.to_tensor(2*g-theta,dtype='float64') + param = [gamma,alpha,beta] + #print(param) + p1 = paddle.to_tensor(theta,dtype='float64') + p2 = paddle.to_tensor(-theta,dtype='float64') + cir.rz(p1,1) + cir.cnot([1,0]) + cir.rz(param[0],0) + cir.ry(param[1],1) + cir.cnot([0,1]) + cir.ry(param[2],1) + cir.cnot([1,0]) + cir.rz(p2,0) + def add_n_pauli_gate(circuit, theta, pauli_word, which_qubits): r""" 添加一个对应着 N 个泡利算符张量积的旋转门,例如 :math:`e^{-\theta/2 * X \otimes I \otimes X \otimes Y}` -- GitLab