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

Fix for standalone msg variables inside agent python #1111

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions swig/python/codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def __init__(self, tree, file = sys.stdout):
self._message_iterator_var = None # default
self._input_message_var = 'message_in' # default
self._output_message_var = 'message_out' # default
self._standalone_message_var = [] # default
self.dispatch(tree)
print("", file=self.f)
self.f.flush()
Expand Down Expand Up @@ -506,7 +507,20 @@ def dispatchMemberFunction(self, t, t_parent):
# proceed
self.write(py_func)


# standalone message input variable arg
elif t.value.id in self._standalone_message_var:
# check for legit FGPU function calls and translate
self.write(f"{t.value.id}.")
if t.attr in self.fgpu_input_msg_funcs:
# proceed
self.write(t.attr)
else:
# possible getter setter type function
py_func = self._deviceVariableFunctionName(t, ["getVariable"])
if not py_func:
self.RaiseError(t, f"Function '{t.attr}' does not exist in '{t.value.id}' message input object")
# proceed
self.write(py_func)

# math functions (try them in raw function call format) or constants
elif t.value.id == "math":
Expand Down Expand Up @@ -607,6 +621,10 @@ def _Assign(self, t):
self.fill()
# check if target exists in locals
if t.targets[0].id not in self._locals :
# Special case, catch message.at() where a message is returned outside a message loop
if hasattr(t.value, "func") and t.value.func.attr == 'at' :
if t.value.func.value.id == self._input_message_var :
self._standalone_message_var.append(t.targets[0].id)
self.write("auto ")
self._locals.append(t.targets[0].id)
self.dispatch(t.targets[0])
Expand Down Expand Up @@ -752,7 +770,7 @@ def _FunctionDef(self, t):
# check for return annotation type
if not isinstance(t.returns, ast.Name):
self.RaiseError(t, "Agent function conditions return type must be 'bool'")
if t.returns.id is not 'bool':
if t.returns.id != 'bool':
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 got a weird warning about this, so thought best to fix. Unrelated to PR.

self.RaiseError(t, "Agent function conditions return type must be 'bool'")
# check to ensure no arguments (discard any with a warning)
if t.args.args:
Expand Down
13 changes: 13 additions & 0 deletions tests/python/codegen/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ async def f():
}
"""

py_fgpu_standalone_msg_input = """\
m = message_in.at(1)
pass
n = m.getVariableInt("foo")
"""
cpp_fgpu_standalone_msg_input = """\
auto m = FLAMEGPU->message_in.at(1);
;
auto n = m.getVariable<int>("foo");
"""

py_fgpu_for_msg_input_args = """\
for m in message_in(x, y, z) :
pass
Expand Down Expand Up @@ -754,6 +765,8 @@ def test_fgpu_for_msg_input(self):
self._checkException(py_fgpu_for_msg_input_func_unknown, "Function 'unsupported' does not exist")
# Test math function inside message loop (Previously bug #1077)
self._checkExpected(py_fgpu_for_msg_input_math_func, cpp_fgpu_for_msg_input_math_func)
# Test standalone input message (Previously bug #1110)
self._checkExpected(py_fgpu_standalone_msg_input, cpp_fgpu_standalone_msg_input)
# Test message input where message input requires arguments (e.g. spatial messaging)
self._checkExpected(py_fgpu_for_msg_input_args, cpp_fgpu_for_msg_input_args)
# Test to ensure that arguments are processed as local variables
Expand Down
2 changes: 1 addition & 1 deletion tests/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def pytest_sessionfinish(session, exitstatus):
# Exit if the terminalreport plugin could not be found
if not terminalreporter:
return
outcome = "Passed" if exitstatus == 0 else "Failed(code={exitstatus})"
outcome = "Passed" if exitstatus == 0 else f"Failed(code={exitstatus})"
passed = len(terminalreporter.stats.get('passed', []))
failed = len(terminalreporter.stats.get('failed', []))
skipped = len(terminalreporter.stats.get('skipped', []))
Expand Down