feat(ops): Deadline and StopOnSignal end a run cleanly at the next step
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 3h 50m
- Merged PRs (30d)
- 143
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jejjohnson/pipekit
-
area:code layer:0-primitives priority:p2 type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
jejjohnson/pipekit#296 ·
Maintainers usually reply within 1 day
-
area:code type:feature
Difficulty 3/5 1-2 days Newbie friendliness 57/100
jejjohnson/pipekit#411 ·
Maintainers usually reply within 1 day
-
area:code type:feature
Difficulty 4/5 3-5 days Newbie friendliness 48/100
jejjohnson/pipekit#410 ·
Maintainers usually reply within 1 day
-
area:code type:feature
Difficulty 5/5 Over a week Newbie friendliness 38/100
jejjohnson/pipekit#409 ·
Maintainers usually reply within 1 day
-
area:code type:feature
Difficulty 3/5 1-2 days Newbie friendliness 75/100
jejjohnson/pipekit#408 ·
Maintainers usually reply within 1 day
All issues in jejjohnson/pipekit
Similar issues
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorPossibly taken @jejjohnson claimed this today. Opentype:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jejjohnson/integrix#144 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
finos/ai-governance-framework#459 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
freelawproject/litigant-portal#1307 ·
Maintainers usually reply within 2 days
-
type/bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
h2oai/h2o-llmstudio#1163 ·
Maintainers usually reply within 1 day