JuliaLang / JuliaLang/PackageCompiler.jl

Problem with app using Turing

Open
#703 1 comment 0 reactions 0 assignees View on GitHub
question upstream
Dominant language
Julia
Stars
1.6k
Forks
205
Avg merge
18h 37m
Merged PRs (30d)
7

Description

Hi. I try to compile an app to predict bayesian model . I saved posterior chain, and model specification. My precomp_file is something like that.

**precomp_file.jl**

```julia
using Turing
using Distributions
using LinearAlgebra
using DataFrames
using CSV
using StatsBase
using Tracker
using MKL
using Bijectors

import Logging
Logging.disable_logging(Logging.Warn)

# El objetivo es precompilar las funciones para
# que la app vaya rápido

## Leer cadena y especificación modelo
chain_path = "/home/jose/Julia_projects/bayesian_app/resources/cadena_refactor.jls"
# al hacer include dentro de la app mira por defecto en src
esp_modelo_path = "/home/jose/Julia_projects/bayesian_app/src/especificacion_modelo_refactor.jl"
df_path = "/home/jose/Julia_projects/bayesian_app/resources/Advertising.csv"
chain = read(chain_path, Chains)

df = CSV.read(df_path, DataFrame, ntasks=10)

include(esp_modelo_path)

## predecir
predicciones = predict(model_turing(df ), chain)

pred_df = DataFrame(predicciones)
pred_df = pred_df[!, Not([:iteration, :chain])]
medias = mean.(eachcol(pred_df))
mediana = quantile.(eachcol(pred_df), 0.5)
desv_ti = std.(eachcol(pred_df))
q01 = quantile.(eachcol(pred_df), 0.1)
q90 = quantile.(eachcol(pred_df), 0.9)

pred_interval = DataFrame(hcat(medias, mediana, desv_ti, q01, q90), :auto)

rename!(pred_interval,[:means,:median , :std, :q01, :q90])

CSV.write("data/predicciones.csv", pred_interval)

```

where **especificacion_modelo_refactor.jl i**s a julia script only with model turing specification

```julia
@model function model_turing(df)
TV = df.TV
radio = df.radio
newspaper = df.newspaper
# Prior coeficientes
a ~ Normal(0, 0.5)
tv_coef ~ Normal(0, 0.5)
radio_coef ~ Normal(0, 0.5)
newspaper_coef ~ Normal(0, 0.5)
σ₁ ~ Gamma(1, 1)

mu = a .+ tv_coef .* TV .+ radio_coef .* radio .+ newspaper_coef .* newspaper
sales ~ MvNormal(mu, σ₁^2 * I)
end

```
My app file is something like that.

```julia
module bayesian_app

using Turing
using Distributions
using LinearAlgebra
using DataFrames
using CSV
using StatsBase
using Tracker
using MKL

function julia_main()::Cint
try
real_main()
catch
Base.invokelatest(Base.display_error, Base.catch_stack())
return 1
end
return 0
end

function real_main()
if length(ARGS) == 0
error("pass arguments")
end

# Read chain
chain = read(ARGS[1], Chains)
# Read model_espec in julia script
include(ARGS[2])

# read data
df = CSV.read(ARGS[3], DataFrame, ntasks=10)
# Predict
predicciones = predict(model_turing(df), chain )

pred_df = DataFrame(predicciones)
pred_df = pred_df[!, Not([:iteration, :chain])]
medias = mean.(eachcol(pred_df))
mediana = quantile.(eachcol(pred_df), 0.5)
desv_ti = std.(eachcol(pred_df))
q01 = quantile.(eachcol(pred_df), 0.1)
q90 = quantile.(eachcol(pred_df), 0.9)

pred_interval = DataFrame(hcat(medias, mediana, desv_ti, q01, q90), :auto)

rename!(pred_interval,[:means,:median , :std, :q01, :q90])
CSV.write("pred_interval_80.csv", pred_interval)
CSV.write("pred_posterior.csv", pred_df)

end

end # module

```

And **I try to compile using**
```julia
create_app("../bayesian_app", "../bayesian_bin_predict", precompile_execution_file="../bayesian_app/src/precomp_file.jl", force=true, filter_stdlibs = false)
```

And get the compile, once I install some dpendencies like Tracker.jl an others.

I try to test my app passing a mcmc chain, a julia file where I wrote the model especification , but I get weird error message

```bash
../bayesian_bin_predict/bin/bayesian_app cadena_refactor.jls especificacion_modelo_refactor.jl Advertising.csv
┌ Warning: Package Bijectors does not have ChainRulesCore in its dependencies:
│ - If you have Bijectors checked out for development and have
│ added ChainRulesCore as a dependency but haven't updated your primary
│ environment's manifest file, try `Pkg.resolve()`.
│ - Otherwise you may need to report an issue with Bijectors
└ Loading ChainRulesCore into Bijectors from project dependency, future warnings for Bijectors are suppressed.

┌ Warning: Error requiring `Tracker` from `Bijectors`
```
But when I see Manifest and Project I view Tracker.jl and Bijectors.

Any idea?

Thanks

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the reported create_app invocation with precomp_file.jl, then compare its dependency setup with the bayesian_app module and the generated application's Project and Manifest files. Trace the Bijectors warning and the failed Tracker requirement; done means the compiled app runs with the three supplied arguments without those dependency warnings or errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.