Coverage for jaxquantum / utils / units.py: 32%
37 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-03 20:38 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-03 20:38 +0000
1""" Units handling."""
4import scipy.constants as constants
5import jax.numpy as np
7# Common Units
8# ================================================================================================
10FLUX_QUANTUM = constants.h / (2 * constants.e)
13def GHz_to_joule(ghz):
14 return ghz * 1e9 * constants.h
17def joule_to_GHz(joule):
18 return joule / (1e9 * constants.h)
20def n_thermal(frequency: float, temperature: float) -> float:
21 """Calculate the average thermal photon number for a given frequency and temperature.
23 Args:
24 frequency (float): Frequency in GHz.
25 temperature (float): Temperature in Kelvin.
27 Returns:
28 float: Average thermal photon number.
29 """
30 k_B = constants.k # Boltzmann constant in J/K
31 h = constants.h # Planck constant in J·s
33 exponent = h * (frequency * 1e9) / (k_B * temperature)
34 n_avg = 1 / (np.exp(exponent) - 1)
35 return n_avg
38# Superconducting Qubit Unit Conversions
39# ================================================================================================
41FLUX_QUANTUM = constants.h / (2 * constants.e)
44def inductive_energy_to_inductance(El):
45 """Convert inductive energy E_L to inductance.
47 Args:
48 El (float): inductive energy in GHz.
50 Returns:
51 float: Inductance in nH.
52 """
54 inv_L = GHz_to_joule(El) * (2 * np.pi) ** 2 / (FLUX_QUANTUM**2)
55 return 1e9 / inv_L
57def inductance_to_inductive_energy(L):
58 """Convert inductance to inductive energy E_L.
60 Args:
61 L (float): Inductance in nH.
63 Returns:
64 float: Inductive energy in GHz.
65 """
67 inv_L = 1e9 / L
68 El_joules = inv_L * (FLUX_QUANTUM**2) / (2 * np.pi) ** 2
69 return joule_to_GHz(El_joules)
72def inv_pF_to_Ec(inv_pfarad):
73 """
74 1/picoFarad -> GHz
75 """
76 inv_nFarad = inv_pfarad * 1e3
77 Gjoule = (constants.e) ** 2 / (2) * inv_nFarad
78 return joule_to_GHz(Gjoule * 1e9)
81def Ec_to_inv_pF(Ec):
82 """
83 GHz -> 1/picoFarad
84 """
85 joule = GHz_to_joule(Ec)
86 Gjoule = joule / 1e9
87 inv_nFarad = Gjoule / ((constants.e) ** 2 / (2))
88 return inv_nFarad * 1e-3
91def calculate_resonator_zpf(freq, impedance):
92 expected_Z0 = impedance # Ohms
93 expected_E_L_over_E_C = (1 / (4 * expected_Z0)) ** 2 * (
94 constants.h**2 / (8 * constants.e**4)
95 )
96 desired_E_C = np.sqrt(freq**2 / expected_E_L_over_E_C / 8)
97 desired_E_L = freq**2 / desired_E_C / 8
98 storage_q_zpf = (1 / 32 * desired_E_L / desired_E_C) ** (1 / 4)
101 # print((desired_E_L / desired_E_C), expected_E_L_over_E_C)
103 return storage_q_zpf, desired_E_C, desired_E_L