Skip to content
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

Handling imprecise time values #2684

Closed
ktbarrett opened this issue Aug 24, 2021 · 0 comments · Fixed by #2685
Closed

Handling imprecise time values #2684

ktbarrett opened this issue Aug 24, 2021 · 0 comments · Fixed by #2685
Labels
category:codebase:scheduler relating to cocotb's coroutine scheduler, triggers, and coroutine objects type:feature new or enhanced functionality

Comments

@ktbarrett
Copy link
Member

ktbarrett commented Aug 24, 2021

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, a ValueError is thrown. Additionally, the useful helper method get_sim_steps also throws a ValueError 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: throw ValueError like is currently done (default)
  • round: round to the nearest step using round builtin
  • ceil: round up to the nearest step using math.ceil
  • floor: round down to the nearest step using math.floor

This argument could also be passed to Timer.

An environment variable, a cocotb module global variable, or an attribute on the get_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 like ceil. If this was to be done, a FutureWarning 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.

@ktbarrett ktbarrett added type:feature new or enhanced functionality category:codebase:scheduler relating to cocotb's coroutine scheduler, triggers, and coroutine objects labels Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:codebase:scheduler relating to cocotb's coroutine scheduler, triggers, and coroutine objects type:feature new or enhanced functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant