Search in sources :

Example 1 with AssetImpl

use of ml.comet.experiment.impl.asset.AssetImpl in project comet-java-sdk by comet-ml.

the class BaseExperimentAsync method logAssetFileAsync.

/**
 * Asynchronous version that only logs any received exceptions or failures.
 *
 * @param file         The file asset to be stored
 * @param fileName     The file name under which the asset should be stored in Comet. E.g. "someFile.txt"
 * @param overwrite    Whether to overwrite files of the same name in Comet
 * @param assetType    the type of the asset.
 * @param groupingName optional name of group this asset should belong.
 * @param metadata     the optional metadata to associate.
 * @param onComplete   The optional action to be invoked when this operation asynchronously completes.
 *                     Can be {@code null} if not interested in completion signal.
 */
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
void logAssetFileAsync(@NonNull File file, @NonNull String fileName, boolean overwrite, @NonNull Optional<String> assetType, @NonNull Optional<String> groupingName, @NonNull Optional<Map<String, Object>> metadata, @NonNull ExperimentContext context, @NonNull Optional<Action> onComplete) {
    this.updateContext(context);
    AssetImpl asset = createAssetFromFile(file, Optional.of(fileName), overwrite, metadata, assetType);
    groupingName.ifPresent(asset::setGroupingName);
    this.logAssetAsync(asset, onComplete);
}
Also used : AssetImpl(ml.comet.experiment.impl.asset.AssetImpl) RemoteAssetImpl(ml.comet.experiment.impl.asset.RemoteAssetImpl) ArtifactAssetImpl(ml.comet.experiment.impl.asset.ArtifactAssetImpl)

Example 2 with AssetImpl

use of ml.comet.experiment.impl.asset.AssetImpl in project comet-java-sdk by comet-ml.

the class AssetUtils method createAssetFromFile.

/**
 * Creates the {@link Asset} from the local file.
 *
 * @param file        the asset file.
 * @param logicalPath the logical name for the asset file.
 * @param overwrite   if {@code true} mark as override
 * @param metadata    the metadata to associate with asset. The dictionary values must be JSON compatible.
 * @param type        the type of the asset. If not specified the default type {@code AssetType.ASSET}
 *                    will be assigned.
 * @return the instance of the {@link AssetImpl} from the local file.
 */
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public static AssetImpl createAssetFromFile(@NonNull File file, Optional<String> logicalPath, boolean overwrite, @NonNull Optional<Map<String, Object>> metadata, @NonNull Optional<String> type) {
    String logicalFileName = logicalPath.orElse(file.getName());
    AssetImpl asset = new AssetImpl();
    asset.setRawFile(file);
    asset.setLogicalPath(logicalFileName);
    asset.setFileExtension(FilenameUtils.getExtension(logicalFileName));
    return updateAsset(asset, overwrite, metadata, type);
}
Also used : AssetImpl(ml.comet.experiment.impl.asset.AssetImpl) RemoteAssetImpl(ml.comet.experiment.impl.asset.RemoteAssetImpl)

Example 3 with AssetImpl

use of ml.comet.experiment.impl.asset.AssetImpl in project comet-java-sdk by comet-ml.

the class AssetUtils method createAssetFromData.

/**
 * Creates the {@link Asset} from the file-like data.
 *
 * @param data        the asset's data.
 * @param logicalPath the logical name for the asset file.
 * @param overwrite   if {@code true} mark as override
 * @param metadata    the metadata to associate with asset. The dictionary values must be JSON compatible.
 * @param type        the type of the asset. If not specified the default type {@code AssetType.ASSET_TYPE_ASSET}
 *                    will be assigned.
 * @return the instance of the {@link AssetImpl} from the file-like data.
 */
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public static AssetImpl createAssetFromData(byte[] data, @NonNull String logicalPath, boolean overwrite, @NonNull Optional<Map<String, Object>> metadata, @NonNull Optional<String> type) {
    AssetImpl asset = new AssetImpl();
    asset.setRawFileLikeData(data);
    asset.setLogicalPath(logicalPath);
    asset.setFileExtension(FilenameUtils.getExtension(logicalPath));
    return updateAsset(asset, overwrite, metadata, type);
}
Also used : AssetImpl(ml.comet.experiment.impl.asset.AssetImpl) RemoteAssetImpl(ml.comet.experiment.impl.asset.RemoteAssetImpl)

Example 4 with AssetImpl

use of ml.comet.experiment.impl.asset.AssetImpl in project comet-java-sdk by comet-ml.

the class AssetUtils method mapToFileAsset.

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
static AssetImpl mapToFileAsset(@NonNull File folder, @NonNull Path assetPath, boolean logFilePath, boolean prefixWithFolderName, @NonNull Optional<Map<String, Object>> metadata, @NonNull Optional<String> type, @NonNull Optional<String> groupingName) {
    AssetImpl asset = new AssetImpl();
    asset.setRawFile(assetPath.toFile());
    String fileName = FileUtils.resolveAssetFileName(folder, assetPath, logFilePath, prefixWithFolderName);
    asset.setLogicalPath(fileName);
    asset.setFileExtension(FilenameUtils.getExtension(fileName));
    metadata.ifPresent(asset::setMetadata);
    if (type.isPresent()) {
        asset.setType(type.get());
    } else {
        asset.setType(AssetType.ASSET.type());
    }
    groupingName.ifPresent(asset::setGroupingName);
    return asset;
}
Also used : AssetImpl(ml.comet.experiment.impl.asset.AssetImpl) RemoteAssetImpl(ml.comet.experiment.impl.asset.RemoteAssetImpl)

Example 5 with AssetImpl

use of ml.comet.experiment.impl.asset.AssetImpl in project comet-java-sdk by comet-ml.

the class BaseExperiment method logCode.

@Override
public void logCode(@NonNull String code, @NonNull String logicalPath, @NonNull ExperimentContext context) {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("log raw source code, file name: {}", logicalPath);
    }
    AssetImpl asset = createAssetFromData(code.getBytes(StandardCharsets.UTF_8), logicalPath, false, empty(), Optional.of(SOURCE_CODE.type()));
    this.logAsset(asset, context);
}
Also used : AssetImpl(ml.comet.experiment.impl.asset.AssetImpl) ArtifactAssetImpl(ml.comet.experiment.impl.asset.ArtifactAssetImpl)

Aggregations

AssetImpl (ml.comet.experiment.impl.asset.AssetImpl)15 ArtifactAssetImpl (ml.comet.experiment.impl.asset.ArtifactAssetImpl)8 RemoteAssetImpl (ml.comet.experiment.impl.asset.RemoteAssetImpl)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Test (org.junit.jupiter.api.Test)3 File (java.io.File)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ExperimentContext (ml.comet.experiment.context.ExperimentContext)1 RestApiResponse (ml.comet.experiment.impl.rest.RestApiResponse)1 AssetUtils.createAssetFromFile (ml.comet.experiment.impl.utils.AssetUtils.createAssetFromFile)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1