Running from different version of Julia

With the following code

function finding_minimum_sum(list_of_distance, list_of_projected_load, show_list = true)
	x = list_of_distance
	y = list_of_projected_load
	l1 = length(x)
	l2 = length(y)
	xy = []
	for i in 1:l2
		xy1a = []
		xy2a = []
		for j in 1:l1
			if (i ≤ j) && (i != l2)
				push!(xy1a, sum(x[i:j])*y[j+1])
			end
			if (i != 1 && i > j)
				push!(xy2a, sum(x[j:(i-1)])*y[j])
			end
		end
		if !isempty(xy1a) && !isempty(xy2a)
			an = collect(Iterators.flatten([xy2a, xy1a]))
			push!(xy, sum(insert!(an, i, y[i])))
		else
			if i == 1
				push!(xy, sum(collect(Iterators.flatten([y[1], xy1a]))))
			else
				push!(xy, sum(collect(Iterators.flatten([xy2a, y[l2]]))))
			end
		end
	end
	min_sum = extrema(xy)[1]
	ls = findall(x->x==min_sum, xy)
	if show_list
		return xy, ls
	else
		return ls
	end
end

given with the following:
lst1 = [2, 4]
lst2 = [1, 2, 3]
finding_minimum_sum(lst1, lst2)

if the above code run in Julia 1.9.2 the output will be:
([23, 16, 17], [2]

while running the code in Julia 1.9.3 the output will be:
([23], [1])

How to resolve to the new version?

Are you sure you ran the same code in both?
I just tried it on 1.8.5 and 1.9.3 and got the same in both cases (Any[23, 16, 17], [2]).

Yes, I’m sure and here’s my proof. (I take a screen shots, these are from different laptop) see my upload photos.)


Is it possible that the problem is in installation of Julia 1.9.3 (I use portable apps)?

Thank you for giving your time…

Yeah, I couldn’t spot any difference from the screenshots. Just to double check (I’m not trying to be annoying :sweat_smile: ), can you also show the values of list_of_distance and list_of_projected_load in both notebooks, right before you call the function?

Here’s some other things that might cause the issue, if both the function code and the input variables are exactly identical:

  • There might be other code that, e.g., redefines some functions or sets some global variables which interfere with the code. It’s impossible to know that without seeing the both notebooks.
  • If the code is running on different machines there might be something different in both startup.jl files.
  • … black magic?

If you start a new REPL and just paste this code in it, do you still get different results? (that’s what I tried)

function finding_minimum_sum(list_of_distance, list_of_projected_load, show_list = true)
	x = list_of_distance
	y = list_of_projected_load
	l1 = length(x)
	l2 = length(y)
	xy = []
	for i in 1:l2
		xy1a = []
		xy2a = []
		for j in 1:l1
			if (i ≤ j) && (i != l2)
				push!(xy1a, sum(x[i:j])*y[j+1])
			end
			if (i != 1 && i > j)
				push!(xy2a, sum(x[j:(i-1)])*y[j])
			end
		end
		if !isempty(xy1a) && !isempty(xy2a)
			an = collect(Iterators.flatten([xy2a, xy1a]))
			push!(xy, sum(insert!(an, i, y[i])))
		else
			if i == 1
				push!(xy, sum(collect(Iterators.flatten([y[1], xy1a]))))
			else
				push!(xy, sum(collect(Iterators.flatten([xy2a, y[l2]]))))
			end
		end
	end
	min_sum = extrema(xy)[1]
	ls = findall(x->x==min_sum, xy)
	if show_list
		return xy, ls
	else
		return ls
	end
end

lst1 = [2, 4]
lst2 = [1, 2, 3]
finding_minimum_sum(lst1, lst2)

Just to corroborate what Sevi is saying, here’s what I get on 1.9.2 and 1.9.3:

Also your code is just a series of fairly basic functions shipped with the base Julia install, so it’s exceedingly unlikely that there’s such a change in the output returned between Julia patch versions (indeed this would likely be a serious bug in the language).

1 Like

Thank you again…
Here I take a screen shot of the code with variables, and also I did delete all the variables and function other than the code you see in the pictures.

I also tried in Julia REPL

I suspected that in portable of Julia 1.9.3 might got the problem, I remember that when add packages it always not finished( It hangs - I don’t know what exact terms), so what i did is to close the Julia REPL when it happens, then I will open it again then add package then it hangs again… many times i did that… but when I check the status it shows that the package is installed. so i continue adding packages even though it always hangs.

I used portable julia(not julia installer) because our company restricted in installation of software…

Thank you.

IT’s time to talk about Function programming

In Functional programming, there are two types of Functions

  1. Pure Function like sin()
  2. Impure Function like time()

A Pure Function will ALWAYS return the same output for the same input. For example

sin(pi/6) == 0.5

An Impure Function MAY give different output for the same input like

julia> time()

1.698050756408463e9

julia> time()

1.698050757773564e9

Could you explain what a “portable Julia” is?

Also to narrow down the possible sources of the issue it would be good to forget about Pluto and even opening REPLs for a moment. Can you just create a file test.jl your find_maximum_sum function in and then at the bottom add

println(find_maximum_sum([2,4], [1,2,3]))

Then call Julia from the terminal without startup file and run this file, which will now print the result to the terminal:

C:\Users\...>C:/.../Julia-1.9.3/bin/julia.exe --startup-file=no findminsum.jl
(Any[23, 16, 17], [2])

C:\Users\...>C:/.../Julia-1.9.2/bin/julia.exe --startup-file=no findminsum.jl
(Any[23, 16, 17], [2])
1 Like

This is what I mean of Julia Portable, see picture below.

That gives me the same result:

C:\(...)>C:/(...)/julia-1.9.3-win64/julia-1.9.3/bin/julia.exe --startup-file=no findminsum.jl
(Any[23, 16, 17], [2])

so it’s not a problem with the portable version.

1 Like

so… I still don’t know what is the reason why my julia 1.9.3 gives different output…
Thank you, anyway…

I would add a few @show into the code and look where the two executions start to diverge and then try to pin down what the problem might be. Since the code is short and test data is small, that should be quite simple to do.

2 Likes

Your code in your Julia 1.9.3 is different than your Julia 1.9.2 notebook.

The code you pasted above and are using for Julia 1.9.2 is as follows.

function finding_minimum_sum(list_of_distance, list_of_projected_load, show_list = true)
    # ...
    for i in 1:l2
        # ...
    end
    if show_list
        return xy, ls
    else
        return ls
    end
end

The code you have in your Julia 1.9.3 notebook is as follows with the if statement inside the for loop.

function finding_minimum_sum(list_of_distance, list_of_projected_load, show_list = true)
    # ...
    for i in 1:l2
        # ...
        if show_list
            return xy, ls
        else
            return ls
        end
    end
end
8 Likes

Great Scott!

Talk about not seeing the forest for all the trees… I thought I looked at it very carefully, but didn’t catch the block scopes. Can’t unsee it now :rofl:

1 Like

It’s a bit disturbing how bad “human vision” is. I’m finding it questionable that “we” are the ones “training” AI how to do “computer vision”.

3 Likes

While we are here, I should point out that you probably want to add a type to these arrays, especially if the the element type can be made concrete.

1 Like

Best bet in these situations is to copy/paste into different files and then diff file1.jl file2.jl

2 Likes

To be fair, the OP only gave us the text for one version. The rest were screenshots.

2 Likes

Oh yeah, I thought the person I was replying to was op - my bad.

Thank you, I notice now. :sweat_smile: