feat(ops): Deadline and StopOnSignal end a run cleanly at the next step
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start with src/pipekit_ops/operators/_flow.py and the existing Timeout, RateLimit, and Until operators; read the P8/P9 work referenced by the issue and the P10 roadmap entry. Then check the operator exports, docs/design/api/operators.md, and the tests described as G10-1 through G10-6. Done means both operators are exported, documented, tested, and P10 is marked built in the roadmap.
索引モデルが issue の本文から書いたものです。
説明
Problem / Request
pipekit-ops can bound one call (Timeout) but not a whole run, and cannot stop a run cleanly when a batch scheduler sends a signal.
This issue adds two pass-through operators, Deadline(seconds) and StopOnSignal(signals), which end the loop around them by raising Stop(resumable=True) at the next call after the budget is spent or the signal arrived.
It is phase P10 of packages/pipekit-ops/docs/design/roadmap.md.
User Story
As someone running a long simulation on a preemptible node, I want the run to stop at the next chunk edge when its wall-clock budget runs out or the scheduler sends
SIGTERM, so that the last good state is checkpointed and the run can resume.
Motivation
Two of sesmax-experiment's monitors read nothing of the model (monitor/builtins.py @ 12f169f6bf):
WatchdogMonitor(max_wall_s)starts a clock at the start of the run and stops the run, resumably, at the first chunk edge aftermax_wall_sseconds.SignalMonitor(signals=(SIGTERM, SIGINT))installs handlers at the start of the run that only note the signal, stops the run resumably at the next chunk edge, and puts the previous handlers back at the end. A handler can only be installed from the main thread, so it raisesValueErrorelsewhere.
They are the run-level partners of Timeout, which abandons one call that hangs.
Any loop on preemptible hardware needs both, so they belong next to Timeout and Until in pipekit_ops.operators.
Proposed API
# pipekit_ops/operators/_flow.py (proposed, this issue)
class Deadline(Operator):
"""Pass x through; raise Stop(resumable=True) at the first call after `seconds`.
The clock starts in open() (P9), or at the first call if never opened.
"""
def __init__(self, seconds: float, clock: Callable[[], float] = time.monotonic) -> None: ...
def _apply(self, x: Any) -> Any: ...
class StopOnSignal(Operator):
"""Pass x through; raise Stop(resumable=True) at the first call after a signal.
open() installs handlers that only note the signal; close() restores the
previous handlers. open() from any thread but the main one raises ValueError.
"""
def __init__(self, signals: Sequence[signal.Signals] = (signal.SIGTERM, signal.SIGINT)) -> None: ...
def _apply(self, x: Any) -> Any: ...
Stop is from P8 (pipekit-ops, #382): Stop(reason, carrier=None, *, resumable=False, complete=False), a BaseException.
opened and open() / close(ok) are from P9 (#384).
Design Snapshot
from pipekit_ops import Deadline, Sequential, StopOnSignal, opened
from pipekit_cycle import Cycle
step = Sequential([advance, Deadline(6 * 3600.0), StopOnSignal()])
cycle = Cycle(step_op=step, n_steps=10_000)
with opened(step):
frame, chunk = cycle(frame0, 0)
if cycle.stop is not None and cycle.stop.resumable:
write_checkpoint(frame, chunk)
The reason of the Stop names the cause: "deadline of 21600 s passed after 21604 s" or "received SIGTERM".
The carrier in the Stop is the guard's input, the frame as far as the step got; placed after advance, it is one step ahead of the state Cycle returns, which is that of the last finished step.
StopOnSignal refuses to run inside a Map thread or process worker, because handlers belong to the main thread; its docstring says to place it in the outer loop.
References & Existing Code
- Roadmap:
packages/pipekit-ops/docs/design/roadmap.md, phase P10 (merged in #374). WatchdogMonitorandSignalMonitorin sesmax-experiment, linked above.Timeout,RateLimitandUntilinpipekit_ops/operators/_flow.py@be1b64a900;RateLimithas the_clockhook to copy for tests.
Implementation Steps
- Add
DeadlineandStopOnSignalinsrc/pipekit_ops/operators/_flow.py. - Re-export them from
pipekit_ops.operatorsandpipekit_ops. - Neither stores its clock, handlers or received signal in
get_config, so a loaded copy starts fresh. - Mark P10 as built in the roadmap.
Definition of Done
- Code lands at the path above
- Public API exported via
pipekit_ops/__init__.py - Tests pass:
make test - Lint and typecheck pass:
make lint && make typecheck - Google-style docstrings; the
StopOnSignalexample sendsSIGTERMto its own process withos.kill - pipekit-ops still imports only the standard library
Testing
- G10-1: under
opened, with a fake clock that reads 0 atopen()and k s at call k,Deadline(2.5)returns its input unchanged (is) on calls 1 and 2 and raisesStopwithresumable=Trueon call 3. - G10-2: under
opened, afteros.kill(os.getpid(), signal.SIGTERM), the next call ofStopOnSignal()raisesStopwhose reason namesSIGTERM. - G10-3: after
openedexits, normally or by an exception, the handler of each signal is the one that was there before. - G10-4:
StopOnSignal().open()called from another thread raisesValueError. - G10-5: under
openedand with the clock of G10-1, aCycleof 10 steps whose step isSequential([op, Deadline(2.5)])returns the state after step 2 withcycle.stop.resumabletrue. - G10-6: both operators pass
assert_round_trip. -
Deadlinenever opened starts its clock at its first call.
Documentation
-
docs/design/api/operators.mdlists both next toTimeout, with when to use which.
Relationships
- Parent (theme epic): #379
- Blocked by: #382, #384, and #383 for gate G10-5
- Blocks: none
- Related: #381
- 主要言語
- Python
- スター
- 0
- フォーク
- 0
- 平均マージ
- 3時間 50分
- マージ済み PR(30日)
- 143
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
jejjohnson/pipekit のほかの issue
-
area:code layer:0-primitives priority:p2 type:feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jejjohnson/pipekit#296 ·
メンテナーはふだん 1 日以内に返信
-
area:code type:feature
難易度 3/5 1〜2日 初心者へのやさしさ 57/100
jejjohnson/pipekit#411 ·
メンテナーはふだん 1 日以内に返信
-
area:code type:feature
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
jejjohnson/pipekit#410 ·
メンテナーはふだん 1 日以内に返信
-
area:code type:feature
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
jejjohnson/pipekit#409 ·
メンテナーはふだん 1 日以内に返信
-
area:code type:feature
難易度 3/5 1〜2日 初心者へのやさしさ 75/100
jejjohnson/pipekit#408 ·
メンテナーはふだん 1 日以内に返信
jejjohnson/pipekit の issue をすべて見る
似ている issue
-
A JSON chat answer blocks the backend event loop for the whole RAG run対応中かも @NopeCharon が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
The-OpenROAD-Project/ORAssistant#656 ·
メンテナーはふだん 1 日以内に返信
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionError対応中かも @jejjohnson が今日担当しました。 オープンtype:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
jejjohnson/integrix#144 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
finos/ai-governance-framework#459 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信