Table of Contents

Class ExperimentRun<T>

Namespace
AiDotNet.Models
Assembly
AiDotNet.dll

Represents a single training run within an experiment.

public class ExperimentRun<T> : IExperimentRun<T>

Type Parameters

T

The numeric data type used for calculations.

Inheritance
ExperimentRun<T>
Implements
Inherited Members

Remarks

For Beginners: A run captures all the details of one training session, including parameters, metrics, and artifacts.

This class is thread-safe and can be safely accessed from multiple threads concurrently.

Constructors

ExperimentRun(string, string?, Dictionary<string, string>?)

Initializes a new instance of the ExperimentRun class.

public ExperimentRun(string experimentId, string? runName = null, Dictionary<string, string>? tags = null)

Parameters

experimentId string

The experiment ID this run belongs to.

runName string

Optional name for the run.

tags Dictionary<string, string>

Optional tags.

Properties

EndTime

Gets the timestamp when the run ended.

[JsonProperty]
public DateTime? EndTime { get; }

Property Value

DateTime?

ExperimentId

Gets the experiment ID this run belongs to.

[JsonProperty]
public string ExperimentId { get; }

Property Value

string

RunId

Gets the unique identifier for this run.

[JsonProperty]
public string RunId { get; }

Property Value

string

RunName

Gets or sets the name of this run.

public string? RunName { get; set; }

Property Value

string

StartTime

Gets the timestamp when the run was started.

[JsonProperty]
public DateTime StartTime { get; }

Property Value

DateTime

Status

Gets the current status of the run.

[JsonProperty]
public string Status { get; }

Property Value

string

Tags

Gets the tags associated with this run in a thread-safe manner.

[JsonProperty]
public ConcurrentDictionary<string, string> Tags { get; }

Property Value

ConcurrentDictionary<string, string>

Methods

AddNote(string)

Adds a note or comment to the run.

public void AddNote(string note)

Parameters

note string

Complete()

Marks the run as completed successfully.

public void Complete()

Fail(string?)

Marks the run as failed with an optional error message.

public void Fail(string? errorMessage = null)

Parameters

errorMessage string

GetArtifacts()

Gets all artifacts logged for this run.

public List<string> GetArtifacts()

Returns

List<string>

GetDuration()

Gets the duration of the run.

public TimeSpan? GetDuration()

Returns

TimeSpan?

GetErrorMessage()

Gets the error message if the run failed.

public string? GetErrorMessage()

Returns

string

GetLatestMetric(string)

Gets the latest value for a specific metric.

public T? GetLatestMetric(string metricName)

Parameters

metricName string

Returns

T

GetMetrics()

Gets all metrics logged for this run.

public Dictionary<string, List<(int Step, T Value, DateTime Timestamp)>> GetMetrics()

Returns

Dictionary<string, List<(int Step, T Value, DateTime Timestamp)>>

GetNotes()

Gets all notes added to this run.

public List<(DateTime Timestamp, string Note)> GetNotes()

Returns

List<(DateTime Timestamp, string Note)>

GetParameters()

Gets all parameters logged for this run.

public Dictionary<string, object> GetParameters()

Returns

Dictionary<string, object>

LogArtifact(string, string?)

Logs an artifact (file) associated with this run.

public void LogArtifact(string localPath, string? artifactPath = null)

Parameters

localPath string
artifactPath string

LogArtifacts(string, string?)

Logs a directory of artifacts.

public void LogArtifacts(string localDir, string? artifactPath = null)

Parameters

localDir string
artifactPath string

LogMetric(string, T, int, DateTime?)

Logs a metric value at a specific step/iteration.

public void LogMetric(string key, T value, int step = 0, DateTime? timestamp = null)

Parameters

key string
value T
step int
timestamp DateTime?

LogMetrics(Dictionary<string, T>, int, DateTime?)

Logs multiple metrics at once for a specific step.

public void LogMetrics(Dictionary<string, T> metrics, int step = 0, DateTime? timestamp = null)

Parameters

metrics Dictionary<string, T>
step int
timestamp DateTime?

LogModel<TInput, TOutput, TMetadata>(IModel<TInput, TOutput, TMetadata>, string?)

Logs a trained model as an artifact.

public void LogModel<TInput, TOutput, TMetadata>(IModel<TInput, TOutput, TMetadata> model, string? artifactPath = null) where TInput : class where TOutput : class where TMetadata : class

Parameters

model IModel<TInput, TOutput, TMetadata>
artifactPath string

Type Parameters

TInput
TOutput
TMetadata

LogParameter(string, object)

Logs a single parameter value for this run.

public void LogParameter(string key, object value)

Parameters

key string
value object

LogParameters(Dictionary<string, object>)

Logs multiple parameters at once.

public void LogParameters(Dictionary<string, object> parameters)

Parameters

parameters Dictionary<string, object>