espnet3.bin.atlas.core.scheduler.AtlasGraphRuntime
espnet3.bin.atlas.core.scheduler.AtlasGraphRuntime
class espnet3.bin.atlas.core.scheduler.AtlasGraphRuntime(study_dir: Path, recipe_dir: Path, config, graph, state, trial_resources_default, agent)
Bases: object
Drives one study’s graph: runs/schedules nodes, submits jobs, tracks budget.
Built once per init/run/worker invocation via _load_runtime and shared by all of a study’s cmd_* commands and the standalone worker entry point.
Build the runtime from an already-loaded config/graph/state.
- Parameters:
- study_dir – Study’s root directory.
- recipe_dir – Recipe root directory.
- config – The study’s resolved
atlas.yamlconfig. - graph – The study’s loaded
ResearchGraph. - state – The study’s
StateStore. - trial_resources_default – Default
Resourcesfor trial jobs, merged per-node with each node’s ownresources. - agent – The raw coding-agent client (e.g.
CliAgent); wrapped here in aStudySessionAgentClientfor session reuse.
get_bootstrap_node_name() → str
Pick the first node to run for a study with no node runs yet.
A study whose knowledge pack already exists skips the setup node and starts at propose_trial; any other study starts at the graph’s declared start node.
- Returns: The node name to create the first node run for.
- Return type: str
Example
>>> runtime.get_bootstrap_node_name()
'research_context'get_gpu_monitor_interval_sec() → int
Return how often a GPU job’s self-controller polls its trial, in seconds.
This is atlas.tick_interval_sec_trial_active (default 600), with a floor of 1 second.
- Returns: Poll interval in seconds, at least 1.
- Return type: int
Example
>>> runtime.get_gpu_monitor_interval_sec()
600reconcile_tick_jobs(exclude_job_id: str | None = None) → None
Repair recorded controller-tick job statuses via the submission agent.
A tick job that died (crash, walltime, cancellation) can stay recorded as active, which would stop a replacement controller from being submitted. This asks the agent for the real state of every active tick job and updates the record. Unlike trial jobs, a tick job reaching a terminal state triggers no trial reconciliation. unknown answers and agent failures leave the record unchanged.
- Parameters:exclude_job_id – A tick job to skip, normally the caller’s own job, which is running by definition.
run_gpu_self_controller(node_name: str, run_id: str, trial_id: str | None = None, attempt_id: str | None = None) → StageResult
Finish a trial and advance its local graph nodes inside the GPU job.
Runs node_name as usual, then — since in this mode the trial’s own GPU job is acting as its controller rather than being observed externally — marks that job’s own record completed/failed itself, and submits any now-pending trial nodes.
- Parameters:
- node_name – Graph node to run (typically
run_trialfinishing). - run_id – This node run’s unique id.
- trial_id – Trial the node operates on, or
None. - attempt_id – Attempt id within this node run, or
Noneto default to"attempt_000000".
- node_name – Graph node to run (typically
- Returns: The stage’s result, as from
run_node(). - Return type:StageResult
Example
>>> result = runtime.run_gpu_self_controller(
... "run_trial", run_id="run_1", trial_id="trial_001"
... )run_node(node_name: str, run_id: str, trial_id: str | None = None, attempt_id: str | None = None, controller_mode: bool = False, gpu_self_controller: bool = False) → StageResult
Execute one graph node’s stage and, in controller mode, route to the next.
Builds the node’s StageContext (wrapping the agent with _SkillAgent if the node declares a skill), records node_started/node_finished events, runs the stage (catching InvalidAgentResponseError into a failure result instead of propagating it), and — unless the result reports an invalid agent response — calls _schedule_next() to advance the graph.
- Parameters:
- node_name – Graph node to run.
- run_id – This node run’s unique id.
- trial_id – Trial the node operates on, or
Nonefor a study-level node. - attempt_id – Attempt id within this node run; defaults to
"attempt_000000"whenNone. - controller_mode – Whether this call is itself acting as the controller (so
_schedule_next()may recurse into the next local node immediately). - gpu_self_controller – Whether this run is executing inside a GPU job acting as its own controller.
- Returns: The stage’s result.
- Return type:StageResult
Example
>>> result = runtime.run_node("propose_trial", run_id="run_1")
>>> result.status
'success'should_stop() → bool
Return whether the controller should stop scheduling study work.
- Parameters:None – This method reads the configured study and its persisted state.
- Returns: True when a stop request, completed study, or budget limit applies.
- Return type: bool
Example
>>> runtime.should_stop()
Falsesubmit_job(, job_id: str, job_type: str, name: str, command: list[str], workdir: Path, stdout: Path, stderr: Path, resources: Resources, env: dict[str, str] | None = None, metadata: dict | None = None, trial_id: str | None = None, node_run_id: str | None = None) → JobRecord
Delegate one asynchronous job submission to the configured agent.
Asks the configured submission agent (Slurm, local, or custom) to launch command with the given resources/environment, then persists a JobRecord for it in state.
- Parameters:
- job_id – Atlas-assigned id for this job.
- job_type – Kind of job, e.g.
"trial"or"tick". - name – Human-readable job name (e.g. shown in
squeue). - command – Argv to run.
- workdir – Working directory for the job.
- stdout – Path to redirect stdout to.
- stderr – Path to redirect stderr to.
- resources – Resource limits to request.
- env – Extra environment variables for the job process, or
None. - metadata – Extra metadata recorded alongside the job, or
None. - trial_id – Trial this job belongs to, or
Nonefor a study-level job. - node_run_id – Graph node run this job executes, or
None.
- Returns: The persisted job record, including its backend and backend-native
external_id. - Return type:JobRecord
- Raises:RuntimeError – If the agent reports the submission did not succeed (no
"submitted"status or missingexternal_id).
Example
>>> job = runtime.submit_job(
... job_id="job_1", job_type="trial", name="ar-study-trial-0001",
... command=["python", "worker.py"], workdir=Path("."),
... stdout=Path("out.log"), stderr=Path("err.log"),
... resources=Resources(gpus=1),
... )
>>> job.status
'submitted'tick(trial_id: str | None = None) → None
Run one scheduler cycle: bootstrap, reconcile jobs, advance.
Bootstraps the study’s first node run if none exist yet, refreshes active job statuses (reconciling any that finished), schedules new parallel proposals and submits pending submission-execution nodes (only for a whole-study tick, i.e. trial_id is None), and advances any pending local-execution nodes. No-ops entirely if the study’s STOP file exists.
- Parameters:trial_id – If given, scope the refresh/local-node work to this trial only (used by a GPU self-controller acting for just its own trial);
Noneruns the full study-wide tick. - Returns: None.
Example
>>> runtime.tick()