failed to execute first example of Differential Algebraic Equations - julia

I am using JuliaPro v0.6.0.1 and the JunoIDE
I tried to apply the DifferentialEquations.jl. In order to run a first example I added the package DifferentialEquations followed by the using statement. In a next step I copied the first example:
f(t,u) = 1.01*u
u0=1/2
tspan = (0.0,1.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8)
using Plots
plot(sol,linewidth=5,title="Solution to the linear ODE with a thick line",
xaxis="Time (t)",yaxis="u(t) (in μm)",label="My Thick Line!") # legend=false
plot!(sol.t, t->0.5*exp(1.01t),lw=3,ls=:dash,label="True Solution!")
Instead of getting the expected graphic I've got the message:
UndefVarError: ODEProblem not defined
Furthermore I've got the warnings right after the: using DifferentialEquations statement
WARNING: The call to compilecache failed to create a usable precompiled cache file for module StochasticDiffEq. Got:
WARNING: Module Iterators uuid did not match cache file.
> LoadError: Declaring __precompile__(true) is only allowed in module files being imported.
which I do not understand. Nevertheless the last warning deals with StochasticDiffEq whereas I'm applying an Ordinary Differential Equation problem.
Any help is appropiated

JuliaPro is incompatible with some packages including DifferentialEquations. I would avoid using JuliaPro and instead use a standard installation until JuliaPro is updated.

Related

Parsing error in MonteCarlo::MonteCarlo function in R

I am trying to run a power analysis using a MonteCarlo approach in R.
I have created a function of two parameters that does output a boolean (tested manually for all relevant values of the parameters). I also have run baby-examples of the MonteCarlo function to make sure that I understand it and that it works well.
Yet when I try to run the real thing, I get the following error message:
Error in parse(text = all_funcs_found[i]) : <text>:1:1: unexpected '::'
1: ::
I read through the source code of the MonteCarlo function (which I found here) and found
#loop through non-primitive functions used in func and check from which package they are
for(i in 1:length(all_funcs_found)){
if(environmentName(environment(eval(parse(text=all_funcs_found[i]))))%in%env_names){
packages<-c(packages,env_names[which(env_names==environmentName(environment(eval(parse(text=all_funcs_found[i])))))])
}
}
which doesn't really make sense to me - why should there be a problem there?
Thank you for any ideas.
I found the answer: the function I wrote was calling a function from a specific library in the form libraryname::functionname.
This works OK if you use the function once manually, but makes MonteCarlo break.
I solved the problem by first loading the relevant library, then removing the 'libraryname::' part from the definition of the main function. MonteCarlo then runs just fine.

How to fix the error "argument "modelName" is missing, with no default" when using MVN package

I am using the MVN package, in R, to find whether each class of the dataset iris is multivariate normal or not.
I used the below code earlier in the day and generated results from it. However, I went to revisit it and now keep getting the following error message:
Error in mvn(data = iris[Species == m[1], 1:4], mvnTest = c("mardia")) :
argument "modelName" is missing, with no default
Can not figure out what this means and how to fix it !
Code:
#Mardia's Test
SM<-mvn(data=iris,subset="Species", mvnTest="mardia")
SM$multivariateNormality
SetosaPlot<-mvn(data=iris, subset="Species", multivariatePlot="qq")
You loaded the mclust package. When you did so you should have seen a warning
The following object is masked from ‘package:MVN’: mvn
So now mvn() is calling mclust::mvn() (i.e. the mvn function in the mclust package) rather than MVN::mvn().
In general you can make sure you get the version from the MVN package by using
MVN::mvn(data=iris, subset="Species", multivariatePlot="qq")
If you want to know where R is finding mvn, try find("mvn")
In general, to resolve these kinds of problems you should start a clean R session, so that you know you're starting with no packages loaded.
(By the way, no real data set is ever truly multivariate normal; you're not testing "whether it is MVN or not", but rather whether it is close enough to MVN that you can't reject the null hypothesis of multivariate normality ...)

GraphPlots Julia - How to add node labels?

I am currently in the process of plotting a directed graphs using Julia. After some time on the internet I came across the GraphPLot package which seems to be doing an ok job.
However, I can't find out how to add node labels! Here is my code and output from the jupyter notebook.
Update:
I tried the suggested method from GitHub
nodelabel = [1:number_vertices(g)]
gplot(g, nodelabel = nodelabel)
But I get a weird error:
LoadError: Must have one label per node (or none)
while loading In[44], in expression starting on line 1
Changing
nodelabel = [1:num_vertices(g)]
To nodelabel = collect(1:num_vertices(g)) solves the issue.

Problems building an R package (NAs introduced by coercion)

I have written the Boggler package which includes a Play.Boggle() function that calls, on line 87, a progress bar script using shell:
shell(cmd = sprintf('Rscript.exe R/progress_bar.R "%i"', time.limit + 1), wait=FALSE)
Everything works fine when sourcing the files individually and then calling the main Play.Boggle() function, but when I try to check/build the package (under Win7-64 using RStudio), I get a failure message -- here's what the 00install.out reports:
** preparing package for lazy loading
Warning in eval(expr, envir, enclos) : NAs introduced by coercion
Error in time.limit:0 : NA/NaN argument
To make sure the argument "%i" (time.limit + 1) was correctly passed to the progress_bar.R, I added a cat(time.limit) to the script (commenting the rest out to make sure the package would build without any errors) and directed its output to a log file like this:
'Rscript.exe R/progress_bar.R "%i" > out.log'
Conclusion: the time limit is indeed passed along as expected. So I can't figure out why I get this "NA/NaN argument" error message. It must have something to do with lazy loading, concept that I haven't fully got my head around yet.
So my question is: what can I do to successfully check/build this package with full functionality (including progress_bar.R)?
Note: On github, the progress_bar.R script is there but all its content is commented out so that the package can successfully be installed. The shell(...) function call is still active, doing nothing but executing an empty script.
So the problem arises when trying to build or check, in which case all R scripts are executed, as pointed out by Roland. A simple workaround allows the package to check/build without any problems. The fix is just to add to the progress_bar.R the following lines after it tries to recuperate the commandargs (lines 10-11):
if(time.limit %in% c(NA, NaN))
time.limit <- 10 # or any minimal number
There's surely other ways to go about this. But this being a game programmed for fun, I'll happily go with that patch. Hopefully this can be of help to someone down the road and I won't have wasted 50 precious rep points in vain for that bounty! :D

What is the cause of "Error in .C("unlock solver")" Error in deSolve Package?

I have been using the deSolve package in a MCMC algorithm to estimate parameters in an ODE and wrote the functions used in the solver in C to speed up the algorithm. Sometimes, but not always I get the error Error in .C("unlock solver") when running the ode function. I am able to successfully compile and link the C files using the commands
system("R CMD SHLIB [insert-file-path]")
dyn.load("[dll-file-path]")
but when I try to solve the ODE using the dll file, the error is thrown. Then, even when running a simple script like the one below, I get the same error. I think the issue is related to using the compiled code, but I don't know how and cannot find any references on this error.
> require(deSolve)
> initVal <- c(y=1)
> times <- seq(0, 1, 0.001)
> parms <- c(k=1)
> model1 <- function(t, y, parms){
+ with(as.list(c(y, parms)),{
+ dy <- -k*y;
+ list(c(dy))
+ })
+ }
> out <- ode(y=initVal, times=times, parms=parms, func=model1)
Error in .C("unlock_solver") :
"unlock_solver" not resolved from current namespace (deSolve)
Partial Solution
If I restart R and only load the DLL using the dyn.load function, but don't compile the code, the ode function runs without an error. This fixes my problem, but I still have no idea why.
Edit:
REAL solution from Thomas Petzoldt on the R help list:
[The error] occurs, if package deSolve is loaded after the compiled model... The solution is to load deSolve before [before loading DLL's], ideally at the very beginning of your script, and at least before loading/unloading the DLL/.so
If that doesn't work, the below might as well (old answer):
I have found a somewhat inelegant solution.
The problem seems to be that the "unlock_solver" function within deSolve is somehow not being accessed correctly. You can unload and reload the entire deSolve.so file, rather than restarting R.
To do this you can use something like:
require(deSolve)
# encounter error
library.dynam.unload("deSolve", libpath=paste(.libPaths()[1], "//deSolve", sep=""))
library.dynam("deSolve", package="deSolve", lib.loc=.libPaths()[1])
You'll need to replace ".libPaths()[1]" with wherever you have installed deSolve, if it isn't in the first element of your .libPaths variable.
This is something of a sledge hammer, though. I've sent out a request to the r-help list asking if there is some way to either change where R looks for "unlock_solver", or to just unload/reload a portion of deSolve.
Make sure you have the following packages installed (at the beginning of your script) to compile the .dll file.
packages <- c("deSolve","coda", "adaptMCMC")
if(require(packages)){
install.packages(packages,dependencies = T)
}
ppp <- lapply(packages,require,character.only=T)
First remove the current .dll file in your wdir
c_compile <- "your_c_file"
dyn.unload(paste0(c_compile,".dll")) # unload dll (Windows only)
Then compile the C file and the .dll
system(paste0("R CMD SHLIB ",c_compile,".c"))
dyn.load(paste0(c_compile,".dll"))# Load dll (Windows only)

Resources