Handling imprecise time values #2684
Labels
category:codebase:scheduler
relating to cocotb's coroutine scheduler, triggers, and coroutine objects
type:feature
new or enhanced functionality
Problem
A couple users (to my memory @alexforencich and @jwprice100) have lamented about how timing is handled in cocotb. When one creates a time wait with
Timer
with a value that cannot be accurately represented in the simulator, aValueError
is thrown. Additionally, the useful helper methodget_sim_steps
also throws aValueError
if a value is given which cannot be accurately represented, which is very limiting.Proposed Solutions
There are several suggestions, feel free to agree/debate each independently.
Change
get_sim_steps
to take an argument to decide how to handle imprecise values by rounding. The round modes would be:error
: throwValueError
like is currently done (default)round
: round to the nearest step usinground
builtinceil
: round up to the nearest step usingmath.ceil
floor
: round down to the nearest step usingmath.floor
This argument could also be passed to
Timer
.An environment variable, a
cocotb
module global variable, or an attribute on theget_sim_steps
object could be added to globally affect the default rounding mode.The default of
error
could be changed in 2.0 to be something more sensible likeceil
. If this was to be done, aFutureWarning
about the default should be added. This change would not break existing passing tests, but may make existing failing tests pass and would be difficult to change in the future without breaking tests, so it must be considered carefully.The text was updated successfully, but these errors were encountered: