Fix flaky ReproUtilTest by adding fallback lookup for trainers #425
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Modified ReproUtil.recoverTrainer to include a fallback when looking up trainer components. If lookup by name fails due to mismatched component names, it now attempts to look up the component by its class type. It sorts the candidate components by their numeric suffix to ensure deterministic mapping between the provenance and configuration list.
Motivation
NonDex detected test flakiness in:
org.tribuo.reproducibility.ReproUtilTest.reproduceTransformTrainerorg.tribuo.reproducibility.ReproUtilTest#testBaggingTrainerorg.tribuo.reproducibility.ReproUtilTest.testBaggingTrainerAllInvocationsChangeOne of the cause is possibly the non-deterministic component naming in OLCUT. ProvenanceUtil generates component names like logisticregressiontrainer-1 vs logisticregressiontrainer-2 based on iteration order, which relies on HashMap/HashSet and has no guarantee in determinism. The PR allow ReproUtil to recover the trainer based on its type when the name lookup fails and enforces a strict sorting order to guarantee the correct component is selected. This should improve robustness of those tests. An example of NonDex output attached.
NonDex_ReproUtilTests.txt