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 framework] Setting context values now clones instead of owns #22455

Merged

Conversation

jwnimmer-tri
Copy link
Collaborator

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

For the following classes ...

  • ContinuousState
  • DiscreteValues
  • Parameters

... when setting a new value from Python (either in the constructor, or with a set function) the value is now copied instead of aliased. Having the context keep mutable aliases to objects that the user provided is not only too dangerous in the first place, but also incompatible with forthcoming upstream pybind11 semantics.

Towards #21968.


This change is Reviewable

@jwnimmer-tri jwnimmer-tri added priority: low release notes: fix This pull request contains fixes (no new features) labels Jan 14, 2025
@jwnimmer-tri
Copy link
Collaborator Author

+@sherm1 for feature review, please.

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.

Feature :lgtm: with one question

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 1 unresolved discussion, needs at least two assigned reviewers


bindings/pydrake/systems/framework_py_semantics.cc line 1106 at r1 (raw file):

        return std::make_unique<ContinuousState<T>>(
            state.Clone(), num_q, num_v, num_z);
      }),

BTW do the BasicVector-matching overloads have unit tests somewhere?

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.

+@rpoyner-tri for platform review, please.

Reviewable status: LGTM missing from assignee rpoyner-tri(platform)


bindings/pydrake/systems/framework_py_semantics.cc line 1106 at r1 (raw file):

Previously, sherm1 (Michael Sherman) wrote…

BTW do the BasicVector-matching overloads have unit tests somewhere?

They both have code coverage (tests do run them -- confirmed by inserting DRAKE_UNREACHABLE).

However, if I remove them leaving only the VectorBase, then all tests still pass. So, I added more tests for the BasicVector subclassing.

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.

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: LGTM missing from assignee rpoyner-tri(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.

:lgtm:

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

@rpoyner-tri rpoyner-tri merged commit 6fa5816 into RobotLocomotion:master Jan 15, 2025
10 checks passed
@jwnimmer-tri jwnimmer-tri deleted the pybind11-framework-semantics branch January 15, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low release notes: fix This pull request contains fixes (no new features)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants