File tree 1 file changed +16
-4
lines changed 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 102
102
"Pim" ,
103
103
]
104
104
105
+
106
+ def _ensure_int (x ):
107
+ """
108
+ Ensure that a floating-point value `x` is exactly an integer, and return it
109
+ as an int.
110
+ """
111
+ out = int (x )
112
+ if out != x :
113
+ raise ValueError (f"{ x } is not an integral value" )
114
+ return out
115
+
116
+
105
117
# Functions necessary to generate the Lindbladian/Liouvillian
106
118
def num_dicke_states (N ):
107
119
"""Calculate the number of Dicke states.
@@ -641,8 +653,8 @@ def energy_degeneracy(N, m):
641
653
The energy degeneracy
642
654
"""
643
655
numerator = Decimal (factorial (N ))
644
- d1 = Decimal (factorial (N / 2 + m ))
645
- d2 = Decimal (factorial (N / 2 - m ))
656
+ d1 = Decimal (factorial (_ensure_int ( N / 2 + m ) ))
657
+ d2 = Decimal (factorial (_ensure_int ( N / 2 - m ) ))
646
658
degeneracy = numerator / (d1 * d2 )
647
659
return int (degeneracy )
648
660
@@ -671,8 +683,8 @@ def state_degeneracy(N, j):
671
683
if j < 0 :
672
684
raise ValueError ("j value should be >= 0" )
673
685
numerator = Decimal (factorial (N )) * Decimal (2 * j + 1 )
674
- denominator_1 = Decimal (factorial (N / 2 + j + 1 ))
675
- denominator_2 = Decimal (factorial (N / 2 - j ))
686
+ denominator_1 = Decimal (factorial (_ensure_int ( N / 2 + j + 1 ) ))
687
+ denominator_2 = Decimal (factorial (_ensure_int ( N / 2 - j ) ))
676
688
degeneracy = numerator / (denominator_1 * denominator_2 )
677
689
degeneracy = int (np .round (float (degeneracy )))
678
690
return degeneracy
You can’t perform that action at this time.
0 commit comments