Skip to content

ValueError("Time steps T must match sampling time" #332

Closed

Description

@bj2sn

Got this error when using timeresp.py. Checked the source code, I think the problem is at line 337-338:
if dt < sys.dt:
raise ValueError("Time steps T must match sampling time")

It will be better to use the following, since float rounding error can be smaller or larger:

if abs(dt-sys.dt) > 1e-5:

Activity

  1. murrayrm commented on Jul 23, 2019

    @murrayrm
    Member

    Can you attach a code snippet that generates the error? This check is done in the discrete time portion of the code and so a small error between dt and sys.dt should not really occur (the only allowed differences between dt and sys.dt should be specifying a simulation sample time that is an integer multiple of the system sampling time).

    Also, can you indicate which version of python-control you are using (control.__version__ will tell you). The line that you indicated doesn't seem to match the latest release.

  2. bj2sn commented on Jul 24, 2019

    @bj2sn
    Author

    My "control" version is 0.8.2, Python version 3.7.3 (IPython 7.6.1) Windows 10 (64 bits)
    The problem can be demonstrated by a simple test:

    import numpy as np
    samp_rate = 500e3
    T = np.arange(100)
    T[1]-T[0]
    Out[5]: 2e-06

    T[2]-T[1]
    Out[6]: 2e-06

    T[3]-T[2]
    Out[7]: 2.0000000000000003e-06

    T[4]-T[3]
    Out[8]: 1.9999999999999995e-06

    So, if we call timeresp.py with T[3:] as our time steps in simulation, line 265 "dt = T[1] - T[0]" will yield dt = 1.9999999999999995e-06, but sys.dt should be 2e-6. Subsequently, line 337 will raise the ValueError.

    If simulation time uses T, or T[1:], or T[2:] will have no problem!

  3. bj2sn commented on Jul 24, 2019

    @bj2sn
    Author

    It seems the problem goes away by changing line 337 in timeresp.py to:
    if abs(dt - sys.dt) > 1e-18:

  4. murrayrm commented on Jul 24, 2019

    @murrayrm
    Member

    Thanks for the extra info @bj2sn. A fix will be a bit more complicated because the discrete time simulation routines allow you to specify a sample time for the simulation that is a multiple of the sampling time for the system. So, for example, you can have that dt is 2 * sys.dt. On the current master, this check is done on line 362.

    Will put this on my list of things to fix.

  5. self-assigned this
    on Jul 24, 2019
  6. added this to the 0.8.3 milestone on Aug 9, 2019
  7. murrayrm commented on Jan 2, 2020

    @murrayrm
    Member

    Fixed in PR #356.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions