OpenRow.tsx 8.91 KB
Newer Older
Lijiao's avatar
Lijiao committed
1
import * as React from 'react';
2
import * as copy from 'copy-to-clipboard';
3
import { Stack, PrimaryButton, Pivot, PivotItem, DefaultButton } from '@fluentui/react';
4
import { Trial } from '../../static/model/trial';
5
import { MANAGER_IP, RETIARIIPARAMETERS } from '../../static/const';
6
import { EXPERIMENT, TRIALS } from '../../static/datamodel';
7
import { reformatRetiariiParameter } from '../../static/function';
8
9
10
import JSONTree from 'react-json-tree';
import PaiTrialLog from '../public-child/PaiTrialLog';
import TrialLog from '../public-child/TrialLog';
11
import MessageInfo from '../modals/MessageInfo';
12
import PanelMonacoEditor from '../public-child/PanelMonacoEditor';
13
import '../../static/style/overview/overview.scss';
14
import '../../static/style/copyParameter.scss';
15
import '../../static/style/openRow.scss';
Lijiao's avatar
Lijiao committed
16
17

interface OpenRowProps {
18
    trialId: string;
Lijiao's avatar
Lijiao committed
19
20
}

Lijiao's avatar
Lijiao committed
21
interface OpenRowState {
22
23
24
    typeInfo: string;
    info: string;
    isHidenInfo: boolean;
25
    showRetiaParamPanel: boolean;
Lijiao's avatar
Lijiao committed
26
27
28
}

class OpenRow extends React.Component<OpenRowProps, OpenRowState> {
Lijiao's avatar
Lijiao committed
29
30
    constructor(props: OpenRowProps) {
        super(props);
Lijiao's avatar
Lijiao committed
31
        this.state = {
32
33
            typeInfo: '',
            info: '',
34
35
            isHidenInfo: true,
            showRetiaParamPanel: false
Lijiao's avatar
Lijiao committed
36
        };
37
38
    }

39
40
    hideMessageInfo = (): void => {
        this.setState(() => ({ isHidenInfo: true }));
41
    };
Lijiao's avatar
Lijiao committed
42

43
44
45
46
47
48
49
50
    hideRetiaParam = (): void => {
        this.setState(() => ({ showRetiaParamPanel: false }));
    };

    isshowRetiaParamPanel = (): void => {
        this.setState(() => ({ showRetiaParamPanel: true }));
    };

51
52
53
    /**
     * info: message content
     * typeInfo: message type: success | error...
54
     * continuousTime: show time, 2000ms
55
56
57
58
     */
    getCopyStatus = (info: string, typeInfo: string): void => {
        this.setState(() => ({ info, typeInfo, isHidenInfo: false }));
        setTimeout(this.hideMessageInfo, 2000);
59
    };
Lijiao's avatar
Lijiao committed
60

61
62
    copyParams = (trial: Trial): void => {
        // get copy parameters
63
        const params = JSON.stringify(reformatRetiariiParameter(trial.description.parameters as any), null, 4);
64
65
        if (copy.default(params)) {
            this.getCopyStatus('Success copy parameters to clipboard in form of python dict !', 'success');
66
        } else {
67
            this.getCopyStatus('Failed !', 'error');
68
        }
69
    };
70

Yuge Zhang's avatar
Yuge Zhang committed
71
72
73
74
75
76
77
    openTrialLog = (filename: string): void => {
        window.open(`${MANAGER_IP}/trial-file/${this.props.trialId}/${filename}`);
    };

    openModelOnnx = (): void => {
        // TODO: netron might need prefix.
        window.open(`/netron/index.html?url=${MANAGER_IP}/trial-file/${this.props.trialId}/model.onnx`);
78
    };
79

Lijiao's avatar
Lijiao committed
80
    render(): React.ReactNode {
81
        const { isHidenInfo, typeInfo, info, showRetiaParamPanel } = this.state;
82
83
        const trialId = this.props.trialId;
        const trial = TRIALS.getTrial(trialId);
84
        const logPathRow = trial.info.logPath || "This trial's log path is not available.";
85
86
        const originParameters = trial.description.parameters;
        const hasVisualHyperParams = RETIARIIPARAMETERS in originParameters;
Lijiao's avatar
Lijiao committed
87
        return (
88
89
            <Stack className='openRow'>
                <Stack className='openRowContent'>
90
                    <Pivot>
91
92
93
94
95
96
97
98
                        <PivotItem headerText='Parameters' key='1' itemIcon='TestParameter'>
                            {trial.info.hyperParameters !== undefined ? (
                                <Stack id='description'>
                                    <Stack className='bgHyper'>
                                        <JSONTree
                                            hideRoot={true}
                                            shouldExpandNode={(): boolean => true} // default expandNode
                                            getItemString={(): null => null} // remove the {} items
99
                                            data={reformatRetiariiParameter(originParameters as any)}
100
                                        />
101
                                    </Stack>
102
103
104
105
106
107
                                    <Stack horizontal className='copy'>
                                        <PrimaryButton
                                            onClick={this.copyParams.bind(this, trial)}
                                            text='Copy as json'
                                            styles={{ root: { width: 128, marginRight: 10 } }}
                                        />
108
109
110
111
112
113
                                        {hasVisualHyperParams && (
                                            <DefaultButton
                                                onClick={this.isshowRetiaParamPanel}
                                                text='Original parameters'
                                            />
                                        )}
114
115
                                        {/* copy success | failed message info */}
                                        {!isHidenInfo && <MessageInfo typeInfo={typeInfo} info={info} />}
116
117
118
119
120
121
122
                                        {showRetiaParamPanel && (
                                            <PanelMonacoEditor
                                                hideConfigPanel={this.hideRetiaParam}
                                                panelName='Retiarii parameters'
                                                panelContent={JSON.stringify(originParameters, null, 2)}
                                            />
                                        )}
123
                                    </Stack>
124
125
126
127
128
129
130
                                </Stack>
                            ) : (
                                <Stack className='logpath'>
                                    <span className='logName'>Error: </span>
                                    <span className='error'>{`This trial's parameters are not available.'`}</span>
                                </Stack>
                            )}
131
                        </PivotItem>
132
                        <PivotItem headerText='Log' key='2' itemIcon='M365InvoicingLogo'>
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
                            {
                                // FIXME: this should not be handled in web UI side
                                EXPERIMENT.trainingServicePlatform !== 'local' ? (
                                    <PaiTrialLog
                                        logStr={logPathRow}
                                        id={trialId}
                                        logCollection={EXPERIMENT.logCollectionEnabled}
                                    />
                                ) : (
                                    <div>
                                        <TrialLog logStr={logPathRow} id={trialId} />
                                        {/* view each trial log in drawer*/}
                                        <div id='trialog'>
                                            <div className='copy' style={{ marginTop: 15 }}>
                                                <PrimaryButton
Yuge Zhang's avatar
Yuge Zhang committed
148
                                                    onClick={this.openTrialLog.bind(this, 'trial.log')}
149
150
151
                                                    text='View trial log'
                                                />
                                                <PrimaryButton
Yuge Zhang's avatar
Yuge Zhang committed
152
                                                    onClick={this.openTrialLog.bind(this, 'stderr')}
153
154
155
156
                                                    text='View trial error'
                                                    styles={{ root: { marginLeft: 15 } }}
                                                />
                                                <PrimaryButton
Yuge Zhang's avatar
Yuge Zhang committed
157
                                                    onClick={this.openTrialLog.bind(this, 'stdout')}
158
159
160
161
                                                    text='View trial stdout'
                                                    styles={{ root: { marginLeft: 15 } }}
                                                />
                                            </div>
162
163
                                        </div>
                                    </div>
164
165
                                )
                            }
166
                        </PivotItem>
Yuge Zhang's avatar
Yuge Zhang committed
167
168
169
170
171
172
173
174
175
176
177
178
                        {EXPERIMENT.metadata.tag.includes('retiarii') ? (
                            <PivotItem headerText='Visualization' key='3' itemIcon='FlowChart'>
                                <div id='visualization'>
                                    <div id='visualizationText'>Visualize models with 3rd-party tools.</div>
                                    <PrimaryButton
                                        onClick={this.openModelOnnx.bind(this)}
                                        text='Netron'
                                        styles={{ root: { marginLeft: 15 } }}
                                    />
                                </div>
                            </PivotItem>
                        ) : null}
179
                    </Pivot>
180
                </Stack>
181
            </Stack>
Lijiao's avatar
Lijiao committed
182
183
184
185
        );
    }
}

186
export default OpenRow;