Skip to content

Repository files navigation

https://www.comet.com official Java SDK

versionMaven Centrallicensejavadoc

BranchTestsCoverageLintingCode Security
masterCIcodecovLint Code BaseCodeQL

Using Comet Java SDK

Add dependency to the pom.xml

 <dependencies>
<dependency>
<groupId>ml.comet</groupId>
<artifactId>comet-java-client</artifactId>
<version>1.1.14</version>
</dependency>
</dependencies>

Create experiment and log metrics and parameters

OnlineExperimentexperiment = ExperimentBuilder.OnlineExperiment()
.withApiKey("someApiKey")
.withProjectName("someProject")
.withWorkspace("someWorkspace")
.build();
experiment.setExperimentName("My experiment");
experiment.logParameter("batch_size", "500");
experiment.logMetric("strMetric", 123);
experiment.end();

The OnlineExperiment also can be used with try-with-resources statement which automatically handles call to the experiment.end().

try (OnlineExperimentexperiment = ExperimentBuilder.OnlineExperiment()
.withApiKey("someApiKey")
.withProjectName("someProject")
.withWorkspace("someWorkspace")
.build()) {
experiment.setExperimentName("My experiment");
experiment.logParameter("batch_size", "500");
experiment.logMetric("strMetric", 123);
} catch (Exceptione) {
e.printStackTrace();
}

Configure experiment object

Configuration sources hierarchy

The configuration parameters search order as following (first-listed are higher priority):

  • system properties or environment variables
  • configuration file set by call to withConfigOverride(java.io.File)
  • application.conf (all resources on the classpath with this name)
  • reference.conf (all resources on the classpath with this name)

Programmatic configuration

It is possible to override some or all configuration parameters programmatically when you create a new experiment's instance using ExperimentBuilder factory.

// Setting specific configuration parameters with builderExperimentBuilder.OnlineExperiment().withApiKey("someApiKey").build();
// Override configuration file (can have partial keys)ExperimentBuilder.OnlineExperiment().withConfigOverride(newFile("/tmp/comet.conf")).build();
// Read from environment variables OR from configuration file in classpath (application.conf)ExperimentBuilder.OnlineExperiment().build();

Full list of environment variables

COMET_API_KEY
COMET_PROJECT_NAME
COMET_WORKSPACE_NAME
COMET_BASE_URL
COMET_MAX_AUTH_RETRIES

Examples

Releases

Packages

Used by

Contributors

Languages