A Coding Implementation of Quantum State Evolution, Decoherence, and Entanglement Dynamics using QuTiP

🔬

On this superior QuTiP tutorial, we discover the wealthy dynamics of quantum programs utilizing Python and the QuTiP framework. We’ll start by making ready basic single- and two-qubit states, together with Bell pairs, after which transfer on to implement key quantum operations corresponding to Pauli matrices, Hadamard gates, and CNOT. From there, we’ll simulate Rabi oscillations in a pushed two-level system, examine coherent state evolution in a quantum harmonic oscillator, and mannequin decoherence in open programs. We’ll visualize phase-space trajectories by way of Wigner features and quantify entanglement technology between coupled qubits. By the top of this tutorial, you’ll have constructed an entire workflow for state preparation, time evolution, open-system dynamics, and entanglement evaluation, all inside a Colab setting. Try the FULL CODES here.

!pip set up qutip matplotlib numpy


import numpy as np
import matplotlib.pyplot as plt
from qutip import *


print("🔬 Superior QuTip Tutorial: Quantum Dynamics & Entanglement")
print("=" * 60)

Within the setup part, we set up QuTiP together with NumPy and Matplotlib to make sure our Colab setting has all the mandatory libraries for quantum simulations. This step lays the groundwork for subsequent imports and ensures the reproducibility of our outcomes. Try the FULL CODES here.

print("n1. Creating Quantum States")
floor = foundation(2, 0) 
excited = foundation(2, 1) 
plus = (floor + excited).unit() 
minus = (floor - excited).unit() 


print(f"Floor state |0⟩: {floor.dag()}")
print(f"Superposition |+⟩: {plus.dag()}")


bell_phi_plus = (tensor(floor, floor) + tensor(excited, excited)).unit()
bell_psi_minus = (tensor(floor, excited) - tensor(excited, floor)).unit()


print(f"nBell state |Φ+⟩ = (|00⟩ + |11⟩)/√2")
rho_bell = bell_phi_plus * bell_phi_plus.dag()
print(f"Entanglement measure: {concurrence(rho_bell):.3f}")

We start by defining the computational foundation states |0⟩ and |1⟩ and establishing their superpositions |+⟩ and |–⟩ for instance fundamental qubit manipulations. We then create Bell states to reveal maximal entanglement, computing their concurrence to quantify the entanglement. Try the FULL CODES here.

print("n2. Quantum Gates and Operations")
sx, sy, sz = sigmax(), sigmay(), sigmaz()
print(f"Pauli-X matrix:n{sx}")


hadamard = (sx + sz) / np.sqrt(2)
cnot = tensor(fock_dm(2, 0), qeye(2)) + tensor(fock_dm(2, 1), sx)


h_ground = hadamard * floor
print(f"nH|0⟩ = {h_ground.dag()}")

We discover the Pauli operators σₓ, σᵧ, and σ_z as the basic constructing blocks of qubit rotations and reflections. Utilizing these, we assemble the Hadamard gate for superposition technology and the CNOT gate for entangling operations, making use of them to our ready states. Try the FULL CODES here.

print("n3. Quantum Dynamics: Rabi Oscillations")
omega_0 = 1.0 
omega_r = 0.5 


H = 0.5 * omega_0 * sz + 0.5 * omega_r * sx


t_list = np.linspace(0, 4*np.pi/omega_r, 100)
psi0 = floor
end result = mesolve(H, psi0, t_list, [], [])


excited_pop = [expect(fock_dm(2, 1), state) for state in result.states]


plt.determine(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.plot(t_list, excited_pop, 'b-', linewidth=2)
plt.xlabel('Time (ℏ/ω)')
plt.ylabel('Excited State Inhabitants')
plt.title('Rabi Oscillations')
plt.grid(True, alpha=0.3)

We mannequin a pushed two-level system with a Hamiltonian that {couples} σ_z and σₓ phrases to simulate Rabi oscillations. By time-evolving the bottom state below this Hamiltonian, we observe the excited-state inhabitants oscillations and visualize them over a full Rabi cycle. Try the FULL CODES here.

print("n4. Quantum Harmonic Oscillator")
N = 20 
a = destroy(N) 
H_ho = a.dag() * a + 0.5 


alpha = 2.0 
psi0_coh = coherent(N, alpha)


t_list_ho = np.linspace(0, 2*np.pi, 50)
result_ho = mesolve(H_ho, psi0_coh, t_list_ho, [], [])


x_op = (a + a.dag()) / np.sqrt(2)
p_op = 1j * (a.dag() - a) / np.sqrt(2)


x_expect = [expect(x_op, state) for state in result_ho.states]
p_expect = [expect(p_op, state) for state in result_ho.states]


plt.subplot(1, 2, 2)
plt.plot(x_expect, p_expect, 'r-', linewidth=2)
plt.plot(x_expect[0], p_expect[0], 'go', markersize=8, label='Begin')
plt.plot(x_expect[-1], p_expect[-1], 'ro', markersize=8, label='Finish')
plt.xlabel('⟨x⟩')
plt.ylabel('⟨p⟩')
plt.title('Coherent State Section Area')
plt.legend()
plt.grid(True, alpha=0.3)
plt.axis('equal')


plt.tight_layout()
plt.present()

We prolong our examine to an N-level harmonic oscillator, initializing a coherent state and evolving it below the usual​ Hamiltonian. We compute and plot the phase-space trajectory ⟨x⟩ vs. ⟨p⟩ to watch classical-like movement within the quantum regime. Try the FULL CODES here.

print("n5. Quantum Decoherence and Open Methods")
gamma = 0.2 
n_th = 0.1 


c_ops = [np.sqrt(gamma * (1 + n_th)) * a, np.sqrt(gamma * n_th) * a.dag()]


psi0_sq = squeeze(N, 0.5) * foundation(N, 0)


t_list_damp = np.linspace(0, 10, 100)
result_damp = mesolve(H_ho, psi0_sq, t_list_damp, c_ops, [])


n_expect = [expect(a.dag() * a, state) for state in result_damp.states]


plt.determine(figsize=(10, 4))
plt.subplot(1, 2, 1)
plt.plot(t_list_damp, n_expect, 'g-', linewidth=2)
plt.xlabel('Time')
plt.ylabel('⟨n⟩')
plt.title('Photon Quantity Decay')
plt.grid(True, alpha=0.3)

We introduce dissipation by way of collapse operators for a damped harmonic oscillator, simulating interplay with a thermal setting. We then evolve an preliminary squeezed state and monitor the decay of photon quantity ⟨n⟩ for instance decoherence results. Try the FULL CODES here.

print("n6. Wigner Perform Visualization")
final_state = result_damp.states[-1]
xvec = np.linspace(-4, 4, 50)
W_final = wigner(final_state, xvec, xvec)


plt.subplot(1, 2, 2)
plt.contourf(xvec, xvec, W_final, 20, cmap='RdBu')
plt.colorbar(label='W(x,p)')
plt.xlabel('x')
plt.ylabel('p')
plt.title('Wigner Perform (Ultimate State)')


plt.tight_layout()
plt.present()

We compute the Wigner quasi-probability distribution of the ultimate damped state on a grid in part area. By contour-plotting W(x,p), we achieve intuitive perception into nonclassical options and the impact of decoherence on state coherence. Try the FULL CODES here.

print("n7. Entanglement Dynamics")
omega1, omega2 = 1.0, 1.1
g = 0.1 


H_coupled = (omega1/2 * tensor(sz, qeye(2)) +
            omega2/2 * tensor(qeye(2), sz) +
            g * tensor(sx, sx))


psi0_prod = tensor(plus, floor)


t_list_ent = np.linspace(0, 20, 200)
result_ent = mesolve(H_coupled, psi0_prod, t_list_ent, [], [])


entanglement = [concurrence(state * state.dag()) for state in result_ent.states]


plt.determine(figsize=(8, 5))
plt.plot(t_list_ent, entanglement, 'purple', linewidth=2)
plt.xlabel('Time')
plt.ylabel('Concurrence')
plt.title('Entanglement Technology in Coupled Qubits')
plt.grid(True, alpha=0.3)
plt.ylim(0, 1)
plt.present()

We couple two qubits with a σₓ⊗σₓ interplay and evolve an preliminary product state, measuring concurrence at every time step. This enables us to watch the real-time buildup and decay of entanglement as a perform of coupling energy and detuning. Try the FULL CODES here.

print("n8. Abstract of Superior Options Demonstrated:")
print("✓ Quantum state preparation and manipulation")
print("✓ Time evolution with mesolve()")
print("✓ Rabi oscillations in two-level programs")
print("✓ Coherent states and harmonic oscillators")
print("✓ Open quantum programs with decoherence")
print("✓ Wigner perform visualization")
print("✓ Entanglement quantification and dynamics")


print(f"n🎯 Tutorial full! Explored {len(t_list_ent)} time steps")
print("Attempt modifying parameters to discover completely different quantum phenomena!")


print("n💡 Superior Workout routines:")
print("1. Implement quantum error correction codes")
print("2. Simulate quantum algorithms (Grover, Shor)")
print("3. Discover cavity QED with Jaynes-Cummings mannequin")
print("4. Research quantum part transitions")
print("5. Implement quantum suggestions management")

We recap the important thing demonstrations, state preparation, gate operations, time evolution, decoherence modeling, phase-space visualization, and entanglement quantification, and spotlight how QuTiP’s mesolve() and built-in features streamline these workflows. We conclude with ideas for superior workout routines to deepen our exploration of quantum phenomena.

In conclusion, we’ve gone via the cornerstone phenomena of quantum mechanics, from superposition and entanglement to decoherence and phase-space visualization, utilizing QuTiP’s intuitive API. Alongside the way in which, we ready quantum states, utilized gates, solved time-dependent dynamics with mesolve(), and quantified entanglement with concurrence. Our coherent-state and damped-oscillator examples revealed classical analogues in quantum part area, whereas the coupled-qubit simulation showcased real-time entanglement development. We encourage you to tweak parameters, corresponding to coupling strengths, damping charges, and preliminary states, to deepen your understanding.


Try the FULL CODES here. Be at liberty to take a look at our GitHub Page for Tutorials, Codes and Notebooks. Additionally, be happy to comply with us on Twitter and don’t neglect to hitch our 100k+ ML SubReddit and Subscribe to our Newsletter.

The publish A Coding Implementation of Quantum State Evolution, Decoherence, and Entanglement Dynamics using QuTiP appeared first on MarkTechPost.

Similar Posts