-
Notifications
You must be signed in to change notification settings - Fork 21
Documentation for transient federates. #347
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b68aaae
Start on docs for transient federates
edwardalee d29445e
Apply suggestions from code review
ChadliaJerad e9de82b
Remove TransientExec and update decentralized explanation
edwardalee 3312759
Removed untested statement
edwardalee f2006a5
Treatment of banks.
edwardalee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| target C { | ||
| timeout: 3 s | ||
| } | ||
|
|
||
| preamble {= | ||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| =} | ||
|
|
||
| /** Persistent upstream federate. Sends 0, 1, 2, ... every 500 ms. */ | ||
| reactor Up(period: time = 500 ms) { | ||
| output out: int | ||
| timer t(0, period) | ||
| state count: int = 0 | ||
|
|
||
| reaction(t) -> out {= | ||
| lf_set(out, self->count); | ||
| lf_print("Up sending %d", self->count); | ||
| self->count++; | ||
| =} | ||
| } | ||
|
|
||
| /** | ||
| * Launches a federate executable after `launch_time`. | ||
| * The executable name is `federate__` followed by `fed_instance_name`. | ||
| */ | ||
| reactor TransientExec(launch_time: time = 0, fed_instance_name: char* = "instance") { | ||
| timer t(launch_time) | ||
|
|
||
| reaction(t) {= | ||
| char cmd[576]; | ||
| snprintf(cmd, sizeof(cmd), "%s/bin/federate__%s -i %s", | ||
| LF_FED_PACKAGE_DIRECTORY, | ||
| self->fed_instance_name, | ||
| lf_get_federation_id()); | ||
| lf_print("Launching: %s", cmd); | ||
| if (system(cmd) != 0) { | ||
| lf_print_error_and_exit("Failed to launch federate__%s", self->fed_instance_name); | ||
| } | ||
| =} | ||
| } | ||
|
|
||
| /** | ||
| * Transient federate that forwards inputs from `Up` to `Down`. | ||
| * After two inputs it leaves the federation by calling `lf_stop()`. | ||
| */ | ||
| reactor Middle { | ||
| input in: int | ||
| output out: int | ||
| output join: int | ||
| state count: int = 0 | ||
|
|
||
| reaction(startup) -> join {= | ||
| tag_t t = lf_tag_start_effective(); | ||
| lf_print("Middle joined at effective start tag (" PRINTF_TIME ", %u)", | ||
| t.time - lf_time_start(), t.microstep); | ||
| lf_set(join, 0); | ||
| =} | ||
|
|
||
| reaction(in) -> out {= | ||
| self->count++; | ||
| lf_print("Middle forwarding %d (count %d)", in->value, self->count); | ||
| lf_set(out, in->value); | ||
| if (self->count == 2) { | ||
| lf_stop(); | ||
| } | ||
| =} | ||
| } | ||
|
|
||
| /** Persistent downstream federate. Continues even while Middle is absent. */ | ||
| reactor Down(period: time = 500 ms) { | ||
| timer t(0, period) | ||
| input in: int | ||
| input join: int | ||
|
|
||
| reaction(t) {= | ||
| lf_print("Down timer at (" PRINTF_TIME ", %u)", | ||
| lf_time_logical_elapsed(), lf_tag().microstep); | ||
| =} | ||
|
|
||
| reaction(join) {= | ||
| lf_print("Down observed Middle join"); | ||
| =} | ||
|
|
||
| reaction(in) {= | ||
| lf_print("Down received %d from Middle", in->value); | ||
| =} | ||
| } | ||
|
|
||
| federated reactor { | ||
| midExec = new TransientExec(launch_time = 1 s, fed_instance_name = "mid") | ||
| up = new Up() | ||
| down = new Down() | ||
|
|
||
| @transient | ||
| mid = new Middle() | ||
|
|
||
| up.out -> mid.in | ||
| mid.join -> down.join | ||
| mid.out -> down.in | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| target Python { | ||
| timeout: 3 s | ||
| } | ||
|
|
||
| preamble {= | ||
| import os | ||
| import subprocess | ||
| =} | ||
|
ChadliaJerad marked this conversation as resolved.
|
||
|
|
||
| # Persistent upstream federate. Sends 0, 1, 2, ... every 500 ms. | ||
| reactor Up(period=500 ms) { | ||
| output out | ||
| timer t(0, period) | ||
| state count = 0 | ||
|
|
||
| reaction(t) -> out {= | ||
| out.set(self.count) | ||
| print("Up sending {}".format(self.count)) | ||
| self.count += 1 | ||
| =} | ||
| } | ||
|
|
||
| # Launches a federate executable after `launch_time`. | ||
| # The executable name is `federate__` followed by `fed_instance_name`. | ||
| # `federation_name` must match the .lf file name (without the extension). | ||
| reactor TransientExec( | ||
| launch_time=0, | ||
| federation_name="TransientFederates", | ||
| fed_instance_name="instance") { | ||
| timer t(launch_time) | ||
|
|
||
| reaction(t) {= | ||
| exe = os.path.join( | ||
| lf.package_directory(), "fed-gen", self.federation_name, "bin", | ||
| "federate__" + self.fed_instance_name) | ||
| cmd = [exe, "-i", lf.get_federation_id()] | ||
| print("Launching:", cmd) | ||
| result = subprocess.run(cmd) | ||
| if result.returncode != 0: | ||
| sys.exit("Failed to launch " + self.fed_instance_name) | ||
| =} | ||
| } | ||
|
|
||
| # Transient federate that forwards inputs from `Up` to `Down`. | ||
| # After two inputs it leaves the federation by calling `lf.stop()`. | ||
| reactor Middle { | ||
| input inp | ||
| output out | ||
| output join | ||
| state count = 0 | ||
|
|
||
| reaction(startup) -> join {= | ||
| t = lf.tag_start_effective() | ||
| print("Middle joined at effective start tag ({}, {})".format( | ||
| t.time - lf.time.start(), t.microstep)) | ||
| join.set(0) | ||
| =} | ||
|
|
||
| reaction(inp) -> out {= | ||
| self.count += 1 | ||
| print("Middle forwarding {} (count {})".format(inp.value, self.count)) | ||
| out.set(inp.value) | ||
| if self.count == 2: | ||
| lf.stop() | ||
| =} | ||
| } | ||
|
|
||
| # Persistent downstream federate. Continues even while Middle is absent. | ||
| reactor Down(period=500 ms) { | ||
| timer t(0, period) | ||
| input inp | ||
| input join | ||
|
|
||
| reaction(t) {= | ||
| print("Down timer at ({}, {})".format( | ||
| lf.time.logical_elapsed(), lf.tag().microstep)) | ||
| =} | ||
|
|
||
| reaction(join) {= | ||
| print("Down observed Middle join") | ||
| =} | ||
|
|
||
| reaction(inp) {= | ||
| print("Down received {} from Middle".format(inp.value)) | ||
| =} | ||
| } | ||
|
|
||
| federated reactor { | ||
| midExec = new TransientExec( | ||
| launch_time = 1 s, | ||
| federation_name = "TransientFederates", | ||
| fed_instance_name = "mid") | ||
| up = new Up() | ||
| down = new Down() | ||
|
|
||
| @transient | ||
| mid = new Middle() | ||
|
|
||
| up.out -> mid.inp | ||
| mid.join -> down.join | ||
| mid.out -> down.inp | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.