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

Add runtime tests #475

Merged
merged 13 commits into from
Dec 2, 2024
Merged

Add runtime tests #475

merged 13 commits into from
Dec 2, 2024

Conversation

michaeldeistler
Copy link
Contributor

@michaeldeistler michaeldeistler commented Oct 29, 2024

Note that the tests are disabled in the workflow: pytest -m "not runtime"

Copy link
Contributor

@jnsbck jnsbck left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for implementing this, I think this will be really useful. I had also worked on the same thing, but was pursuing sth slightly different. I have added my proof of concept to this branch. (see also my comments). Feel free to work off of it or remove it. I think having a seperate CI for regressions might be useful in the long run.

Happy to discuss this more.

.github/workflows/regression_tests.yml Show resolved Hide resolved
tests/regression_test_runner.py Outdated Show resolved Hide resolved
tests/test_regression.py Outdated Show resolved Hide resolved
tests/test_runtime.py Outdated Show resolved Hide resolved
tests/test_runtime.py Outdated Show resolved Hide resolved
@jnsbck jnsbck linked an issue Nov 4, 2024 that may be closed by this pull request
@jnsbck

This comment was marked as resolved.

@jaxleyverse jaxleyverse deleted a comment from github-actions bot Nov 4, 2024
@jnsbck

This comment was marked as resolved.

@jnsbck jnsbck force-pushed the runtimetests branch 2 times, most recently from 5b0281b to 2855ff7 Compare November 21, 2024 19:03
@jaxleyverse jaxleyverse deleted a comment from github-actions bot Nov 21, 2024
@jaxleyverse jaxleyverse deleted a comment from github-actions bot Nov 21, 2024
@jnsbck jnsbck force-pushed the runtimetests branch 4 times, most recently from eb50f1b to 8e6de5a Compare November 22, 2024 10:53
@jaxleyverse jaxleyverse deleted a comment from github-actions bot Nov 22, 2024
@jaxleyverse jaxleyverse deleted a comment from github-actions bot Nov 22, 2024
@jaxleyverse jaxleyverse deleted a comment from github-actions bot Nov 22, 2024
@jaxleyverse jaxleyverse deleted a comment from github-actions bot Nov 22, 2024
@jnsbck jnsbck force-pushed the runtimetests branch 3 times, most recently from 824a83f to b8798c5 Compare November 22, 2024 14:04
@jaxleyverse jaxleyverse deleted a comment from github-actions bot Nov 22, 2024
Copy link
Contributor

New Baselines

test_runtime(num_cells=1, artificial=False, connect=False, connection_prob=0.0, voltage_solver=jaxley.stone)
🆕 build_time: (0.566s).
🆕 compile_time: (18.334s).
🆕 run_time: (2.804s).

test_runtime(num_cells=1, artificial=False, connect=False, connection_prob=0.0, voltage_solver=jax.sparse)
🆕 build_time: (0.394s).
🆕 compile_time: (3.041s).
🆕 run_time: (2.451s).

test_runtime(num_cells=10, artificial=False, connect=True, connection_prob=0.1, voltage_solver=jaxley.stone)
🆕 build_time: (1.836s).
🆕 compile_time: (29.308s).
🆕 run_time: (18.758s).

test_runtime(num_cells=10, artificial=False, connect=True, connection_prob=0.1, voltage_solver=jax.sparse)
🆕 build_time: (1.256s).
🆕 compile_time: (26.581s).
🆕 run_time: (25.064s).

test_runtime(num_cells=1000, artificial=True, connect=True, connection_prob=0.001, voltage_solver=jaxley.stone)
🆕 build_time: (109.680s).
🆕 compile_time: (45.643s).
🆕 run_time: (41.482s).

test_runtime(num_cells=1000, artificial=True, connect=True, connection_prob=0.001, voltage_solver=jax.sparse)
🆕 build_time: (108.686s).
🆕 compile_time: (61.090s).
🆕 run_time: (58.329s).

@jnsbck
Copy link
Contributor

jnsbck commented Nov 22, 2024

@michaeldeistler This should be ready for review. The following is implemented and works:

  • tests/test_regression.py contains the regression tests that are run using pytest -m regression
  • automates writing results to database, comparing results stored baselines and producing a report (see above).
  • regression_tests.yml runs the regression tests.
  • update_regression_baseline.yml to update the baseline
  • idea is to trigger this on comment
  • comments with updated baseline report
  • pushes the updated baselines to the branch in which the workflow is run.

If you want to run this locally do you can do NEW_BASELINE=1 pytest -m regression i.e. on main and then run pytest -m regression on feature.

Some thoughts I had: Even with a 20% tolerance the regression tests frequently fail for some reason. (might need to average across several runs or take the max across several runs for the baseline, but currently the regression tests take quite long. Would be good to merge #489 to speed this up).

Lemme know if anything is unclear

@jnsbck jnsbck self-requested a review November 22, 2024 15:20
jnsbck

This comment was marked as resolved.

Copy link
Contributor Author

@michaeldeistler michaeldeistler left a comment

Choose a reason for hiding this comment

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

Wow this is amazing!!!

I don't think I understand when exactly the updating of the times is being run. On a comment to this particular PR (i.e., #475)? Or some other PR/issue? Also, what should the comment be? Anything? Who would the comment have to be by? Anyone? (BTW I am commenting now, so does this trigger the regression tests :D ?)

.github/workflows/regression_tests.yml Show resolved Hide resolved
.github/workflows/update_regression_baseline.yml Outdated Show resolved Hide resolved
.github/workflows/update_regression_baseline.yml Outdated Show resolved Hide resolved
@@ -55,6 +55,8 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
tests/regression_test_results.json
tests/regression_test_baselines.json
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 don't get this. Why do we first put it in the gitignore just to then force add it?

Copy link
Contributor

@jnsbck jnsbck Dec 2, 2024

Choose a reason for hiding this comment

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

I agree this appears a bit odd, but I want to prevent users from pushing an updated baseline file from their local machine (which is why I have added it to the gitignore). The only way baselines should be updated is through github actions (to ensure regression tests are run in a consistent environment). That is why the github actions uses -f, while for the user changes to these files are ignored.

EDIT: This also makes running regression tests locally easier, since: running NEW_BASELINE=1 pytest -m regression on main and then pytest -m regression on feature. Ignores the changes to the baseline when switching the branch, so no stashing etc. necessary to run the test on feature with the baseline file from main.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, got it, yes makes sense!

tests/test_regression.py Show resolved Hide resolved
@jnsbck
Copy link
Contributor

jnsbck commented Dec 2, 2024

The event issue_comment gets triggered on every comment that gets posted to an issue or PR. However, the workflow to produce an updated baseline is only triggered if the comment body contains the string /update_regression_baseline (so your comment would not have triggered it a) because the issue_comment workflow has to be merged to main first due to the way the event listener works on github and b) cos you did not use the command above). The workflow is run on the PR branch, which means the new baseline is produced from the updated codebase. The change to the baselines is then merged into the current PR. The command to start the workflow can currently be used by all users, but we could limit this to admins as well.

@jnsbck
Copy link
Contributor

jnsbck commented Dec 2, 2024

I have verified this to work in a seperate repo, if the workflow to update the baselines exists on the default branch. Upon commenting with /update_regression_baselines on any PR, the workflow gets triggered. First a comment is posted to inform the user the workflow is run, then the new baselines are computed and compared to the ones stored in main, and a report is produced and the prev. comment is updated with the result. If successful, the updated baselines are pushed to the PR branch if the branch is part of the repo or a seperate PR is opened in case the branch is from a fork (The user is also made aware of this in the comment), see below.

image

Since the workflow can only be triggered on the default branch this PR has to be merged first and needs a seperate PR to update the baselines using /update_regression_baselines. Hence the regression tests above failing.

Side note: The report is always written to the pytest output (above the Failure report), so you can check why the regression test action might have failed in detail.

image

With this, I think this can be merged @michaeldeistler, unless you have any other reseverations.

@michaeldeistler
Copy link
Contributor Author

Thanks a lot! Feel free to merge (I cannot approve because it is technically "my" PR).

@jnsbck jnsbck merged commit dd7bbb5 into main Dec 2, 2024
1 of 2 checks passed
@jnsbck jnsbck deleted the runtimetests branch December 2, 2024 15:31
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.

Add runtime tests
2 participants