HassamGani commited on
Commit ·
745f1df
1
Parent(s): 70e7e24
Queue side jobs get their own agents so budgets come from a parallel plan; kill window scales with simultaneous retirements
Browse files- reorgbench/gen/queue.py +13 -5
- reorgbench/metrics/score.py +3 -1
- reorgbench/oracle.py +7 -1
reorgbench/gen/queue.py
CHANGED
|
@@ -58,6 +58,16 @@ def _namespace(task: Task, ns: str) -> None:
|
|
| 58 |
task.facts = [PlantedFact(ns + f.name, f.token, f.discovered_by, f.needed_by) for f in task.facts]
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def _ledger_guard(cps: list[Checkpoint], initial: set[str]) -> Checkpoint:
|
| 62 |
allows = [c.allows for c in cps if getattr(c, "allows", None)]
|
| 63 |
|
|
@@ -70,10 +80,7 @@ def _ledger_guard(cps: list[Checkpoint], initial: set[str]) -> Checkpoint:
|
|
| 70 |
def _merge_staffing(main: list[list[str]], side: Counter) -> list[list[str]]:
|
| 71 |
out = []
|
| 72 |
for alt in main:
|
| 73 |
-
|
| 74 |
-
for r, k in side.items():
|
| 75 |
-
c[r] = max(c[r], k)
|
| 76 |
-
out.append(sorted(c.elements()))
|
| 77 |
return out
|
| 78 |
|
| 79 |
|
|
@@ -104,10 +111,11 @@ def build_queue(seed: int, attempt: int = 0) -> tuple[Task, list]:
|
|
| 104 |
gens[0].template.finish_messy(gens[0], gens[1:]) # one handbook with every job's rules
|
| 105 |
for j, t in enumerate(side, 1):
|
| 106 |
_namespace(t, f"j{j}_")
|
|
|
|
| 107 |
side_roles: Counter = Counter()
|
| 108 |
side_cps: list[Checkpoint] = []
|
| 109 |
for t in side:
|
| 110 |
-
side_roles
|
| 111 |
side_cps += t.phases[-1].checkpoints
|
| 112 |
initial = {o for o in objects if o.startswith("ledger.entries/")}
|
| 113 |
about = {id(t): g.story["subject"] for t, g in zip(tasks, gens)}
|
|
|
|
| 58 |
task.facts = [PlantedFact(ns + f.name, f.token, f.discovered_by, f.needed_by) for f in task.facts]
|
| 59 |
|
| 60 |
|
| 61 |
+
def _own_agents(task: Task, k: int) -> None:
|
| 62 |
+
"""A side job gets its own agents ("support#j2"), so the careful plan runs the jobs in parallel."""
|
| 63 |
+
lab = lambda l: f"{l.split('#')[0]}#j{k}"
|
| 64 |
+
for p in task.phases:
|
| 65 |
+
o = p.oracle
|
| 66 |
+
o.steps = {lab(l): v for l, v in o.steps.items()}
|
| 67 |
+
o.hires, o.retire, o.retire_now, o.reset = ([lab(l) for l in xs] for xs in (o.hires, o.retire, o.retire_now,
|
| 68 |
+
o.reset))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
def _ledger_guard(cps: list[Checkpoint], initial: set[str]) -> Checkpoint:
|
| 72 |
allows = [c.allows for c in cps if getattr(c, "allows", None)]
|
| 73 |
|
|
|
|
| 80 |
def _merge_staffing(main: list[list[str]], side: Counter) -> list[list[str]]:
|
| 81 |
out = []
|
| 82 |
for alt in main:
|
| 83 |
+
out.append(sorted((Counter(alt) + side).elements()))
|
|
|
|
|
|
|
|
|
|
| 84 |
return out
|
| 85 |
|
| 86 |
|
|
|
|
| 111 |
gens[0].template.finish_messy(gens[0], gens[1:]) # one handbook with every job's rules
|
| 112 |
for j, t in enumerate(side, 1):
|
| 113 |
_namespace(t, f"j{j}_")
|
| 114 |
+
_own_agents(t, j + 1)
|
| 115 |
side_roles: Counter = Counter()
|
| 116 |
side_cps: list[Checkpoint] = []
|
| 117 |
for t in side:
|
| 118 |
+
side_roles += Counter(r for st in t.phases[0].staffings[:1] for r in st)
|
| 119 |
side_cps += t.phases[-1].checkpoints
|
| 120 |
initial = {o for o in objects if o.startswith("ledger.entries/")}
|
| 121 |
about = {id(t): g.story["subject"] for t, g in zip(tasks, gens)}
|
reorgbench/metrics/score.py
CHANGED
|
@@ -147,7 +147,9 @@ def retirement(task: Task, res: EpisodeResult, g: CausalGraph) -> dict[str, Any]
|
|
| 147 |
|
| 148 |
good = [k for k in scored if fine_kill(k)]
|
| 149 |
retired = {k["payload"]["target"]: k["round"] for k in kills}
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
|
| 152 |
# handoff: planted facts a killed agent held that someone else still needed, and whether it passed them on
|
| 153 |
held = relayed = 0
|
|
|
|
| 147 |
|
| 148 |
good = [k for k in scored if fine_kill(k)]
|
| 149 |
retired = {k["payload"]["target"]: k["round"] for k in kills}
|
| 150 |
+
# one kill per round: when several agents become obsolete at the same change, the last can't go before then
|
| 151 |
+
at = {t: sum(1 for x in obsolete.values() if x == t) for t in obsolete.values()}
|
| 152 |
+
timely = [a for a, t in obsolete.items() if a in retired and retired[a] - t <= KILL_WINDOW + at[t] - 1]
|
| 153 |
|
| 154 |
# handoff: planted facts a killed agent held that someone else still needed, and whether it passed them on
|
| 155 |
held = relayed = 0
|
reorgbench/oracle.py
CHANGED
|
@@ -31,6 +31,12 @@ def role_of_label(label: str) -> str:
|
|
| 31 |
return label.split("#", 1)[0]
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def fill(value: Any, facts: dict[str, Any]) -> tuple[Any, set[str]]:
|
| 35 |
"""Substitute {fact} placeholders. A string that is exactly one placeholder keeps the fact's type."""
|
| 36 |
missing: set[str] = set()
|
|
@@ -313,7 +319,7 @@ class OracleOrchestrator:
|
|
| 313 |
self.kills = [(a, n) for a, n in self.kills if a in self.alive]
|
| 314 |
for i, (aid, now) in enumerate(self.kills):
|
| 315 |
# of several agents of one role leaving, the latest hire goes first
|
| 316 |
-
later = [a for a, _ in self.kills if self.role_of[a]
|
| 317 |
and self.alive.index(a) > self.alive.index(aid)]
|
| 318 |
if now or ((aid, self.assigned[aid]) in self.done and not later):
|
| 319 |
self.alive.remove(aid)
|
|
|
|
| 31 |
return label.split("#", 1)[0]
|
| 32 |
|
| 33 |
|
| 34 |
+
def crew_of(label: str) -> str:
|
| 35 |
+
"""Agents that are one crew of a role: "support", "support#2"... A queue's side job ("support#j2") is its own."""
|
| 36 |
+
base, _, n = label.partition("#")
|
| 37 |
+
return base if not n or n.isdigit() else label
|
| 38 |
+
|
| 39 |
+
|
| 40 |
def fill(value: Any, facts: dict[str, Any]) -> tuple[Any, set[str]]:
|
| 41 |
"""Substitute {fact} placeholders. A string that is exactly one placeholder keeps the fact's type."""
|
| 42 |
missing: set[str] = set()
|
|
|
|
| 319 |
self.kills = [(a, n) for a, n in self.kills if a in self.alive]
|
| 320 |
for i, (aid, now) in enumerate(self.kills):
|
| 321 |
# of several agents of one role leaving, the latest hire goes first
|
| 322 |
+
later = [a for a, _ in self.kills if crew_of(self.role_of[a]) == crew_of(self.role_of[aid])
|
| 323 |
and self.alive.index(a) > self.alive.index(aid)]
|
| 324 |
if now or ((aid, self.assigned[aid]) in self.done and not later):
|
| 325 |
self.alive.remove(aid)
|