BUG: make Presets.status more tolerant of unknown/uninitialized positions#1319
BUG: make Presets.status more tolerant of unknown/uninitialized positions#1319tangkong merged 3 commits intopcdshub:masterfrom
Conversation
pcdsdevices/interface.py
Outdated
| wm_state = getattr(device, method_name) | ||
| diff = abs(wm_state()) | ||
| state_val = wm_state() | ||
| if not isinstance(state_val, (int, float)): |
There was a problem hiding this comment.
We don't ever get numpy floats in these, right?
There was a problem hiding this comment.
Unsure, but it's probably prudent to future-proof ourselves. I thought about this for half a second then forgot about it. numbers.Number should work.
In [5]: for n in [1, 1.2, np.int32(3.3), np.float64(3.2)]:
...: print(isinstance(n, numbers.Number))
...:
True
True
True
True| pos = preset_pos - curr_pos | ||
| except Exception: | ||
| # current position is not known or unset | ||
| pos = "Unknown" |
There was a problem hiding this comment.
This approach is definitely better than the status quo, but I have to wonder if a cleaner approach would have been to make a custom error message.
It's not clear to me.
At any rate, these are intended more for interactive behavior at beamlines, so eschewing an exception for a str output will often be appreciated.
There was a problem hiding this comment.
That was my reasoning here as well. Thinking about the actual issue that spawned this bug report (overloaded callback queue delaying position update), an uninitialized position could be caused by a multitude of causes. I think it might be hard to provide anything more useful than the "position is unknown" in an error message
e4f0113 to
817f569
Compare
Description
Makes Preset
Preset.device.wm_*andPresets.statemethods more tolerant of missing or uninitialized device positions.This changes the signature of the
wm_*methods slightly to also return "Unknown" if the position cannot be resolved.Motivation and Context
closes #1236
As these are autogenerated methods, it's a little harder to confirm that this return type change won't break downstream consumers. At least within
pcdsdevices, the only method that calls adevice.wm_*method isPresets.state. It's possible that some script very strictly requires the output of a preset to be a numeric, but if the position was uninitialized, those scripts would throw exceptions anyway (no return would be reached)How Has This Been Tested?
Checking that CI passes.
By manually setting
device.postitiontoNoneand seeing the output not explodeWhere Has This Been Documented?
This PR
Pre-merge checklist