comana 0.0.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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.9.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.1.3"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "simplecov", ">= 0"
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 ippei94da
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
+ = comana
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to comana
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) 2012 ippei94da. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
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 = "comana"
18
+ gem.homepage = "http://github.com/ippei94da/comana"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Manager for scientific computing}
21
+ gem.description = %Q{An aim of this gem is to provide a framework of
22
+ managing scientific computing.
23
+ Researchers on computing have to check calculation and
24
+ generate new calculation and execute, repeatedly.
25
+ The abstract class that this gem provide would help the work.
26
+ }
27
+ gem.email = "ippei94da@gmail.com"
28
+ gem.authors = ["ippei94da"]
29
+ # dependencies defined in Gemfile
30
+ end
31
+ Jeweler::RubygemsDotOrgTasks.new
32
+
33
+ require 'rspec/core'
34
+ require 'rspec/core/rake_task'
35
+ RSpec::Core::RakeTask.new(:spec) do |spec|
36
+ spec.pattern = FileList['spec/**/*_spec.rb']
37
+ end
38
+
39
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
40
+ spec.pattern = 'spec/**/*_spec.rb'
41
+ spec.rcov = true
42
+ end
43
+
44
+ task :default => :spec
45
+
46
+ require 'rdoc/task'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "comana #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/comana.rb ADDED
@@ -0,0 +1,99 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ #
5
+ # Comana: COmputation MANAger
6
+ #
7
+ # This profides a framework of scientific computation.
8
+ # Users have to redefine some methods in subclasses for various computation.
9
+ #
10
+ class Comana
11
+ class NotImplementedError < Exception; end
12
+ class AlreadyStartedError < Exception; end
13
+
14
+ #
15
+ def initialize(dir)
16
+ @dir = dir
17
+ set_parameters
18
+ end
19
+
20
+ # Return a symbol which indicate state of calculation.
21
+ # :yet not started
22
+ # :started started, but not ended, including short time from last output
23
+ # :terminated started, but long time no output
24
+ # :next started, normal ended and need next calculation
25
+ # :finished started, normal ended and not need next calculation
26
+ def state
27
+ return :finished if finished?
28
+ return :next if normal_ended?
29
+ return :yet unless started?
30
+ return :terminated if (Time.now - latest_modified_time > @alive_time)
31
+ return :started
32
+ end
33
+
34
+ # Execute calculation.
35
+ # If log of Comana exist, raise Comana::AlreadyStartedError,
36
+ # because the calculation has been done by other process already.
37
+ def calculate
38
+ raise AlreadyStartedError if started?
39
+ File.open(@log, "w")
40
+ send_command
41
+ end
42
+
43
+ # Generate next calculation and return the computation object.
44
+ def prepare_next
45
+ raise NotImplementedError, "#{self.class}::prepare_next need to be redefined"
46
+ end
47
+
48
+ # Return initial state.
49
+ def initial_state
50
+ raise NotImplementedError, "#{self.class}::initial_state need to be redefined"
51
+ end
52
+
53
+ # Return latest state.
54
+ def latest_state
55
+ raise NotImplementedError, "#{self.class}::latest_state need to be redefined"
56
+ end
57
+
58
+ private
59
+
60
+ def send_command
61
+ raise NotImplementedError, "#{self.class}::send_command need to be redefined"
62
+ end
63
+
64
+ def set_parameters
65
+ raise NotImplementedError, "#{self.class}::set_parameters need to be redefined"
66
+
67
+ # e.g.,
68
+ #@logfile = "comana.log"
69
+ #@alive_time = 3600
70
+ #@outfiles = ["output_a", "ouput_b"] # should be use files only to output.
71
+ end
72
+
73
+ # Return latest modified time of files in calc dir recursively.
74
+ #require "find"
75
+ def latest_modified_time
76
+ tmp = Dir.glob("#{@dir}/**/*").max_by do |file|
77
+ File.mtime(file)
78
+ end
79
+ File.mtime(tmp)
80
+ end
81
+
82
+ def started?
83
+ File.exist?( "#{@dir}/#{@logfile}" )
84
+ end
85
+
86
+ # Return true if the condition is satisfied.
87
+ # E.g., when calculation output contains orthodox ending sequences.
88
+ def normal_ended?
89
+ raise NotImplementedError, "#{self.class}::normal_ended? need to be redefined"
90
+ end
91
+
92
+ # Return true if the condition is satisfied.
93
+ # E.g., calculation achieve convergence.
94
+ def finished?
95
+ raise NotImplementedError, "#{self.class}::finished? need to be redefined"
96
+ end
97
+
98
+ end
99
+
@@ -0,0 +1,221 @@
1
+ require "fileutils"
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ NOW = Time.now
5
+ CALC_DIR = "spec/dummy"
6
+ LOG = "#{CALC_DIR}/log"
7
+ #OUTFILES = ["output_a"]
8
+
9
+ class Comana
10
+ public :latest_modified_time, :started?
11
+ end
12
+
13
+ class CalcFinished < Comana
14
+ def normal_ended? ; true ; end
15
+ def finished? ; true ; end
16
+ def send_command ; ; end
17
+ def prepare_next ; ; end
18
+ def initial_state ; ; end
19
+ def latest_state ; ; end
20
+ def teardown ; ; end
21
+ def set_parameters
22
+ @logfile = "log"
23
+ @alive_time = 500
24
+ end
25
+ end
26
+
27
+ describe Comana, "with not calculated" do
28
+ class CalcYet < Comana
29
+ def normal_ended? ; false ; end
30
+ def finished? ; false ; end
31
+ def send_command ; ; end
32
+ def prepare_next ; ; end
33
+ def initial_state ; ; end
34
+ def latest_state ; ; end
35
+ def teardown ; ; end
36
+ def set_parameters
37
+ @logfile = "log"
38
+ @alive_time = 3600
39
+ end
40
+ end
41
+ before do
42
+ @calc = CalcYet .new(CALC_DIR)
43
+
44
+ File.utime(NOW - 1000 ,NOW - 1000, "#{CALC_DIR}/input_a")
45
+ File.utime(NOW - 2000 ,NOW - 2000, "#{CALC_DIR}/input_b")
46
+ FileUtils.rm(LOG) if File.exist?(LOG)
47
+ end
48
+
49
+ it "should return the state" do
50
+ @calc.state.should == :yet
51
+ end
52
+
53
+ it "should return latest modified time" do
54
+ @calc.latest_modified_time.should == (NOW - 1000)
55
+ end
56
+
57
+ it "should return false without log." do
58
+ @calc.started?.should_not == nil
59
+ @calc.started?.should be_false
60
+ end
61
+
62
+ it "should return true with log." do
63
+ File.open(LOG, "w")
64
+ @calc.started?.should be_true
65
+ end
66
+
67
+ after do
68
+ FileUtils.rm(LOG) if File.exist?(LOG)
69
+ end
70
+ end
71
+
72
+ describe Comana, "with log" do
73
+ class CalcStarted < Comana
74
+ def normal_ended? ; false ; end
75
+ def finished? ; false ; end
76
+ def send_command ; ; end
77
+ def prepare_next ; ; end
78
+ def initial_state ; ; end
79
+ def latest_state ; ; end
80
+ def teardown ; ; end
81
+ def set_parameters
82
+ @logfile = "log"
83
+ @alive_time = 5000
84
+ end
85
+ end
86
+
87
+ before do
88
+ @calc = CalcStarted .new(CALC_DIR)
89
+ File.utime(NOW - 1000 ,NOW - 1000, "#{CALC_DIR}/input_a")
90
+ File.utime(NOW - 2000 ,NOW - 2000, "#{CALC_DIR}/input_b")
91
+ File.open(LOG, "w")
92
+ end
93
+
94
+ it "should return :started" do
95
+ @calc.state.should == :started
96
+ end
97
+
98
+ after do
99
+ FileUtils.rm(LOG) if File.exist?(LOG)
100
+ end
101
+ end
102
+
103
+ #describe Comana, "with output" do
104
+ # class CalcStarted < Comana
105
+ # def normal_ended? ; false ; end
106
+ # def finished? ; false ; end
107
+ # def send_command ; ; end
108
+ # def prepare_next ; ; end
109
+ # def initial_state ; ; end
110
+ # def latest_state ; ; end
111
+ # def teardown ; ; end
112
+ # def set_parameters
113
+ # @logfile = "log"
114
+ # @alive_time = 5000
115
+ # end
116
+ # end
117
+ #
118
+ # before do
119
+ # @calc = CalcStarted .new(CALC_DIR)
120
+ # File.utime(NOW - 1000 ,NOW - 1000, "#{CALC_DIR}/input_a")
121
+ # File.utime(NOW - 2000 ,NOW - 2000, "#{CALC_DIR}/input_b")
122
+ # #File.open(OUTPUT, "w")
123
+ # end
124
+ #
125
+ # it "should return :started"
126
+ #
127
+ # after do
128
+ # FileUtils.rm(LOG) if File.exist?(LOG)
129
+ # end
130
+ #end
131
+
132
+ describe Comana, "with terminated" do
133
+ class CalcTerminated < Comana
134
+ def normal_ended? ; false ; end
135
+ def finished? ; false ; end
136
+ def send_command ; ; end
137
+ def prepare_next ; ; end
138
+ def initial_state ; ; end
139
+ def latest_state ; ; end
140
+ def teardown ; ; end
141
+ def set_parameters
142
+ @logfile = "log"
143
+ @alive_time = 500
144
+ end
145
+ end
146
+
147
+ before do
148
+ @calc_terminated = CalcTerminated.new(CALC_DIR)
149
+
150
+ File.utime(NOW - 1000 ,NOW - 1000, "#{CALC_DIR}/input_a")
151
+ File.utime(NOW - 2000 ,NOW - 2000, "#{CALC_DIR}/input_b")
152
+ File.open(LOG, "w")
153
+ end
154
+
155
+ it "should return the state" do
156
+ File.open(LOG, "w")
157
+ File.utime(NOW - 1000 ,NOW - 1000, LOG)
158
+ @calc_terminated .state.should == :terminated
159
+ end
160
+
161
+ after do
162
+ FileUtils.rm(LOG) if File.exist?(LOG)
163
+ end
164
+ end
165
+
166
+ describe Comana, "with next" do
167
+ class CalcNext < Comana
168
+ def normal_ended? ; true ; end
169
+ def finished? ; false ; end
170
+ def send_command ; ; end
171
+ def prepare_next ; ; end
172
+ def initial_state ; ; end
173
+ def latest_state ; ; end
174
+ def teardown ; ; end
175
+ def set_parameters
176
+ @logfile = "log"
177
+ @alive_time = 500
178
+ end
179
+ end
180
+
181
+ before do
182
+ @calc_next = CalcNext .new(CALC_DIR)
183
+
184
+ File.utime(NOW - 1000 ,NOW - 1000, "#{CALC_DIR}/input_a")
185
+ File.utime(NOW - 2000 ,NOW - 2000, "#{CALC_DIR}/input_b")
186
+ File.open(LOG, "w")
187
+ end
188
+
189
+ it "should return the state" do
190
+
191
+ File.open(LOG, "w")
192
+ File.utime(NOW - 1000 ,NOW - 1000, LOG)
193
+ @calc_next .state.should == :next
194
+ end
195
+
196
+ after do
197
+ FileUtils.rm(LOG) if File.exist?(LOG)
198
+ end
199
+ end
200
+
201
+ describe Comana, "with finished" do
202
+ before do
203
+ @calc_finished = CalcFinished .new(CALC_DIR)
204
+
205
+ File.utime(NOW - 1000 ,NOW - 1000, "#{CALC_DIR}/input_a")
206
+ File.utime(NOW - 2000 ,NOW - 2000, "#{CALC_DIR}/input_b")
207
+ #FileUtils.rm(LOG) if File.exist?(LOG)
208
+ File.open(LOG, "w")
209
+ end
210
+
211
+ it "should return the state" do
212
+
213
+ File.open(LOG, "w")
214
+ File.utime(NOW - 1000 ,NOW - 1000, LOG)
215
+ @calc_finished .state.should == :finished
216
+ end
217
+
218
+ after do
219
+ FileUtils.rm(LOG) if File.exist?(LOG)
220
+ end
221
+ end
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'comana'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comana
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ippei94da
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.9.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.9.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
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: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.3
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: 1.1.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.3
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.8.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
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: '0'
94
+ description: ! "An aim of this gem is to provide a framework of\n managing scientific
95
+ computing.\n Researchers on computing have to check calculation and\n generate
96
+ new calculation and execute, repeatedly.\n The abstract class that this gem provide
97
+ would help the work.\n "
98
+ email: ippei94da@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - LICENSE.txt
103
+ - README.rdoc
104
+ files:
105
+ - .document
106
+ - .rspec
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION
112
+ - lib/comana.rb
113
+ - spec/comana_spec.rb
114
+ - spec/dummy/input_a
115
+ - spec/dummy/input_b
116
+ - spec/spec_helper.rb
117
+ homepage: http://github.com/ippei94da/comana
118
+ licenses:
119
+ - MIT
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ segments:
131
+ - 0
132
+ hash: 940464947
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.21
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Manager for scientific computing
145
+ test_files: []