-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfit_temperature.py
51 lines (36 loc) · 1.15 KB
/
fit_temperature.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
import numpy as np
import pandas as pd
import math as mt
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
#data = pd.read_excel(r'.\hist_kp.xlsx')
data = pd.read_excel(r'.\temperature_data.xlsx', sheet_name = "21 qubits")
energy = np.array(data['energy'])
deg = np.array(data['deg'])
num_occ = np.array(data['num_occ.'])
energy = energy * 6.62607015e-25 * 7.56622700
# Boltzmann distribution
k_B = 1.380649E-23
def Z(x, T):
E = 0
for i in range(0, len(x[0])-1):
x1 = np.float64(-(x[0][i])/(k_B * T))
E += x[1][i] * (mt.e ** x1)
return E
def boltzmann_distribution(x,T):
y = np.float64(-(x[0])/(k_B * T))
return x[1]*(mt.e ** y) / Z(x, T)
x_model = np.linspace(min(energy), max(energy), 302)
y_data = num_occ/2000
popt, pcov = curve_fit(boltzmann_distribution, [energy, deg], y_data, p0 = [10])
print(popt)
print(pcov)
# drawing
plt.figure(1, dpi=120)
plt.plot(x_model, boltzmann_distribution([x_model, deg], popt), color = "red")
plt.scatter(energy, y_data, label="Energy Distribution")
plt.xlabel("Energy (J)")
plt.ylabel("Occurrences")
plt.savefig('fit15.pdf')
plt.savefig('fit15.png')
plt.show()