pione 0.1.0 → 0.1.1

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.
Files changed (38) hide show
  1. data/History.txt +13 -0
  2. data/Rakefile +3 -3
  3. data/example/DeferredChoice/DeferredChoice.pione +50 -0
  4. data/example/Fib/Fib.pione +17 -16
  5. data/example/SingleParticlesWithRef/SingleParticlesWithRef.Display2.pione +128 -0
  6. data/lib/pione.rb +1 -0
  7. data/lib/pione/agent/broker.rb +18 -4
  8. data/lib/pione/agent/task-worker.rb +19 -21
  9. data/lib/pione/command-option/task-worker-owner-option.rb +1 -1
  10. data/lib/pione/command/basic-command.rb +13 -8
  11. data/lib/pione/command/front-owner-command.rb +1 -1
  12. data/lib/pione/command/pione-broker.rb +2 -1
  13. data/lib/pione/command/pione-client.rb +41 -2
  14. data/lib/pione/command/pione-syntax-checker.rb +14 -3
  15. data/lib/pione/command/pione-task-worker.rb +4 -1
  16. data/lib/pione/command/pione-tuple-space-provider.rb +6 -7
  17. data/lib/pione/model/assignment.rb +6 -0
  18. data/lib/pione/model/message.rb +7 -3
  19. data/lib/pione/model/variable.rb +11 -0
  20. data/lib/pione/parser/common-parser.rb +36 -14
  21. data/lib/pione/parser/document-parser.rb +82 -5
  22. data/lib/pione/parser/rule-definition-parser.rb +2 -30
  23. data/lib/pione/system/config.rb +54 -6
  24. data/lib/pione/system/document.rb +13 -4
  25. data/lib/pione/system/global.rb +8 -8
  26. data/lib/pione/system/init.rb +3 -0
  27. data/lib/pione/transformer/document-transformer.rb +5 -1
  28. data/lib/pione/transformer/rule-definition-transformer.rb +8 -14
  29. data/lib/pione/tuple-space/tuple-space-receiver.rb +1 -1
  30. data/lib/pione/version.rb +2 -1
  31. data/pione.gemspec +2 -0
  32. data/test/parser/spec_document-parser.rb +5 -0
  33. data/test/parser/spec_document-parser.yml +62 -0
  34. data/test/{spec_document.rb → system/spec_document.rb} +22 -2
  35. data/test/test-util.rb +3 -3
  36. data/test/transformer/spec_rule-definition-transformer.rb +68 -73
  37. metadata +46 -5
  38. data/example/Fib/FibBC.pione +0 -56
@@ -0,0 +1,13 @@
1
+ # History
2
+
3
+ ## 0.1.1
4
+
5
+ * Improved performance
6
+ * Added the concept of document parameter
7
+ * Added --list-params option
8
+ * Fixed bugs of features handling
9
+ * Improved comment parser
10
+
11
+ ## 0.1.0
12
+
13
+ * First gem release
data/Rakefile CHANGED
@@ -3,13 +3,13 @@ require "bundler/gem_tasks"
3
3
  $stand_alone = "bin/pione-client --stand-aline"
4
4
 
5
5
  desc 'generate HTML API documentation'
6
- task :html do
7
- sh "yard doc -o html --hide-void-return --no-api --private"
6
+ task 'html' do
7
+ sh 'bundle exec yard doc -o html --hide-void-return --no-api --private'
8
8
  end
9
9
 
10
10
  desc 'Show undocumented function list'
11
11
  task 'html:undoc' do
12
- sh 'yard stats --list-undoc --no-api --private'
12
+ sh 'bundle exec yard stats --list-undoc --no-api --private'
13
13
  end
14
14
 
15
15
  desc 'count characters in input direcotry'
@@ -0,0 +1,50 @@
1
+ Rule Main
2
+ output 'result.txt'
3
+ param $DIALOG := "zenity"
4
+ Flow
5
+ rule UserSelect.params({DIALOG: $DIALOG})
6
+ rule A
7
+ rule B
8
+ rule C
9
+ End
10
+
11
+ Rule UserSelect
12
+ output 'a.txt:b.txt:c.txt'
13
+ param $DIALOG
14
+ feature +Interactive
15
+ Action
16
+ if [ "{$DIALOG}" = "zenity" ]
17
+ then
18
+ zenity --list --title "select action" --column rule "rule A" "rule B" "rule C" > rule.txt
19
+ else
20
+ xmessage -print -center -buttons "rule A,rule B,rule C" "select action" > rule.txt
21
+ fi
22
+ RULE=`cat rule.txt`
23
+ case "$RULE" in
24
+ "rule A") touch a.txt ;;
25
+ "rule B") touch b.txt ;;
26
+ "rule C") touch c.txt ;;
27
+ esac
28
+ End
29
+
30
+ Rule A
31
+ input 'a.txt'
32
+ output 'result.txt'
33
+ Action
34
+ echo 'You selected rule A' > {$O[1]}
35
+ End
36
+
37
+ Rule B
38
+ input 'b.txt'
39
+ output 'result.txt'
40
+ Action
41
+ echo 'You selected rule B' > {$O[1]}
42
+ End
43
+
44
+ Rule C
45
+ input 'c.txt'
46
+ output 'result.txt'
47
+ Action
48
+ echo 'You selected rule C' > {$O[1]}
49
+ End
50
+
@@ -1,9 +1,10 @@
1
+ param $NUM := 3
2
+
1
3
  Rule Main
2
4
  output 'result.txt'
3
- param $NUM := 3
4
5
  Flow
5
- rule Fib
6
- rule Result
6
+ rule Fib.params({N: $NUM})
7
+ rule Result.params({N: $NUM})
7
8
  End
8
9
 
9
10
  Rule Fib0
@@ -19,38 +20,38 @@ Action
19
20
  End
20
21
 
21
22
  Rule Fib
22
- output 'fib{$NUM}.txt'
23
- param $NUM
23
+ output 'fib{$N}.txt'
24
+ param $N
24
25
  Flow
25
- case $NUM
26
+ case $N
26
27
  when 0
27
28
  rule Fib0
28
29
  when 1
29
30
  rule Fib1
30
31
  else
31
- $P1 := $NUM - 2
32
- $P2 := $NUM - 1
33
- rule Fib.params({NUM: $P1})
34
- rule Fib.params({NUM: $P2})
35
- rule Calc.params({NUM: $NUM, P1: $P1, P2: $P2})
32
+ $P1 := $N - 2
33
+ $P2 := $N - 1
34
+ rule Fib.params({N: $P1})
35
+ rule Fib.params({N: $P2})
36
+ rule Calc.params({N: $N, P1: $P1, P2: $P2})
36
37
  end
37
38
  End
38
39
 
39
40
  Rule Calc
40
41
  input 'fib{$P1}.txt'
41
42
  input 'fib{$P2}.txt'
42
- output 'fib{$NUM}.txt'
43
- param $NUM
43
+ output 'fib{$N}.txt'
44
+ param $N
44
45
  param $P1
45
46
  param $P2
46
47
  Action
47
- expr `cat {$I[1]}` + `cat {$I[2]}` > {$O[1]}
48
+ echo "`cat {$I[1]}` + `cat {$I[2]}`" | bc > {$O[1]}
48
49
  End
49
50
 
50
51
  Rule Result
51
- input 'fib{$NUM}.txt'
52
+ input 'fib{$N}.txt'
52
53
  output 'result.txt'
53
- param $NUM
54
+ param $N
54
55
  Action
55
56
  cat {$I[1]} > {$O[1]}
56
57
  End
@@ -0,0 +1,128 @@
1
+ #
2
+ # Eos for 3D reconstrucion from 2D rois using 3D initail reference
3
+ #
4
+
5
+ #
6
+ # Variables
7
+ #
8
+
9
+ # Target structure name
10
+ $TARGET := "all"
11
+
12
+ #
13
+ # Search Area for 3D
14
+ #
15
+
16
+ # Rot1
17
+ $ROT1MIN := 0
18
+ $ROT1MAX := 359
19
+ $ROT1D := 30
20
+ $nRot1 := 12
21
+
22
+ # Rot2
23
+ $ROT2MIN := 0
24
+ $ROT2MAX := 359
25
+ $ROT2D := 30
26
+ $nRot2 := 12
27
+
28
+ # Rot3
29
+ $ROT3MIN := 0
30
+ $ROT3MAX := 0
31
+ $ROT3D := 30
32
+ $nRot3 := 1
33
+
34
+ # For 2D
35
+ $STEP := 12
36
+ $ROTMIN := 0
37
+ $ROTMAX := 359
38
+ $nROT := 360 / $STEP
39
+
40
+ # Pad size for 2D
41
+ $PAD_W := 64
42
+ $PAD_H := 64
43
+
44
+ #
45
+ # Rules
46
+ #
47
+
48
+ Rule Main
49
+ input '*.roi'.all
50
+ input '{$TARGET}.ref3d'
51
+ input '{$TARGET}.ref2d'
52
+ output '{$TARGET}.3d'
53
+ output 'checked'
54
+ Flow
55
+ rule Create3dinfo
56
+ rule Create3dlst
57
+ rule Create3d
58
+ rule ShowResult
59
+ End
60
+
61
+ Rule Create3dinfo
62
+ input '*.roi'
63
+ input '{$TARGET}.ref2d'
64
+ output '{$*}.corinfo'
65
+ output '{$*}.fit'
66
+ output '{$*}.3dinfo'
67
+ Flow
68
+ rule ConvertRoiToPad
69
+ rule ConvertPadToCorinfo
70
+ rule ConvertCorinfoTo3dinfo
71
+ End
72
+
73
+ # .roi.pad
74
+ Rule ConvertRoiToPad
75
+ input '*.roi'
76
+ output '{$*}.pad'
77
+ Action
78
+ mrcImageWindowing -i {$*}.roi -o {$*}.mask -W 0.1 0.0 0.05 0.0 -m 18
79
+ mrcImagePad -i {$*}.mask -o {$*}.padtmp -W {$PAD_W} -H {$PAD_H} -m 3
80
+ mrcImageWindowing -i {$*}.padtmp -o {$*}.pad -W 0.1 0.0 0.1 0.0 -m 2
81
+ End
82
+
83
+ # .pad.corinfo
84
+ Rule ConvertPadToCorinfo
85
+ input '*.pad'
86
+ input '{$TARGET}.ref2d'
87
+ output '{$*}.corinfo'
88
+ output '{$*}.fit'
89
+ Action
90
+ mrcImageAutoRotationCorrelation -i {$*}.pad -r {$TARGET}.ref2d -O {$*}.corinfo -fit {$*}.fit -cor {$*}.cormap -n {$nROT} -m 18 -range {$ROTMIN} {$ROTMAX} -Iter 2 -nRot2 {$nRot2} -nRot1 {$nRot1} -nRot3 {$nRot3} 2> /dev/null
91
+ End
92
+
93
+ # .corinfo.3dinfo
94
+ Rule ConvertCorinfoTo3dinfo
95
+ input '*.corinfo'
96
+ output '{$*}.3dinfo'
97
+ Action
98
+ awk '/Cor/ { print $7,$16,$2,$3,$4,$5,$9,$11,$12}' {$*}.corinfo | sort -r | sed -e s/.pad/.fit/ > {$*}.3dinfolst
99
+ head -n 1 {$*}.3dinfolst | awk '{print $2,$3,$4,$5,$6,$1}' > {$*}.3dinfo
100
+ End
101
+
102
+ # .3dinfo.3dlst
103
+ Rule Create3dlst
104
+ input '*.3dinfo'.all
105
+ output '{$TARGET}.3dlst'
106
+ Action
107
+ cat {$I[1].join(" ")} | sort > {$TARGET}.3dlst
108
+ End
109
+
110
+ # .3dlst.3d
111
+ Rule Create3d
112
+ input '{$TARGET}.3dlst'
113
+ input '*.fit'.all
114
+ output '{$TARGET}.3d'
115
+ Action
116
+ mrc2Dto3D -I {$TARGET}.3dlst -o {$TARGET}.3d -InterpolationMode 2 -Double -DoubleCounter {$TARGET}.3dcounter -CounterThreshold 0.5 -m 1 -WeightMode 2
117
+ End
118
+
119
+ # show result by Display2
120
+ Rule ShowResult
121
+ input '{$TARGET}.3d'
122
+ output 'checked'
123
+ feature +Interactive
124
+ Action
125
+ Display2 -i '{$TARGET}.3d'
126
+ echo "I checked the result." > checked
127
+ End
128
+
@@ -29,6 +29,7 @@ require 'ostruct'
29
29
  require 'net/ftp'
30
30
  require 'highline'
31
31
  require 'dropbox_sdk'
32
+ require 'naming'
32
33
 
33
34
  #
34
35
  # load pione
@@ -106,7 +106,7 @@ module Pione
106
106
 
107
107
  # Return excess number of workers belongs to this broker.
108
108
  def excess_task_workers
109
- @task_worker_resource - @task_workers.size
109
+ @task_worker_resource - @task_workers.size - @spawnings
110
110
  end
111
111
 
112
112
  # Return task wainting workers.
@@ -128,7 +128,14 @@ module Pione
128
128
  def create_task_worker(tuple_space_server)
129
129
  connection_id = Util.generate_uuid
130
130
  @assignment_table[connection_id] = tuple_space_server
131
- Agent[:task_worker].spawn(Global.front, connection_id)
131
+ Thread.new do
132
+ begin
133
+ @spawnings += 1
134
+ Agent[:task_worker].spawn(Global.front, connection_id, @features)
135
+ ensure
136
+ @spawnings -= 1
137
+ end
138
+ end
132
139
  end
133
140
 
134
141
  # Deletes unavilable tuple space servers.
@@ -197,8 +204,11 @@ module Pione
197
204
  attr_reader :tuple_space_servers
198
205
  attr_reader :task_worker_resource
199
206
 
207
+ # current spawning task worker number
208
+ attr_reader :spawnings
209
+
200
210
  # @api private
201
- def initialize(data={})
211
+ def initialize(features, data={})
202
212
  super()
203
213
  @task_workers = []
204
214
  @tuple_space_servers = []
@@ -206,6 +216,8 @@ module Pione
206
216
  @sleeping_time = data[:sleeping_time] || 1
207
217
  @assignment_table = {}
208
218
  @tuple_space_server_lock = Mutex.new
219
+ @spawnings = 0
220
+ @features = features
209
221
 
210
222
  # balancer
211
223
  @balancer = EasyBalancer.new(self)
@@ -265,7 +277,9 @@ module Pione
265
277
 
266
278
  # Transits to the state +sleeping+.
267
279
  def transit_to_sleeping
268
- sleep 1
280
+ if @tuple_space_servers.size == 0 or excess_task_workers == 0
281
+ sleep 1
282
+ end
269
283
  end
270
284
  end
271
285
 
@@ -25,28 +25,26 @@ module Pione
25
25
  # @return [Thread]
26
26
  # worker monitor thread
27
27
  def self.spawn(front, connection_id, features=nil)
28
- @mutex.synchronize do
29
- args = [
30
- "pione-task-worker",
31
- "--parent-front", Global.front.uri,
32
- "--connection-id", connection_id
33
- ]
34
- args << "--debug" if Pione.debug_mode?
35
- args << "--show-communication" if Global.show_communication
36
- args << "--features" << features if features
37
- pid = Process.spawn(*args)
38
- thread = Process.detach(pid)
39
- # connection check
40
- while thread.alive?
41
- break if front.task_worker_front_connection_id.include?(connection_id)
42
- sleep 0.1
43
- end
44
- # error check
45
- unless thread.alive?
46
- Process.abort("You cannot run pione-task-worker.")
47
- end
48
- return thread
28
+ args = [
29
+ "pione-task-worker",
30
+ "--parent-front", Global.front.uri,
31
+ "--connection-id", connection_id
32
+ ]
33
+ args << "--debug" if Pione.debug_mode?
34
+ args << "--show-communication" if Global.show_communication
35
+ args << "--features" << features if features
36
+ pid = Process.spawn(*args)
37
+ thread = Process.detach(pid)
38
+ # connection check
39
+ while thread.alive?
40
+ break if front.task_worker_front_connection_id.include?(connection_id)
41
+ sleep 0.1
42
+ end
43
+ # error check
44
+ unless thread.alive?
45
+ Process.abort("You cannot run pione-task-worker.")
49
46
  end
47
+ return thread
50
48
  end
51
49
 
52
50
  define_state :task_waiting
@@ -9,7 +9,7 @@ module Pione
9
9
  end
10
10
 
11
11
  # --features
12
- define_option('--features="FEATURES"', 'set features') do |features|
12
+ define_option('--features=FEATURES', 'set features') do |features|
13
13
  @features = features
14
14
  end
15
15
  end
@@ -25,13 +25,18 @@ module Pione
25
25
  end
26
26
 
27
27
  module InstanceInterface
28
- # Returns program name.
29
- # @return [String]
30
- # program name
31
- def program_name
32
- name, b = self.class.program_name
33
- tail = self.instance_exec(&b)
34
- "%s %s" % [name, tail]
28
+ # Setup program name. If the setup process is failed, program name is not
29
+ # changed.
30
+ #
31
+ # @return [void]
32
+ def setup_program_name
33
+ begin
34
+ name, b = self.class.program_name
35
+ tail = self.instance_exec(&b)
36
+ $PROGRAM_NAME = "%s %s" % [name, tail]
37
+ rescue Exception
38
+ nil
39
+ end
35
40
  end
36
41
 
37
42
  # Returns program message.
@@ -65,7 +70,7 @@ module Pione
65
70
  parse_options
66
71
  validate_options
67
72
  prepare
68
- $PROGRAM_NAME = program_name
73
+ setup_program_name
69
74
  start
70
75
  end
71
76
 
@@ -11,7 +11,7 @@ module Pione
11
11
  validate_options
12
12
  setup_front
13
13
  prepare
14
- $PROGRAM_NAME = program_name
14
+ setup_program_name
15
15
  start
16
16
  end
17
17
 
@@ -16,6 +16,7 @@ TXT
16
16
 
17
17
  def initialize
18
18
  @task_worker = [Util.core_number - 1, 1].max
19
+ @features = nil
19
20
  end
20
21
 
21
22
  def create_front
@@ -30,7 +31,7 @@ TXT
30
31
 
31
32
  def prepare
32
33
  super
33
- @broker = Pione::Agent[:broker].new(task_worker_resource: @task_worker)
34
+ @broker = Pione::Agent[:broker].new(@features, task_worker_resource: @task_worker)
34
35
  @tuple_space_receiver = Pione::TupleSpaceReceiver.instance
35
36
  end
36
37