Parallelizing bnlearn (with parallel package)

I use the package R bnlearnto evaluate Bayesian network structures. It has built-in parallelization using a package parallel. However, this does not work.

Using the example from manpage bnlearn::parallel integration:

library(parallel)
library(bnlearn)

cl = makeCluster(2)

# check it works.
clusterEvalQ(cl, runif(10))    # -> this works

data(learning.test)
res = gs(learning.test, cluster = cl)

Here I get an error "Error in check.cluster(cluster) : cluster is not a valid cluster object."

Does anyone know how to make this work?

+4
source share
1 answer

This is mistake. Report this to the package employee.

Here is the code check.cluster:

function (cluster) 
{
    if (is.null(cluster)) 
        return(TRUE)
    if (any(class(cluster) %!in% supported.clusters)) 
        stop("cluster is not a valid cluster object.")
    if (!requireNamespace("parallel")) 
        stop("this function requires the parallel package.")
    if (!isClusterRunning(cluster)) 
        stop("the cluster is stopped.")
}

Now, if you look at the class cl:

class(cl)
#[1] "SOCKcluster" "cluster" 

Let me reproduce the check:

bnlearn:::supported.clusters
#[1] "MPIcluster"  "PVMcluster"  "SOCKcluster"

`%!in%` <- function (x, table) {
  match(x, table, nomatch = 0L) == 0L
}
any(class(cl) %!in% bnlearn:::supported.clusters)
#[1] TRUE

cluster supported.clusters. , , , .

supported.clusters:

assignInNamespace("supported.clusters", 
                  c("cluster", "MPIcluster",  
                    "PVMcluster", "SOCKcluster"), 
                  "bnlearn")
+6

All Articles