Class: GEPA::Logging::ExperimentTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/gepa/logging/experiment_tracker.rb

Overview

Lightweight experiment tracker that records metrics locally and can fan out to user hooks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subscribers: []) ⇒ ExperimentTracker

Returns a new instance of ExperimentTracker.



9
10
11
12
# File 'lib/gepa/logging/experiment_tracker.rb', line 9

def initialize(subscribers: [])
  @subscribers = Array(subscribers)
  @events = []
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



7
8
9
# File 'lib/gepa/logging/experiment_tracker.rb', line 7

def events
  @events
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/gepa/logging/experiment_tracker.rb', line 36

def active?
  !@events.empty?
end

#each_event(&block) ⇒ Object



40
41
42
# File 'lib/gepa/logging/experiment_tracker.rb', line 40

def each_event(&block)
  @events.each(&block)
end

#end_runObject



34
# File 'lib/gepa/logging/experiment_tracker.rb', line 34

def end_run; end

#initialize_backendsObject



19
# File 'lib/gepa/logging/experiment_tracker.rb', line 19

def initialize_backends; end

#log_metrics(metrics, step: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/gepa/logging/experiment_tracker.rb', line 23

def log_metrics(metrics, step: nil)
  entry = { metrics: symbolize_keys(metrics), step: step }
  @events << entry

  @subscribers.each do |subscriber|
    subscriber.call(entry)
  rescue StandardError => e
    DSPy.log('gepa.experiment_tracker.error', error: e.message)
  end
end

#start_runObject



21
# File 'lib/gepa/logging/experiment_tracker.rb', line 21

def start_run; end

#with_subscriber(proc = nil, &block) ⇒ Object



14
15
16
17
# File 'lib/gepa/logging/experiment_tracker.rb', line 14

def with_subscriber(proc = nil, &block)
  @subscribers << (proc || block)
  self
end