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

Infinite recursion calling loadmesh with a non AbstractMeshKey #72

Closed
quffaro opened this issue Mar 5, 2024 · 11 comments
Closed

Infinite recursion calling loadmesh with a non AbstractMeshKey #72

quffaro opened this issue Mar 5, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@quffaro
Copy link
Contributor

quffaro commented Mar 5, 2024

dset = DeltaSet1D()
add_vertices!(dset, 1)
dset |> loadmesh

This code will produce an error

Stacktrace:
     [1] loadmesh(s::DeltaSet1D, subdivision::Circumcenter)
       @ CombinatorialSpaces.Meshes ~/.julia/packages/CombinatorialSpaces/Wg7wx/src/Meshes.jl:74--- the last 1 lines are repeated 79982 more times ---

This occurs because loadmesh will call subdivide_duals!(loadmesh(s), subdivision), and iterate.

I imagine there should be some way to eyeball whether this will recurse. I'm willing to assign this to myself.

@lukem12345
Copy link
Member

Hi, which version of loadmesh is this calling? Can you please do @which? This function is not meant to be used this way.

@quffaro
Copy link
Contributor Author

quffaro commented Mar 5, 2024

It's calling it here:

loadmesh(s)
     @ CombinatorialSpaces.Meshes ~/.julia/packages/CombinatorialSpaces/Wg7wx/src/Meshes.jl:74

@lukem12345
Copy link
Member

Ok. It seems that there are two issues here. The typing on loadmesh should not allow this usage.

@quffaro
Copy link
Contributor Author

quffaro commented Mar 5, 2024

Is it possible to distinguish at the type level "bad" objects from "good" ones so we could just overload loadmesh, or should there be code which checks for recursive badness (and throws an error?)?

@jpfairbanks
Copy link
Member

jpfairbanks commented Mar 5, 2024

It is this fallback method here.

This should have a generic type like AbstractMeshIdentifier that has concrete subtypes for all our existing meshes so that the fallback method isn't defined for Any. Then we could do

loadmesh(m::AbstractDeltaSet) = m so that loadmesh is idempotent.

@lukem12345
Copy link
Member

Yes this should subtype AbstractMeshKey. The name "load" was originally chosen because we were literally loading a mesh from a zip file (i.e. Artifacts). What Matt wants is a helper function that takes a primal mesh, creates a dual mesh, and subdivides it.

@lukem12345
Copy link
Member

lukem12345 commented Mar 5, 2024

If we add the functionality that you suggested James, we should not keep calling this function loadmesh, because this falls into classic object-oriented naming scheme badness. Besides it being now misleadingly tied to a particular way that an object lives in memory.

It would be more Julian methinks to just overload EmbeddedDeltaDualComplex2D at this point.

@lukem12345
Copy link
Member

But currently EmbeddedDeltaDualComplex2D already does this for a given EmbeddedDeltaSet2D. It just doesn't subdivide it in the same step. We could just do that, subdividing either Circumcentrically, Barycentrically, or None. And pick either circum. or bary. as default.

1 similar comment
@lukem12345
Copy link
Member

But currently EmbeddedDeltaDualComplex2D already does this for a given EmbeddedDeltaSet2D. It just doesn't subdivide it in the same step. We could just do that, subdividing either Circumcentrically, Barycentrically, or None. And pick either circum. or bary. as default.

@lukem12345
Copy link
Member

@quffaro Please add minimal reproducible code that demonstrates this behavior by calling EmbeddedDeltaDualComplex1D and subdivide_duals!, not using the loadmesh function.

@quffaro
Copy link
Contributor Author

quffaro commented Mar 5, 2024

Affirmative!

Point3D = GeometryBasics.Point3{Float64}
primal=EmbeddedDeltaSet1D{Bool, Point3D}()
add_vertices!(primal, 5, point=[Point3D(i, i^2, 0) for i in -2:2])
add_edges!(primal, 1:4, 2:5, edge_orientation=true)

ds=EmbeddedDeltaDualComplex1D{Bool, Float64, Point3D}(primal)
subdivide_duals!(ds, Barycenter()) 

dss = copy(ds)
subdivide_duals!(dss, Barycenter())

dss==ds

@epatters epatters added the bug Something isn't working label Mar 5, 2024
@lukem12345 lukem12345 changed the title StackOverflowError when subdividing DeltaSet1D with one vertex Infinite recursion calling loadmesh with a non AbstractMeshKey Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants