Flow API
Python 파일의 flow 객체 하나가 PXFLOW Studio에서 여는 Flow 하나가 됩니다. 이어서 작성하는 input, Node, 연결과 result가 Canvas의 같은 요소로 나타납니다.
SDK 생성자는 px.Flow(...)이고, 이 생성자가 반환한 특정 Flow의 구성 작업은 flow.input(...), flow.node(...), flow.connect(...), flow.result(...)로 이어갑니다.
문법별 페이지
- SDK 생성자 ·
px.Flow(...)로 Flow 객체 만들기 - Flow 객체 메서드 ·
.input()으로 public input 만들기 - Flow 객체 메서드 ·
.node()로 Canvas Node 배치하기 - Flow 객체 메서드 ·
.connect()로 port 연결선 만들기 - Flow 객체 메서드 ·
.result()로 public result 공개하기 - Flow 객체 메서드 ·
.viewer()로 공개 결과 뷰어 연결 저장하기 - Flow 객체 메서드 ·
.group()으로 같은 Flow의 Node 묶기 - Flow 객체 메서드 ·
.subflow()로 다른 Flow 참조하기
아래 예제는 Flow 하나를 처음부터 끝까지 만드는 최소 구성입니다. 각 문법 페이지의 짧은 예제가 어떤 객체에서 이어지는지 궁금하면 이 코드를 기준으로 보세요.
from pipelinexlab import px
class UtilizationResults(px.Results):
utilization: float
@px.function(
key="calculate_utilization",
version="1.0.0",
description="Calculates demand-to-resistance utilization.",
)
def calculate_utilization(demand: float, resistance: float) -> UtilizationResults:
return UtilizationResults(utilization=demand / resistance)
flow = px.Flow(
"girder_check",
label="Girder check",
description="Checks girder demand against resistance.",
)
demand = flow.input(
"demand", float, unit="kN.m", description="Design demand."
)
resistance = flow.input(
"resistance", float, unit="kN.m", description="Design resistance."
)
check = flow.node("check", calculate_utilization)
flow.connect(demand, check.inputs.demand)
flow.connect(resistance, check.inputs.resistance)
flow.result("utilization", check.results.utilization)px.Flow
px.Flow(flow_key, *, label, description)코드와 저장 문서에서 Flow를 계속 찾을 고유한 key와 화면에 표시할 이름을 정합니다. 한 Python Flow module은 파일 최상위에 public flow 객체를 정확히 하나 둡니다. Project에 Flow가 여러 개면 Flow마다 module을 나눕니다.
flow = px.Flow(
"girder_check",
label="Girder check",
description="Checks girder demand and resistance.",
)| 값 | 용도 |
|---|---|
flow_key | source, .pxflow, SDK와 Studio가 함께 쓰는 stable key |
label | Project와 Studio에 표시할 이름 |
description | Flow가 받는 값과 만드는 결과를 설명하는 문장 |
flow.input
flow.input(port_key, ValueType, *, description, unit=None, constraints=None)Flow 밖에서 값을 받을 public input port를 만듭니다. 반환된 handle은 flow.connect(...)의 source로 사용합니다.
span = flow.input(
"span",
float,
unit="m",
description="Clear span between bearing centre-lines.",
)Studio에서는 Canvas boundary의 input으로 표시되고, Report Workbench에서는 연결 가능한 Flow input으로 표시됩니다.
flow.node
flow.node(node_key, target, *, settings=None, client=None)@px.function 또는 @px.component target을 현재 Flow의 Canvas Node로 배치합니다.
check = flow.node("utilization_check", calculate_utilization)target | Canvas 표현 | 편집 위치 |
|---|---|---|
@px.function symbol | Function Reference Node | Definitions → Functions |
imported @px.component symbol | read-only unsupported Component Node | exact target/raw settings 확인; settings UI와 Component editor는 계획 |
두 decorator의 필수 key가 저장된 target identity입니다. Python 구현 symbol 이름을 바꿔도 같은 key를 유지하면 target identity는 바뀌지 않습니다.
settings는 Component placement의 instance object를 저장합니다. @px.component(..., settings=...)가 선언한 Component는 그 선언에 대조해 값을 판정하고, 선언이 없는 기존 object는 V1 호환으로 그대로 보존합니다. input 값은 settings에 넣지 않고 flow.connect(...)로 연결합니다. host-rendered presentation은 Node presentation과 third-party UI의 contract_only V2입니다.
일반 Python def는 helper입니다. Function이 부르는 helper는 @px.function(..., helpers=[...])로 선언해 revision에 싣고, Component 구현 module 안의 helper는 module과 함께 실행됩니다. helper는 flow.node(...) target이 아니며 Canvas에 별도 Node로 나타나지 않습니다.
flow.connect
flow.connect(source, target_input)source result 또는 Flow input 하나를 Node input 하나에 연결합니다. 이 문장 한 줄은 Studio의 port 연결선 하나입니다.
flow.connect(demand, check.inputs.demand)
flow.connect(resistance, check.inputs.resistance)연결할 때 destination은 항상 node.inputs.<port_key>, Node source는 node.results.<port_key>처럼 이름 있는 port까지 선택합니다.
flow.result
flow.result(port_key, source)Node result를 Flow 밖에서 사용할 public result로 공개합니다.
flow.result("utilization", check.results.utilization)이 result는 Run 결과 화면, Report result 선택기와 승인된 App에서 같은 key로 찾습니다.
flow.group
flow.group(group_key, *, members, label=None)같은 Flow의 Node를 편집 가능한 시각적 Subflow로 묶습니다. member의 계산과 기존 연결은 그대로 유지됩니다.
service_check = flow.node("service_check", calculate_utilization)
ultimate_check = flow.node("ultimate_check", calculate_utilization)
flow.group(
"strength_checks",
members=[service_check, ultimate_check],
label="Strength checks",
)Studio에서 Group을 더블클릭하면 내부 Flow를 열어 member Node를 편집합니다.
flow.subflow
flow.subflow(subflow_key, imported_flow, *, label=None, client=None)다른 module이 소유하는 Flow를 현재 Flow에 external reference로 배치합니다.
from section_library.flows.properties import flow as section_flow
section = flow.subflow(
"section_properties",
section_flow,
label="Section properties",
)Studio에서 더블클릭하면 참조 Flow의 내부를 읽기 전용으로 보고, Edit source Flow로 원본 Project 또는 package 위치를 엽니다.