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
[systems] Add DiagramBuilder::RemoveSystem #19243
[systems] Add DiagramBuilder::RemoveSystem #19243
Conversation
1e424be
to
31ffb92
Compare
31ffb92
to
eebc61e
Compare
+@rpoyner-tri for feature review, please. +@sherm1 for high-level feature review, please -- as well as platform review. |
eebc61e
to
b016700
Compare
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.
Reviewable status: 1 unresolved discussion, LGTM missing from assignees rpoyner-tri(platform),sherm1(platform) (waiting on @jwnimmer-tri, @rpoyner-tri, and @sherm1)
systems/framework/diagram_builder.cc
line 98 at r3 (raw file):
} // Disconnect any internal connections associated with this system.
Whoops. I forgot to test coverage for this block.
b016700
to
2b0b2e6
Compare
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.
Reviewable status: LGTM missing from assignees rpoyner-tri(platform),sherm1(platform) (waiting on @rpoyner-tri and @sherm1)
systems/framework/diagram_builder.cc
line 98 at r3 (raw file):
Previously, jwnimmer-tri (Jeremy Nimmer) wrote…
Whoops. I forgot to test coverage for this block.
Done.
5a09c18
to
f88beb5
Compare
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.
Reviewed 2 of 6 files at r1, 2 of 4 files at r2, 2 of 2 files at r4, all commit messages.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee sherm1(platform) (waiting on @jwnimmer-tri and @sherm1)
systems/framework/diagram_builder.h
line 255 at r4 (raw file):
/// decrementing the indices of all higher-numbered ports that remain. /// /// @warning Because a DigramBuilder owns the objects it contains, the system
typo
Suggestion:
DiagramBuilder
f88beb5
to
1a1d98b
Compare
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.
Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: LGTM missing from assignee sherm1(platform) (waiting on @sherm1)
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.
It's not clear to me how this is related to render camera preview in #19158 -- please explain if that is the motivation for this PR.
High-level feature, and platform with a few minor comments
Reviewed 2 of 6 files at r1, 2 of 4 files at r2, 1 of 2 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: 3 unresolved discussions (waiting on @jwnimmer-tri)
systems/framework/diagram_builder.h
line 256 at r5 (raw file):
/// /// @warning Because a DiagramBuilder owns the objects it contains, the system /// will be deleted.
BTW consider mentioning that this must be done prior to Build() -- might not be obvious to someone who doesn't realize Build() transfers ownership out.
systems/framework/diagram_builder.cc
line 51 at r5 (raw file):
return item.get() == &system; })); DRAKE_DEMAND(system_index < registered_systems_.size());
BTW I doubt there is a performance concern here, but you could use a find_if==end result to issue the above error message without doing the search twice. I think system_index==registered_systems_.size() is the same condition as systems_.count()==0.
systems/framework/test/diagram_builder_test.cc
line 64 at r5 (raw file):
// // This setup is carefully chosen such that removing 'adder' will cover all // branching conditions within the implementation.
BTW confirmed with kcov
The only thing that wasn't covered was CheckInvariants() which is called only in Debug. You could consider a manual call here in the test cases FWIW.
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.
It's not clear to me how this is related to render camera preview in #19158 -- please explain if that is the motivation for this PR.
That PR contains a call to this new function:
# Disable LCM image transmission. It has a non-trivial cost, and
# at the moment Meldis can't display LCM images anyway.
self._builder.builder().RemoveSystem(camera_publisher)
Reviewable status: complete! all discussions resolved, LGTM from assignees rpoyner-tri(platform),sherm1(platform) (waiting on @jwnimmer-tri)
systems/framework/diagram_builder.h
line 256 at r5 (raw file):
Previously, sherm1 (Michael Sherman) wrote…
BTW consider mentioning that this must be done prior to Build() -- might not be obvious to someone who doesn't realize Build() transfers ownership out.
That's true of all functions in the the header. I won't try to fix it in this PR.
systems/framework/diagram_builder.cc
line 51 at r5 (raw file):
Previously, sherm1 (Michael Sherman) wrote…
BTW I doubt there is a performance concern here, but you could use a find_if==end result to issue the above error message without doing the search twice. I think system_index==registered_systems_.size() is the same condition as systems_.count()==0.
I don't think performance carries any weight here.
systems/framework/test/diagram_builder_test.cc
line 64 at r5 (raw file):
Previously, sherm1 (Michael Sherman) wrote…
BTW confirmed with kcov
The only thing that wasn't covered was CheckInvariants() which is called only in Debug. You could consider a manual call here in the test cases FWIW.
For my own taste, running bazel test //systems/framework:diagram_builder_test -c dbg
during development was sufficient. Checking the invariants buys us the most when they are running continuously in all test cases, not just one line here.
Merging now, to unblock a train of coming PRs. If there are other lingering improvements I'm happy to fix in a follow-up. |
FYI (irrelevent here where performance is not a concern, but I should have at least mentioned it): |
Previously, sherm1 (Michael Sherman) wrote…
I actually did that initially. It fails to meet the API promise that the relative order of the systems and ports remains unchanged. |
Towards #19158.
This change is