qgon.pipeline
Pipelines: chains several functions as steps and runs them.
import qgon
@qgon.pipeline.step(returns="data")def prepare(n: int = 100): return list(range(n))
@qgon.pipeline.step(returns="score")def train(data, lr: float = 0.1): return sum(data) * lr
@qgon.pipeline.pipeline(name="demo", project="Sandbox")def flow(n: int = 100, lr: float = 0.1): data = prepare(n) return train(data, lr)
result = flow(n=10) # agents on the GPU queue (default gpu) run the steps; this process runs the controllerprint(result, flow.last_run.id)- Import the modules a step function uses inside that function, because each step runs as a separate task.
- To record metrics inside a step, use
qgon.init().log(...); they go to that step's task. - For testing, call
qgon.pipeline.run_locally()first to run every step in this process, one after another, without a queue.
Pipelines built in the web app use a JSON spec. Each step clones a finished experiment, changes only its parameters and sends it to a queue.
qgon.pipeline.run_spec({"name": "training pipeline", "steps": [ {"id": "prep", "base_task": "<experiment id>"}, {"id": "train", "base_task": "<experiment id>", "params": {"Args/data": "${prep.artifacts.data.url}"}}]})# CLI: qgon pipeline --spec spec.json [--json]A script step such as {"kind": "script", "code_dir": "home/alice/proj", "entry": "prep.py", "args": [...], "params": {"out": "${a.id}"}, "env_version": 3, "task_type": "data_processing"} uploads a code folder from the controller workspace as a draft each time the pipeline starts (the same function as qgon run --draft). Its params are passed as Args/<key> for argparse.
import qgon.pipelinestep
decoratorTurns a function into a pipeline step.
step( _func: Optional[Callable] = None, *, name: Optional[str] = None, returns: Union[str, Sequence[str]] = 'result', queue: Optional[str] = None, cache: bool = False, packages: Optional[Union[str, Sequence[str]]] = None, docker: Optional[str] = None, retries: Optional[int] = None, continue_on_fail: bool = False, **engine_kwargs: Any,)Full description (Korean original)
returns- 결과 이름 (여러 개를 돌려주면 이름 목록). 결과는 다음 단계로 넘어가고 결과물로 저장된다.
queue- 이 단계를 넣을 큐 (기본: 파이프라인의 queue → gpu).
cache- True 면 코드·입력이 같을 때 이전 결과를 다시 쓴다.
packages- 단계 작업에 필요한 패키지 (기본: 자동 감지).
retries- 실패 시 다시 시도할 횟수.
engine_kwargs- 엔진(PipelineDecorator.component)에 그대로 넘긴다.
In the app · Build › Pipelines
Turns a function into a pipeline; calling it runs the pipeline and returns the last return value.
pipeline( _func: Optional[Callable] = None, *, name: str, project: str, version: Optional[str] = None, queue: Optional[str] = None, controller_queue: Optional[str] = None, abort_on_failure: bool = False, **engine_kwargs: Any,)Full description (Korean original)
name·project- 화면 'Build › 파이프라인' 에 보일 이름과 프로젝트.
queue- 단계의 기본 큐 (기본 gpu, 환경변수 QGON_QUEUE).
controller_queue- 컨트롤러를 에이전트에서 돌릴 큐, 관리자용(services 큐는 관리자 전용). 기본 None = 이 프로세스(워크스페이스)가 컨트롤러로 돈다.
abort_on_failure- True 면 한 단계가 실패할 때 나머지를 멈춘다.
engine_kwargs- 엔진(PipelineDecorator.pipeline)에 그대로 넘긴다.
실행 후 함수.last_run 으로 파이프라인 실행(id·status·url)을 볼 수 있다.
In the app · Build › Pipelines
run_locally
functionMakes pipelines started afterwards run every step in this process, one after another, without a queue (for testing).
run_locally() -> NoneIn the app · Build › Pipelines
debug
functionMakes pipelines started afterwards run steps as plain function calls without creating step tasks (for debugging).
debug() -> NoneIn the app · Build › Pipelines
PipelineRun
dataclassOne pipeline run.
PipelineRun()| Field | Type | Notes |
|---|---|---|
id | str | - |
| Member | What it does |
|---|---|
engine -> Task | The engine task object of this pipeline run, for advanced use. |
status -> str | The pipeline run's current status, read from the server. |
url -> str | Address of this pipeline run in the qgon web app; it opens this run in the pipeline run history. |
In the app · Build › Pipelines
kwargs_from_spec
functionConverts a pipeline spec into run arguments {name, project, default_queue, steps} with the steps in topological order; an invalid spec raises ValueError with a readable message.
kwargs_from_spec(spec: dict) -> Dict[str, Any]Full description (Korean original)
단계: {id, name, base_task, params{구역/이름: 값}, queue, parents(명시 + ${참조} 로 생기는 부모), condition, time_limit_min}
In the app · Build › Pipelines
Runs a pipeline from a spec and waits until it ends, with this process as the controller and the steps on queues.
run_spec( spec: dict, *, on_start: Optional[Callable[[dict], None]] = None, poll_seconds: float = 20.0, workspace: Optional[str] = None, def_id: Optional[str] = None,) -> dictFull description (Korean original)
스크립트 단계는 시작할 때마다 컨트롤러 워크스페이스의 그때 코드로 초안을 만든다(숨김 하위 프로젝트 <project>/.qgon-pipeline-steps, 태그 qgon-pipe-step). 시작에 실패하면 만든 초안·코드 묶음을 지운다. def_id(화면 파이프라인 목록의 정의 id) 가 있으면 컨트롤러 작업에 태그 qgon-pipe:<id>.
on_start({ok, task_id, project, name}): 컨트롤러 작업을 만들고 단계를 다 넣은 뒤 한 번.
poll_seconds 마다 컨트롤러 작업 상태를 보고 stopped 면(화면 '멈추기') 멈춘다. Ctrl-C·SIGTERM(KeyboardInterrupt)도 멈춘다. 둘 다 실행 중인 단계도 중단한다.
돌려줌: {done, status: completed|failed|stopped, task_id, steps:{id: completed|failed|skipped|…}}
In the app · Build › Pipelines