Fix unstable output of periodic sequence due to precision error.#35311
Merged
shunping merged 2 commits intoapache:masterfrom Jun 17, 2025
Merged
Fix unstable output of periodic sequence due to precision error.#35311shunping merged 2 commits intoapache:masterfrom
shunping merged 2 commits intoapache:masterfrom
Conversation
7bcd8d4 to
3d15fa0
Compare
Collaborator
Author
|
@claudevdm, could you please review this one too since you did the previous one and have some context? Thanks a lot! |
Contributor
|
Assigning reviewers: R: @jrmccluskey for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Collaborator
Author
|
stop reviewer notifications |
Collaborator
Author
|
remind me after tests pass |
Contributor
|
Stopping reviewer notifications for this pull request: requested by reviewer. If you'd like to restart, comment |
claudevdm
approved these changes
Jun 17, 2025
Collaborator
Author
|
Thanks @claudevdm! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A fix following #35300.
See the explanation below (copied from the inline comments):
In
ImpulseSeqGenRestrictionProvider, the total number of counts (i.e.total_outputs) is computed byceil((end - start) / interval)(beam/sdks/python/apache_beam/transforms/periodicsequence.py
Line 45 in facdc4e
endisstart + duration(beam/sdks/python/apache_beam/ml/ts/util.py
Line 172 in facdc4e
Due to precision error of arithmetic operations, even if
durationis set tolen(self._data) * interval,(end - start) / intervalcould be a little bit smaller or bigger thanlen(self._data).In case of being bigger,
total_outputswould belen(self._data) + 1, as theceil()operation is used, which is NOT what we want.Assuming that the precision error is no bigger than 1%, by subtracting a small amount, we ensure that the result after
ceil()is stable even if a certain degree of precision error is present.