Class: CodeRunner::Trinopt

Inherits:
Run
  • Object
show all
Defined in:
lib/trinoptcrmod/trinopt.rb

Overview

This is a customised subclass of the CodeRunner::Run class which is designed to run the CodeRunner/Trinity optimisation framework

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run_optimisation(id = ) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/trinoptcrmod/trinopt.rb', line 104

def self.run_optimisation(id = ARGV[-1])
MPI.Init
  @runner = CodeRunner.fetch_runner(Y: '../../', U: true)
  #@run = @runner.run_list[id.to_i]
  @run = self.load(Dir.pwd, @runner)
  #raise "Can't find run with id #{id}; #{@runner.run_list.keys}" unless @run
  opt = CodeRunner::Trinity::Optimisation.new(
    @run.output, @run.search
  )
  @trinity_runner = CodeRunner.fetch_runner(Y: 'trinity_runs', X: '/dev/null', C: 'trinity', D: @run.trinity_defaults)
  @trinity_runner.nprocs = MPI::Comm::WORLD.size
  @chease_runner = CodeRunner.fetch_runner(Y: 'gs_runs', X: @run.chease_exec, C: 'chease', D: @run.gs_defaults)
  @chease_runner.nprocs = '1'
  #Dir.chdir('trinity_runs'){@trinity_runner.run_class.use_new_defaults_file('rake_test_opt', 'ifspppl_chease_input.trin')}
  #Dir.chdir(tfolderchease){@chease_runner.run_class.use_new_defaults_file('rake_test_opt_chease', 'chease_example.in')}
  #assert_equal([:trinity, :powerin], opt.optimisation_variables[0])
  opt.trinity_runner = @trinity_runner
  opt.chease_runner = @chease_runner
  opt.serial_optimise(:simplex, @run)
  MPI.Finalize
end

Instance Method Details

#check_parametersObject



100
101
# File 'lib/trinoptcrmod/trinopt.rb', line 100

def check_parameters
end

#generate_component_runsObject



142
143
144
# File 'lib/trinoptcrmod/trinopt.rb', line 142

def generate_component_runs
	#puts "HERE"
end

#generate_input_fileObject

This is a hook which gets called just before submitting a simulation. It sets up the folder and generates any necessary input files.



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/trinoptcrmod/trinopt.rb', line 76

def generate_input_file
		check_parameters
		if @restart_id
			@runner.run_list[@restart_id].restart(self)
		end
      File.open("driver_script.rb", "w"){|f| f.puts optimisation_script}
      FileUtils.makedirs('trinity_runs')
      FileUtils.makedirs('gs_runs')
      FileUtils.ln_s("../../#{@trinity_defaults}_defaults.rb", "trinity_runs")
      FileUtils.ln_s("../../#{@gs_defaults}_defaults.rb", "gs_runs")
      save
end

#get_statusObject



163
164
165
# File 'lib/trinoptcrmod/trinopt.rb', line 163

def get_status
	return :Unknown
end

#input_file_extensionObject



168
169
170
# File 'lib/trinoptcrmod/trinopt.rb', line 168

def input_file_extension
	''
end

#optimisation_scriptObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/trinoptcrmod/trinopt.rb', line 89

def optimisation_script
  return <<EOF
  require 'coderunner'
  CodeRunner.setup_run_class('trinity')
  CodeRunner.setup_run_class('trinopt')
  require 'trinitycrdriver'
  require 'trinitycrdriver/optimisation'
  CodeRunner::Trinopt.run_optimisation(#@id)
EOF
end

#parameter_stringObject

Parameters which follow the Trinity executable, in this case just the input file.



135
136
137
# File 'lib/trinoptcrmod/trinopt.rb', line 135

def parameter_string
	" driver_script.rb #@id"
end

#parameter_transitionObject



139
140
# File 'lib/trinoptcrmod/trinopt.rb', line 139

def parameter_transition
end

A hook which gets called when printing the standard run information to the screen using the status command.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trinoptcrmod/trinopt.rb', line 42

def print_out_line
	#p ['id', id, 'ctd', ctd]
	#p rcp.results.zip(rcp.results.map{|r| send(r)})
	name = @run_name
	name += " (res: #@restart_id)" if @restart_id
	beginning = sprintf("%2d:%d %-60s %1s:%2.1f(%s) %3s%1s",  @id, @job_no, name, @status.to_s[0,1],  @run_time.to_f / 60.0, @nprocs.to_s, percent_complete, "%")
	if ctd
		#beginning += sprintf("Q:%f, Pfusion:%f MW, Ti0:%f keV, Te0:%f keV, n0:%f x10^20", fusionQ, pfus, ti0, te0, ne0)
	end
	beginning += "  ---#{@comment}" if @comment
	beginning
end

#process_directory_code_specificObject

This method, as its name suggests, is called whenever CodeRunner is asked to analyse a run directory. This happens if the run status is not :Complete, or if the user has specified recalc_all(-A on the command line) or reprocess_all (-a on the command line).



152
153
154
155
156
157
158
159
160
161
# File 'lib/trinoptcrmod/trinopt.rb', line 152

def process_directory_code_specific
	get_status
	#p ['id is', id, 'ctd is ', ctd]
	#if ctd
		#get_global_results 
	#end
	#p ['fusionQ is ', fusionQ]
	#@percent_complete = completed_timesteps.to_f / ntstep.to_f * 100.0
    @percent_complete = 0.0
end

#restart(new_run) ⇒ Object

Modify new_run so that it becomes a restart of self. Adusts all the parameters of the new run to be equal to the parameters of the run that calls this function, and sets up its run name correctly



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/trinoptcrmod/trinopt.rb', line 61

def restart(new_run)
	#new_run = self.dup
	(rcp.variables).each{|v| new_run.set(v, send(v)) if send(v)}
	new_run.is_a_restart = true
	new_run.restart_id = @id
	new_run.restart_run_name = @run_name
	new_run.nopt = -1
	new_run.run_name = nil
	new_run.naming_pars = @naming_pars
	new_run.update_submission_parameters(new_run.parameter_hash.inspect, false) if new_run.parameter_hash 
	new_run.naming_pars.delete(:restart_id)
	new_run.generate_run_name
    raise "This function is not complete"
end

#vim_outputObject Also known as: vo



128
129
130
# File 'lib/trinoptcrmod/trinopt.rb', line 128

def vim_output
  system "vim -Ro #{output_file} #{error_file}"
end