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

property GKZ_VECTOR not created as expected #311

Open
kalmarek opened this issue Jul 28, 2020 · 6 comments
Open

property GKZ_VECTOR not created as expected #311

kalmarek opened this issue Jul 28, 2020 · 6 comments

Comments

@kalmarek
Copy link
Contributor

there is a title, but I don't think it's related to GKZ_VECTOR...

for i in 1:100
@info i
let n = 5

    c = polytope.cube(n)
    pts = Matrix{Rational{BigInt}}(c.VERTICES);
   
    for i in n+1:size(pts, 1)
        let sub_pts = pts[1:i, :]
        
            try
                pc = polytope.PointConfiguration(POINTS=sub_pts)
                pc.TRIANGULATION

                gkz = pc.TRIANGULATION.GKZ_VECTOR
            catch ex
                @error "at i = $i exception was thrown:" ex
            end                
        end
    end    
end;
end

non-deterministically (hence the outer loop) shows:

┌ Error: at i = 17 exception was thrown:
│   ex =
│    Exception occured at Polymake side:
│    property GKZ_VECTOR not created as expected at /home/kalmar/.julia/dev/Polymake/deps/usr/share/polymake/perllib/Polymake/Core/BigObject.pm line 1559.
│    
└ @ Main /tmp/placing.jl:18

to my complete chagrin shifting pc = polytope.PointConfiguration(POINTS=sub_pts) out of the try ... catch ... end block "fixes" the issue....

(the issue is even more pronounced for n=6)

@saschatimme
Copy link
Collaborator

saschatimme commented Jul 29, 2020

Maybe something related to pc being freed? Note that the scoping rules for try block are such that pc is not accessible outside the try block.

@benlorenz
Copy link
Member

GC.@preserve pc begin
   gkz = pc.TRIANGULATION.GKZ_VECTOR
end

does help here, so I think pc is freed before the gkz computation is done. According to some extra debug statements I added polymake suddenly sees pc.TRIANGULATION as a generic simplicial complex instead of a triangulation subobject, but for this generic object the GKZ vector does not make sense anymore and cannot be created.

Inside polymake $object->type->full_name changes from
GeometricSimplicialComplex<Rational> as PointConfiguration<Rational>::TRIANGULATION
to
GeometricSimplicialComplex<Rational>
because the parent object is removed and a subobject alone will not keep its parent alive.

@saschatimme
Copy link
Collaborator

But does this maybe point to a general problem with our Julia bindings? Should we add internally a GC.@preserve to every property lookup?

@benlorenz
Copy link
Member

In some sense one can produce the change from triangulation to generic object also in the polymake shell but not within one statement, so the error cannot appear there.

Adding a GC.@preserve might not even help as this would only preserve pc during the lookup for TRIANGULATION, and preserve the pc.TRIANGULATION object during the GKZ_VECTOR lookup, but we would need to preserve pc for the second lookup. I don't really see how that could be done ...

@kalmarek
Copy link
Contributor Author

kalmarek commented Aug 5, 2020

@benlorenz thanks for looking into this!
I'd just document this bug/feature as a design decision.
Even in julia access to subfield must be GC.@preserved when the validity of the subfield depends on the lifetime of parent struct. We've seen exactly the same issue in #225 / #293 btw.

@benlorenz
Copy link
Member

We should add a note about this in the documentation.

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

3 participants