Class ArtifactFunctions
- Namespace
- OptunaSharp.Artifacts
- Assembly
- OptunaSharp.dll
Module-level artifact functions: upload_artifact, download_artifact,
get_all_artifact_meta.
public static class ArtifactFunctions
- Inheritance
-
ArtifactFunctions
- Inherited Members
Methods
DownloadArtifact(IArtifactStore, string, string)
Download an artifact from the artifact store (Python download_artifact).
public static void DownloadArtifact(IArtifactStore artifactStore, string filePath, string artifactId)
Parameters
artifactStoreIArtifactStoreAn artifact store.
filePathstringA path to save the downloaded artifact.
artifactIdstringThe identifier of the artifact to download.
Remarks
Both streams are disposed on failure, but a partially written destination file is retained.
Exceptions
- FileExistsError
The destination already exists, as a file or a directory: Python's
FileExistsError("File already exists: …"), NumSharp's class since 0.81.0 (an IOException, so acatch (IOException)still sees it).- IOException
File copying fails.
- ArtifactNotFound
The requested artifact does not exist.
- UnauthorizedAccessException
The destination cannot be written.
GetAllArtifactMeta(object, BaseStorage?)
List the associated artifact information of the provided trial or study
(Python get_all_artifact_meta). If a Study is provided, the
artifacts uploaded to the study are returned, not those of all its trials.
public static List<ArtifactMeta> GetAllArtifactMeta(object studyOrTrial, BaseStorage? storage = null)
Parameters
studyOrTrialobjectTrial, FrozenTrial, or Study whose artifact metadata is requested.
storageBaseStorageStorage backend holding study and trial records.
Returns
- List<ArtifactMeta>
Metadata attached directly to the supplied study or trial.
Exceptions
- ValueError
No storage can be resolved, or stored metadata is not valid JSON.
- TypeError
The object is neither Trial, FrozenTrial, nor Study.
- InvalidCastException
Stored artifact metadata has an incompatible shape.
- KeyNotFoundException
A required metadata field is missing.
UploadArtifact(IArtifactStore, string, object, BaseStorage?, string?, string?)
Upload an artifact to the artifact store (Python upload_artifact).
public static string UploadArtifact(IArtifactStore artifactStore, string filePath, object studyOrTrial, BaseStorage? storage = null, string? mimetype = null, string? encoding = null)
Parameters
artifactStoreIArtifactStoreAn artifact store.
filePathstringA path to the file to be uploaded.
studyOrTrialobjectA Trial, FrozenTrial or Study.
storageBaseStorageA storage object. Required only if
studyOrTrialis a FrozenTrial.mimetypestringA MIME type of the artifact; guessed from the file extension when omitted.
encodingstringA Content-Encoding of the artifact; guessed from the file extension when omitted.
Returns
- string
An artifact ID.
Remarks
Metadata is stored before the content is uploaded. An upload failure can leave metadata pointing to absent or partial content; the operation is not transactional.
Exceptions
- ValueError
No storage can be resolved for the supplied object.
- TypeError
The object is neither Trial, FrozenTrial, nor Study.
- UpdateFinishedTrialError
Metadata is written to a finished trial.
- IOException
The local input file cannot be read.
- UnauthorizedAccessException
Read access to the input file is denied.
- Exception
The artifact or metadata backend fails.