-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/resolve timelines #62
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
Open
maarten-ic
wants to merge
11
commits into
develop
Choose a base branch
from
feature/resolve-timelines
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3d1f169
Additional dunder methods for Ports and Timeline
maarten-ic 40d6bef
Fix potential typing issue
maarten-ic 56ebfb2
Extend Timeline API
maarten-ic a093eca
Add timeline checker and testcases
maarten-ic 7a1a4e1
Update public API in v0.2/__init__.py
maarten-ic 016a815
Rename test module
maarten-ic 849daa7
Improve error message for cyclic dependencies
maarten-ic f98cc6b
Fix docstring link
maarten-ic c354722
Merge remote-tracking branch 'origin/develop' into feature/resolve-ti…
maarten-ic 78280ff
Update timeline annotation in test
maarten-ic 7f7add8
Improve exceptions, docstrings and add testcase
maarten-ic 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| import ymmsl | ||
| from ymmsl.v0_2 import ConduitFilter, Configuration, Timeline | ||
| from ymmsl.v0_2 import Reference as Ref | ||
| from ymmsl.v0_2.timeline_resolver import ( | ||
| ROOT_TIMELINE, | ||
| ConduitTimelineError, | ||
| CyclicDependency, | ||
| InconsistentTimelines, | ||
| TooManyReducerFilters, | ||
| resolve_timelines, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def timelines_configuration() -> Configuration: | ||
| return ymmsl.load_as( | ||
| Configuration, Path(__file__).parent / "ymmsl1/timelines.ymmsl" | ||
| ) | ||
|
|
||
|
|
||
| def test_consistent_configuration(timelines_configuration: Configuration) -> None: | ||
| timelines_configuration.check_consistent() | ||
|
|
||
|
|
||
| def test_dispatch(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("dispatch")] | ||
| resolve_timelines(model) | ||
| assert model.components[Ref("first")].timeline == ROOT_TIMELINE | ||
| assert model.components[Ref("second")].timeline == ROOT_TIMELINE | ||
|
|
||
|
|
||
| def test_macromicro(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("macromicro")] | ||
| resolve_timelines(model) | ||
| assert model.components[Ref("macro")].timeline == ROOT_TIMELINE | ||
| assert model.components[Ref("micro")].timeline == Timeline(":macro") | ||
|
|
||
| # Check that ports have the correct relative timelines: | ||
| macro = model.components[Ref("macro")] | ||
| assert macro.ports["init"].timeline == Timeline("") | ||
| assert macro.ports["out"].timeline == Timeline("macro") | ||
| assert macro.ports["in"].timeline == Timeline("macro") | ||
|
|
||
| for micro_port in model.components[Ref("micro")].ports.values(): | ||
| assert micro_port.timeline == Timeline("") | ||
|
|
||
|
|
||
| def test_cycle(timelines_configuration: Configuration) -> None: | ||
| with pytest.raises(CyclicDependency, match="cycle in model"): | ||
| resolve_timelines(timelines_configuration.models[Ref("cycle")]) | ||
|
|
||
|
|
||
| def test_reducer(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("reducer")] | ||
| resolve_timelines(model) | ||
| assert model.components[Ref("first")].timeline == ROOT_TIMELINE | ||
| assert model.components[Ref("second")].timeline == ROOT_TIMELINE | ||
|
|
||
|
|
||
| def test_only_reducer(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("reducer")] | ||
| # Remove the conduit first.final -> second.init1 and keep only the reduced conduit | ||
| del model.conduits[0] | ||
| assert model.conduits[0].filters == [ConduitFilter("last")] | ||
| resolve_timelines(model) | ||
| assert model.components[Ref("first")].timeline == ROOT_TIMELINE | ||
| assert model.components[Ref("second")].timeline == ROOT_TIMELINE | ||
|
|
||
|
|
||
| def test_too_many_reducers(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("reducer")] | ||
| model.conduits[-1].filters.append(model.conduits[-1].filters[0]) | ||
| with pytest.raises(TooManyReducerFilters, match="too many reducer filters"): | ||
| resolve_timelines(model) | ||
|
|
||
|
|
||
| def test_inconsistent_timelines(timelines_configuration: Configuration) -> None: | ||
| with pytest.raises(InconsistentTimelines): | ||
| resolve_timelines(timelines_configuration.models[Ref("inconsistent")]) | ||
|
|
||
|
|
||
| def test_repeaters(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("repeaters")] | ||
| resolve_timelines(model) | ||
| assert model.components[Ref("macro")].timeline == ROOT_TIMELINE | ||
| assert model.components[Ref("meso")].timeline == Timeline(":macro") | ||
| assert model.components[Ref("micro")].timeline == Timeline(":macro:meso") | ||
|
|
||
|
|
||
| def test_too_many_repeaters(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("repeaters")] | ||
| model.conduits[-2].filters.append(ConduitFilter.REPEAT) | ||
| with pytest.raises(ConduitTimelineError, match="remove a repeater"): | ||
| resolve_timelines(model) | ||
|
|
||
|
|
||
| def test_too_few_repeaters(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("repeaters")] | ||
| model.conduits[-1].filters.pop() | ||
| with pytest.raises(ConduitTimelineError, match="add a repeater"): | ||
| resolve_timelines(model) | ||
|
|
||
|
|
||
| def test_repeater_and_too_many_reducers(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("repeaters")] | ||
| model.conduits[-1].filters.insert(0, ConduitFilter.LAST) | ||
| with pytest.raises(TooManyReducerFilters, match="too many reducer filters"): | ||
| resolve_timelines(model) | ||
|
|
||
|
|
||
| def test_repeater_after_reducer(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("repeater_reducer")] | ||
| resolve_timelines(model) | ||
| assert model.components[Ref("macro1")].timeline == ROOT_TIMELINE | ||
| assert model.components[Ref("macro2")].timeline == ROOT_TIMELINE | ||
| assert model.components[Ref("micro1")].timeline == Timeline(":macro1") | ||
| assert model.components[Ref("micro2")].timeline == Timeline(":macro2") | ||
|
|
||
| # Remove filters on the last conduit to make the incoming timelines inconsistent | ||
| model.conduits[-1].filters = [] | ||
| with pytest.raises(InconsistentTimelines, match="different timelines"): | ||
| resolve_timelines(model) | ||
|
|
||
|
|
||
| def test_repeater_after_reducer_error(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("repeater_reducer_error")] | ||
| with pytest.raises(ConduitTimelineError, match="remove a repeater and reducer"): | ||
| resolve_timelines(model) | ||
| model.conduits[-1].filters = [] | ||
| resolve_timelines(model) | ||
| assert model.components[Ref("macro")].timeline == ROOT_TIMELINE | ||
| assert model.components[Ref("micro1")].timeline == Timeline(":macro") | ||
| assert model.components[Ref("micro2")].timeline == Timeline(":macro") | ||
|
|
||
|
|
||
| def test_inconsistent_interact(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("inconsistent_interact")] | ||
| with pytest.raises(ConduitTimelineError, match="missing timeline annotations"): | ||
| resolve_timelines(model) | ||
| model.components[Ref("B")].ports["out"].timeline = Timeline("A") | ||
| model.components[Ref("B")].ports["in"].timeline = Timeline("A") | ||
| resolve_timelines(model) | ||
|
|
||
|
|
||
| def test_model_ports(timelines_configuration: Configuration) -> None: | ||
| model = timelines_configuration.models[Ref("model_ports")] | ||
| resolve_timelines(model) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have too many repeaters as well? If I connect an init component to a micro with two repeaters? Or would that come out as InconsistentTimelines? But there aren't two known timelines in this case, so that's not what I would expect...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would indeed come out as
InconsistentTimelines(which then suggests to add a reducer, or remove a repeater).Note that
TooManyReducerFiltersonly triggers when trying to reduce "above" the root timeline. You can also have too many reducers and end up with anInconsistentTimelineserror (which will suggest to remove a reducer or add a repeater).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to rename this exception to
ReducerFilterOnRootTimeline(or similar) to avoid this confusion?