"Cfunction: closures are not supported on this platform" error for barplot?

Got the error “cfunction: closures are not supported on this platform”

fig2 = Figure((6, 4), “in”)
2 xs = [“1”, “2”, “3”, “4”, “5”, “6”, “7”]
3 barplot(xs, drdp[end, :], dpi=300)
4 ylim((0, 1))
5 ylabel(“Degree of Rate Control”)
6 xlabel(“Step id”)
7 savefig(“si-3.png”)

Stacktrace:
[1] axeslbl(x_tick::Float64, y_tick::Float64, x_org::Float64, y_org::Float64, major_x::Int64, major_y::Int64, tick_size::Float64, fx::Function, fy::GRUtils.var"#43#44"{typeof(identity)})
@ GR ~/.julia/packages/GR/M9Dkl/src/GR.jl:2285
[2] draw(ax::GRUtils.Axes, background::Bool)
@ GRUtils ~/.julia/packages/GRUtils/pFWly/src/axes.jl:510
[3] draw
@ ~/.julia/packages/GRUtils/pFWly/src/axes.jl:449 [inlined]
[4] draw(p::GRUtils.PlotObject)
@ GRUtils ~/.julia/packages/GRUtils/pFWly/src/plotobjects.jl:213
[5] draw(f::Figure)
@ GRUtils ~/.julia/packages/GRUtils/pFWly/src/figures.jl:200
[6] savefig
@ ~/.julia/packages/GRUtils/pFWly/src/frontend.jl:1470 [inlined]
[7] savefig(filename::String)
@ GRUtils ~/.julia/packages/GRUtils/pFWly/src/frontend.jl:1469
[8] top-level scope
@ In[16]:7

Full code:
using GRUtils
using DifferentialEquations
using DiffEqSensitivity, ForwardDiff
using LaTeXStrings

kf0 = Array([1.33e8, 2.01e11, 2.64e6, 5.24e1, 2.05e5, 1.48e12, 5.32e2])
K = Array([2.15e2, 5.93e-5, 6.28e-2, 1.18e-5, 1.03e3, 1.92e5, 4.50e1])

function calc_rate2(y, kf)
global K
kr = kf ./ K
press = Array([0.07, 0.21, 0.085, 0.38])
press = press .* 1.01325
fwd_factor = Array([press[1] * y[1], press[2] * y[1], y[3] * y[1], y[5] *
y[1], y[2] * y[6], y[7], y[4]^2])
rev_factor = Array([y[2], y[3], y[4] * y[5], y[4] * y[6], y[7] * y[1],
press[3] * y[1], press[4] * y[1]^2])
r = kf .* fwd_factor .- kr .* rev_factor
return r
end

function calc_overall_rate2(y, kf)
global K
kr = kf ./ K
press = Array([0.07, 0.21, 0.085, 0.38])
press = press .* 1.01325
r1 = kf[7] * y[4]^2 - kr[7] * press[4] * y[1]^2
return r1
end

function state_eqn2(y, kf, t)
r = calc_rate2(y, kf)
eq1 = -r[1] - r[2] -r[3] -r[4] + r[5] + r[6] + 2 * r[7] # *
eq2 = r[1] - r[5] # CO*
eq3 = r[2] - r[3] # H2O*
eq4 = r[3] + r[4] - 2 * r[7] # H*
eq5 = r[3] - r[4] # OH*
eq6 = r[4] - r[5] # O*
eq7 = r[5] - r[6] # CO2*
Array([eq1, eq2, eq3, eq4, eq5, eq6, eq7])
end

tspan = (0., 50.)
y0 = [0.9; 0.01; 0.01; 0.01; 0.01; 0.01; 0.05]
prob2 = ODEProblem(state_eqn2, y0, tspan, kf0)

function rate_wrapper2(p)
p = exp.(p)
nt = 501
_prob = remake(prob2, p=p)
theta_sol = Array(solve(_prob, Kvaerno5(), saveat=LinRange(2.0, 50.0, nt), sensealg=ForwardDiffSensitivity(), atol=1e-8, rtol=1e-8))’ # [nt, nu]
p_matrix = reshape(p, 1, size(p, 1)) # [1, np]
p_repeat = repeat(p_matrix, nt, 1) # [nt, np]
r = Array{Real, 1}(undef, nt)
for i in 1:nt
r[i] = calc_overall_rate2(theta_sol[i, :], p_repeat[i, :])
end
return log.(r)
end

drdp = ForwardDiff.jacobian(rate_wrapper2, log.(kf0))

fig2 = Figure((6, 4), “in”)
xs = [“1”, “2”, “3”, “4”, “5”, “6”, “7”]
barplot(xs, drdp[end, :], dpi=300)
ylim((0, 1))
ylabel(“Degree of Rate Control”)
xlabel(“Step id”)
savefig(“si-3.png”)

also got a warning “Unrecognized keyword arguments: [:atol, :rtol]”

What’s the platform? Ie what’s the output of versioninfo()?

Probably ARM. Cfunction closures aren’t supported there.

1 Like

Mac OS, MacBook Pro M1 (2021)

And what version of Julia? How did you install it? Output of versioninfo please…

That’s a problem in the GR.jl package in the sense it should avoid using cfunction closures if possible at all, Julia just doesn’t support them on the ARM architecture because of a limitation of llvm, see the Note in Calling C and Fortran Code · The Julia Language (the reference to powerpc is outdated as they now work on that architecture)

1 Like