From d1f63ddd5238f524340fa89c489a146d6026d659 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Tue, 1 Sep 2020 13:09:14 -0400 Subject: [PATCH] created distribution --- README.md | 2 +- pom.xml | 8 ++ src/main/java/com/wandb/client/WandbRun.java | 88 +++++++++++++++++--- 3 files changed, 84 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 57db0f8..48a3fa3 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,4 @@ 1. Install Java and Maven 2. Install dependencies using `make install` 3. Build jar file `make build` -4. Run jar file `make run` +4. Run jar file `make run` \ No newline at end of file diff --git a/pom.xml b/pom.xml index efca912..ba1411b 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,14 @@ + + + github + GitHub Packages + https://maven.pkg.github.com/wandb/client-ng-java + + + 1.8 1.8 diff --git a/src/main/java/com/wandb/client/WandbRun.java b/src/main/java/com/wandb/client/WandbRun.java index 275f73e..0f2f3c5 100644 --- a/src/main/java/com/wandb/client/WandbRun.java +++ b/src/main/java/com/wandb/client/WandbRun.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.PrintStream; +import java.util.List; public class WandbRun { public static void main(String[] args) throws IOException, InterruptedException { @@ -32,10 +33,9 @@ public static void main(String[] args) throws IOException, InterruptedException + data.getRunId() ); - for (double i = 0.0; i < 2 * Math.PI; i += 0.01) { + for (double i = 0.0; i < 2 * Math.PI; i += 0.05) { JSONObject log = new JSONObject(); log.put("value", Math.sin(i)); - log.put("value2", Math.sin(i) * 2); System.out.println(log); run.log(log); } @@ -60,31 +60,55 @@ public Builder() { this.runBuilder = WandbServer.RunRecord.newBuilder(); } + /** + * Set a display name for this run, which shows up in the UI and is editable, doesn't have to be unique. + * @param name display name for the run + */ public Builder withName(String name) { this.runBuilder.setDisplayName(name); return this; } + /** + * Set a JSON object to set as initial config + * @param config initial config of the run + */ public Builder withConfig(JSONObject config) { this.runBuilder.setConfig(makeConfigData(config)); return this; } + /** + * Set the name of the project to which this run will belong + * @param name name of the project this run belongs too + */ public Builder withProject(String name) { this.runBuilder.setProject(name); return this; } + /** + * Set a string description associated with the run + * @param notes description associated with the run + */ public Builder withNotes(String notes) { this.runBuilder.setNotes(notes); return this; } + /** + * Sets the type of job you are logging, e.g. eval, worker, ps (default: training) + * @param type type of job you are logging + */ public Builder setJobType(String type) { this.runBuilder.setJobType(type); return this; } + /** + * Set a string by which to group other runs; + * @param runGroup string for which group this run is apart of + */ public Builder withRunGroup(String runGroup) { this.runBuilder.setRunGroup(runGroup); return this; @@ -95,31 +119,50 @@ public Builder setSweepId(String sweepId) { return this; } - public Builder setHost(String host) { - this.runBuilder.setHost(host); + /** + * Adds a list of strings to associate with this run as tags + * @param tags list of strings to associate with this run + */ + public Builder setTags(List tags) { + this.runBuilder.addAllTags(tags); return this; } - public Builder addTag(String tags) { - this.runBuilder.addTags(tags); + /** + * Removes all tags associated with this run. + */ + public Builder clearTags() { + this.runBuilder.clearTags(); return this; } - public Builder clearTags() { - this.runBuilder.clearTags(); + + public Builder setHost(String host) { + this.runBuilder.setHost(host); return this; } + /** + * Sets the internal address for the GRPC server + * @param address GRPC address for this run + */ public Builder onAddress(String address) { this.gprcAddress = address; return this; } + /** + * Sets the internal port for the GRPC server + * @param port GRPC port for this run + */ public Builder onPort(int port) { this.gprcPort = port; return this; } + /** + * Creates a run from the provided configuration + */ public WandbRun build() throws IOException, InterruptedException { return new WandbRun(this); } @@ -155,15 +198,25 @@ private WandbRun(Builder builder) throws IOException, InterruptedException { this.run = this.stub.runUpdate(builder.runBuilder.build()).getRun(); this.stepCounter = 0; + // Object for logging stdout to Wandb this.output = new WandbOutputStream(this); System.setOut(new PrintStream(this.output)); } + /** + * Gets the raw data object associated with the run. + * @return raw data object + */ public WandbServer.RunRecord data() { return this.run; } + /** + * Logs data points for the run. + * @param json data to be logged + * @return raw log results object + */ public WandbServer.HistoryResult log(JSONObject json) { return this.log(json, ++this.stepCounter); } @@ -173,8 +226,11 @@ public WandbServer.HistoryResult log(JSONObject json, int step) { return this.stub.log(makeLogData(json)); } + /** + * Prints run link URL to stdout. + */ public void printRunInfo() { - String baseUrl = "https://app.wandb.ai"; + String baseUrl = this.run.getHost(); System.out.println("Monitor your run (" + this.run.getDisplayName() + ") at: " + baseUrl + "/" + this.run.getEntity() + "/" @@ -197,16 +253,22 @@ public void done(int exitCode) { this.shutdown(); } - private void exit(int exitCode) { - this.stub.runExit(WandbServer.RunExitRecord.newBuilder().setExitCode(exitCode).build()); + private WandbServer.RunExitResult exit(int exitCode) { + return this.stub.runExit(WandbServer.RunExitRecord.newBuilder().setExitCode(exitCode).build()); } - private void shutdown() { - this.stub.serverShutdown(WandbServer.ServerShutdownRequest.newBuilder().build()); + private WandbServer.ServerShutdownResult shutdown() { + WandbServer.ServerShutdownResult result = this.stub.serverShutdown( + WandbServer.ServerShutdownRequest + .newBuilder() + .build() + ); + this.channel.shutdown(); try { this.grpcProcess.waitFor(); } catch (InterruptedException ignore) {} + return result; } static private WandbServer.HistoryRecord makeLogData(JSONObject json) {