trinitycrdriver 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49e4039f446adecc1130738a3d689af2a3193c61
4
- data.tar.gz: 65142591fe93ea98359f1edf1bd2cdb9043745d3
3
+ metadata.gz: 99d128788dbcf852da53d869d20f874b57cdb6b4
4
+ data.tar.gz: eca654dc62344fc0f941784cb60c3c65b6779ea5
5
5
  SHA512:
6
- metadata.gz: 84b29e1c9e3272fba5a1b4fb5815fc4cfcfec9e8a352b8195d5b0289e2881cfe8d9beaa459083433ace8f63bd8fd38d5aebcfdf922c3bd1dca4052706a4c1353
7
- data.tar.gz: ac3d4cf4163d2be4bf1459bf2ef7d8b9d20e478958e0ba82f634704458bfec2cd20e650140ba3acb53d7abd4ef227ae173344d3ef7c550a40b0aaabdc09f4dbe
6
+ metadata.gz: 9098ed22b3dd3371c01c81728d3d83d8c6b11b3f51d0058c4dab0bc2926e2a8e0e9f4e1135b5f6e71fb9d5408cf86f8c2d5b63a37a06a891a4a9e70dce5c0523
7
+ data.tar.gz: 1a726053cdedf417eefa3b2634536592bdd5089c7781b5cbd125bb88af2e093aee0ef16582e4498cd8945c6bf0e550d0e56a895d31fe45f4573044432a44f0b0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -11,27 +11,31 @@ require 'mkmf'
11
11
 
12
12
  #$objs = srcs.collect { |f| f.sub(".c", ".o") }
13
13
  RbConfig::CONFIG['CC'] = CONFIG['CC'] = ENV['CC'] || "mpicc"
14
- RbConfig::CONFIG['CPP'] = CONFIG['CPP'] = ENV['CPP'] || "mpicc -E"
14
+ #RbConfig::CONFIG['CPP'] = CONFIG['CPP'] = ENV['CPP'] || "mpicc -E"
15
15
  p 'CONFIG[CC]', CONFIG['CC']
16
16
  crgemspec=Gem::Specification.find_by_name('coderunner')
17
17
  crconfig = crgemspec.full_gem_path
18
18
  $CPPFLAGS = " -I#{File.join(crconfig, 'include')} "+$CPPFLAGS
19
19
  p ['CPPFLAGS', $CPPFLAGS]
20
- raise "Please set the environment variable TRINITY_DIR" unless ENV['TRINITY_DIR']
21
- $LOCAL_LIBS = " -L#{ENV['TRINITY_DIR']} " + $LOCAL_LIBS
22
- $LOCAL_LIBS = " -L#{ENV['GS2']} " + $LOCAL_LIBS
23
- have_library("gfortran")
24
- have_library("netcdf")
25
- have_library("netcdff")
26
- have_library("fftw3")
27
- have_library("fftw3f")
28
- have_library("fftw3_mpi")
29
- have_library("fftw3f_mpi")
30
- have_library("simpledataio")
20
+ #raise "Please set the environment variable TRINITY_DIR" unless ENV['TRINITY_DIR']
21
+ #$LOCAL_LIBS = " -L#{ENV['TRINITY_DIR']} " + $LOCAL_LIBS
22
+ #$LOCAL_LIBS = " -L#{ENV['GS2']} " + $LOCAL_LIBS
23
+ #case ENV['GK_SYSTEM']
24
+ #when 'debian'
25
+ #have_library("gfortran")
26
+ #have_library("netcdf")
27
+ #have_library("netcdff")
28
+ #have_library("fftw3")
29
+ #have_library("fftw3f")
30
+ #have_library("fftw3_mpi")
31
+ #have_library("fftw3f_mpi")
32
+ #have_library("simpledataio")
33
+ #when 'stampede'
34
+ #end
31
35
 
32
36
  #have_library("gs2", "__gs2_main_MOD_gs2spec_from_trin")
33
- have_library("gs2")
34
- have_library("trinity")
37
+ #have_library("gs2")
38
+ #have_library("trinity")
35
39
 
36
40
  dir_config('mpi')
37
41
  have_header("mpi.h")
@@ -10,15 +10,19 @@ struct _Comm {
10
10
  bool free;
11
11
  };
12
12
 
13
- static VALUE trinitycrdriver_run_trinity(VALUE class, VALUE input_file_name, VALUE mpi_comm){
13
+ static VALUE trinitycrdriver_run_trinity(VALUE self, VALUE input_file_name, VALUE mpi_comm){
14
14
  printf("RUNNING TRINITY!!!\n\n");
15
15
 
16
16
  struct _Comm *comm;
17
17
  char * input_file_name_c;
18
18
 
19
19
  Data_Get_Struct(mpi_comm, struct _Comm, comm);
20
- input_file_name_c = StringValueCStr(input_file_name);
21
- run_trinity_c(input_file_name_c, comm->Comm);
20
+
21
+ /*RFCALL_12("run_trin_actual", input_file_name, INT2FIX(comm->Comm));*/
22
+ rb_funcall(self, rb_intern("run_trin_actual2"), 2, input_file_name, INT2FIX(comm->Comm));
23
+
24
+ /*input_file_name_c = StringValueCStr(input_file_name);*/
25
+ /*run_trinity_c(input_file_name_c, comm->Comm);*/
22
26
 
23
27
  /*printf("input file name was %s\n", input_file_name_c);*/
24
28
  /**/
@@ -1,100 +1,109 @@
1
1
 
2
2
  class CodeRunner::Trinity::Optimisation
3
- include GSL::MultiMin
4
- # optimisation_spec is a hash of {:code_name => {:variable => [initial_guess, dimension_scale_factor]}}
5
- # dimension_scale_factor is just some estimate of the length scale in which the result
6
- # varies significantly
7
- # code_name is either trinity or chease (both can be used simultaneously)
8
- attr_reader :optimisation_spec
9
- attr_reader :optimisation_variables
10
- attr_accessor :trinity_runner
11
- attr_accessor :chease_runner
12
- def initialize(optimised_quantity, optimisation_spec)
13
- #@folder = folder
14
- @optimised_quantity = optimised_quantity
15
- @optimisation_spec = optimisation_spec
16
- @optimisation_variables = optimisation_spec.map{|code, hash| hash.map{|var, pars| [code, var]}}.flatten(1)
17
- @optimisation_starts = optimisation_spec.map{|code, hash| hash.map{|var, pars| pars[0]}}.flatten(1)
18
- @optimisation_steps = optimisation_spec.map{|code, hash| hash.map{|var, pars| pars[1]}}.flatten(1)
19
- #@runner = CodeRunner.fetch_runner(
20
- #p ['optimisation_variables', @optimisation_variables]
21
- end
22
- def dimension
23
- @optimisation_variables.size
24
- end
25
- def serial_optimise(optimisation_method, parameters_obj)
26
- optimisation_meth = case optimisation_method
27
- when :simplex
28
- FMinimizer::NMSIMPLEX
29
- else
30
- raise "Unknown optimisation_method"
31
- end
32
- opt = FMinimizer.alloc(optimisation_meth, @optimisation_variables.size)
33
- func = Proc.new{|v, optimiser| optimiser.func(v)}
34
- gsl_func = Function.alloc(func, dimension)
35
- gsl_func.set_params(self)
36
- opt.set(gsl_func, @optimisation_starts.to_gslv, @optimisation_steps.to_gslv)
37
- parameters_obj.nit.times do |i|
38
- opt.iterate
39
- p ['status', opt.x, opt.minimum, i, parameters_obj.nit]
40
- end
3
+ include GSL::MultiMin
4
+ # optimisation_spec is a hash of {:code_name => {:variable => [initial_guess, dimension_scale_factor]}}
5
+ # dimension_scale_factor is just some estimate of the length scale in which the result
6
+ # varies significantly
7
+ # code_name is either trinity or chease (both can be used simultaneously)
8
+ attr_reader :optimisation_spec
9
+ attr_reader :optimisation_variables
10
+ attr_accessor :trinity_runner
11
+ attr_accessor :chease_runner
12
+ def initialize(optimised_quantity, optimisation_spec)
13
+ #@folder = folder
14
+ @optimised_quantity = optimised_quantity
15
+ @optimisation_spec = optimisation_spec
16
+ @optimisation_variables = optimisation_spec.map{|code, hash| hash.map{|var, pars| [code, var]}}.flatten(1)
17
+ @optimisation_starts = optimisation_spec.map{|code, hash| hash.map{|var, pars| pars[0]}}.flatten(1)
18
+ @optimisation_steps = optimisation_spec.map{|code, hash| hash.map{|var, pars| pars[1]}}.flatten(1)
19
+ #@runner = CodeRunner.fetch_runner(
20
+ #p ['optimisation_variables', @optimisation_variables]
21
+ end
22
+ def dimension
23
+ @optimisation_variables.size
24
+ end
25
+ def serial_optimise(optimisation_method, parameters_obj)
26
+ optimisation_meth = case optimisation_method
27
+ when :simplex
28
+ FMinimizer::NMSIMPLEX
29
+ else
30
+ raise "Unknown optimisation_method"
31
+ end
32
+ opt = FMinimizer.alloc(optimisation_meth, @optimisation_variables.size)
33
+ func = Proc.new{|v, optimiser| optimiser.func(v)}
34
+ gsl_func = Function.alloc(func, dimension)
35
+ gsl_func.set_params(self)
36
+ opt.set(gsl_func, @optimisation_starts.to_gslv, @optimisation_steps.to_gslv)
37
+ parameters_obj.nit.times do |i|
38
+ opt.iterate
39
+ p ['status', opt.x, opt.minimum, i, parameters_obj.nit]
40
+ end
41
41
 
42
- p 'heellllllo'
43
- MPI.Finalize
44
-
45
- end
46
- def func(v)
47
- pars = {}
48
- pars[:chease] = {}
49
- pars[:trinity] = {}
50
- for i in 0...v.size
51
- code, varname = @optimisation_variables[i]
52
- val = v[i]
53
- pars[code][varname] = val
54
- end
55
- if not @first_run_done
56
- pars[:trinity][:ntstep] = 300
57
- #@first_run_done = true
58
- #else
59
- #pars[:trinity][:ntstep] = 100
60
- end
42
+ p 'heellllllo'
43
+ MPI.Finalize
44
+
45
+ end
46
+ def func(v)
47
+ pars = {}
48
+ pars[:chease] = {}
49
+ pars[:trinity] = {}
50
+ for i in 0...v.size
51
+ code, varname = @optimisation_variables[i]
52
+ val = v[i]
53
+ pars[code][varname] = val
54
+ end
55
+ if not @first_run_done
56
+ pars[:trinity][:ntstep] = 300
57
+ else
58
+ #pars[:trinity].delete(:ntstep)
59
+ pars[:trinity][:ntstep] = 100
60
+ end
61
61
 
62
- pars[:chease][:ap] = [0.3,0.5,0.4,0.0,0.4,0.0,0.0]
62
+ pars[:chease][:ap] = [0.3,0.5,0.4,0.0,0.4,0.0,0.0]
63
63
  pars[:chease][:at] = [0.16,1.0,1.0,-1.1,-1.1]
64
64
 
65
65
 
66
- trinity_runner.run_class.instance_variable_set(:@mpi_communicator, MPI::Comm::WORLD)
67
- if false and trinity_runner.run_list.size > 0
68
- else
69
- crun = chease_runner.run_class.new(chease_runner)
70
- crun.update_submission_parameters(pars[:chease].inspect)
71
- if chease_runner.run_list.size > 0
72
- crun.restart_id = @cid
73
- end
74
- chease_runner.submit(crun)
75
- crun = chease_runner.run_list[@cid = chease_runner.max_id]
76
- crun.recheck
77
- chease_runner.update
78
- #chease_runner.print_out(0)
79
- FileUtils.cp(crun.directory + '/ogyropsi.dat', trinity_runner.root_folder + '/.')
66
+ trinity_runner.run_class.instance_variable_set(:@mpi_communicator, MPI::Comm::WORLD)
67
+ if false and trinity_runner.run_list.size > 0
68
+ else
69
+ crun = chease_runner.run_class.new(chease_runner)
70
+ crun.update_submission_parameters(pars[:chease].inspect)
71
+ if @first_run_done
72
+ #crun.nppfun=4
73
+ #crun.neqdsk=0
74
+ #crun.expeq_file = trinity_runner.run_list[@id]
75
+ end
76
+ if chease_runner.run_list.size > 0
77
+ crun.restart_id = @cid
78
+ end
79
+ chease_runner.submit(crun)
80
+ crun = chease_runner.run_list[@cid = chease_runner.max_id]
81
+ crun.recheck
82
+ chease_runner.update
83
+ #chease_runner.print_out(0)
84
+ #FileUtils.cp(crun.directory + '/ogyropsi.dat', trinity_runner.root_folder + '/.')
80
85
 
81
- run = trinity_runner.run_class.new(trinity_runner)
82
- run.update_submission_parameters(pars[:trinity].inspect)
83
- #trinity_runner.run_class.instance_variable_set(:@delay_execution, true)
84
- if trinity_runner.run_list.size > 0
85
- #run.restart_id = @id
86
- end
87
- trinity_runner.submit(run)
88
- run = trinity_runner.run_list[@id = trinity_runner.max_id]
89
- run.recheck
90
- trinity_runner.update
91
- #trinity_runner.print_out(0)
92
- result = run.send(@optimised_quantity)
93
- p ['result is ', result]
94
- return -result
95
- end
86
+ run = trinity_runner.run_class.new(trinity_runner)
96
87
 
88
+ run.update_submission_parameters(pars[:trinity].inspect)
89
+ run.gs_folder = crun.directory
90
+ run.evolve_geometry = ".true."
91
+ #trinity_runner.run_class.instance_variable_set(:@delay_execution, true)
92
+ if trinity_runner.run_list.size > 0
93
+ run.restart_id = @id
94
+ end
95
+ trinity_runner.submit(run)
96
+ run = trinity_runner.run_list[@id = trinity_runner.max_id]
97
+ run.recheck
98
+ trinity_runner.update
99
+ #trinity_runner.print_out(0)
100
+ result = run.send(@optimised_quantity)
101
+ p ['result is ', result]
102
+ @first_run_done = true
103
+ return -result
104
+ end
97
105
 
98
- #v.square.sum
99
- end
106
+
107
+ #v.square.sum
108
+ end
100
109
  end
@@ -1,4 +1,18 @@
1
-
1
+ require 'ffi'
2
+ class CodeRunner
3
+ class Trinity
4
+ module TrinityDriver
5
+ extend FFI::Library
6
+ ffi_lib ENV['TRINITY'] + '/libtrin.so'
7
+ attach_function :runtr, :run_trinity_c, [:string, :int], :void
8
+ end
9
+ def run_trin_actual2(input_file, mpicomm_int)
10
+ puts 'calling TrinityDriver.runtr'
11
+ TrinityDriver.runtr(input_file, mpicomm_int)
12
+ end
13
+ private :run_trin_actual2
14
+ end
15
+ end
2
16
  require 'trinitycrdriver/trinitycrdriver'
3
17
  require 'mpi'
4
18
 
@@ -2,17 +2,17 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: trinitycrdriver 0.1.0 ruby lib
5
+ # stub: trinitycrdriver 0.1.1 ruby lib
6
6
  # stub: ext/trinitycrdriver/extconf.rb
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "trinitycrdriver"
10
- s.version = "0.1.0"
10
+ s.version = "0.1.1"
11
11
 
12
12
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
14
14
  s.authors = ["Edmund Highcock"]
15
- s.date = "2015-07-23"
15
+ s.date = "2015-07-28"
16
16
  s.description = "A gem to allow coderunner to run the trinity code directly."
17
17
  s.email = "edmundhighcock@users.sourceforge.net"
18
18
  s.extensions = ["ext/trinitycrdriver/extconf.rb"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trinitycrdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edmund Highcock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderunner