-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
pydrake: math overloads provide inconsistent user experience #15038
Comments
it's a matter of adding |
@EricCousineau-TRI , what is the best way to add a new method def foo(self):
print('hello world!')
setattr(A, 'foo', foo) Update: never mind. I think it's better to add it from C++. |
FWIW No need to use |
RobotLocomotion#15038 Co-authored-by: Soonho Kong <soonho.kong@tri.global>
* Enable numpy math functions to work with symbolic variables. #15038 Co-authored-by: Soonho Kong <soonho.kong@tri.global>
…comotion#15039) * Enable numpy math functions to work with symbolic variables. RobotLocomotion#15038 Co-authored-by: Soonho Kong <soonho.kong@tri.global>
@EricCousineau-TRI , we still have a remaining issue here. The following code gives from pydrake.all import AutoDiffXd, Variable, sin
x = 1
y = AutoDiffXd(1, [1, 0])
z = Variable('z')
print(sin(x))
print(sin(y))
print(sin(z))
As @RussTedrake wrote above, one solution is to update
To be specific, here is a patch: modified bindings/pydrake/all.py
@@ -30,10 +30,10 @@ from . import getDrakePath
from .autodiffutils import *
from .forwarddiff import *
from .lcm import *
-from .math import *
from .perception import *
from .polynomial import *
from .symbolic import *
+from .math import *
from .trajectories import * What do you think about this approach? |
I am not a huge fan of playing games with import order. If we have multiple competing definitions of a name and we need a specific one of those definitions to win, then we should explicitly disavow the unwanted implementations, i.e., we should not even attempt to import the unwanted implementations. In fact, it should be a test failure if any of the "all.py" files ever overwrites a previously-imported name. When there are multiple definitions in play, we need to ask the drake developer to choose which one is supposed to win, instead of leaving it to alphabetical chance. |
I'm not sure how hard that is to achieve. But the |
I'm onboard with polishing later, but #15052 looks like a great intermediate solution! |
* DNM Disable CI * notes: clean up the first few sections * wip * wip * wip * wip * wip * wip * wip * wip: first pass done * Factor out to h2 and sort the Build Dependencies * Remove non-notable changes (refactorings, docs) * Move APT site to announcements * Punt hydroelastic viz change into dynamics section Probably all of the hydroelatic changes should be culled, but having them all in once place is a start. * Prioritize and reword the breaking changes section * Note AVX breaking change * Fix some pydrake typos Remove non-notable (unit test) change * quadrotor example: add getter for geometry frame (#15046) * quadrotor example: add getter for geometry frame * Enable numpy math functions to work with symbolic variables. (#15039) * Enable numpy math functions to work with symbolic variables. #15038 Co-authored-by: Soonho Kong <soonho.kong@tri.global> * Remove deprecated code 2021-04-21 (#15050) Missed previously, perhaps owing to idiosyncratic date. * drake::multibody::MultiBodyPlant::CalcCenterOfMassPosition * all overloads * wip * wip * integrate new commits from merge of master * Merge remote-tracking branch 'upstream/master' into release_notes-v0.30.0 * Fix CaMel case typo * wip * set date * Revert "DNM Disable CI" This reverts commit 608e8ec. * wip
Consider the following example:
Here's a simple basic use case, which does work fine.
returns
But there are some nearby patterns that lay a trap for users:
gives
Q: Can we teach
Expression
to understand the numpy version?Here is another one:
gives
Q: Can we move the
math
import in all.py below thesymbolic
import, so the symbolic version doesn't clobber the more general one?(I know that we're in the land of perhaps ill-advised
pydrake.all
ness, but I believe that should be better for non-expert users).cc @EricCousineau-TRI . @soonho-tri -- might you be willing to take a look?
The text was updated successfully, but these errors were encountered: