Class: Ace::Sim::Molecules::SessionStore
- Inherits:
-
Object
- Object
- Ace::Sim::Molecules::SessionStore
show all
- Defined in:
- lib/ace/sim/molecules/session_store.rb
Defined Under Namespace
Classes: RunDirectoryExistsError
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#chain_dir(run_dir, provider, iteration) ⇒ Object
-
#final_dir(run_dir) ⇒ Object
-
#initialize(cache_root: nil) ⇒ SessionStore
constructor
A new instance of SessionStore.
-
#prepare_run(run_id) ⇒ Object
-
#prepare_step_dir(run_dir, provider, iteration, step_index, step_name) ⇒ Object
-
#run_dir_for(run_id) ⇒ Object
-
#write_session(run_dir, payload) ⇒ Object
-
#write_synthesis(run_dir, payload) ⇒ Object
-
#write_text(path, content) ⇒ Object
-
#write_yaml(path, payload) ⇒ Object
Constructor Details
#initialize(cache_root: nil) ⇒ SessionStore
Returns a new instance of SessionStore.
14
15
16
|
# File 'lib/ace/sim/molecules/session_store.rb', line 14
def initialize(cache_root: nil)
@cache_root = cache_root || Ace::Sim.get("sim", "cache_root") || ".ace-local/sim"
end
|
Instance Attribute Details
#cache_root ⇒ Object
Returns the value of attribute cache_root.
12
13
14
|
# File 'lib/ace/sim/molecules/session_store.rb', line 12
def cache_root
@cache_root
end
|
Instance Method Details
#chain_dir(run_dir, provider, iteration) ⇒ Object
30
31
32
33
|
# File 'lib/ace/sim/molecules/session_store.rb', line 30
def chain_dir(run_dir, provider, iteration)
provider_slug = provider.to_s.gsub(/[^a-zA-Z0-9_-]/, "-")
File.join(run_dir, "chains", "#{provider_slug}-#{iteration}")
end
|
#final_dir(run_dir) ⇒ Object
35
36
37
|
# File 'lib/ace/sim/molecules/session_store.rb', line 35
def final_dir(run_dir)
File.join(run_dir, "final")
end
|
#prepare_run(run_id) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/ace/sim/molecules/session_store.rb', line 22
def prepare_run(run_id)
run_dir = run_dir_for(run_id)
raise RunDirectoryExistsError, "Run directory already exists: #{run_dir}" if Dir.exist?(run_dir)
FileUtils.mkdir_p(File.join(run_dir, "chains"))
run_dir
end
|
#prepare_step_dir(run_dir, provider, iteration, step_index, step_name) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/ace/sim/molecules/session_store.rb', line 39
def prepare_step_dir(run_dir, provider, iteration, step_index, step_name)
dirname = format("%02d-%s", step_index, step_name)
dir = File.join(chain_dir(run_dir, provider, iteration), dirname)
FileUtils.mkdir_p(dir)
dir
end
|
#run_dir_for(run_id) ⇒ Object
18
19
20
|
# File 'lib/ace/sim/molecules/session_store.rb', line 18
def run_dir_for(run_id)
File.join(cache_root, "simulations", run_id)
end
|
#write_session(run_dir, payload) ⇒ Object
46
47
48
|
# File 'lib/ace/sim/molecules/session_store.rb', line 46
def write_session(run_dir, payload)
write_yaml(File.join(run_dir, "session.yml"), payload)
end
|
#write_synthesis(run_dir, payload) ⇒ Object
50
51
52
|
# File 'lib/ace/sim/molecules/session_store.rb', line 50
def write_synthesis(run_dir, payload)
write_yaml(File.join(run_dir, "synthesis.yml"), payload)
end
|
#write_text(path, content) ⇒ Object
58
59
60
61
62
|
# File 'lib/ace/sim/molecules/session_store.rb', line 58
def write_text(path, content)
FileUtils.mkdir_p(File.dirname(path))
File.write(path, content)
path
end
|
#write_yaml(path, payload) ⇒ Object
54
55
56
|
# File 'lib/ace/sim/molecules/session_store.rb', line 54
def write_yaml(path, payload)
write_text(path, YAML.dump(payload))
end
|