From 4a0f232f9d5185bca510042a2ab2556d57b2de3a Mon Sep 17 00:00:00 2001 From: yangguohao <70266361+yangguohao@users.noreply.github.com> Date: Sun, 21 Nov 2021 14:46:42 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E5=8D=95=E6=B5=8B=E6=96=87=E4=BB=B6.p?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\346\265\213\346\226\207\344\273\266.py" | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git "a/documents/\345\215\225\346\265\213\346\226\207\344\273\266.py" "b/documents/\345\215\225\346\265\213\346\226\207\344\273\266.py" index c74bf4a..a0958d2 100644 --- "a/documents/\345\215\225\346\265\213\346\226\207\344\273\266.py" +++ "b/documents/\345\215\225\346\265\213\346\226\207\344\273\266.py" @@ -1,6 +1,6 @@ from paddle_quantum.circuit import UAnsatz from paddle_quantum.utils import Hamiltonian,NKron, gate_fidelity,SpinOps,dagger -from paddle_quantum.trotter import construct_trotter_circuit, get_1d_heisenberg_hamiltonian,__group_hamiltonian_xyz,optimal_circuit,__sort_pauli_word +from paddle_quantum.trotter import construct_trotter_circuit, get_1d_heisenberg_hamiltonian from paddle import matmul, transpose, trace import paddle import numpy as np @@ -9,6 +9,7 @@ from scipy import linalg import matplotlib.pyplot as plt def get_evolve_op(t,h): return scipy.linalg.expm(-1j * t * h.construct_h_matrix()) + def test(h,n): t = 2 r = 1 @@ -19,23 +20,35 @@ def test(h,n): print('电路的酉矩阵与正确的演化算符之间的保真度为:%.2f' % gate_fidelity(cir.U.numpy(), get_evolve_op(t,h))) print(cir) + +print('--------------test1------------') h1 = get_1d_heisenberg_hamiltonian(length=2, j_x=1, j_y=1, j_z=2,h_z=2 * np.random.rand(2) - 1,periodic_boundary_condition=False)# -h2 = Hamiltonian([[1., 'X0, X1'], [1., 'Z2, Z3'], [1., 'Y0, Y1'], [1., 'X1, X2'], [1., 'Y2, Y3'], [1., 'Z0, Z1']]) test(h1,2) +print('--------------test2------------') +h2 = Hamiltonian([[1., 'X0, X1'], [1., 'Z2, Z3'], [1., 'Y0, Y1'], [1., 'X1, X2'], [1., 'Y2, Y3'], [1., 'Z0, Z1']]) test(h2,4) +print('--------------test3------------') +h3 = Hamiltonian([ [1, 'Y0, Y1'], [1, 'X1, X0'],[1, 'X0, Y1'],[1, 'Z0, Z1']]) +test(h3,2) """ + +运行耗时: 130毫秒 +--------------test1------------ +([1.0, 1.0, 2.0, 0.8812020131972615, 0.7453483155128535], ['XX', 'YY', 'ZZ', 'Z', 'Z'], [[0, 1], [0, 1], [0, 1], [0], [1]]) 系统的哈密顿量为: 1.0 X0, X1 1.0 Y0, Y1 2.0 Z0, Z1 --0.08627686700375259 Z0 --0.7839872913953019 Z1 -电路的酉矩阵与正确的演化算符之间的保真度为:0.68 ----------------x----Rz(6.429)----*-----------------x----Rz(-1.57)----Rz(-0.34)-- +0.8812020131972615 Z0 +0.7453483155128535 Z1 +电路的酉矩阵与正确的演化算符之间的保真度为:0.99 +---------------x----Rz(6.429)----*-----------------x----Rz(-1.57)----Rz(3.525)-- | | | ---Rz(1.571)----*----Ry(-3.85)----x----Ry(3.854)----*----Rz(-3.13)--------------- +--Rz(1.571)----*----Ry(-3.85)----x----Ry(3.854)----*----Rz(2.981)--------------- +--------------test2------------ +([1.0, 1.0, 1.0, 1.0, 1.0, 1.0], ['XX', 'YY', 'ZZ', 'ZZ', 'XX', 'YY'], [[0, 1], [0, 1], [0, 1], [2, 3], [1, 2], [2, 3]]) 系统的哈密顿量为: 1.0 X0, X1 1.0 Z2, Z3 @@ -43,12 +56,24 @@ test(h2,4) 1.0 X1, X2 1.0 Y2, Y3 1.0 Z0, Z1 -电路的酉矩阵与正确的演化算符之间的保真度为:0.19 ---H--------*-------------------------*--------H----Rx(1.571)----*-----------------*----Rx(-1.57)-----------------------------------------*-------------------------*------------------------ - | | | | | | ---H--------x--------Rz(4.000)--------x--------H----Rx(1.571)----x----Rz(4.000)----x----Rx(-1.57)----H----*-----------------*----H--------x--------Rz(4.000)--------x------------------------ - | | ---*---------------------*------------H-------------------------------------------------------------------x----Rz(4.000)----x----H----Rx(1.571)--------*---------------------*----Rx(-1.57)-- - | | | | ---x----Rz(4.000)--------x--------Rx(1.571)------------------------------------------------------------------------------------------------------------x--------Rz(4.000)----x----Rx(-1.57)-- +电路的酉矩阵与正确的演化算符之间的保真度为:0.51 +-------------------x--------Rz(2.429)--------*---------------------x----Rz(-1.57)------------------------------------------------------------------------------- + | | | +--Rz(1.571)--------*--------Ry(-3.85)--------x--------Ry(3.854)----*--------H--------*-----------------*----H--------------------------------------------------- + | | +------*-------------------------*------------H---------------------------------------x----Rz(4.000)----x----H----Rx(1.571)----*-----------------*----Rx(-1.57)-- + | | | | +------x--------Rz(4.000)--------x--------Rx(1.571)----------------------------------------------------------------------------x----Rz(4.000)----x----Rx(-1.57)-- + +--------------test3------------ +([1.0, 1.0, 1.0, 1.0], ['YY', 'XX', 'ZZ', 'XY'], [[0, 1], [1, 0], [0, 1], [0, 1]]) +系统的哈密顿量为: +1.0 Y0, Y1 +1.0 X1, X0 +1.0 X0, Y1 +1.0 Z0, Z1 +电路的酉矩阵与正确的演化算符之间的保真度为:0.46 +---------------x----Rz(2.429)----*-----------------x----Rz(-1.57)----H----*-----------------*--------H------ + | | | | | +--Rz(1.571)----*----Ry(-3.85)----x----Ry(3.854)----*----Rx(1.571)---------x----Rz(4.000)----x----Rx(-1.57)-- """ -- GitLab