Comprehensive Python library for simulating quantum systems dynamics and quantum information processing.
—
Creation of fundamental quantum states including basis states, coherent states, squeezed states, and multi-qubit entangled states.
Fundamental quantum states for various physical systems.
def basis(N: int, n: int = 0, offset: int = 0) -> Qobj:
"""
Create basis state |n⟩ in N-dimensional Hilbert space.
Parameters:
- N: Dimension of Hilbert space
- n: Index of basis state (0 to N-1)
- offset: Lowest number state index
Returns:
- Qobj: Basis state |n⟩
"""
def fock(N: int, n: int = 0, offset: int = 0) -> Qobj:
"""
Create Fock state |n⟩ (alias for basis).
Parameters:
- N: Dimension of Hilbert space
- n: Photon/particle number
- offset: Lowest number state index
Returns:
- Qobj: Fock state |n⟩
"""
def fock_dm(N: int, n: int = 0, offset: int = 0) -> Qobj:
"""
Create Fock state density matrix |n⟩⟨n|.
Parameters:
- N: Dimension of Hilbert space
- n: Photon/particle number
- offset: Lowest number state index
Returns:
- Qobj: Fock state density matrix
"""
def qutrit_basis() -> list:
"""
Create set of qutrit basis states {|0⟩, |1⟩, |2⟩}.
Returns:
- list: List of three qutrit basis states
"""
def zero_ket(N: int, dims: list = None) -> Qobj:
"""
Create zero ket state |0⟩.
Parameters:
- N: Dimension of Hilbert space
- dims: Dimensions for tensor structure
Returns:
- Qobj: Zero state |0⟩
"""States for continuous variable quantum systems and quantum optics.
def coherent(N: int, alpha: complex, offset: int = 0, method: str = 'operator') -> Qobj:
"""
Create coherent state |α⟩.
Parameters:
- N: Dimension of Hilbert space truncation
- alpha: Complex coherent state amplitude
- offset: Lowest number state index
- method: 'operator' or 'analytic' calculation method
Returns:
- Qobj: Coherent state |α⟩
"""
def coherent_dm(N: int, alpha: complex, offset: int = 0, method: str = 'operator') -> Qobj:
"""
Create coherent state density matrix |α⟩⟨α|.
Parameters:
- N: Dimension of Hilbert space truncation
- alpha: Complex coherent state amplitude
- offset: Lowest number state index
- method: 'operator' or 'analytic' calculation method
Returns:
- Qobj: Coherent state density matrix
"""
def squeezed(N: int, z: complex, offset: int = 0, method: str = 'operator') -> Qobj:
"""
Create squeezed vacuum state.
Parameters:
- N: Dimension of Hilbert space truncation
- z: Complex squeezing parameter
- offset: Lowest number state index
- method: 'operator' or 'analytic' calculation method
Returns:
- Qobj: Squeezed vacuum state
"""
def displaced_fock(N: int, n: int, alpha: complex, offset: int = 0) -> Qobj:
"""
Create displaced Fock state D(α)|n⟩.
Parameters:
- N: Dimension of Hilbert space truncation
- n: Initial Fock state number
- alpha: Displacement amplitude
- offset: Lowest number state index
Returns:
- Qobj: Displaced Fock state
"""Thermal equilibrium states and mixed quantum states.
def thermal_dm(N: int, n: float, method: str = 'operator') -> Qobj:
"""
Create thermal state density matrix.
Parameters:
- N: Dimension of Hilbert space truncation
- n: Average thermal photon number
- method: 'operator' or 'analytic' calculation method
Returns:
- Qobj: Thermal state density matrix
"""
def maximally_mixed_dm(N: int, dims: list = None) -> Qobj:
"""
Create maximally mixed state ρ = I/N.
Parameters:
- N: Dimension of Hilbert space
- dims: Dimensions for tensor structure
Returns:
- Qobj: Maximally mixed density matrix
"""
def ket2dm(state: Qobj) -> Qobj:
"""
Convert ket state to density matrix |ψ⟩⟨ψ|.
Parameters:
- state: Input ket state
Returns:
- Qobj: Density matrix representation
"""States for spin systems and angular momentum representations.
def spin_state(j: float, m: float, type: str = 'ket') -> Qobj:
"""
Create spin state |j,m⟩.
Parameters:
- j: Total angular momentum quantum number
- m: Magnetic quantum number (-j ≤ m ≤ j)
- type: 'ket' for state vector, 'dm' for density matrix
Returns:
- Qobj: Spin state |j,m⟩ or density matrix
"""
def spin_coherent(j: float, theta: float, phi: float, type: str = 'ket') -> Qobj:
"""
Create spin coherent state.
Parameters:
- j: Spin quantum number
- theta: Polar angle (0 to π)
- phi: Azimuthal angle (0 to 2π)
- type: 'ket' for state vector, 'dm' for density matrix
Returns:
- Qobj: Spin coherent state
"""Entangled states for quantum information and quantum computing applications.
def bell_state(state: str = '00') -> Qobj:
"""
Create Bell state.
Parameters:
- state: '00', '01', '10', or '11' for different Bell states
Returns:
- Qobj: Bell state (|00⟩±|11⟩)/√2 or (|01⟩±|10⟩)/√2
"""
def singlet_state() -> Qobj:
"""
Create singlet state (|01⟩-|10⟩)/√2.
Returns:
- Qobj: Singlet state
"""
def triplet_states() -> list:
"""
Create triplet states |T₁⟩, |T₀⟩, |T₋₁⟩.
Returns:
- list: List of three triplet state Qobj's
"""
def ghz_state(N: int = 3) -> Qobj:
"""
Create N-qubit GHZ state (|00...0⟩+|11...1⟩)/√2.
Parameters:
- N: Number of qubits
Returns:
- Qobj: N-qubit GHZ state
"""
def w_state(N: int = 3) -> Qobj:
"""
Create N-qubit W state (|100...0⟩+|010...0⟩+...+|00...01⟩)/√N.
Parameters:
- N: Number of qubits
Returns:
- Qobj: N-qubit W state
"""States for quantum computing in computational basis.
def qstate(string: str, targets: list = None) -> Qobj:
"""
Create multi-qubit computational basis state from string.
Parameters:
- string: Binary string like '0101' or '++--' for Pauli eigenstates
- targets: List of target qubit indices
Returns:
- Qobj: Multi-qubit computational basis state
"""
def ket(string: str, dim: int = 2) -> Qobj:
"""
Create ket state from string representation.
Parameters:
- string: String representation of quantum state
- dim: Dimension per subsystem
Returns:
- Qobj: Ket state vector
"""
def bra(string: str, dim: int = 2) -> Qobj:
"""
Create bra state from string representation.
Parameters:
- string: String representation of quantum state
- dim: Dimension per subsystem
Returns:
- Qobj: Bra state vector
"""Utilities for working with multi-level system state indexing.
def state_number_enumerate(dims: list) -> list:
"""
Enumerate all possible state configurations for composite system.
Parameters:
- dims: List of dimensions for each subsystem
Returns:
- list: All possible state number combinations
"""
def state_number_index(dims: list, state: list) -> int:
"""
Convert state number list to single index.
Parameters:
- dims: List of dimensions for each subsystem
- state: List of state numbers for each subsystem
Returns:
- int: Single index representing the state
"""
def state_index_number(dims: list, index: int) -> list:
"""
Convert single index to state number list.
Parameters:
- dims: List of dimensions for each subsystem
- index: Single index representing the state
Returns:
- list: List of state numbers for each subsystem
"""
def state_number_qobj(dims: list, state: list) -> Qobj:
"""
Create basis state from state number list.
Parameters:
- dims: List of dimensions for each subsystem
- state: List of state numbers for each subsystem
Returns:
- Qobj: Basis state corresponding to state numbers
"""Specialized states for continuous variable and phase space representations.
def phase_basis(N: int, m: int, phi0: float = 0) -> Qobj:
"""
Create Pegg-Barnett phase eigenstate.
Parameters:
- N: Dimension of Hilbert space
- m: Phase state index
- phi0: Reference phase
Returns:
- Qobj: Phase eigenstate
"""States and projectors for measurement and quantum operations.
def projection(N: int, n: int, offset: int = 0) -> Qobj:
"""
Create projection operator |n⟩⟨n|.
Parameters:
- N: Dimension of Hilbert space
- n: Index of basis state
- offset: Lowest number state index
Returns:
- Qobj: Projection operator
"""import qutip as qt
import numpy as np
# Basic states
ground = qt.basis(2, 0) # |0⟩ ground state
excited = qt.basis(2, 1) # |1⟩ excited state
superpos = (ground + excited).unit() # (|0⟩+|1⟩)/√2
# Harmonic oscillator states
vacuum = qt.fock(10, 0) # |0⟩ vacuum state
n1_state = qt.fock(10, 1) # |1⟩ single photon
thermal = qt.thermal_dm(10, 0.5) # Thermal state with ⟨n⟩=0.5
# Coherent states
alpha = 1.0 + 0.5j
coh_state = qt.coherent(20, alpha) # Coherent state |α⟩
coh_dm = qt.coherent_dm(20, alpha) # Coherent density matrix
# Squeezed states
squeeze_param = 0.5
squeezed = qt.squeezed(20, squeeze_param)
# Multi-qubit entangled states
bell = qt.bell_state('00') # |Φ⁺⟩ = (|00⟩+|11⟩)/√2
ghz3 = qt.ghz_state(3) # 3-qubit GHZ state
w3 = qt.w_state(3) # 3-qubit W state
# Spin states
j_half_up = qt.spin_state(0.5, 0.5) # |1/2, 1/2⟩ spin-up
j_half_down = qt.spin_state(0.5, -0.5) # |1/2, -1/2⟩ spin-down
# Spin coherent state pointing along (θ,φ)
theta, phi = np.pi/4, np.pi/3
spin_coh = qt.spin_coherent(0.5, theta, phi)
# Computational basis states from strings
three_qubit = qt.qstate('101') # |101⟩ computational basis
pauli_eigen = qt.qstate('+-+') # Pauli eigenstate
# Mixed states
mixed = qt.maximally_mixed_dm(4) # Maximally mixed 4-level system
# Custom superposition
psi = 0.6*qt.basis(3,0) + 0.8*qt.basis(3,2) # |ψ⟩ = 0.6|0⟩ + 0.8|2⟩
psi = psi.unit() # Normalize# State construction functions return Qobj instances representing quantum states
# with appropriate dimensions and type attributes ('ket', 'bra', or 'oper' for density matrices)