ERROR: LoadError: UndefVarError: int not defined

Hi all,

I’m new to programming with Julia, and I’m really stuck.

This is the Julia version running

julia> VERSION
v"1.4.1"

This call_DPM.jl only works with the Julia 0.2.1, this issue happens also with 1.4.1 versions of julia, thus I never managed to run the code here is the error I get:

ERROR: LoadError: UndefVarError: int not defined
Stacktrace:
[1] top-level scope at /Users/yong/Downloads/PopR-master/PopR/exec/call_DPM.jl:3
[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 /Users/yong/Downloads/PopR-master/PopR/exec/call_DPM.jl:3

How do I fix this bug of call_DPM.jl so that it runs in the current version?

The call_dpm.jl code is as follows:

julia code main wrapper

bl=int(ARGS[1])
thin =int(ARGS[3])
numiters =int(ARGS[2])

Typeof=ARGS[4]

cd(ARGS[5])

cps = ARGS[6]

writedlm(“CP.csv”,{cps})

@everywhere CP=readdlm(“CP.csv”)

@everywhere CP=CP[1]

@everywhere typealias Float Float64

@everywhere datas=readdlm(“datas.csv”,‘,’,Float)’

@everywhere single_priors = readdlm(“single_priors.csv”,‘,’,Float)

@everywhere matrix_priors = readdlm(“matrix_priors.csv”,‘,’,Float)

@everywhere const pc_max_ind=int(1e5)
@everywhere const (D, N) = size(datas)

# define normal set types

 
if bl.==1

    @everywhere require(string(CP,"/fixtype.jl"))

else


    @everywhere require(string(CP,"/define_types.jl"))
  
end

#################################################
######### — set up outputs ---- ###############
#################################################

np = nprocs()
nit=int((np)*numiters/thin);

class_ids=Array(Float,(size(datas,2),nit));
k_0s=Array(Float,nit);
K_record=Array(Int8,nit);
alpha_record=Array(Float,nit);

#################################################
######### — RUN IT ----########################
#################################################

if bl.==1

@everywhere require(string(CP,"/DPM_sampler_fix.jl"))

inp = {datas,numiters,thin,stats,priors,consts,CP};
M = {inp for i=1:np};#need to put np-1 again for parallel
    
outs = pmap(DPM_sampler_fix,M);

else

@everywhere require(string(CP,"/DPM_sampler.jl"))

inp = {datas,numiters,thin,stats,priors,consts,CP};
M = {inp for i=1:np}; #need to put np-1 again for parallel
    
outs = pmap(DPM_sampler,M);

end

get outputs

nit=int(numiters/thin);
n=0
for i=1:length(outs)
n=n+1
class_ids[:,((n-1)*nit+1):((n-1)*nit+nit)] = outs[i][1]
k_0s[((n-1)*nit+1):((n-1)*nit+nit)] = outs[i][2]
K_record[((n-1)*nit+1):((n-1)*nit+nit)] =outs[i][3]
alpha_record[((n-1)*nit+1):((n-1)*nit+nit)] = outs[i][4]
end

#################################################
######### — Write out ----#####################
#################################################

writecsv(“source_ids.csv”,class_ids)
writecsv(“K_record.csv”,K_record)
writecsv(“gammas.csv”,alpha_record)
writecsv(“k_0s.csv”,k_0s)

This is indeed code from 2013, written originally for Julia 0.2.1. Source is here.

1 Like

The normal recommendation would be to upgrade sequentially through Julia 0.3, 0.4, 0.5, 0.6, 0.7, 1.x in order to get helpful deprecation messages along the way. That’s obviously an unusually long process in this case. Julia 0.2 was a long time ago but I can at least give some hints of what needs changing:

int(ARGS[1])parse(Int, ARGS[1])
int(1e5)Int(1e5)
inp = {datas,numiters,thin,stats,priors,consts,CP}inp = [datas,numiters,thin,stats,priors,consts,CP]

You will need to add a using DelimitedFiles to make readdlm and writedlm available.

I’m not sure but you can at least try to replace require with include.

2 Likes

yeah, OP Julia has a somewhat unfair reputation for breaking things too much, considering 1.0 was over two years ago and the language has been stable since then.

But in this scenario, 0.2.1 was a loooong time ago with a lot of breaking changes in between 0.3, 0.4, ... 1.0.

If you are new to programming with Julia I would say either

  1. Find a different project to learn about, something written for 1.x. Hopefully someone more informed than me can point you to a Julia package for population structures.
  2. If you are tasked with porting this code over to 1.0, I would probably start from scratch… Read the manual, read tutorials, and try to replicate the logic of the code without worrying too much about porting it line-by-line.

This is definitely frustrating to hear, and doesn’t make for a good introduction to Julia! But remember this was 8 years ago when the language was in its infancy and the developers made no promises of long-term stability.

2 Likes