Skip to content

Commit

Permalink
created distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Sep 1, 2020
1 parent 28b1ba6 commit d1f63dd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
</dependency>
</dependencies>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/wandb/client-ng-java</url>
</repository>
</distributionManagement>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down
88 changes: 75 additions & 13 deletions src/main/java/com/wandb/client/WandbRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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<String> 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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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() + "/"
Expand All @@ -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) {
Expand Down

0 comments on commit d1f63dd

Please sign in to comment.