I am trying to run this example on a fresh julia installation (Version 1.0.2 (2018-11-08)):
https://github.com/JuliaOpt/JuMP.jl/blob/master/examples/basic.jl
But I always get this error.
julia> using JuMP, Clp
julia> m = Model(with_optimizer(Clp.Optimizer))
ERROR: UndefVarError: with_optimizer not defined
Stacktrace:
[1] top-level scope at none:0
What am I doing wrong? It seems such a simple example should run quite easily.
You are looking at the example from master branch from the GitHub repository. There are breaking changes in JuMP API since its last release.
You should look at basic.jl file in your local repository. It should be located in a directory location like ~/.julia/packages/JuMP/Xvn0n/examples/basic.jl (the Xvn0n part might be different in your case but the path pattern should be the same; if you are on Windows then ~ is a directory of your user profile).
The example you are referring to looks like this in the released version of the package:
using JuMP, Clp
m = Model(solver = ClpSolver())
#variable(m, 0 <= x <= 2)
#variable(m, 0 <= y <= 30)
#objective(m, Max, 5x + 3y)
#constraint(m, 1x + 5y <= 3.0)
print(m)
status = solve(m)
println("Objective value: ", getobjectivevalue(m))
println("x = ", getvalue(x))
println("y = ", getvalue(y))
You can also find the zipped sources of the latest release here https://github.com/JuliaOpt/JuMP.jl/releases/tag/v0.18.4, but of course as new releases are published the number will change so the most reliable place to look at the codes are examples that JuMP has on your local machine.
Related
I am trying to run the code below in VS Code for Julia (or directly on Julia). It is a simple example that computes the Maximum Likelihood estimator of the mean and the variance of a normal distribution (source):
Random.seed!(1234)
n = 1_000
data = randn(n)
mle = Model(optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0))
#NLparameter(mle, problem_data[i = 1:n] == data[i])
μ0 = randn()
σ0 = rand() + 1
#info "Starting guess, mean: $μ0, std: $σ0"
#variable(mle, μ, start = μ0)
#variable(mle, σ >= 0.0, start = σ0)
#NLexpression(mle, loglikelihood,
-(n / 2) * (log(2π) + 2 * log(σ)) - inv(2 * σ^2) * sum((xi - μ)^2 for xi in problem_data)
)
#NLobjective(mle, Max, loglikelihood)
optimize!(mle)
This is a nonlinear optimization problem using JuMP, and when running optimize!(mle) I am getting 'terminal process terminated with exit code 3221226356' in VS Code. Similarly, when I run it directly in Julia, it just shuts down entirely. (I have the latest versions) (I have tried in a different computer and everything works fine). Any help would be greatly appreciated!
P.S. I have seen it might have to do with a 'heap corruption problem', but I have no idea what that means/how to solve it.
This has been cross-posted on the Julia discourse, we'll continue to debug it there: https://discourse.julialang.org/t/cant-run-simple-jump-example/67938
It's either:
An issue in VS-Code (although "when I run it directly in Julia" may rule this out)
An issue with Ipopt, which is either due to it installing an old version, or a weird incompatibility with this user's system
Either way, this is likely hard to debug.
I recently installed GNAT Ada (2020) and GNAVI GWindows on a new PC.
On trying to build an old project developed under the 2015 version, I get this:
No candidate interpretations match the actuals:
Too many arguments in call to "Put"
expected private type "Printer_Canvas_Type" defined at gwindows-drawing.ads:603
found private type "Canvas_Type" defined at gwindows-drawing.ads:96
This is one of the several similar pieces of code that produce the same result (MapCanvas is declared elsewhere as Canvas_Type):
Put (MapCanvas, (DATUM_BASE_X +
(x * 10 * GRID_MONAD_SPACING)) +
(5 * GRID_MONAD_SPACING),
y - (GRID_MONAD_SPACING + 5),
Integer'Image (x));
Possibly related, I also get this in regard to the last argument in the call to Put - Integer'Image(x)
expected type "Standard.Wide_String"
found type"Standard.String"
As an experiment, I tried converting the last argument using To_Wide_String (Integer'Image (x)) but the result was the same.
Elsewhere, similar code with a literal compiles ok:
Put (MapCanvas, (DATUM_BASE_X - 1 +
(GRID_MONAD_SPACING / 2) +
(x * 10 * GRID_MONAD_SPACING)),
y + 20 + (60 * GRID_MONAD_SPACING),
"0 2 4 6 8 ");
On the previous PC with GNAT Ada 2015, everything compiled. I've compared the declarations
of Put in gwindows-drawing.ads in the old and new installations of GWindows and they are identical.
Unfortunately I can no longer build on the old PC without a lot of backtracking - the old project drive
is in use elsewhere, though I do have it all backed up.
I'd appreciate any ideas on where to look for the cause of the problem.
GWindows has two string modes matching Windows API: ANSI (8-bit character) and Unicode.
The type GString is either a String or a Wide_String.
You can switch the framework's mode with ansi.cmd and unicode.cmd .
Obviously your old project was in ANSI mode.
function foo(x)
n = 0
t = time()
while n < x
n += 1
end
sec = time() - t
println("done in $sec seconds $(x / sec) operations/sec")
end
foo(1e7)
I'm on Windows using Atom latest version of everything. I run the above code and it prints fine for 1e1,..., 1e7
But for foo(1e8) and above, it prints the line, and then the line DISAPPEARS. I'm completely baffled by that.
It only happens in Atom (VS Code works fine). I use control-enter on the foo(1e8) line to evaluate it and I can see it printing the line and then the line erases by itself. For foo(1e7) and below, it prints fine.
Here's the video of this with 1e8 then 1e7 and it happens on Linux too. As you can see from one of the attempts the video was able to capture the printing and erasing (see at 5 second mark in the video). When I changed to 1e7, it prints fine every single time.
everything is up-to-date: Julia 1.4.1, Atom 1.46, Juno 0.8.1 and I did a complete Julia package update as well.
github.com/JunoLab/Juno.jl/issues/560.
(credit to pfitzseb )
I'm trying to run the RScriptSample present in the samples in the Stream Processor.
I've followed the steps given here.
I have installed R and rJava, and set R_HOME and JRI_HOME accordingly.
#App:name("RScriptSample")
#App:description('Use a R script to process events and produce aggregated outputs based on the provided input variable parameters and expected output attributes.')
define stream weather (time long, temp double);
#sink(type='log')
define stream dataOut (time long, temp double, c long, m double );
#info(name = 'query')
from weather#window.lengthBatch(2)#r:eval("c <- sum(time); m <- sum(temp)", "c long, m double", time, temp)
select * insert into dataOut;
The code does not compile. I'm getting this error in the last line.
No extension exist for r:eval
What am I doing wrong?
Since this extension is under GPL extension, it is not copied to the pack by default. Add the jar to {SP_HOME}/lib folder and try out the sample.
Compatible Version: 4.x.x
I'm still a noob with F#, and I don't understand all the syntax and logic for loading and using packages.
For example, i would like to use (Blue Mountain's) RProvider.
http://bluemountaincapital.github.io/FSharpRProvider/index.html
Using VS2015, in my current solution, I've installed the package with the PM console and Install-Package RProvider
I modified a bit the RProvider.fsx because I've got newer versions of R.NET Community
#nowarn "211"
// Standard NuGet or Paket location
#I "."
#I "lib/net40"
// Standard NuGet locations for R.NET
#I "../R.NET.Community.1.6.4/lib/net40"
#I "../R.NET.Community.FSharp.0.1.9/lib/net40"
// Standard Paket locations for R.NET
#I "../R.NET.Community/lib/net40"
#I "../R.NET.Community.FSharp.1.6.4/lib/net40"
// Try various folders that people might like
#I "bin"
#I "../bin"
#I "../../bin"
#I "lib"
#I "../packages"
// Reference RProvider and RDotNet
#r "RDotNet.dll"
#r "RDotNet.FSharp.dll"
#r "RProvider.dll"
#r "RProvider.Runtime.dll"
open RProvider
do fsi.AddPrinter(fun (synexpr:RDotNet.SymbolicExpression) -> synexpr.Print())
Now my questions are
1) how to load a package (RProvider) from F# interactive ?
well actually i managed to do it this way
For example the RProvider.fsx file is in the path
C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford\packages\RProvider.1.1.15\RProvider.fsx
what i did is
#I #"C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford";;
#load "packages\RProvider.1.1.15\RProvider.fsx";;
and it works :-)
but can I avoid writing the whole path ?
2) In VS2015 if I want to include it in a solution...
in the solution explorer i have included the RProvider.fsx file (below AssemblyInfo.fs, App.config and packages.config come after, is this right ?)
and last the program itself Rtype.fs
I'm trying to reproduce the example from
http://bluemountaincapital.github.io/FSharpRProvider/Statistics-QuickStart.html
open System
open *RDotNet* // the namespace or module 'RDotNet' is not defined
open *RProvider*
open *RProvider*.graphics
open RProvider.stats
// let x = System.Environment.CurrentDirectory
// val x : string
printfn "hello world"
Console.ReadKey() |> ignore
// Random number generator
let rng = Random()
let rand () = rng.NextDouble()
// Generate fake X1 and X2
let X1s = [ for i in 0 .. 9 -> 10. * rand () ]
let X2s = [ for i in 0 .. 9 -> 5. * rand () ]
// Build Ys, following the "true" model
let Ys = [ for i in 0 .. 9 -> 5. + 3. * X1s.[i] - 2. * X2s.[i] + rand () ]
let dataset =
namedParams [
"Y", box Ys;
"X1", box X1s;
"X2", box X2s; ]
|> R.data_frame
let result = R.lm(formula = "Y~X1+X2", data = dataset)
let coefficients = result.AsList().["coefficients"].AsNumeric()
let residuals = result.AsList().["residuals"].AsNumeric()
let summary = R.summary(result)
*summary.AsList().["r.squared"].AsNumeric()
R.plot result*
//this expression should have type 'unit' but has type 'NumericVector'...
I'm getting some warnings/errors by Intellisense although the compiler managed a build.
When executing the exe, it looks like the windows screen is busy, i manage to see some graphs, but they look like they have got nothing to do with what Rtype.fs is saying...
thanks for helping !
EDIT
First of all, I would not recommend using a different version of R.NET than the one that RProvider installs automatically as a dependency. The loading is a bit fragile and it might break things.
1) Regarding the path, you should be able to pass relative path to #load, so just dropping the #I from your script should do the trick.
2) When referencing a dependency from a project (rather than from a script file), you need to add a dependency to the project references. In Visual Studio, this is done by right click on the "References" in your project and using "Add Reference". For type providers, you also need to click "Enable" when the reference is loaded.