-
Notifications
You must be signed in to change notification settings - Fork 1
/
HamiltonianUtils.py
62 lines (48 loc) · 1.41 KB
/
HamiltonianUtils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 22 15:58:13 2021
@author: burak
"""
import pennylane as qml
import torch
import numpy as np
def findHermitian(coeffs, randomPauliGroup, n_qubit_size):
'''
Given Pauli strings, it prepares an arbitrary Hamiltonian
Parameters
----------
coeffs : list
List of pauli coefficients
randomPauliGroup : list
List of Pauli strings
n_qubit_size : TYPE
Number of qubits
Returns
-------
hamiltonian : np.ndarray
Hermitian matrix
'''
I = np.eye(2)
pauliSet = [qml.PauliX(0).matrix, qml.PauliZ(0).matrix, qml.PauliY(0).matrix]
hamiltonian = 0j
for i in range(n_qubit_size):
pauli_word = np.array([1])
cur_hermitian = pauliSet[randomPauliGroup[i]] * coeffs[i]
for j in range(n_qubit_size):
if(i==j):
pauli_word = np.kron(pauli_word, cur_hermitian)
else:
pauli_word = np.kron(pauli_word, I)
hamiltonian += pauli_word
return hamiltonian
def timeEvolution(local_hamiltonian, psi, timestamp):
# U = expm(-1j * H * t )
U = torch.matrix_exp(local_hamiltonian * -1j * timestamp)
return U @ psi
'''expm(-1j * H * 1 )
k.values()
torch.matrix_exp(torchH * -1j * 1)
a=1
H.real
for i in range(n_qubit_size):
a = np.kron(a , expm(-1j * 1 *pauliSet[randomPauliGroup[i]] * coeffs[i] ))'''