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

test rendering and fix non-determinism #118

Merged
merged 1 commit into from
May 13, 2024
Merged

Conversation

esc
Copy link
Member

@esc esc commented May 12, 2024

The rendering code keeps breaking across changes made by different contributors. Thus, we needed to test the rendering code too. We do this in a headless fashion and compare the textual 'dot' representation of the rendered SCFG that the graphviz package produces to a predefined, expected result. Since this type of test is rather verbose, we minimize the amount of testing to simply exercise some of the core rendering routines.

However, this test exposed multiple bugs across the code-base:

  • The if-else in the core rendering was broken and no longer worked for simple SCFGs.

  • The render_scfg function was completely broken, since the rendering is now done in the constructors and the render_scfg only needs to return the graphviz digraph.

  • The dot output itself was non-deterministic. That is to say, both the order of the nodes in the SCFG itself and also the order of the nodes in the dot output were unpredictable. This is due to the use the of the Python set class, which doesn't have order and when iterating over a set the elements will be returned in a random order. Graphviz doesn't care about order, so the rendered SCFGs would look largely the same, which is perhaps why this went unnoticed. Also, sometimes isomorphic variants would be produced, that are semantically equivalent but had different block ordering. As result several calls to sorted and use of a deque were inserted to stabilize both the order of the blocks within the SCFG datastructure and also the creation of an SCFG from a YAML representation.

The rendering code keeps breaking across changes made by different
contributors. Thus, we needed to test the rendering code too. We do this
in a headless fashion and compare the textual 'dot' representation of
the rendered SCFG that the graphviz package produces to a predefined,
expected result. Since this type of test is rather verbose, we minimize
the amount of testing to simply exercise some of the core rendering
routines.

However, this test exposed multiple bugs across the code-base:

* The if-else in the core rendering was broken and no longer worked for
  simple SCFGs.

* The `render_scfg` function was completely broken, since the rendering
  is now done in the constructors and the `render_scfg` only needs to
  return the graphviz digraph.

* The `dot` output itself was non-deterministic. That is to say, both
  the order of the nodes in the SCFG itself and also the order of the
  nodes in the `dot` output were unpredictable. This is due to the use
  the of the Python set class, which doesn't have order and when
  iterating over a set the elements will be returned in a random order.
  Graphviz doesn't care about order, so the rendered SCFGs would look
  largely the same, which is perhaps why this went unnoticed. Also,
  sometimes isomorphic variants would be produced, that are semantically
  equivalent but had different block ordering.  As result several calls
  to `sorted` and use of a `deque` were inserted to stabilize both the
  order of the blocks within the SCFG datastructure and also the
  creation of an SCFG from a YAML representation.
@esc esc mentioned this pull request May 12, 2024
Copy link
Contributor

@kc611 kc611 left a comment

Choose a reason for hiding this comment

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

The only comment I have is that the expected_original and expected_restructured can potentially change across graphviz versions. Otherwise the PR LGTM!

@esc
Copy link
Member Author

esc commented May 13, 2024

The only comment I have is that the expected_original and expected_restructured can potentially change across graphviz versions. Otherwise the PR LGTM!

yeah, will have to keep an eye on it and make some changes if it turns out to be too unstable.

@esc esc merged commit afe1835 into numba:main May 13, 2024
2 checks passed
@esc esc deleted the test_rendering_again branch May 15, 2024 13:00
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.

2 participants