1- #%%
1+ # %%
22import os
3- import json
4- from typing import Dict , Any , List , Optional , Set
5- import yaml
6- from dataclasses import dataclass
7- from abc import ABC , abstractmethod
8- from prefect import flow , get_run_logger
9- from prefect .artifacts import create_markdown_artifact
10- from pydantic import BaseModel , Field , computed_field
11- from functools import cached_property
12- from typing import TypeVar , Protocol , Generic , Any , Optional , List , Union , AbstractSet , MutableMapping
133
144# from dependency_injector import containers, providers
155# from dependency_injector.wiring import Provide, inject
166import sys
177# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../' '../', '../')))
8+ from abc import abstractmethod
9+ from dataclasses import dataclass
10+ from typing import (
11+ Any ,
12+ Generic ,
13+ Protocol ,
14+ TypeVar ,
15+ )
16+
17+ from pydantic import BaseModel
18+
19+ sys .path .insert (
20+ 0 , os .path .abspath (os .path .join (os .path .dirname (__file__ ), "../" "../" , "../" ))
21+ )
1822# from dpti.workflows.service.service_container import WorkflowContainer, WorkflowServices
1923from dpti .workflows .service .workflow_decorator import workflow_task_decorator
20- from dpti .workflows .service .workflow_service_module import WorkflowServiceModule
21- from dpti .workflows .service .workflow_service_module import WorkflowServices , BasicWorkflowServices
22-
23- from dpti .workflows .simulations .base import SettingsBase , FlowRuntimeContext , FlowMetaInfo , FlowProcedureControl
24+ from dpti .workflows .service .workflow_service_module import (
25+ WorkflowServices ,
26+ )
27+ from dpti .workflows .simulations .base import (
28+ FlowMetaInfo ,
29+ FlowProcedureControl ,
30+ FlowRuntimeContext ,
31+ )
2432
25-
26- #%%
33+ # %%
2734
2835# WorkflowSettingsType = TypeVar('WorkflowSettingsType')
2936
3340# flow_run_number: int
3441
3542
36-
3743# class WorkflowSettings(BaseModel):
3844# config_yaml: str
3945# flow_trigger_dir: str
@@ -67,33 +73,31 @@ class FlowTriggerInfo:
6773 flow_trigger_dir : str
6874
6975
70-
7176class workflow_context (BaseModel ):
7277 flow_meta_info : FlowMetaInfo
7378 flow_trigger_info : FlowTriggerInfo
7479 # workflow_services: WorkflowServices # Protocol 类型
7580 flow_procedure_control : FlowProcedureControl
76-
81+
7782 # model_config = {
7883 # "arbitrary_types_allowed": True # 允许任意类型
7984 # }
80-
81- # flow_params
8285
8386
87+ # flow_params
8488
85- DomainInputType = TypeVar ('DomainInputType' , bound = BaseModel )
8689
90+ DomainInputType = TypeVar ("DomainInputType" , bound = BaseModel )
8791
8892
8993class WorkflowSettingsModel (Protocol ):
90- """需要满足的最小接口要求"""
94+ """需要满足的最小接口要求."""
95+
9196 flow_trigger_info : FlowTriggerInfo
9297 flow_procedure_control : FlowProcedureControl
9398 domain_input_raw : BaseModel
9499
95100
96-
97101class BaseWorkflow (Generic [DomainInputType ]):
98102 workflow_services : WorkflowServices
99103 flow_trigger_dir : str
@@ -104,40 +108,38 @@ class BaseWorkflow(Generic[DomainInputType]):
104108 flow_run_number : int = 0
105109 # @inject
106110 # def __init__(self, workflow_services:WorkflowServices=Provide[WorkflowContainer.workflow_services]):
107- # """初始化工作流应用flow装饰器"""
108- # 应用flow装饰器
109- # self.workflow_services = workflow_services
110-
111+ # """初始化工作流应用flow装饰器"""
112+ # 应用flow装饰器
113+ # self.workflow_services = workflow_services
114+
111115 # def init_workflow_services(self, workflow_services:WorkflowServices):
112116 # self.workflow_services = workflow_services
113117
114- # self.flow_object = flow(
115- # name=f"{self.__class__.__name__}Flow",
116- # # flow_run_name=,
117- # log_prints=True,
118- # persist_result=True
119- # )(self.execute_flow)
120-
121-
122-
118+ # self.flow_object = flow(
119+ # name=f"{self.__class__.__name__}Flow",
120+ # # flow_run_name=,
121+ # log_prints=True,
122+ # persist_result=True
123+ # )(self.execute_flow)
123124
124125 # def __call__(self, flow_params: WorkflowSettingsModel) -> Any:
125126 # """执行工作流"""
126127 # r = self.execute_flow(flow_params=flow_params)
127128 # return r
128129
129-
130130 @workflow_task_decorator
131131 def flow_start_check (self ):
132132 flow_trigger_dir = self .flow_trigger_dir
133133 flow_run_number = self .flow_run_number
134134
135135 # config_yaml = self.flow_params.domain_params.config_yaml
136-
136+
137137 io_handler = self .workflow_services .io_handler
138138
139139 self .check_if_flow_trigger_dir_exists ()
140- produced_flow_running_dir = self .workflow_services .io_handler .setup_flow_running_dir ()
140+ produced_flow_running_dir = (
141+ self .workflow_services .io_handler .setup_flow_running_dir ()
142+ )
141143 # io_handler.create_job_dir()
142144
143145 return produced_flow_running_dir
@@ -151,23 +153,21 @@ def check_if_flow_trigger_dir_exists(self):
151153
152154 # def check_if_config_yaml_exists(self, io_handler: IOHandler):
153155 # pass
154-
156+
155157 def execute_flow (self ) -> Any :
156- """执行工作流"""
158+ """执行工作流. """
157159 r = self ._execute_impl ()
158160 return r
159-
161+
160162 @abstractmethod
161163 def _execute_impl (self ) -> Any :
162- """执行工作流"""
164+ """执行工作流. """
163165 pass
164166
165-
166-
167-
168167 # @abstractmethod
169168 # def _execute_impl(self, domain_input_raw: DomainInputRawType) -> Any:
170169 # """执行工作流"""
171170 # pass
172171
173- #%%
172+
173+ # %%
0 commit comments