-
Notifications
You must be signed in to change notification settings - Fork 2
/
calc.py
57 lines (42 loc) · 1.6 KB
/
calc.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
import numpy as np
import matplotlib.pyplot as plt
from qiskit import QuantumCircuit, execute, Aer, QuantumRegister
num_qubits = 1
qreg = QuantumRegister(num_qubits, 'q')
G = 6.67430e-11
h_bar = 1.0545718e-34
speed_of_light = 3.00e8
spin_bh = 0.2
def apply_black_hole_properties(qc, mass, spin):
qc.rx(2 * np.arcsin(np.sqrt(spin)), qreg[0])
qc.rz(mass * np.pi, qreg[0])
def calculate_temperature(mass):
qc = QuantumCircuit(qreg)
apply_black_hole_properties(qc, mass, spin_bh)
backend = Aer.get_backend('statevector_simulator')
job = execute(qc, backend)
result = job.result()
statevector = result.get_statevector()
avg_energy = np.real(np.vdot(statevector, np.dot(h_bar * speed_of_light**3 / (8 * np.pi * G), statevector)))
temperature = avg_energy / (3.15e7 * mass) # 3.15e7 is a conversion factor for time
return temperature
def Calc(arr):
plt.figure(figsize=(8, 6))
for initial_mass_str in arr:
initial_mass = float(initial_mass_str)
t_max = 100
delta_t = 1
time = np.arange(0, t_max, delta_t)
masses_bh = initial_mass * np.exp(-0.1 * time)
temperature_data = []
for i, mass_bh in enumerate(masses_bh):
temperature = calculate_temperature(mass_bh)
temperature_data.append(temperature)
plt.plot(time, temperature_data, label=f"Mass: {initial_mass} kg")
plt.xlabel("Time (quantum time units)")
plt.ylabel("Temperature (K)")
plt.title("Black Hole Temperature vs. Time")
plt.legend()
plt.grid()
plt.tight_layout()
plt.savefig('./static/plot.png')