cronoscrmod 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "coderunner", ">= 0.13.18"
6
+ #gem "matlab-ruby", "> 2.0.0"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "rdoc", "~> 3.12"
13
+ gem "bundler", "> 1.0.0"
14
+ gem "jeweler", ">= 1.8.4"
15
+ #gem "rcov", ">= 0"
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 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.md ADDED
@@ -0,0 +1,42 @@
1
+ cronoscrmod
2
+ ===========
3
+
4
+ A module to allow CodeRunner to run the integrated tokamak modelling suite Cronos
5
+
6
+
7
+ cronoscrmod requires matlab-ruby, but for technical reasons, you must install this yourself manually.
8
+
9
+ Try:
10
+
11
+ `gem install matlab-ruby`
12
+
13
+ If this fails, see the notes below.
14
+
15
+
16
+ Notes
17
+ -----
18
+
19
+
20
+ Instructions for Mac OS X
21
+
22
+ You need to install matlab-ruby for cronoscrmod, but `gem install matlab-ruby` does not in general work. It is recommended that you install it yourself like this:
23
+
24
+
25
+ `git clone git@github.com:edmundhighcock/matlab-ruby.git`
26
+
27
+ `cd matlab-ruby`
28
+
29
+ `ruby setup.rb config -- --with-matlab-include=/Applications/MATLAB_R2012a.app/extern/include/ --with-matlab-lib=/Applications/MATLAB_R2012a.app/bin/maci64/`
30
+
31
+ `ruby setup.rb setup`
32
+
33
+ `sudo ruby setup.rb install`
34
+
35
+ You also need to make sure the Matlab libraries are in the linker path:
36
+
37
+ Add these lines to your login script:
38
+
39
+ `export PATH=$PATH:/Applications/MATLAB_R2012a.app/bin/`
40
+
41
+ `export DYLD_LIBRARY_PATH=/Applications/MATLAB_R2012a.app/bin/maci64:$DYLD_LIBRARY_PATHo`
42
+
data/README.md.orig ADDED
@@ -0,0 +1,4 @@
1
+ cronoscrmod
2
+ ===========
3
+
4
+ A module to allow CodeRunner to run the integrated tokamak modelling suite Cronos
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = cronoscrmod
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to cronoscrmod
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) 2013 Edmund Highcock. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
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://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "cronoscrmod"
18
+ gem.homepage = "http://github.com/edmundhighcock/cronoscrmod"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A module to allow CodeRunner to run the integrated tokamak modelling suite Cronos}
21
+ gem.description = %Q{A module to allow CodeRunner to run the integrated tokamak modelling suite Cronos. Requires matlab and matlab-ruby (Cronos also requires Matlab).}
22
+ gem.email = "edmundhighcock@users.sourceforge.net"
23
+ gem.authors = ["Edmund Highcock"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ #require 'rcov/rcovtask'
36
+ #Rcov::RcovTask.new do |test|
37
+ ##test.libs << 'test'
38
+ ##test.pattern = 'test/**/test_*.rb'
39
+ ##test.verbose = true
40
+ ##test.rcov_opts << '--exclude "gems/*"'
41
+ ##end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "cronoscrmod #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1 @@
1
+ require 'cronoscrmod/cronos.rb'
@@ -0,0 +1,230 @@
1
+ eputs "The Cronos CodeRunner module is written by Edmund Highcock, based on MatLab tools written by Jonathan Citrin" unless $has_put_startup_message_for_coderunner
2
+
3
+ require 'matlab'
4
+ class CodeRunner
5
+ class Cronos < Run
6
+ # Where this file is
7
+ @code_module_folder = folder = File.dirname(File.expand_path(__FILE__)) # i.e. the directory this file is in
8
+
9
+ class EngineHandler
10
+ def initialize(engine)
11
+ @engine = engine
12
+ @cronos_path_set = false
13
+ @pathc
14
+ end
15
+ def start_cronos(path)
16
+ return
17
+ return if @cronos_path_set
18
+ raise "cronos not found in #{path}" unless FileTest.exist?("#{path}/cronos.m")
19
+ @engine.eval_string("addpath #{File.expand_path(path)};")
20
+ @engine.eval_string("addpath #{File.expand_path(path)}/interface;")
21
+ @engine.eval_string("addpath #{File.expand_path(path)}/op;")
22
+ @engine.eval_string("cronos")
23
+ @engine.eval_string("zuidirect")
24
+ @cronos_path_set = true
25
+ end
26
+
27
+ def new_file
28
+ @engine.eval_string("zuicreate")
29
+ STDIN.gets
30
+ end
31
+ end
32
+
33
+ def run_command
34
+ "echo 'manual run'"
35
+ end
36
+
37
+ module CodeRunner::InteractiveMethods
38
+ def cronos(*args)
39
+ if args.size > 0
40
+ args.each do |com|
41
+ CodeRunner::Cronos.rcp.engine_handler.cronos.puts(com)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+
49
+ class CronosHandler
50
+ def initialize(runner)
51
+ if runner and runner.executable
52
+ start_cronos(runner.executable)
53
+ end
54
+ end
55
+ attr_reader :cronos
56
+
57
+ def start_cronos(path)
58
+ return if @cronos_started
59
+ raise "cronos not found in #{path}" unless FileTest.exist?("#{path}/cronos.m")
60
+ @cronos = IO.popen("#{path}/cronos 3>&2 2>&1 1>&3 | grep -v 'Time Machine' 3>&2 2>&1 1>&3 ", 'w')
61
+ @cronos_started = true
62
+ end
63
+ def new_file
64
+ @cronos.puts("zuicreate")
65
+ end
66
+ end
67
+
68
+ begin
69
+ #@engine = Matlab::Engine.new("matlab -nodesktop -nosplash")
70
+ #@engine_handler = EngineHandler.new(@engine)
71
+ @engine_handler = CronosHandler.new((rcp.runner? ? rcp.runner : nil))
72
+ #rescue => err
73
+ #if err.to_s =~ /driver for matlab/
74
+ #puts "Please make sure matlab is in your path"
75
+
76
+ #raise
77
+ #else
78
+ #raise
79
+ #end
80
+ end
81
+
82
+ def set_cronos_path
83
+ rcp.engine_handler.start_cronos(@runner.executable.sub(/cronos$/, ""))
84
+ end
85
+
86
+
87
+
88
+
89
+
90
+
91
+ ################################################
92
+ # Quantities that are read or determined by CodeRunner
93
+ # after the simulation has ended
94
+ ###################################################
95
+
96
+ @results = [
97
+ ]
98
+
99
+ @variables = [
100
+ :aim,
101
+ :duplicate_id,
102
+
103
+ ]
104
+
105
+ @code_long="Cronos Integrated Tokamak Modeller"
106
+
107
+ @run_info=[:time, :is_a_restart, :restart_id, :restart_run_name, :completed_timesteps, :percent_complete]
108
+
109
+ @uses_mpi = false
110
+
111
+ @modlet_required = false
112
+
113
+ @naming_pars = []
114
+
115
+ # Any subfolders of the main run folder
116
+ @excluded_sub_folders = ["rapsauve_#{ENV['USER']}"]
117
+
118
+ # A hook which gets called when printing the standard run information to the screen using the status command.
119
+ def print_out_line
120
+ #p ['id', id, 'ctd', ctd]
121
+ #p rcp.results.zip(rcp.results.map{|r| send(r)})
122
+ name = @run_name
123
+ name += " (res: #@restart_id)" if @restart_id
124
+ name += " real_id: #@real_id" if @real_id
125
+ beginning = sprintf("%2d:%d %-60s %1s:%2.1f(%s)", @id, @job_no, name, @status.to_s[0,1], @run_time.to_f / 60.0, @nprocs.to_s)
126
+ if @status == :Incomplete and @completed_timesteps
127
+ beginning += sprintf(" %d steps ", @completed_timesteps)
128
+ elsif @percent_complete
129
+ beginning+=sprintf(" %3s%1s ", percent_complete, "%")
130
+ end
131
+ if ctd
132
+ #beginning += sprintf("Q:%f, Pfusion:%f MW, Ti0:%f keV, Te0:%f keV, n0:%f x10^20", fusionQ, pfus, ti0, te0, ne0)
133
+ end
134
+ beginning += " ---#{@comment}" if @comment
135
+ beginning
136
+ end
137
+
138
+
139
+ # This is a hook which gets called just before submitting a simulation. It sets up the folder and generates any necessary input files.
140
+ def generate_input_file
141
+ #FileUtils.touch("#@run_name.mat")
142
+ #cronos.new_file
143
+ #eputs "Make sure you save the file as #@run_name.mat... overwrite the existing empty place holder. When you have saved the file press enter."
144
+ if @duplicate_id
145
+ old = @runner.run_list[@duplicate_id]
146
+ system "cp #{old.directory}/#{old.run_name}.mat #@directory/#@run_name.mat"
147
+ load
148
+ elsif @restart_id
149
+ old = @runner.run_list[@restart_id]
150
+ system "cp #{old.directory}/#{old.run_name}_resultat.mat #@directory/#@run_name.mat"
151
+ load
152
+ else
153
+ sz = Terminal.terminal_size[1]
154
+ eputs((str = "When you have created the file press enter. Don't save it (CodeRunner will automatically save it in the right place. You can edit parameters later as well. CodeRunner will not submit the file... submit it manually using a batch or interactive run."; ["-"*sz, str, "-"*sz]))
155
+ cronos.puts("zuicreate")
156
+ STDIN.gets
157
+ end
158
+ cronos.puts("param.gene.origine = '#@directory/#@run_name.mat'")
159
+ cronos.puts("param.gene.file = '#@directory/#{@run_name}_resultat.mat'")
160
+ cronos.puts("param.gene.rapsauve = '#@directory/#{@run_name}_resultat'")
161
+ cronos.puts("param.edit.currentfile= '#@directory/#@run_name.mat'")
162
+ cronos.puts("param.from.creation.com = '#@comment'")
163
+ cronos.puts("zuisavedata('force')")
164
+ #cronos.eval("zuicreate")
165
+ refresh_gui
166
+
167
+ end
168
+
169
+ def refresh_gui
170
+ cronos.puts(["[hfig,h] = zuiformhandle('direct');",
171
+ "if ishandle(hfig)
172
+ set(h.text_loadfile, 'string', param.gene.origine)
173
+ set(h.text_nom_machine, 'string', param.from.machine)
174
+ set(h.text_numchoc, 'string', sprintf('%d', param.from.shot.num))
175
+
176
+ end"])
177
+ end
178
+
179
+ def load
180
+ cronos.puts("zuiload('#@directory/#@run_name.mat')")
181
+ refresh_gui
182
+ end
183
+
184
+ def cronos
185
+ set_cronos_path
186
+ rcp.engine_handler.cronos
187
+ end
188
+
189
+
190
+
191
+ # Parameters which follow the Trinity executable, in this case just the input file.
192
+ def parameter_string
193
+ end
194
+
195
+ def parameter_transition
196
+ end
197
+
198
+
199
+ @source_code_subfolders = []
200
+
201
+ # 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).
202
+ #
203
+ def process_directory_code_specific
204
+ get_status
205
+ #p ['fusionQ is ', fusionQ]
206
+ #@percent_complete = completed_timesteps.to_f / ntstep.to_f * 100.0
207
+ end
208
+
209
+ def results_file_name
210
+ "#{@run_name}_resultat.mat"
211
+ end
212
+
213
+ def get_status
214
+ Dir.chdir(@directory) do
215
+ if FileTest.exist? results_file_name
216
+ @status = :Complete
217
+ @percent_complete = 100.0
218
+ elsif temps = Dir.entries.grep(/resultat_\d+/) and temps.size > 1
219
+ @status = :Incomplete
220
+ @completed_timesteps = temps.map{|f| f.scan(/resultat_(\d+)/)[0][0].to_i}.max
221
+ else
222
+ @status = :Unknown
223
+ @percent_complete = 0
224
+ end
225
+ end
226
+ end
227
+
228
+ end
229
+ end
230
+
File without changes
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'coderunner'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+
3
+ raise "Please specify $CRONOS_EXEC" unless ENV['CRONOS_EXEC']
4
+
5
+ class TestCronoscrmod < Test::Unit::TestCase
6
+ def setup
7
+ FileUtils.mkdir('test/jet') rescue 0
8
+ @runner = CodeRunner.fetch_runner(Y: 'test/jet', C: 'cronos', X: ENV['CRONOS_EXEC'])
9
+ end
10
+ def teardown
11
+ FileUtils.rm('test/jet/.code_runner_script_defaults.rb')
12
+ #FileUtils.rm('test/jet/.CODE_RUNNER_TEMP_RUN_LIST_CACHE')
13
+ end
14
+ def test_basics
15
+ assert_equal(@runner.run_class, CodeRunner::Cronos)
16
+ @runner.print_out(0)
17
+ end
18
+ def test_matlab
19
+
20
+ #require 'matlab'
21
+
22
+ ##engine = Matlab::Engine.new(command = "#{ENV['MATLAB_BINDIR']}matlab -nodesktop -nosplash")
23
+ #p ['output', CodeRunner::Cronos.rcp.engine.put_variable("x", 124.456)]
24
+ #p ['output', CodeRunner::Cronos.rcp.engine.get_variable("x")]
25
+ end
26
+ def test_create
27
+ CodeRunner.submit(Y: 'test/jet', p: '{aim: "test_cronos"}', T: true)
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cronoscrmod
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Edmund Highcock
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: coderunner
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.13.18
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.13.18
30
+ - !ruby/object:Gem::Dependency
31
+ name: shoulda
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>'
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>'
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.4
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.4
94
+ description: A module to allow CodeRunner to run the integrated tokamak modelling
95
+ suite Cronos. Requires matlab and matlab-ruby (Cronos also requires Matlab).
96
+ email: edmundhighcock@users.sourceforge.net
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files:
100
+ - LICENSE.txt
101
+ - README.md
102
+ - README.md.orig
103
+ - README.rdoc
104
+ files:
105
+ - .document
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION
112
+ - lib/cronoscrmod.rb
113
+ - lib/cronoscrmod/cronos.rb
114
+ - lib/cronoscrmod/defaults_files/cronos_defaults.rb
115
+ - test/helper.rb
116
+ - test/test_cronoscrmod.rb
117
+ - README.md.orig
118
+ homepage: http://github.com/edmundhighcock/cronoscrmod
119
+ licenses:
120
+ - MIT
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ segments:
132
+ - 0
133
+ hash: 3245162892836041727
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 1.8.23
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: A module to allow CodeRunner to run the integrated tokamak modelling suite
146
+ Cronos
147
+ test_files: []