当前位置:网站首页>dflow入门5——Big step & Big parameter
dflow入门5——Big step & Big parameter
2022-08-03 08:15:00 【frank_haha】
为了梳理学习dflow时遇到的知识点,我决定开这一个系列记录自己的学习过程。当然了,最好是去看 官方教程 和 文档
本文,我们将讨论dflow的两个feature,big step 和 big parameter
big step
事实上,我们在上一节已经涉及到了Steps的一些用法
具体来说,他可以做循环、步骤重用和条件判断等等
事实上,steps还有一个潜在的用法,就是打包小的templates,实现模块化
我们来看test_big_parameter.py
import time
from dflow import InputParameter, OutputParameter, Step, Steps, Workflow
from dflow.python import (OP, OPIO, BigParameter, OPIOSign, PythonOPTemplate,
upload_packages)
if "__file__" in locals():
upload_packages.append(__file__)
class Hello:
def __init__(self, msg):
self.msg = msg
class Duplicate(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'foo': BigParameter(Hello)
})
@classmethod
def get_output_sign(cls):
return OPIOSign({
'foo': BigParameter(Hello)
})
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
foo = op_in["foo"]
print(foo.msg)
foo.msg = foo.msg * 2
op_out = OPIO({
"foo": foo
})
return op_out
首先定义了template,接收一个自定义参数,然后做一些操作
wf = Workflow(name="big-param")
steps = Steps(name="hello-steps")
steps.inputs.parameters["foo"] = InputParameter()
steps.outputs.parameters["foo"] = OutputParameter()
step1 = Step(
name="step1",
template=PythonOPTemplate(Duplicate, image="python:3.8"),
parameters={
"foo": steps.inputs.parameters["foo"]},
key="step1"
)
steps.add(step1)
step2 = Step(
name="step2",
template=PythonOPTemplate(Duplicate, image="python:3.8"),
parameters={
"foo": step1.outputs.parameters["foo"]},
key="step2"
)
steps.add(step2)
steps.outputs.parameters["foo"].value_from_parameter = \
step2.outputs.parameters["foo"]
随后定义了空的steps,两个子的step串联,再压到steps里面,最后把steps的输出定向为最后一个串联模块的输出
下面一句是它的初始化
big_step = Step(name="big-step", template=steps,
parameters={
"foo": Hello("hello")})
可以看到,big step 的初始化和普通的小step的初始化基本一致,区别在于template的参数不再是PythonOPTemplate,因为steps本身就是一个OP,直接继承了OP,和PythonOPTemplate是等价的
因此,big step 完全可以当做一个 step 去使用!!
这将有利于我们构建更长、更复杂的工作流
Big parameter
上面的例子已经提到了。Big parameter 是自定义的参数,可以丰富变量类型。让OP跟普通python函数的接轨更加顺滑。
边栏推荐
猜你喜欢

图解Kernel Device Tree(设备树)的使用

The use of the database table structure document generation tool screw

PowerShell:执行 Install-Module 时,不能从 URI 下载

HCIP练习02(OSPF)

用diskpart的offline命令弹出顽固硬盘

Shell运维开发基础(一)

mysql5.7服务器The innodb_system data file 'ibdata1' must be writable导致无法启动服务器
![[ 漏洞复现篇 ] yapi 代码执行 getshell 漏洞复现详解](/img/85/a4142689c22492cd898bd8275cd2c5.png)
[ 漏洞复现篇 ] yapi 代码执行 getshell 漏洞复现详解

WordPress主题-B2美化通用子主题商业运营版

Nacos使用实践
随机推荐
【TPC-DS】25张表的详细介绍,SQL的查询特征
Neo4j 4.X:导入OWL文件
BOM系列之localStorage
数据监控平台
unity的game界面里有canvas的线框?如何隐藏掉?
国内IT市场还有发展吗?有哪些创新好用的IT运维工具可以推荐?
服务器资源监控工具-nmon、nmon_analyser
WPS EXCEL 筛选指定长度的文本 内容 字符串
“==”和equals的区别
ArcEngine(五)用ICommand接口实现放大缩小
2022下半年软考「高项&集成」复习计划ta来喽~
DeFi明斯基时刻:压力测试与启示
HCIA实验(07)
用云机器/虚拟机架设方舟游戏?
Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
ArcEngine(二)加载地图文档
Evaluate: A detailed introduction to the introduction of huggingface evaluation indicator module
ArcEngine(一)加载矢量数据
学习笔记:机器学习之逻辑回归
Transformer、BERT、GPT 论文精读笔记