python_api_connect.ipynb 5.42 KB
Newer Older
kvartet's avatar
kvartet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "white-electron",
   "metadata": {},
   "source": [
    "## 连接并管理已存在的 Experiment"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "recent-italic",
   "metadata": {},
   "source": [
    "### 1. 连接 Experiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "statistical-repair",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2021-02-25 07:50:38] Connect to port 8080 success, experiment id is IF0JnfLE, status is RUNNING.\n"
     ]
    }
   ],
   "source": [
    "from nni.experiment import Experiment\n",
    "experiment = Experiment.connect(8080)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "defensive-scratch",
   "metadata": {},
   "source": [
    "### 2. Experiment 查看和管理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "independent-touch",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': 'IF0JnfLE',\n",
       " 'revision': 6,\n",
kvartet's avatar
kvartet committed
57
       "  'maxTrialNum': 10,\n",
kvartet's avatar
kvartet committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
       " 'logDir': '/home/ningshang/nni-experiments/IF0JnfLE',\n",
       " 'nextSequenceId': 2,\n",
       " 'params': {'authorName': 'default',\n",
       "  'experimentName': 'example_sklearn-classification',\n",
       "  'trialConcurrency': 1,\n",
       "  'maxExecDuration': 3600,\n",
       "  'maxTrialNum': 5,\n",
       "  'searchSpace': '{\"C\": {\"_type\": \"uniform\", \"_value\": [0.1, 1]}, \"kernel\": {\"_type\": \"choice\", \"_value\": [\"linear\", \"rbf\", \"poly\", \"sigmoid\"]}, \"degree\": {\"_type\": \"choice\", \"_value\": [1, 2, 3, 4]}, \"gamma\": {\"_type\": \"uniform\", \"_value\": [0.01, 0.1]}, \"coef0\": {\"_type\": \"uniform\", \"_value\": [0.01, 0.1]}}',\n",
       "  'trainingServicePlatform': 'local',\n",
       "  'tuner': {'builtinTunerName': 'TPE',\n",
       "   'classArgs': {'optimize_mode': 'maximize'},\n",
       "   'checkpointDir': '/home/ningshang/nni-experiments/IF0JnfLE/checkpoint'},\n",
       "  'versionCheck': True,\n",
       "  'clusterMetaData': [{'key': 'trial_config',\n",
       "    'value': {'command': 'python3 main.py',\n",
       "     'codeDir': '/home/ningshang/nni/examples/trials/sklearn/classification/.',\n",
       "     'gpuNum': 0}}]},\n",
       " 'startTime': 1614239412494}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "experiment.get_experiment_profile()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "printable-bookmark",
   "metadata": {},
kvartet's avatar
kvartet committed
92
93
94
95
96
97
98
99
100
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2021-03-05 12:18:32] (root) Successfully update maxTrialNum.\n"
     ]
    }
   ],
kvartet's avatar
kvartet committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
   "source": [
    "experiment.update_max_trial_number(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "marine-serial",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': 'IF0JnfLE',\n",
       " 'revision': 8,\n",
kvartet's avatar
kvartet committed
116
       " 'execDuration': 28,\n",
kvartet's avatar
kvartet committed
117
118
119
120
121
122
       " 'logDir': '/home/ningshang/nni-experiments/IF0JnfLE',\n",
       " 'nextSequenceId': 2,\n",
       " 'params': {'authorName': 'default',\n",
       "  'experimentName': 'example_sklearn-classification',\n",
       "  'trialConcurrency': 1,\n",
       "  'maxExecDuration': 3600,\n",
kvartet's avatar
kvartet committed
123
       "  'maxTrialNum': 200,\n",
kvartet's avatar
kvartet committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
       "  'searchSpace': '{\"C\": {\"_type\": \"uniform\", \"_value\": [0.1, 1]}, \"kernel\": {\"_type\": \"choice\", \"_value\": [\"linear\", \"rbf\", \"poly\", \"sigmoid\"]}, \"degree\": {\"_type\": \"choice\", \"_value\": [1, 2, 3, 4]}, \"gamma\": {\"_type\": \"uniform\", \"_value\": [0.01, 0.1]}, \"coef0\": {\"_type\": \"uniform\", \"_value\": [0.01, 0.1]}}',\n",
       "  'trainingServicePlatform': 'local',\n",
       "  'tuner': {'builtinTunerName': 'TPE',\n",
       "   'classArgs': {'optimize_mode': 'maximize'},\n",
       "   'checkpointDir': '/home/ningshang/nni-experiments/IF0JnfLE/checkpoint'},\n",
       "  'versionCheck': True,\n",
       "  'clusterMetaData': [{'key': 'trial_config',\n",
       "    'value': {'command': 'python3 main.py',\n",
       "     'codeDir': '/home/ningshang/nni/examples/trials/sklearn/classification/.',\n",
       "     'gpuNum': 0}}]},\n",
       " 'startTime': 1614239412494}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "experiment.get_experiment_profile()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "opened-lounge",
   "metadata": {},
   "source": [
    "### 3. 停止 Experiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "emotional-machinery",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2021-02-25 07:50:49] Stopping experiment, please wait...\n",
      "[2021-02-25 07:50:49] Experiment stopped\n"
     ]
    }
   ],
   "source": [
    "experiment.stop()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "nni-dev",
   "language": "python",
   "name": "nni-dev"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}