Search in sources :

Example 1 with ModelOverview

use of ml.comet.experiment.registrymodel.ModelOverview in project comet-java-sdk by comet-ml.

the class CometApiImpl method updateRegistryModel.

private void updateRegistryModel(@NonNull String registryName, @NonNull String workspace, @NonNull RegistryModelUpdateRequest request) {
    // get registry model details
    Optional<ModelOverview> overviewOptional = this.getRegistryModelDetails(registryName, workspace);
    if (!overviewOptional.isPresent()) {
        throw new ModelNotFoundException(getString(REGISTRY_MODEL_NOT_FOUND, workspace, registryName));
    }
    // update registry model details
    request.setRegistryModelId(overviewOptional.get().getRegistryModelId());
    String errorMsg = getString(FAILED_TO_UPDATE_REGISTRY_MODEL, workspace, registryName, request);
    RestApiResponse response = this.executeSyncRequest(this.restApiClient::updateRegistryModel, request, errorMsg);
    this.checkRestApiResponse(response, errorMsg);
}
Also used : ModelOverview(ml.comet.experiment.registrymodel.ModelOverview) ModelNotFoundException(ml.comet.experiment.registrymodel.ModelNotFoundException) LogMessages.getString(ml.comet.experiment.impl.resources.LogMessages.getString) RestApiResponse(ml.comet.experiment.impl.rest.RestApiResponse)

Example 2 with ModelOverview

use of ml.comet.experiment.registrymodel.ModelOverview in project comet-java-sdk by comet-ml.

the class CometApiImpl method getRegistryModelVersion.

@Override
public Optional<ModelVersionOverview> getRegistryModelVersion(@NonNull String registryName, @NonNull String workspace, @NonNull String version) {
    Optional<ModelOverview> overviewOptional = this.getRegistryModelDetails(registryName, workspace);
    if (!overviewOptional.isPresent()) {
        return Optional.empty();
    }
    ModelOverview overview = overviewOptional.get();
    if (overview.getVersions() == null || overview.getVersions().size() == 0) {
        String msg = getString(FAILED_TO_GET_REGISTRY_MODEL_VERSIONS, workspace, registryName);
        this.logger.error(msg);
        throw new ModelNotFoundException(msg);
    }
    return overview.getVersions().stream().filter(versionOverview -> Objects.equals(versionOverview.getVersion(), version)).findFirst();
}
Also used : SdkErrorCodes.registryModelNotFound(ml.comet.experiment.impl.constants.SdkErrorCodes.registryModelNotFound) Connection(ml.comet.experiment.impl.http.Connection) ModelVersionOverview(ml.comet.experiment.registrymodel.ModelVersionOverview) UPDATE_REGISTRY_MODEL_DESCRIPTION_IGNORED(ml.comet.experiment.impl.resources.LogMessages.UPDATE_REGISTRY_MODEL_DESCRIPTION_IGNORED) SneakyThrows(lombok.SneakyThrows) LoggerFactory(org.slf4j.LoggerFactory) ExperimentModelResponse(ml.comet.experiment.impl.rest.ExperimentModelResponse) ZipUtils(ml.comet.experiment.impl.utils.ZipUtils) StringUtils(org.apache.commons.lang3.StringUtils) FAILED_TO_UPDATE_REGISTRY_MODEL_VERSION(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_UPDATE_REGISTRY_MODEL_VERSION) RegistryModelUpdateItemRequest(ml.comet.experiment.impl.rest.RegistryModelUpdateItemRequest) FAILED_TO_GET_REGISTRY_MODEL_VERSIONS(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_GET_REGISTRY_MODEL_VERSIONS) FAILED_TO_GET_REGISTRY_MODEL_NOTES(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_GET_REGISTRY_MODEL_NOTES) RegistryModelUpdateRequest(ml.comet.experiment.impl.rest.RegistryModelUpdateRequest) RegistryModelNotesResponse(ml.comet.experiment.impl.rest.RegistryModelNotesResponse) ModelNotFoundException(ml.comet.experiment.registrymodel.ModelNotFoundException) ExperimentMetadata(ml.comet.experiment.model.ExperimentMetadata) PipedInputStream(java.io.PipedInputStream) COMET_BASE_URL(ml.comet.experiment.impl.config.CometConfig.COMET_BASE_URL) ModelUtils(ml.comet.experiment.impl.utils.ModelUtils) COMET_MAX_AUTH_RETRIES(ml.comet.experiment.impl.config.CometConfig.COMET_MAX_AUTH_RETRIES) MODEL_REGISTERED_IN_WORKSPACE(ml.comet.experiment.impl.resources.LogMessages.MODEL_REGISTERED_IN_WORKSPACE) RestApiUtils.createRegistryModelNotesUpdateRequest(ml.comet.experiment.impl.utils.RestApiUtils.createRegistryModelNotesUpdateRequest) MODEL_VERSION_CREATED_IN_WORKSPACE(ml.comet.experiment.impl.resources.LogMessages.MODEL_VERSION_CREATED_IN_WORKSPACE) Path(java.nio.file.Path) LogMessages.getString(ml.comet.experiment.impl.resources.LogMessages.getString) REGISTRY_MODEL_VERSION_NOT_FOUND(ml.comet.experiment.impl.resources.LogMessages.REGISTRY_MODEL_VERSION_NOT_FOUND) ModelVersionNotFoundException(ml.comet.experiment.registrymodel.ModelVersionNotFoundException) ModelDownloadInfo(ml.comet.experiment.registrymodel.ModelDownloadInfo) NonNull(lombok.NonNull) CometApi(ml.comet.experiment.CometApi) RegistryModelOverviewListResponse(ml.comet.experiment.impl.rest.RegistryModelOverviewListResponse) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) FAILED_TO_UPDATE_REGISTRY_MODEL(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_UPDATE_REGISTRY_MODEL) ModelRegistryRecord(ml.comet.experiment.registrymodel.ModelRegistryRecord) RestApiUtils(ml.comet.experiment.impl.utils.RestApiUtils) FAILED_TO_GET_REGISTRY_MODEL_DETAILS(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_GET_REGISTRY_MODEL_DETAILS) Optional(java.util.Optional) RegistryModelDetailsResponse(ml.comet.experiment.impl.rest.RegistryModelDetailsResponse) ExperimentModelListResponse(ml.comet.experiment.impl.rest.ExperimentModelListResponse) EXTRACTED_N_REGISTRY_MODEL_FILES(ml.comet.experiment.impl.resources.LogMessages.EXTRACTED_N_REGISTRY_MODEL_FILES) RegistryModelNotesUpdateRequest(ml.comet.experiment.impl.rest.RegistryModelNotesUpdateRequest) WORKSPACE_HAS_NO_REGISTRY_MODELS(ml.comet.experiment.impl.resources.LogMessages.WORKSPACE_HAS_NO_REGISTRY_MODELS) Single(io.reactivex.rxjava3.core.Single) CometApiBuilder(ml.comet.experiment.builder.CometApiBuilder) ZipInputStream(java.util.zip.ZipInputStream) REGISTRY_MODEL_NOT_FOUND(ml.comet.experiment.impl.resources.LogMessages.REGISTRY_MODEL_NOT_FOUND) DOWNLOADING_REGISTRY_MODEL_TO_FILE(ml.comet.experiment.impl.resources.LogMessages.DOWNLOADING_REGISTRY_MODEL_TO_FILE) DOWNLOADING_REGISTRY_MODEL_PROMPT(ml.comet.experiment.impl.resources.LogMessages.DOWNLOADING_REGISTRY_MODEL_PROMPT) ExceptionUtils(ml.comet.experiment.impl.utils.ExceptionUtils) DownloadModelOptions(ml.comet.experiment.registrymodel.DownloadModelOptions) Function(java.util.function.Function) CometConfig(ml.comet.experiment.impl.config.CometConfig) ArrayList(java.util.ArrayList) FAILED_TO_DELETE_REGISTRY_MODEL_VERSION(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_DELETE_REGISTRY_MODEL_VERSION) FAILED_TO_DOWNLOAD_REGISTRY_MODEL(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_DOWNLOAD_REGISTRY_MODEL) Model(ml.comet.experiment.registrymodel.Model) Observable(io.reactivex.rxjava3.core.Observable) RegistryModelItemCreateRequest(ml.comet.experiment.impl.rest.RegistryModelItemCreateRequest) ModelOverview(ml.comet.experiment.registrymodel.ModelOverview) FAILED_TO_UPDATE_REGISTRY_MODEL_NOTES(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_UPDATE_REGISTRY_MODEL_NOTES) RegistryModelCreateRequest(ml.comet.experiment.impl.rest.RegistryModelCreateRequest) FAILED_TO_DELETE_REGISTRY_MODEL(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_DELETE_REGISTRY_MODEL) OutputStream(java.io.OutputStream) RestApiResponse(ml.comet.experiment.impl.rest.RestApiResponse) CometUtils(ml.comet.experiment.impl.utils.CometUtils) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Project(ml.comet.experiment.model.Project) EXPERIMENT_HAS_NO_MODELS(ml.comet.experiment.impl.resources.LogMessages.EXPERIMENT_HAS_NO_MODELS) UPDATE_REGISTRY_MODEL_IS_PUBLIC_IGNORED(ml.comet.experiment.impl.resources.LogMessages.UPDATE_REGISTRY_MODEL_IS_PUBLIC_IGNORED) FAILED_TO_FIND_EXPERIMENT_MODEL_BY_NAME(ml.comet.experiment.impl.resources.LogMessages.FAILED_TO_FIND_EXPERIMENT_MODEL_BY_NAME) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) ConnectionInitializer(ml.comet.experiment.impl.http.ConnectionInitializer) File(java.io.File) BaseCometBuilder(ml.comet.experiment.builder.BaseCometBuilder) DOWNLOADING_REGISTRY_MODEL_TO_DIR(ml.comet.experiment.impl.resources.LogMessages.DOWNLOADING_REGISTRY_MODEL_TO_DIR) CREATE_NEW(java.nio.file.StandardOpenOption.CREATE_NEW) CometApiException(ml.comet.experiment.exception.CometApiException) Collections(java.util.Collections) COMET_API_KEY(ml.comet.experiment.impl.config.CometConfig.COMET_API_KEY) ModelOverview(ml.comet.experiment.registrymodel.ModelOverview) ModelNotFoundException(ml.comet.experiment.registrymodel.ModelNotFoundException) LogMessages.getString(ml.comet.experiment.impl.resources.LogMessages.getString)

Example 3 with ModelOverview

use of ml.comet.experiment.registrymodel.ModelOverview in project comet-java-sdk by comet-ml.

the class CometApiTest method testUpdateRegistryModelVersion.

@Test
public void testUpdateRegistryModelVersion() {
    String modelName = String.format("%s-%d", SOME_MODEL_NAME, System.currentTimeMillis());
    // register model with defaults
    // 
    registerModelWithDefaults(modelName);
    // wait for registry model to be processed by backend
    // 
    Awaitility.await("failed to get registry model").pollInterval(1, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS).until(() -> COMET_API.getRegistryModelDetails(modelName, SHARED_EXPERIMENT.getWorkspaceName()).isPresent());
    // update model's version
    // 
    String comment = "testUpdateRegistryModelVersion comment";
    List<String> stages = Collections.singletonList("testUpdateRegistryModelVersion");
    COMET_API.updateRegistryModelVersion(modelName, SHARED_EXPERIMENT.getWorkspaceName(), DEFAULT_MODEL_VERSION, comment, stages);
    // get registry model and check that it was updated
    // 
    Awaitility.await("failed to get registry model").pollInterval(1, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS).until(() -> COMET_API.getRegistryModelDetails(modelName, SHARED_EXPERIMENT.getWorkspaceName()).isPresent());
    Optional<ModelOverview> overviewOptional = COMET_API.getRegistryModelDetails(modelName, SHARED_EXPERIMENT.getWorkspaceName());
    assertTrue(overviewOptional.isPresent(), "model expected");
    ModelOverview modelOverview = overviewOptional.get();
    assertNotNull(modelOverview.getVersions(), "versions list expected");
    assertEquals(1, modelOverview.getVersions().size(), "wrong versions list size");
    ModelVersionOverview versionOverview = modelOverview.getVersions().get(0);
    assertEquals(comment, versionOverview.getComment(), "wrong comment");
    assertEquals(stages, versionOverview.getStages(), "wrong stages");
}
Also used : RegistryModelOverview(ml.comet.experiment.impl.rest.RegistryModelOverview) ModelOverview(ml.comet.experiment.registrymodel.ModelOverview) LogMessages.getString(ml.comet.experiment.impl.resources.LogMessages.getString) ModelVersionOverview(ml.comet.experiment.registrymodel.ModelVersionOverview) Test(org.junit.jupiter.api.Test)

Example 4 with ModelOverview

use of ml.comet.experiment.registrymodel.ModelOverview in project comet-java-sdk by comet-ml.

the class CometApiTest method testGetRegistryModelDetails_not_found.

@Test
public void testGetRegistryModelDetails_not_found() {
    String modelName = String.format("%s-%d", SOME_MODEL_NAME, System.currentTimeMillis());
    // try to get not existing model
    // 
    Optional<ModelOverview> overviewOptional = COMET_API.getRegistryModelDetails(modelName, SHARED_EXPERIMENT.getWorkspaceName());
    assertFalse(overviewOptional.isPresent());
}
Also used : RegistryModelOverview(ml.comet.experiment.impl.rest.RegistryModelOverview) ModelOverview(ml.comet.experiment.registrymodel.ModelOverview) LogMessages.getString(ml.comet.experiment.impl.resources.LogMessages.getString) Test(org.junit.jupiter.api.Test)

Example 5 with ModelOverview

use of ml.comet.experiment.registrymodel.ModelOverview in project comet-java-sdk by comet-ml.

the class CometApiTest method testGetRegistryModelDetails.

@Test
public void testGetRegistryModelDetails() {
    String modelName = String.format("%s-%d", SOME_MODEL_NAME, System.currentTimeMillis());
    // register model with defaults
    // 
    String registryName = registerModelWithDefaults(modelName);
    // get model details and check results
    // 
    Optional<ModelOverview> overviewOptional = COMET_API.getRegistryModelDetails(registryName, SHARED_EXPERIMENT.getWorkspaceName());
    assertTrue(overviewOptional.isPresent(), "overview expected");
    ModelOverview overview = overviewOptional.get();
    assertEquals(registryName, overview.getModelName(), "wrong name");
    assertEquals(SOME_DESCRIPTION, overview.getDescription(), "wrong description");
    assertTrue(overview.isPublic(), "must be public");
    assertEquals(1L, overview.getNumberOfVersions(), "wrong number of versions");
    assertNotNull(overview.getUserName(), "user name expected");
    assertNotNull(overview.getCreatedAt(), "createdAt expected");
    assertNotNull(overview.getLastUpdated(), "last updated expected");
    assertNotNull(overview.getVersions(), "at least one version expected");
    ModelVersionOverview version = overview.getVersions().get(0);
    assertEquals("1.0.0", version.getVersion(), "wrong version");
    assertEquals(SOME_COMMENT, version.getComment(), "wrong version's comment");
    assertEquals(Collections.singletonList(SOME_STAGE), version.getStages(), "wrong stages");
    assertNotNull(version.getUserName(), "user name expected");
    assertNotNull(version.getRestApiUrl(), "REST API URL missing");
    assertNotNull(version.getCreatedAt(), "createdAt expected");
    assertNotNull(version.getLastUpdated(), "last updated expected");
    assertNotNull(version.getAssets(), "assets expected");
    String[] fileNames = toAssetFileNames(assetFolderFiles);
    assertEquals(fileNames.length, version.getAssets().size(), "wrong assets number");
}
Also used : RegistryModelOverview(ml.comet.experiment.impl.rest.RegistryModelOverview) ModelOverview(ml.comet.experiment.registrymodel.ModelOverview) LogMessages.getString(ml.comet.experiment.impl.resources.LogMessages.getString) ModelVersionOverview(ml.comet.experiment.registrymodel.ModelVersionOverview) Test(org.junit.jupiter.api.Test)

Aggregations

ModelOverview (ml.comet.experiment.registrymodel.ModelOverview)8 LogMessages.getString (ml.comet.experiment.impl.resources.LogMessages.getString)6 ModelVersionOverview (ml.comet.experiment.registrymodel.ModelVersionOverview)5 RegistryModelOverview (ml.comet.experiment.impl.rest.RegistryModelOverview)4 Test (org.junit.jupiter.api.Test)4 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 CometApi (ml.comet.experiment.CometApi)2 RestApiResponse (ml.comet.experiment.impl.rest.RestApiResponse)2 ModelNotFoundException (ml.comet.experiment.registrymodel.ModelNotFoundException)2 Observable (io.reactivex.rxjava3.core.Observable)1 Single (io.reactivex.rxjava3.core.Single)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 Files (java.nio.file.Files)1 CREATE_NEW (java.nio.file.StandardOpenOption.CREATE_NEW)1 Collections (java.util.Collections)1