ecFlow 变量

我们已经看到 ecFlow 使用一些变量 (variable),比如 ECF_HOMEECF_INCLUDE

共有三种变量:

  • ecFlow 使用的变量,例如 ECF_HOME
  • 用户定义的变量,不应该以 ECF 开头,推荐使用大写字母来定义变量。
  • ecFlow 生成的变量,可以在 job 中使用,例如包含 suite 的日期 ECF_DATE

Ecf脚本

之前的例子中,我们复制 t1.ecft2.ecf。 编辑这两个文件,以用户定义的变量 SLEEP 为参数调用 unix 的 sleep 命令。

  1. %include <head.h>
  2. echo "I will now sleep for %SLEEP% seconds"
  3. sleep %SLEEP%
  4. %include <tail.h>

suite definition

添加变量到 suite definition

Text

  1. # Definition of the suite test.
  2. suite test
  3. edit ECF_INCLUDE "$ECF_HOME" # replace '$ECF_HOME' with the path to your ECF_HOME directory
  4. edit ECF_HOME "$ECF_HOME"
  5. family f1
  6. task t1
  7. edit SLEEP 20
  8. task t2
  9. edit SLEEP 20
  10. endfamily
  11. endsuite

Python

  1. import os
  2. from pathlib import Path
  3. from ecflow import Defs, Suite, Task, Family, Edit
  4. def create_family_f1():
  5. return Family(
  6. "f1",
  7. Task("t1", Edit(SLEEP=20)),
  8. Task("t2", Edit(SLEEP=20)))
  9. print("Creating suite definition")
  10. home = os.path.abspath(Path(Path(__file__).parent, "../../../build/course"))
  11. defs = Defs(
  12. Suite('test',
  13. Edit(ECF_INCLUDE=home, ECF_HOME=home),
  14. create_family_f1()))
  15. print(defs)
  16. print("Checking job creation: .ecf -> .job0")
  17. print(defs.check_job_creation())
  18. print("Saving definition to file 'test.def'")
  19. defs.save_as_defs(str(Path(home, "test.def")))
  20. # To restore the definition from file 'test.def' we can use:
  21. # restored_defs = ecflow.Defs("test.def")

运行脚本:

  1. $python test.py
  2. Creating suite definition
  3. # 4.8.0
  4. suite test
  5. edit ECF_INCLUDE '/g3/wangdp/project/study/ecflow/ecflow-tutorial-code/build/course'
  6. edit ECF_HOME '/g3/wangdp/project/study/ecflow/ecflow-tutorial-code/build/course'
  7. family f1
  8. task t1
  9. edit SLEEP '20'
  10. task t2
  11. edit SLEEP '20'
  12. endfamily
  13. endsuite
  14. Checking job creation: .ecf -> .job0
  15. Saving definition to file 'test.def'

任务

  1. 修改文件
  2. 替换 suite
  3. 查看 ecflow_ui,将看到任务处于 active 状态 20 秒,查看 job output。

ecFlow 变量 - 图1