-
Notifications
You must be signed in to change notification settings - Fork 484
pytest based synthesis tests #1257
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
base: main
Are you sure you want to change the base?
Conversation
merge hls4ml main into add-conftest
Add synthesis tests pytest
update add-conftest branch
Add conftest
test/pytest/conftest.py
Outdated
| "Vivado": {"csim": False, "synth": True, "export": False}, | ||
| "Vitis": {"csim": False, "synth": True, "export": False}, | ||
| "Quartus": {"synth": True, "fpgasynth": False}, | ||
| "oneAPI": {"build_type": "fpga_emu", "run": False}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fpga_emu is actually just C compilation, so this needs to be changed, though to what I am not sure. The descriptions are given in https://github.com/oneapi-src/oneAPI-samples/tree/release/2025.0/DirectProgramming/C%2B%2BSYCL_FPGA/Tutorials/GettingStarted/fpga_compile#four-compilation-options and they correspond to fpga_emu, report, fpga_sim, and fpga. I would guess report unless you want to run cosim, in which case it's fpga_sim. The first two don't require Quartus, while the last two do.
|
Can we test this to actually run SYNTHESIS tests? |
|
yes, but if the env var 'RUN_SYNTHESIS' is not set, the default is False. |
|
Thanks, this looks very nice to me! From the test logs, it seems to have triggered the synthesis tests successfully and the code looks good to me, so I think this is basically ready for merge. I just have a few questions for the way forward:
|
|
My feeling is that Quartus is basically obsolete now, with the code having migrated to oneAPI. I don't know if we need to spend effort towards setting up synthesis tests for it. |
|
Fair point. The other thing brought up at the meeting was if we can rebalance the batching of tests somehow? Right now some of them take a few minutes while another takes 1:50h. |
|
@JanFSchulte thanks for the review and the follow-up questions.
|
Description
This PR introduces synthesis tests into the
pytestframework forhls4ml.The goal of this change is to automate the validation of HLS synthesis reports against predefined baselines to ensure stability and correctness over time, using pytest.
Main Changes
Baselines are shipped with this repository under
test/pytest/baselines/<backend>/<version>/<report>.json. Each test case specifies its baseline name, matching the artifact names produced by CI so comparisons stay aligned. Baselines must be refreshed within the PR that changes the synthesis expectations; otherwise the tests will fail.test/pytest/conftest.pyfixture: introduces the sharedsynthesis_configfixture that drives every synthesis test. It gathers:RUN_SYNTHESIS, defaultfalseif env var is unset);VIVADO_VERSION,VITIS_VERSION,QUARTUS_VERSION,ONEAPI_VERSION) with defaults if the environment variables are unset;Synthesis helper (
test/pytest/synthesis_helpers.py):run_synthesis_test.run_synthesisis disabled the helper returns early; otherwise it builds, saves the report, and compares it to the selected baseline.pytest.fail(...), so synthesis regressions surface immediately instead of being skipped.Tolerances: backend-specific tolerances are still provisional and will need further tuning as we collect more data.
CI integration (
test/pytest/ci-template.yml):generate_ci_yaml.pynow has aSPLIT_BY_TEST_CASEmap. For any test file listed there, the script inspects its test functions, batches them according to the configured chunk size, and emits separate CI jobs (each passingPYTESTFILE="path::test_fn"). This keeps heavy synthesis suites liketest_keras_apisharded without touching the test code.oneAPI report parsing has been hardened to tolerate values such as
n/a, avoiding the previousinvalid literal for int() with base 10: 'n/a'error.Current test coverage:
test_keras_api.pyis the first pytest using the synthesis flow. Each parametrized test now takes thesynthesis_configfixture, formats a baseline filename (e.g.hls4mlprj_keras_api_dense_{backend}_{io_type}.json), and callsrun_synthesis_test(...)after the assertions. Some cases (such astest_conv2d) guard the call with backend/strategy filters to avoid unsupported configurations or to avoid syntehsis that take too long for the jobs.Type of change
Tests
Synthesis tests are run conditionally and compared against versioned baselines if
RUN_SYNTHESIS=trueis set in the environment.Checklist
pre-commiton the files I edited or added.