Qiskit:
# A = 0.55I + 0.225Z_2 + 0.225Z_3
coefficient_set = [0.55, 0.225, 0.225]
a1 = coefficient_set[2]*np.array([[1,0,0,0,0,0,0,0], [0,1,0,0,0,0,0,0], [0,0,1,0,0,0,0,0], [0,0,0,1,0,0,0,0], [0,0,0,0,-1,0,0,0], [0,0,0,0,0,-1,0,0], [0,0,0,0,0,0,-1,0], [0,0,0,0,0,0,0,-1]])
a0 = coefficient_set[1]*np.array([[1,0,0,0,0,0,0,0], [0,1,0,0,0,0,0,0], [0,0,-1,0,0,0,0,0], [0,0,0,-1,0,0,0,0], [0,0,0,0,1,0,0,0], [0,0,0,0,0,1,0,0], [0,0,0,0,0,0,-1,0], [0,0,0,0,0,0,0,-1]])
a2 = coefficient_set[0]*np.array([[1,0,0,0,0,0,0,0], [0,1,0,0,0,0,0,0], [0,0,1,0,0,0,0,0], [0,0,0,1,0,0,0,0], [0,0,0,0,1,0,0,0], [0,0,0,0,0,1,0,0], [0,0,0,0,0,0,1,0], [0,0,0,0,0,0,0,1]])
a3 = np.add(np.add(a2, a0), a1)
A = a3 =
array([[1. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 1. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0.55, 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0.55, 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0.55, 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0.55, 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0.1 , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.1 ]])
PennyLane:
Id = np.identity(2)
Z = np.array([[1, 0], [0, -1]])
X = np.array([[0, 1], [1, 0]])
A_0 = np.identity(8)
A_1 = np.kron(np.kron(Id, Z), Id)
A_2 = np.kron(np.kron(Id, Id), Z)
A_num = coefficient_set[0] * A_0 + coefficient_set[1] * A_1 + coefficient_set[2] * A_2
A_num =
array([[1. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0.55, 0. , 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0.55, 0. , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0.1 , 0. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 1. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0.55, 0. , 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0.55, 0. ],
[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0.1 ]])
I simulated the circuit, and the result shows that Qiskit seems to be correct
from qiskit import QuantumCircuit, QuantumRegister,ClassicalRegister,execute, Aer
#%%
backend = Aer.get_backend('unitary_simulator')
q = QuantumRegister(3, 'q')
c = ClassicalRegister(3, 'c')
circuit = QuantumCircuit(q, c)
#circuit.h(q[0])
circuit.z(q[2])
print(circuit)
job = execute(circuit, backend, shots=8192)
result = job.result()
print(np.real(result.get_unitary(circuit,3)))
A_2=
[[ 1. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 1. 0. 0. 0. 0. 0. 0.]
[-0. -0. -1. -0. -0. -0. -0. -0.]
[-0. -0. -0. -1. -0. -0. -0. -0.]
[ 0. 0. 0. 0. 1. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 1. 0. 0.]
[-0. -0. -0. -0. -0. -0. -1. -0.]
[-0. -0. -0. -0. -0. -0. -0. -1.]]
but in pennylane:
A_2 =
array([[ 1., 0., 0., 0., 0., 0., 0., 0.],
[ 0., -1., 0., -0., 0., -0., 0., -0.],
[ 0., 0., 1., 0., 0., 0., 0., 0.],
[ 0., -0., 0., -1., 0., -0., 0., -0.],
[ 0., 0., 0., 0., 1., 0., 0., 0.],
[ 0., -0., 0., -0., 0., -1., 0., -0.],
[ 0., 0., 0., 0., 0., 0., 1., 0.],
[ 0., -0., 0., -0., 0., -0., 0., -1.]])
But Pennylane’s result is correct, which makes me confused and I don’t know the reason.