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

Feature/add missing fields in plain scxml #63

Merged
merged 14 commits into from
Oct 30, 2024

Conversation

MarcoLm993
Copy link
Collaborator

This addresses the requests from @EnricoGhiorzi in #59

It will be turned into an actual PR once the BT SCXML one (#58) will be merged.
Before that happens, we can use it to better align on SCAN's actual requirements

"w",
encoding="utf-8",
) as f:
f.write(scxml_model.as_xml_string(data_type_as_argument=False))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This makes sure that the data types are stored using the comment structure.

Choose a reason for hiding this comment

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

That's great, thanks!

else_body = add_targets_to_scxml_send(entry.get_else_execution(), events_to_automata)
new_body.append(ScxmlIf(if_conditionals, else_body))
elif isinstance(entry, ScxmlSend):
target_automata = events_to_automata.get(entry.get_event(), {"NONE"})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@EnricoGhiorzi on this one I am not entirely sure: there are cases in which we send an event, but we define no transition for it.
This might be desired in case the developer wants to expose a specific information from a single automaton only for referring to it in a property.
For now, I decided to add a "NONE" target for such cases, but we can find other alternatives

Choose a reason for hiding this comment

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

I see the use for such a feature, but I worry about aligning the model with the implementation. Would this be how the real system implements such a feature? In other words, is it possible to monitor a topic that has a publisher but no subscribers? (I guess the monitor itself is a subscriber, but that is not modelled.)

Reguarding the "NONE" syntax, I looked up the SCXML specification but is provided no insight: there is no way to send an event into the void, and having a non-existing target would raise an error.

Another option could be to automatically create such a "NONE" automaton and just let it process any event it receives.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To monitor a topic, you need to subscribe to it, and as you mentioned above, the monitor will do exactly that.
If you are fine with it, you can assume to have the NONE automaton that acts as a receiver for all events (though I am not sure it makes sense to auto-generate it: maybe it is easier to have a script removing the send events with a NONE target)

Choose a reason for hiding this comment

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

maybe it is easier to have a script removing the send events with a NONE target

I don't get it: if we remove these sends, the events will not be observable in SCAN either. I think we either need to send the events into the void (as it is now) and allow that in SCAN, or to generate a target NONE automaton, either at AS2FM or SCAN level, possibly consistently with the actual implementation. @SofiaFaraci might have some insight on this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My comment about (optionally) removing the NONE events was only for executing system outside of SCAN. Otherwise, I would be happy to keep it as is and allow the NONE target in SCAN, if that works for you.

Choose a reason for hiding this comment

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

I think we either need to send the events into the void (as it is now) and allow that in SCAN, or to generate a target NONE automaton, either at AS2FM or SCAN level, possibly consistently with the actual implementation. @SofiaFaraci might have some insight on this.

In the actual implementation there is no need for a target for the send tag, the events are directly handled by the generated C++ code of the SMs that sends the event.

Copy link

@EnricoGhiorzi EnricoGhiorzi left a comment

Choose a reason for hiding this comment

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

Thank you for this PR, it addresses so many of the issues we have with the format! There are a couple of points that I commented on but the code looks generally good.

I run the code on @SofiaFaraci's model and it works, minus adding the simplest NONE.scxml automaton to receive the messages sent to it. I think that's the main issue to address, either on AS2FM side or on SCAN side.

This PR also addresses the same topic as the branch feature/get-closer-to-standard-scxml, maybe we could add those commits to this PR too?

"w",
encoding="utf-8",
) as f:
f.write(scxml_model.as_xml_string(data_type_as_argument=False))

Choose a reason for hiding this comment

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

That's great, thanks!

src/as2fm/scxml_converter/scxml_entries/scxml_data.py Outdated Show resolved Hide resolved
else_body = add_targets_to_scxml_send(entry.get_else_execution(), events_to_automata)
new_body.append(ScxmlIf(if_conditionals, else_body))
elif isinstance(entry, ScxmlSend):
target_automata = events_to_automata.get(entry.get_event(), {"NONE"})

Choose a reason for hiding this comment

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

I see the use for such a feature, but I worry about aligning the model with the implementation. Would this be how the real system implements such a feature? In other words, is it possible to monitor a topic that has a publisher but no subscribers? (I guess the monitor itself is a subscriber, but that is not modelled.)

Reguarding the "NONE" syntax, I looked up the SCXML specification but is provided no insight: there is no way to send an event into the void, and having a non-existing target would raise an error.

Another option could be to automatically create such a "NONE" automaton and just let it process any event it receives.

@MarcoLm993
Copy link
Collaborator Author

Thank you for this PR, it addresses so many of the issues we have with the format! There are a couple of points that I commented on but the code looks generally good.

I run the code on @SofiaFaraci's model and it works, minus adding the simplest NONE.scxml automaton to receive the messages sent to it. I think that's the main issue to address, either on AS2FM side or on SCAN side.

This PR also addresses the same topic as the branch feature/get-closer-to-standard-scxml, maybe we could add those commits to this PR too?

The only change from that branch is this: 27ab9c2

I will have a look at renaming the event fields and to allow _event.origin in the transition (though we are not planning to really make use of that feature for now: are you?)

@EnricoGhiorzi
Copy link

I will have a look at renaming the event fields and to allow _event.origin in the transition (though we are not planning to really make use of that feature for now: are you?)

Internally SCAN already supports _event.origin but there is no need to add that to AS2FM if it is not necessary (that is, if use-case developers don't need it). It could also potentially be a can of worms, so I would advise caution (for example, it makes it difficult to figure out at compile time which automata can potentially receive a certain event).

Copy link

@EnricoGhiorzi EnricoGhiorzi left a comment

Choose a reason for hiding this comment

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

Looks all good!

@MarcoLm993
Copy link
Collaborator Author

I just fixed the remaining conversion problems and updated the test files. It should be good to go!

@MarcoLm993
Copy link
Collaborator Author

MarcoLm993 commented Oct 25, 2024

After some discussion with Enrico, it seems there is a problem with verifying n-to-n communication entries (that is the standard with topics) and we opted for exporting, for plain scxml, an additional state machine that gets all the published messages and sends them to all subscribers.
This is not expected to affect the conversion to Jani, since there we do not distinguish between difference sources of a message
I had a second thought on it, and maybe it makes sense to model this as a separated state machine for Jani as well, since that way we could model the message queuing in a better and more explicit way. I will make an issue for this, and it will be discussed and addressed in another PR.

@MarcoLm993 MarcoLm993 force-pushed the feature/add-missing-fields-in-plain-scxml branch from 15ab218 to b1bc59a Compare October 25, 2024 11:44
Base automatically changed from feature/scxml-for-bt-control-nodes to main October 25, 2024 12:19
Signed-off-by: Marco Lampacrescia <[email protected]>
Signed-off-by: Marco Lampacrescia <[email protected]>
Signed-off-by: Marco Lampacrescia <[email protected]>
Signed-off-by: Marco Lampacrescia <[email protected]>
@MarcoLm993 MarcoLm993 force-pushed the feature/add-missing-fields-in-plain-scxml branch from b1bc59a to eae7ad6 Compare October 25, 2024 12:23
@MarcoLm993 MarcoLm993 marked this pull request as ready for review October 25, 2024 12:25
elem.attrib.clear()
for k in sorted(elem.keys()):
elem.set(k, elem.get(k))
for k in sorted(elem_attributes.keys()):
Copy link
Member

Choose a reason for hiding this comment

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

💓

@MarcoLm993 MarcoLm993 merged commit b5699a6 into main Oct 30, 2024
4 checks passed
@MarcoLm993 MarcoLm993 deleted the feature/add-missing-fields-in-plain-scxml branch October 30, 2024 14:10
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.

4 participants