Python library for simulating superconducting qubits with energy spectra, plotting, and QuTiP integration
—
Comprehensive implementations of superconducting qubit circuits with customizable parameters and built-in analysis capabilities. Each qubit model provides methods for eigenvalue calculations, Hamiltonian construction, and visualization.
Cooper-pair box implementation optimized for the transmon regime where charging energy is much smaller than Josephson energy, providing protection against charge noise.
class Transmon:
def __init__(self, EJ: float, EC: float, ng: float, ncut: int,
truncated_dim: int = 6, id_str: str = None,
evals_method: str = None, evals_method_options: dict = None,
esys_method: str = None, esys_method_options: dict = None):
"""
Cooper-pair box / transmon qubit.
Parameters:
- EJ (float): Josephson energy in system units
- EC (float): Charging energy in system units
- ng (float): Offset charge in units of 2e
- ncut (int): Charge basis cutoff, should be >= 5 for convergence
- truncated_dim (int): Truncated Hilbert space dimension (default: 6)
- id_str (str): Optional identifier string
- evals_method (str): Method for eigenvalue calculations
- evals_method_options (dict): Options for eigenvalue method
- esys_method (str): Method for eigensystem calculations
- esys_method_options (dict): Options for eigensystem method
"""
def hamiltonian(self) -> np.ndarray:
"""Return Hamiltonian matrix in charge basis."""
def eigenvals(self, evals_count: int = 6) -> np.ndarray:
"""Calculate eigenvalues (energy levels)."""
def eigensys(self, evals_count: int = 6) -> tuple:
"""Calculate eigenvalues and eigenvectors."""
def plot_evals_vs_paramvals(self, param_name: str, param_vals: np.ndarray,
evals_count: int = 6, **kwargs):
"""Plot energy levels vs parameter values."""
def wavefunction(self, esys: tuple = None, which: int = 0,
mode: str = 'abs_sqr') -> WaveFunction:
"""Return wavefunction for specified eigenstate."""
@property
def n_operator(self) -> np.ndarray:
"""Number operator matrix in charge basis."""
@property
def exp_i_phi_operator(self) -> np.ndarray:
"""Exponential of i*phi operator matrix."""
@property
def cos_phi_operator(self) -> np.ndarray:
"""Cosine phi operator matrix."""
@property
def sin_phi_operator(self) -> np.ndarray:
"""Sine phi operator matrix."""Transmon with flux-tunable Josephson energy for frequency control and sweet spot operation.
class TunableTransmon:
def __init__(self, EJmax: float, EC: float, d: float, flux: float,
ng: float, ncut: int, truncated_dim: int = 6,
id_str: str = None, evals_method: str = None):
"""
Tunable transmon with flux control.
Parameters:
- EJmax (float): Maximum Josephson energy
- EC (float): Charging energy
- d (float): Junction asymmetry parameter
- flux (float): External flux in units of flux quantum
- ng (float): Offset charge
- ncut (int): Charge basis cutoff
- truncated_dim (int): Truncated dimension (default: 6)
- id_str (str): Optional identifier string
- evals_method (str): Method for eigenvalue calculations
"""
def effective_EJ(self) -> float:
"""Calculate effective Josephson energy at current flux."""Heavy fluxonium implementation with large superinductance, providing protection against flux noise in certain parameter regimes.
class Fluxonium:
def __init__(self, EJ: float, EC: float, EL: float, flux: float,
cutoff: int = 110, truncated_dim: int = None):
"""
Fluxonium qubit with superinductance.
Parameters:
- EJ (float): Josephson energy
- EC (float): Charging energy
- EL (float): Inductive energy
- flux (float): External flux in units of flux quantum
- cutoff (int): Phi basis cutoff for discretization
- truncated_dim (int): Truncated dimension
"""
def phi_osc(self) -> float:
"""Oscillator length scale for phi coordinate."""
def E_plasma(self) -> float:
"""Plasma frequency."""
def plot_potential(self, phi_grid: np.ndarray = None, contour_vals: np.ndarray = None):
"""Plot effective potential energy."""Three-junction flux qubit implementation supporting both symmetric and asymmetric designs with C-shunt configuration.
class FluxQubit:
def __init__(self, EJ1: float, EJ2: float, EJ3: float, ECJ1: float, ECJ2: float, ECJ3: float,
ECg1: float, ECg2: float, ng1: float = 0.0, ng2: float = 0.0, flux: float = 0.0,
ncut: int = 10, truncated_dim: int = None):
"""
Three-junction flux qubit.
Parameters:
- EJ1, EJ2, EJ3 (float): Josephson energies of three junctions
- ECJ1, ECJ2, ECJ3 (float): Junction charging energies
- ECg1, ECg2 (float): Gate coupling energies
- ng1, ng2 (float): Offset charges
- flux (float): External flux threading the loop
- ncut (int): Charge basis cutoff
- truncated_dim (int): Truncated dimension
"""
def hamiltonian(self) -> np.ndarray:
"""Hamiltonian matrix in charge basis."""
def potential(self, phi1: float, phi2: float) -> float:
"""Potential energy at given phase coordinates."""Implementation of the 0-π qubit design with charge protection through large charging energy.
class ZeroPi:
def __init__(self, EJ: float, EL: float, ECJ: float, EC: float, ng: float = 0.0,
flux: float = 0.0, grid: Grid1d = None, ncut: int = 30, truncated_dim: int = None):
"""
Zero-pi qubit with charge protection.
Parameters:
- EJ (float): Josephson energy
- EL (float): Inductive energy
- ECJ (float): Junction charging energy
- EC (float): Island charging energy
- ng (float): Offset charge
- flux (float): External flux
- grid (Grid1d): Discretization grid for phi variable
- ncut (int): Charge basis cutoff
- truncated_dim (int): Truncated dimension
"""
def hilbertdim(self) -> int:
"""Dimension of Hilbert space."""
def potential(self, phi: float, theta: float) -> float:
"""Potential energy at phase coordinates."""Extended 0-π qubit model with complete parameter set for detailed modeling.
class FullZeroPi:
def __init__(self, EJ: float, EL: float, ECJ: float, EC: float, dEJ: float = 0.0,
dEL: float = 0.0, flux: float = 0.0, ng: float = 0.0, zeropi_cutoff: int = 10,
zeta_cutoff: int = 10, truncated_dim: int = None):
"""
Full zero-pi qubit model.
Parameters:
- EJ (float): Josephson energy
- EL (float): Inductive energy
- ECJ (float): Junction charging energy
- EC (float): Island charging energy
- dEJ (float): Junction energy disorder
- dEL (float): Inductance disorder
- flux (float): External flux
- ng (float): Offset charge
- zeropi_cutoff (int): Cutoff for zero-pi mode
- zeta_cutoff (int): Cutoff for zeta mode
- truncated_dim (int): Truncated dimension
"""Protected qubit design using cos(2φ) potential for enhanced coherence.
class Cos2PhiQubit:
def __init__(self, EJ: float, EC: float, ECJ: float, ng: float = 0.0, flux: float = 0.0,
grid: Grid1d = None, ncut: int = 30, truncated_dim: int = None):
"""
Cos(2φ) protected qubit.
Parameters:
- EJ (float): Josephson energy of junctions
- EC (float): Charging energy of island
- ECJ (float): Junction charging energy
- ng (float): Offset charge
- flux (float): External flux
- grid (Grid1d): Discretization grid for phi
- ncut (int): Charge basis cutoff
- truncated_dim (int): Truncated dimension
"""
def n_theta_operator(self) -> np.ndarray:
"""Charge operator conjugate to theta."""
def phi_operator(self) -> np.ndarray:
"""Phi phase operator matrix."""Custom qubit class for user-provided Hamiltonians and energy eigenvalue data.
class GenericQubit:
def __init__(self, hamiltonian: np.ndarray = None, truncated_dim: int = None,
energy_esys: tuple = None):
"""
Generic qubit from user-defined Hamiltonian.
Parameters:
- hamiltonian (np.ndarray): User-provided Hamiltonian matrix
- truncated_dim (int): Truncated Hilbert space dimension
- energy_esys (tuple): Pre-computed (eigenvals, eigenvecs) tuple
"""
def eigenvals(self, evals_count: int = 6) -> np.ndarray:
"""Calculate or return stored eigenvalues."""
def eigensys(self, evals_count: int = 6) -> tuple:
"""Calculate or return stored eigensystem."""import scqubits as scq
import numpy as np
# Create transmon with typical parameters
transmon = scq.Transmon(EJ=25.0, EC=0.2, ng=0.0, ncut=30)
# Calculate first 6 energy levels
energies = transmon.eigenvals(evals_count=6)
print("Energy levels:", energies)
# Get full eigensystem
evals, evecs = transmon.eigensys(evals_count=6)
# Plot spectrum vs offset charge
ng_vals = np.linspace(-2, 2, 100)
transmon.plot_evals_vs_paramvals('ng', ng_vals, evals_count=4)
# Calculate matrix elements
n_matrix = transmon.matrix_elements(transmon.n_operator)# Create fluxonium
fluxonium = scq.Fluxonium(EJ=2.0, EC=0.5, EL=0.8, flux=0.0)
# Sweep external flux
flux_vals = np.linspace(0, 1, 101)
param_sweep = scq.ParameterSweep(
hilbert_space=scq.HilbertSpace([fluxonium]),
paramvals_by_name={'flux': flux_vals},
evals_count=8
)
param_sweep.run()
param_sweep.plot_evals_vs_paramvals()Install with Tessl CLI
npx tessl i tessl/pypi-scqubits