Skip to content

Conversation

@mwiebe
Copy link
Contributor

@mwiebe mwiebe commented Feb 19, 2025

What was the problem/requirement? (What/Why)

To use task chunking as defined by https://github.com/OpenJobDescription/openjd-specifications/blob/mainline/rfcs/0001-task-chunking.md, clients of the library need to be able to iterate over a parameter space based on chunking.

What was the solution? (How)

  • Modify StepParameterSpaceIterator to handle parameter spaces that include a CHUNK[INT] parameter. The iteration pattern depends on the values in the 'chunks' object of the parameter definition.
    • If targetRuntimeSeconds is 0 or unspecified, split the CHUNK[INT] dimension into chunks, and then iterate over the whole space with that selection of chunks.
    • If targetRuntimeSeconds is a positive integer, move the CHUNK[INT] dimension to the innermost loop, and dynamically select the chunk each time it advances. Let the user of the iterator modify its chunks_default_task_count to adapt the chunk size over time.
    • The StepParameterSpaceIterator object behaved more like a pseudo-container than an iterator. Change it to act as the iterator itself (returning 'self' from iter() instead of a new object).
    • Changed how the special case zero-dimensional iteration works to be a Node/Iterator pair just like the others, for a more uniform interface.
  • Changes to IntRangeExpr:
    • Fix a bug in IntRangeExpr.from_list that wasn't handling the end of a linear sequence correctly.
    • Change the string representation of IntRangeExpr to use "," instead of "-" when there are just two values.
  • Add and update unit tests for all of the modifications.

What is the impact of this change?

Clients such as the openjd CLI command will be able to use chunked iteration of parameter spaces to run job templates that include chunking.

How was this change tested?

Implemented unit tests for the new chunked iteration modes.

Was this change documented?

Updated docstrings about chunked iteration.

Is this a breaking change?

This change includes a few small changes to the public contract of IntRangeExpr and the StepParameterSpaceIterator. Most code won't depend on these specifics, but some could.

Does this change impact security?

No


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@mwiebe mwiebe requested a review from a team as a code owner February 19, 2025 20:08
@mwiebe mwiebe force-pushed the param-space-chunk-iter branch 5 times, most recently from 7ed8d49 to c9a52e5 Compare February 21, 2025 00:43
Copy link
Contributor

@jusiskin jusiskin left a comment

Choose a reason for hiding this comment

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

Great job with this code change.

I haven't finished my review pass yet, but wanted to surface one thing we should add to help clarify an assumption here.

@mwiebe mwiebe force-pushed the param-space-chunk-iter branch 2 times, most recently from 139032d to beeaec2 Compare February 22, 2025 01:33
Copy link

@leongdl leongdl left a comment

Choose a reason for hiding this comment

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

This will take me some time to understand all the logic.

if chunks_default_task_count <= 0:
chunk_count = 1
else:
chunk_count = (task_count + chunks_default_task_count - 1) // chunks_default_task_count
Copy link

Choose a reason for hiding this comment

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

That's an interesting way to implement something almost like ceiling!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you messed around with graphics code like implementing https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Algorithm_for_integer_arithmetic and similar this stuff is pretty natural :)

Copy link
Contributor

@jusiskin jusiskin left a comment

Choose a reason for hiding this comment

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

Great job with this, @mwiebe! Just a few suggested changes here.

@mwiebe mwiebe force-pushed the param-space-chunk-iter branch 2 times, most recently from acabd96 to 63fc330 Compare February 25, 2025 18:35
Copy link

@leongdl leongdl left a comment

Choose a reason for hiding this comment

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

I generally understand the logic, but probably need to do a few more thinking passes to walk through the logic.

@mwiebe mwiebe force-pushed the param-space-chunk-iter branch from 63fc330 to 2011e71 Compare February 25, 2025 18:48
@mwiebe mwiebe force-pushed the param-space-chunk-iter branch from 2011e71 to 8e678bd Compare February 25, 2025 19:35
* Modify StepParameterSpaceIterator to handle parameter spaces that
  include a CHUNK[INT] parameter. The iteration pattern depends on the
  values in the 'chunks' object of the parameter definition.
   * If targetRuntimeSeconds is 0 or unspecified, split the CHUNK[INT]
     dimension into chunks, and then iterate over the whole space with
     that selection of chunks.
   * If targetRuntimeSeconds is a positive integer, move the CHUNK[INT]
     dimension to the innermost loop, and dynamically select the chunk
     each time it advances. Let the user of the iterator modify its
     chunks_default_task_count to adapt the chunk size over time.
   * The StepParameterSpaceIterator object behaved more like a
     pseudo-container than an iterator. Change it to act as the iterator
     itself (returning 'self' from __iter__() instead of a new object).
   * Changed how the special case zero-dimensional iteration works to be
     a Node/Iterator pair just like the others, for a more uniform
     interface.
* Changes to IntRangeExpr:
   * Fix a bug in IntRangeExpr.from_list that wasn't handling the end of a
     linear sequence correctly.
   * Change the string representation of IntRangeExpr to use "," instead of
     "-" when there are just two values.
* Add and update unit tests for all of the modifications.
* Update parameter space validation to ensure only one CHUNK[INT]
  parameter is defined.

BREAKING CHANGE: This change includes a few small changes to the public contract
    of IntRangeExpr and the StepParameterSpaceIterator. Most code won't depend
    on these specifics, but some could.

Signed-off-by: Mark Wiebe <[email protected]>
@mwiebe mwiebe force-pushed the param-space-chunk-iter branch from 8e678bd to f1bfdf3 Compare February 25, 2025 19:38
@sonarqubecloud
Copy link

@mwiebe mwiebe merged commit 9253018 into OpenJobDescription:mainline Feb 25, 2025
19 checks passed
@mwiebe mwiebe deleted the param-space-chunk-iter branch February 25, 2025 19:41
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.

3 participants