Repository navigation
PSPLIB generator, eval tick cap, pool holds every job - #4
Conversation
… truncated runs A policy that keeps choosing wait made the episode run forever (the paper env has no max_ticks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s rejected Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Activities of RCPSP .sm/.mm instances become job templates: duration and renewable demand / availability scaled to cap; random (seeded) or sequential order; precedence ignored. The registry reads a file or a directory (sorted); the adapter only parses. Unit tests for parsing, scaling, seeding and loading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideData structuresDefine the PSPLIB activity templates and generator state used to turn renewable-resource profiles into jobs.
Increase the paper environment’s waiting-pool capacity to match its job count, preventing rejection of waiting jobs.
APIExpose PSPLIB generator parsing and its public generator type through the adapters module.
Add the PSPLIB generator specification and file-or-directory loader, and pass I/O through the generator registry interface.
Pass the I/O context into the generator registry when constructing the CLI simulator.
Pass the initialized threaded I/O context into the generator registry when constructing the C API simulator.
Uses of the APIAdd a PSPLIB environment configuration option and use it throughout training workers and saved checkpoints.
ImplementationAdd the PSPLIB parser and tests for parsing, validation, scaled job profiles, deterministic ordering, and generator loading.
Cap evaluation episode duration, report whether an episode was truncated, and add the corresponding output column.
DocumentationDocument the larger waiting pool and how to train and run with PSPLIB workloads.
Lock files and vendored codeUpdate ignore rules for generated or local artifacts.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 9 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/adapters/generators/psplib.zig" line_range="124" />
<code_context>
+ const n = try ints(row, &nums);
+ if (n < r) return error.InvalidInput;
+ var a: [max_res]u32 = @splat(0);
+ @memcpy(a[0..r], nums[0..r]);
+ avail = a;
+ }
</code_context>
<issue_to_address>
**Malformed instance crashes parser**
When a supplied PSPLIB file declares more than eight renewable resources and reaches `RESOURCEAVAILABILITIES` before a `REQUESTS/DURATIONS` section, `parse` copies `r` entries into the fixed eight-element availability array without first bounding `r`; a crafted instance with more than eight renewable resources and an availability section before any requests section triggers an out-of-bounds slice and terminates the process instead of returning `InvalidInput`.
Reject resource counts above `max_res` before copying availability values into the fixed-size array.
</issue_to_address>
### Comment 2
<location path="paper/evaluate.py" line_range="123" />
<code_context>
ap.add_argument("--seed-start", type=int, default=EVAL_SEED_START)
ap.add_argument("--sims", type=int, default=32, help="MCTS simulations per move (0 = skip ptr+mcts)")
ap.add_argument("--policies", default=",".join(BUILTIN))
+ ap.add_argument("--max-ticks", type=int, default=2000,
+ help="end (truncate) an episode after this many ticks; counted in the 'truncated' column")
ap.add_argument("--device", default="cpu")
</code_context>
<issue_to_address>
**Invalid caps break evaluation**
When the effective `max_ticks` value is zero or negative, `SchedEnv` resets an already-finished engine for a zero cap, so `run` fails on its first `step`; for a negative cap, `sim_create` treats the value as no cap and a wait-only policy never ends, so evaluation fails or hangs.
Validate the effective cap from the CLI and checkpoint as positive before constructing `SchedEnv`.
Also at `paper/evaluate.py:149`.
</issue_to_address>
### Comment 3
<location path="src/adapters/generators/psplib.zig" line_range="111" />
<code_context>
+ var nums: [3 + 2 * max_res + 8]u32 = undefined;
+ const n = try ints(row, &nums);
+ // new activity: jobnr mode dur R.. N..; extra mode lines lack jobnr -> skipped (mode 1 only)
+ if (n != 3 + r + n_non) continue;
+ var e: @TypeOf(raw.items[0]) = .{ .dur = std.math.cast(u16, nums[2]) orelse return error.InvalidInput, .dem = @splat(0) };
+ @memcpy(e.dem[0..r], nums[3 .. 3 + r]);
</code_context>
<issue_to_address>
**Alternative modes distort workloads**
When a `.mm` instance has activities with more than one mode, `parse` accepts each mode row because the rows have the same number of fields, then appends every mode as a separate template without checking the mode number. Random and sequential workloads therefore include unintended modes and weight activities with more modes more heavily.
Filter `.mm` request rows to mode 1 before appending templates.
Also at `src/adapters/generators/psplib.zig:110`.
</issue_to_address>
### Comment 4
<location path="src/adapters/generators/psplib.zig" line_range="72" />
<code_context>
+ },
+ };
+ const a = self.acts[i];
+ const dur: u16 = @intCast(@min(a.dur, out.layout.n_ticks));
+ const c: f32 = @floatFromInt(self.cap);
+ for (0..out.layout.n_res) |res| {
</code_context>
<issue_to_address>
**PSPLIB durations are shortened**
When an activity duration exceeds the configured `n_ticks` horizon, `Psplib.job` clamps `a.dur` to `out.layout.n_ticks`, so the generated job has a shorter duration than the PSPLIB activity and schedules and metrics no longer reflect the input workload.
Preserve the parsed PSPLIB duration instead of clamping it to the horizon.
</issue_to_address>
### Comment 5
<location path="paper/ptrmcts.py" line_range="104" />
<code_context>
+ raise FileNotFoundError(path)
+ if "," in path or "=" in path:
+ raise ValueError(f"PSPLIB path must not contain ',' or '=': {path}")
+ return {**ENV_KW, "machines": f"psplib:path={path},n=1", "n_res": 4}
+
+
</code_context>
<issue_to_address>
**PSPLIB training rejects valid instances**
When the selected instance, or an instance in the selected directory, has fewer than four renewable resources, `--psplib` sets `n_res` to 4, so `Psplib.machine` rejects the request when the instance provides fewer renewable resources and `SchedEnv` construction fails before training starts.
Set `n_res` to a value supported by the selected PSPLIB instance instead of always fixing it at 4.
</issue_to_address>
### Comment 6
<location path="paper/evaluate.py" line_range="146" />
<code_context>
if overlap:
raise SystemExit(f"evaluation seeds {overlap[0]}.. were used in training ({used.start}..{used.stop - 1})")
- env_kw = ck["env"] if ck else ENV_KW
+ env_kw = dict(ck["env"] if ck else ENV_KW)
+ # a policy that keeps choosing "wait" would otherwise never end the episode;
+ # every job has arrived long before this, so the cap does not change the workload
</code_context>
<issue_to_address>
**Checkpoint paths trigger local reads**
When a user evaluates an untrusted checkpoint whose environment selects a FIFO or a directory with a large number of `.sm`/`.mm` files, evaluation passes checkpoint-controlled `env["machines"]` to `SchedEnv`, and the PSPLIB generator reads the resulting path as the current user. A checkpoint pointing to a FIFO or a directory with many matching files can hang or exhaust the evaluation process, so users see a stuck or terminated run.
Validate checkpoint environment specs before constructing the environment, and restrict PSPLIB inputs to explicitly trusted regular files or bounded directories.
Also at `src/app/registry.zig:97`.
</issue_to_address>
### Comment 7
<location path="src/adapters/generators/psplib.zig" line_range="271" />
<code_context>
+ d.* = try g.job(.{ .id = 0, .arrival = 0 }, Usage.fromSlice(buf, layout));
+ }
+ }
+ try std.testing.expectEqualSlices(u16, &seqs[0], &seqs[1]);
+}
</code_context>
<issue_to_address>
**Random mode accepts one template**
When random selection is broken and always returns the first template, the `psplib: jobs follow the templates, scaled to cap; seeded and sequential` test passes: `expectEqualSlices` at line 271 only compares two runs, so always selecting the first template produces identical sequences. The test therefore accepts random mode that never selects other templates.
Assert that the reproducible sequence also selects more than one template.
</issue_to_address>
### Comment 8
<location path="src/adapters/generators/psplib.zig" line_range="255-257" />
<code_context>
+ try std.testing.expectEqual(want, dur);
+ const exp: [3]Elem = if (want == 3) .{ 20, 0, 20 } else .{ 0, 40, 10 };
+ for (0..3) |r| {
+ try std.testing.expectEqual(exp[r], u.resource(r)[0]);
+ try std.testing.expectEqual(exp[r], u.resource(r)[dur - 1]);
+ try std.testing.expectEqual(@as(Elem, 0), u.resource(r)[dur]);
+ }
+ }
</code_context>
<issue_to_address>
**Interior demand can be zero**
When the generator writes the expected demand at the endpoints but leaves interior ticks at zero, the `psplib: jobs follow the templates, scaled to cap; seeded and sequential` test passes if demands are written only at the first and last active ticks, with zeros between them: lines 255-257 check those endpoints and the tick after the job, but no interior tick. It therefore accepts a non-constant job profile.
Assert the expected demand at every tick in `0..dur` and zero at `dur`.
</issue_to_address>
### Comment 9
<location path="paper/evaluate.py" line_range="149" />
<code_context>
+ env_kw = dict(ck["env"] if ck else ENV_KW)
+ # a policy that keeps choosing "wait" would otherwise never end the episode;
+ # every job has arrived long before this, so the cap does not change the workload
+ env_kw["max_ticks"] = env_kw.get("max_ticks") or args.max_ticks
env = SchedEnv(**env_kw)
</code_context>
<issue_to_address>
**Paper changes lack regression tests**
When the paper tick-cap and pool-size changes are merged without dedicated tests, the new evaluation tick-cap and reporting path, and the 80-slot paper pool configuration, can regress without any test failing; existing truncation coverage exercises engine behavior, not these paper changes.
Add paper-level tests for capped evaluation and truncated reporting, and for admitting all jobs with the configured pool.
Also at `paper/ptrmcts.py:61`.
</issue_to_address>| const n = try ints(row, &nums); | ||
| if (n < r) return error.InvalidInput; | ||
| var a: [max_res]u32 = @splat(0); | ||
| @memcpy(a[0..r], nums[0..r]); |
There was a problem hiding this comment.
🟡 Medium · Malformed instance crashes parser
When a supplied PSPLIB file declares more than eight renewable resources and reaches RESOURCEAVAILABILITIES before a REQUESTS/DURATIONS section, parse copies r entries into the fixed eight-element availability array without first bounding r; a crafted instance with more than eight renewable resources and an availability section before any requests section triggers an out-of-bounds slice and terminates the process instead of returning InvalidInput.
Reject resource counts above max_res before copying availability values into the fixed-size array.
Prompt for AI agents
In `src/adapters/generators/psplib.zig` at line 124:
**Malformed instance crashes parser**
When a supplied PSPLIB file declares more than eight renewable resources and reaches `RESOURCEAVAILABILITIES` before a `REQUESTS/DURATIONS` section, `parse` copies `r` entries into the fixed eight-element availability array without first bounding `r`; a crafted instance with more than eight renewable resources and an availability section before any requests section triggers an out-of-bounds slice and terminates the process instead of returning `InvalidInput`.
Reject resource counts above `max_res` before copying availability values into the fixed-size array.| ap.add_argument("--seed-start", type=int, default=EVAL_SEED_START) | ||
| ap.add_argument("--sims", type=int, default=32, help="MCTS simulations per move (0 = skip ptr+mcts)") | ||
| ap.add_argument("--policies", default=",".join(BUILTIN)) | ||
| ap.add_argument("--max-ticks", type=int, default=2000, |
There was a problem hiding this comment.
🟡 Medium · Invalid caps break evaluation
When the effective max_ticks value is zero or negative, SchedEnv resets an already-finished engine for a zero cap, so run fails on its first step; for a negative cap, sim_create treats the value as no cap and a wait-only policy never ends, so evaluation fails or hangs.
Validate the effective cap from the CLI and checkpoint as positive before constructing SchedEnv.
Also at paper/evaluate.py:149.
Prompt for AI agents
In `paper/evaluate.py` at line 123:
**Invalid caps break evaluation**
When the effective `max_ticks` value is zero or negative, `SchedEnv` resets an already-finished engine for a zero cap, so `run` fails on its first `step`; for a negative cap, `sim_create` treats the value as no cap and a wait-only policy never ends, so evaluation fails or hangs.
Validate the effective cap from the CLI and checkpoint as positive before constructing `SchedEnv`.
Also at `paper/evaluate.py:149`.| var nums: [3 + 2 * max_res + 8]u32 = undefined; | ||
| const n = try ints(row, &nums); | ||
| // new activity: jobnr mode dur R.. N..; extra mode lines lack jobnr -> skipped (mode 1 only) | ||
| if (n != 3 + r + n_non) continue; |
There was a problem hiding this comment.
🟠 High · Alternative modes distort workloads
When a .mm instance has activities with more than one mode, parse accepts each mode row because the rows have the same number of fields, then appends every mode as a separate template without checking the mode number. Random and sequential workloads therefore include unintended modes and weight activities with more modes more heavily.
Filter .mm request rows to mode 1 before appending templates.
Also at src/adapters/generators/psplib.zig:110.
Prompt for AI agents
In `src/adapters/generators/psplib.zig` at line 111:
**Alternative modes distort workloads**
When a `.mm` instance has activities with more than one mode, `parse` accepts each mode row because the rows have the same number of fields, then appends every mode as a separate template without checking the mode number. Random and sequential workloads therefore include unintended modes and weight activities with more modes more heavily.
Filter `.mm` request rows to mode 1 before appending templates.
Also at `src/adapters/generators/psplib.zig:110`.| }, | ||
| }; | ||
| const a = self.acts[i]; | ||
| const dur: u16 = @intCast(@min(a.dur, out.layout.n_ticks)); |
There was a problem hiding this comment.
🟡 Medium · PSPLIB durations are shortened
When an activity duration exceeds the configured n_ticks horizon, Psplib.job clamps a.dur to out.layout.n_ticks, so the generated job has a shorter duration than the PSPLIB activity and schedules and metrics no longer reflect the input workload.
Preserve the parsed PSPLIB duration instead of clamping it to the horizon.
Prompt for AI agents
In `src/adapters/generators/psplib.zig` at line 72:
**PSPLIB durations are shortened**
When an activity duration exceeds the configured `n_ticks` horizon, `Psplib.job` clamps `a.dur` to `out.layout.n_ticks`, so the generated job has a shorter duration than the PSPLIB activity and schedules and metrics no longer reflect the input workload.
Preserve the parsed PSPLIB duration instead of clamping it to the horizon.| raise FileNotFoundError(path) | ||
| if "," in path or "=" in path: | ||
| raise ValueError(f"PSPLIB path must not contain ',' or '=': {path}") | ||
| return {**ENV_KW, "machines": f"psplib:path={path},n=1", "n_res": 4} |
There was a problem hiding this comment.
🟡 Medium · PSPLIB training rejects valid instances
When the selected instance, or an instance in the selected directory, has fewer than four renewable resources, --psplib sets n_res to 4, so Psplib.machine rejects the request when the instance provides fewer renewable resources and SchedEnv construction fails before training starts.
Set n_res to a value supported by the selected PSPLIB instance instead of always fixing it at 4.
Prompt for AI agents
In `paper/ptrmcts.py` at line 104:
**PSPLIB training rejects valid instances**
When the selected instance, or an instance in the selected directory, has fewer than four renewable resources, `--psplib` sets `n_res` to 4, so `Psplib.machine` rejects the request when the instance provides fewer renewable resources and `SchedEnv` construction fails before training starts.
Set `n_res` to a value supported by the selected PSPLIB instance instead of always fixing it at 4.| if overlap: | ||
| raise SystemExit(f"evaluation seeds {overlap[0]}.. were used in training ({used.start}..{used.stop - 1})") | ||
| env_kw = ck["env"] if ck else ENV_KW | ||
| env_kw = dict(ck["env"] if ck else ENV_KW) |
There was a problem hiding this comment.
🟡 Medium · Checkpoint paths trigger local reads
When a user evaluates an untrusted checkpoint whose environment selects a FIFO or a directory with a large number of .sm/.mm files, evaluation passes checkpoint-controlled env["machines"] to SchedEnv, and the PSPLIB generator reads the resulting path as the current user. A checkpoint pointing to a FIFO or a directory with many matching files can hang or exhaust the evaluation process, so users see a stuck or terminated run.
Validate checkpoint environment specs before constructing the environment, and restrict PSPLIB inputs to explicitly trusted regular files or bounded directories.
Also at src/app/registry.zig:97.
Prompt for AI agents
In `paper/evaluate.py` at line 146:
**Checkpoint paths trigger local reads**
When a user evaluates an untrusted checkpoint whose environment selects a FIFO or a directory with a large number of `.sm`/`.mm` files, evaluation passes checkpoint-controlled `env["machines"]` to `SchedEnv`, and the PSPLIB generator reads the resulting path as the current user. A checkpoint pointing to a FIFO or a directory with many matching files can hang or exhaust the evaluation process, so users see a stuck or terminated run.
Validate checkpoint environment specs before constructing the environment, and restrict PSPLIB inputs to explicitly trusted regular files or bounded directories.
Also at `src/app/registry.zig:97`.| d.* = try g.job(.{ .id = 0, .arrival = 0 }, Usage.fromSlice(buf, layout)); | ||
| } | ||
| } | ||
| try std.testing.expectEqualSlices(u16, &seqs[0], &seqs[1]); |
There was a problem hiding this comment.
🟡 Medium · Random mode accepts one template
When random selection is broken and always returns the first template, the psplib: jobs follow the templates, scaled to cap; seeded and sequential test passes: expectEqualSlices at line 271 only compares two runs, so always selecting the first template produces identical sequences. The test therefore accepts random mode that never selects other templates.
Assert that the reproducible sequence also selects more than one template.
Prompt for AI agents
In `src/adapters/generators/psplib.zig` at line 271:
**Random mode accepts one template**
When random selection is broken and always returns the first template, the `psplib: jobs follow the templates, scaled to cap; seeded and sequential` test passes: `expectEqualSlices` at line 271 only compares two runs, so always selecting the first template produces identical sequences. The test therefore accepts random mode that never selects other templates.
Assert that the reproducible sequence also selects more than one template.| try std.testing.expectEqual(exp[r], u.resource(r)[0]); | ||
| try std.testing.expectEqual(exp[r], u.resource(r)[dur - 1]); | ||
| try std.testing.expectEqual(@as(Elem, 0), u.resource(r)[dur]); |
There was a problem hiding this comment.
🟡 Medium · Interior demand can be zero
When the generator writes the expected demand at the endpoints but leaves interior ticks at zero, the psplib: jobs follow the templates, scaled to cap; seeded and sequential test passes if demands are written only at the first and last active ticks, with zeros between them: lines 255-257 check those endpoints and the tick after the job, but no interior tick. It therefore accepts a non-constant job profile.
Assert the expected demand at every tick in 0..dur and zero at dur.
Prompt for AI agents
In `src/adapters/generators/psplib.zig` at lines 255-257:
**Interior demand can be zero**
When the generator writes the expected demand at the endpoints but leaves interior ticks at zero, the `psplib: jobs follow the templates, scaled to cap; seeded and sequential` test passes if demands are written only at the first and last active ticks, with zeros between them: lines 255-257 check those endpoints and the tick after the job, but no interior tick. It therefore accepts a non-constant job profile.
Assert the expected demand at every tick in `0..dur` and zero at `dur`.| env_kw = dict(ck["env"] if ck else ENV_KW) | ||
| # a policy that keeps choosing "wait" would otherwise never end the episode; | ||
| # every job has arrived long before this, so the cap does not change the workload | ||
| env_kw["max_ticks"] = env_kw.get("max_ticks") or args.max_ticks |
There was a problem hiding this comment.
🟡 Medium · Paper changes lack regression tests
When the paper tick-cap and pool-size changes are merged without dedicated tests, the new evaluation tick-cap and reporting path, and the 80-slot paper pool configuration, can regress without any test failing; existing truncation coverage exercises engine behavior, not these paper changes.
Add paper-level tests for capped evaluation and truncated reporting, and for admitting all jobs with the configured pool.
Also at paper/ptrmcts.py:61.
Prompt for AI agents
In `paper/evaluate.py` at line 149:
**Paper changes lack regression tests**
When the paper tick-cap and pool-size changes are merged without dedicated tests, the new evaluation tick-cap and reporting path, and the 80-slot paper pool configuration, can regress without any test failing; existing truncation coverage exercises engine behavior, not these paper changes.
Add paper-level tests for capped evaluation and truncated reporting, and for admitting all jobs with the configured pool.
Also at `paper/ptrmcts.py:61`.From CLAUDE.md L29-31:
- Every behavior change needs a test; integration tests in tests/. Engine
semantics: add a hand-worked case to tests/scenario_test.zig; the
`property:` test there checks against a naive reference simulator.
Follow-up to #3 (these commits landed after it was merged):
psplibusage generator (psplib:path=<.sm file or dir>): PSPLIB activities as jobs, demand / availability scaled to cap; seeded random or sequential order. Paper:train.py --psplib.paper/evaluate.py: episodes capped at--max-ticks(default 2000) with atruncatedcolumn, so a policy that keeps waiting can't hang evaluation.🤖 Generated with Claude Code
Summary by Sourcery
Support PSPLIB workloads, bounded policy evaluation, and lossless waiting pools across the simulator and paper experiments.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: