9
9
10
10
import java .io .IOException ;
11
11
import java .io .PrintStream ;
12
+ import java .util .List ;
12
13
13
14
public class WandbRun {
14
15
public static void main (String [] args ) throws IOException , InterruptedException {
@@ -32,10 +33,9 @@ public static void main(String[] args) throws IOException, InterruptedException
32
33
+ data .getRunId ()
33
34
);
34
35
35
- for (double i = 0.0 ; i < 2 * Math .PI ; i += 0.01 ) {
36
+ for (double i = 0.0 ; i < 2 * Math .PI ; i += 0.05 ) {
36
37
JSONObject log = new JSONObject ();
37
38
log .put ("value" , Math .sin (i ));
38
- log .put ("value2" , Math .sin (i ) * 2 );
39
39
System .out .println (log );
40
40
run .log (log );
41
41
}
@@ -60,31 +60,55 @@ public Builder() {
60
60
this .runBuilder = WandbServer .RunRecord .newBuilder ();
61
61
}
62
62
63
+ /**
64
+ * Set a display name for this run, which shows up in the UI and is editable, doesn't have to be unique.
65
+ * @param name display name for the run
66
+ */
63
67
public Builder withName (String name ) {
64
68
this .runBuilder .setDisplayName (name );
65
69
return this ;
66
70
}
67
71
72
+ /**
73
+ * Set a JSON object to set as initial config
74
+ * @param config initial config of the run
75
+ */
68
76
public Builder withConfig (JSONObject config ) {
69
77
this .runBuilder .setConfig (makeConfigData (config ));
70
78
return this ;
71
79
}
72
80
81
+ /**
82
+ * Set the name of the project to which this run will belong
83
+ * @param name name of the project this run belongs too
84
+ */
73
85
public Builder withProject (String name ) {
74
86
this .runBuilder .setProject (name );
75
87
return this ;
76
88
}
77
89
90
+ /**
91
+ * Set a string description associated with the run
92
+ * @param notes description associated with the run
93
+ */
78
94
public Builder withNotes (String notes ) {
79
95
this .runBuilder .setNotes (notes );
80
96
return this ;
81
97
}
82
98
99
+ /**
100
+ * Sets the type of job you are logging, e.g. eval, worker, ps (default: training)
101
+ * @param type type of job you are logging
102
+ */
83
103
public Builder setJobType (String type ) {
84
104
this .runBuilder .setJobType (type );
85
105
return this ;
86
106
}
87
107
108
+ /**
109
+ * Set a string by which to group other runs;
110
+ * @param runGroup string for which group this run is apart of
111
+ */
88
112
public Builder withRunGroup (String runGroup ) {
89
113
this .runBuilder .setRunGroup (runGroup );
90
114
return this ;
@@ -95,31 +119,50 @@ public Builder setSweepId(String sweepId) {
95
119
return this ;
96
120
}
97
121
98
- public Builder setHost (String host ) {
99
- this .runBuilder .setHost (host );
122
+ /**
123
+ * Adds a list of strings to associate with this run as tags
124
+ * @param tags list of strings to associate with this run
125
+ */
126
+ public Builder setTags (List <String > tags ) {
127
+ this .runBuilder .addAllTags (tags );
100
128
return this ;
101
129
}
102
130
103
- public Builder addTag (String tags ) {
104
- this .runBuilder .addTags (tags );
131
+ /**
132
+ * Removes all tags associated with this run.
133
+ */
134
+ public Builder clearTags () {
135
+ this .runBuilder .clearTags ();
105
136
return this ;
106
137
}
107
138
108
- public Builder clearTags () {
109
- this .runBuilder .clearTags ();
139
+
140
+ public Builder setHost (String host ) {
141
+ this .runBuilder .setHost (host );
110
142
return this ;
111
143
}
112
144
145
+ /**
146
+ * Sets the internal address for the GRPC server
147
+ * @param address GRPC address for this run
148
+ */
113
149
public Builder onAddress (String address ) {
114
150
this .gprcAddress = address ;
115
151
return this ;
116
152
}
117
153
154
+ /**
155
+ * Sets the internal port for the GRPC server
156
+ * @param port GRPC port for this run
157
+ */
118
158
public Builder onPort (int port ) {
119
159
this .gprcPort = port ;
120
160
return this ;
121
161
}
122
162
163
+ /**
164
+ * Creates a run from the provided configuration
165
+ */
123
166
public WandbRun build () throws IOException , InterruptedException {
124
167
return new WandbRun (this );
125
168
}
@@ -155,15 +198,25 @@ private WandbRun(Builder builder) throws IOException, InterruptedException {
155
198
this .run = this .stub .runUpdate (builder .runBuilder .build ()).getRun ();
156
199
this .stepCounter = 0 ;
157
200
201
+ // Object for logging stdout to Wandb
158
202
this .output = new WandbOutputStream (this );
159
203
System .setOut (new PrintStream (this .output ));
160
204
161
205
}
162
206
207
+ /**
208
+ * Gets the raw data object associated with the run.
209
+ * @return raw data object
210
+ */
163
211
public WandbServer .RunRecord data () {
164
212
return this .run ;
165
213
}
166
214
215
+ /**
216
+ * Logs data points for the run.
217
+ * @param json data to be logged
218
+ * @return raw log results object
219
+ */
167
220
public WandbServer .HistoryResult log (JSONObject json ) {
168
221
return this .log (json , ++this .stepCounter );
169
222
}
@@ -173,8 +226,11 @@ public WandbServer.HistoryResult log(JSONObject json, int step) {
173
226
return this .stub .log (makeLogData (json ));
174
227
}
175
228
229
+ /**
230
+ * Prints run link URL to stdout.
231
+ */
176
232
public void printRunInfo () {
177
- String baseUrl = "https://app.wandb.ai" ;
233
+ String baseUrl = this . run . getHost () ;
178
234
System .out .println ("Monitor your run (" + this .run .getDisplayName () + ") at: "
179
235
+ baseUrl + "/"
180
236
+ this .run .getEntity () + "/"
@@ -197,16 +253,22 @@ public void done(int exitCode) {
197
253
this .shutdown ();
198
254
}
199
255
200
- private void exit (int exitCode ) {
201
- this .stub .runExit (WandbServer .RunExitRecord .newBuilder ().setExitCode (exitCode ).build ());
256
+ private WandbServer . RunExitResult exit (int exitCode ) {
257
+ return this .stub .runExit (WandbServer .RunExitRecord .newBuilder ().setExitCode (exitCode ).build ());
202
258
}
203
259
204
- private void shutdown () {
205
- this .stub .serverShutdown (WandbServer .ServerShutdownRequest .newBuilder ().build ());
260
+ private WandbServer .ServerShutdownResult shutdown () {
261
+ WandbServer .ServerShutdownResult result = this .stub .serverShutdown (
262
+ WandbServer .ServerShutdownRequest
263
+ .newBuilder ()
264
+ .build ()
265
+ );
266
+
206
267
this .channel .shutdown ();
207
268
try {
208
269
this .grpcProcess .waitFor ();
209
270
} catch (InterruptedException ignore ) {}
271
+ return result ;
210
272
}
211
273
212
274
static private WandbServer .HistoryRecord makeLogData (JSONObject json ) {
0 commit comments