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

can only open more than one gmt session at one time #378

Closed
htyeim opened this issue Jun 9, 2020 · 7 comments
Closed

can only open more than one gmt session at one time #378

htyeim opened this issue Jun 9, 2020 · 7 comments

Comments

@htyeim
Copy link
Contributor

htyeim commented Jun 9, 2020

GMT.jl will crash if I run two sessions (gmtbegin(), gmtend()) at one time. Code is proved in the end.

The plotting is not problem if I only open one session. But if I open another session which is very common when someone needs to deal with a lot of data, the first one will crash giving the error:

psconvert [ERROR]: Failed to truncate file /Users/t/.gmt/sessions/gmt6.1685/gmt_1.ps- (via truncate) back to 22644 bytes
end [ERROR]: Failed to call psconvert
end [ERROR]: process_figures returned error 78
end [ERROR]: No directory named /Users/t/.gmt/sessions/gmt6.1685
ERROR: LoadError: Something went wrong when calling the module. GMT error number = 78
Stacktrace:
 [1] error(::String, ::Int32) at ./error.jl:42
 [2] gmt(::String) at /Users/t/.julia/packages/GMT/fKV5i/src/gmt_main.jl:241
 [3] #gmtend#45 at /Users/t/.julia/packages/GMT/fKV5i/src/gmtbegin.jl:32 [inlined]
 [4] gmtend at /Users/t/.julia/packages/GMT/fKV5i/src/gmtbegin.jl:29 [inlined] (repeats 2 times)

code can reproduce the problem is given below. Please save it as a jl file (e.g., test.jl) and run julia test.jl. At the first time it will be OK but if you open another terminal and run julia test.jl again before the first one finish. The error above will raise by the first process. If you then open any another session, the second will crash as when it started the first one crashed.

using GMT

function plot_one(figname)
    @show figname
    gmtbegin()
    gmtfig(figname, fmt = "png")
    rect = [2 2; 2 6; 6 6; 6 2; 2 2];
    plot(rect, region = [0 10 0 10], lw = 1, fill = :blue, axis = :a, )
    gmtend()
end

function plot_all(path_root)
    isdir(path_root) || mkpath(path_root)
    for i in 1:100
        
        plot_one(joinpath(path_root, string(i)))
    end
end

function test()

    p = "only_tmp1"
    if !isdir(p) 
        plot_all(p)
        return
    else
        p = "only_tmp2"
        if isdir(p) 
            @warn "may need to rm only_tmp directories"
            return
        end
        plot_all(p)GMT.jl will crash if I run two sessions (`gmtbegin()`, `gmtend()`) at one  time. Code is proved in the end.

The plotting is not problem if I only open one session. But if I open another session which is very common when someone needs to deal with a lot of data, the first one will crash giving the error:

psconvert [ERROR]: Failed to truncate file /Users/t/.gmt/sessions/gmt6.1685/gmt_1.ps- (via truncate) back to 22644 bytes
end [ERROR]: Failed to call psconvert
end [ERROR]: process_figures returned error 78
end [ERROR]: No directory named /Users/t/.gmt/sessions/gmt6.1685
ERROR: LoadError: Something went wrong when calling the module. GMT error number = 78
Stacktrace:
[1] error(::String, ::Int32) at ./error.jl:42
[2] gmt(::String) at /Users/t/.julia/packages/GMT/fKV5i/src/gmt_main.jl:241
[3] #gmtend#45 at /Users/t/.julia/packages/GMT/fKV5i/src/gmtbegin.jl:32 [inlined]
[4] gmtend at /Users/t/.julia/packages/GMT/fKV5i/src/gmtbegin.jl:29 [inlined] (repeats 2 times)



code can reproduce the problem is given below. Please save it as a jl file (e.g., test.jl) and run `julia test.jl`. At the first time it will be OK but if you open another terminal and run `julia  test.jl` again before the first one finishes. The error above will rise by the first process.

using GMT

function plot_one(figname)
@show figname
gmtbegin()
gmtfig(figname, fmt = "png")
rect = [2 2; 2 6; 6 6; 6 2; 2 2];
plot(rect, region = [0 10 0 10], lw = 1, fill = :blue, axis = :a, )
gmtend()
end

function plot_all(path_root)
isdir(path_root) || mkpath(path_root)
for i in 1:100

    plot_one(joinpath(path_root, string(i)))
end

end

function test()

p = "only_tmp1"
if !isdir(p) 
    plot_all(p)
    return
else
    p = "only_tmp2"
    if isdir(p) 
        @warn "may need to rm only_tmp directories"
        return
    end
    plot_all(p)
end

end
test()


I think it may be related to some  `global` variables? The second one will delete all sessions directories in `~/.gmt` even if the sessions were not started by the current process. I personally think it is not very reasonable.
    end
    
end
test()

I think it may related to some global variable? The second one will delete all sessions directories in ~/.gmt even if the sessions were not started by current process. I personally think it is not very reasonable.

@joa-quim
Copy link
Member

joa-quim commented Jun 9, 2020

The responsible is this line
https://github.com/GenericMappingTools/GMT.jl/blob/master/src/GMT.jl#L178
I added it because I was having troubles with sessions left overs when some modern mode script screwed but did not think that people would want to launch several different julia sessions.

@htyeim
Copy link
Contributor Author

htyeim commented Jun 9, 2020

Is it run(`gmt clear sessions`) L173 or FMT[1] = ENV["JULIA_GMT_IMGFMT"] L178?

I think it might be common to use different sessions at one time. For example I have three simulation results need to plot. Each contain the density and temperature of 8 ions species and 7 neutral species at ~2000 time points.
For each species at each time I need to plot a figure as below:

image

Then use VideoIO.jl to combine all the figures into one movie:

It uses contour which is very slow (~0.1 s for one, the whole time would be hours), so I would like to plot three models at the same time (manually parallel computation...).

I think it might be a solution that clear only removes sessions with last modify datetime before current time minus 1 day (or 1 hour or so)?

Another problem is contour seems not accept -jf option which shows in https://www.generic-mapping-tools.org/GMT.jl/latest/common_opts/#Spherical-distance-1 and https://docs.generic-mapping-tools.org/latest/contour.html#units.

@joa-quim
Copy link
Member

joa-quim commented Jun 9, 2020

Sorry, your are right, it's line L173
Comment it out for now. Don't know if I have choice to delete by time tag
I'll look for -the -jf but have students exams to grade.

@htyeim
Copy link
Contributor Author

htyeim commented Jun 9, 2020

No problem. I think the sessions are cleared by gmt not GMT.jl so time tag might need to be checked in gmt? I will try to found a way using GMT.jl.
I was trying to speed up contour then found -jf. But it might not be relevant so it's not necessary to check now.

@joa-quim
Copy link
Member

joa-quim commented Jun 9, 2020

Just a quick thought, no confirmed with docs. contour can accept a mesh of Delaunay triangulations, so if your data is always at same positions no need to recompute the triangulation every time.

@htyeim
Copy link
Contributor Author

htyeim commented Jun 9, 2020

The grid is defined by the model and the data is different at each time. Can it speed up this kind of process? I think it's a good idea. To mesh the data outside contour using other packages that is fast than that inside contour. But I don't know the Delaunay triangulations actually...

@joa-quim
Copy link
Member

joa-quim commented Jun 9, 2020

For sure the triangulation done by contour is the same as that of triangulate (that allows you to save the triangulation network). The idea is not to find a faster program, but to reuse the network which will be computed only once.

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

No branches or pull requests

2 participants