Issue 1438 write tar consistency#1442
Issue 1438 write tar consistency#1442marco66colombo wants to merge 5 commits intofastmachinelearning:mainfrom
Conversation
hls4ml/writer/quartus_writer.py
Outdated
| self.write_activation_tables(model) | ||
| self.write_yml(model) | ||
| self.write_tar(model) | ||
| write_tar = model.config.get_writer_config().get('WriteTar', False) |
There was a problem hiding this comment.
Why should we move the check outside of the write_tar() function? It was deliberately placed inside so we have a clean set of steps for the writer. Also it is easier to log (we're not doing it now, but could do in the future)
There was a problem hiding this comment.
Because right now if you don't set 'WriteTar' field in the writer config, the behaviour of write_tar() is not the one expected, i.e. it doesn't create the tarball archive. To my understanding, that field this is mainly leveraged for local testing, in which you don't want to have the test folder filled with tarball files.
I think a different and cleaner solution would be to set an environment variable that prevents the tar files to be generated (basically moving back the check inside write_tar(), but checking if the env variable is set this time). This solution has the advantage of being set only once before running the tests and it is applied to all the tests.
There was a problem hiding this comment.
The check is identical, it is just outside of the function now. The idea of the writer is that it follows a set of steps. The tar writer function may or may not write the tar, depending on the config, just like all the other functions write contents based on the provided config. Using env vars to change the behavior of the conversion process while you also have the conversion config itself that controls all other aspects of conversion would be splitting control and introducing inconsistency that will likely be a burden later on.
There was a problem hiding this comment.
Thanks, this makes sense. I moved the WriteTar check outside write_tar() following earlier discussion, but I agree that keeping that logic inside write_tar() can preserve the writer-step semantics and original design.
If preferred, I can restore that behavior (move the check back inside write_tar()) while keeping the backend config fixes for Catapult and VivadoAccelerator, plus the related test coverage updates.
|
As mentioned in the Follow-up section, we still need to decide how to (and if) ensure tar artifact generation in CI. Should we enable tar artifact generation for every CI test case? If yes, I see two practical approaches:
Happy to proceed with either approach if we want to activate artifact generation. |
|
Since the group was leaning toward using an env var, avoiding edits across many test files, and keeping the default CI behavior as “no tar generation,” I implemented the env-var control in the writer path. I chose this over a Please let me know if this approach is acceptable, or if you’d prefer the pytest-fixture route instead. I also restored |
| ('false', False), | ||
| ('1', True), | ||
| ], | ||
| ) |
There was a problem hiding this comment.
I think you need to add the id=[...] here for the proper naming of the tests
There was a problem hiding this comment.
thanks for the comment, done
|
I have one Currently, Lines 63 to 71 in b50bd46 In this PR, Catapult now sets: config['WriterConfig'] = {
'WriteTar': write_tar,
}That matches existing patterns in some backends (for example): hls4ml/hls4ml/backends/quartus/quartus_backend.py Lines 140 to 142 in b50bd46 hls4ml/hls4ml/backends/oneapi/oneapi_backend.py Lines 171 to 174 in b50bd46 But other backends provide the full writer-config key set (for example Vivado): hls4ml/hls4ml/backends/vivado/vivado_backend.py Lines 282 to 287 in b50bd46 Given this mixed pattern, I was wondering what is the expected policy.
|
Description
This PR fixes #1438 by making
WriteTarhandling consistent and explicit across writers.Summary
WriteTarif condition one layer higher: checkWriterConfig.WriteTarinwrite_hls()before callingwrite_tar().write_tar()as a pure “write tarball” method (no internal config check).write_tarsupport to Catapult backend config (create_initial_config(..., write_tar=False)+WriterConfig['WriteTar']), so Catapult follows the same config path as other backends.test_writer_config::test_write_tarcoverage to includeCatapult.write_tarsupport toVivadoAcceleratorBackend.create_initial_config(...)and includeVivadoAcceleratorintest_writer_config::test_write_tarcoverage.Motivation / Context
Issue #1438 highlights inconsistent artifact behavior and writer semantics.
A key point from prior maintainer discussion is that keeping tar generation disabled by default is better for users, to avoid generating large numbers of extra files during local development and debugging.
This PR keeps that default (
WriteTar=False) while making behavior consistent across backends.Notable behavior note
For Catapult specifically, when
WriteTar=Trueand tar creation is triggered:This is intentional for consistency across backends.
For VivadoAccelerator, with
WriteTar=True, tar can be generated/regenerated twice (once via the Vivado writer path and once viawrite_new_tarafter accelerator-specific files are added). This matches past behavior and is not introduced in this PR.Follow-up (in progress)
I still need to update tests/CI so artifact generation is always enabled where CI expects tar artifacts.
Possible approaches under consideration:
test/pytest/conftest.py(for example wrapping conversion/config creation to forcewrite_tar=Truein CI).write_tar=True(more explicit, but many more edits required).I am working on this as a follow-up step.
Type of change
Tests
test/pytest/test_writer_config.pyin a local environment.Test Configuration:
Checklist
pre-commiton the files I edited or added.