Coverage for jaxquantum / devices / superconducting / ideal_qubit.py: 0%

33 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-12-03 20:38 +0000

1"""IdealQubit.""" 

2 

3from flax import struct 

4from jax import config 

5 

6 

7from jaxquantum.devices.base.base import Device, BasisTypes, HamiltonianTypes 

8from jaxquantum.core.operators import identity, sigmaz, sigmax, sigmay, sigmam, sigmap 

9 

10config.update("jax_enable_x64", True) 

11 

12 

13@struct.dataclass 

14class IdealQubit(Device): 

15 """ 

16 Ideal qubit Device. 

17 """ 

18 

19 @classmethod 

20 def param_validation(cls, N, N_pre_diag, params, hamiltonian, basis): 

21 """This can be overridden by subclasses.""" 

22 assert basis == BasisTypes.fock, ( 

23 "IdealQubit is a two-level system defined in the Fock basis." 

24 ) 

25 assert hamiltonian == HamiltonianTypes.full, ( 

26 "IdealQubit requires a full Hamiltonian." 

27 ) 

28 assert N == N_pre_diag == 2, "IdealQubit is a two-level system." 

29 assert "f" in params, "IdealQubit requires a frequency parameter 'f'." 

30 

31 params["Δ"] = params.get("Δ", 0.0) 

32 

33 def common_ops(self): 

34 """Written in the linear basis.""" 

35 ops = {} 

36 

37 assert self.N_pre_diag == 2 

38 assert self.N == 2 

39 

40 N = self.N_pre_diag 

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

42 ops["sigmaz"] = sigmaz() 

43 ops["sigmax"] = sigmax() 

44 ops["sigmay"] = sigmay() 

45 ops["sigmam"] = sigmam() 

46 ops["sigmap"] = sigmap() 

47 

48 return ops 

49 

50 def get_linear_frequency(self): 

51 """Get frequency of linear terms.""" 

52 return self.params["f"] 

53 

54 def get_H_linear(self): 

55 """Return linear terms in H.""" 

56 w = self.get_linear_frequency() 

57 return (w / 2) * self.linear_ops["sigmaz"] 

58 

59 def get_H_full(self): 

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

61 

62 return self.get_H_linear() + self.params["Δ"] / 2 * self.linear_ops["sigmax"]