ensembl-hive  2.7.0
LongMultSt_pyconf.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
9  # initialize the database and build the graph in it (it will also print the value of EHIVE_URL) :
11 
12  # optionally also seed it with your specific values:
13  seed_pipeline.pl -url $EHIVE_URL -logic_name take_b_apart -input_id '{ "a_multiplier" => "12345678", "b_multiplier" => "3359559666" }'
14 
15  # run the pipeline:
16  beekeeper.pl -url $EHIVE_URL -loop
17 
18 =head1 DESCRIPTION
19 
20  This is a special version of LongMult_conf with hive_use_param_stack mode switched on, and Runnables implemented in Python
21 
22  This is the PipeConfig file for the long multiplication pipeline example.
23  The main point of this pipeline is to provide an example of how to write Hive Runnables and link them together into a pipeline.
24 
25  Please refer to Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf module to understand the interface implemented here.
26 
27  The setting. Let's assume we are given two loooooong numbers to multiply. Reeeeally long.
28  Soooo long that they do not fit into registers of the CPU and should be multiplied digit-by-digit.
29  For the purposes of this example we also assume this task is very computationally intensive and has to be done in parallel.
30 
31  The long multiplication pipeline consists of three "analyses" (types of tasks):
32  'take_b_apart', 'part_multiply' and 'add_together' that we use to examplify various features of the Hive.
33 
34  * A 'take_b_apart' job takes in two string parameters, 'a_multiplier' and 'b_multiplier',
35  takes the second one apart into digits, finds what _different_ digits are there,
36  creates several jobs of the 'part_multiply' analysis and one job of 'add_together' analysis.
37 
38  * A 'part_multiply' job takes in 'a_multiplier' and 'digit', multiplies them and accumulates the result in 'partial_product' accumulator.
39 
40  * An 'add_together' job waits for the first two analyses to complete,
41  takes in 'a_multiplier', 'b_multiplier' and 'partial_product' hash and produces the final result in 'final_result' table.
42 
43  Please see the implementation details in Runnable modules themselves.
44 
45 =head1 LICENSE
46 
47  See the NOTICE file distributed with this work for additional information
48  regarding copyright ownership.
49 
50  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
51  You may obtain a copy of the License at
52 
53  http://www.apache.org/licenses/LICENSE-2.0
54 
55  Unless required by applicable law or agreed to in writing, software distributed under the License
56  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57  See the License for the specific language governing permissions and limitations under the License.
58 
59 =head1 CONTACT
60 
61  Please subscribe to the Hive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss Hive-related questions or to be notified of our updates
62 
63 =cut
64 
65 
67 
68 use strict;
69 use warnings;
70 
71 use base ('Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf'); # All Hive databases configuration files should inherit from HiveGeneric, directly or indirectly
72 
73 
74 =head2 pipeline_create_commands
75 
76  Description : Implements pipeline_create_commands() interface method of Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf that lists the commands that will create and set up the Hive database.
77  In addition to the standard creation of the database and populating it with Hive tables and procedures it also creates two pipeline-specific tables used by Runnables to communicate.
78 
79 =cut
80 
81 sub pipeline_create_commands {
82  my ($self) = @_;
83  return [
84  @{$self->SUPER::pipeline_create_commands}, # inheriting database and hive tables' creation
85 
86  # additional tables needed for long multiplication pipeline's operation:
87  $self->db_cmd('CREATE TABLE final_result (a_multiplier varchar(255) NOT NULL, b_multiplier varchar(255) NOT NULL, result varchar(255) NOT NULL, PRIMARY KEY (a_multiplier, b_multiplier))'),
88  ];
89 }
90 
91 
92 =head2 pipeline_wide_parameters
93 
94  Description : Interface method that should return a hash of pipeline_wide_parameter_name->pipeline_wide_parameter_value pairs.
95  The value doesn't have to be a scalar, can be any Perl structure now (will be stringified and de-stringified automagically).
96  Please see existing PipeConfig modules for examples.
97 
98 =cut
99 
100 sub pipeline_wide_parameters {
101  my ($self) = @_;
102  return {
103  %{$self->SUPER::pipeline_wide_parameters}, # here we inherit anything from the base class
104 
105  'take_time' => 1,
106  };
107 }
108 
109 
110 sub hive_meta_table {
111  my ($self) = @_;
112  return {
113  %{$self->SUPER::hive_meta_table}, # here we inherit anything from the base class
114 
115  'hive_use_param_stack' => 1, # switch on the new param_stack mechanism
116  };
117 }
118 
119 
120 =head2 pipeline_analyses
121 
122  Description : Implements pipeline_analyses() interface method of Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf that defines the structure of the pipeline: analyses, jobs, rules, etc.
123  Here it defines three analyses:
124  * 'take_b_apart' that is auto-seeded with a pair of jobs (to check the commutativity of multiplication).
125  Each job will dataflow (create more jobs) via branch #2 into 'part_multiply' and via branch #1 into 'add_together'.
126 
127  * 'part_multiply' with jobs fed from take_b_apart#2.
128  It multiplies input parameters 'a_multiplier' and 'digit' and dataflows 'partial_product' parameter into branch #1.
129 
130  * 'add_together' with jobs fed from take_b_apart#1.
131  It adds together results of partial multiplication computed by 'part_multiply'.
132  These results are accumulated in 'partial_product' hash.
133  Until the hash is complete the corresponding 'add_together' job is blocked by a semaphore.
134 
135 =cut
136 
137 sub pipeline_analyses {
138  my ($self) = @_;
139  return [
140  { -logic_name => 'take_b_apart',
141  -module => 'eHive.examples.LongMult.DigitFactory',
142  -language => 'python3',
143  -meadow_type=> 'LOCAL', # do not bother the farm with such a simple task (and get it done faster)
144  -analysis_capacity => 2, # use per-analysis limiter
145  -input_ids => [
146  { 'a_multiplier' => '9650156169', 'b_multiplier' => '327358788' },
147  { 'a_multiplier' => '327358788', 'b_multiplier' => '9650156169' },
148  ],
149  -flow_into => {
150  '2->A' => [ 'part_multiply' ], # will create a semaphored fan of jobs; will use param_stack mechanism to pass parameters around
151  'A->1' => [ 'add_together' ], # will create a semaphored funnel job to wait for the fan to complete and add the results
152  },
153  },
154 
155  { -logic_name => 'part_multiply',
156  -module => 'eHive.examples.LongMult.PartMultiply',
157  -language => 'python3',
158  -analysis_capacity => 4, # use per-analysis limiter
159  -flow_into => {
160  1 => [ '?accu_name=partial_product&accu_address={digit}' ],
161  },
162  },
163 
164  { -logic_name => 'add_together',
165  -module => 'eHive.examples.LongMult.AddTogether',
166  -language => 'python3',
167  -flow_into => {
168  1 => [ '?table_name=final_result', 'last' ],
169  },
170  },
171 
172  { -logic_name => 'last',
174  }
175  ];
176 }
177 
178 1;
179 
Bio::EnsEMBL::Hive::RunnableDB::Dummy
Definition: Dummy.pm:28
Bio::EnsEMBL::Hive::Examples::LongMult::PipeConfig::LongMultSt_pyconf
Definition: LongMultSt_pyconf.pm:48
Bio::EnsEMBL::Hive::Version
Definition: Version.pm:19
main
public main()
Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf
Definition: HiveGeneric_conf.pm:54
Bio::EnsEMBL::Hive
Definition: Hive.pm:38