Skip to content

Conversation

moorepants
Copy link
Member

@moorepants moorepants commented Apr 15, 2022

References to other Issues or PRs

Fixes #23366

Brief description of what is fixed or changed

New output which tells more clearly that the frame is of the wrong type.

Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %paste
import sympy as sm
import sympy.physics.mechanics as me
me.init_vprinting(use_latex='mathjax')
q1, q2, u1, u2 = me.dynamicsymbols('q1, q2, u1, u2')
N = me.ReferenceFrame('N')
N_v_A = u1*N.x
N_v_A.diff(N, u1), N_v_A.diff(N, u2)

## -- End pasted text --
---------------------------------------------------------------------------
VectorTypeError                           Traceback (most recent call last)
Input In [1], in <cell line: 7>()
      5 N = me.ReferenceFrame('N')
      6 N_v_A = u1*N.x
----> 7 N_v_A.diff(N, u1), N_v_A.diff(N, u2)

File ~/src/sympy/sympy/physics/vector/vector.py:540, in Vector.diff(self, var, frame, var_in_dcm)
    496 """Returns the partial derivative of the vector with respect to a
    497 variable in the provided reference frame.
    498 
   (...)
    535 
    536 """
    538 from sympy.physics.vector.frame import _check_frame
--> 540 _check_frame(frame)
    541 var = sympify(var)
    543 inlist = []

File ~/src/sympy/sympy/physics/vector/frame.py:1453, in _check_frame(other)
   1451 from .vector import VectorTypeError
   1452 if not isinstance(other, ReferenceFrame):
-> 1453     raise VectorTypeError(other, ReferenceFrame('A'))

VectorTypeError: 
Expected an instance of <class
'sympy.physics.vector.frame.ReferenceFrame'>, but received object
'u1(t)' of u1.

Other comments

Release Notes

  • physics.vector
    • More informative error message if args are swapped in Vector.diff()

@sympy-bot
Copy link

sympy-bot commented Apr 15, 2022

Hi, I am the SymPy bot (v163). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • physics.vector
    • More informative error message if args are swapped in Vector.diff() (#23372 by @moorepants)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.11.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #23366



#### Brief description of what is fixed or changed

New output which tells more clearly that the frame is of the wrong type.

```python
Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %paste
import sympy as sm
import sympy.physics.mechanics as me
me.init_vprinting(use_latex='mathjax')
q1, q2, u1, u2 = me.dynamicsymbols('q1, q2, u1, u2')
N = me.ReferenceFrame('N')
N_v_A = u1*N.x
N_v_A.diff(N, u1), N_v_A.diff(N, u2)

## -- End pasted text --
---------------------------------------------------------------------------
VectorTypeError                           Traceback (most recent call last)
Input In [1], in <cell line: 7>()
      5 N = me.ReferenceFrame('N')
      6 N_v_A = u1*N.x
----> 7 N_v_A.diff(N, u1), N_v_A.diff(N, u2)

File ~/src/sympy/sympy/physics/vector/vector.py:540, in Vector.diff(self, var, frame, var_in_dcm)
    496 """Returns the partial derivative of the vector with respect to a
    497 variable in the provided reference frame.
    498 
   (...)
    535 
    536 """
    538 from sympy.physics.vector.frame import _check_frame
--> 540 _check_frame(frame)
    541 var = sympify(var)
    543 inlist = []

File ~/src/sympy/sympy/physics/vector/frame.py:1453, in _check_frame(other)
   1451 from .vector import VectorTypeError
   1452 if not isinstance(other, ReferenceFrame):
-> 1453     raise VectorTypeError(other, ReferenceFrame('A'))

VectorTypeError: 
Expected an instance of <class
'sympy.physics.vector.frame.ReferenceFrame'>, but received object
'u1(t)' of u1.
```

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* physics.vector
  * More informative error message if args are swapped in Vector.diff()
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@github-actions
Copy link

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

       before           after         ratio
     [77f1d79c]       [05a85ca4]
     <sympy-1.10.1^0>                 
+      99.1±0.8ms        176±0.7ms     1.77  sum.TimeSum.time_doit

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@moorepants
Copy link
Member Author

This is ready for review.

@sidhu1012
Copy link
Contributor

LGTM!

@sidhu1012 sidhu1012 merged commit 7f7f309 into sympy:master Apr 17, 2022
@moorepants moorepants deleted the vector-diff-error branch April 17, 2022 15:28
@moorepants moorepants added the CZI: Codegen/Biomech Sam Brockie's CZI-funded postdoc work on codegen and biomechanics label Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CZI: Codegen/Biomech Sam Brockie's CZI-funded postdoc work on codegen and biomechanics physics.vector
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mechanics vector.diff() needs a clear error message if you swap the two arguments.
3 participants