Class: GEPA::Logging::ExperimentTracker
- Inherits:
-
Object
- Object
- GEPA::Logging::ExperimentTracker
- 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
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #each_event(&block) ⇒ Object
- #end_run ⇒ Object
-
#initialize(subscribers: []) ⇒ ExperimentTracker
constructor
A new instance of ExperimentTracker.
- #initialize_backends ⇒ Object
- #log_metrics(metrics, step: nil) ⇒ Object
- #start_run ⇒ Object
- #with_subscriber(proc = nil, &block) ⇒ Object
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
#events ⇒ Object (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
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_run ⇒ Object
34 |
# File 'lib/gepa/logging/experiment_tracker.rb', line 34 def end_run; end |
#initialize_backends ⇒ Object
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.) end end |
#start_run ⇒ Object
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 |