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.

index.tsx 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import ConfigInfo, { type BasicInfoData } from '@/components/ConfigInfo';
  2. import { hyperParameterOptimizedMode } from '@/enums';
  3. import { useComputingResource } from '@/hooks/useComputingResource';
  4. import { experimentStatusInfo } from '@/pages/Experiment/status';
  5. import {
  6. schedulerAlgorithms,
  7. searchAlgorithms,
  8. } from '@/pages/HyperParameter/components/CreateForm/utils';
  9. import { HyperParameterData } from '@/pages/HyperParameter/types';
  10. import { type NodeStatus } from '@/types';
  11. import { elapsedTime } from '@/utils/date';
  12. import {
  13. formatCodeConfig,
  14. formatDataset,
  15. formatDate,
  16. formatEnum,
  17. formatMirror,
  18. formatModel,
  19. } from '@/utils/format';
  20. import { Flex } from 'antd';
  21. import classNames from 'classnames';
  22. import { useMemo } from 'react';
  23. import ParameterInfo from '../ParameterInfo';
  24. import styles from './index.less';
  25. // 格式化优化方向
  26. const formatOptimizeMode = (value: string) => {
  27. return value === hyperParameterOptimizedMode.Max ? '越大越好' : '越小越好';
  28. };
  29. type HyperParameterBasicProps = {
  30. info?: HyperParameterData;
  31. className?: string;
  32. isInstance?: boolean;
  33. runStatus?: NodeStatus;
  34. };
  35. function HyperParameterBasic({
  36. info,
  37. className,
  38. runStatus,
  39. isInstance = false,
  40. }: HyperParameterBasicProps) {
  41. const getResourceDescription = useComputingResource()[1];
  42. const basicDatas: BasicInfoData[] = useMemo(() => {
  43. if (!info) {
  44. return [];
  45. }
  46. return [
  47. {
  48. label: '实验名称',
  49. value: info.name,
  50. },
  51. {
  52. label: '实验描述',
  53. value: info.description,
  54. },
  55. {
  56. label: '创建人',
  57. value: info.create_by,
  58. },
  59. {
  60. label: '创建时间',
  61. value: info.create_time,
  62. format: formatDate,
  63. },
  64. {
  65. label: '更新时间',
  66. value: info.update_time,
  67. format: formatDate,
  68. },
  69. ];
  70. }, [info]);
  71. const configDatas: BasicInfoData[] = useMemo(() => {
  72. if (!info) {
  73. return [];
  74. }
  75. return [
  76. {
  77. label: '代码',
  78. value: info.code_config,
  79. format: formatCodeConfig,
  80. },
  81. {
  82. label: '主函数代码文件',
  83. value: info.main_py,
  84. },
  85. {
  86. label: '镜像',
  87. value: info.image,
  88. format: formatMirror,
  89. },
  90. {
  91. label: '数据集',
  92. value: info.dataset,
  93. format: formatDataset,
  94. },
  95. {
  96. label: '模型',
  97. value: info.model,
  98. format: formatModel,
  99. },
  100. {
  101. label: '总试验次数',
  102. value: info.num_samples,
  103. },
  104. {
  105. label: '搜索算法',
  106. value: info.search_alg,
  107. format: formatEnum(searchAlgorithms),
  108. },
  109. {
  110. label: '调度算法',
  111. value: info.scheduler,
  112. format: formatEnum(schedulerAlgorithms),
  113. },
  114. {
  115. label: '单次试验最大时间',
  116. value: info.max_t,
  117. },
  118. {
  119. label: '最小试验数',
  120. value: info.min_samples_required,
  121. },
  122. {
  123. label: '指标优化方向',
  124. value: info.mode,
  125. format: formatOptimizeMode,
  126. },
  127. {
  128. label: '指标',
  129. value: info.metric,
  130. },
  131. {
  132. label: '资源规格',
  133. value: info.computing_resource_id,
  134. format: getResourceDescription,
  135. },
  136. ];
  137. }, [info, getResourceDescription]);
  138. const instanceDatas = useMemo(() => {
  139. if (!info || !runStatus) {
  140. return [];
  141. }
  142. return [
  143. {
  144. label: '启动时间',
  145. value: formatDate(info.create_time),
  146. ellipsis: true,
  147. },
  148. {
  149. label: '执行时长',
  150. value: elapsedTime(info.create_time, runStatus.finishedAt),
  151. ellipsis: true,
  152. },
  153. {
  154. label: '状态',
  155. value: (
  156. <Flex align="center">
  157. <img
  158. style={{ width: '17px', marginRight: '7px' }}
  159. src={experimentStatusInfo[runStatus.phase]?.icon}
  160. draggable={false}
  161. alt=""
  162. />
  163. <div
  164. style={{
  165. color: experimentStatusInfo[runStatus?.phase]?.color,
  166. fontSize: '15px',
  167. lineHeight: 1.6,
  168. }}
  169. >
  170. {experimentStatusInfo[runStatus?.phase]?.label}
  171. </div>
  172. </Flex>
  173. ),
  174. ellipsis: true,
  175. },
  176. ];
  177. }, [runStatus, info]);
  178. return (
  179. <div className={classNames(styles['hyper-parameter-basic'], className)}>
  180. {isInstance && runStatus && (
  181. <ConfigInfo
  182. title="运行信息"
  183. datas={instanceDatas}
  184. labelWidth={70}
  185. style={{ marginBottom: '20px' }}
  186. />
  187. )}
  188. {!isInstance && (
  189. <ConfigInfo
  190. title="基本信息"
  191. datas={basicDatas}
  192. labelWidth={70}
  193. style={{ marginBottom: '20px' }}
  194. />
  195. )}
  196. <ConfigInfo
  197. title="配置信息"
  198. datas={configDatas}
  199. labelWidth={120}
  200. style={{ marginBottom: '20px' }}
  201. >
  202. {info && <ParameterInfo info={info} />}
  203. </ConfigInfo>
  204. </div>
  205. );
  206. }
  207. export default HyperParameterBasic;