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

Custom Serialization in Python Target #2375

Merged
merged 26 commits into from
Jul 31, 2024
Merged

Custom Serialization in Python Target #2375

merged 26 commits into from
Jul 31, 2024

Conversation

Depetrol
Copy link
Collaborator

This PR enables a new feature for using arbitrary python package names that follows a specific API as the connection serializer in Python target federated execution.

Syntax:

<source_port_reference> -> <destination_port_reference> after <time_value> serializer "<serializer_name>"

This feature is backwards compatible. If <serializer_name> is any of [NATIVE, ROS2, PROTO], it will use these serialization methods instead of finding a python package.

The custom Python package would have to export a Serializer class that has the following API:

class Serializer():
    def serialize(self, obj)->bytes:
        return <bytes_object>
    def deserialize(self, message:bytes):
        return <deserialized_object>

The Serializer class will be initialized at the first send and first receive on both ends of the connection. It is persisted in each networksender and networkreceiver as a state variable. Python objects are serialized with serialize(), sent over the socket and deserialized with deserialize().

This feature allows for user-defined custom serialization for any strategy. For example, the user could define a serialization method that enables fast inter-process communication with shared memory. Potentially ROS2 and PROTO serialization could be implemented with custom python packages too. It also supports different serialization methods for different connections.

@Depetrol Depetrol added enhancement Enhancement of existing feature python Related to the Python target labels Jul 19, 2024
@Depetrol Depetrol requested review from edwardalee and lhstrh July 19, 2024 19:30
@Depetrol Depetrol self-assigned this Jul 19, 2024
@Depetrol
Copy link
Collaborator Author

CI is failing because of #2376

Copy link
Collaborator

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

This looks like a great start! I've made some suggestions, however.

cmnrd
cmnrd previously requested changes Jul 23, 2024
.github/workflows/py-tests.yml Outdated Show resolved Hide resolved
@lhstrh lhstrh requested a review from cmnrd July 29, 2024 09:14
@Depetrol Depetrol requested a review from lhstrh July 29, 2024 18:23
@cmnrd
Copy link
Collaborator

cmnrd commented Jul 29, 2024

I still cannot say that I like installing something into the user's system as a side effect of the preamble in a test file. I also think that requiring the serializer to be a standalone Python package that is installed separately is not a practical design from a usability perspective. However, I have made those points before and will not continue arguing for them. I cannot give this my approval, but if someone else does, I will not block it.

@cmnrd cmnrd dismissed their stale review July 29, 2024 18:58

Dismissing my own review.

@Depetrol
Copy link
Collaborator Author

I agree that installing something into the user's system as a side effect of the preamble in a test file is not a perfect solution, but it doesn't require developers to install it manually in order to run the test, and makes the test self-contained.

However I would argue that installing a standalone Python package is more user friendly compared with using relative imports. There are several reasons:

  • There are not many ways to implement a serializer, and most likely the user will use a written custom serializer provided by others(most likely perhaps by us). In this case, installing it as a custom python package is the easiest way for the package to be distributed.
  • For a generic serializer, it will likely be used multiple times in multiple locations. It would be a hassle for the users to import it every time that it is used.
  • If the serializer has to be imported every time that it is used, it would be almost equivalent to provide a "transparent" serializer that assumes the object being sent over the connection is a bytes object, and send the bytes object as-is. The user could do their serialization before passing the object to the "transparent" serializer. For example, out_port.set(custom_serialize_func(<object>)).
  • If the user references the serializer using relative import without installing it in the system environment, this will break because the generated code is in a different location as the .lf code where it is written. The user would also have to specify a files parameter every time the serializer is used to copy the serializer into the generated directory.

Copy link
Collaborator

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

Maybe you haven't pushed the changes that resolve the issues?

@lhstrh lhstrh requested a review from edwardalee July 29, 2024 20:53
@lhstrh
Copy link
Member

lhstrh commented Jul 29, 2024

@edwardalee sorry I re-requested a review but I hadn't noticed that you just provided feedback already

Copy link
Collaborator

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

This looks good to me. It depends on this PR

@lhstrh lhstrh added this pull request to the merge queue Jul 31, 2024
Merged via the queue into master with commit a088c1a Jul 31, 2024
26 checks passed
@lhstrh lhstrh deleted the custom-serializer branch July 31, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of existing feature python Related to the Python target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants