Class: CodeRunner::Trinity::Optimisation
- Inherits:
-
Object
- Object
- CodeRunner::Trinity::Optimisation
- Includes:
- GSL::MultiMin
- Defined in:
- lib/trinitycrdriver/optimisation.rb
Instance Attribute Summary collapse
-
#chease_runner ⇒ Object
Returns the value of attribute chease_runner.
-
#optimisation_spec ⇒ Object
readonly
code_name is either trinity or chease (both can be used simultaneously).
-
#optimisation_variables ⇒ Object
readonly
Returns the value of attribute optimisation_variables.
-
#trinity_runner ⇒ Object
Returns the value of attribute trinity_runner.
Instance Method Summary collapse
-
#dimension ⇒ Object
p [‘optimisation_variables’, @optimisation_variables].
- #func(v) ⇒ Object
-
#initialize(optimised_quantity, optimisation_spec) ⇒ Optimisation
constructor
A new instance of Optimisation.
- #serial_optimise(optimisation_method, parameters_obj) ⇒ Object
Constructor Details
#initialize(optimised_quantity, optimisation_spec) ⇒ Optimisation
Returns a new instance of Optimisation.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/trinitycrdriver/optimisation.rb', line 12 def initialize(optimised_quantity, optimisation_spec) #@folder = folder @optimised_quantity = optimised_quantity @optimisation_spec = optimisation_spec @optimisation_variables = optimisation_spec.map{|code, hash| hash.map{|var, pars| [code, var]}}.flatten(1) @optimisation_starts = optimisation_spec.map{|code, hash| hash.map{|var, pars| pars[0]}}.flatten(1) @optimisation_steps = optimisation_spec.map{|code, hash| hash.map{|var, pars| pars[1]}}.flatten(1) #@runner = CodeRunner.fetch_runner( #p ['optimisation_variables', @optimisation_variables] end |
Instance Attribute Details
#chease_runner ⇒ Object
Returns the value of attribute chease_runner.
11 12 13 |
# File 'lib/trinitycrdriver/optimisation.rb', line 11 def chease_runner @chease_runner end |
#optimisation_spec ⇒ Object (readonly)
code_name is either trinity or chease (both can be used simultaneously)
8 9 10 |
# File 'lib/trinitycrdriver/optimisation.rb', line 8 def optimisation_spec @optimisation_spec end |
#optimisation_variables ⇒ Object (readonly)
Returns the value of attribute optimisation_variables.
9 10 11 |
# File 'lib/trinitycrdriver/optimisation.rb', line 9 def optimisation_variables @optimisation_variables end |
#trinity_runner ⇒ Object
Returns the value of attribute trinity_runner.
10 11 12 |
# File 'lib/trinitycrdriver/optimisation.rb', line 10 def trinity_runner @trinity_runner end |
Instance Method Details
#dimension ⇒ Object
p [‘optimisation_variables’, @optimisation_variables]
22 23 24 |
# File 'lib/trinitycrdriver/optimisation.rb', line 22 def dimension @optimisation_variables.size end |
#func(v) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/trinitycrdriver/optimisation.rb', line 46 def func(v) pars = {} pars[:chease] = {} pars[:trinity] = {} for i in 0...v.size code, varname = @optimisation_variables[i] val = v[i] pars[code][varname] = val end if not @first_run_done pars[:trinity][:ntstep] = 300 else #pars[:trinity].delete(:ntstep) pars[:trinity][:ntstep] = 100 end pars[:chease][:ap] = [0.3,0.5,0.4,0.0,0.4,0.0,0.0] pars[:chease][:at] = [0.16,1.0,1.0,-1.1,-1.1] trinity_runner.run_class.instance_variable_set(:@mpi_communicator, MPI::Comm::WORLD) if false and trinity_runner.run_list.size > 0 else crun = chease_runner.run_class.new(chease_runner) crun.update_submission_parameters(pars[:chease].inspect) if @first_run_done #crun.nppfun=4 #crun.neqdsk=0 #crun.expeq_file = trinity_runner.run_list[@id] end if chease_runner.run_list.size > 0 crun.restart_id = @cid end chease_runner.submit(crun) crun = chease_runner.run_list[@cid = chease_runner.max_id] crun.recheck chease_runner.update #chease_runner.print_out(0) #FileUtils.cp(crun.directory + '/ogyropsi.dat', trinity_runner.root_folder + '/.') run = trinity_runner.run_class.new(trinity_runner) run.update_submission_parameters(pars[:trinity].inspect) run.gs_folder = crun.directory run.evolve_geometry = ".true." #trinity_runner.run_class.instance_variable_set(:@delay_execution, true) if trinity_runner.run_list.size > 0 run.restart_id = @id end trinity_runner.submit(run) run = trinity_runner.run_list[@id = trinity_runner.max_id] run.recheck trinity_runner.update #trinity_runner.print_out(0) result = run.send(@optimised_quantity) p ['result is ', result] @first_run_done = true return -result end #v.square.sum end |
#serial_optimise(optimisation_method, parameters_obj) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/trinitycrdriver/optimisation.rb', line 25 def serial_optimise(optimisation_method, parameters_obj) optimisation_meth = case optimisation_method when :simplex FMinimizer::NMSIMPLEX else raise "Unknown optimisation_method" end opt = FMinimizer.alloc(optimisation_meth, @optimisation_variables.size) func = Proc.new{|v, optimiser| optimiser.func(v)} gsl_func = Function.alloc(func, dimension) gsl_func.set_params(self) opt.set(gsl_func, @optimisation_starts.to_gslv, @optimisation_steps.to_gslv) parameters_obj.nit.times do |i| opt.iterate p ['status', opt.x, opt.minimum, i, parameters_obj.nit] end p 'heellllllo' MPI.Finalize end |