Skip to content

Add DeepRM Packer scheduling policy - #5

Merged
dev0Guy merged 3 commits into
mainfrom
packer-policy
Nov 26, 2026
Merged

dev0Guy merged 3 commits into
mainfrom
packer-policy

Conversation

@dev0Guy

@dev0Guy dev0Guy commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

What

New policy packer, the packing baseline from DeepRM (Mao et al., HotNets'16; get_packer_action in the reference code): among the (job, machine) pairs that fit now, pick the max of

score = Σ_r free[r][now] · peak[r]

How it differs from tetris

  • no normalization by capacity² (raw product);
  • only the machine's free capacity at the current tick (the fit check still covers the job's whole duration).

With one machine it is exactly DeepRM's Packer. Ties: first machine, then oldest job. Uses PairCache like best_fit/tetris.

Tests

  • Hand-worked scenario in tests/scenario_test.zig where packer and tetris pick different machines, plus the job order packer picks and wait when nothing fits.
  • Added to the "cached pair scores give the same decision as a fresh scan" property test.

Also

Registered (--policy packer, env.policy_action("packer")), added to paper/evaluate.py, the CI smoke loop and the docs.

Paper workload, 50 seeds, avg slowdown: sjf 1.92, tetris_srpt 2.01, packer 3.30, fifo 3.34, best_fit 3.36, tetris 5.81. That matches DeepRM, where Packer trails SJF on slowdown.

🤖 Generated with Claude Code

Summary by Sourcery

Add the DeepRM Packer baseline and integrate it throughout policy execution, evaluation, testing, and documentation.

New Features:

  • Add the DeepRM Packer scheduling policy, selecting fitting job-machine pairs by current free capacity weighted by job demand.
  • Register the Packer policy across the CLI, Python evaluation, and supported policy documentation.

Bug Fixes:

  • Prevent pair-score caches from reusing stale machine timestamps across engines or resets.

CI:

  • Include the Packer policy in the CI policy smoke tests.

Documentation:

  • Document the Packer policy and its usage in the CLI, README, and Python guide.

Tests:

  • Add scenario coverage for Packer’s machine and job selection, tie handling, waiting behavior, and cache reuse.
  • Verify cached Packer decisions against fresh scans in the policy property tests.

Chores:

  • Bound MCTS episodes with a maximum tick limit to prevent policies that continually wait from hanging training.

packer: among pairs that fit now, max sum_r free[r][now] * peak[r]
(unnormalized, current tick only), as DeepRM's get_packer_action; uses
PairCache. Hand-worked scenario (differs from tetris), added to the
cache-vs-fresh-scan property test, registered, in paper eval, CI smoke
run and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Uses of the API

Include Packer in the paper evaluation's built-in policy set.

  • paper/evaluate.py L44

Implementation

Implement Packer scoring and register the policy so it can be selected and resolved by name.

  • src/adapters.zig L10
  • src/adapters/policies/packer.zig L1-47
  • src/app/registry.zig L258, L353

Make machine cache stamps globally unique so a cached policy cannot reuse stale scores across engines or resets.

  • src/model/machines.zig L132-134, L137 (removed lines), L163-166

Limit PRTMCTS training episodes to 1000 ticks to prevent policies that wait indefinitely from hanging training.

  • paper/ptrmcts.py L63-66

Configuration

Add Packer to the CI smoke-test policy matrix.

  • .github/workflows/ci.yml L39

Documentation

Document Packer in the CLI policy list and explain its scoring rule alongside the other scheduling policies.

  • docs/guide.md L40, L89

Add Packer to the documented Python built-in policy choices.

  • docs/python.md L109

List Packer among the supported policies in the README.

  • readme.md L72

Tests

Verify Packer's scoring, tie-breaking, waiting behavior, cache isolation across engines, and cached-versus-fresh decision equivalence.

  • tests/scenario_test.zig L452-503, L840

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/adapters/policies/packer.zig" line_range="40" />
<code_context>
+    }
+
+    pub fn decide(self: *Packer, st: *const model.State) model.Action {
+        self.cache.update(st, score, {}) catch @panic("packer: out of memory");
+        return self.cache.pick(st, PairCache.noPen, {});
+    }
</code_context>
<issue_to_address>
**Stale scores survive Packer reuse**

When the same Packer is reused across engine resets or separate engines with matching cached dimensions, epochs, stamps, and job IDs but changed capacities or demands, `PairCache.update` treats the matching IDs and metadata as proof that cached rows are current and skips recomputing them, so `Packer.decide` uses stale fit results or scores and returns an inferior or illegal placement, or waits despite a fitting job.

Invalidate or rebuild the `PairCache` when the engine or job state changes instead of treating matching IDs and metadata as sufficient.
</issue_to_address>

### Comment 2
<location path="src/adapters/policies/packer.zig" line_range="25" />
<code_context>
+    const mach = st.machines.get(m);
+    var acc: f32 = 0;
+    for (0..st.machines.layout.n_res) |r| {
+        acc += @as(f32, @floatFromInt(mach.resource(r)[0])) * @as(f32, @floatFromInt(peak[r]));
+    }
+    return acc;
</code_context>
<issue_to_address>
**Packer chooses a lower-scoring pair**

When fitting candidates have distinct integer dot products that round to the same `f32` value, `score` converts and accumulates the dot products as `f32`, so `PairCache.pick` treats distinct scores as tied and resolves the tie by order, selecting a pair with a lower mathematical score.

Use a score representation and accumulation that preserve distinctions between candidate integer dot products.

Also at `src/adapters/policies/packer.zig:26-27`.
</issue_to_address>

### Comment 3
<location path="tests/scenario_test.zig" line_range="488" />
<code_context>
+        _ = try sim2.place(want, 0);
+    }
+    const s3 = sim2.eng.state();
+    try testing.expect(p2.decide(&s3) == .wait);
+}
+
</code_context>
<issue_to_address>
**Wait assertion has no waiting jobs**

When the preceding placement loop has placed all three jobs, the `scenario: packer scores free-now x demand, unnormalized (DeepRM)` test places all three jobs in the preceding loop, so this assertion passes on an empty job set even if Packer incorrectly selects jobs that do not fit. It does not verify the claimed wait behavior when jobs remain but none fit.

Leave a job unplaced that cannot fit in the remaining capacity before asserting that the policy waits.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/adapters/policies/packer.zig Resolved
Comment thread src/adapters/policies/packer.zig Resolved
Comment thread tests/scenario_test.zig Resolved
dev0Guy and others added 2 commits November 25, 2026 21:24
… test

- Machines epoch/stamp now come from one process-wide counter, so a
  PairCache policy reused with another engine can't match stale scores
  (regression test: same Packer on a second engine with swapped machines).
- packer sums the dot product in u64 before converting to f32.
- packer wait assertion now has a job left that does not fit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A policy that keeps choosing wait never ended the episode, and MCTS
replay made each step slower, so training stalled after ~8 iterations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dev0Guy
dev0Guy merged commit 313c48a into main Nov 26, 2026
3 checks passed
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.

1 participant