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

Simplify attribute handling using new @attr features #4476

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
cohomCalg_jll = "5558cf25-a90e-53b0-b813-cadaa3ae7ade"

[compat]
AbstractAlgebra = "0.44.0"
AbstractAlgebra = "0.44.4"
AlgebraicSolving = "0.8.0"
Distributed = "1.6"
GAP = "0.13.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1299,21 +1299,19 @@ julia> h = euler_characteristic(qsm_model; check = false)
378
```
"""
function euler_characteristic(m::AbstractFTheoryModel; check::Bool = true)
@attr Int function euler_characteristic(m::AbstractFTheoryModel; check::Bool = true)
@req (m isa WeierstrassModel || m isa GlobalTateModel || m isa HypersurfaceModel) "Euler characteristic of F-theory model supported for Weierstrass, global Tate and hypersurface models only"
@req base_space(m) isa NormalToricVariety "Euler characteristic of F-theory model currently supported only for toric base"
@req ambient_space(m) isa NormalToricVariety "Euler characteristic of F-theory model currently supported only for toric ambient space"

return get_attribute!(m, :euler_characteristic) do
# Trigger potential short-cut computation of cohomology ring
cohomology_ring(ambient_space(m); check)
# Trigger potential short-cut computation of cohomology ring
cohomology_ring(ambient_space(m); check)

# Compute the cohomology class corresponding to the hypersurface equation
cy = cohomology_class(toric_divisor_class(ambient_space(m), degree(hypersurface_equation(m))))
# Compute the cohomology class corresponding to the hypersurface equation
cy = cohomology_class(toric_divisor_class(ambient_space(m), degree(hypersurface_equation(m))))

# Compute the Euler characteristic
return Int(integrate(chern_class(m, 4; check) * cy; check))
end::Int
# Compute the Euler characteristic
return Int(integrate(chern_class(m, 4; check) * cy; check))
end


Expand Down
24 changes: 10 additions & 14 deletions experimental/FTheoryTools/src/AbstractFTheoryModels/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@
julia> qsm_model = literature_model(arxiv_id = "1903.00009", model_parameters = Dict("k" => 4))
Hypersurface model over a concrete base

julia> verify_euler_characteristic_from_hodge_numbers(qsm_model, check = false)
julia> verify_euler_characteristic_from_hodge_numbers(qsm_model; check = false)
true
```
"""
function verify_euler_characteristic_from_hodge_numbers(m::AbstractFTheoryModel; check::Bool = true)
@attr Bool function verify_euler_characteristic_from_hodge_numbers(m::AbstractFTheoryModel; check::Bool = true)
@req (m isa WeierstrassModel || m isa GlobalTateModel || m isa HypersurfaceModel) "Verification of Euler characteristic of F-theory model supported for Weierstrass, global Tate and hypersurface models only"
@req base_space(m) isa NormalToricVariety "Verification of Euler characteristic of F-theory model currently supported only for toric base"
@req ambient_space(m) isa NormalToricVariety "Verification of Euler characteristic of F-theory model currently supported only for toric ambient space"
Expand All @@ -136,16 +136,14 @@
@req has_attribute(m, :h13) "Verification of Euler characteristic of F-theory model requires h13"
@req has_attribute(m, :h22) "Verification of Euler characteristic of F-theory model requires h22"

return get_attribute!(m, :verify_euler_characteristic_from_hodge_numbers) do
# Computer Euler characteristic from integrating c4
ec = euler_characteristic(m, check = check)
# Computer Euler characteristic from integrating c4
ec = euler_characteristic(m; check)

# Compute Euler characteristic from adding Hodge numbers
ec2 = 4 + 2 * hodge_h11(m) - 4 * hodge_h12(m) + 2 * hodge_h13(m) + hodge_h22(m)
# Compute Euler characteristic from adding Hodge numbers
ec2 = 4 + 2 * hodge_h11(m) - 4 * hodge_h12(m) + 2 * hodge_h13(m) + hodge_h22(m)

# Compute result of verification
return ec == ec2
end::Bool
# Compute result of verification
return ec == ec2
end


Expand All @@ -170,11 +168,9 @@
true
```
"""
function is_calabi_yau(m::AbstractFTheoryModel; check::Bool = true)
@attr Bool function is_calabi_yau(m::AbstractFTheoryModel; check::Bool = true)
@req (m isa WeierstrassModel || m isa GlobalTateModel || m isa HypersurfaceModel) "Verification of Euler characteristic of F-theory model supported for Weierstrass, global Tate and hypersurface models only"
@req base_space(m) isa NormalToricVariety "Verification of Euler characteristic of F-theory model currently supported only for toric base"
@req ambient_space(m) isa NormalToricVariety "Verification of Euler characteristic of F-theory model currently supported only for toric ambient space"
return get_attribute!(m, :is_calabi_yau) do
return is_trivial(chern_class(m, 1, check = check))
end::Bool
return is_trivial(chern_class(m, 1; check))

Check warning on line 175 in experimental/FTheoryTools/src/AbstractFTheoryModels/properties.jl

View check run for this annotation

Codecov / codecov/patch

experimental/FTheoryTools/src/AbstractFTheoryModels/properties.jl#L175

Added line #L175 was not covered by tests
end
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ julia> passes_elementary_quantization_checks(g4)
true
```
"""
function well_quantized_ambient_space_models_of_g4_fluxes(m::AbstractFTheoryModel; check::Bool = true)
@attr FamilyOfG4Fluxes function well_quantized_ambient_space_models_of_g4_fluxes(m::AbstractFTheoryModel; check::Bool = true)

# (1) Entry checks
@req base_space(m) isa NormalToricVariety "Computation of well-quantized G4-fluxes only supported for toric base and ambient spaces"
Expand All @@ -151,10 +151,6 @@ function well_quantized_ambient_space_models_of_g4_fluxes(m::AbstractFTheoryMode
@req is_complete(ambient_space(m)) "Computation of well-quantized G4-fluxes only supported for complete toric ambient spaces"
@req is_simplicial(ambient_space(m)) "Computation of well-quantized G4-fluxes only supported for simplicial toric ambient space"
end
if has_attribute(m, :well_quantized_ambient_space_models_of_g4_fluxes)
return get_attribute(m, :well_quantized_ambient_space_models_of_g4_fluxes)::FamilyOfG4Fluxes
end


# (2) Compute data, that is frequently used by the sophisticated intersection product below
S = cox_ring(ambient_space(m))
Expand Down Expand Up @@ -270,14 +266,12 @@ function well_quantized_ambient_space_models_of_g4_fluxes(m::AbstractFTheoryMode
set_attribute!(fgs, :is_well_quantized, true)
set_attribute!(fgs, :is_vertical, false)
set_attribute!(fgs, :breaks_non_abelian_gauge_group, true)
set_attribute!(m, :well_quantized_ambient_space_models_of_g4_fluxes, fgs)
set_attribute!(m, :inter_dict, inter_dict)
set_attribute!(m, :s_inter_dict, s_inter_dict)


# (10) Finally, return the result
return fgs::FamilyOfG4Fluxes

return fgs
end


Expand Down Expand Up @@ -383,7 +377,7 @@ julia> passes_verticality_checks(qsm_g4_candidate)
true
```
"""
function well_quantized_and_vertical_ambient_space_models_of_g4_fluxes(m::AbstractFTheoryModel; check::Bool = true)
@attr FamilyOfG4Fluxes function well_quantized_and_vertical_ambient_space_models_of_g4_fluxes(m::AbstractFTheoryModel; check::Bool = true)

# (1) Entry checks
@req base_space(m) isa NormalToricVariety "Computation of well-quantized G4-fluxes only supported for toric base and ambient spaces"
Expand All @@ -392,9 +386,6 @@ function well_quantized_and_vertical_ambient_space_models_of_g4_fluxes(m::Abstra
@req is_complete(ambient_space(m)) "Computation of well-quantized G4-fluxes only supported for complete toric ambient spaces"
@req is_simplicial(ambient_space(m)) "Computation of well-quantized G4-fluxes only supported for simplicial toric ambient space"
end
if has_attribute(m, :well_quantized_and_vertical_ambient_space_models_of_g4_fluxes)
return get_attribute(m, :well_quantized_and_vertical_ambient_space_models_of_g4_fluxes)::FamilyOfG4Fluxes
end


# (2) Compute data, that is frequently used by the sophisticated intersection product below
Expand Down Expand Up @@ -578,14 +569,12 @@ function well_quantized_and_vertical_ambient_space_models_of_g4_fluxes(m::Abstra
set_attribute!(fgs, :is_well_quantized, true)
set_attribute!(fgs, :is_vertical, true)
set_attribute!(fgs, :breaks_non_abelian_gauge_group, true)
set_attribute!(m, :well_quantized_and_vertical_ambient_space_models_of_g4_fluxes, fgs)
set_attribute!(m, :inter_dict, inter_dict)
set_attribute!(m, :s_inter_dict, s_inter_dict)


# (12) Finally, return the result
return fgs::FamilyOfG4Fluxes

return fgs
end


Expand Down Expand Up @@ -718,7 +707,7 @@ julia> qsm_g4_candidate == g4_flux(qsm_model, g4_class)
true
```
"""
function well_quantized_and_vertical_and_no_non_abelian_gauge_group_breaking_ambient_space_models_of_g4_fluxes(m::AbstractFTheoryModel; check::Bool = true)
@attr FamilyOfG4Fluxes function well_quantized_and_vertical_and_no_non_abelian_gauge_group_breaking_ambient_space_models_of_g4_fluxes(m::AbstractFTheoryModel; check::Bool = true)

# (1) Entry checks
@req base_space(m) isa NormalToricVariety "Computation of well-quantized G4-fluxes only supported for toric base and ambient spaces"
Expand All @@ -727,9 +716,6 @@ function well_quantized_and_vertical_and_no_non_abelian_gauge_group_breaking_amb
@req is_complete(ambient_space(m)) "Computation of well-quantized G4-fluxes only supported for complete toric ambient spaces"
@req is_simplicial(ambient_space(m)) "Computation of well-quantized G4-fluxes only supported for simplicial toric ambient space"
end
if has_attribute(m, :well_quantized_and_vertical_and_no_non_abelian_gauge_group_breaking_ambient_space_models_of_g4_fluxes)
return get_attribute(m, :well_quantized_and_vertical_and_no_non_abelian_gauge_group_breaking_ambient_space_models_of_g4_fluxes)::FamilyOfG4Fluxes
end


# (2) Compute data, that is frequently used by the sophisticated intersection product below
Expand Down Expand Up @@ -938,12 +924,10 @@ function well_quantized_and_vertical_and_no_non_abelian_gauge_group_breaking_amb
set_attribute!(fgs, :is_well_quantized, true)
set_attribute!(fgs, :is_vertical, true)
set_attribute!(fgs, :breaks_non_abelian_gauge_group, false)
set_attribute!(m, :well_quantized_and_vertical_and_no_non_abelian_gauge_group_breaking_ambient_space_models_of_g4_fluxes, fgs)
set_attribute!(m, :inter_dict, inter_dict)
set_attribute!(m, :s_inter_dict, s_inter_dict)


# (12) Finally, return the result
return fgs::FamilyOfG4Fluxes

return fgs
end
35 changes: 7 additions & 28 deletions experimental/FTheoryTools/src/G4Fluxes/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,15 @@
true
```
"""
function basis_of_h22(v::NormalToricVariety; check::Bool = true)::Vector{CohomologyClass}

@attr Vector{CohomologyClass} function basis_of_h22(v::NormalToricVariety; check::Bool = true)
# (0) Some initial checks
if check
@req is_complete(v) "Computation of basis of H22 is currently only supported for complete toric varieties"
@req is_simplicial(v) "Computation of basis of H22 is currently only supported for simplicial toric varieties"
end
if dim(v) < 4
set_attribute!(v, :basis_of_h22, Vector{CohomologyClass}())
end
if has_attribute(v, :basis_of_h22)
return get_attribute(v, :basis_of_h22)
return Vector{CohomologyClass}()

Check warning on line 51 in experimental/FTheoryTools/src/G4Fluxes/auxiliary.jl

View check run for this annotation

Codecov / codecov/patch

experimental/FTheoryTools/src/G4Fluxes/auxiliary.jl#L51

Added line #L51 was not covered by tests
end

# (1) Prepare some data of the variety
mnf = Oscar._minimal_nonfaces(v)
ignored_sets = Set([Tuple(sort(Vector{Int}(Polymake.row(mnf, i)))) for i in 1:Polymake.nrows(mnf)])
Expand Down Expand Up @@ -146,17 +141,15 @@
# (10) Return the basis elements in terms of cohomology classes
S = cohomology_ring(v, check = check)
c_ds = [k.f for k in gens(S)]
final_list_of_tuples = []
final_list_of_tuples = Tuple{Int64, Int64}[]
for (key, value) in dict_of_filtered_quadratic_elements
if value in new_good_positions
push!(final_list_of_tuples, key)
end
end
basis_of_h22 = [cohomology_class(v, MPolyQuoRingElem(c_ds[my_tuple[1]]*c_ds[my_tuple[2]], S)) for my_tuple in final_list_of_tuples]
set_attribute!(v, :basis_of_h22, basis_of_h22)
set_attribute!(v, :basis_of_h22_indices, final_list_of_tuples)
return basis_of_h22

end


Expand All @@ -170,12 +163,7 @@
# has empty intersection with the hypersurface. The following method identifies the remaining pairs of
# toric divisors d1, d2 that we must consider.

function _ambient_space_divisor_pairs_to_be_considered(m::AbstractFTheoryModel)::Vector{Tuple{Int64, Int64}}

if has_attribute(m, :_ambient_space_divisor_pairs_to_be_considered)
return get_attribute(m, :_ambient_space_divisor_pairs_to_be_considered)
end

@attr Vector{Tuple{Int64, Int64}} function _ambient_space_divisor_pairs_to_be_considered(m::AbstractFTheoryModel)
gS = gens(cox_ring(ambient_space(m)))
mnf = Oscar._minimal_nonfaces(ambient_space(m))
ignored_sets = Set([Tuple(sort(Vector{Int}(Polymake.row(mnf, i)))) for i in 1:Polymake.nrows(mnf)])
Expand Down Expand Up @@ -221,10 +209,8 @@
end
end

# Remember this result as attribute and return the findings.
set_attribute!(m, :_ambient_space_divisor_pairs_to_be_considered, list_of_elements)
# Return the findings.
return list_of_elements

end


Expand All @@ -234,12 +220,7 @@
# This method makes a pre-selection of such base divisor pairs. "Pre" means that we execute a sufficient,
# but not necessary, check to tell if a pair of base divisors restricts trivially.

function _ambient_space_base_divisor_pairs_to_be_considered(m::AbstractFTheoryModel)::Vector{Tuple{Int64, Int64}}

if has_attribute(m, :_ambient_space_base_divisor_pairs_to_be_considered)
return get_attribute(m, :_ambient_space_base_divisor_pairs_to_be_considered)
end

@attr Vector{Tuple{Int64, Int64}} function _ambient_space_base_divisor_pairs_to_be_considered(m::AbstractFTheoryModel)
gS = gens(cox_ring(ambient_space(m)))
mnf = Oscar._minimal_nonfaces(ambient_space(m))
ignored_sets = Set([Tuple(sort(Vector{Int}(Polymake.row(mnf, i)))) for i in 1:Polymake.nrows(mnf)])
Expand Down Expand Up @@ -285,10 +266,8 @@
end
end

# Remember this result as attribute and return the findings.
set_attribute!(m, :_ambient_space_base_divisor_pairs_to_be_considered, list_of_elements)
# Return the findings.
return list_of_elements

end


Expand Down
50 changes: 24 additions & 26 deletions experimental/Schemes/src/NormalToricVarieties/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,33 @@
# too. On the other hand, none of the vⱼ was in τ⟂ for j > s,
# so neither can be any convex combination, but the trivial one.
# This proves the claim. Now (*) follows directly.
function _torusinvariant_weil_divisors(X::NormalToricVariety; check::Bool=false, algorithm::Symbol=:via_polymake)
return get_attribute!(X, :_torusinvariant_weil_divisors) do
ray_list = rays(polyhedral_fan(X))
ideal_sheaves = Vector{AbsIdealSheaf}()
if algorithm == :via_polymake
ideal_sheaves = [_ideal_sheaf_via_polymake(X, i; check) for i in 1:length(ray_list)]
elseif algorithm == :via_oscar
for tau in ray_list
tau_dual = polarize(cone(tau))
ideal_dict = IdDict{AbsAffineScheme, Ideal}()
for U in affine_charts(X)
if !(tau in cone(U))
ideal_dict[U] = ideal(OO(U), one(OO(U)))
continue
end
sigma_dual = weight_cone(U)
hb = hilbert_basis(sigma_dual)
x = gens(OO(U))
ideal_dict[U] = ideal(OO(U), [x[i] for i in 1:length(x) if !(-hb[i] in tau_dual)])
@attr Vector{<:AbsWeilDivisor} function _torusinvariant_weil_divisors(X::NormalToricVariety; check::Bool=false, algorithm::Symbol=:via_polymake)
ray_list = rays(polyhedral_fan(X))
ideal_sheaves = Vector{AbsIdealSheaf}()
if algorithm == :via_polymake
ideal_sheaves = [_ideal_sheaf_via_polymake(X, i; check) for i in 1:length(ray_list)]
elseif algorithm == :via_oscar
for tau in ray_list
tau_dual = polarize(cone(tau))
ideal_dict = IdDict{AbsAffineScheme, Ideal}()
for U in affine_charts(X)
if !(tau in cone(U))
ideal_dict[U] = ideal(OO(U), one(OO(U)))
continue
end
push!(ideal_sheaves, IdealSheaf(X, ideal_dict; check))
sigma_dual = weight_cone(U)
hb = hilbert_basis(sigma_dual)
x = gens(OO(U))
ideal_dict[U] = ideal(OO(U), [x[i] for i in 1:length(x) if !(-hb[i] in tau_dual)])
end
else
error("algorithm not recognized")
push!(ideal_sheaves, IdealSheaf(X, ideal_dict; check))
end
generating_divisors = [WeilDivisor(X, ZZ, IdDict{AbsIdealSheaf, ZZRingElem}(I => one(ZZ))) for I in ideal_sheaves]
result = generating_divisors
return result
end::Vector{<:AbsWeilDivisor}
else
error("algorithm not recognized")

Check warning on line 76 in experimental/Schemes/src/NormalToricVarieties/attributes.jl

View check run for this annotation

Codecov / codecov/patch

experimental/Schemes/src/NormalToricVarieties/attributes.jl#L76

Added line #L76 was not covered by tests
end
generating_divisors = [WeilDivisor(X, ZZ, IdDict{AbsIdealSheaf, ZZRingElem}(I => one(ZZ))) for I in ideal_sheaves]
result = generating_divisors
return result
end

function _ideal_sheaf_via_polymake(X::NormalToricVariety, i::Int; check::Bool=false)
Expand Down
36 changes: 17 additions & 19 deletions experimental/Schemes/src/ToricDivisors/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,22 @@
end

# For method delegation.
function underlying_divisor(td::ToricDivisor; check::Bool=false, algorithm::Symbol=:direct)
return get_attribute!(td, :underlying_divisor) do
X = scheme(td)
iszero(coefficients(td)) && return WeilDivisor(X, ZZ)
if algorithm == :direct
a = coefficients(td)::Vector{ZZRingElem}
pos = [(c > 0 ? c : zero(ZZ)) for c in a]
neg = [(c < 0 ? -c : zero(ZZ)) for c in a]
is_zero(pos) && return -WeilDivisor(_ideal_sheaf_via_polymake(X, neg))
is_zero(neg) && return WeilDivisor(_ideal_sheaf_via_polymake(X, pos))
pos_div = WeilDivisor(_ideal_sheaf_via_polymake(X, pos))
neg_div = WeilDivisor(_ideal_sheaf_via_polymake(X, neg))
return pos_div - neg_div
else
g = _torusinvariant_weil_divisors(X; algorithm)
generating_divisors = _torusinvariant_weil_divisors(X; check, algorithm)
return sum(a*D for (a, D) in zip(coefficients(td), generating_divisors))
end
end::WeilDivisor
@attr WeilDivisor function underlying_divisor(td::ToricDivisor; check::Bool=false, algorithm::Symbol=:direct)
X = scheme(td)
iszero(coefficients(td)) && return WeilDivisor(X, ZZ)
if algorithm == :direct
a = coefficients(td)::Vector{ZZRingElem}
pos = [(c > 0 ? c : zero(ZZ)) for c in a]
neg = [(c < 0 ? -c : zero(ZZ)) for c in a]
is_zero(pos) && return -WeilDivisor(_ideal_sheaf_via_polymake(X, neg))
is_zero(neg) && return WeilDivisor(_ideal_sheaf_via_polymake(X, pos))
pos_div = WeilDivisor(_ideal_sheaf_via_polymake(X, pos))
neg_div = WeilDivisor(_ideal_sheaf_via_polymake(X, neg))
return pos_div - neg_div

Check warning on line 67 in experimental/Schemes/src/ToricDivisors/attributes.jl

View check run for this annotation

Codecov / codecov/patch

experimental/Schemes/src/ToricDivisors/attributes.jl#L65-L67

Added lines #L65 - L67 were not covered by tests
else
g = _torusinvariant_weil_divisors(X; algorithm)
generating_divisors = _torusinvariant_weil_divisors(X; check, algorithm)
return sum(a*D for (a, D) in zip(coefficients(td), generating_divisors))
end
end

Loading
Loading