Class: Lemans::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/lemans/run.rb

Overview

A whole run: every task, k attempts each, several trials in flight. Concurrency and resume exist because a sequential run is a day of wall clock.

Defined Under Namespace

Classes: Attempt, Shutdown

Instance Method Summary collapse

Constructor Details

#initialize(bench:, tasks:, agent_name:, runs_dir:, attempts: 1, concurrency: 4, resume: false, model: nil, backend: "daytona") ⇒ Run

rubocop:disable Lint/InheritException



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lemans/run.rb', line 16

def initialize(bench:, tasks:, agent_name:, runs_dir:, attempts: 1, concurrency: 4,
               resume: false, model: nil, backend: "daytona")
  @bench = bench
  @tasks = tasks
  @agent_name = agent_name
  @runs_dir = Pathname(runs_dir)
  @attempts = attempts
  @concurrency = concurrency
  @resume = resume
  @model = Array(model)
  @backend = backend
end

Instance Method Details

#call(&report) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lemans/run.rb', line 33

def call(&report)
  begin
    @runs_dir.mkpath
  rescue SystemCallError => e
    raise ConfigError, "cannot use runs directory #{@runs_dir}: #{e.message}"
  end
  queue = Queue.new
  pending.shuffle.each { queue << _1 }
  queue.close

  results = Concurrent::Array.new
  workers = Array.new(@concurrency) { Thread.new { drain(queue, results, &report) } }
  workers.each(&:join)
  raise @abort if @abort

  summarize(results)
rescue Interrupt
  queue&.clear
  queue&.close
  workers = Array(workers).select(&:alive?)
  report&.call(:interrupted, { in_flight: workers.size })
  workers.each { _1.raise(Shutdown) }

  workers.each do |worker| # rubocop:disable Style/CombinableLoops
    worker.join
  rescue Shutdown
    # ignore: our own stop signal coming back
  end
  summarize(results || []).merge(interrupted: true)
end

#totalObject

How many attempts this run will actually schedule — resume already subtracted the retired ones.



31
# File 'lib/lemans/run.rb', line 31

def total = pending.size