Commit cb3eb95f authored by Leo Gordon's avatar Leo Gordon
Browse files

another version of LongMult pipeline to test -wait_for rules

parent 5a3beced
=head1 NAME
# initialize the database and build the graph in it (it will also print the value of EHIVE_URL) : Bio::EnsEMBL::Hive::PipeConfig::LongMultWf_conf -password <mypass>
# optionally also seed it with your specific values: -url $EHIVE_URL -logic_name take_b_apart -input_id '{ "a_multiplier" => "12345678", "b_multiplier" => "3359559666" }'
# run the pipeline: -url $EHIVE_URL -loop
This is the PipeConfig file for the long multiplication pipeline example.
The main point of this pipeline is to provide an example of how to write Hive Runnables and link them together into a pipeline.
Please refer to Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf module to understand the interface implemented here.
The setting. let's assume we are given two loooooong numbers to multiply. reeeeally long.
soooo long that they do not fit into registers of the cpu and should be multiplied digit-by-digit.
For the purposes of this example we also assume this task is very computationally intensive and has to be done in parallel.
The long multiplication pipeline consists of three "analyses" (types of tasks):
'take_b_apart', 'part_multiply' and 'add_together' that we use to examplify various features of the Hive.
* A 'take_b_apart' job takes in two string parameters, 'a_multiplier' and 'b_multiplier',
takes the second one apart into digits, finds what _different_ digits are there,
creates several jobs of the 'part_multiply' analysis and one job of 'add_together' analysis.
* A 'part_multiply' job takes in 'a_multiplier' and 'digit', multiplies them and accumulates the result in 'partial_product' accumulator.
* An 'add_together' job waits for the first two analyses to complete,
takes in 'a_multiplier', 'b_multiplier' and 'partial_product' hash and produces the final result in 'final_result' table.
Please see the implementation details in Runnable modules themselves.
=head1 LICENSE
Copyright [1999-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
=head1 CONTACT
Please subscribe to the Hive mailing list: to discuss Hive-related questions or to be notified of our updates
package Bio::EnsEMBL::Hive::PipeConfig::LongMultWf_conf;
use strict;
use warnings;
use base ('Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf'); # All Hive databases configuration files should inherit from HiveGeneric, directly or indirectly
=head2 pipeline_create_commands
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.
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.
sub pipeline_create_commands {
my ($self) = @_;
return [
@{$self->SUPER::pipeline_create_commands}, # inheriting database and hive tables' creation
# additional tables needed for long multiplication pipeline's operation:
$self->db_cmd('CREATE TABLE final_result (a_multiplier char(40) NOT NULL, b_multiplier char(40) NOT NULL, result char(80) NOT NULL, PRIMARY KEY (a_multiplier, b_multiplier))'),
$self->db_cmd('CREATE TABLE intermediate_result (a_multiplier char(40) NOT NULL, digit char(1) NOT NULL, partial_product char(80) NOT NULL, PRIMARY KEY (a_multiplier, digit))'),
=head2 pipeline_wide_parameters
Description : Interface method that should return a hash of pipeline_wide_parameter_name->pipeline_wide_parameter_value pairs.
The value doesn't have to be a scalar, can be any Perl structure now (will be stringified and de-stringified automagically).
Please see existing PipeConfig modules for examples.
sub pipeline_wide_parameters {
my ($self) = @_;
return {
%{$self->SUPER::pipeline_wide_parameters}, # here we inherit anything from the base class
'take_time' => 1,
=head2 pipeline_analyses
Description : Implements pipeline_analyses() interface method of Bio::EnsEMBL::Hive::PipeConfig::HiveGeneric_conf that defines the structure of the pipeline: analyses, jobs, rules, etc.
Here it defines three analyses:
* 'take_b_apart' that is auto-seeded with a pair of jobs (to check the commutativity of multiplication).
Each job will dataflow (create more jobs) via branch #2 into 'part_multiply' and via branch #1 into 'add_together'.
* 'part_multiply' with jobs fed from take_b_apart#2.
It multiplies input parameters 'a_multiplier' and 'digit' and dataflows 'partial_product' parameter into branch #1.
* 'add_together' with jobs fed from take_b_apart#1.
It adds together results of partial multiplication computed by 'part_multiply'.
These results are accumulated in 'partial_product' hash.
Until the hash is complete the corresponding 'add_together' job is blocked by a semaphore.
sub pipeline_analyses {
my ($self) = @_;
return [
{ -logic_name => 'take_b_apart',
-module => 'Bio::EnsEMBL::Hive::RunnableDB::LongMult::DigitFactory',
-meadow_type=> 'LOCAL', # do not bother the farm with such a simple task (and get it done faster)
-analysis_capacity => 2, # use per-analysis limiter
-input_ids => [
{ 'a_multiplier' => '9650156169', 'b_multiplier' => '327358788' },
{ 'a_multiplier' => '327358788', 'b_multiplier' => '9650156169' },
-flow_into => {
2 => { 'part_multiply' => { 'a_multiplier' => '#a_multiplier#', 'digit' => '#digit#', 'take_time' => '#take_time#' } },
1 => [ 'add_together' ],
{ -logic_name => 'part_multiply',
-module => 'Bio::EnsEMBL::Hive::RunnableDB::LongMult::PartMultiply',
-analysis_capacity => 4, # use per-analysis limiter
-flow_into => {
1 => [ ':////intermediate_result' ],
{ -logic_name => 'add_together',
-module => 'Bio::EnsEMBL::Hive::RunnableDB::LongMult::AddTogether',
# -analysis_capacity => 0, # this is a way to temporarily block a given analysis
-parameters => {
'intermediate_table_name' => 'intermediate_result',
-wait_for => [ 'part_multiply' ],
-flow_into => {
1 => [ ':////final_result' ],
......@@ -50,9 +50,9 @@ use base ('Bio::EnsEMBL::Hive::Process');
sub param_defaults {
return {
'partial_product' => { }, # to be used when b_multiplier only contains digits '0' and '1'
'take_time' => 0, # how much time run() method will spend in sleeping state
'intermediate_table_name' => undef, # if defined, take data from there rather than from accu
'partial_product' => { }, # to be used when b_multiplier only contains digits '0' and '1'
'take_time' => 0, # how much time run() method will spend in sleeping state
......@@ -73,8 +73,17 @@ sub param_defaults {
sub fetch_input { # fetch all the (relevant) precomputed products
my $self = shift @_;
my $a_multiplier = $self->param_required('a_multiplier');
my $partial_product = $self->param('partial_product');
my $a_multiplier = $self->param_required('a_multiplier');
my $intermediate_table_name = $self->param('intermediate_table_name');
my $partial_product;
if($intermediate_table_name) { # special compatibility mode, where data is fetched from a given table
my $adaptor = $self->db->get_NakedTableAdaptor();
$adaptor->table_name( $intermediate_table_name );
$partial_product = $self->param('partial_product', $adaptor->fetch_by_a_multiplier_HASHED_FROM_digit_TO_partial_product( $a_multiplier ) );
} else {
$partial_product = $self->param('partial_product');
$partial_product->{1} = $a_multiplier;
$partial_product->{0} = 0;
......@@ -114,6 +123,7 @@ sub write_output { # store and dataflow
}, 1);
=head2 _add_together
Description: this is a private function (not a method) that adds all the products with a shift
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment