corfucrmod 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 560d6ee96bf999ecb52a78212c96a8ff0b2ca3ee
4
+ data.tar.gz: c1a07d5e1c42eeef2e9b726cd75fa1cd95d02b1d
5
+ SHA512:
6
+ metadata.gz: 0a9bef5ea41425fe687d0a37afbe7e542a51fc537adb4fe30c986c92b2eec587543b83d1a59c45d1e5895a7c71cfd6dfeb792068fea60cda60dbeaabcf9cf469
7
+ data.tar.gz: 3f8e1dbea324c8072e74c62d923989a780929c7033b0780e49fa820c0384ad45cb1916a482f3107870568e38efc21cee475ebddb02e5421e52fc20a66023aae0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "coderunner", ">= 0.14.2"
5
+ gem "text-data-tools", ">= 1.1.3"
6
+ gem "gs2crmod", ">=0.11.33"
7
+ gem "trinitycrmod", ">= 0.7.11"
8
+ gem "ruby-mpi", ">=0.2.0"
9
+ gem "cheasecrmod", ">=0.1.0"
10
+ gem "tokfile", ">=0.0.3"
11
+
12
+ # Add dependencies to develop your gem here.
13
+ # Include everything needed to run rake, tests, features, etc.
14
+ group :development do
15
+ gem "shoulda", " 3.0.1"
16
+ gem "rdoc", "~> 3.12"
17
+ gem "bundler", "> 1.0.0"
18
+ gem "jeweler", ">= 2.0.1"
19
+ gem "simplecov", ">=0"
20
+ gem "minitest", "~> 4"
21
+ gem "rake-compiler"
22
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Edmund Highcock
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = corfucrmod
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to corfucrmod
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2014 Edmund Highcock. See LICENSE.txt for
18
+ further details.
19
+
data/README.rdoc.orig ADDED
@@ -0,0 +1,19 @@
1
+ = trinitycrdriver
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to trinitycrdriver
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2014 Edmund Highcock. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "corfucrmod"
18
+ gem.homepage = "http://github.com/edmundhighcock/corfucrmod"
19
+ gem.license = "GPLv3.0"
20
+ gem.summary = %Q{A gem which implements the CorFu Optimisation Framework.}
21
+ gem.description = %Q{CorFu, the Coderunner/Trinity Fusion Optimisation Framework
22
+ allows the optimisation of fusion performance using first principles
23
+ flux calculations via Trinity.}
24
+ gem.email = "edmundhighcock@users.sourceforge.net"
25
+ gem.authors = ["Edmund Highcock"]
26
+ gem.files.exclude 'test/**/*'
27
+ gem.extensions = %w[ext/corfucrmod/extconf.rb]
28
+ # dependencies defined in Gemfile
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ desc "Code coverage detail"
40
+ task :simplecov do
41
+ ENV['COVERAGE'] = "true"
42
+ Rake::Task['test'].execute
43
+ end
44
+
45
+ task :default => :test
46
+
47
+ require 'rdoc/task'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "corfucrmod #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
57
+ NAME = 'corfucrmod'
58
+
59
+ require "rake/extensiontask"
60
+
61
+ Rake::ExtensionTask.new "corfucrmod" do |ext|
62
+ ext.lib_dir = "lib/corfucrmod"
63
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/clean.sh ADDED
@@ -0,0 +1,9 @@
1
+ rm -rf lib/trinitycrdriver/trinitycrdriver.so
2
+ rm -rf rake_test_opt_chease_defaults.rb
3
+ rm -rf rake_test_opt_defaults.rb
4
+ rm -rf test/chease_opt/.CODE_RUNNER_TEMP_RUN_LIST_CACHE
5
+ rm -rf test/chease_opt/ogyropsi.dat
6
+ rm -rf test/chease_opt/v/
7
+ rm -rf test/chease_opt_chease/.CODE_RUNNER_TEMP_RUN_LIST_CACHE
8
+ rm -rf test/chease_opt_chease/v/
9
+ rm -rf test/trinopt/
@@ -0,0 +1,96 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: corfucrmod 1.0.0 ruby lib
6
+ # stub: ext/corfucrmod/extconf.rb
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "corfucrmod".freeze
10
+ s.version = "1.0.0"
11
+
12
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
13
+ s.require_paths = ["lib".freeze]
14
+ s.authors = ["Edmund Highcock".freeze]
15
+ s.date = "2019-07-28"
16
+ s.description = "CorFu, the Coderunner/Trinity Fusion Optimisation Framework\n allows the optimisation of fusion performance using first principles\n flux calculations via Trinity.".freeze
17
+ s.email = "edmundhighcock@users.sourceforge.net".freeze
18
+ s.extensions = ["ext/corfucrmod/extconf.rb".freeze]
19
+ s.extra_rdoc_files = [
20
+ "LICENSE.txt",
21
+ "README.rdoc",
22
+ "README.rdoc.orig"
23
+ ]
24
+ s.files = [
25
+ ".document",
26
+ "Gemfile",
27
+ "LICENSE.txt",
28
+ "README.rdoc",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "clean.sh",
32
+ "corfucrmod.gemspec",
33
+ "ext/corfucrmod/extconf.rb",
34
+ "ext/corfucrmod/trinitycrdriver_ext.c",
35
+ "lib/corfucrmod.rb",
36
+ "lib/corfucrmod/corfu.rb",
37
+ "lib/corfucrmod/optimisation.rb",
38
+ "lib/corfucrmod/trinitycrdriver.rb"
39
+ ]
40
+ s.homepage = "http://github.com/edmundhighcock/corfucrmod".freeze
41
+ s.licenses = ["GPLv3.0".freeze]
42
+ s.rubygems_version = "2.6.8".freeze
43
+ s.summary = "A gem which implements the CorFu Optimisation Framework.".freeze
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 4
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<coderunner>.freeze, [">= 0.14.2"])
50
+ s.add_runtime_dependency(%q<text-data-tools>.freeze, [">= 1.1.3"])
51
+ s.add_runtime_dependency(%q<gs2crmod>.freeze, [">= 0.11.33"])
52
+ s.add_runtime_dependency(%q<trinitycrmod>.freeze, [">= 0.7.11"])
53
+ s.add_runtime_dependency(%q<ruby-mpi>.freeze, [">= 0.2.0"])
54
+ s.add_runtime_dependency(%q<cheasecrmod>.freeze, [">= 0.1.0"])
55
+ s.add_runtime_dependency(%q<tokfile>.freeze, [">= 0.0.3"])
56
+ s.add_development_dependency(%q<shoulda>.freeze, ["= 3.0.1"])
57
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
58
+ s.add_development_dependency(%q<bundler>.freeze, ["> 1.0.0"])
59
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 2.0.1"])
60
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
61
+ s.add_development_dependency(%q<minitest>.freeze, ["~> 4"])
62
+ s.add_development_dependency(%q<rake-compiler>.freeze, [">= 0"])
63
+ else
64
+ s.add_dependency(%q<coderunner>.freeze, [">= 0.14.2"])
65
+ s.add_dependency(%q<text-data-tools>.freeze, [">= 1.1.3"])
66
+ s.add_dependency(%q<gs2crmod>.freeze, [">= 0.11.33"])
67
+ s.add_dependency(%q<trinitycrmod>.freeze, [">= 0.7.11"])
68
+ s.add_dependency(%q<ruby-mpi>.freeze, [">= 0.2.0"])
69
+ s.add_dependency(%q<cheasecrmod>.freeze, [">= 0.1.0"])
70
+ s.add_dependency(%q<tokfile>.freeze, [">= 0.0.3"])
71
+ s.add_dependency(%q<shoulda>.freeze, ["= 3.0.1"])
72
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
73
+ s.add_dependency(%q<bundler>.freeze, ["> 1.0.0"])
74
+ s.add_dependency(%q<jeweler>.freeze, [">= 2.0.1"])
75
+ s.add_dependency(%q<simplecov>.freeze, [">= 0"])
76
+ s.add_dependency(%q<minitest>.freeze, ["~> 4"])
77
+ s.add_dependency(%q<rake-compiler>.freeze, [">= 0"])
78
+ end
79
+ else
80
+ s.add_dependency(%q<coderunner>.freeze, [">= 0.14.2"])
81
+ s.add_dependency(%q<text-data-tools>.freeze, [">= 1.1.3"])
82
+ s.add_dependency(%q<gs2crmod>.freeze, [">= 0.11.33"])
83
+ s.add_dependency(%q<trinitycrmod>.freeze, [">= 0.7.11"])
84
+ s.add_dependency(%q<ruby-mpi>.freeze, [">= 0.2.0"])
85
+ s.add_dependency(%q<cheasecrmod>.freeze, [">= 0.1.0"])
86
+ s.add_dependency(%q<tokfile>.freeze, [">= 0.0.3"])
87
+ s.add_dependency(%q<shoulda>.freeze, ["= 3.0.1"])
88
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
89
+ s.add_dependency(%q<bundler>.freeze, ["> 1.0.0"])
90
+ s.add_dependency(%q<jeweler>.freeze, [">= 2.0.1"])
91
+ s.add_dependency(%q<simplecov>.freeze, [">= 0"])
92
+ s.add_dependency(%q<minitest>.freeze, ["~> 4"])
93
+ s.add_dependency(%q<rake-compiler>.freeze, [">= 0"])
94
+ end
95
+ end
96
+
@@ -0,0 +1,46 @@
1
+ require 'mkmf'
2
+
3
+ #Need to link with C GSL libraries to use in C extensions
4
+ #gsl_inc = `gsl-config --cflags`
5
+
6
+ #$CFLAGS = " -Wall -I../include #{gsl_inc}"
7
+
8
+ #srcs = Dir.glob("*.c")
9
+
10
+ #p ['srcs', srcs]
11
+
12
+ #$objs = srcs.collect { |f| f.sub(".c", ".o") }
13
+ RbConfig::CONFIG['CC'] = CONFIG['CC'] = ENV['CC'] || "mpicc"
14
+ #RbConfig::CONFIG['CPP'] = CONFIG['CPP'] = ENV['CPP'] || "mpicc -E"
15
+ p 'CONFIG[CC]', CONFIG['CC']
16
+ crgemspec=Gem::Specification.find_by_name('coderunner')
17
+ crconfig = crgemspec.full_gem_path
18
+ $CPPFLAGS = " -I#{File.join(crconfig, 'include')} "+$CPPFLAGS
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
+ #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
35
+
36
+ #have_library("gs2", "__gs2_main_MOD_gs2spec_from_trin")
37
+ #have_library("gs2")
38
+ #have_library("trinity")
39
+
40
+ dir_config('mpi')
41
+ have_header("mpi.h")
42
+ have_library("mpi")
43
+ have_library("mpi_f90")
44
+ have_library("mpi_f77")
45
+
46
+ create_makefile("corfucrmod/trinitycrdriver_ext")
@@ -0,0 +1,73 @@
1
+ #include <math.h>
2
+ #include <string.h>
3
+ #include "code_runner_ext.h"
4
+ #include <mpi.h>
5
+ #include <stdbool.h>
6
+
7
+ /* Taken from the ruby-mpi gem*/
8
+ struct _Comm {
9
+ MPI_Comm Comm;
10
+ bool free;
11
+ };
12
+
13
+ static VALUE corfucrmod_run_trinity(VALUE self, VALUE input_file_name, VALUE mpi_comm){
14
+ printf("RUNNING TRINITY!!!\n\n");
15
+
16
+ struct _Comm *comm;
17
+ char * input_file_name_c;
18
+
19
+ Data_Get_Struct(mpi_comm, struct _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);*/
26
+
27
+ /*printf("input file name was %s\n", input_file_name_c);*/
28
+ /**/
29
+ /*free(input_file_name_c);*/
30
+
31
+
32
+
33
+ return Qnil;
34
+
35
+ }
36
+
37
+ void Init_corfucrmod()
38
+ {
39
+
40
+ VALUE ctrinity;
41
+
42
+ cgraph_kit = Qnil;
43
+ ccode_runner_gs2 = Qnil;
44
+ ccode_runner_ext = Qnil;
45
+ printf("HERE!!!\n\n");
46
+ ccode_runner = RGET_CLASS_TOP("CodeRunner");
47
+ /*VALUE ctrinity = RGET_CLASS_TOP("CodeRunner");*/
48
+ ctrinity = RGET_CLASS(ccode_runner, "Trinity");
49
+ rb_define_method(ctrinity, "run_trinity", corfucrmod_run_trinity, 2);
50
+ /*rb_define_class_under(ccode_runner, "Trinity",*/
51
+ /*RGET_CLASS(*/
52
+ /*RGET_CLASS(ccode_runner, "Run"), */
53
+ /*"FortranNamelist"*/
54
+ /*)*/
55
+ /*);*/
56
+
57
+ /*ccode_runner_gs2_gsl_tensor_complexes = rb_define_module_under(ccode_runner_gs2, "GSLComplexTensors");*/
58
+ /*rb_include_module(ccode_runner_gs2, ccode_runner_gs2_gsl_tensor_complexes);*/
59
+
60
+ /*ccode_runner_gs2_gsl_tensors = rb_define_module_under(ccode_runner_gs2, "GSLTensors"); */
61
+ /*rb_include_module(ccode_runner_gs2, ccode_runner_gs2_gsl_tensors);*/
62
+
63
+ /*cgsl = RGET_CLASS_TOP("GSL");*/
64
+ /*cgsl_vector = RGET_CLASS(cgsl, "Vector");*/
65
+ /*cgsl_vector_complex = RGET_CLASS(cgsl_vector, "Complex");*/
66
+
67
+ /*rb_define_method(ccode_runner_gs2_gsl_tensor_complexes, "field_gsl_tensor_complex_2", gs2crmod_tensor_complexes_field_gsl_tensor_complex_2, 1);*/
68
+ /*rb_define_method(ccode_runner_gs2_gsl_tensors, "field_real_space_gsl_tensor", gs2crmod_tensor_field_gsl_tensor, 1);*/
69
+ /*rb_define_method(ccode_runner_gs2_gsl_tensors, "field_correlation_gsl_tensor", gs2crmod_tensor_field_correlation_gsl_tensor, 1);*/
70
+
71
+ /*rb_define_method(ccode_runner_ext, "hello_world", code_runner_ext_hello_world, 0);*/
72
+ }
73
+
data/lib/corfucrmod.rb ADDED
@@ -0,0 +1 @@
1
+ require 'corfucrmod/corfu'
@@ -0,0 +1,367 @@
1
+ require 'mpi'
2
+ class CodeRunner
3
+ # This is a customised subclass of the CodeRunner::Run class which is designed to run the CodeRunner/Trinity optimisation framework
4
+ #
5
+ CodeRunner.setup_run_class('trinity')
6
+ CodeRunner.setup_run_class('chease')
7
+ class Corfu < Run
8
+
9
+
10
+ # Where this file is
11
+ @code_module_folder = File.dirname(File.expand_path(__FILE__)) # i.e. the directory this file is in
12
+
13
+
14
+ ################################################
15
+ # Quantities that are read or determined by CodeRunner
16
+ # after the simulation has ended
17
+ ###################################################
18
+
19
+ @results = [
20
+ ]
21
+
22
+ @code_long="CodeRunner/Trinity Optimisation Framework"
23
+
24
+ @run_info=[:time, :is_a_restart, :restart_id, :restart_run_name, :completed_steps, :percent_complete, :start_time]
25
+
26
+ @variables = [
27
+ :chease_exec,
28
+ :ecom_exec,
29
+ :output,
30
+ :search,
31
+ :trinity_defaults,
32
+ :trinity_defaults_strings,
33
+ :gs_defaults,
34
+ :chease_defaults_strings,
35
+ :ecom_defaults_strings,
36
+ :nit,
37
+ :ntstep_first,
38
+ :ntstep,
39
+ :delete_final_run,
40
+ :trinity_pars,
41
+ :chease_pars,
42
+ :ecom_pars,
43
+ :gs_code,
44
+ :convergence,
45
+ :max_func_evals,
46
+ :use_previous_pressure,
47
+ :use_ifspppl_first,
48
+ :wall_mins_margin
49
+ ]
50
+ def gs_defaults_strings
51
+ case @gs_code
52
+ when 'chease'
53
+ @chease_defaults_strings ||= @gs_defaults_strings # For backwards compatibility
54
+ else
55
+ @ecom_defaults_strings
56
+ end
57
+ end
58
+ def gs_defaults_strings=(strs)
59
+ @chease_defaults_strings = strs
60
+ end
61
+ def gs_pars
62
+ case @gs_code
63
+ when 'chease'
64
+ @chease_pars ||= @gs_pars
65
+ when 'ecom'
66
+ @gs_pars
67
+ end
68
+ end
69
+
70
+ # For backwards compatibility
71
+ def gs_pars=(pars)
72
+ @chease_pars = pars
73
+ end
74
+
75
+ @uses_mpi = true
76
+
77
+ @modlet_required = false
78
+
79
+ @naming_pars = []
80
+
81
+ # Any folders which are a number will contain the results from flux simulations.
82
+ @excluded_sub_folders = ['trinity_runs', 'gs_runs']
83
+
84
+ def initialize(*args)
85
+ @trinity_defaults_strings = []
86
+ @chease_defaults_strings = []
87
+ @ecom_defaults_strings = []
88
+ @convergence = 0.05
89
+ @max_func_evals = 4
90
+ @wall_mins_margin = 5.0
91
+ @wall_mins = 1.0e10
92
+ super(*args)
93
+ end
94
+ def evaluate_defaults_file(filename)
95
+ text = File.read(filename)
96
+ instance_eval(text)
97
+ text.scan(/^\s*@(\w+)/) do
98
+ var_name = $~[1].to_sym
99
+ next if var_name == :defaults_file_description
100
+ next if var_name == :code_run_environment
101
+ unless rcp.variables.include? var_name or (CodeRunner::Trinity.rcp.variables.include? var_name) or (CodeRunner::Chease.rcp.variables.include? var_name or CodeRunner::Gryfx.rcp.variables.include? var_name or CodeRunner::Gs2.rcp.variables.include? var_name or CodeRunner::Ecom.rcp.variables.include? var_name)
102
+ warning("---#{var_name}---, specified in #{File.expand_path(filename)}, is not a variable. This could be an error")
103
+ end
104
+ end
105
+ eputs '@nstep_is', @nstep
106
+ eputs '@nstep_first', @nstep_first
107
+ end
108
+
109
+ # A hook which gets called when printing the standard run information to the screen using the status command.
110
+ def print_out_line
111
+ #p ['id', id, 'ctd', ctd]
112
+ #p rcp.results.zip(rcp.results.map{|r| send(r)})
113
+ name = @run_name
114
+ name += " (res: #@restart_id)" if @restart_id
115
+ 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, "%")
116
+ if ctd
117
+ #beginning += sprintf("Q:%f, Pfusion:%f MW, Ti0:%f keV, Te0:%f keV, n0:%f x10^20", fusionQ, pfus, ti0, te0, ne0)
118
+ end
119
+ beginning += " ---#{@comment}" if @comment
120
+ beginning
121
+ end
122
+
123
+
124
+
125
+ # Modify new_run so that it becomes a restart of self. Adusts
126
+ # all the parameters of the new run to be equal to the parameters
127
+ # of the run that calls this function, and sets up its run name
128
+ # correctly
129
+ def restart(new_run)
130
+ #new_run = self.dup
131
+ (rcp.variables).each{|v| new_run.set(v, send(v)) if send(v)}
132
+ new_run.is_a_restart = true
133
+ new_run.restart_id = @id
134
+ new_run.restart_run_name = @run_name
135
+ new_run.run_name = nil
136
+ new_run.naming_pars = @naming_pars
137
+ new_run.update_submission_parameters(new_run.parameter_hash.inspect, false) if new_run.parameter_hash
138
+ new_run.trinity_pars = @trinity_pars.absorb(new_run.trinity_pars) if @trinity_pars and new_run.trinity_pars
139
+ new_run.naming_pars.delete(:restart_id)
140
+ new_run.generate_run_name
141
+ raise "trinity_runs directory already exists" if FileTest.exist? new_run.directory + '/trinity_runs'
142
+ FileUtils.ln_s(@directory + '/trinity_runs', new_run.directory + '/trinity_runs')
143
+ FileUtils.ln_s(@directory + '/gs_runs', new_run.directory + '/gs_runs')
144
+ end
145
+ # This is a hook which gets called just before submitting a simulation. It sets up the folder and generates any necessary input files.
146
+ def generate_input_file
147
+ check_parameters
148
+ if @restart_id
149
+ @runner.run_list[@restart_id].restart(self)
150
+ else
151
+ FileUtils.makedirs('trinity_runs')
152
+ FileUtils.makedirs('gs_runs')
153
+ end
154
+ File.open("driver_script.rb", "w"){|f| f.puts optimisation_script}
155
+ #FileUtils.ln_s("../../#{@trinity_defaults}_defaults.rb", "trinity_runs")
156
+ #FileUtils.ln_s("../../#{@gs_defaults}_defaults.rb", "gs_runs")
157
+ save
158
+ end
159
+
160
+ def optimisation_script
161
+ return <<EOF
162
+ require 'mpi'
163
+ class MPI::Comm
164
+ def Bcast_string(str)
165
+ @arr = NArray.int(1)
166
+ if rank==0
167
+ @arr[0] = str.length
168
+ Bcast(@arr, 0)
169
+ Bcast(str, 0)
170
+ else
171
+ Bcast(@arr,0)
172
+ str << " " while str.length < @arr[0]
173
+ Bcast(str,0)
174
+ end
175
+ end
176
+ end
177
+ puts 'Initializing mpi'
178
+ MPI.Init
179
+ comm = MPI::Comm::WORLD
180
+ rank = comm.rank
181
+ puts ['Rank is: ', rank]
182
+ if rank==0
183
+ begin
184
+ require 'coderunner'
185
+ CodeRunner.setup_run_class('trinity')
186
+ CodeRunner.setup_run_class('corfu')
187
+ #require 'corfucrmod'
188
+ require 'corfucrmod/trinitycrdriver'
189
+ CodeRunner::Corfu.run_optimisation(#@id)
190
+ rescue =>err
191
+ arr = NArray.int(1)
192
+ arr[0] = 0
193
+ comm.Bcast(arr,0)
194
+ raise err
195
+ end
196
+ arr = NArray.int(1)
197
+ arr[0] = 0
198
+ comm.Bcast(arr,0)
199
+ else
200
+ require 'corfucrmod/trinitycrdriver'
201
+ arr = NArray.int(1)
202
+ puts "Proc \#{comm.rank} waiting for message"
203
+ loop do
204
+ comm.Bcast(arr, 0)
205
+ puts "Proc \#{comm.rank} received instructions: \#{arr[0]}"
206
+ dir = ""
207
+ run_name = ""
208
+ if arr[0] == 1
209
+ comm.Bcast_string(dir)
210
+ comm.Bcast_string(run_name)
211
+ puts "Proc \#{comm.rank} calling Trinity with run_name: \#{run_name}"
212
+ Dir.chdir(dir){CodeRunner::Trinity.new.run_trinity(run_name+'.trin', comm)}
213
+ else
214
+ break
215
+ end
216
+ end
217
+ end
218
+ MPI.Finalize
219
+ EOF
220
+ end
221
+
222
+ def check_parameters
223
+ if delete_final_run
224
+ raise CRFatal.new("Cancelled submission") unless Feedback.get_boolean("You have set delete_final_run which will cause the final run to be deleted. Is this correct?")
225
+ end
226
+ end
227
+
228
+
229
+ def self.run_optimisation(id = ARGV[-1])
230
+ eputs 'Fetching runner'
231
+ runner = CodeRunner.fetch_runner(Y: '../../', U: true)
232
+ eputs 'Got runner'
233
+ #@run = @runner.run_list[id.to_i]
234
+ #run = self.load(Dir.pwd, runner)
235
+ run = self.new(runner)
236
+ run.read_info
237
+ run.start_time = Time.now.to_i
238
+ eputs 'Loaded run'
239
+ #ep @run
240
+ #raise "Can't find run with id #{id}; #{@runner.run_list.keys}" unless @run
241
+ opt = CodeRunner::Corfu::Optimisation.new(
242
+ run.output, run.search
243
+ )
244
+ eputs 'Created opt'
245
+ trinity_runner = CodeRunner.fetch_runner(Y: 'trinity_runs', X: '/dev/null', C: 'trinity')
246
+ trinity_runner.nprocs = MPI::Comm::WORLD.size
247
+ eputs 'Got trinity runner'
248
+ case run.gs_code
249
+ when 'chease'
250
+ gs_runner = CodeRunner.fetch_runner(Y: 'gs_runs', X: run.chease_exec, C: 'chease')
251
+ gs_runner.nprocs = '1'
252
+ when 'ecom'
253
+ gs_runner = CodeRunner.fetch_runner(Y: 'gs_runs', X: run.ecom_exec, C: 'ecom')
254
+ gs_runner.nprocs = '1'
255
+ else
256
+ raise "Unknown gs_code #{run.gs_code.inspect}"
257
+ end
258
+ eputs 'Got gs runner'
259
+ opt.trinity_runner = trinity_runner
260
+ opt.gs_runner = gs_runner
261
+ opt.serial_optimise(:simplex, run)
262
+ end
263
+
264
+
265
+
266
+ def vim_output
267
+ system "vim -Ro #{output_file} #{error_file}"
268
+ end
269
+ alias :vo :vim_output
270
+
271
+
272
+ # Parameters which follow the Trinity executable, in this case just the input file.
273
+ def parameter_string
274
+ " driver_script.rb #@id"
275
+ end
276
+
277
+ def parameter_transition
278
+ end
279
+
280
+ def generate_component_runs
281
+ #puts "HERE"
282
+ end
283
+
284
+
285
+
286
+ @source_code_subfolders = []
287
+
288
+ # 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).
289
+ #
290
+ def process_directory_code_specific
291
+ get_status
292
+ #p ['id is', id, 'ctd is ', ctd]
293
+ #if ctd
294
+ #get_global_results
295
+ #end
296
+ #p ['fusionQ is ', fusionQ]
297
+ #@percent_complete = completed_timesteps.to_f / ntstep.to_f * 100.0
298
+ @percent_complete = 0.0
299
+ end
300
+
301
+ def get_status
302
+ return :Unknown
303
+ end
304
+
305
+
306
+ def input_file_extension
307
+ ''
308
+ end
309
+
310
+ def graphkit(name, options)
311
+ results = eval(File.read(@directory + '/results'))
312
+ case name
313
+ when 'evolution'
314
+ data = {}
315
+ pars_already_listed = []
316
+ results[:func_calls].reverse.each do |pars, res|
317
+ next if pars_already_listed.include? pars
318
+ pars_already_listed.push pars
319
+ pars.each do |code,cpars|
320
+ cpars.each do |vname, val|
321
+ label = "#{code}_#{vname}"
322
+ data[label] ||= []
323
+ data[label].push val
324
+ end
325
+ end
326
+ data['results']||=[]
327
+ data['results'].push res
328
+ end
329
+ kit = GraphKit.quick_create(data.values)
330
+ data.keys.zip(GraphKit::AXES).each{|lbl,ax| kit.set(ax + :label, lbl)}
331
+ kit
332
+ when 'iteration'
333
+ require 'tokfile/ogyropsi'
334
+ step = options[:step_index]
335
+ raise "Please specify step_index" unless step
336
+ iter, _trinstep = trinrunstep(step)[0]
337
+ kit = TokFile::Ogyropsi.new("#@directory/trinity_runs/v/id_#{iter}/chease/ogyropsi#{sprintf("%05d", step)}.dat").summary_graphkit
338
+ kit.gp.multiplot = " layout 3,3 title 'Iteration: #{iter}; Step: #{step}; Pars: #{results[:func_calls][iter-1][0]}; Result: #{results[:func_calls][iter-1][1].inspect}'"
339
+ kit[-1].gp.size = "ratio 1"
340
+ #pp 'kit', kit
341
+ return kit
342
+ end
343
+ end
344
+
345
+ def trinstep_mappings
346
+ @trinstep_mappings = (
347
+ trinity_runner = CodeRunner.fetch_runner(Y: @directory + '/trinity_runs')
348
+ sizes = trinity_runner.run_list.values.sort_by{|r| r.id}.map{|r| r.get_completed_timesteps; r.completed_timesteps}
349
+ i = 0; cs = 0
350
+ sizes.inject({}){|h,sz| cs+=sz; h[i+=1]=cs; h}
351
+ )
352
+ end
353
+
354
+ def trinrunstep(overall_step)
355
+ p 'trinstep_mappings', trinstep_mappings
356
+ trinrun, cusum = trinstep_mappings.to_a.find{|t, c| c>=overall_step}
357
+ [trinrun, cusum-overall_step + 1]
358
+ end
359
+
360
+ def max_step
361
+ trinstep_mappings[-1][1]
362
+ end
363
+
364
+ end
365
+ end
366
+ require 'corfucrmod/optimisation'
367
+