Skip to content

Create ControllerVector to allow making an array of sub controllers of a given class distinguished by an index #122

Description

@evvaaaa

In #119, we pair controllers together based on the name of the attribute. If the name of two subcontrollers foo_1/foo_2 or Foo1/Foo2 is the same then they're grouped together in the same pvi group under foo.

Problem

This is assuming too much on the FastCS side. We should instead allow controllers to have a ControllerVector called foo which can be indexed by int (not necessarily contiguous). On the transport, these elements are grouped together under foo.

Required Changes

  1. Add a new ControllerVector which can be passed into register_subcontroller.
  2. Update demo to use this for the ramps
  3. Unit tests

Activity

  1. GDYendell commented on Feb 18, 2025

    @GDYendell
    Contributor

    Could you outline how PviTree would change if this is done? It is not clear to me from the description.

  2. evvaaaa commented on Feb 19, 2025

    @evvaaaa
    ContributorAuthor

    Could you outline how PviTree would change.

    We wouldn't be assuming Device:Foo1 and Device:Foo83 should exist as

    foo (structure):
        d (structure):
            v1 Device:Foo1:PVI
            v83 Device:Foo83:PVI
    

    Simply because they both have the same end string up to the number. We would have a SubControllerVector in the Device Controller called Foo with entry 1 and 83, and the above structure would be obtained, or if we just register them as controllers like normal we'd have

    foo1 (structure):
        d Device:Foo1:PVI
    foo83 (structure):
        d Device:Foo83:PVI
    

    Same is true for attributes

    foo (structure):
        rw (structure):
            v1 Device:Foo1
            v83 Device:Foo83
    
  3. GDYendell commented on Feb 20, 2025

    @GDYendell
    Contributor

    @evalott100 re: our very short discussion as I ran out the door. After our session today, I understand your last comment. Would it make sense to rename this issue something like "Add SubControllerVector to allow grouping multiple instances of a SubController".

    Ophyd has a DeviceVector - does it also have a SignalVector? Does PandA have a use case for AttributeVector or just SubControllerVector? I think I might have a use case for it to simplify something in fastcs-odin (parameters from odin with list values that we want to split out into scalar attributes). If you don't need it right now maybe it could be done separately later?

  4. evvaaaa commented on Feb 21, 2025

    @evvaaaa
    ContributorAuthor

    Will close this and write a new issue with these changes (we can discuss if we want to alter these here though).

    1

    "Add SubControllerVector to allow grouping multiple instances of a SubController".

    Sure, I think we should also include the ophyd-async style Controller parsing we were discussing:

    • All Attributes which are on the controller object as python attributes get added to controller._attributes: dict[str, Attribute]
    • All Controllers which are on the controller object as python attributes get added to controller._sub_controllers: dict[str, Controller | ControllerVector]

    2

    I don't really see any need for sub controllers to be their own class SubController? I think we should remove it. A subcontroller is just a controller living in another controller.

    3

    If you don't need it right now maybe it could be done separately later?

    Yep I agree, we should only cover class ControllerVector(dict[int, Controller | ControllerVector]), we could make this a subclass of Controller/BaseController too if it ends up being more convenient, especially if we do decide to get rid of SubController.

    If a transport has no interpretation of ControllerVector then it just uses each of the contained Controller values as normal from get_flattened_sub_controllers:

    class Controller(BaseController):
        def get_sub_controllers(self) -> dict[str, Controller | ControllerVector]:
            return self._controllers
    
        def get_flattened_sub_controllers(self) -> dict[str, Controller]:
            # uses sub_controller.flatten() if sub_controller is a ControllerVector
  5. GDYendell commented on Feb 21, 2025

    @GDYendell
    Contributor

    I think the difference between Controller and SubController is purely philosophical at this point, but there may be some implementation details that we will need to abstract out.

  6. evvaaaa commented on Feb 21, 2025

    @evvaaaa
    ContributorAuthor

    but there may be some implementation details that we will need to abstract out.

    Other than type hinting I can't see too much that relies on SubController, other than

    • SubController.top_level_attribute (being deprecated)
    • If anything downstream is discriminating based on SubController vs Controller (I can't really see why this would ever be necessary when anything other than the controller you pass into FastCS is a SubController.
  7. changed the title [-]Allow for explicit pairing of SubControllers/Attributes[/-] [+]Create ControllerVector to allow making an array of sub controllers of a given class distinguished by an index[/+] on Feb 25, 2025
  8. evvaaaa commented on Mar 7, 2025

    @evvaaaa
    ContributorAuthor

    UPDATE

    We shouldn't group Attributes at all, only SubController. This is incorrect in the current p4p backend.

  9. added
    needs design
    on Apr 25, 2025
  10. removed
    needs design
    on Aug 6, 2025
  11. self-assigned this
    on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions