Skip to content

Fixing bug in timeresp.forced_response #336

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

Merged
merged 2 commits into from
Aug 16, 2019

Conversation

adm78
Copy link
Contributor

@adm78 adm78 commented Aug 8, 2019

When forced_response was called with a discrete MIMO sys and T=None, the following error occurred:

Traceback (most recent call last): File "/home/andrew/Apps/python-control/control/tests/timeresp_test.py", line 281, in test_forced_response _t, yout, _xout = forced_response(sysd, U=u, X0=x0) File "/home/andrew/Apps/python-control/control/timeresp.py", line 374, in forced_response tout, yout, xout = sp.signal.dlsim(dsys, np.transpose(U), T, X0) File "/home/andrew/.virtualenvs/python-control-dev/local/lib/python2.7/site-packages/scipy/signal/ltisys.py", line 3327, in dlsim u_dt_interp = interp1d(t, u.transpose(), copy=False, bounds_error=True) File "/home/andrew/.virtualenvs/python-control-dev/local/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 433, in __init__ _Interpolator1D.__init__(self, x, y, axis=axis) File "/home/andrew/.virtualenvs/python-control-dev/local/lib/python2.7/site-packages/scipy/interpolate/polyint.py", line 60, in __init__ self._set_yi(yi, xi=xi, axis=axis) File "/home/andrew/.virtualenvs/python-control-dev/local/lib/python2.7/site-packages/scipy/interpolate/polyint.py", line 125, in _set_yi raise ValueError("x and y arrays must be equal in length along " ValueError: x and y arrays must be equal in length along interpolation axis.

Fix:

  • Removing use of len method on U and T arrays, replacing with appropriate numpy shape call
  • Ensure correct U dimension is being checked for MIMO systems
  • Adding new unit test for this case

…ueError when applied to discrete sys with T=None.
@coveralls
Copy link

coveralls commented Aug 8, 2019

Coverage Status

Coverage decreased (-0.08%) to 83.416% when pulling 8b08481 on adm78:bugfix/forced_response into 129a053 on python-control:master.

if len(U) != len(T):
ValueError('Pamameter ``T`` must have same length as'
'input vector ``U``')
if (len(U.shape) == 1 and U.shape[0] != T.shape[0]) or (len(U.shape) > 1 and U.shape[1] != T.shape[0]):
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this fits in 78 columns. If not, break into two lines (at or)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've broken this line in the updated PR.

else:
# Make sure the input vector and time vector have same length
# TODO: allow interpolation of the input vector
Copy link
Member

Choose a reason for hiding this comment

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

Leave this comment in, since at some point we would like to allow "subsampling"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have re-added this comment in the updated PR.

@murrayrm murrayrm added this to the 0.8.3 milestone Aug 9, 2019
# Set and/or check time vector in discrete time case
if isdtime(sys, strict=True):
if T is None:
if U is None:
raise ValueError('Parameters ``T`` and ``U`` can\'t both be'
'zero for discrete-time simulation')
# Set T to equally spaced samples with same length as U
T = np.array(range(len(U))) * (1 if sys.dt is True else sys.dt)
if len(U.shape) == 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using U.ndim

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have replaced all instances of range(len(U)) with U.ndim in the updated PR.

if len(U) != len(T):
ValueError('Pamameter ``T`` must have same length as'
'input vector ``U``')
if (len(U.shape) == 1 and U.shape[0] != T.shape[0]) or (len(U.shape) > 1 and U.shape[1] != T.shape[0]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider U.ndim instead of len(U.shape)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have replaced all instances of range(len(U)) with U.ndim in the updated PR.

@murrayrm murrayrm merged commit 114890f into python-control:master Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants