You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

watchpoint_handler.py 24 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Define the watchpoint stream handler."""
  16. from mindinsight.conditionmgr.condition import ValueTypeEnum
  17. from mindinsight.debugger.common.exceptions.exceptions import DebuggerParamValueError, \
  18. DebuggerParamTypeError
  19. from mindinsight.debugger.common.log import LOGGER as log
  20. from mindinsight.debugger.common.utils import is_scope_type
  21. from mindinsight.debugger.proto.debug_grpc_pb2 import SetCMD
  22. from mindinsight.debugger.stream_cache.watchpoint import Watchpoint, WatchpointHit, \
  23. WatchNodeTree
  24. from mindinsight.debugger.stream_handler.base_handler import StreamHandlerBase
  25. class WatchpointHandler(StreamHandlerBase):
  26. """Watchpoint Handler."""
  27. def __init__(self):
  28. self._watchpoints = {}
  29. # list of ids of new created watchpoints
  30. self._created_watchpoints = []
  31. # list of SetCMD of watchpoints to be deleted
  32. self._deleted_watchpoints = []
  33. # dict of <id, SetCMD> of watchpoint to be updated
  34. self._updated_watchpoints = {}
  35. # the collection of watched node full names, which have been sent to MindSpore
  36. self._all_watched_node_full_names = set()
  37. # the collection of new watched node full names, which have not been sent to MindSpore
  38. self._new_watched_node_full_names = set()
  39. # record the temp stored nodes in MS, which could be set as watch node for recheck on GPU
  40. # should be clean at the beginning of each step
  41. self._temp_cached_node_full_names = set()
  42. self._latest_id = 0
  43. self._cache_set_cmd = {}
  44. def put(self, value):
  45. """
  46. Put Watchpoint into watchpoint handler.
  47. Args:
  48. value (Watchpoint): The name of nodes that have been chosen.
  49. """
  50. new_id = value.watchpoint_id
  51. self._watchpoints[new_id] = value
  52. self._created_watchpoints.append(new_id)
  53. self._updated_watchpoints[new_id] = value
  54. self._latest_id = new_id
  55. log.debug("Put watchpoint %d into cache.", new_id)
  56. def clean_temp_cached_names(self):
  57. """Clean temp cached node."""
  58. self._temp_cached_node_full_names.clear()
  59. def add_temp_cached_name(self, node_full_name):
  60. """Add temp stored node in cache."""
  61. if node_full_name:
  62. self._temp_cached_node_full_names.add(node_full_name)
  63. def sync_set_cmd(self, set_cmds):
  64. """Clean temp watchpoints."""
  65. self._new_watched_node_full_names = set()
  66. self._created_watchpoints = []
  67. self._deleted_watchpoints = []
  68. self._updated_watchpoints = {}
  69. for set_cmd in set_cmds:
  70. self._cache_set_cmd[set_cmd.id] = set_cmd
  71. def clean_cache_set_cmd(self, set_cmd):
  72. """Clean cache set command."""
  73. self._cache_set_cmd.pop(set_cmd.id, None)
  74. def get_watchpoint_by_id(self, watchpoint_id):
  75. """Get watchpoint by watchpoint id."""
  76. res = self.get(watchpoint_id)
  77. watchpoint = res.get('watch_points')[0]
  78. return watchpoint
  79. def get(self, filter_condition=None):
  80. """
  81. Get the watchpoints.
  82. Args:
  83. filter_condition (Union[None, int]): The filter conditions. Get watchpoint by
  84. id. If None, return all watchpoint. Default: None.
  85. Returns:
  86. dict, the watchpoint list.
  87. """
  88. reply = []
  89. if not filter_condition:
  90. # get watch condition list
  91. for _, watchpoint in self._watchpoints.items():
  92. watchpoint_info = watchpoint.get_watch_condition_info()
  93. reply.append(watchpoint_info)
  94. else:
  95. self.validate_watchpoint_id(filter_condition)
  96. reply = [self._watchpoints.get(filter_condition)]
  97. log.debug("get the watch points with filter_condition:%s", filter_condition)
  98. return {'watch_points': reply}
  99. def get_pending_commands(self, graph_stream):
  100. """
  101. Get all watchpoint in SetCMD proto format.
  102. Args:
  103. graph_stream (GraphHandler): Graph handler.
  104. Returns:
  105. list[SetCMD], updated watchpoint to be sent to MindSpore.
  106. """
  107. res = []
  108. new_watched_nodes = set()
  109. self._all_watched_node_full_names.clear()
  110. for _, watchpoint in self._updated_watchpoints.items():
  111. # construct set command with leaf nodes
  112. watch_nodes = watchpoint.get_watch_nodes()
  113. leaf_watch_nodes = self._expand_to_leaf_nodes(graph_stream, watch_nodes)
  114. res.append(watchpoint.get_pending_cmd(leaf_watch_nodes))
  115. # update all watched node names
  116. watch_node_names = [watch_node.full_name for watch_node in [*watch_nodes, *leaf_watch_nodes]]
  117. new_watched_nodes.update(watch_node_names)
  118. res.extend(self._deleted_watchpoints)
  119. for _, set_cmd in self._cache_set_cmd.items():
  120. res.append(set_cmd)
  121. self._all_watched_node_full_names = new_watched_nodes
  122. return res
  123. @staticmethod
  124. def _expand_to_leaf_nodes(graph_stream, watch_nodes):
  125. """
  126. Get all leaf node basic info according to watch nodes.
  127. Args:
  128. graph_stream (GraphHandler): Graph handler.
  129. watch_nodes (list[NodeBasicInfo]): The list of watch node basic infos.
  130. Returns:
  131. list[NodeBasicInfo], expanded leaf basic node infos.
  132. """
  133. leaf_watch_nodes = []
  134. for node in watch_nodes:
  135. if is_scope_type(node.type):
  136. pure_node_name = None
  137. if len(node.name.split('/')) > 1:
  138. graph_name, pure_node_name = node.name.split('/', 1)
  139. else:
  140. graph_name = node.name
  141. search_node_infos = graph_stream.get_node_basic_info_by_scope(pure_node_name, graph_name=graph_name)
  142. leaf_watch_nodes.extend(search_node_infos)
  143. else:
  144. leaf_watch_nodes.append(node)
  145. return leaf_watch_nodes
  146. def is_recheckable(self, backend=None):
  147. """
  148. Check if current status is able to recheck.
  149. Args:
  150. backend (str): The backend info. 'Ascend' or 'GPU'. Default: None.
  151. Returns:
  152. bool, if enable to recheck.
  153. """
  154. enable_recheck = bool(self._updated_watchpoints or self._deleted_watchpoints)
  155. if backend == 'GPU' and enable_recheck:
  156. # on GPU, disable to recheck if there are new watched node of which the tensor
  157. # has not been stored on MindSpore
  158. diff_set = self._new_watched_node_full_names - self._all_watched_node_full_names
  159. enable_recheck = not diff_set or diff_set.issubset(self._temp_cached_node_full_names)
  160. return enable_recheck
  161. def set_watch_nodes(self, graph, graph_stream, watch_point_id, graph_name=None):
  162. """
  163. set watch nodes for graph.
  164. Args:
  165. graph (dict): The graph with list of nodes.
  166. graph_stream (GraphHandler): The graph handler.
  167. watch_point_id (int): The id of watchpoint.
  168. graph_name (str): The graph name.
  169. """
  170. if not (watch_point_id and graph):
  171. return
  172. log.debug("add watch flags")
  173. watchpoint = self._watchpoints.get(watch_point_id)
  174. self._set_watch_status_recursively(graph, graph_stream, watchpoint, graph_name)
  175. def _set_watch_status_recursively(self, graph, graph_stream, watchpoint, graph_name=None):
  176. """Set watch status to graph."""
  177. if graph.get('children'):
  178. self._set_watch_status_recursively(
  179. graph.get('children'), graph_stream, watchpoint, graph_name)
  180. if graph.get('nodes'):
  181. _ = self._set_watch_state_for_nodes(graph['nodes'], graph_stream, watchpoint, graph_name)
  182. def _set_watch_state_for_nodes(self, nodes, graph_stream, watchpoint, graph_name):
  183. """
  184. Set watch state for nodes.
  185. Args:
  186. nodes (list[Node]): List of node info.
  187. Returns:
  188. int, the number of all watched nodes.
  189. """
  190. all_watched_num = 0
  191. for node in nodes:
  192. node_name = node.get('name')
  193. # search result could have `nodes` in nodes object
  194. if node.get('nodes'):
  195. flag = self._set_watch_state_for_nodes(node.get('nodes'), graph_stream, watchpoint, graph_name)
  196. else:
  197. full_name = graph_stream.get_full_name(node_name, graph_name)
  198. new_node_name = node_name if graph_name is None else '/'.join([graph_name, node_name])
  199. flag = watchpoint.get_node_status(new_node_name, node.get('type'), full_name)
  200. node['watched'] = flag
  201. if flag == WatchNodeTree.TOTAL_WATCH:
  202. all_watched_num += 1
  203. # calculate the state of current node.
  204. if not all_watched_num:
  205. state = WatchNodeTree.NOT_WATCH
  206. elif all_watched_num == len(nodes):
  207. state = WatchNodeTree.TOTAL_WATCH
  208. else:
  209. state = WatchNodeTree.PARTIAL_WATCH
  210. return state
  211. def create_watchpoint(self, condition_mgr, watch_condition, watch_nodes=None, watch_point_id=None):
  212. """
  213. Create watchpoint.
  214. Args:
  215. condition_mgr (ConditionMgr): Instance of ConditionMgr.
  216. watch_condition (dict): The watch condition.
  217. "condition": {
  218. id: "tensor_too_large",
  219. "params": [
  220. {
  221. "name": "abs_mean_gt",
  222. "disable": false,
  223. "value": 1.1
  224. }
  225. ]
  226. }
  227. - id (str): Id of condition.
  228. - param (list[dict]): The list of param for this condition.
  229. watch_nodes (list[NodeBasicInfo]): The list of node basic info.
  230. watch_point_id (int): The id of watchpoint.
  231. Returns:
  232. int, the new id of watchpoint.
  233. """
  234. validate_watch_condition(condition_mgr, watch_condition)
  235. watch_condition = set_default_param(condition_mgr, watch_condition)
  236. new_id = self._latest_id + 1
  237. watchpoint = Watchpoint(new_id, watch_condition)
  238. if watch_nodes:
  239. watchpoint.add_nodes(watch_nodes)
  240. self._add_watch_node_in_cache(watch_nodes)
  241. elif watch_point_id:
  242. self.validate_watchpoint_id(watch_point_id)
  243. watchpoint.copy_nodes_from(self._watchpoints.get(watch_point_id))
  244. self.put(watchpoint)
  245. return new_id
  246. def update_watchpoint(self, watch_point_id, watch_nodes, watched=False):
  247. """
  248. Update watchpoint.
  249. Args:
  250. watch_point_id (int): The id of watchpoint.
  251. watch_nodes (list[NodeBasicInfo]): The list of node basic info.
  252. watched (bool): The update operator on nodes. If False, remove nodes from watch nodes.
  253. If True, add nodes to watch nodes. Default: False.
  254. """
  255. self.validate_watchpoint_id(watch_point_id)
  256. watchpoint = self._watchpoints.get(watch_point_id)
  257. if watched:
  258. watchpoint.add_nodes(watch_nodes)
  259. self._add_watch_node_in_cache(watch_nodes)
  260. else:
  261. watchpoint.remove_nodes(watch_nodes)
  262. self._remove_watch_node_from_cache(watch_nodes)
  263. self._updated_watchpoints[watch_point_id] = watchpoint
  264. log.debug("Update watchpoint %d in cache.", watch_point_id)
  265. def delete_watchpoint(self, watch_point_id=None):
  266. """
  267. Delete watchpoint.
  268. Args:
  269. watch_point_id (Union[None, int]): The id of watchpoint.
  270. If None, delete all watchpoints. Default: None.
  271. """
  272. if watch_point_id is None:
  273. watch_point_ids = [sub_id for sub_id, _ in self._watchpoints.items()]
  274. else:
  275. self.validate_watchpoint_id(watch_point_id)
  276. watch_point_ids = [watch_point_id]
  277. for single_id in watch_point_ids:
  278. self._delete_single_watchpoint(single_id)
  279. def _delete_single_watchpoint(self, watch_point_id):
  280. """
  281. Delete single watchpoint.
  282. Args:
  283. watch_point_id (int): The id of watchpoint.
  284. """
  285. self._watchpoints.pop(watch_point_id)
  286. # if the watchpoint has not been created by MindSpore, clean the relative cache directly
  287. if watch_point_id in self._created_watchpoints:
  288. self._created_watchpoints.remove(watch_point_id)
  289. self._updated_watchpoints.pop(watch_point_id)
  290. log.debug("Cancel create watchpoint %d in cache.", watch_point_id)
  291. return
  292. set_cmd = SetCMD()
  293. set_cmd.id = watch_point_id
  294. set_cmd.delete = True
  295. self._deleted_watchpoints.append(set_cmd)
  296. log.debug("Delete watchpoint %d in cache.", watch_point_id)
  297. def validate_watchpoint_id(self, watch_point_id):
  298. """Validate watchpoint id."""
  299. if not isinstance(watch_point_id, int):
  300. log.error("Invalid watchpoint id %s. The watch point id should be int.", watch_point_id)
  301. raise DebuggerParamTypeError("Watchpoint id should be int type.")
  302. if watch_point_id and watch_point_id not in self._watchpoints:
  303. log.error("Invalid watchpoint id: %d.", watch_point_id)
  304. raise DebuggerParamValueError("Invalid watchpoint id: {}".format(watch_point_id))
  305. def _add_watch_node_in_cache(self, watch_nodes):
  306. """
  307. Add watch nodes in cache.
  308. Args:
  309. watch_nodes (list[NodeBasicInfo]): The list of node basic info.
  310. """
  311. node_full_names = [node.full_name for node in watch_nodes]
  312. self._new_watched_node_full_names.update(node_full_names)
  313. def _remove_watch_node_from_cache(self, watch_nodes):
  314. """
  315. Remove watch nodes from cache.
  316. Args:
  317. watch_nodes (list[NodeBasicInfo]): The list of node basic info.
  318. """
  319. for node in watch_nodes:
  320. if node.full_name in self._new_watched_node_full_names:
  321. self._new_watched_node_full_names.remove(node.full_name)
  322. class WatchpointHitHandler(StreamHandlerBase):
  323. """Watchpoint hit handler."""
  324. def __init__(self):
  325. # dict of <ui node_name, dict of <slot, WatchpointHit>>,
  326. self._hits = {}
  327. @property
  328. def empty(self):
  329. """Whether the watchpoint hit is empty."""
  330. return not self._hits
  331. def put(self, value):
  332. """
  333. Put value into watchpoint hit cache. Called by grpc server.
  334. Args:
  335. value (dict): The watchpoint hit info.
  336. - tensor_proto (TensorProto): The message about hit tensor.
  337. - watchpoint (Watchpoint): The Watchpoint that a node hit.
  338. - node_name (str): The UI node name.
  339. - graph_name (str): The graph name.
  340. """
  341. watchpoint_hit = WatchpointHit(
  342. tensor_proto=value.get('tensor_proto'),
  343. watchpoint=value.get('watchpoint'),
  344. node_name=value.get('node_name'),
  345. graph_name=value.get('graph_name')
  346. )
  347. # get all hit watchpoints according to node name ans tensor slot
  348. watchpoint_hits = self._get_watchpoints_by_tensor_name(watchpoint_hit.node_name,
  349. watchpoint_hit.slot)
  350. if watchpoint_hit not in watchpoint_hits:
  351. watchpoint_hits.append(watchpoint_hit)
  352. def _get_watchpoints_by_tensor_name(self, node_name, slot):
  353. """
  354. Get hit tensors according to ui node name and slot.
  355. Args:
  356. node_name (str): The node name.
  357. slot (str): The tensor slot.
  358. Returns:
  359. list, list of watchpoints.
  360. """
  361. hit_node = self._hits.get(node_name)
  362. if hit_node is None:
  363. hit_node = {}
  364. self._hits[node_name] = hit_node
  365. hit_tensors = hit_node.get(slot)
  366. if hit_tensors is None:
  367. hit_tensors = []
  368. hit_node[slot] = hit_tensors
  369. return hit_tensors
  370. def get(self, filter_condition=None):
  371. """
  372. Get watchpoint hit list.
  373. Args:
  374. filter_condition (str): Get the watchpoint hit according to specified node name.
  375. If not given, get all watchpoint hits. Default: None.
  376. Returns:
  377. dict, the watchpoint hit list.
  378. """
  379. if filter_condition is None:
  380. log.debug("Get all watchpoint hit list.")
  381. reply = self.get_watchpoint_hits()
  382. else:
  383. log.debug("Get the watchpoint for node: <%s>.", filter_condition)
  384. reply = self._hits.get(filter_condition)
  385. return reply
  386. def get_watchpoint_hits(self):
  387. """Return the list of watchpoint hits."""
  388. watch_point_hits = []
  389. for node_name, watchpoint_hits in self._hits.items():
  390. tensors = []
  391. graph_name = None
  392. for slot, tensor_hits in watchpoint_hits.items():
  393. if graph_name is None:
  394. graph_name = tensor_hits[0].graph_name
  395. tensor_info = self._get_tensor_hit_info(slot, tensor_hits)
  396. tensors.append(tensor_info)
  397. watch_point_hits.append({
  398. 'node_name': node_name,
  399. 'tensors': tensors,
  400. 'graph_name': graph_name
  401. })
  402. return {'watch_point_hits': watch_point_hits}
  403. @staticmethod
  404. def _get_tensor_hit_info(slot, tensor_hits):
  405. """
  406. Get watchpoint hit info of specified tensor.
  407. Args:
  408. slot (str): Slot id.
  409. tensor_hits (list): A list of watchpoint hit objects that the tensor hit.
  410. Returns:
  411. dict, tensor hit info.
  412. """
  413. res = {}
  414. watch_points = [tensor_hit.watchpoint for tensor_hit in tensor_hits]
  415. if watch_points:
  416. res = {
  417. 'slot': slot,
  418. 'watch_points': watch_points
  419. }
  420. return res
  421. def _is_tensor_hit(self, tensor_name):
  422. """
  423. Check if the tensor is record in hit cache.
  424. Args:
  425. tensor_name (str): The name of ui tensor name.
  426. Returns:
  427. bool, if the tensor is hit.
  428. """
  429. node_name, slot = tensor_name.rsplit(':', 1)
  430. watchpoint_hits = self._hits.get(node_name, {}).get(slot)
  431. return bool(watchpoint_hits)
  432. def update_tensor_history(self, tensor_history):
  433. """
  434. Add hit flag to tensor history.
  435. Args:
  436. tensor_history (dict): The tensor history.
  437. """
  438. if not self._hits:
  439. return
  440. # add hit tensor names to `tensor_names`
  441. for tensor_info in tensor_history.get('tensor_history'):
  442. tensor_name = tensor_info['name']
  443. hit_flag = self._is_tensor_hit(tensor_name)
  444. tensor_info['is_hit'] = hit_flag
  445. def get_tensor_hit_infos(self, tensor_name):
  446. """
  447. Get all hit information of a tensor.
  448. Args:
  449. tensor_name (str): Tensor name showed on UI.
  450. Returns:
  451. dict, tensor hit info.
  452. """
  453. tensor_hit_info = {}
  454. if self._is_tensor_hit(tensor_name):
  455. node_name, slot = tensor_name.rsplit(':', 1)
  456. tensor_hits = self._get_watchpoints_by_tensor_name(node_name, slot)
  457. tensor_hit_info = self._get_tensor_hit_info(slot, tensor_hits)
  458. return tensor_hit_info
  459. def validate_watch_condition(condition_mgr, watch_condition):
  460. """Validate watch condition."""
  461. if not isinstance(watch_condition, dict):
  462. log.error("<watch_condition> should be dict. %s received.", watch_condition)
  463. raise DebuggerParamTypeError("<watch_condition> should be dict.")
  464. # validate condition_id
  465. condition_id = watch_condition.get('id')
  466. if condition_id not in condition_mgr.conditions.keys():
  467. log.error("Invalid watch condition. Acceptable values are <%s>. %s received.",
  468. str(condition_mgr.conditions.keys()), condition_id)
  469. raise DebuggerParamValueError("Invalid watch condition value.")
  470. # validate param
  471. validate_watch_condition_params(condition_mgr, watch_condition)
  472. def validate_watch_condition_params(condition_mgr, watch_condition):
  473. """
  474. Validate watch condition parameters.
  475. Args:
  476. condition_mgr (ConditionMgr): Instance of ConditionMgr.
  477. watch_condition (dict): Watch condition.
  478. - id (str): Condition id. Should be in WATCHPOINT_CONDITION_MAPPING.
  479. - param (list): Condition value. Should be given for comparison condition. The value
  480. will be translated to np.float32.
  481. """
  482. condition_id = watch_condition.get('id')
  483. params = watch_condition.get('params')
  484. condition = condition_mgr.get_condition(condition_id)
  485. if condition_id in condition_mgr.get_no_param_condition():
  486. if params:
  487. log.error("No param is expected for %s condition", condition_id)
  488. raise DebuggerParamValueError("No param is expected.")
  489. return
  490. for param in params:
  491. condition_param_name = param.get("name")
  492. if condition_param_name not in condition.names:
  493. log.error("Invalid name of parameter for condition: %s, available values: %s",
  494. condition_id, condition.names)
  495. raise DebuggerParamValueError("Invalid name of parameter.")
  496. condition_param = condition.get_parameter_definition(condition_param_name)
  497. if condition_param.type.name in (ValueTypeEnum.FLOAT64.name, ValueTypeEnum.INT64.name) \
  498. and not isinstance(param.get("value"), (float, int)):
  499. log.error("Number param should be given for condition: %s", condition_id)
  500. raise DebuggerParamValueError("Number param should be given.")
  501. if condition_param.type.name == ValueTypeEnum.BOOL.name \
  502. and not isinstance(param.get("value"), bool):
  503. log.error("Bool param should be given for condition: %s", condition_id)
  504. raise DebuggerParamValueError("Bool param should be given.")
  505. if not condition_param.is_valid(param.get("value")):
  506. log.error("Param %s out of range for condition: %s", condition_param_name, condition_id)
  507. raise DebuggerParamValueError("Parameter out of range.")
  508. def set_default_param(condition_mgr, watch_condition):
  509. """
  510. Set default param.
  511. Args:
  512. condition_mgr (ConditionMgr): Instance of ConditionMgr.
  513. watch_condition (dict): The watch condition.
  514. "condition": {
  515. id: "tensor_too_large",
  516. "params": [
  517. {
  518. "name": "abs_mean_gt",
  519. "disable": false,
  520. "value": 1.1
  521. }
  522. ]
  523. }
  524. - id (str): Id of condition.
  525. - param (list[dict]): The list of param for this condition.
  526. Returns:
  527. dict, the new watch_condition.
  528. """
  529. condition_id = watch_condition.get('id')
  530. condition = condition_mgr.get_condition(condition_id)
  531. for param in condition.parameters:
  532. if not param.visible_on_ui and not param.support_disable:
  533. watch_condition["params"].append({
  534. "name": param.name,
  535. "disable": False,
  536. "value": param.default_value
  537. })
  538. watch_condition["abbr"] = condition.abbr
  539. return watch_condition