comana 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/comana.gemspec CHANGED
@@ -5,14 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "comana"
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
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-05-08"
12
+ s.date = "2012-05-10"
13
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
- s.executables = ["submitqueue"]
16
15
  s.extra_rdoc_files = [
17
16
  "LICENSE.txt",
18
17
  "README.rdoc"
@@ -25,7 +24,6 @@ Gem::Specification.new do |s|
25
24
  "README.rdoc",
26
25
  "Rakefile",
27
26
  "VERSION",
28
- "bin/submitqueue",
29
27
  "comana.gemspec",
30
28
  "dot.machineinfo",
31
29
  "lib/comana.rb",
@@ -48,6 +46,8 @@ Gem::Specification.new do |s|
48
46
  "spec/outputted/input_a",
49
47
  "spec/outputted/input_b",
50
48
  "spec/outputted/output",
49
+ "spec/queuesubmitter/locked/lock_queuesubmitter/dummy",
50
+ "spec/queuesubmitter/unlocked/dummy",
51
51
  "spec/queuesubmitter_spec.rb",
52
52
  "spec/spec_helper.rb"
53
53
  ]
data/dot.machineinfo CHANGED
@@ -1,3 +1,14 @@
1
1
  --- # vim:syntax=yaml
2
- "Host1":
3
- "vasp": "/usr/local/calc/vasp/vasp4631serial"
2
+
3
+ fileserver: Pt
4
+
5
+ SeriesA:
6
+ economy_nodes: 1 # num of nodes for prior efficiency mode.
7
+ speed_nodes: 4 # num of nodes for prior speed mode.
8
+ vasp: "/usr/local/calc/bin/mpiexec /usr/local/calc/bin/vasp4631-mpich2"
9
+
10
+ SeriesB:
11
+ economy_nodes: 1
12
+ speed_nodes: 8
13
+ vasp: "/usr/local/calc/bin/mpiexec /usr/local/calc/bin/vasp4631-mpich2"
14
+
@@ -1,10 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
  # coding: utf-8
3
3
 
4
- #
5
- # Comana: COmputation MANAger
6
- #
7
- # This profides a framework of scientific computation.
4
+ # This class profides a framework of scientific computation.
8
5
  # Users have to redefine some methods in subclasses for various computation.
9
6
  #
10
7
  class ComputationManager
@@ -44,22 +41,17 @@ class ComputationManager
44
41
  end
45
42
 
46
43
  while true
47
- end_status = calculate
48
- raise ExecuteError unless end_status
49
- if finished?
50
- break
51
- else
52
- prepare_next
53
- end
44
+ calculate
45
+ break if finished?
46
+ prepare_next
54
47
  end
55
- puts "Done."
56
48
  end
57
49
 
58
50
  private
59
51
 
60
- # Redefine in subclass.
61
- # Return nil if cannot execute, return false if error in executing,
62
- # like Kernel.system.
52
+ # Redefine in subclass, e.g.,
53
+ # end_status = system "command"
54
+ # raise ExecuteError unless end_status
63
55
  def calculate
64
56
  raise NotImplementedError, "#{self.class}::calculate need to be redefined"
65
57
  end
@@ -9,24 +9,36 @@ require "comana/machineinfo.rb"
9
9
  #
10
10
  class QueueSubmitter < ComputationManager
11
11
  QSUB_SCRIPT = "script.qsub"
12
+ WALLTIME = "7:00:00:00" # day:hour:minute:second
12
13
 
13
14
  class PrepareNextError < Exception; end
15
+ class InitializeError < Exception; end
14
16
 
15
- #
17
+ # opts is a hash includes data belows:
18
+ # :d => calculation as comana subclass.
19
+ # :c => command line.
20
+ # :n => name of cluster.
21
+ # :s => flag for speed prior mode (option).
22
+ # :machineinfo => MachineInfo class instance.
23
+ # NOTE:
24
+ # :d is a comana subclass not directory name to check to be calculatable.
16
25
  def initialize(opts)
17
- super(opts[:d])
26
+ raise InitializeError, "No :d entry in options" unless opts.has_key?(:d)
27
+ raise InitializeError, "No :c entry in options" unless opts.has_key?(:c)
28
+ raise InitializeError, "No :n entry in options" unless opts.has_key?(:n)
29
+ raise InitializeError, "No :machineinfo entry in options" unless opts.has_key?(:machineinfo)
30
+
31
+ super(opts[:d].dir)
18
32
  @command = opts[:c]
19
33
  @nodes = opts[:n]
20
- @speed = opts[:s]
34
+ @speed = opts[:s]
21
35
  @machineinfo = opts[:machineinfo]
22
36
  @lockdir = "lock_queuesubmitter"
23
37
  end
24
38
 
25
39
  def calculate
26
40
  script_path = "#{@dir}/#{QSUB_SCRIPT}"
27
- File.open(script_path, "w") do |io|
28
- dump_qsub_str(io)
29
- end
41
+ File.open(script_path, "w") { |io| dump_qsub_str(io) }
30
42
 
31
43
  system("cd #{@dir}; qsub #{script_path} > #{@dir}/#{@lockdir}/stdout")
32
44
  end
@@ -36,8 +48,9 @@ class QueueSubmitter < ComputationManager
36
48
  raise PrepareNextError
37
49
  end
38
50
 
51
+ # Return true after qsub executed.
39
52
  def finished?
40
- # do nothing
53
+ Dir.exist? @dir + "/" +@lockdir
41
54
  end
42
55
 
43
56
  private
@@ -51,15 +64,16 @@ class QueueSubmitter < ComputationManager
51
64
  str = [
52
65
  "#! /bin/sh",
53
66
  "#PBS -N #{@dir}",
54
- "#PBS -l nodes=#{num}:ppn=1:#{@nodes},walltime=168:00:00",
67
+ "#PBS -l nodes=#{num}:ppn=1:#{@nodes},walltime=#{WALLTIME}",
55
68
  "#PBS -j oe",
56
- "mkdir -p ${PBS_O_WORKDIR}",
57
- "cp ${PBS_NODEFILE} ${PBS_O_WORKDIR}/pbs_nodefile",
58
- "rsync -azq --delete #{fs}:${PBS_O_WORKDIR}/ ${PBS_O_WORKDIR}",
59
- "cd ${PBS_O_WORKDIR}",
60
- "#{@command}",
61
- "#rsync -azq --delete ${PBS_O_WORKDIR}/ #{fs}:${PBS_O_WORKDIR}",
69
+ "mkdir -p ${PBS_O_WORKDIR} && \\",
70
+ "rsync -azq --delete #{fs}:${PBS_O_WORKDIR}/ ${PBS_O_WORKDIR} && \\",
71
+ "cp ${PBS_NODEFILE} ${PBS_O_WORKDIR}/pbs_nodefile && \\",
72
+ "cd ${PBS_O_WORKDIR} && \\",
73
+ "#{@command} && \\",
74
+ "rsync -azq --delete ${PBS_O_WORKDIR}/ #{fs}:${PBS_O_WORKDIR} && \\",
62
75
  "#rm -rf ${PBS_O_WORKDIR}",
76
+ "mv ${PBS_O_WORKDIR} ~/.trash",
63
77
  ].join("\n")
64
78
 
65
79
  if io
data/memo.txt CHANGED
@@ -1,15 +1,25 @@
1
+ # Comana: COmputation MANAger
2
+
1
3
  Comana don't have information of output files.
2
4
  Because it is difficult to define final output and to deal systematically.
3
5
  e.g., repeated calculation till convergence.
4
6
 
7
+ 0.0.7 release [2012-05-10]
8
+ Bugfix of danger to rsync large directory:
9
+ - bin/submitqueue is removed.
10
+ - lib/queuesubmitter.rb is modified.
11
+ lib/queuesubmitter.rb is modified.
12
+ - finished? returns bool.
13
+ - content of qsub script to use "rsync" and "mv dir ~/.trash".
14
+
5
15
  0.0.6 release
6
- Add bin/submitqueue.
7
- Add lib/queuesubmitter.rb.
16
+ bin/submitqueue is add.
17
+ lib/queuesubmitter.rb is add.
8
18
 
9
19
  0.0.5 release
10
- Changed directory structure and file name.
11
- Changed method name.
12
- Added MachineInfo.
20
+ Directory structure and file names are changed.
21
+ Method names are hanged.
22
+ MachineInfo is added.
13
23
 
14
24
  0.0.4 release
15
25
 
@@ -127,7 +127,8 @@ end
127
127
  describe ComputationManager, "cannot execute" do
128
128
  class CalcNotExecutable < ComputationManager
129
129
  def calculate
130
- system "" # notExistCommand
130
+ end_status = system "" # notExistCommand
131
+ raise ExecuteError unless end_status
131
132
  end
132
133
 
133
134
  def finished?
File without changes
@@ -11,10 +11,72 @@ end
11
11
 
12
12
  #describe QueueSubmitter, "with chars to be escaped" do
13
13
  describe QueueSubmitter do
14
+ describe "#initialize" do
15
+ context "opts not have :d" do
16
+ opts = {
17
+ #:d => "dir_name",
18
+ :c => "command_line",
19
+ :n => "Nodes",
20
+ :s => true,
21
+ :machineinfo => MachineInfo.new(
22
+ "fileserver" => "FS",
23
+ "Nodes" => { "speed_nodes" => 4, "economy_nodes" => 1, }
24
+ )
25
+ }
26
+ it {lambda{QueueSubmitter.new(opts)}.should raise_error(
27
+ QueueSubmitter::InitializeError)}
28
+ end
29
+
30
+ context "opts not have :c" do
31
+ opts = {
32
+ :d => "dir_name",
33
+ #:c => "command_line",
34
+ :n => "Nodes",
35
+ :s => true,
36
+ :machineinfo => MachineInfo.new(
37
+ "fileserver" => "FS",
38
+ "Nodes" => { "speed_nodes" => 4, "economy_nodes" => 1, }
39
+ )
40
+ }
41
+ it {lambda{QueueSubmitter.new(opts)}.should raise_error(
42
+ QueueSubmitter::InitializeError)}
43
+ end
44
+
45
+ context "opts not have :n" do
46
+ opts = {
47
+ :d => "dir_name",
48
+ :c => "command_line",
49
+ #:n => "Nodes",
50
+ :s => true,
51
+ :machineinfo => MachineInfo.new(
52
+ "fileserver" => "FS",
53
+ "Nodes" => { "speed_nodes" => 4, "economy_nodes" => 1, }
54
+ )
55
+ }
56
+ it {lambda{QueueSubmitter.new(opts)}.should raise_error(
57
+ QueueSubmitter::InitializeError)}
58
+ end
59
+
60
+ context "opts not have :c" do
61
+ opts = {
62
+ :d => "dir_name",
63
+ :c => "command_line",
64
+ :n => "Nodes",
65
+ :s => true,
66
+ #:machineinfo => MachineInfo.new(
67
+ # "fileserver" => "FS",
68
+ # "Nodes" => { "speed_nodes" => 4, "economy_nodes" => 1, }
69
+ #)
70
+ }
71
+ it {lambda{QueueSubmitter.new(opts)}.should raise_error(
72
+ QueueSubmitter::InitializeError)}
73
+ end
74
+ end
75
+
14
76
  describe "#dump_qsub_str" do
15
77
  before do
16
78
  opts = {
17
- :d => "dir_name",
79
+ :d => ComputationManager.new("spec/not_started"),
18
80
  :c => "command_line",
19
81
  :n => "Nodes",
20
82
  :s => true,
@@ -27,16 +89,17 @@ describe QueueSubmitter do
27
89
 
28
90
  @correct = [
29
91
  "#! /bin/sh",
30
- "#PBS -N dir_name",
31
- "#PBS -l nodes=4:ppn=1:Nodes,walltime=168:00:00",
92
+ "#PBS -N spec/not_started",
93
+ "#PBS -l nodes=4:ppn=1:Nodes,walltime=7:00:00:00",
32
94
  "#PBS -j oe",
33
- "mkdir -p ${PBS_O_WORKDIR}",
34
- "cp ${PBS_NODEFILE} ${PBS_O_WORKDIR}/pbs_nodefile",
35
- "rsync -azq --delete FS:${PBS_O_WORKDIR}/ ${PBS_O_WORKDIR}",
36
- "cd ${PBS_O_WORKDIR}",
37
- "command_line",
38
- "#rsync -azq --delete ${PBS_O_WORKDIR}/ FS:${PBS_O_WORKDIR}",
95
+ "mkdir -p ${PBS_O_WORKDIR} && \\",
96
+ "rsync -azq --delete FS:${PBS_O_WORKDIR}/ ${PBS_O_WORKDIR} && \\",
97
+ "cp ${PBS_NODEFILE} ${PBS_O_WORKDIR}/pbs_nodefile && \\",
98
+ "cd ${PBS_O_WORKDIR} && \\",
99
+ "command_line && \\",
100
+ "rsync -azq --delete ${PBS_O_WORKDIR}/ FS:${PBS_O_WORKDIR} && \\",
39
101
  "#rm -rf ${PBS_O_WORKDIR}",
102
+ "mv ${PBS_O_WORKDIR} ~/.trash",
40
103
  ].join("\n")
41
104
  end
42
105
 
@@ -52,4 +115,42 @@ describe QueueSubmitter do
52
115
  end
53
116
  end
54
117
  end
118
+
119
+ describe "#finished?" do
120
+ context "locked" do
121
+ it do
122
+ opts = {
123
+ :d => ComputationManager.new("spec/queuesubmitter/locked"),
124
+ :c => "command_line",
125
+ :n => "Nodes",
126
+ :s => true,
127
+ :machineinfo => MachineInfo.new(
128
+ "fileserver" => "FS",
129
+ "Nodes" => { "speed_nodes" => 4, "economy_nodes" => 1, }
130
+ )
131
+ }
132
+ @qs00 = QueueSubmitter.new(opts)
133
+
134
+ @qs00.finished?.should == true
135
+ end
136
+ end
137
+
138
+ context "unlocked" do
139
+ it do
140
+ opts = {
141
+ :d => ComputationManager.new("spec/queuesubmitter/unlocked"),
142
+ :c => "command_line",
143
+ :n => "Nodes",
144
+ :s => true,
145
+ :machineinfo => MachineInfo.new(
146
+ "fileserver" => "FS",
147
+ "Nodes" => { "speed_nodes" => 4, "economy_nodes" => 1, }
148
+ )
149
+ }
150
+ @qs00 = QueueSubmitter.new(opts)
151
+
152
+ @qs00.finished?.should == false
153
+ end
154
+ end
155
+ end
55
156
  end
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.6
4
+ version: 0.0.7
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-05-08 00:00:00.000000000 Z
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &81878250 !ruby/object:Gem::Requirement
16
+ requirement: &80007130 !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: *81878250
24
+ version_requirements: *80007130
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &81877750 !ruby/object:Gem::Requirement
27
+ requirement: &80006610 !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: *81877750
35
+ version_requirements: *80006610
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &81877070 !ruby/object:Gem::Requirement
38
+ requirement: &80005810 !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: *81877070
46
+ version_requirements: *80005810
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &81876620 !ruby/object:Gem::Requirement
49
+ requirement: &80005240 !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: *81876620
57
+ version_requirements: *80005240
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &81875300 !ruby/object:Gem::Requirement
60
+ requirement: &80004850 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,14 +65,13 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *81875300
68
+ version_requirements: *80004850
69
69
  description: ! "Comana, COmputation MANAger,\n is a software to provide a framework
70
70
  of\n managing scientific computing.\n Researchers on computing have to check
71
71
  calculation and\n generate new calculation and execute, repeatedly.\n The
72
72
  abstract class that this gem provide would help the work.\n "
73
73
  email: ippei94da@gmail.com
74
- executables:
75
- - submitqueue
74
+ executables: []
76
75
  extensions: []
77
76
  extra_rdoc_files:
78
77
  - LICENSE.txt
@@ -85,7 +84,6 @@ files:
85
84
  - README.rdoc
86
85
  - Rakefile
87
86
  - VERSION
88
- - bin/submitqueue
89
87
  - comana.gemspec
90
88
  - dot.machineinfo
91
89
  - lib/comana.rb
@@ -108,6 +106,8 @@ files:
108
106
  - spec/outputted/input_a
109
107
  - spec/outputted/input_b
110
108
  - spec/outputted/output
109
+ - spec/queuesubmitter/locked/lock_queuesubmitter/dummy
110
+ - spec/queuesubmitter/unlocked/dummy
111
111
  - spec/queuesubmitter_spec.rb
112
112
  - spec/spec_helper.rb
113
113
  homepage: http://github.com/ippei94da/comana
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: 362387791
128
+ hash: 244597455
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements:
data/bin/submitqueue DELETED
@@ -1,65 +0,0 @@
1
- #! /usr/bin/env ruby
2
- # coding: utf-8
3
-
4
- require "optparse"
5
- require "yaml"
6
- require "pp"
7
- require "comana/queuesubmitter.rb"
8
- require "comana/machineinfo.rb"
9
-
10
- ## option analysis
11
- OPTS = {}
12
- op = OptionParser.new
13
- #op.on("-e", "--economy" , "Prior efficiency."){OPTS[:e] = true}
14
- op.on("-s" , "--speed" , "Prior speed to efficiency."){OPTS[:s] = true}
15
- op.on("-n nodes" , "--nodes" , "Node series." ){|v| OPTS[:n] = v}
16
- op.on("-c command", "--command", "Command to calculate." ){|v| OPTS[:c] = v}
17
- op.on("-d dir" , "--dir" , "Directory to calculate." ){|v| OPTS[:d] = v}
18
- op.parse!(ARGV)
19
- #cluster = ARGV[0]
20
- #cluster = ARGV
21
-
22
- OPTS[:machineinfo] = MachineInfo.load_file
23
-
24
- qs = QueueSubmitter.new(OPTS)
25
- begin
26
- qs.start
27
- rescue QueueSubmitter::AlreadyStartedError
28
- puts "Already started. Exit"
29
- exit
30
- rescue QueueSubmitter::PrepareNextError
31
- puts "Submitted. Exit"
32
- exit
33
- end
34
-
35
- #yaml = YAML.load_file("#{ENV["HOME"]}/.machineinfo")
36
- #pp yaml
37
- #
38
- #if File.exits?(SCRIPT_FILE)
39
- # puts "#{SCRIPT_FILE} already exist. Exit."
40
- # exit
41
- #end
42
- #
43
- #File.open(SCRIPT_FILE, "w") do |io|
44
- # io.puts "#PBS -N task"
45
- # io.puts "#PBS -l nodes=4:ppn=1:Ga"
46
- # io.puts "cd $PBS_O_WORKDIR"
47
- # io.puts "runvasp"
48
- # #io.puts "#/usr/local/bin/mpiexec /usr/local/bin/vasp5212mpi-ifc11-fast"
49
- # #io.puts "#/home/ippei/local/mpi/mpiexec-0.84/mpiexec /usr/local/calc/bin/vasp5212-mpich2"
50
- # #io.puts "#/usr/local/calc/mpiexec/bin/mpiexec /usr/local/calc/bin/vasp5212-mpich2"
51
- # #io.puts "#~/tmp.rb #OK"
52
- #
53
- # #io.puts condition
54
- # #io.puts rsync
55
- # #io.puts run
56
- # #io.puts rsync
57
- # #io.puts mv to trash?
58
- #end
59
- #
60
- ## Record job_id in pbs. Overwrite if exists.
61
- #job_id = `qsub #{SCRIPT_FILE}`
62
- #File.open(PBS_LOG, "w") do |io|
63
- # io.puts job_id
64
- #end
65
- #