qutip
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseQuTiP: Quantum Toolbox in Python
QuTiP:Python量子工具箱
Overview
概述
QuTiP provides comprehensive tools for simulating and analyzing quantum mechanical systems. It handles both closed (unitary) and open (dissipative) quantum systems with multiple solvers optimized for different scenarios.
QuTiP为量子力学系统的模拟与分析提供全面工具。它支持处理封闭(幺正)和开放(耗散)量子系统,并针对不同场景优化了多种求解器。
Installation
安装
bash
uv pip install qutipOptional packages for additional functionality:
bash
undefinedbash
uv pip install qutip可选扩展功能包:
bash
undefinedQuantum information processing (circuits, gates)
量子信息处理(电路、量子门)
uv pip install qutip-qip
uv pip install qutip-qip
Quantum trajectory viewer
量子轨迹可视化工具
uv pip install qutip-qtrl
undefineduv pip install qutip-qtrl
undefinedQuick Start
快速开始
python
from qutip import *
import numpy as np
import matplotlib.pyplot as pltpython
from qutip import *
import numpy as np
import matplotlib.pyplot as pltCreate quantum state
创建量子态
psi = basis(2, 0) # |0⟩ state
psi = basis(2, 0) # |0⟩ 态
Create operator
创建哈密顿量
H = sigmaz() # Hamiltonian
H = sigmaz() # 泡利Z算符
Time evolution
时间演化
tlist = np.linspace(0, 10, 100)
result = sesolve(H, psi, tlist, e_ops=[sigmaz()])
tlist = np.linspace(0, 10, 100)
result = sesolve(H, psi, tlist, e_ops=[sigmaz()])
Plot results
绘制结果
plt.plot(tlist, result.expect[0])
plt.xlabel('Time')
plt.ylabel('⟨σz⟩')
plt.show()
undefinedplt.plot(tlist, result.expect[0])
plt.xlabel('Time')
plt.ylabel('⟨σz⟩')
plt.show()
undefinedCore Capabilities
核心功能
1. Quantum Objects and States
1. 量子对象与量子态
Create and manipulate quantum states and operators:
python
undefined创建并操作量子态与算符:
python
undefinedStates
量子态
psi = basis(N, n) # Fock state |n⟩
psi = coherent(N, alpha) # Coherent state |α⟩
rho = thermal_dm(N, n_avg) # Thermal density matrix
psi = basis(N, n) # 福克态 |n⟩
psi = coherent(N, alpha) # 相干态 |α⟩
rho = thermal_dm(N, n_avg) # 热密度矩阵
Operators
量子算符
a = destroy(N) # Annihilation operator
H = num(N) # Number operator
sx, sy, sz = sigmax(), sigmay(), sigmaz() # Pauli matrices
a = destroy(N) # 湮灭算符
H = num(N) # 数算符
sx, sy, sz = sigmax(), sigmay(), sigmaz() # 泡利矩阵
Composite systems
复合系统
psi_AB = tensor(psi_A, psi_B) # Tensor product
**See** `references/core_concepts.md` for comprehensive coverage of quantum objects, states, operators, and tensor products.psi_AB = tensor(psi_A, psi_B) # 张量积
**参考** `references/core_concepts.md` 以全面了解量子对象、量子态、算符及张量积相关内容。2. Time Evolution and Dynamics
2. 时间演化与动力学
Multiple solvers for different scenarios:
python
undefined针对不同场景提供多种求解器:
python
undefinedClosed systems (unitary evolution)
封闭系统(幺正演化)
result = sesolve(H, psi0, tlist, e_ops=[num(N)])
result = sesolve(H, psi0, tlist, e_ops=[num(N)])
Open systems (dissipation)
开放系统(含耗散)
c_ops = [np.sqrt(0.1) * destroy(N)] # Collapse operators
result = mesolve(H, psi0, tlist, c_ops, e_ops=[num(N)])
c_ops = [np.sqrt(0.1) * destroy(N)] # 坍缩算符
result = mesolve(H, psi0, tlist, c_ops, e_ops=[num(N)])
Quantum trajectories (Monte Carlo)
量子轨迹(蒙特卡洛方法)
result = mcsolve(H, psi0, tlist, c_ops, ntraj=500, e_ops=[num(N)])
**Solver selection guide:**
- `sesolve`: Pure states, unitary evolution
- `mesolve`: Mixed states, dissipation, general open systems
- `mcsolve`: Quantum jumps, photon counting, individual trajectories
- `brmesolve`: Weak system-bath coupling
- `fmmesolve`: Time-periodic Hamiltonians (Floquet)
**See** `references/time_evolution.md` for detailed solver documentation, time-dependent Hamiltonians, and advanced options.result = mcsolve(H, psi0, tlist, c_ops, ntraj=500, e_ops=[num(N)])
**求解器选择指南:**
- `sesolve`:纯态、幺正演化
- `mesolve`:混合态、耗散、通用开放系统
- `mcsolve`:量子跳跃、光子计数、单个轨迹
- `brmesolve`:弱系统-环境耦合
- `fmmesolve`:含时周期哈密顿量(弗洛凯理论)
**参考** `references/time_evolution.md` 获取求解器详细文档、含时哈密顿量及进阶选项说明。3. Analysis and Measurement
3. 分析与测量
Compute physical quantities:
python
undefined计算物理量:
python
undefinedExpectation values
期望值
n_avg = expect(num(N), psi)
n_avg = expect(num(N), psi)
Entropy measures
熵度量
S = entropy_vn(rho) # Von Neumann entropy
C = concurrence(rho) # Entanglement (two qubits)
S = entropy_vn(rho) # 冯·诺依曼熵
C = concurrence(rho) # 纠缠度(两量子比特)
Fidelity and distance
保真度与距离
F = fidelity(psi1, psi2)
D = tracedist(rho1, rho2)
F = fidelity(psi1, psi2)
D = tracedist(rho1, rho2)
Correlation functions
关联函数
corr = correlation_2op_1t(H, rho0, taulist, c_ops, A, B)
w, S = spectrum_correlation_fft(taulist, corr)
corr = correlation_2op_1t(H, rho0, taulist, c_ops, A, B)
w, S = spectrum_correlation_fft(taulist, corr)
Steady states
稳态
rho_ss = steadystate(H, c_ops)
**See** `references/analysis.md` for entropy, fidelity, measurements, correlation functions, and steady state calculations.rho_ss = steadystate(H, c_ops)
**参考** `references/analysis.md` 了解熵、保真度、测量、关联函数及稳态计算相关内容。4. Visualization
4. 可视化
Visualize quantum states and dynamics:
python
undefined可视化量子态与动力学过程:
python
undefinedBloch sphere
布洛赫球
b = Bloch()
b.add_states(psi)
b.show()
b = Bloch()
b.add_states(psi)
b.show()
Wigner function (phase space)
维格纳函数(相空间)
xvec = np.linspace(-5, 5, 200)
W = wigner(psi, xvec, xvec)
plt.contourf(xvec, xvec, W, 100, cmap='RdBu')
xvec = np.linspace(-5, 5, 200)
W = wigner(psi, xvec, xvec)
plt.contourf(xvec, xvec, W, 100, cmap='RdBu')
Fock distribution
福克分布
plot_fock_distribution(psi)
plot_fock_distribution(psi)
Matrix visualization
矩阵可视化
hinton(rho) # Hinton diagram
matrix_histogram(H.full()) # 3D bars
**See** `references/visualization.md` for Bloch sphere animations, Wigner functions, Q-functions, and matrix visualizations.hinton(rho) # 辛顿图
matrix_histogram(H.full()) # 3D柱状图
**参考** `references/visualization.md` 了解布洛赫球动画、维格纳函数、Q函数及矩阵可视化相关内容。5. Advanced Methods
5. 进阶方法
Specialized techniques for complex scenarios:
python
undefined针对复杂场景的专用技术:
python
undefinedFloquet theory (periodic Hamiltonians)
弗洛凯理论(周期哈密顿量)
T = 2 * np.pi / w_drive
f_modes, f_energies = floquet_modes(H, T, args)
result = fmmesolve(H, psi0, tlist, c_ops, T=T, args=args)
T = 2 * np.pi / w_drive
f_modes, f_energies = floquet_modes(H, T, args)
result = fmmesolve(H, psi0, tlist, c_ops, T=T, args=args)
HEOM (non-Markovian, strong coupling)
HEOM(非马尔可夫、强耦合)
from qutip.nonmarkov.heom import HEOMSolver, BosonicBath
bath = BosonicBath(Q, ck_real, vk_real)
hsolver = HEOMSolver(H_sys, [bath], max_depth=5)
result = hsolver.run(rho0, tlist)
from qutip.nonmarkov.heom import HEOMSolver, BosonicBath
bath = BosonicBath(Q, ck_real, vk_real)
hsolver = HEOMSolver(H_sys, [bath], max_depth=5)
result = hsolver.run(rho0, tlist)
Permutational invariance (identical particles)
置换不变性(全同粒子)
psi = dicke(N, j, m) # Dicke states
Jz = jspin(N, 'z') # Collective operators
**See** `references/advanced.md` for Floquet theory, HEOM, permutational invariance, stochastic solvers, superoperators, and performance optimization.psi = dicke(N, j, m) # 迪克态
Jz = jspin(N, 'z') # 集体算符
**参考** `references/advanced.md` 了解弗洛凯理论、HEOM、置换不变性、随机求解器、超算符及性能优化相关内容。Common Workflows
常见工作流
Simulating a Damped Harmonic Oscillator
模拟阻尼谐振子
python
undefinedpython
undefinedSystem parameters
系统参数
N = 20 # Hilbert space dimension
omega = 1.0 # Oscillator frequency
kappa = 0.1 # Decay rate
N = 20 # 希尔伯特空间维度
omega = 1.0 # 振子频率
kappa = 0.1 # 衰减率
Hamiltonian and collapse operators
哈密顿量与坍缩算符
H = omega * num(N)
c_ops = [np.sqrt(kappa) * destroy(N)]
H = omega * num(N)
c_ops = [np.sqrt(kappa) * destroy(N)]
Initial state
初始态
psi0 = coherent(N, 3.0)
psi0 = coherent(N, 3.0)
Time evolution
时间演化
tlist = np.linspace(0, 50, 200)
result = mesolve(H, psi0, tlist, c_ops, e_ops=[num(N)])
tlist = np.linspace(0, 50, 200)
result = mesolve(H, psi0, tlist, c_ops, e_ops=[num(N)])
Visualize
可视化
plt.plot(tlist, result.expect[0])
plt.xlabel('Time')
plt.ylabel('⟨n⟩')
plt.title('Photon Number Decay')
plt.show()
undefinedplt.plot(tlist, result.expect[0])
plt.xlabel('Time')
plt.ylabel('⟨n⟩')
plt.title('光子数衰减')
plt.show()
undefinedTwo-Qubit Entanglement Dynamics
两量子比特纠缠动力学
python
undefinedpython
undefinedCreate Bell state
创建贝尔态
psi0 = bell_state('00')
psi0 = bell_state('00')
Local dephasing on each qubit
每个量子比特的局部退相位
gamma = 0.1
c_ops = [
np.sqrt(gamma) * tensor(sigmaz(), qeye(2)),
np.sqrt(gamma) * tensor(qeye(2), sigmaz())
]
gamma = 0.1
c_ops = [
np.sqrt(gamma) * tensor(sigmaz(), qeye(2)),
np.sqrt(gamma) * tensor(qeye(2), sigmaz())
]
Track entanglement
追踪纠缠度
def compute_concurrence(t, psi):
rho = ket2dm(psi) if psi.isket else psi
return concurrence(rho)
tlist = np.linspace(0, 10, 100)
result = mesolve(qeye([2, 2]), psi0, tlist, c_ops)
def compute_concurrence(t, psi):
rho = ket2dm(psi) if psi.isket else psi
return concurrence(rho)
tlist = np.linspace(0, 10, 100)
result = mesolve(qeye([2, 2]), psi0, tlist, c_ops)
Compute concurrence for each state
计算每个态的纠缠度
C_t = [concurrence(state.proj()) for state in result.states]
plt.plot(tlist, C_t)
plt.xlabel('Time')
plt.ylabel('Concurrence')
plt.title('Entanglement Decay')
plt.show()
undefinedC_t = [concurrence(state.proj()) for state in result.states]
plt.plot(tlist, C_t)
plt.xlabel('Time')
plt.ylabel('Concurrence')
plt.title('纠缠度衰减')
plt.show()
undefinedJaynes-Cummings Model
Jaynes-Cummings模型
python
undefinedpython
undefinedSystem parameters
系统参数
N = 10 # Cavity Fock space
wc = 1.0 # Cavity frequency
wa = 1.0 # Atom frequency
g = 0.05 # Coupling strength
N = 10 # 腔福克空间维度
wc = 1.0 # 腔频率
wa = 1.0 # 原子频率
g = 0.05 # 耦合强度
Operators
算符
a = tensor(destroy(N), qeye(2)) # Cavity
sm = tensor(qeye(N), sigmam()) # Atom
a = tensor(destroy(N), qeye(2)) # 腔算符
sm = tensor(qeye(N), sigmam()) # 原子算符
Hamiltonian (RWA)
哈密顿量(旋转波近似)
H = wc * a.dag() * a + wa * sm.dag() * sm + g * (a.dag() * sm + a * sm.dag())
H = wc * a.dag() * a + wa * sm.dag() * sm + g * (a.dag() * sm + a * sm.dag())
Initial state: cavity in coherent state, atom in ground state
初始态:腔处于相干态,原子处于基态
psi0 = tensor(coherent(N, 2), basis(2, 0))
psi0 = tensor(coherent(N, 2), basis(2, 0))
Dissipation
耗散
kappa = 0.1 # Cavity decay
gamma = 0.05 # Atomic decay
c_ops = [np.sqrt(kappa) * a, np.sqrt(gamma) * sm]
kappa = 0.1 # 腔衰减
gamma = 0.05 # 原子衰减
c_ops = [np.sqrt(kappa) * a, np.sqrt(gamma) * sm]
Observables
可观测量
n_cav = a.dag() * a
n_atom = sm.dag() * sm
n_cav = a.dag() * a
n_atom = sm.dag() * sm
Evolve
演化
tlist = np.linspace(0, 50, 200)
result = mesolve(H, psi0, tlist, c_ops, e_ops=[n_cav, n_atom])
tlist = np.linspace(0, 50, 200)
result = mesolve(H, psi0, tlist, c_ops, e_ops=[n_cav, n_atom])
Plot
绘图
fig, axes = plt.subplots(2, 1, figsize=(8, 6), sharex=True)
axes[0].plot(tlist, result.expect[0])
axes[0].set_ylabel('⟨n_cavity⟩')
axes[1].plot(tlist, result.expect[1])
axes[1].set_ylabel('⟨n_atom⟩')
axes[1].set_xlabel('Time')
plt.tight_layout()
plt.show()
undefinedfig, axes = plt.subplots(2, 1, figsize=(8, 6), sharex=True)
axes[0].plot(tlist, result.expect[0])
axes[0].set_ylabel('⟨n_cavity⟩')
axes[1].plot(tlist, result.expect[1])
axes[1].set_ylabel('⟨n_atom⟩')
axes[1].set_xlabel('Time')
plt.tight_layout()
plt.show()
undefinedTips for Efficient Simulations
高效模拟技巧
- Truncate Hilbert spaces: Use smallest dimension that captures dynamics
- Choose appropriate solver: for pure states is faster than
sesolvemesolve - Time-dependent terms: String format (e.g., ) is fastest
'cos(w*t)' - Store only needed data: Use instead of storing all states
e_ops - Adjust tolerances: Balance accuracy with computation time via
Options - Parallel trajectories: automatically uses multiple CPUs
mcsolve - Check convergence: Vary , Hilbert space size, and tolerances
ntraj
- 截断希尔伯特空间:使用能捕捉动力学过程的最小维度
- 选择合适的求解器:处理纯态的速度快于
sesolvemesolve - 含时项:字符串格式(如)速度最快
'cos(w*t)' - 仅存储所需数据:使用而非存储所有态
e_ops - 调整容差:通过在精度与计算时间间取得平衡
Options - 并行轨迹:会自动使用多CPU
mcsolve - 检查收敛性:调整、希尔伯特空间大小及容差
ntraj
Troubleshooting
故障排除
Memory issues: Reduce Hilbert space dimension, use option, or consider Krylov methods
store_final_stateSlow simulations: Use string-based time-dependence, increase tolerances slightly, or try for stiff problems
method='bdf'Numerical instabilities: Decrease time steps ( option), increase tolerances, or check Hamiltonian/operators are properly defined
nstepsImport errors: Ensure QuTiP is installed correctly; quantum gates require package
qutip-qip内存问题:减小希尔伯特空间维度,使用选项,或考虑使用Krylov方法
store_final_state模拟缓慢:使用字符串格式的含时项,略微提高容差,或针对刚性问题尝试
method='bdf'数值不稳定性:减小时间步长(选项),提高容差,或检查哈密顿量/算符定义是否正确
nsteps导入错误:确保QuTiP安装正确;量子门功能需要安装包
qutip-qipReferences
参考资料
This skill includes detailed reference documentation:
- : Quantum objects, states, operators, tensor products, composite systems
references/core_concepts.md - : All solvers (sesolve, mesolve, mcsolve, brmesolve, etc.), time-dependent Hamiltonians, solver options
references/time_evolution.md - : Bloch sphere, Wigner functions, Q-functions, Fock distributions, matrix plots
references/visualization.md - : Expectation values, entropy, fidelity, entanglement measures, correlation functions, steady states
references/analysis.md - : Floquet theory, HEOM, permutational invariance, stochastic methods, superoperators, performance tips
references/advanced.md
本技能包含详细的参考文档:
- :量子对象、量子态、算符、张量积、复合系统
references/core_concepts.md - :所有求解器(sesolve、mesolve、mcsolve、brmesolve等)、含时哈密顿量、求解器选项
references/time_evolution.md - :布洛赫球、维格纳函数、Q函数、福克分布、矩阵绘图
references/visualization.md - :期望值、熵、保真度、纠缠度量、关联函数、稳态计算
references/analysis.md - :弗洛凯理论、HEOM、置换不变性、随机方法、超算符、性能优化
references/advanced.md
External Resources
外部资源
- Documentation: https://qutip.readthedocs.io/
- Tutorials: https://qutip.org/qutip-tutorials/
- API Reference: https://qutip.readthedocs.io/en/stable/apidoc/apidoc.html
- GitHub: https://github.com/qutip/qutip