Commit 37235722 authored by Alberto Ramos's avatar Alberto Ramos

Added information on the use of PackageCompiler

parent e9df23a0
...@@ -37,5 +37,37 @@ julia> import Pkg ...@@ -37,5 +37,37 @@ julia> import Pkg
It is better to start with the [Getting started](https://ific.uv.es/~alramos/docs/ADerrors/tutorial/) guide. It is better to start with the [Getting started](https://ific.uv.es/~alramos/docs/ADerrors/tutorial/) guide.
# Alleviating time to first run
`Julia` is well known for being slow the first time that you run some
routines. On the first call to a function Julia not only runs the
code, but also compiles it, making the first call slow.
This problem can be alleviated in general with
[PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl). This
is specially true for the case of `ADerrors` since most functions are
type static.
As example, the file `extra/typical.jl` contains the most typical
calls to `ADerrors`. One can execute this file telling julia to
annotate the functions that are compiled
```julia
julia --trace-compile=precompile_aderrors.jl typical.jl
```
Now the functions annotated in `precompile_aderrors.jl` can be
compiled and included in a `sysimage` that is autmatically loaded
whenever you start Julia
```julia
julia> using PackageCompiler
julia> PackageCompiler.create_sysimage(:ADerrors; precompile_statements_file="precompile_aderrors.jl", replace_default=true)
```
This will make `ADerrors` from the first call. Obviously you can tune
the file `typical.jl` to your usage, or add other packages. Please
note that packages included in the sysimage are locked to the versions
of the sysimage. If you update `ADerrors` make sure to re-generate the
sysimage. Probably is better to read [the documentation of
PackageCompiler](https://julialang.github.io/PackageCompiler.jl/dev/sysimages/)
in order to fully understand the drawbacks.
using ADerrors
# Input of uwreal's
a = uwreal(rand(1000), 1)
b = uwreal([1.0, 0.1], 2)
p = cobs([1.0, 2.0], [1.0 0.1;
0.1 2.0], [3, 4])
# Most common operations.
# You might add something else if
# you use it frequently
for op in (:-, :sin, :cos, :log, :log10, :log2, :sqrt, :exp, :exp2, :exp10, :sinh, :cosh, :tanh)
@eval c = $op(a)
end
c = 1.0 + b
c = 1.0 - b
c = 1.0 * b
c = 1.0 / b
c = a + 2.0
c = a - 2.0
c = a * 2.0
c = a / 2.0
c = a ^ 3
c = a + b
c = a - b
c = a * b
c = a / b
# Error analysis
uwerr(c)
cov([c, a, b])
trcov([1.0 2.0 3.0;
2.0 1.0 0.4;
3.0 0.4 1.0], [c, a, b])
details(c)
# Error analysis of fit parameters
npt = 12
sig = zeros(npt, npt)
dx = zeros(npt)
for i in 1:npt
dx[i] = 0.01*i
sig[i,i] = dx[i]^2
for j in i+1:npt
sig[i,j] = 0.0001 - 0.000005*abs(i-j)
sig[j,i] = 0.0001 - 0.000005*abs(i-j)
end
end
y = [0.0802273592699947
0.09150837606934502
0.047923648239388834
0.024851583326401416
0.01635482325054799
0.13115281737744588
0.21013177679604178
0.002143355151617357
0.2292183950698425
-0.05174734852593241
0.1384913891139784
-0.05211234898997283]
dt = cobs(y, sig, [100+n for n in 1:npt])
chisq(p, d) = sum( (d .- p[1]) .^ 2 ./ dx .^2 )
xp = [sum(value.(dt) ./ dx)/sum(1.0 ./ dx)]
(fitp, csqexp) = fit_error(chisq, xp, dt)
chiexp(chisq, xp, dt)
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