Coverage for jaxquantum/devices/superconducting/resonator.py: 97%

32 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-27 22:28 +0000

1"""Resonator.""" 

2 

3from flax import struct 

4from jax import config 

5 

6import jax.numpy as jnp 

7 

8from jaxquantum.core.operators import identity, destroy, create 

9from jaxquantum.devices.superconducting.flux_base import FluxDevice 

10 

11config.update("jax_enable_x64", True) 

12 

13 

14@struct.dataclass 

15class Resonator(FluxDevice): 

16 """ 

17 Resonator Device. 

18 """ 

19 

20 def common_ops(self): 

21 """Written in the linear basis.""" 

22 ops = {} 

23 

24 N = self.N_pre_diag 

25 ops["id"] = identity(N) 

26 ops["a"] = destroy(N) 

27 ops["a_dag"] = create(N) 

28 ops["phi"] = self.phi_zpf() * (ops["a"] + ops["a_dag"]) 

29 ops["n"] = 1j * self.n_zpf() * (ops["a_dag"] - ops["a"]) 

30 

31 return ops 

32 

33 def phi_zpf(self): 

34 """Return Phase ZPF.""" 

35 return (2 * self.params["Ec"] / self.params["El"]) ** (0.25) 

36 

37 def n_zpf(self): 

38 n_zpf = (self.params["El"] / (32.0 * self.params["Ec"])) ** (0.25) 

39 return n_zpf 

40 

41 def get_linear_frequency(self): 

42 """Get frequency of linear terms.""" 

43 return jnp.sqrt(8 * self.params["El"] * self.params["Ec"]) 

44 

45 def get_H_linear(self): 

46 """Return linear terms in H.""" 

47 w = self.get_linear_frequency() 

48 ops = self.linear_ops 

49 return w * (ops["a_dag"] @ ops["a"] + 1 / 2) 

50 

51 def get_H_full(self): 

52 """Return full H in linear basis.""" 

53 return self.get_H_linear() 

54 

55 def potential(self, phi): 

56 """Return potential energy for a given phi.""" 

57 return 0.5 * self.params["El"] * (2 * jnp.pi * phi) ** 2