Fix unknown scheduler error handling in calculate_sigmas function #6280
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
calculate_sigmas
currently doesn't handle unknown scheduler names correctly. The variablesigmas
never gets bound in the error case, so it will fail with a rather unintuitiveNameError: name 'sigmas' is not defined
.This pull modernizes
calculate_sigmas
and scheduler lookup to use a dictionary for the scheduler list and adds type annotations. Of course it also fixes the original issue by raisingValueError
after the log message. Changes tested to be compatible with Python 3.8.Taking this approach also has the advantage of not having to repeat/keep the list of scheduler names in sync (since it can just be generated from the list keys) and reduces duplicated code. Also, custom nodes can easily add themselves to the scheduler list without having to do stuff like monkeypatch
calculate_sigmas
.It could be changed to just use a simple tuple if desired, but
NamedTuple
is a lot more readable.I've been using this myself for a while without any issues but more testing would definitely be good. (I don't see an obvious way it would cause a problem though.)