artofscience / SAOR

Sequential Approximate Optimization Repository
GNU General Public License v3.0
5 stars 1 forks source link

Simplify convergence criteria. #26

Closed MaxvdKolk closed 3 years ago

MaxvdKolk commented 3 years ago

Just for fun played around with the convergence criteria a little (see #23). Not sure if this is the way we want to go, but I tried to simplify the interface a little bit.

By implementing the __bool__ functionality, we can perform checks as follows, but not sure if this might conflict with if ... checks for checking with respect to None. It might be nicer to just provide a property or a function call, as done in the current code.

converged = MaxIter(10)
while not converged:
    ... 

Also added the __and__ and __or__ that return either a And or Or variant, to combine different criteria

converged = MaxIter(10) & ObjectiveChange(1e-3)  # requires both to return true 
converged = MaxIter(10) | ObjectiveChange(1e-3)  # requires either to return true 

Not sure if this is nice, or just gimmicky. This can then also be chained, although haven't tried that in-depth,

converged = a & b & c | d & e | f

Although this isn't the most readable way to express such a big relation of criteria 😅


Interested to hear your thoughts

Giannis1993 commented 3 years ago

I am closing this cuz I wanted to clean up the repo. I'll open a new issue to discuss on that.