comana 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -18,7 +18,8 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.homepage = "http://github.com/ippei94da/comana"
19
19
  gem.license = "MIT"
20
20
  gem.summary = %Q{Manager for scientific computing}
21
- gem.description = %Q{An aim of this gem is to provide a framework of
21
+ gem.description = %Q{Comana, COmputation MANAger,
22
+ is a software to provide a framework of
22
23
  managing scientific computing.
23
24
  Researchers on computing have to check calculation and
24
25
  generate new calculation and execute, repeatedly.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/comana.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "comana"
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ippei94da"]
12
- s.date = "2012-04-23"
13
- s.description = "An aim of this gem is to provide a framework of\n managing scientific computing.\n Researchers on computing have to check calculation and\n generate new calculation and execute, repeatedly.\n The abstract class that this gem provide would help the work.\n "
12
+ s.date = "2012-05-07"
13
+ s.description = "Comana, COmputation MANAger,\n is a software to provide a framework of\n managing scientific computing.\n Researchers on computing have to check calculation and\n generate new calculation and execute, repeatedly.\n The abstract class that this gem provide would help the work.\n "
14
14
  s.email = "ippei94da@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -25,15 +25,23 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "comana.gemspec",
28
+ "dot.machineinfo",
28
29
  "lib/comana.rb",
29
- "spec/comana_spec.rb",
30
+ "lib/comana/computationmanager.rb",
31
+ "lib/comana/machineinfo.rb",
32
+ "memo.txt",
33
+ "spec/computationmanager_spec.rb",
34
+ "spec/locked/comana_lock/dummy",
30
35
  "spec/locked/input_a",
31
36
  "spec/locked/input_b",
37
+ "spec/locked_outputted/comana_lock/dummy",
32
38
  "spec/locked_outputted/input_a",
33
39
  "spec/locked_outputted/input_b",
34
40
  "spec/locked_outputted/output",
35
- "spec/not_calculated/input_a",
36
- "spec/not_calculated/input_b",
41
+ "spec/machineinfo",
42
+ "spec/machineinfo_spec.rb",
43
+ "spec/not_started/input_a",
44
+ "spec/not_started/input_b",
37
45
  "spec/outputted/input_a",
38
46
  "spec/outputted/input_b",
39
47
  "spec/outputted/output",
data/dot.machineinfo ADDED
@@ -0,0 +1,3 @@
1
+ --- # vim:syntax=yaml
2
+ "Host1":
3
+ "vasp": "/usr/local/calc/vasp/vasp4631serial"
@@ -0,0 +1,86 @@
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
+ attr_reader :dir
15
+
16
+ # You can redefine in subclass to modify from default values.
17
+ def initialize(dir)
18
+ @dir = dir # redefine in subclass.
19
+ @lockdir = "comana_lock"
20
+ @alive_time = 3600
21
+ end
22
+
23
+ # Return a symbol which indicate state of calculation.
24
+ # :yet not started
25
+ # :started started, but not ended, including short time from last output
26
+ # :terminated started, but long time no output
27
+ # :finished started, normal ended and not need next calculation
28
+ def state
29
+ return :finished if finished?
30
+ return :yet unless started?
31
+ return :terminated if (Time.now - latest_modified_time > @alive_time)
32
+ return :started
33
+ end
34
+
35
+ # Execute calculation.
36
+ # If log of Comana exist, raise Comana::AlreadyStartedError,
37
+ # because the calculation has been done by other process already.
38
+ def start
39
+ begin
40
+ Dir.mkdir "#{@dir}/#{@lockdir}"
41
+ rescue Errno::EEXIST
42
+ raise AlreadyStartedError, "Exist #{@dir}/#{@lockdir}"
43
+ end
44
+
45
+ while true
46
+ calculate
47
+ if finished?
48
+ break
49
+ else
50
+ prepare_next
51
+ end
52
+ end
53
+ puts "Done."
54
+ end
55
+
56
+ private
57
+
58
+ def calculate
59
+ raise NotImplementedError, "#{self.class}::calculate need to be redefined"
60
+ end
61
+
62
+ def prepare_next
63
+ raise NotImplementedError, "#{self.class}::prepare_next need to be redefined"
64
+ end
65
+
66
+ # Return latest modified time of files in calc dir recursively.
67
+ # require "find"
68
+ def latest_modified_time
69
+ tmp = Dir.glob("#{@dir}/**/*").max_by do |file|
70
+ File.mtime(file)
71
+ end
72
+ File.mtime(tmp)
73
+ end
74
+
75
+ def started?
76
+ return true if File.exist?( "#{@dir}/#{@lockdir}" )
77
+ return false
78
+ end
79
+
80
+ # Return true if the condition is satisfied.
81
+ def finished?
82
+ raise NotImplementedError, "#{self.class}::finished? need to be redefined"
83
+ end
84
+
85
+ end
86
+
@@ -0,0 +1,33 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "yaml"
5
+
6
+ #
7
+ #
8
+ #
9
+ class MachineInfo
10
+
11
+ class NoEntryError < Exception; end
12
+
13
+ #
14
+ def initialize(data)
15
+ @data = data
16
+ end
17
+
18
+ def self.load_file(data_file)
19
+ #pp data_file
20
+ #pp ENV["PWD"]
21
+ #pp File.open(DATA_FILE, "r").readlines
22
+ data = YAML.load_file(data_file)
23
+ MachineInfo.new data
24
+ #pp @data
25
+ end
26
+
27
+ def get_host(host)
28
+ raise NoEntryError unless @data.has_key?(host)
29
+ @data[host]
30
+ end
31
+
32
+ end
33
+
data/lib/comana.rb CHANGED
@@ -1,86 +1,2 @@
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
- attr_reader :dir
15
-
16
- #
17
- def initialize(dir)
18
- @dir = dir
19
- set_parameters
20
- end
21
-
22
- # Return a symbol which indicate state of calculation.
23
- # :yet not started
24
- # :started started, but not ended, including short time from last output
25
- # :terminated started, but long time no output
26
- # :finished started, normal ended and not need next calculation
27
- def state
28
- return :finished if finished?
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
- begin
39
- Dir.mkdir @lockdir
40
- rescue Errno::EEXIST
41
- raise AlreadyStartedError
42
- end
43
- send_command
44
- end
45
-
46
- private
47
-
48
- def send_command
49
- raise NotImplementedError, "#{self.class}::send_command need to be redefined"
50
- end
51
-
52
- def set_parameters
53
- raise NotImplementedError, "#{self.class}::set_parameters need to be redefined"
54
-
55
- # e.g.,
56
- #@lockdir = "comana_lock"
57
- #@alive_time = 3600
58
- #@outfiles = ["output_a", "ouput_b"] # Files only to output should be indicated.
59
- end
60
-
61
- # Return latest modified time of files in calc dir recursively.
62
- # require "find"
63
- # Not only @outfiles, to catch an irregular state at the beginning before output.
64
- def latest_modified_time
65
- tmp = Dir.glob("#{@dir}/**/*").max_by do |file|
66
- File.mtime(file)
67
- end
68
- File.mtime(tmp)
69
- end
70
-
71
- def started?
72
- return true if File.exist?( "#{@dir}/#{@lockdir}" )
73
- #@outfiles.each do |file|
74
- # return true if File.exist?( "#{@dir}/#{file}" )
75
- #end
76
- return false
77
- end
78
-
79
- # Return true if the condition is satisfied.
80
- # E.g., when calculation output contains orthodox ending sequences.
81
- def finished?
82
- raise NotImplementedError, "#{self.class}::finished? need to be redefined"
83
- end
84
-
85
- end
86
-
1
+ require "comana/computationmanager.rb"
2
+ require "comana/machineinfo.rb"
data/memo.txt ADDED
@@ -0,0 +1,11 @@
1
+ Comana don't have information of output files.
2
+ Because it is difficult to define final output and to deal systematically.
3
+ e.g., repeated calculation till convergence.
4
+
5
+ 0.0.5 release
6
+ Changed directory structure and file name.
7
+ Changed method name.
8
+ Added MachineInfo.
9
+
10
+ 0.0.4 release
11
+
@@ -7,22 +7,17 @@ class Comana
7
7
  public :latest_modified_time, :started?
8
8
  end
9
9
 
10
- describe Comana, "not calculated" do
10
+ describe Comana, "not started" do
11
11
  class CalcYet < Comana
12
12
  def finished? ; false ; end
13
- def set_parameters
14
- @lockdir = "lock"
15
- @alive_time = 3600
16
- @outfiles = ["output"]
17
- end
18
13
  end
19
14
  before do
20
- calc_dir = "spec/not_calculated"
15
+ calc_dir = "spec/not_started"
21
16
  @calc = CalcYet.new(calc_dir)
22
17
 
23
18
  File.utime(NOW - 1000 ,NOW - 1000, "#{calc_dir}/input_a")
24
19
  File.utime(NOW - 2000 ,NOW - 2000, "#{calc_dir}/input_b")
25
- @lockdir = "#{calc_dir}/lockdir"
20
+ @lockdir = "#{calc_dir}/comana_lock"
26
21
  FileUtils.rm(@lockdir) if File.exist?(@lockdir)
27
22
  end
28
23
 
@@ -51,11 +46,6 @@ end
51
46
  describe Comana, "with lock" do
52
47
  class CalcStarted < Comana
53
48
  def finished? ; false ; end
54
- def set_parameters
55
- @lockdir = "lock"
56
- @alive_time = 5000
57
- @outfiles = ["output"]
58
- end
59
49
  end
60
50
 
61
51
  before do
@@ -73,11 +63,6 @@ end
73
63
  describe Comana, "with output, without lock" do
74
64
  class CalcStarted < Comana
75
65
  def finished? ; false ; end
76
- def set_parameters
77
- @lockdir = "lock"
78
- @alive_time = 5000
79
- @outfiles = ["output"]
80
- end
81
66
  end
82
67
 
83
68
  before do
@@ -99,10 +84,10 @@ end
99
84
  describe Comana, "terminated" do
100
85
  class CalcTerminated < Comana
101
86
  def finished? ; false ; end
102
- def set_parameters
103
- @lockdir = "lock"
87
+ def initialize(dir)
88
+ @dir = dir
89
+ @lockdir = "comana_lock"
104
90
  @alive_time = 500
105
- @outfiles = ["output"]
106
91
  end
107
92
  end
108
93
 
@@ -113,7 +98,7 @@ describe Comana, "terminated" do
113
98
  File.utime(NOW - 1000 ,NOW - 1000, "#{calc_dir}/input_a")
114
99
  File.utime(NOW - 2000 ,NOW - 2000, "#{calc_dir}/input_b")
115
100
  File.utime(NOW - 9000 ,NOW - 9000, "#{calc_dir}/output")
116
- File.utime(NOW - 9000 ,NOW - 9000, "#{calc_dir}/lock")
101
+ File.utime(NOW - 9000 ,NOW - 9000, "#{calc_dir}/comana_lock")
117
102
  end
118
103
 
119
104
  it "should return the state" do
@@ -124,11 +109,6 @@ end
124
109
  describe Comana, "finished" do
125
110
  class CalcFinished < Comana
126
111
  def finished? ; true ; end
127
- def set_parameters
128
- @lockdir = "lock"
129
- @alive_time = 500
130
- @outfiles = ["output"]
131
- end
132
112
  end
133
113
 
134
114
  before do
data/spec/machineinfo ADDED
@@ -0,0 +1,7 @@
1
+ --- # vim:syntax=yaml
2
+ "Host1":
3
+ "data1": "1-1"
4
+ "data2": "1-2"
5
+ "Host2":
6
+ "data1": "2-1"
7
+ "data2": "2-2"
@@ -0,0 +1,56 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "fileutils"
5
+
6
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
7
+ require "comana/machineinfo.rb"
8
+
9
+ describe MachineInfo do
10
+ describe "#load_file" do
11
+ context "not exist machineinfo file" do
12
+ DATA_FILE = "spec/machineinfo"
13
+ #DATA_FILE = "spec/dummy.yaml"
14
+ #data = {
15
+ # "Host1" => { "data1" => "1-1", "data2" => "1-2" },
16
+ # "Host2" => { "data1" => "2-1", "data2" => "2-2" },
17
+ #}
18
+ #io = File.open(DATA_FILE, "w")
19
+ #YAML.dump(data, io)
20
+ #io.close
21
+
22
+ #pp File.open(DATA_FILE, "r").readlines
23
+
24
+ it { lambda{MachineInfo.load_file(DATA_FILE)}.should_not raise_error}
25
+
26
+ mi00 = MachineInfo.load_file(DATA_FILE)
27
+ it {mi00.get_host("Host1").should == { "data1" => "1-1", "data2" => "1-2" } }
28
+
29
+ #FileUtils.rm DATA_FILE
30
+ end
31
+
32
+ context "not exist machineinfo file" do
33
+ it { lambda{ MachineInfo.load_file("") }.should raise_error(Errno::ENOENT) }
34
+ end
35
+ end
36
+
37
+ describe "#get_host" do
38
+ before do
39
+ @mi00 = MachineInfo.new({
40
+ "Host1" => { "data1" => "1-1", "data2" => "1-2" },
41
+ "Host2" => { "data1" => "2-1", "data2" => "2-2" },
42
+ })
43
+ end
44
+
45
+ context "exist in data" do
46
+ subject { @mi00.get_host("Host1") }
47
+ it {should == { "data1" => "1-1", "data2" => "1-2" } }
48
+ end
49
+
50
+ context "no entry" do
51
+ it {lambda{@mi00.get_host("")}.should raise_error(MachineInfo::NoEntryError)}
52
+ end
53
+ end
54
+
55
+ end
56
+
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comana
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-23 00:00:00.000000000 Z
12
+ date: 2012-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &84974590 !ruby/object:Gem::Requirement
16
+ requirement: &75511580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.9.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *84974590
24
+ version_requirements: *75511580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &84974230 !ruby/object:Gem::Requirement
27
+ requirement: &75526670 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.12'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *84974230
35
+ version_requirements: *75526670
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &84973850 !ruby/object:Gem::Requirement
38
+ requirement: &75525340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.1.3
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *84973850
46
+ version_requirements: *75525340
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &84973550 !ruby/object:Gem::Requirement
49
+ requirement: &75524370 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.8.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *84973550
57
+ version_requirements: *75524370
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &84973190 !ruby/object:Gem::Requirement
60
+ requirement: &75523390 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,11 +65,11 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *84973190
69
- description: ! "An aim of this gem is to provide a framework of\n managing scientific
70
- computing.\n Researchers on computing have to check calculation and\n generate
71
- new calculation and execute, repeatedly.\n The abstract class that this gem provide
72
- would help the work.\n "
68
+ version_requirements: *75523390
69
+ description: ! "Comana, COmputation MANAger,\n is a software to provide a framework
70
+ of\n managing scientific computing.\n Researchers on computing have to check
71
+ calculation and\n generate new calculation and execute, repeatedly.\n The
72
+ abstract class that this gem provide would help the work.\n "
73
73
  email: ippei94da@gmail.com
74
74
  executables: []
75
75
  extensions: []
@@ -85,15 +85,23 @@ files:
85
85
  - Rakefile
86
86
  - VERSION
87
87
  - comana.gemspec
88
+ - dot.machineinfo
88
89
  - lib/comana.rb
89
- - spec/comana_spec.rb
90
+ - lib/comana/computationmanager.rb
91
+ - lib/comana/machineinfo.rb
92
+ - memo.txt
93
+ - spec/computationmanager_spec.rb
94
+ - spec/locked/comana_lock/dummy
90
95
  - spec/locked/input_a
91
96
  - spec/locked/input_b
97
+ - spec/locked_outputted/comana_lock/dummy
92
98
  - spec/locked_outputted/input_a
93
99
  - spec/locked_outputted/input_b
94
100
  - spec/locked_outputted/output
95
- - spec/not_calculated/input_a
96
- - spec/not_calculated/input_b
101
+ - spec/machineinfo
102
+ - spec/machineinfo_spec.rb
103
+ - spec/not_started/input_a
104
+ - spec/not_started/input_b
97
105
  - spec/outputted/input_a
98
106
  - spec/outputted/input_b
99
107
  - spec/outputted/output
@@ -113,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
121
  version: '0'
114
122
  segments:
115
123
  - 0
116
- hash: -295869967
124
+ hash: 196413437
117
125
  required_rubygems_version: !ruby/object:Gem::Requirement
118
126
  none: false
119
127
  requirements: