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

Minimal associated primes #3705

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

HechtiDerLachs
Copy link
Collaborator

An attempt to make the specialized functionality in Singular for zero dimensional ideals available.

This seemed to be useful for @simonbrandhorst in some examples, but now I can't even get the tests to terminate. Let's see what the CI says.

@wdecker : The documentation reads as if only QQ was allowed as a coefficient ring. Do you remember whether this is the case? Because it seems to have run also over number fields.

@HechtiDerLachs HechtiDerLachs marked this pull request as draft May 8, 2024 12:12
@HechtiDerLachs
Copy link
Collaborator Author

@ederc : Could you have a look at the tests? I don't understand what's going wrong. But maybe minimal_primes now called singular_generators before and that lead to some false caching?

@simonbrandhorst
Copy link
Collaborator

Thanks for wrapping this @HechtiDerLachs !

@ederc
Copy link
Member

ederc commented May 8, 2024

Well, the tests fail because you try to apply assPrimes from Singular on a zero dimensional ideal over a finite field, but assPrimes assumes that the ideal lives over QQ. AFAIK there is a modular std call behind the scenes in assPrimes.

@HechtiDerLachs
Copy link
Collaborator Author

The problem I meant occured in an earlier test run. Some call to dim was complaining that singular_groebner_generators did not return a groebner basis. But it doesn't seem to be reproduced anymore; sorry for calling you.

But what you say about minAss is good to know. I will restrict the cases where it's called.

@HechtiDerLachs
Copy link
Collaborator Author

@ederc : Now the error is back, see this test.

@ederc
Copy link
Member

ederc commented May 9, 2024

There was a missing caching of the isGB flag if a GB was computed during small_generating_set. I pushed a fix to your branch.

@simonbrandhorst
Copy link
Collaborator

is there anything holding this PR up @HechtiDerLachs ?

@HechtiDerLachs
Copy link
Collaborator Author

The tests were still failing. I just had a look and it seems there is another bug in minimal_primes (due to me, unfortunately). I will have a look.

@HechtiDerLachs
Copy link
Collaborator Author

@ederc : I'm sorry, but it looks like I accidentally overwrote your fixes to this branch when doing a rebase. Do you still have them somewhere? If yes, could you push them here again? Thx!

@ederc
Copy link
Member

ederc commented Jun 29, 2024

I do not have this code anymore, we need to look again where the isGB flag needs to be set.

@benlorenz
Copy link
Member

@ederc : I'm sorry, but it looks like I accidentally overwrote your fixes to this branch when doing a rebase. Do you still have them somewhere? If yes, could you push them here again? Thx!

The Github UI shows HechtiDerLachs force-pushed the minimal_associated_primes branch from 9aa5177 to 2cd696e, and clicking on that 9aa5177 commit should get you to the last commit before the force push, and the history is also available. With that commit hash known you can also try doing git log 9aa5177 locally since git will keep lost commits for a few days.
You could also look through git reflog locally.

@ederc
Copy link
Member

ederc commented Jun 30, 2024

@HechtiDerLachs Caching isGB is back in.

@HechtiDerLachs
Copy link
Collaborator Author

HechtiDerLachs commented Jun 30, 2024

Thanks a lot @ederc and @benlorenz ! I was hoping that something like this was possible, but didn't know how.

Unfortunately it seems that a lot of tests time out. Or something else goes wrong which I do not fully understand, yet.

Edit: I checked two of the failing tests locally around the point where they were cancelled and they run just fine on my machine.

Copy link

codecov bot commented Jul 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.48%. Comparing base (020e83a) to head (1d68e74).
Report is 19 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3705      +/-   ##
==========================================
- Coverage   84.59%   84.48%   -0.12%     
==========================================
  Files         631      641      +10     
  Lines       85085    85440     +355     
==========================================
+ Hits        71981    72181     +200     
- Misses      13104    13259     +155     
Files with missing lines Coverage Δ
src/Rings/mpoly-ideals.jl 94.19% <100.00%> (+0.31%) ⬆️

... and 40 files with indirect coverage changes

@HechtiDerLachs
Copy link
Collaborator Author

I really can't make sense of the failing tests. Everything that I tried on my local machine about things where the CI gets stuck really goes through for me. And in some cases I can't even find the error messages.

@HechtiDerLachs HechtiDerLachs marked this pull request as ready for review July 1, 2024 09:01
@fingolfin
Copy link
Member

Triage talked about it yesterday and we suspect that it's the same problem as in #3905 i.e. Singular tries to start subprocesses and gets stuck. So hopefully @hannes14 can take a look when he's back from vacation.

@fieker
Copy link
Contributor

fieker commented Aug 28, 2024

Its still under Hans aegis:

  • it is fixed (in Singular)
  • it needs the release cascade
  • (maybe)

@fingolfin
Copy link
Member

The atexit related crashes are fixed in @hannes14 most recent update from last week. But there are still errors / crashes, just again different ones

@benlorenz
Copy link
Member

There are still exit handlers running

│    Can't call method "flags" on an undefined value at /Users/aaruni/Desktop/oscar-runners/runner-2/julia-depot/scratchspaces/d720cf60-89b5-51f5-aff5-213f193123e7/polymake_6360604600323823479_1.10_depstree_v2/share/polymake/perllib/Polymake/Core/BigObject.pm line 1247 during global destruction.

which I think is problematic. But at least I don't see any stuck jobs that ran into a timeout.

Many of the failing jobs don't have any logs for the Run tests step, some show an exit code of 143 (sigterm) which might indicate the workers running out of memory? (due to multiple processes?)

@fingolfin
Copy link
Member

@hannes14 so I guess that ball is in your court again ;-).

Out of curiosity, how does Singular determine how many processes to fork? Does it take the number of cores and/or RAM into account?

@hannes14
Copy link
Member

Singular uses sysconf(_SC_NPROCESSORS_ONLN) resp. sysconf(_SC_NPROCESSORS_CONF),
RAM is not considered

result = typeof(I)[]
# `unique!` does not work for lists of ideals. I don't know why, but for the moment we need the
# following workaround.
for p in filter!(!is_one, vcat([minimal_primes(j; algorithm, factor_generators=false) for j in J]...))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for p in filter!(!is_one, vcat([minimal_primes(j; algorithm, factor_generators=false) for j in J]...))
for p in filter!(!is_one, reduce(vcat, [minimal_primes(j; algorithm, factor_generators=false) for j in J]))

Comment on lines 1213 to 1219
unique_comp = typeof(I)[]
for q in J
is_one(q) && continue
q in unique_comp && continue
push!(unique_comp, q)
end
J = unique_comp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HechtiDerLachs I resolved the merge conflicts -- I hope I didn't screw that up too badly...

@fingolfin
Copy link
Member

Tests pass now, but test/AlgebraicGeometry/Schemes/Resolution_structure.jl in Julia 1.10 went from ~64 seconds to ~370 seconds

unique_comp = typeof(I)[]
for q in J
is_one(q) && continue
q in unique_comp && continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This compares ideals, won't that trigger additional GB computations and thus be slow in general?? Maybe you just want to remove "obviously" identical ideals (with generators lists being the same, up to reordering?)

Copy link
Collaborator

@afkafkafk13 afkafkafk13 Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fingolfin : is_one(q) triggers a GB computation, but (at least hopefully) the ideal membership test in 1240 will use those GB from the prior runs of the loop for the comparison.

I rather wonder whether the factorization in Oscar is so much superior that it does not make sense to do a facstd of J in Singular and then go on with the components from there.

Edit: If it is about working over field extensions, I understand the point.

@@ -1126,6 +1126,12 @@ julia> L = minimal_primes(I)
function minimal_primes(I::MPolyIdeal; algorithm::Symbol = :GTZ, cache::Bool=true)
has_attribute(I, :minimal_primes) && return get_attribute(I, :minimal_primes)::Vector{typeof(I)}
R = base_ring(I)
if coefficient_ring(R) isa QQField && is_zero(dim(I))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dim(I) triggers a GB computation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triage suggest this would perhaps make sense with is_known_to_be_zero_dimensional(I) check -- i.e. if we know this information, we can call the 0-dim method.

But otherwise, leave it singular -- if it detects the 0-dim case it still handles it well.

@simonbrandhorst
Copy link
Collaborator

I can confirm that the test timings go up. The reason was not the call to dim but that
Singular.LibAssprimeszerodim.assPrimes was slower in all cases I could produce.

Here is an example.

julia> R, (x, y) = polynomial_ring(QQ, [:x, :y])
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])

julia> I = ideal(R,[x^5*y - 2*x^4*y^2 - 2*x^4*y + x^3*y^3 + 2*x^3*y^2 - x^2*y^3 + 2*x^2*y^2 + 2*x^2*y + 2*x*y^4 + x*y^3 - 2*x*y^2 - x*y - y^5 - 2*y^4 - y^3, x^6 - 2*x^5 - 3*x^4*y^2 - 2*x^4*y + 2*x^3*y^3 + 3*x^3*y^2 + 2*x^3*y + 2*x^3 + 5*x^2*y^2 + 2*x^2*y - x^2 + 3*x*y^4 - 5*x*y^2 - 2*x*y - 2*y^5 - 4*y^4 - 2*y^3, x^7 + y^3 - 6]
       )
Ideal generated by
  x^5*y - 2*x^4*y^2 - 2*x^4*y + x^3*y^3 + 2*x^3*y^2 - x^2*y^3 + 2*x^2*y^2 + 2*x^
  2*y + 2*x*y^4 + x*y^3 - 2*x*y^2 - x*y - y^5 - 2*y^4 - y^3
  x^6 - 2*x^5 - 3*x^4*y^2 - 2*x^4*y + 2*x^3*y^3 + 3*x^3*y^2 + 2*x^3*y + 2*x^3 + 
  5*x^2*y^2 + 2*x^2*y - x^2 + 3*x*y^4 - 5*x*y^2 - 2*x*y - 2*y^5 - 4*y^4 - 2*y^3
  x^7 + y^3 - 6

julia> @time minimal_primes(I)
  0.031095 seconds (54.79 k allocations: 1.706 MiB)
2-element Vector{MPolyIdeal{QQMPolyRingElem}}:
 Ideal with 2 generators
 Ideal (y^7 + 7*y^6 + 21*y^5 + 35*y^4 + 36*y^3 + 21*y^2 + 7*y - 5, x - y - 1)

julia> @time Oscar.minimal_primes_zero_dim(I)
 20.402501 seconds (108.43 k allocations: 1.781 MiB)
2-element Vector{MPolyIdeal{QQMPolyRingElem}}:
 Ideal with 5 generators
 Ideal with 5 generators

julia> dim(I)
0

Therefore it should not be the default algorithm. Maybe there exists input where it is faster. I do not know.
do you ? @hannes14
Since this PR also contains some fixes, I suggest to move forward with it.

Copy link
Collaborator

@afkafkafk13 afkafkafk13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two bug fixes make sense.

The benefit of the new method is rather limited and seems to rely on Singular's parallization via modular.lib. Hence we should at least inform the user that this is using a modular approach. -- minor change, but approval has to wait for it.

Comment on lines 1180 to 1181
Calls a specialized variant of `minimal_primes` for zero dimensional ideals
with coefficient ring over the rationals.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Calls a specialized variant of `minimal_primes` for zero dimensional ideals
with coefficient ring over the rationals.
Calls a specialized modular variant of `minimal_primes` for zero dimensional ideals
with coefficient ring over the rationals.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should one take away from this additional information? That the result may not be correct anymore? Consider me a user/developer, who stumbles upon this method and reads the docstring.

Copy link
Collaborator

@afkafkafk13 afkafkafk13 Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any better hint for the knowledgable user that there is a modular approach and Singular-level parallelization going on in the background is welcome -- but it needs to be of a kind that does not disturb the average user.

(I might not even have included this function into the list of exported commands -- i.e. put a _ in front of it --, if it had been my choice.... It is very often significantly inferior to the usual method from primdec.lib concerning time consumption due to the overhead.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can already not understand why I should write specialized here. This alone gives no information. Specialized modular is even more confusing. Two comments:

  1. This Singular function comes with final tests (depending on the value). I will check asap what precisely these checks are doing and whether they guarantee correctness (correctness in some cases).
  2. As we will more and more rely on modular GB based methods, we should develop a general philosophy of telling the truth to the user. In contrast to Magma, we should not cheat here.

With respect to this PR, let us decide on how to handle this as soon as I have checked what the tests do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed the word specialized should be deleted, whereas I would keep modular.

I strongly second the need for a general philosophy as stated in 2. .

W.r.t. this PR: What we definitely need are the two bug fixes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I removed specialized and added modular.

So far I did not export the function because I could not determine a clear use-case for it.

@fieker
Copy link
Contributor

fieker commented Nov 5, 2024

My 2 pennies:

  • adding modular is pointless as no-one outside knows what this implies. Maybe call it Las Vegas/ Monte Carlo/ .. whatever to indicate that is is not guarateed correct.
  • any function in Singular that is using Singular parallelization, at this point in time, cannot be used in Oscar reliably. Thus I'd question the point of linking them in. It needs structural changes in Singular before they can be used at all. This is under discussion. Even the feasibility is not clear yet. Unfortunately.

@wdecker
Copy link
Collaborator

wdecker commented Nov 5, 2024 via email

@jankoboehm
Copy link
Contributor

jankoboehm commented Nov 6, 2024

My two pennies: We have to separate three different issues here:

modular or not:
modular is just an algorithmic option to the command and there should always be a non-modular version if possible (since modular in general is not for all inputs faster).

verification:
If modular, one should be able to turn verfication on/off via an algorithmic option to the command or via a global "physics/science" mode, or both. As standard, verification has to be on.

resources:
Even on one core modular can be for some algorithms much faster that non-modular. We should enhance Singular (i.e. tasks.lib, resources.lib, parallel.lib) with a special case so that it does not fork if we use a single core. This does not harm even if the forking works smoothly eventually.

@afkafkafk13
Copy link
Collaborator

afkafkafk13 commented Nov 6, 2024

My two pennies: We have to separate three different issues here:

modular or not: modular is just an algorithmic option to the command and there should always be a non-modular version if possible (since modular in general is not for all inputs faster).

This was, what I had in mind: Be frank about this being a modular method (as opposed to the non-modular approach in primdec.lib).

verification: If modular, one should be able to turn verfication on/off via an algorithmic option to the command or via a global "physics/science" mode, or both. As standard, verification has to be on.

Here the tests are switched on by default, so this is indeed verified (and certifies correctness according to the underlying article of Idrees, Pfister, Steidel). But the Oscar-method in this PR currently does not provide the means to turn it off yet. Is it desired to be able to switch it off?

resources: Even on one core modular can be for some algorithms much faster that non-modular. We should enhance Singular (i.e. tasks.lib, resources.lib, parallel.lib) with a special case so that it does not fork if we use a single core. This does not harm even if the forking works smoothly eventually.

This is a valid point in general, but not of relevance here. The current PR is an instance where no parallelism is used at all in Singular and computation only passes through the modular command.
Edit: I take the last phrase back.

@afkafkafk13
Copy link
Collaborator

Please revert to draft for the moment. This touches on things that need to be checked/cleaned up in Singular before having this in Oscar.

@lgoettgens lgoettgens marked this pull request as draft November 6, 2024 12:09
@simonbrandhorst
Copy link
Collaborator

This should not delay the two bugfixes. I will remove the singular part from this PR and return to non-draft.

@afkafkafk13
Copy link
Collaborator

Splitting up this PR into the urgent part to be merged asap and the one touching on Singular is fine with me.

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

Successfully merging this pull request may close these issues.