Class: NERA::JobScript
- Inherits:
-
Object
- Object
- NERA::JobScript
- Defined in:
- lib/nera/nera_job_script.rb
Overview
This class create & parse job scripts
Instance Method Summary collapse
-
#create_script(job_id, sim_id, param_id, sim_inst, run_stat) ⇒ Object
create job script ——————–.
-
#initialize(db_folder) ⇒ JobScript
constructor
db_folder is the instance of DbFolders.
-
#parse_status(path_stat) ⇒ Object
parse status file ——————–.
Constructor Details
#initialize(db_folder) ⇒ JobScript
db_folder is the instance of DbFolders
20 21 22 23 24 25 |
# File 'lib/nera/nera_job_script.rb', line 20 def initialize( db_folder) unless db_folder.instance_of?(NERA::DbFolders) then raise ArgumentError, "Argument must be an instance of NERA::DbFolders." end @db_folder = db_folder end |
Instance Method Details
#create_script(job_id, sim_id, param_id, sim_inst, run_stat) ⇒ Object
create job script ——————–
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/nera/nera_job_script.rb', line 108 def create_script(job_id, sim_id, param_id, sim_inst, run_stat) unless job_id.is_a?(Integer) and sim_id.is_a?(Integer) and param_id.is_a?(Integer) raise ArgumentError, "Each ID of Job, Simulation and Parameter must be an Integer." end unless sim_inst.kind_of?(NERA::Simulator) raise ArgumentError, "Simulation_Instance must be a subclass of NERA::Simulator." else # if sim_inst.param == {} # raise ArgumentError, "@param in Simulation_Instance must be set a parameter." # end end unless run_stat.is_a?(Array) raise ArgumentError, "Run_Status must be an Array." else run_stat.each do | stat | unless stat.has_key?(:id) and stat.has_key?(:seed) raise ArgumentError, "Run Status must have keys, :id and :seed." end end end run_ids =[] seeds = [] run_stat.each do |run_info| run_ids << run_info[:id] seeds << run_info[:seed] end job_info ={ :job_id => job_id, :job_script_id => sprintf("j%06d",job_id), :database => File.basename( @db_folder.path_to_simulator_layer), :simulator => sim_inst.class.to_s, :sim_id => sim_id, :param_id => param_id, :params => sim_inst.param, # {:L => 256, :K => 0.22325, :tmax => 512}, :run_ids => run_ids, :seeds => seeds, :execs => seeds.map do |sed| sim_inst.simulate_command( sed).split("\n").join(' && ').sub(/;$/,'') end } path_job_script = @db_folder.path_to_job_script( job_id) unless FileTest.directory?(@db_folder.path_to_job_layer) raise "must not happen" end if FileTest.exist?(path_job_script) raise "must not happen" end File.open(path_job_script,"w") do |io| io.puts job_script_body(job_info) io.flush end return path_job_script end |
#parse_status(path_stat) ⇒ Object
parse status file ——————–
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/nera/nera_job_script.rb', line 170 def parse_status(path_stat) unless path_stat.is_a?(String) and FileTest.exists?(path_stat) raise ArgumentError, "#{path_stat} is not valid status file." end str = "" File.open(path_stat).each do |line| str += line end header = {} body = {} = {} begin eval(str) rescue raise RuntimeError, "This nera_status.rb is not valid." end job_info = header.merge( ) body.each_pair do |run_id, info| info[:real_time] = 0.0 info[:user_time] = 0.0 info[:output].each_line do |line| if line =~ /^real [-+]?(?:[0-9]+(\.[0-9]*)?|(\.[0-9]+))([eE][-+]?[0-9]+)?/ info[:real_time] = line.sub(/^real /,'').to_f elsif line =~ /^user [-+]?(?:[0-9]+(\.[0-9]*)?|(\.[0-9]+))([eE][-+]?[0-9]+)?/ info[:user_time] += line.sub(/^user /,'').to_f end end end return job_info, body end |