Skip to content

Commit f3b6e60

Browse files
committed
test(model): Pin chunk-metadata divergence across every non-adaptive case
Signed-off-by: David Leong <leongdl@amazon.com>
1 parent 63939af commit f3b6e60

2 files changed

Lines changed: 72 additions & 19 deletions

File tree

‎specs/python-model-interface.md‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,20 +1160,31 @@ yields `1-1`, `2-2`, … instead of `1-5`, `6-10`, …. It is ignored when
11601160
the space has no chunked parameter, matching the pure-Python reference.
11611161
Iteration observes it, and `len()` counts the overridden granularity.
11621162

1163-
Indexing observes it too, but only for a space that supports random
1164-
access. A `CONTIGUOUS` chunked space requires sequential iteration, so
1165-
`it[i]` raises `IndexError` for any index — with or without the
1166-
override — even though `len(it)` reports a count.
1163+
It is currently the only way to change the chunk size of a *static*
1164+
chunked space: the `chunks_default_task_count` setter accepts adaptive
1165+
spaces only, and raises `ValueError` otherwise.
11671166

1168-
This is the only way to change the chunk size of a *static* chunked
1169-
space: the `chunks_default_task_count` setter accepts adaptive spaces
1170-
only, and raises `ValueError` otherwise.
1171-
1172-
`chunks_task_count_override=0` raises `ValueError`. The Rust layer
1173-
clamps the override to at least 1, so 0 would silently mean 1, and the
1167+
Any non-positive value raises `ValueError`, so one `except ValueError`
1168+
covers `0` and negatives alike. The Rust layer clamps the override to at
1169+
least 1, so 0 would otherwise silently mean 1, and the
11741170
`chunks_default_task_count` setter already rejects it. The pure-Python
11751171
reference does not validate this argument.
11761172

1173+
Two current-implementation limitations, both divergences from the v0
1174+
reference rather than intended behaviour. Each has a `strict` xfail in
1175+
`test/openjd/model_v1/test_known_gaps.py`, so clearing either will fail
1176+
CI until this text is updated with it.
1177+
1178+
- Indexing observes the override only for a space that supports random
1179+
access. A `CONTIGUOUS` chunked space requires sequential iteration, so
1180+
`it[i]` raises `IndexError` for any index — with or without the
1181+
override — even though `len(it)` reports a count. See
1182+
`test_a_contiguous_chunked_space_supports_indexing`.
1183+
- `chunks_parameter_name` and `chunks_default_task_count` both return
1184+
`None` once the space is non-adaptive, which supplying the override
1185+
makes it. v0 reports the parameter name and the override value. See
1186+
`test_chunk_metadata_is_reported_for_a_non_adaptive_space`.
1187+
11771188
### `StepDependencyGraph`
11781189

11791190
Step dependency graph for topological ordering.

‎test/openjd/model_v1/test_known_gaps.py‎

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,65 @@ def _chunked_step(constraint: str) -> Any:
8585

8686
@pytest.mark.xfail(
8787
reason="v1 derives chunks_parameter_name and chunks_default_task_count from adaptive "
88-
"detection, so both are None for a statically chunked space. v0 reports them for any "
89-
"chunked space. See openjd-model step_param_space.rs: chunks_param_name and "
88+
"detection, so both are None for any non-adaptive chunked space. v0 reports them for "
89+
"any chunked space. See openjd-model step_param_space.rs: chunks_param_name and "
9090
"adaptive_chunk_size are both built from adaptive_info.",
9191
strict=True,
9292
)
93-
def test_chunk_metadata_is_reported_for_a_static_space() -> None:
94-
"""v0 returns ``"Frame"`` and ``5`` for this space. v1 returns ``None`` for both.
95-
96-
Neither value is unknowable — both are in the template — so a consumer inspecting a
97-
static chunked space through v1 cannot learn which parameter chunks, or at what size.
93+
@pytest.mark.parametrize(
94+
"chunks,override,expected_count",
95+
[
96+
# Statically chunked: no override involved, v0 reports the template's size.
97+
({"defaultTaskCount": 5, "rangeConstraint": "CONTIGUOUS"}, None, 5),
98+
# Statically chunked, re-chunked by the override.
99+
({"defaultTaskCount": 5, "rangeConstraint": "CONTIGUOUS"}, 1, 1),
100+
# Adaptive, turned static by the override. v0 reports the override as the size.
101+
(
102+
{"defaultTaskCount": 5, "targetRuntimeSeconds": 60, "rangeConstraint": "CONTIGUOUS"},
103+
1,
104+
1,
105+
),
106+
],
107+
ids=["static", "static-overridden", "adaptive-overridden"],
108+
)
109+
def test_chunk_metadata_is_reported_for_a_non_adaptive_space(
110+
chunks: dict, override: int | None, expected_count: int
111+
) -> None:
112+
"""v0 returns ``"Frame"`` and the chunk size for each of these. v1 returns ``None``.
113+
114+
Neither value is unknowable — both are in the template, or are the override the caller
115+
just passed — so a consumer inspecting a non-adaptive chunked space through v1 cannot
116+
learn which parameter chunks, or at what size. One root cause, three ways to reach it:
117+
anything that leaves the space non-adaptive drops both getters.
98118
"""
119+
from openjd.model._v1 import create_job, decode_job_template
99120
from openjd.model._v1.job import StepParameterSpaceIterator
100121

101-
it = StepParameterSpaceIterator(step=_chunked_step("CONTIGUOUS"))
122+
template = {
123+
"specificationVersion": "jobtemplate-2023-09",
124+
"name": "T",
125+
"extensions": ["TASK_CHUNKING"],
126+
"steps": [
127+
{
128+
"name": "S",
129+
"parameterSpace": {
130+
"taskParameterDefinitions": [
131+
{"name": "Frame", "type": "CHUNK[INT]", "range": "1-10", "chunks": chunks}
132+
]
133+
},
134+
"script": {
135+
"actions": {"onRun": {"command": "echo", "args": ["{{Task.Param.Frame}}"]}}
136+
},
137+
}
138+
],
139+
}
140+
job_template = decode_job_template(template=template, supported_extensions=["TASK_CHUNKING"])
141+
step = create_job(job_template=job_template, job_parameter_values={}).steps[0]
142+
143+
it = StepParameterSpaceIterator(step=step, chunks_task_count_override=override)
102144
assert it.chunks_adaptive is False
103145
assert it.chunks_parameter_name == "Frame"
104-
assert it.chunks_default_task_count == 5
146+
assert it.chunks_default_task_count == expected_count
105147

106148

107149
@pytest.mark.xfail(

0 commit comments

Comments
 (0)