Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility issues with Julia version and with operationg system compativility #10

Closed

Conversation

ilmirajat
Copy link

@ilmirajat ilmirajat commented Nov 29, 2023

Issues

Issue 1: Code dedends on some old Julia version

If you download the latest version of Julia and try to use model as instructed in Readme, it just does not work.

At first DelimiteredFiles is not longer part of the standard library in version 1.9+ and you must install it as a separate dependency.

Secondly, manifest file forma is changed. The old format should be supported according to error message, but - well - it just didn't not work.

Issue 2: Folder separator issue

Second issue related folder delimiter (\ in windowd and / in Linux and MacOS). My understanding is that in Julia you can use forward slash (/) as folder separator also in Windows and it is automatically converted to backslash (). However, I have not tested if it works in this way in Windows.

Changes and solutions

Solution to issue 1

In this PR I have added DelimiteredFiles to dependency list (using REPL). This was removed from standard class library in version 1.9 and there for project did not work with the current version of Julia. I also upgrade deps to v. 2.0 format. It automatically set julia_version to 1.9.4. The latest LTS is also good options.

I did this in REPL with following commands:

using Pkg
Pkg.add("DelimitedFiles")
Pkg.upgrade_manifest()
Pkg.resolve()
Pkg.update()

Solution to issue 2

There was an function that had hardcoded paths. I changed folder delimiter to forward slass /. I presume that that works also in Windows, but I have not tested it.

- add DelimiteredFiles to depenbency list. This was removed from standard class library in version 1.9 and there for project did not work with the current version of Julia
- upgrade deps to v. 2.0 format
- change folder delimter to /. That should work in all operating system and not just with Windows
@tkorvola
Copy link
Collaborator

tkorvola commented Dec 1, 2023

Slash generally works as directory separator in Windows everywhere except with commands that use it to indicate options, e.g., dir /p. It is thus the most portable option if you need to pick one: probably works on every platform you care about. Then again, sometimes you don't need to pick anything because a library handles it for you, e.g., joinpath.

@tkorvola
Copy link
Collaborator

tkorvola commented Dec 1, 2023

What was the version problem again? I did ]activate ., ]instantiate, got some errors, ]up, then everything was apparently fine. I was able to generate a model from "input_data.xlsx", solve it and write out the bid matrix. No problems with missing packages. Julia 1.9.4.

@ilmirajat
Copy link
Author

Slash generally works as directory separator in Windows everywhere except with commands that use it to indicate options, e.g., dir /p. It is thus the most portable option if you need to pick one: probably works on every platform you care about. Then again, sometimes you don't need to pick anything because a library handles it for you, e.g., joinpath.

In addition, Julia Filesystem module has function normpath, that normalizes "Normalize a path, removing "." and ".." entries and changing "/" to the canonical path separator for the system." My understanding is that this is commonly called by other functions, but I have not checked this from the source code or by testing with a Windows machine. In this PR I have replaced \ with / in one function. I haven't tested if it works in Windows, but it should.

Anyways, are you asking that I should test this PR also in Windows, or was this a general comment? If you wish, I can test this in Windows later if my old Windows laptop still works. I haven't used it for years.

What was the version problem again? I did ]activate ., ]instantiate, got some errors, ]up, then everything was apparently fine. I was able to generate a model from "input_data.xlsx", solve it and write out the bid matrix. No problems with missing packages. Julia 1.9.4.

I got quite a few errors and maybe some of them were same that you got. DelimitedFiles error (see below) is the only one that, for sure, does not work after 1.9 if you do fresh Julia installation; see JuliaLang/julia#48161. Maybe the other errors weren't fatal ones.

I'm not experienced with Julia, therefore I can only guess the reason why you didn't get the error relating the package. My guess is that it was already installed in you machine and you just updated the latest version of Julia instead of doing a fresh installation. Julia seems to have all modules in a folder that is probably the same in all Julia version. In MacOS the folder is ~/.julia/packages. So probably upgrading Julia version does not remove packages installed via older Julia version.

I failed to save the all error. As it didn't work smoothly I googled, read Julia documentation and tried things until I managed to fix the problem. I forgot to save some log errors Iogs. You will get this the same error e.g. in this way after you have run activate command and instantiate command as instructed in the readme.

julia> import Pkg; Pkg.precompile()
ERROR: Could not locate the source code for the DelimitedFiles package. Are you trying to use a manifest generated by a different version of Julia?
Stacktrace:
  [1] pkgerror(msg::String)
    @ Pkg.Types /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Types.jl:69
  [2] is_package_downloaded(manifest_file::String, pkg::Pkg.Types.PackageSpec; platform::Base.BinaryPlatforms.Platform)
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:2194
  [3] is_package_downloaded
    @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:2191 [inlined]
  [4] #10
    @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:133 [inlined]
  [5] _all
    @ ./reduce.jl:1283 [inlined]
  [6] #all#831
    @ ./reducedim.jl:1007 [inlined]
  [7] all
    @ ./reducedim.jl:1007 [inlined]
  [8] is_instantiated(env::Pkg.Types.EnvCache; platform::Base.BinaryPlatforms.Platform)
    @ Pkg.Operations /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:133
  [9] is_instantiated
    @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/Operations.jl:117 [inlined]
 [10] instantiate(ctx::Pkg.Types.Context; manifest::Nothing, update_registry::Bool, verbose::Bool, platform::Base.BinaryPlatforms.Platform, allow_build::Bool, allow_autoprecomp::Bool, kwargs::Base.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:1738
 [11] instantiate
    @ /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:1691 [inlined]
 [12] precompile(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; internal_call::Bool, strict::Bool, warn_loaded::Bool, already_instantiated::Bool, timing::Bool, kwargs::Base.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:1118
 [13] precompile(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:156
 [14] precompile(pkgs::Vector{Pkg.Types.PackageSpec})
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:145
 [15] precompile(; name::Nothing, uuid::Nothing, version::Nothing, url::Nothing, rev::Nothing, path::Nothing, mode::Pkg.Types.PackageMode, subdir::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:171
 [16] precompile()
    @ Pkg.API /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Pkg/src/API.jl:162
 [17] top-level scope
    @ REPL[15]:1

By the way, is there a reason to not use the latest version of Julia and to not upgrade the current obsolete deps format to version 2.0 (except that you have had neither time nor need to upgrade the version earlier)? I.e. how you are planning to manage Julia and deps versions in this project? If it is not possible to upgrade to latest version, it would be nice to mention in Readme what version of Julia you should use and warn about errors you will get if you use the latest version.

@tkorvola
Copy link
Collaborator

tkorvola commented Dec 4, 2023

I don't understand why anyone would write pwd() * "\\results" instead of just "results". Seems useless use of pwd() , regardless which way the slash leans. If you don't want to write the slightly cumbersome joinpath("results", "foo_" * bar()), it is better to write "results/foo_" * bar() than the same with a backslash. The backslash is just a regular valid filename character on Unixes (where pathname components can contain anything except slashes and NUL). Grepping for backslashes in the source, I think you got two out of three, and the third is non-functional, in a docstring. There are also some in non-*.jl files, at least README.md.

Where is DelimitedFiles used, so that it would need to be added as a dependency? I cannot find any mention of it or its functions readdlm and writedlm in the source. I don't really understand Julia package management either, but I doubt transitive dependencies belong in Project.toml. Besides, ]st does not show DelimitedFiles on my machine; I guess it's not a transitive dependency either – at least not with current packages; as said, I had to do an ]up.

I don't know any reason to postpone upgrading the manifest format, but as said, I don't know much about Julia package management.

@tkorvola tkorvola mentioned this pull request May 14, 2024
@sundelld sundelld closed this May 21, 2024
@sundelld
Copy link
Contributor

The changes proposed in this PR have been implemented one way or another. Thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants