Skip to content

Commit d1f63dd

Browse files
committed
created distribution
1 parent 28b1ba6 commit d1f63dd

File tree

3 files changed

+84
-14
lines changed

3 files changed

+84
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
1. Install Java and Maven
1010
2. Install dependencies using `make install`
1111
3. Build jar file `make build`
12-
4. Run jar file `make run`
12+
4. Run jar file `make run`

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
</dependency>
4040
</dependencies>
4141

42+
<distributionManagement>
43+
<repository>
44+
<id>github</id>
45+
<name>GitHub Packages</name>
46+
<url>https://maven.pkg.github.com/wandb/client-ng-java</url>
47+
</repository>
48+
</distributionManagement>
49+
4250
<properties>
4351
<maven.compiler.source>1.8</maven.compiler.source>
4452
<maven.compiler.target>1.8</maven.compiler.target>

src/main/java/com/wandb/client/WandbRun.java

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.io.IOException;
1111
import java.io.PrintStream;
12+
import java.util.List;
1213

1314
public class WandbRun {
1415
public static void main(String[] args) throws IOException, InterruptedException {
@@ -32,10 +33,9 @@ public static void main(String[] args) throws IOException, InterruptedException
3233
+ data.getRunId()
3334
);
3435

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) {
3637
JSONObject log = new JSONObject();
3738
log.put("value", Math.sin(i));
38-
log.put("value2", Math.sin(i) * 2);
3939
System.out.println(log);
4040
run.log(log);
4141
}
@@ -60,31 +60,55 @@ public Builder() {
6060
this.runBuilder = WandbServer.RunRecord.newBuilder();
6161
}
6262

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+
*/
6367
public Builder withName(String name) {
6468
this.runBuilder.setDisplayName(name);
6569
return this;
6670
}
6771

72+
/**
73+
* Set a JSON object to set as initial config
74+
* @param config initial config of the run
75+
*/
6876
public Builder withConfig(JSONObject config) {
6977
this.runBuilder.setConfig(makeConfigData(config));
7078
return this;
7179
}
7280

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+
*/
7385
public Builder withProject(String name) {
7486
this.runBuilder.setProject(name);
7587
return this;
7688
}
7789

90+
/**
91+
* Set a string description associated with the run
92+
* @param notes description associated with the run
93+
*/
7894
public Builder withNotes(String notes) {
7995
this.runBuilder.setNotes(notes);
8096
return this;
8197
}
8298

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+
*/
83103
public Builder setJobType(String type) {
84104
this.runBuilder.setJobType(type);
85105
return this;
86106
}
87107

108+
/**
109+
* Set a string by which to group other runs;
110+
* @param runGroup string for which group this run is apart of
111+
*/
88112
public Builder withRunGroup(String runGroup) {
89113
this.runBuilder.setRunGroup(runGroup);
90114
return this;
@@ -95,31 +119,50 @@ public Builder setSweepId(String sweepId) {
95119
return this;
96120
}
97121

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);
100128
return this;
101129
}
102130

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();
105136
return this;
106137
}
107138

108-
public Builder clearTags() {
109-
this.runBuilder.clearTags();
139+
140+
public Builder setHost(String host) {
141+
this.runBuilder.setHost(host);
110142
return this;
111143
}
112144

145+
/**
146+
* Sets the internal address for the GRPC server
147+
* @param address GRPC address for this run
148+
*/
113149
public Builder onAddress(String address) {
114150
this.gprcAddress = address;
115151
return this;
116152
}
117153

154+
/**
155+
* Sets the internal port for the GRPC server
156+
* @param port GRPC port for this run
157+
*/
118158
public Builder onPort(int port) {
119159
this.gprcPort = port;
120160
return this;
121161
}
122162

163+
/**
164+
* Creates a run from the provided configuration
165+
*/
123166
public WandbRun build() throws IOException, InterruptedException {
124167
return new WandbRun(this);
125168
}
@@ -155,15 +198,25 @@ private WandbRun(Builder builder) throws IOException, InterruptedException {
155198
this.run = this.stub.runUpdate(builder.runBuilder.build()).getRun();
156199
this.stepCounter = 0;
157200

201+
// Object for logging stdout to Wandb
158202
this.output = new WandbOutputStream(this);
159203
System.setOut(new PrintStream(this.output));
160204

161205
}
162206

207+
/**
208+
* Gets the raw data object associated with the run.
209+
* @return raw data object
210+
*/
163211
public WandbServer.RunRecord data() {
164212
return this.run;
165213
}
166214

215+
/**
216+
* Logs data points for the run.
217+
* @param json data to be logged
218+
* @return raw log results object
219+
*/
167220
public WandbServer.HistoryResult log(JSONObject json) {
168221
return this.log(json, ++this.stepCounter);
169222
}
@@ -173,8 +226,11 @@ public WandbServer.HistoryResult log(JSONObject json, int step) {
173226
return this.stub.log(makeLogData(json));
174227
}
175228

229+
/**
230+
* Prints run link URL to stdout.
231+
*/
176232
public void printRunInfo() {
177-
String baseUrl = "https://app.wandb.ai";
233+
String baseUrl = this.run.getHost();
178234
System.out.println("Monitor your run (" + this.run.getDisplayName() + ") at: "
179235
+ baseUrl + "/"
180236
+ this.run.getEntity() + "/"
@@ -197,16 +253,22 @@ public void done(int exitCode) {
197253
this.shutdown();
198254
}
199255

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());
202258
}
203259

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+
206267
this.channel.shutdown();
207268
try {
208269
this.grpcProcess.waitFor();
209270
} catch (InterruptedException ignore) {}
271+
return result;
210272
}
211273

212274
static private WandbServer.HistoryRecord makeLogData(JSONObject json) {

0 commit comments

Comments
 (0)