Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-8716

Use visitor pattern to clean up afw::table pybind11 wrappers

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Done
    • Resolution: Done
    • Fix Version/s: None
    • Component/s: afw
    • Story Points:
      6
    • Sprint:
      DRP S17-3, DRP S17-4
    • Team:
      Data Release Production

      Description

      The way BaseRecord is wrapped in pybind11 needs some work:

      • get and __getitem__ should be wrapped the way they were with SWIG, which is simpler code than was used, and looks identical for the two methods (though that code uses $action so there are subtle differences). Better yet, make the methods identical if possible.
      • The wrappings should probably use C++ method _get, which needs to be added in the pybind11 wrapper file, rather than the specializations that use suffixes.
      • The C++ wrapper defines _getitem_ for each data type and the code is radically different than for _get_ + suffix. It would be nice if the differences could be eliminated.

      Similar issues apply to several other afw::table classes.

        Attachments

          Issue Links

            Activity

            No builds found.
            rowen Russell Owen created issue -
            rowen Russell Owen made changes -
            Field Original Value New Value
            Link This issue relates to DM-8674 [ DM-8674 ]
            rowen Russell Owen made changes -
            Description The way {{BaseRecord}} is wrapped in pybind11 needs some work:
            - {{get}} and {{\_\_getitem\_\_}} should be identical (as they were with SWIG) but they are different and neither one can be used in place of the other. One or two tests fail either way. Furthermore the code bears little resemblance to the original SWIG (for good reasons, but I understand Fred knows how to work around this now).
            - The wrappings should probably use C++ method {{_get}}, which needs to be added in the pybind11 wrapper file.
            - The C++ wrapper defines {{_getitem_}} for each data type and the code is radically different than for {{_get_ + suffix}}; I hope it can be eliminated or made the same as {{_get_ + suffix}} and renamed to {{_get}}.
            The way {{BaseRecord}} is wrapped in pybind11 needs some work:
            - {{get}} and {{\_\_getitem\_\_}} should be wrapped identically (as they were with SWIG) or should actually be identical if possible.
            - The wrappings should probably use C++ method {{_get}}, which needs to be added in the pybind11 wrapper file, rather than the specializations that use suffixes.
            - The C++ wrapper defines {{_getitem_}} for each data type and the code is radically different than for {{_get_ + suffix}}; I hope it can be eliminated or made the same as {{_get_ + suffix}} and renamed to {{_get}}.
            rowen Russell Owen made changes -
            Description The way {{BaseRecord}} is wrapped in pybind11 needs some work:
            - {{get}} and {{\_\_getitem\_\_}} should be wrapped identically (as they were with SWIG) or should actually be identical if possible.
            - The wrappings should probably use C++ method {{_get}}, which needs to be added in the pybind11 wrapper file, rather than the specializations that use suffixes.
            - The C++ wrapper defines {{_getitem_}} for each data type and the code is radically different than for {{_get_ + suffix}}; I hope it can be eliminated or made the same as {{_get_ + suffix}} and renamed to {{_get}}.
            The way {{BaseRecord}} is wrapped in pybind11 needs some work:
            - {{get}} and {{\_\_getitem\_\_}} should be wrapped identically (as they were with SWIG) or should actually be identical if possible.
            - The wrappings should probably use C++ method {{_get}}, which needs to be added in the pybind11 wrapper file, rather than the specializations that use suffixes.
            - The C++ wrapper defines {{\_getitem\_}} for each data type and the code is radically different than for {{\_get_ + suffix}}. It would be nice if the differences could be eliminated.
            rowen Russell Owen made changes -
            Description The way {{BaseRecord}} is wrapped in pybind11 needs some work:
            - {{get}} and {{\_\_getitem\_\_}} should be wrapped identically (as they were with SWIG) or should actually be identical if possible.
            - The wrappings should probably use C++ method {{_get}}, which needs to be added in the pybind11 wrapper file, rather than the specializations that use suffixes.
            - The C++ wrapper defines {{\_getitem\_}} for each data type and the code is radically different than for {{\_get_ + suffix}}. It would be nice if the differences could be eliminated.
            The way {{BaseRecord}} is wrapped in pybind11 needs some work:
            - {{get}} and {{\_\_getitem\_\_}} should be wrapped the way they were with SWIG, which is simpler code than was used, and looks identical for the two methods (though that code uses {{$action}} so there are subtle differences). Better yet, make the methods identical if possible.
            - The wrappings should probably use C++ method {{_get}}, which needs to be added in the pybind11 wrapper file, rather than the specializations that use suffixes.
            - The C++ wrapper defines {{\_getitem\_}} for each data type and the code is radically different than for {{\_get_ + suffix}}. It would be nice if the differences could be eliminated.
            fred3m Fred Moolekamp made changes -
            Assignee Fred Moolekamp [ fred3m ]
            Hide
            fred3m Fred Moolekamp added a comment -

            While get and __getitem__ have a similar structure in the SWIG code, the $action command is different.

            __getitem__ calls the C++ operator[] method and returns a reference, while getX returns a value, and specifies the type that it expects. For convenience (and to make the code more pythonic) get was implemented in SWIG so that the user doesn't need to specify the type. However, there are numerous tests and places in the code that use getX methods, so when I wrapped afw::table I had to keep that design. This causes the python code to look slightly different since pybind11 doesn't have a $action command.

            So completing this ticket would require changing the API for afw::table, which is probably not a good idea until after the pybind11 port is successful.

            Show
            fred3m Fred Moolekamp added a comment - While get and __getitem__ have a similar structure in the SWIG code, the $action command is different. __getitem__ calls the C++ operator[] method and returns a reference, while getX returns a value, and specifies the type that it expects. For convenience (and to make the code more pythonic) get was implemented in SWIG so that the user doesn't need to specify the type. However, there are numerous tests and places in the code that use getX methods, so when I wrapped afw::table I had to keep that design. This causes the python code to look slightly different since pybind11 doesn't have a $action command. So completing this ticket would require changing the API for afw::table, which is probably not a good idea until after the pybind11 port is successful.
            jbosch Jim Bosch made changes -
            Assignee Jim Bosch [ jbosch ]
            swinbank John Swinbank made changes -
            Epic Link DM-7717 [ 26925 ]
            swinbank John Swinbank made changes -
            Epic Link DM-7717 [ 26925 ]
            swinbank John Swinbank made changes -
            Epic Link DM-7717 [ 26925 ]
            swinbank John Swinbank made changes -
            Team Data Release Production [ 10301 ]
            Hide
            jbosch Jim Bosch added a comment -

            In progress, but the remainder of the work has been deferred until we can run more integration-level tests on the pybind11 stack.

            Show
            jbosch Jim Bosch added a comment - In progress, but the remainder of the work has been deferred until we can run more integration-level tests on the pybind11 stack.
            jbosch Jim Bosch made changes -
            Status To Do [ 10001 ] In Progress [ 3 ]
            jbosch Jim Bosch made changes -
            Summary BaseRecord wrapping of set and get needs work Use visitor pattern to clean up afw::table pybind11 wrappers
            jbosch Jim Bosch made changes -
            Description The way {{BaseRecord}} is wrapped in pybind11 needs some work:
            - {{get}} and {{\_\_getitem\_\_}} should be wrapped the way they were with SWIG, which is simpler code than was used, and looks identical for the two methods (though that code uses {{$action}} so there are subtle differences). Better yet, make the methods identical if possible.
            - The wrappings should probably use C++ method {{_get}}, which needs to be added in the pybind11 wrapper file, rather than the specializations that use suffixes.
            - The C++ wrapper defines {{\_getitem\_}} for each data type and the code is radically different than for {{\_get_ + suffix}}. It would be nice if the differences could be eliminated.
            The way {{BaseRecord}} is wrapped in pybind11 needs some work:
            - {{get}} and {{\_\_getitem\_\_}} should be wrapped the way they were with SWIG, which is simpler code than was used, and looks identical for the two methods (though that code uses {{$action}} so there are subtle differences). Better yet, make the methods identical if possible.
            - The wrappings should probably use C++ method {{_get}}, which needs to be added in the pybind11 wrapper file, rather than the specializations that use suffixes.
            - The C++ wrapper defines {{\_getitem\_}} for each data type and the code is radically different than for {{\_get_ + suffix}}. It would be nice if the differences could be eliminated.

            Similar issues apply to several other afw::table classes.
            Hide
            krzys Krzysztof Findeisen added a comment - - edited

            pipe_tasks uses explicit calls to getL, getI, getD, and getFlag. The resolution of this issue may affect the validity (or lack thereof) of such calls.

            Show
            krzys Krzysztof Findeisen added a comment - - edited pipe_tasks uses explicit calls to getL , getI , getD , and getFlag . The resolution of this issue may affect the validity (or lack thereof) of such calls.
            jbosch Jim Bosch made changes -
            Link This issue blocks DM-9100 [ DM-9100 ]
            jbosch Jim Bosch made changes -
            Link This issue is blocked by DM-9099 [ DM-9099 ]
            jbosch Jim Bosch made changes -
            Link This issue is blocked by DM-8805 [ DM-8805 ]
            swinbank John Swinbank made changes -
            Sprint DRP S17-3 [ 360 ]
            swinbank John Swinbank made changes -
            Story Points 6
            Hide
            rowen Russell Owen added a comment -

            Please also change PeakCatalog to be a SortedCatalog (since it has an ID field) or perhaps explain in the .h file why you chose not to do so.

            Show
            rowen Russell Owen added a comment - Please also change PeakCatalog to be a SortedCatalog (since it has an ID field) or perhaps explain in the .h file why you chose not to do so.
            tjenness Tim Jenness made changes -
            Component/s afw [ 10714 ]
            swinbank John Swinbank made changes -
            Sprint DRP S17-3 [ 360 ] DRP S17-3, DRP S17-4 [ 360, 363 ]
            swinbank John Swinbank made changes -
            Rank Ranked higher
            jbosch Jim Bosch made changes -
            Link This issue relates to DM-9018 [ DM-9018 ]
            Hide
            jbosch Jim Bosch added a comment -

            Finally ready for review. Since it's a weekend, I'm not expecting anyone to have time to look at it before we merge on Monday, but if you'd like to take a look, go ahead! I imagine on Monday morning we'll probably merge tickets like this first and then do a post-merge cleanup ticket to retroactively address any review comments.

            Show
            jbosch Jim Bosch added a comment - Finally ready for review. Since it's a weekend, I'm not expecting anyone to have time to look at it before we merge on Monday, but if you'd like to take a look, go ahead! I imagine on Monday morning we'll probably merge tickets like this first and then do a post-merge cleanup ticket to retroactively address any review comments.
            jbosch Jim Bosch made changes -
            Reviewers Krzysztof Findeisen, Pim Schellart, Russell Owen [ krzys, pschella, rowen ]
            Status In Progress [ 3 ] In Review [ 10004 ]
            Hide
            rowen Russell Owen added a comment -

            I'm done with my review (since there are two other reviewers I will not mark it reviewed). Overall this looks great to me; a big improvement. I put some comments on github and wish I had more time to understand some of the changes, but don't want to hold up the merge.

            Show
            rowen Russell Owen added a comment - I'm done with my review (since there are two other reviewers I will not mark it reviewed). Overall this looks great to me; a big improvement. I put some comments on github and wish I had more time to understand some of the changes, but don't want to hold up the merge.
            Hide
            krzys Krzysztof Findeisen added a comment -

            I'm done with my review. I found some style issues and a few things I couldn't understand, but I agree that we shouldn't hold up the merge.

            Show
            krzys Krzysztof Findeisen added a comment - I'm done with my review. I found some style issues and a few things I couldn't understand, but I agree that we shouldn't hold up the merge.
            krzys Krzysztof Findeisen made changes -
            Reviewers Krzysztof Findeisen, Pim Schellart, Russell Owen [ krzys, pschella, rowen ] Pim Schellart, Russell Owen [ pschella, rowen ]
            Hide
            pschella Pim Schellart [X] (Inactive) added a comment -

            Looks fine.

            Show
            pschella Pim Schellart [X] (Inactive) added a comment - Looks fine.
            pschella Pim Schellart [X] (Inactive) made changes -
            Status In Review [ 10004 ] Reviewed [ 10101 ]
            Hide
            jbosch Jim Bosch added a comment -

            Merged to tickets/DM-8467.

            Show
            jbosch Jim Bosch added a comment - Merged to tickets/ DM-8467 .
            jbosch Jim Bosch made changes -
            Resolution Done [ 10000 ]
            Status Reviewed [ 10101 ] Done [ 10002 ]
            jbosch Jim Bosch made changes -
            Link This issue relates to DM-6782 [ DM-6782 ]

              People

              Assignee:
              jbosch Jim Bosch
              Reporter:
              rowen Russell Owen
              Reviewers:
              Pim Schellart [X] (Inactive), Russell Owen
              Watchers:
              Fred Moolekamp, Jim Bosch, Krzysztof Findeisen, Pim Schellart [X] (Inactive), Russell Owen
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Jenkins

                  No builds found.