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

Prefer symbols over strings as indeterminants #4158

Merged
merged 12 commits into from
Oct 7, 2024

Conversation

lgoettgens
Copy link
Member

@lgoettgens lgoettgens commented Sep 27, 2024

@lkastner @HereAround could you have a look if the attributes coordinate_names and coordinate_names_of_torus in the toric varieties could be changed to Vector{Symbol} instead of Vector{String} to reduce the allocations from copying this around and passing it to polynomial_ring etc? (moved to #4159)

@lgoettgens
Copy link
Member Author

@benlorenz is this failure something similar to what you work around in #4153 or is a genuine failure?

alternative inputs: Test Failed at /Users/aaruni/Desktop/oscar-runners/runner-1/_work/Oscar.jl/Oscar.jl/test/PolyhedralGeometry/subdivision_of_points.jl:17
 Expression: collect(maximal_cells(square_by_incidence)) == collect(maximal_cells(square_by_weights))
 Evaluated: [[1, 2, 3], [2, 3, 4]] == [[2, 3, 4], [1, 2, 3]]

https://github.com/oscar-system/Oscar.jl/actions/runs/11072577996/job/30767135768?pr=4158#step:9:1856

@@ -61,7 +61,7 @@ function global_tate_model(base::NormalToricVariety,
vs2 = collect(keys(defining_section_parametrization))
@req all(in(["a1", "a2", "a3", "a4", "a6"]), vs2) "Only the Tate sections a1, a2, a3, a4, a6 must be parametrized"

gens_base_names = [string(g) for g in gens(cox_ring(base))]
gens_base_names = [string(g) for g in symbols(cox_ring(base))]
Copy link
Member Author

Choose a reason for hiding this comment

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

@HereAround pinging you to make you aware that symbols(::MPolyRing) exists. In many of these cases you probably don't even need to convert to strings afterwards, but I kept it like this if I didn't see an obvious way to change the below code

Copy link
Member

Choose a reason for hiding this comment

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

Actually in this particular case it seems straightforward, as the only place using this seems to be the next line?

@benlorenz
Copy link
Member

@benlorenz is this failure something similar to what you work around in #4153 or is a genuine failure?

alternative inputs: Test Failed at /Users/aaruni/Desktop/oscar-runners/runner-1/_work/Oscar.jl/Oscar.jl/test/PolyhedralGeometry/subdivision_of_points.jl:17
 Expression: collect(maximal_cells(square_by_incidence)) == collect(maximal_cells(square_by_weights))
 Evaluated: [[1, 2, 3], [2, 3, 4]] == [[2, 3, 4], [1, 2, 3]]

oscar-system/Oscar.jl/actions/runs/11072577996/job/30767135768?pr=4158#step:9:1856

I only noticed (and now fixed) those in polyhedron.jl so far but this is similar and I will do another PR soon.

@test collect(maximal_cells(square_by_incidence)) ==
collect(maximal_cells(square_by_weights))
@test issetequal(collect(maximal_cells(square_by_incidence)),
collect(maximal_cells(square_by_weights)))
Copy link
Member Author

Choose a reason for hiding this comment

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

@benlorenz I added this already here to try to get CI green eventually

Copy link
Member

Choose a reason for hiding this comment

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

Ok, thanks! The collect should be unnecessary now but I can take care of that later.
For the cases in polyhedron.jl a rerun usually fixed it.

@lgoettgens lgoettgens force-pushed the lg/prefer-symbols branch 2 times, most recently from 0784fd0 to ef891b7 Compare September 27, 2024 16:20
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 Algebraic Geometry/Commutative Algebra part looks good provided tests pass -- with the exception that I did not look at toric stuff (because you already pinged @HereAround ) and IntersectionTheory should be pinged as well.

@lgoettgens lgoettgens added the optimization Simpler/more performant code or more/better tests label Sep 30, 2024
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 93.84615% with 4 lines in your changes missing coverage. Please review.

Project coverage is 84.59%. Comparing base (32a38b3) to head (61545aa).
Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
experimental/FTheoryTools/src/auxiliary.jl 81.81% 2 Missing ⚠️
experimental/IntersectionTheory/src/Bott.jl 50.00% 1 Missing ⚠️
...metricIntersections/src/symmetric_grassmannians.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4158      +/-   ##
==========================================
- Coverage   84.70%   84.59%   -0.11%     
==========================================
  Files         628      631       +3     
  Lines       84449    84811     +362     
==========================================
+ Hits        71529    71749     +220     
- Misses      12920    13062     +142     
Files with missing lines Coverage Δ
...rimental/BasisLieHighestWeight/src/WeylPolytope.jl 100.00% <100.00%> (ø)
.../FTheoryTools/src/AbstractFTheoryModels/methods.jl 78.27% <100.00%> (ø)
...TheoryTools/src/HypersurfaceModels/constructors.jl 96.72% <100.00%> (ø)
...tal/FTheoryTools/src/HypersurfaceModels/methods.jl 100.00% <100.00%> (ø)
.../FTheoryTools/src/LiteratureModels/constructors.jl 93.81% <100.00%> (ø)
...mental/FTheoryTools/src/TateModels/constructors.jl 97.46% <100.00%> (ø)
...xperimental/FTheoryTools/src/TateModels/methods.jl 66.29% <100.00%> (ø)
...FTheoryTools/src/WeierstrassModels/constructors.jl 95.65% <100.00%> (ø)
...ntal/FTheoryTools/src/WeierstrassModels/methods.jl 100.00% <100.00%> (ø)
...erimental/FTheoryTools/test/hypersurface_models.jl 100.00% <ø> (ø)
... and 29 more

... and 41 files with indirect coverage changes

@@ -525,7 +525,7 @@ function _construct_literature_model_over_arbitrary_base(model_dict::Dict{String
elseif model_dict["model_descriptors"]["type"] == "hypersurface"

# Extract base variable names
auxiliary_base_vars = [string(g) for g in gens(auxiliary_base_ring)]
auxiliary_base_vars = [string(g) for g in symbols(auxiliary_base_ring)]

# Extract fiber ambient space
rays = [[a for a in b] for b in model_dict["model_data"]["fiber_ambient_space_rays"]]
Copy link
Member

Choose a reason for hiding this comment

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

Off-topic for this PR, but: I wonder if [a for a in b] shouldn't be replaced by collect(b) here and elsewhere? This line could perhaps even become

Suggested change
rays = [[a for a in b] for b in model_dict["model_data"]["fiber_ambient_space_rays"]]
rays = collect.(model_dict["model_data"]["fiber_ambient_space_rays"])

(Or maybe not, I did not try it and depending on what the code does this may or may not work, and it may or may not affect performance and allocations in either a good or bad way). So, just something to be potentially aware of, @HereAround

@@ -61,7 +61,7 @@ function global_tate_model(base::NormalToricVariety,
vs2 = collect(keys(defining_section_parametrization))
@req all(in(["a1", "a2", "a3", "a4", "a6"]), vs2) "Only the Tate sections a1, a2, a3, a4, a6 must be parametrized"

gens_base_names = [string(g) for g in gens(cox_ring(base))]
gens_base_names = [string(g) for g in symbols(cox_ring(base))]
Copy link
Member

Choose a reason for hiding this comment

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

Actually in this particular case it seems straightforward, as the only place using this seems to be the next line?

experimental/FTheoryTools/src/TateModels/constructors.jl Outdated Show resolved Hide resolved
@@ -144,7 +144,7 @@ Global Tate model over a not fully specified base
function global_tate_model(auxiliary_base_ring::MPolyRing, auxiliary_base_grading::Matrix{Int64}, d::Int, ais::Vector{T}) where {T<:MPolyRingElem}

# Execute consistency checks
gens_base_names = [string(g) for g in gens(auxiliary_base_ring)]
gens_base_names = [string(g) for g in symbols(auxiliary_base_ring)]
Copy link
Member

Choose a reason for hiding this comment

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

Here we can't (yet) change to just using symbols directly because this vector is passed to _construct_generic_sample which currently expects a Vector{Symbol}. But perhaps this could be changed in the future. Alas this doesn't look like a function that is called millions of time, so may not be worth it (similar in other cases -- use your own judgement)

@lgoettgens
Copy link
Member Author

This is now good to go from my POV

@afkafkafk13 afkafkafk13 merged commit 1217ab3 into oscar-system:master Oct 7, 2024
28 of 29 checks passed
@lgoettgens lgoettgens deleted the lg/prefer-symbols branch October 7, 2024 13:58
@lgoettgens lgoettgens removed the triage label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Simpler/more performant code or more/better tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants