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

[py systems] Adjust scalar conversion to avoid unique_ptr #22491

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

jwnimmer-tri
Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri commented Jan 18, 2025

@jwnimmer-tri jwnimmer-tri added priority: low status: do not review release notes: none This pull request should not be mentioned in the release notes labels Jan 18, 2025
@jwnimmer-tri jwnimmer-tri force-pushed the yo-dawg branch 3 times, most recently from 36d911b to 5098f81 Compare January 21, 2025 20:53
@jwnimmer-tri jwnimmer-tri marked this pull request as ready for review January 21, 2025 20:53
@jwnimmer-tri
Copy link
Collaborator Author

+@rpoyner-tri for feature review, please.

My aim is to hit Sherm for platform review (on Thursday during his on call, or else next week as a special assignment).

Copy link
Contributor

@rpoyner-tri rpoyner-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: my head hurts.

Reviewed 18 of 18 files at r1, all commit messages.
Reviewable status: 5 unresolved discussions, needs at least two assigned reviewers


systems/framework/system_base.h line 1102 at r1 (raw file):

  /** (Internal use only) Declares that `parent_service` is the service
  interface of the Diagram that owns this subsystem. Throws if the parent
  service has already been set and parent_service is non-null. */

nit maybe add the back ticks here, since the distinction between the internal state and the argument is a bit subtle in English text.

Suggestion:

`parent_service`

systems/framework/test/wrapped_system_test.cc line 16 at r1 (raw file):

using symbolic::Expression;

GTEST_TEST(WrappedSystemTset, Basic) {

typo

Suggestion:

WrappedSystemTest

systems/framework/test/wrapped_system_test.cc line 23 at r1 (raw file):

  EXPECT_EQ(dut.num_input_ports(), 2);
  EXPECT_EQ(dut.num_output_ports(), 1);
  EXPECT_TRUE(dynamic_cast<const Adder<double>*>(&dut.unwrap()));

nit I don't know why I find this weird (implicit bool conversion for nullptr check). Did we go through a fashion of forbidding this and then later give up on it?


systems/framework/diagram.cc line 1395 at r1 (raw file):

    // WrappedSystem was originally injected into this control flow.
    if (auto* wrapped =
            dynamic_cast<internal::WrappedSystem<NewType>*>(new_system.get())) {

nit I don't know why I find this weird (implicit bool conversion for nullptr check). Did we go through a fashion of forbidding this and then later give up on it?


systems/framework/diagram.cc line 1399 at r1 (raw file):

      const std::string name = new_system->get_name();
      DRAKE_DEMAND(wrapped->registered_systems_.size() == 1);
      std::shared_ptr<System<NewType>> inner = wrapped->registered_systems_[0];

nit It seems a little strange to me that this "extract" surgery is not a method on WrappedSystem, but I guess we only do it once? 🤷

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+@sherm1 for platform review per schedule (tomorrow), please. Also please check as feature-expert for systems/framework stuff.

... my head hurts.

I did have a whole "Yo, dawg" meme post ready to go, but I decided it was probably a bridge too far.

Reviewable status: 1 unresolved discussion, LGTM missing from assignee sherm1(platform)


systems/framework/diagram.cc line 1395 at r1 (raw file):

Previously, rpoyner-tri (Rick Poyner (rico)) wrote…

nit I don't know why I find this weird (implicit bool conversion for nullptr check). Did we go through a fashion of forbidding this and then later give up on it?

Yes, we disprefer if (foo) { by itself, preferring if (foo != nullptr) to clarify that we're branching on null instead of some other magic.

I've not been extending that to if-with-new-named-variables but maybe we should? I've done that here now.


systems/framework/diagram.cc line 1399 at r1 (raw file):

Previously, rpoyner-tri (Rick Poyner (rico)) wrote…

nit It seems a little strange to me that this "extract" surgery is not a method on WrappedSystem, but I guess we only do it once? 🤷

The logic and invariants here (the registered systems and the parent service) seem to me more strongly coupled with the internals of Diagram than the internals of WrappedSystem.

Copy link
Contributor

@rpoyner-tri rpoyner-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8 of 8 files at r2, all commit messages.
Reviewable status: LGTM missing from assignee sherm1(platform)

Copy link
Contributor

@rpoyner-tri rpoyner-tri left a 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 r3, all commit messages.
Reviewable status: LGTM missing from assignee sherm1(platform)

Copy link
Member

@sherm1 sherm1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whew! My hair fell out. I'm glad I didn't have to feature review the Python stuff, thanks Rico.
Platform :lgtm:

Reviewed 10 of 18 files at r1, 7 of 8 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: 1 unresolved discussion


systems/framework/wrapped_system.h line 20 at r3 (raw file):

@tparam_default_scalar */
template <typename T>
class WrappedSystem final : public Diagram<T> {

BTW implementing as a 1-system Diagram is clever, but please consider adding some documentation here explaining that since it is an unusual twist.

Copy link
Contributor

@rpoyner-tri rpoyner-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r4, all commit messages.
Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees rpoyner-tri(platform),sherm1(platform)

@jwnimmer-tri jwnimmer-tri merged commit df0264a into RobotLocomotion:master Jan 23, 2025
9 of 10 checks passed
@jwnimmer-tri jwnimmer-tri deleted the yo-dawg branch January 23, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low release notes: none This pull request should not be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants