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 bank_index Parameter Override #2411

Merged
merged 6 commits into from
Sep 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,22 @@ private static String generatePythonClassInstantiation(
CodeBuilder code = new CodeBuilder();
code.pr(PyUtil.reactorRef(instance) + " = _" + className + "(");
code.indent();
// Always add the bank_index
code.pr("_bank_index = " + PyUtil.bankIndex(instance) + ",");
boolean hasBankIndexParameter = false;
for (ParameterInstance param : instance.parameters) {
if (!param.getName().equals("bank_index")) {
code.pr(
"_"
+ param.getName()
+ "="
+ PythonParameterGenerator.generatePythonInitializer(param)
+ ",");
if (param.getName().equals("bank_index")) {
if (param.getOverride() != null) hasBankIndexParameter = true;
else continue; // Skip bank_index if it is not explicitly set
}
code.pr(
"_"
+ param.getName()
+ "="
+ PythonParameterGenerator.generatePythonInitializer(param)
+ ",");
}
if (!hasBankIndexParameter) {
// Only add bank_index if not explicitly set
code.pr("_bank_index = " + PyUtil.bankIndex(instance) + ",");
}
code.unindent();
code.pr(")");
Expand Down
28 changes: 28 additions & 0 deletions test/Python/src/federated/BankIndexFed.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
target Python

reactor FirstReactor(bank_index=0) {
output out

reaction(startup) -> out {=
print("bank_index: {:d}".format(self.bank_index))
out.set(self.bank_index)
=}
}

reactor SecondReactor {
input[4] inp

reaction(inp) {=
for i, port in enumerate(inp):
assert port.is_present
print("in[{:d}]: {:d}".format(i, port.value))
assert port.value == i
request_stop()
=}
}

federated reactor {
a = new[4] FirstReactor()
b = new SecondReactor()
a.out -> b.inp
}
12 changes: 12 additions & 0 deletions test/Python/src/federated/BankIndexOverride.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
target Python

reactor SingleReactor(bank_index=0) {
reaction(startup) {=
print("bank_index: {:d}".format(self.bank_index))
assert(self.bank_index == 2)
=}
}

main reactor {
a = new SingleReactor(bank_index=2)
}
Loading