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

Integrating JuLie into Oscar #1935

Merged
merged 62 commits into from
Mar 12, 2023
Merged

Conversation

ClaudiaHeYun
Copy link
Contributor

Three files from JuLie are included: partitions, schur_polynomials, tableaux. Their tests and documentations are included too. We stopped importing partitions from Hecke. Right now there is a problem with YoungTableau, which uses partitions from AbstractAlgebra. For example,

p = Partition([4,3,2])
yt = YoungTableau(p)

will create an error. This can be fixed by specifying p = AbstractAlgebra.general.Partition([4,3,2]). Eventually it would be nice to merge Tableau and YoungTableau.

ClaudiaHeYun and others added 30 commits February 2, 2023 16:20
Add section on optional arguments for parents of return values.
Add first file for documentation.
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

A couple more comments.

I will shortly push several commits to this PR to address some of my own remarks. Please make sure to pull before (force) pushing anything to this PR / branch, to avoid loosing my changes


@Markdown.doc """
schensted(sigma::Vector{Integer})
schensted(sigma::Perm{T})
Copy link
Member

Choose a reason for hiding this comment

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

Note that Perm{T} is from AbstractAlgebra, but we don't use it in OSCAR -- we have our own permutation type here, PermGroupElem

That permutation type definitely should be supported here and in other places taking permutations. (To be clear: I am OK with supporting Perm{T}, too, at least for now)

Copy link
Contributor

Choose a reason for hiding this comment

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

I find it debatable whether a permutation really needs to be an element of a group. I feel there should be both (a permutation as an element of a group and a permutation just by itself) as separate types.

But again, such discussions should not stop any of the real work.

Copy link
Member

Choose a reason for hiding this comment

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

Sure. And note that I did not ask for Perm{T} support to be dropped, but rather for support for PermGroupElem to be added, as that is the kind of permutation most OSCAR users will encounter.

But this is not a blocker for this PR.

experimental/JuLie/tableaux.jl Outdated Show resolved Hide resolved
experimental/JuLie/tableaux.jl Outdated Show resolved Hide resolved
experimental/JuLie.jl Outdated Show resolved Hide resolved
This allows for two different entry points for the ring `P` of the output:
Once as the first argument of a method of `characteristic_polynomial` with
an extended signature, and second as an optional keyword argument for `ring` in
the original method. This should be the general rule for such implementations
Copy link
Member

Choose a reason for hiding this comment

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

You are editing the OSCAR styleguide here. Either this is the general rule within OSCAR, or it isn't; the "should" makes no sense.

Whether this is the rule is debatable, though. Do we really want to force all code to offer both these variants? Why? I.e., why two ways to achieve the same thing?

Also, perhaps ring is not always the best name for the argument, and from the text it sounds this is mandatory.

Indeed, as far as I can tell, the "real" charpoly and minpoly do not support the keyword argument variant.

My recommendation: move this addition to the styleguide into a separate PR (it doesn't really belong into this PR anyway). That way, we can discuss it there, and don't hold up this PR here.

experimental/Experimental.jl Outdated Show resolved Hide resolved
experimental/JuLie/partitions.jl Outdated Show resolved Hide resolved


@Markdown.doc """
conjugate(lambda::Partition{T}) where T<:IntegerUnion
Copy link
Member

Choose a reason for hiding this comment

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

The following is a purely informal remark, I don't expect you to do anything about it:

Note that in Julia (and OSCAR) this is normally called conj. However, I've added a suggestion to #1826 that we should allow conjugate as a synonym for conj.

@fingolfin
Copy link
Member

IntegerUnion is the way to go. You always want to allow Integers since people type partitions(4) and not partitions(ZZRingElem(4)) or ZZ(4) However, programmantic, most functions in Oscar return ZZRingElem = fmpz, so they should be valid input

Ok. But if an fmpz becomes a loop variable (e.g., for i=1 to n when n::fmpz) this may be not so good.

If changing Integer to IntegerUnion allows a loop variable to become an ZZRingElem, then the code already allowed it to become a `BigInt, which is equally bad. There are various ways to address this, but of course it depends on the code.

E.g. if the code really only makes sense for small inputs (e.g. factorial(n) with n >= 2^64 is not something we can actually compute), then one can write code like this:

my_factorial(n::T) where T <: IntegerUnion = my_factorial(T, Int(n))
function my_factorial(::Type{T}, n::Int) where T <: IntegerUnion
  @req n >= 0 "n must be non-negative"
  x = T(1)
  for i in 1:n
    x = mul!(x, x, i)
  end
  return x
end

Anyways, such stuff shouldn't stop merging, can be adapted later.

Agreed

Comment on lines +289 to +296
julia> @btime partitions(Int8(90));
3.376 s (56634200 allocations: 6.24 GiB)

julia> @btime ascending_partitions(Int8(90),alg="ks");
3.395 s (56634200 allocations: 6.24 GiB)

julia> @btime ascending_partitions(Int8(90),alg="m");
3.451 s (56634200 allocations: 6.24 GiB)
Copy link
Member

Choose a reason for hiding this comment

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

Interesting! With which Julia version, OS and hardware did you obtain these benchmark results?

On my M1 MacBook with Julia 1.9.0-rc1, ascending_partitions is actually twice as fast as partitions:

julia> @btime partitions(Int8(90));
  8.959 s (56634195 allocations: 4.53 GiB)

julia> @btime ascending_partitions(Int8(90),alg="ks");
  4.546 s (56634195 allocations: 4.53 GiB)

julia> @btime ascending_partitions(Int8(90),alg="m");
  4.616 s (56634195 allocations: 4.53 GiB)

Copy link
Member

Choose a reason for hiding this comment

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

Oh! With Julia 1.8.5, it is much faster and looks more like your numbers:

julia> @btime partitions(Int8(90));
  2.123 s (56634195 allocations: 4.53 GiB)

julia> @btime ascending_partitions(Int8(90),alg="ks");
  2.478 s (56634195 allocations: 4.53 GiB)

julia> @btime ascending_partitions(Int8(90),alg="m");
  2.432 s (56634195 allocations: 4.53 GiB)

So there seems to be a major performance regression in Julia 1.9 :-(. Wonder if we can pinpoint it...

Copy link
Contributor

Choose a reason for hiding this comment

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

This is weird. I believe my old benchmarks were done even with Julia 1.7.

sequence (which is our convention), one can also encode it as an *ascending*
sequence. In the papers Kelleher & O'Sullivan (2014) and Merca (2012) it is
said that generating the list of all ascending partitions is more efficient
than generating descending ones. To test this, I have implemented the
Copy link
Member

Choose a reason for hiding this comment

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

This docstring uses "I" quite a bit: "I have", "I am", .... For an OSCAR user it won't be clear to whom that "I" refers. So we should rewrite it, either using "we"; or using "U. Thiel"

@ulthiel any preferences?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, this was my personal documentation, so of course I used "I". I don't know. It's maybe also not so important.

Copy link
Contributor

Choose a reason for hiding this comment

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

Noticing that the ascending_partitions stuff is in the pull request as well: I later changed this to ascending_compositions (which was part of my composition generator) because it's technically not a partition by definition. Since the composition stuff is currently not in the pull request (and not in JuLie) I'm unsure what should happen with this functionality. It should definitely be there eventually.

Copy link
Member

Choose a reason for hiding this comment

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

Of course it made perfect sense to use "I" while this was in JuLie, and I am not criticizing this. I am merely pointing out that it doesn't make sense anymore in the context of Oscar, because most readers won't know whom "I" refers to. Moreover, it differs from the style we used elsewhere. Hence it should be changed. I can easily change it now, of course, but as a courtesy I thought I'd ask you for your preferences...?

Regarding your second reply: Note that this is the docstring for ascending_partitions we are discussing here. So you are saying you renamed it later anyway, and moved it to some other module... So should we just delete it from this PR for now and it'll be added back later?



@Markdown.doc """
partitions(m::IntegerUnion, n::IntegerUnion, l1::IntegerUnion, l2::IntegerUnion; z=0)
Copy link
Member

Choose a reason for hiding this comment

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

The type for z here should match the declaration below


The algorithm used is "parta" in [RJ76](@cite), de-gotoed from old ALGOL code by E. Thiel!
"""
function partitions(m::IntegerUnion, n::IntegerUnion, l1::IntegerUnion, l2::IntegerUnion; z::IntegerUnion=0)
Copy link
Member

Choose a reason for hiding this comment

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

If z only allows for two choices, there is no point in allowing it to be IntegerUnion, it can go back to being Int.

However, why isn't this a Bool with a speaking name? E.g.

Suggested change
function partitions(m::IntegerUnion, n::IntegerUnion, l1::IntegerUnion, l2::IntegerUnion; z::IntegerUnion=0)
function partitions(m::IntegerUnion, n::IntegerUnion, l1::IntegerUnion, l2::IntegerUnion; only_distinct_parts::Bool = false)

Comment on lines +289 to +296
julia> @btime partitions(Int8(90));
3.376 s (56634200 allocations: 6.24 GiB)

julia> @btime ascending_partitions(Int8(90),alg="ks");
3.395 s (56634200 allocations: 6.24 GiB)

julia> @btime ascending_partitions(Int8(90),alg="m");
3.451 s (56634200 allocations: 6.24 GiB)
Copy link
Member

Choose a reason for hiding this comment

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

Oh! With Julia 1.8.5, it is much faster and looks more like your numbers:

julia> @btime partitions(Int8(90));
  2.123 s (56634195 allocations: 4.53 GiB)

julia> @btime ascending_partitions(Int8(90),alg="ks");
  2.478 s (56634195 allocations: 4.53 GiB)

julia> @btime ascending_partitions(Int8(90),alg="m");
  2.432 s (56634195 allocations: 4.53 GiB)

So there seems to be a major performance regression in Julia 1.9 :-(. Wonder if we can pinpoint it...

@fingolfin fingolfin closed this Mar 10, 2023
@fingolfin fingolfin reopened this Mar 10, 2023
@micjoswig
Copy link
Member

micjoswig commented Mar 11, 2023

It seems that the test (1.6, x64, ubuntu-latest) was killed only because some test cases took too long?

If you agree, merge this PR now. And create a new issue to reduce the time for testing. At the end of the test output the biggest offenders are listed. Add them explicitly to the new issue.

@fingolfin @benlorenz

@fingolfin
Copy link
Member

The tests of this PR are not slow, I already verified this.

I already spent some effort last week to clean up this PR and fix a bunch of issues with it. It's unfortunate that nobody else really had timte to carefully review this code.

The remaining blocker for me is the part where it changes the developer documentation. I will remove this now from the PR and adjust some more things. If someone wants to re-submit it in a separate PR, they are welcome, we can then discuss it there.

@fingolfin fingolfin enabled auto-merge (squash) March 12, 2023 18:27
@fingolfin fingolfin merged commit b36cc89 into oscar-system:master Mar 12, 2023
@joschmitt joschmitt mentioned this pull request Jan 9, 2024
12 tasks
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

Successfully merging this pull request may close these issues.

8 participants