mitchelloharawild / fable.prophet

fable extension for the prophet forecasting procedure
https://pkg.mitchelloharawild.com/fable.prophet
55 stars 8 forks source link

Cannot use prophet in parallel #13

Closed adrfantini closed 4 years ago

adrfantini commented 4 years ago

There is some incompatibility between future and fable.prophet (or maybe prophet): I get the error in the title.

Here`s an example. This works (using ARIMA):

library(tsibble)
library(dplyr)
library(fable.prophet)
library(fable)
library(future)
plan(multiprocess)
cafe <- tsibbledata::aus_retail %>%
    filter(Industry == "Cafes, restaurants and catering services")

fit <- cafe %>%
    model(
        arima = ARIMA(Turnover)
#        prophet = prophet(Turnover ~ season("year", 4, type = "multiplicative"))
    )

fc <- fit %>%
    forecast(h = 24)

The same, using prophet, does not:

library(tsibble)
library(dplyr)
library(fable.prophet)
library(fable)
library(future)
plan(multiprocess)
cafe <- tsibbledata::aus_retail %>%
    filter(Industry == "Cafes, restaurants and catering services")

fit <- cafe %>%
    model(
#         arima = ARIMA(Turnover)
        prophet = prophet(Turnover ~ season("year", 4, type = "multiplicative"))
    )

fc <- fit %>%
    forecast(h = 24)

However removing plan(multiprocess) works! (single core, of course :( )

library(tsibble)
library(dplyr)
library(fable.prophet)
library(fable)
library(future)
# plan(multiprocess)
cafe <- tsibbledata::aus_retail %>%
    filter(Industry == "Cafes, restaurants and catering services")

fit <- cafe %>%
    model(
#         arima = ARIMA(Turnover)
        prophet = prophet(Turnover ~ season("year", 4, type = "multiplicative"))
    )

fc <- fit %>%
    forecast(h = 24)
mitchelloharawild commented 4 years ago

Hmm, that's unfortunate.

It's related to this issue, where Rcpp must be attached in order to estimate a prophet model: https://github.com/facebook/prophet/issues/1137

I'm not sure why attaching Rcpp is required for prophet, but I suspect solving that will resolve this issue.

adrfantini commented 4 years ago

ok, thanks for the info, I'll monitor that as well!

edvardoss commented 4 years ago

Untill fixed this issue you may use native *apply family from future for nested frames. Its work for Prophet

mitchelloharawild commented 4 years ago

Closing as this has been fixed in upstream changes to imported packages.

library(tsibble)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(fable.prophet)
#> Loading required package: Rcpp
#> Loading required package: fabletools
library(fable)
library(future)
plan(multiprocess)
#> Warning: [ONE-TIME WARNING] Forked processing ('multicore') is disabled
#> in future (>= 1.13.0) when running R from RStudio, because it is
#> considered unstable. Because of this, plan("multicore") will fall
#> back to plan("sequential"), and plan("multiprocess") will fall back to
#> plan("multisession") - not plan("multicore") as in the past. For more details,
#> how to control forked processing or not, and how to silence this warning in
#> future R sessions, see ?future::supportsMulticore
cafe <- tsibbledata::aus_retail %>%
  filter(Industry == "Cafes, restaurants and catering services")

fit <- cafe %>%
  model(
    prophet = prophet(Turnover ~ season("year", 4, type = "multiplicative"))
  )

fc <- fit %>%
  forecast(h = 24)

fc
#> # A fable: 192 x 6 [1M]
#> # Key:     State, Industry, .model [8]
#>    State             Industry                 .model    Month     Turnover .mean
#>    <chr>             <chr>                    <chr>     <mth>       <dist> <dbl>
#>  1 Australian Capit… Cafes, restaurants and … proph… 2019 Jan sample[1000]  40.3
#>  2 Australian Capit… Cafes, restaurants and … proph… 2019 Feb sample[1000]  42.7
#>  3 Australian Capit… Cafes, restaurants and … proph… 2019 Mar sample[1000]  47.5
#>  4 Australian Capit… Cafes, restaurants and … proph… 2019 Apr sample[1000]  46.2
#>  5 Australian Capit… Cafes, restaurants and … proph… 2019 May sample[1000]  45.1
#>  6 Australian Capit… Cafes, restaurants and … proph… 2019 Jun sample[1000]  46.3
#>  7 Australian Capit… Cafes, restaurants and … proph… 2019 Jul sample[1000]  45.3
#>  8 Australian Capit… Cafes, restaurants and … proph… 2019 Aug sample[1000]  46.5
#>  9 Australian Capit… Cafes, restaurants and … proph… 2019 Sep sample[1000]  47.5
#> 10 Australian Capit… Cafes, restaurants and … proph… 2019 Oct sample[1000]  46.7
#> # … with 182 more rows

Created on 2020-07-16 by the reprex package (v0.3.0)