File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
qiskit_algorithms/optimizers Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,9 @@ class GradientDescentState(OptimizerState):
46
46
# too as it does not appear to use super by default and without this failed
47
47
# the exact same way. Note it does not include learning rate as that field
48
48
# is not included in the compare as pre the field decorator.
49
- def __eq__ (self , other : GradientDescentState ):
49
+ def __eq__ (self , other : object ):
50
+ if not isinstance (other , GradientDescentState ):
51
+ return NotImplemented
50
52
return super ().__eq__ (other ) and self .stepsize == other .stepsize
51
53
52
54
Original file line number Diff line number Diff line change @@ -76,12 +76,18 @@ class OptimizerState:
76
76
# Under Python 3.13 the auto-generated equal fails with a error around
77
77
# using numpy all or any. See https://github.com/qiskit-community/qiskit-algorithms/pull/225
78
78
# for further information. Hence this custom function was added.
79
- def __eq__ (self , other : OptimizerState ):
79
+ def __eq__ (self , other : object ):
80
+ if not isinstance (other , OptimizerState ):
81
+ return NotImplemented
80
82
return (
81
83
(
82
84
self .x == other .x
83
- if isinstance (self .x , float )
84
- else (self .x .shape == other .x .shape and (self .x == other .x ).all ())
85
+ if isinstance (self .x , float ) and isinstance (other .x , float )
86
+ else (
87
+ False
88
+ if isinstance (self .x , float ) or isinstance (other .x , float )
89
+ else self .x .shape == other .x .shape and (self .x == other .x ).all ()
90
+ )
85
91
)
86
92
and self .fun == other .fun
87
93
and self .jac == other .jac
You can’t perform that action at this time.
0 commit comments