👉 Сакате сами да го пробате?
Погледнете го моето GitHub репозиториум * : ratwolfzero/Schroedingers_Cat
* вклучувајќи технички детали, математичка позадина и ЧПП
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from qutip import coherent, mesolve, destroy, wigner, Qobj
import random
N = 30
alpha = 2.0
= 200
t_total = 20
t_decohere_start = 10.0
t_static_end = 2.0
gamma = 0.05
kerr_strength = 0.1
tlist_total = np.linspace( 0 , t_total, временски чекори)
dt = tlist_total[ 1 ] - tlist_total[ 0 ]
a = destroy(N)
psi1 = coherent(N, alpha)
psi2 = coherent(N, -alpha)
cat = (psi1 + psi2).unit()
initial_rho = cat * cat.dag()
H_twist = kerr_strength * (a.dag() * a)** 2
H_static = Qobj(np.zeros((N, N)), dims=[[N], [N]])
H_decohere = Qobj(np.zeros((N, N)), dims=[[N], [N]])
c_ops_decoherence = [np.sqrt(gamma) * a]
x = np.linspace(- 5 , 5 , 130 )
p = np.linspace(- 5 , 5 , 130 )
frames_phase1 = np.where(tlist_total < t_decohere_start)[ 0 ]
rho_rot = []
if len (frames_phase1) > 0 :
t_static_frames = np.where(tlist_total[frames_phase1] <= t_static_end)[ 0 ]
t_twist_frames = np.where(tlist_total[frames_phase1] > t_static_end)[ 0 ]
за _ во t_static_frames:
rho_rot.append(initial_rho)
ако len (t_twist_frames) > 0 :
t_twist = tlist_total[frames_phase1][t_twist_frames] - t_static_end
result_rot = mesolve(H_twist, initial_rho, t_twist, c_ops=[])
rho_rot.extend(result_rot.states)
collapse_state = Нема
decoherence_started = Неточно
rho_prev = rho_rot[- 1 ] ако rho_rot или друго initial_rho
fig, ax = plt.subplots(figsize=( 6 , 6 ))
def update ( frame ):
global collapse_state, decoherence_started, rho_prev
ax.clear()
t = tlist_total[frame]
ако collapse_state не е None : rho_t = collapse_state title = "Кутијата е отворена → брановата функција е срушена" else : ако t >= t_decohere_start: ако не е decoherence_started: decoherence_started = True rho_prev = initial_rho else : decoherence_started = False ако не е decoherence_started: idx = frame ако рамка < len (rho_rot) else - 1 rho_t = rho_rot[idx] ако t <= t_static_end: title = f"Статичка почетна состојба (t= {t: .2 f} )" else : title = f"Кохерентна еволуција → спирални рабови и дисторзија на дамки (t= {t: .2 f} )" else : резултат од декохеренција = mesolve(H_decohere, rho_prev, [ 0 , dt], c_ops=c_ops_decoherence)
rho_t = result.states[- 1 ]
rho_prev = rho_t
title = f"Декохеренција → бледнеење на интерференција (t= {t: .2 f} )"
W = wigner(rho_t, x, p)
max_abs_W = np. max (np. abs (W))
ax.contourf(x, p, W, 200 , cmap= "RdBu_r" , vmin=-max_abs_W, vmax=max_abs_W)
ax.set_xlabel( "x" )
ax.set_ylabel( "p" )
ax.set_title(title)
ax.set_aspect( 'еднакво' )
ако t <= t_static_end и collapse_state е None :
ax.text( 2 , 0 , 'Alive' , color= 'black' , fontsize= 10 , ha= 'center' )
ax.text( -2 , 0 , 'Dead' , color= 'black' , fontsize= 10 , ha= 'center' )
ако collapse_state не е None : ако np.allclose(collapse_state.full(), (psi1 * psi1.dag()).full(), atol= 1e-6 ): ax.text( 2 , 0 , 'Жив' , color= 'црно' , fontsize= 10 , ha= 'центар' ) elif np.allclose(collapse_state.full(), (psi2 * psi2.dag()).full(), atol= 1e-6 ): ax.text( -2 , 0 , 'Мртов' , color= 'црно' , fontsize= 10 , ha= 'центар' ) def on_key ( event ): global collapse_state if event.key == 'o' and collapse_state is None : collapse_state = random.choice([psi1*psi1.dag(), psi2*psi2.dag()]) print ( "Кутијата е отворена! Брановата функција е соборена." ) fig.canvas.mpl_connect( 'настан_при_притискање_на_копче'
, on_key)
Интервал на извршување на анимација = (t_total / временски чекори) * 1000
ani = FuncAnimation(fig, update, frames=временски чекори,
interval=интервал, repeat= True )
plt.show()