Building CPLEX fails in Julia - julia

I am trying to install CPLEX in Julia on a computer cluster. I got the following error when I did Pkg.build("CPLEX"). It seems that I didn't pass the right path. I know how to correct it on my local computer but could anyone tell me how to fix it on a computer cluster? Or is it because of some other problems?
For your information,
CPLEX version: 12.10-GCCcore-8.3.0,
Julia version: 1.7.1.
Thanks very much in advance.
Hongyu.
The versions of CPLEX supported by CPLEX.jl are:
* 12.10
* 20.1
You must download and install one of these versions separately.
You should set the `CPLEX_STUDIO_BINARIES` environment variable to point to
the install location then try again. For example (updating the path to the
correct location):
ENV["CPLEX_STUDIO_BINARIES"] = "/opt/CPLEX_Studio201/cplex/bin/x86-64_linux/"
import Pkg
Pkg.add("CPLEX")
Pkg.build("CPLEX")
See the CPLEX.jl README at https://github.com/jump-dev/CPLEX.jl for further
instructions.
Stacktrace:
[1] error(s::String)
# Base ./error.jl:33
[2] try_local_installation()
# Main ~/.julia/packages/CPLEX/88lum/deps/build.jl:132
[3] top-level scope
# ~/.julia/packages/CPLEX/88lum/deps/build.jl:150
[4] include(fname::String)
# Base.MainInclude ./client.jl:451
[5] top-level scope
# none:5
in expression starting at /home/hongyuzh/.julia/packages/CPLEX/88lum/deps/build.jl:143
Stacktrace:
[1] pkgerror(msg::String)
# Pkg.Types /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Types.jl:68
[2] (::Pkg.Operations.var"#62#67"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec})()
# Pkg.Operations /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:962
[3] withenv(::Pkg.Operations.var"#62#67"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec}, ::Pair{String, String}, ::Vararg{Pair{String}})
# Base ./env.jl:172
[4] (::Pkg.Operations.var"#99#103"{String, Bool, Bool, Bool, Pkg.Operations.var"#62#67"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec}, Pkg.Types.PackageSpec})()
# Pkg.Operations /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:1506
[5] with_temp_env(fn::Pkg.Operations.var"#99#103"{String, Bool, Bool, Bool, Pkg.Operations.var"#62#67"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec}, Pkg.Types.PackageSpec}, temp_env::String)
# Pkg.Operations /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:1390
[6] (::Pkg.Operations.var"#98#102"{Bool, Bool, Bool, Pkg.Operations.var"#62#67"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec}, Pkg.Types.Context, Pkg.Types.PackageSpec, String, Pkg.Types.Project, String})(tmp::String)
# Pkg.Operations /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:1469
[7] mktempdir(fn::Pkg.Operations.var"#98#102"{Bool, Bool, Bool, Pkg.Operations.var"#62#67"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec}, Pkg.Types.Context, Pkg.Types.PackageSpec, String, Pkg.Types.Project, String}, parent::String; prefix::String)
# Base.Filesystem ./file.jl:750
[8] mktempdir(fn::Function, parent::String) (repeats 2 times)
# Base.Filesystem ./file.jl:748
[9] sandbox(fn::Function, ctx::Pkg.Types.Context, target::Pkg.Types.PackageSpec, target_path::String, sandbox_path::String, sandbox_project_override::Pkg.Types.Project; force_latest_compatible_version::Bool, allow_earlier_backwards_compatible_versions::Bool, allow_reresolve::Bool)
# Pkg.Operations /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:1435
[10] sandbox(fn::Function, ctx::Pkg.Types.Context, target::Pkg.Types.PackageSpec, target_path::String, sandbox_path::String, sandbox_project_override::Pkg.Types.Project)
# Pkg.Operations /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:1432
[11] build_versions(ctx::Pkg.Types.Context, uuids::Set{Base.UUID}; verbose::Bool)
# Pkg.Operations /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:943
[12] build(ctx::Pkg.Types.Context, uuids::Set{Base.UUID}, verbose::Bool)
# Pkg.Operations /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:822
[13] build(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; verbose::Bool, kwargs::Base.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})
# Pkg.API /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/API.jl:992
[14] build(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
# Pkg.API /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/API.jl:149
[15] build(pkgs::Vector{Pkg.Types.PackageSpec})
# Pkg.API /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/API.jl:144
[16] #build#99
# /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/API.jl:142 [inlined]
[17] build
# /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/API.jl:142 [inlined]
[18] #build#98
# /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/API.jl:141 [inlined]
[19] build(pkg::String)
# Pkg.API /share/apps/Julia/1.7.1-linux-x86_64/share/julia/stdlib/v1.7/Pkg/src/API.jl:141
[20] top-level scope
# REPL[138]:1

(Solution found in comment discussion, adding as answer for better visibility.)
As the error message indicates, you have to set the ENV["CPLEX_STUDIO_BINARIES"] value to the directory that contains cplex. You can find that by running which cplex | xargs dirname (or simply which cplex and removing the final cplex from the result yourself).
One you set CPLEX_STUDIO_BINARIES to that path, you can run Pkg.build("CPLEX") again to let CPLEX.jl pick up the binaries from the path.

Related

How to fix a problem with Cyrillic symbols (cmd system commands)?

In my previous post, I brought up a question about Cyrillic symbols in R.
Today I have faced another one.
For example, we want to see our running processes:
test <- system2(command="tasklist",
stdout=TRUE,
stderr=TRUE,
wait = TRUE)
and what we see...
[1] ""
[2] "€¬п ®Ўа § PID €¬п бҐббЁЁ ь ᥠ­б Џ ¬пвм"
[3] "========================= ======== ================ =========== ============"
[4] "System Idle Process 0 Services 0 24 ЉЃ"
[5] "System 4 Services 0 580 ЉЃ"
***
"Iconv", which helped in the previous task - couldn't help here.
sys.setlocale - too.
What can solve this problem?
I found a solution.
#/c - Carries out the command specified by string and then stops.
command <- function(command,
intern = TRUE,
wait = FALSE)
system(paste("cmd.exe /c", command),
intern = T,
wait = wait)
#changing our charset
command("chcp 1251")
[1] "’ҐЄгй п Є®¤®ў п бва ­Ёж : 1251" //say bye-bye to mojibake)
# and voila!
command("tasklist")
[1] ""
[2] "Имя образа PID Имя сессии № сеанса Память"
[3] "========================= ======== ================ =========== ============"
[4] "System Idle Process 0 Services 0 24 КБ"
[5] "System 4 Services 0 580 КБ"
[6] "smss.exe 380 Services 0 1 232 КБ"
***

Return level in R

I am trying to compute return levels for a certain return period (20 years) for my extreme precipitation. Using the block maxima approach, I made the following object to extract the maximum values:
Gcomb <-c(Gmax[1], Gmax1[1], Gmax2[1], Gmax3[1], Gmax4[1], Gmax5[1], Gmax6[1], Gmax7[1], Gmax8[1],
Gmax[2], Gmax1[2], Gmax2[2], Gmax3[2], Gmax4[2], Gmax5[2], Gmax6[2], Gmax7[2], Gmax8[2], Gmax[3],
Gmax1[3], Gmax2[3], Gmax3[3], Gmax4[3], Gmax5[3], Gmax6[3], Gmax7[3], Gmax8[3], Gmax[4], Gmax1[4],
Gmax2[4], Gmax3[4], Gmax4[4], Gmax5[4], Gmax6[4], Gmax7[4], Gmax8[4], Gmax[5], Gmax1[5], Gmax2[5],
Gmax3[5], Gmax4[5], Gmax5[5], Gmax6[5], Gmax7[5], Gmax8[5], Gmax[6], Gmax1[6], Gmax2[6], Gmax3[6],
Gmax4[6], Gmax5[6], Gmax6[6], Gmax7[6], Gmax8[6], Gmax[7], Gmax1[7], Gmax2[7], Gmax3[7], Gmax4[7],
Gmax5[7], Gmax6[7], Gmax7[7], Gmax8[7])
Gcomb looks like this:
>Gcomb
[1] 191.46960 115.77133 209.15147 243.26880 84.97396 157.38678 138.84937
140.96840 143.80301 196.87990 131.89099
[12] 137.08264 231.11342 116.67323 125.27563 100.72293 159.45056 198.12399
216.74820 120.16774 147.73828 396.64862
[23] 164.02292 132.94519 99.95055 162.81708 186.59691 219.53568 124.76086
174.99396 231.20859 108.70350 139.22649
[34] 160.40935 159.03806 162.56891 217.58543 123.11100 149.26378 245.90994
92.68985 152.45033 171.12381 159.27040
[45] 141.19446 205.46706 101.71022 163.25592 328.31265 119.69154 122.01060
114.79624 147.92126 179.91318 200.70750
[56] 110.50108 231.30966 213.02881 125.74141 152.19133 98.35700 204.43138
182.53252
Now, when I try to compute the return level (a 20-year return level):
library(extRemes)
return.level.fevd(Gcomb, return.period = 20)
I end up with the following error:
Error: $ operator is invalid for atomic vectors
What could be causing this error? I tried creating a vector with the same values, but the error persists
Any help or insight for this would be very appreciated!

Why does Julia throw a premature end of input error when i write and if statement?

This is my code:
using Printf
using Statistics
age = 12
if age < 10
println("$age")
This is the error:
ERROR: LoadError: syntax: incomplete: premature end of input
Stacktrace:
[1] top-level scope at D:\julia\trial.jl:5
[2] include(::Module, ::String) at .\Base.jl:377
[3] exec_options(::Base.JLOptions) at .\client.jl:288
[4] _start() at .\client.jl:484
in expression starting at D:\julia\trial.jl:5
It works well if I remove the if statement and just print the value of age.
Julia terminates its blocks with an end keyword (and does not rely on whitespace to define its blocks).
age = 12
if age < 10
println("$age")
end

Error while importing minitab file into R

I was using the foreign package in R to import the MTP file, but it only shows file read error. I already set up the default directory, but it does not work. I would really appreciate if I could get some help. Thank you in advance.
library(foreign)
d44<-read.mtp("PERAGGR.MTP")
Here is the file that I was using
The read.mtp function is fairly ancient. And since that file is actually an ASCII file, just read it with `readLines:
d44<-readLines("~/Downloads/PERAGGR.MTP")
head(d44)
# ============== top of output==================
[1] "Minitab Portable Worksheet P1.1 2007 523 Rel 15.0 ."
[2] "% 3 1 109 0 Study ."
[3] " 1.000000000E+00 2.000000000E+00 3.000000000E+00 4.000000000E+00 5.000000000E+00"
[4] " 6.000000000E+00 7.000000000E+00 8.000000000E+00 9.000000000E+00 1.000000000E+01"
[5] " 1.100000000E+01 1.200000000E+01 1.300000000E+01 1.400000000E+01 1.500000000E+01"
[6] " 1.600000000E+01 1.700000000E+01 1.800000000E+01 1.900000000E+01 2.000000000E+01"

Inserting the Characters at specific position of the file

I have a file that I made for my model input. But I has some missing characters. I want to insert these characters at their position that model can read its
Its class i checked is that
file. class("outfile.txt")
[1] "character
So the file from my codes after different codes is
HYDRUS_Version=5
WaterFlow=0
SoluteTransport=0
Unsatchem=0
Unsatchem=0
HP1=0
HeatTransport=0
EquilibriumAdsorption=0
MobileImmobile=0
RootWaterUptake=0
RootGrowth=0
MaterialNumbers=0
SubregionNumbers=0
SpaceUnit=cm
TimeUnit=days
PrintTimes=160
NumberOfSolutes=0
InitialCondition=1
NumberOfNodes=101
ProfileDepth=120
ObservationNodes=160
GridVisible=160
SnapToGrid=160
ProfileWidth=160
LeftMargin=160
GridOrgX=160
GridOrgY=160
GridDX=160
GridDY=160
and my required file is [I want to insert 4 characters in it, two ; and [Main] are at the start and two ; and [Profile] are inside the file. I want the final file as given below.
;
[Main] `
HYDRUS_Version=5
WaterFlow=0
SoluteTransport=0
Unsatchem=0
Unsatchem=0
HP1=0
HeatTransport=0
EquilibriumAdsorption=0
MobileImmobile=0
RootWaterUptake=0
RootGrowth=0
MaterialNumbers=0
SubregionNumbers=0
SpaceUnit=cm
TimeUnit=days
PrintTimes=160
NumberOfSolutes=0
InitialCondition=1
;
[Profile]
NumberOfNodes=101
ProfileDepth=120
ObservationNodes=160
GridVisible=160
SnapToGrid=160
ProfileWidth=160
LeftMargin=160
GridOrgX=160
GridOrgY=160
GridDX=160
GridDY=160
you can try:
imported_text <- readLines("outfile.txt")
[1] "HYDRUS_Version=5" "WaterFlow=0" "SoluteTransport=0" "Unsatchem=0" "Unsatchem=0" "HP1=0"
[7] "HeatTransport=0" "EquilibriumAdsorption=0" "MobileImmobile=0" "RootWaterUptake=0" "RootGrowth=0" "MaterialNumbers=0"
[13] "SubregionNumbers=0" "SpaceUnit=cm" "TimeUnit=days" "PrintTimes=160" "NumberOfSolutes=0" "InitialCondition=1"
[19] "NumberOfNodes=101" "ProfileDepth=120" "ObservationNodes=160" "GridVisible=160" "SnapToGrid=160" "ProfileWidth=160"
[25] "LeftMargin=160" "GridOrgX=160" "GridOrgY=160" "GridDX=160" "GridDY=160"
and try the c function:
imported_text2 <- c("; `here I want this`","[Main] `here I want this`",imported_text)
Furthermore you can do: select the
final_text <- c(imported_text2[1:20],"; `here I want this`","[Profile] `here I want this`",imported_text2[21:length(imported_text2)])
[1] "; `here I want this`" "[Main] `here I want this`" "HYDRUS_Version=5"
[4] "WaterFlow=0" "SoluteTransport=0" "Unsatchem=0"
[7] "Unsatchem=0" "HP1=0" "HeatTransport=0"
[10] "EquilibriumAdsorption=0" "MobileImmobile=0" "RootWaterUptake=0"
[13] "RootGrowth=0" "MaterialNumbers=0" "SubregionNumbers=0"
[16] "SpaceUnit=cm" "TimeUnit=days" "PrintTimes=160"
[19] "NumberOfSolutes=0" "InitialCondition=1" "; `here I want this`"
[22] "[Profile] `here I want this`" "NumberOfNodes=101" "ProfileDepth=120"
[25] "ObservationNodes=160" "GridVisible=160" "SnapToGrid=160"
[28] "ProfileWidth=160" "LeftMargin=160" "GridOrgX=160"
[31] "GridOrgY=160" "GridDX=160" "GridDY=160"
EDIT
In order to have the new output (as per OP request):
c(";","[Main]",text[1:18],";","[Profile]",text[19:length(text)])

Resources