-
Notifications
You must be signed in to change notification settings - Fork 130
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
Added data-structure WeakKeyIdDict #1872
Conversation
Thank you very much! This looks very good to me! Unfortunately, the tests fail. And it looks like what you added seems to really interfere with some other internals. On a first glance, I do not see what exactly is going on, but with the help of those people whose code has been broken here, we will manage. Other than that: @fingolfin, @thofma : Do you agree on the places where the files and include statements have been put? |
Yeah, that looks like a pretty weird error. There seems to be some odd interaction occurring between the WeakKeyDicts in Hecke and this here... In https://github.com/mauro3/Oscar.jl/tree/m3/weakkeyid-dict-error there is a slightly more minimal reproducer. The line Not sure, but might be a Julia bug... |
I checked out this pr on my local machine (running on julia 1.8.3). To me it looked like the error occured in line 58 (not 54) of I have to say, though, that I added the two lines @show L.weak_vertices_rev[k]
@show typeof(L.weak_vertices_rev[k]) just before the assertion in line 461 of But removing the two lines again does not seem to affect the tests (apart from printing stuff): They are still running for me. Edit: In order to add those two lines, I had to do |
Calling
so I had to execute Then, I was starting up Oscar on my local branch with this PR and |
@thofma : Could you have a look at the tests? I was talking with @fieker today since @simonbrandhorst suggested that this might have been his code that's producing the trouble here. But @fieker said, it would have been most likely you. Can you explain why the |
When I wrote that code I was not too familiar with the GC. There is probably some lock missing, but the code is a bit complicated. It is the end of the term so I am a bit short on time. Once the term is over, I can say/do more. |
Ok. Thanks for having a look! Let's just not forget about this. |
Also note, there is at least one bug in the PR as it stands: when a key gets GC'ed then the dict-entry is not dropped but lingers as a "nothing" key. I can look into fixing this, if interest is around. |
Is this based on the code of |
Based on code from 2018, see "History" in the first post. |
e1dec88
to
2516363
Compare
I released a new Hecke with a fix and rebased this PR here. This seems to have fixed the problem. There are now new exciting errors with segmentation faults (https://github.com/oscar-system/Oscar.jl/actions/runs/4191718023/jobs/7267185929). |
Thank you very much for this! Unfortunately, I will be gone for some weeks now and don't have time look into this. But I shall get back to it! |
Actually, we could use this in Nemo and perhaps even in AA. So, I wonder, why not add it to AA, next to our |
I like it! |
Did this discussion already move to Nemo/AA, then? |
No, nothing has changed since my comment here: #1872 (comment). (Not quite true. There is now also a merge conflict.) |
2516363
to
2ba00d2
Compare
I tried again and the current version seems to work well now for the particular setting I have in mind. Here's some sample code: using Test
wkd = WeakKeyDict{AbsSpec, MatrixElem}()
P, _ = QQ["x", "y", "z"]
X = Spec(P)
U = hypersurface_complement(X, P[1])
wkd[X] = P[one(P); P[1]]
wkd[U] = OO(U)[one(OO(U)); gens(OO(U))[1]]
@test haskey(wkd, X)
@test haskey(wkd, U)
U = hypersurface_complement(X, P[1]) # override U
GC.gc() # Call the garbage collector
@test length(keys(wkd)) == 1
X = Spec(P) # override X
U = hypersurface_complement(X, P[1]) # override U again as the previous one still had a reference to the original X
GC.gc() # Call the garbage collector
@test isempty(keys(wkd)) Edit: Sorry, my bad. I was using |
Here's a new chunk of code against which we can measure: using Test
wkd = Oscar.WeakKeyIdDict{AbsSpec, MatrixElem}()
P, _ = QQ["x", "y", "z"]
X = Spec(P)
U = hypersurface_complement(X, P[1])
wkd[X] = P[one(P); P[1]]
wkd[U] = OO(U)[one(OO(U)); gens(OO(U))[1]]
@test haskey(wkd, X)
@test haskey(wkd, U)
### Delete only one key
U = hypersurface_complement(X, P[1]) # override U
@test !haskey(wkd, U) # check that `==` is not used.
GC.gc() # Call the garbage collector
@test length(keys(wkd)) == 1 # Throws an error: The number of stored keys is 2.
wkd[X] # Does not finish because of some internal lock.
wkd # Throws a typeassert error. If I remember correctly, the key `X` was just
# replaced by `nothing` of type `Nothing` instead of being garbage collected.
# However, I can not reproduce this error right now.
### Delete all keys
X = Spec(P) # override X
U = hypersurface_complement(X, P[1]) # override U again as the previous one still had a reference to the original X
GC.gc() # Call the garbage collector
@test isempty(keys(wkd)) It still produces several errors as annotated above. |
7113b83
to
ece6153
Compare
I have just rebased this (but did not change anything otherwise). I'll now sync it up with change made to |
@mauro3 I've updated this implementation to match the latest Let's see how it fares... We still may want to move this to |
The example by @HechtiDerLachs still fails, there's clearly a bug there:
I'll look into it. |
This should fix various GC issues, and ensure feature parity
017e2c9
to
e0e8747
Compare
Ah, fixed. I forgot |
Codecov Report
@@ Coverage Diff @@
## master #1872 +/- ##
==========================================
- Coverage 73.39% 73.36% -0.04%
==========================================
Files 451 452 +1
Lines 64172 64382 +210
==========================================
+ Hits 47098 47232 +134
- Misses 17074 17150 +76
📢 Thoughts on this report? Let us know!. |
Nice, all tests pass (at least the ones that pass elsewhere; Julia nightly and 1.10 are as broken as ever). I'll open a PR for AbstractAlgebra then. |
|
As discussed with @HechtiDerLachs over email, here the PR for adding
WeakKeyIdDict
s. Feel free to tweak it.History: This originated in JuliaLang/julia#28161 and transitioned to JuliaLang/julia#28182. Then subsequently I de-coupled it from Julia and made a PR in DataStructures.jl JuliaCollections/DataStructures.jl#402, which thus far has not been merged either.