Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: make PVStateSignal report enum_strs and write_access metadata #1046

Merged
merged 5 commits into from
Oct 21, 2022

Conversation

ZLLentz
Copy link
Member

@ZLLentz ZLLentz commented Aug 18, 2022

Description

PVStateSignal has been given enum_strs and write_access metadata that behaves similarly to how the EpicsSignal metadata does.

On the first value calculation, which occurs only after the device is fully ready to go, we check the parent states device for its static state enum to use to collect the enum strings and for a setpoint reference that we can subscribe to for write access metadata updates, forwarding these in the PVStateSignal as appropriate.

Motivation and Context

We noticed in the lightpath that any devices with PVStateSignal behaved inappropriately at the pcdsdevices level, creating what naively looks like ui bugs in lightpath, while actually being sourced to here.

This signal type is used in the legacy stoppers, gate valves, pulse pickers, and movable stands.

How Has This Been Tested?

Interactively by loading happi devices and via checking the lightpath.
Unit test added.

Where Has This Been Documented?

I need to make the pre-release docs.

Pre-merge checklist

  • Code works interactively
  • Code contains descriptive docstrings, including context and API
  • New/changed functions and methods are covered in the test suite where possible
  • Test suite passes locally
  • Test suite passes on travis
  • Ran docs/pre-release-notes.sh and created a pre-release documentation page
  • Pre-release docs include context, functional descriptions, and contributors as appropriate

@ZLLentz ZLLentz marked this pull request as ready for review August 18, 2022 22:27
that everything is ready. Doing it earlier can run into some
race conditions.
"""
# Do some one-time setup here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure if this was the right place to do this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one-time setup in the first callback seems appropriate and efficient to me.

The only thing worth noting is that _calc_readback happens inside of an acquired RLock . I see nothing in the block that points to a potential deadlock condition though: running subscriptions happens in a separate thread and shouldn't block.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is in an RLock though I might take a moment to see if I can set it up earlier in the chain, both to avoid potential mishaps and to not set a bad example for future people

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't quickly find a better way, I'm going to move on

Copy link
Contributor

@klauer klauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me 👍

ref_str = self.parent._state_logic_set_ref
if isinstance(ref_str, str):
setpoint_sig = getattr(self.parent, ref_str)
setpoint_sig.subscribe(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should stash the subscription identifier and unsubscribe on destroy()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make sure to do this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZLLentz
Copy link
Member Author

ZLLentz commented Aug 19, 2022

Marking as draft again so I don't accidentally hit the green button before resolving the cleanup

@ZLLentz ZLLentz marked this pull request as draft August 19, 2022 20:18

_state_logic_set_ref : str or None
An optional reference to the component that will be used to set some
metadata on the state signal if provided.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is something that will have to be set on any future PVStatePositioner devices if we want the metadata to carry forward correctly. Is there somewhere we can broadcast that information? I don't see natural place in the docs for it yet.

I also can't imagine there's a good way to dynamically guess at the component name without the creator's help. Throwing an error in its absence might be a bit heavy handed, since it's only a gui-related issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually intentionally omitted it in the MovableStand class since the state there isn't settable

raise NotImplementedError('Stand not motorized')

One thing I was considering was switching this to a required attribute, defaults to None, needs to become a list. So then we know that you didn't include it if it's still at None, we know that you meant "this is never settable" if it's an empty list, and if there are multiple set PVs we can summarize their write state together. Maybe it's worth doing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And of course, then we could raise an exception during init if it's left at None

Copy link
Contributor

@tangkong tangkong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also looks good to me. Works well in practice (solving my lightpath issues).

@ZLLentz
Copy link
Member Author

ZLLentz commented Oct 21, 2022

This actually isn't strictly needed for lightpath any more after the full sum of changes leading up to v1.0.0, but I'll still try to get this done for completeness's sake as it could be useful for something else in the future.

@ZLLentz ZLLentz marked this pull request as ready for review October 21, 2022 17:58
@ZLLentz
Copy link
Member Author

ZLLentz commented Oct 21, 2022

It's been a while so I want to at least force the CI to re-run, so I'm going close and re-open the PR

@ZLLentz ZLLentz closed this Oct 21, 2022
@ZLLentz ZLLentz reopened this Oct 21, 2022
@ZLLentz
Copy link
Member Author

ZLLentz commented Oct 21, 2022

old pr, new tests, still passing, gonna merge

@ZLLentz ZLLentz merged commit 3bd3b5c into pcdshub:master Oct 21, 2022
@ZLLentz ZLLentz deleted the enh_pvstatesignal_md branch October 21, 2022 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants