Skip to content

Commit 713f627

Browse files
committed
[FTheoryTools] Improve Monte-Carlo method
1 parent 1b609ae commit 713f627

10 files changed

Lines changed: 105 additions & 78 deletions

File tree

experimental/FTheoryTools/src/HypersurfaceModels/attributes.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ end
287287
288288
Return the singular loci of the Weierstrass model equivalent to the given hypersurface model,
289289
along with the order of vanishing of ``(f, g, \Delta)`` at each locus and the corresponding
290-
refined Tate fiber type. See [singular_loci(w::WeierstrassModel)](@ref) for more details.
290+
refined Tate fiber type. See [`singular_loci(w::WeierstrassModel)`](@ref) for more details.
291291
292292
Raises an error if no such Weierstrass model is known.
293293
@@ -297,6 +297,7 @@ model (see [BMT25](@cite BMT25) for background), in order to demonstrate this fu
297297
!!! warning
298298
The classification of singularities is performed using a Monte Carlo algorithm, involving randomized sampling.
299299
While reliable in practice, this probabilistic method may occasionally yield non-deterministic results.
300+
The random seed can be set with the optional argument `rng`.
300301
301302
# Examples
302303
```jldoctest
@@ -324,12 +325,14 @@ Weierstrass model over a concrete base
324325
325326
julia> set_weierstrass_model(h, w)
326327
327-
julia> length(singular_loci(h))
328+
julia> using Random;
329+
330+
julia> length(singular_loci(h; rng = Random.Xoshiro(1234)))
328331
2
329332
```
330333
"""
331-
@attr Vector{<:Tuple{<:MPolyIdeal{<:MPolyRingElem}, Tuple{Int64, Int64, Int64}, String}} function singular_loci(h::HypersurfaceModel)
334+
@attr Vector{<:Tuple{<:MPolyIdeal{<:MPolyRingElem}, Tuple{Int64, Int64, Int64}, String}} function singular_loci(h::HypersurfaceModel; rng::AbstractRNG = Random.default_rng())
332335
@req base_space(h) isa NormalToricVariety "Singular loci currently only supported for toric varieties as base space"
333336
@req has_attribute(h, :weierstrass_model) || has_attribute(h, :global_tate_model) "No corresponding Weierstrass model or global Tate model is known"
334-
return has_attribute(h, :weierstrass_model) ? singular_loci(weierstrass_model(h)) : singular_loci(global_tate_model(h))
337+
return has_attribute(h, :weierstrass_model) ? singular_loci(weierstrass_model(h); rng) : singular_loci(global_tate_model(h); rng)
335338
end

experimental/FTheoryTools/src/LiteratureModels/constructors.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ Construction over concrete base may lead to singularity enhancement. Consider co
8181
8282
Weierstrass model over a concrete base -- U(1) Weierstrass model based on arXiv paper 1208.2695 Eq. (B.19)
8383
84-
julia> length(singular_loci(w))
84+
julia> using Random;
85+
86+
julia> length(singular_loci(w; rng = Random.Xoshiro(1234)))
8587
1
8688
```
8789
@@ -102,7 +104,9 @@ Construction over concrete base may lead to singularity enhancement. Consider co
102104
103105
Weierstrass model over a concrete base -- U(1) Weierstrass model based on arXiv paper 1208.2695 Eq. (B.19)
104106
105-
julia> length(singular_loci(w))
107+
julia> using Random;
108+
109+
julia> length(singular_loci(w; rng = Random.Xoshiro(1234)))
106110
1
107111
```
108112

experimental/FTheoryTools/src/TateModels/attributes.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,12 @@ end
320320
321321
Return the singular loci of the Weierstrass model equivalent to the given Tate model,
322322
along with the order of vanishing of ``(f, g, \Delta)`` at each locus and the corresponding
323-
refined Tate fiber type. See [singular_loci(w::WeierstrassModel)](@ref) for more details.
323+
refined Tate fiber type. See [`singular_loci(w::WeierstrassModel)`](@ref) for more details.
324324
325325
!!! warning
326326
The classification of singularities is performed using a Monte Carlo algorithm, involving randomized sampling.
327327
While reliable in practice, this probabilistic method may occasionally yield non-deterministic results.
328+
The random seed can be set with the optional argument `rng`.
328329
329330
Below, we demonstrate this functionality by computing the singular loci of a Type ``III`` Tate model
330331
[KMSS11](@cite). In this case, the Tate sections are factored as follows:
@@ -360,13 +361,19 @@ Assuming that the first row of the given grading is the grading under Kbar
360361
361362
Global Tate model over a not fully specified base
362363
364+
<<<<<<< HEAD
363365
julia> sort([k[2:3] for k in singular_loci(t)])
366+
=======
367+
julia> using Random;
368+
369+
julia> sort([k[2:3] for k in singular_loci(t; rng = Random.Xoshiro(1234))])
370+
>>>>>>> 267fca2ae9 ([FTheoryTools] Improve Monte-Carlo method)
364371
2-element Vector{Tuple{Tuple{Int64, Int64, Int64}, String}}:
365372
((0, 0, 1), "I_1")
366373
((1, 2, 3), "III")
367374
```
368375
"""
369-
@attr Vector{<:Tuple{<:MPolyIdeal{<:MPolyRingElem}, Tuple{Int64, Int64, Int64}, String}} function singular_loci(t::GlobalTateModel)
376+
@attr Vector{<:Tuple{<:MPolyIdeal{<:MPolyRingElem}, Tuple{Int64, Int64, Int64}, String}} function singular_loci(t::GlobalTateModel; rng::AbstractRNG = Random.default_rng())
370377
@req (base_space(t) isa NormalToricVariety || base_space(t) isa FamilyOfSpaces) "Singular loci of global Tate model currently only supported for toric varieties and families of spaces as base space"
371-
return singular_loci(weierstrass_model(t))
378+
return singular_loci(weierstrass_model(t); rng)
372379
end

experimental/FTheoryTools/src/TateModels/methods.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Determine the fiber of a (singular) global Tate model over a particular base loc
66
!!! warning
77
This method may run for very long time and is currently not tested as part of the regular OSCAR CI due to its excessive run times.
88
"""
9-
function analyze_fibers(model::GlobalTateModel, centers::Vector{<:Vector{<:Integer}})
9+
function analyze_fibers(model::GlobalTateModel, centers::Vector{<:Vector{<:Integer}}; rng::AbstractRNG = Random.default_rng())
1010

1111
# This method only works if the model is defined over a toric variety over toric scheme
1212
@req base_space(model) isa NormalToricVariety "Analysis of fibers currently only supported for toric variety as base space"
@@ -23,7 +23,7 @@ function analyze_fibers(model::GlobalTateModel, centers::Vector{<:Vector{<:Integ
2323
lin = ideal_of_linear_relations(tas);
2424

2525
# Singular loci
26-
sing_loc = singular_loci(model)
26+
sing_loc = singular_loci(model; rng)
2727

2828
# Pick out the singular loci that are more singular than an I_1
2929
# Then keep only the locus and not the extra info about it

experimental/FTheoryTools/src/WeierstrassModels/attributes.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,21 @@ Advanced technical details are available in [BMT25](@cite BMT25).
178178
179179
!!! warning
180180
The classification of singularities is based on a Monte Carlo algorithm, which involves random sampling.
181-
While extensively tested and highly reliable, the method’s probabilistic nature may lead to non-deterministic results in rare cases.
181+
While reliable in practice, this probabilistic method may occasionally yield non-deterministic results.
182+
The random seed can be set with the optional argument `rng`.
182183
183184
# Examples
184185
```jldoctest
185186
julia> w = weierstrass_model_over_projective_space(3)
186187
Weierstrass model over a concrete base
187188
188-
julia> length(singular_loci(w))
189+
julia> using Random;
190+
191+
julia> length(singular_loci(w; rng = Random.Xoshiro(1234)))
189192
1
190193
```
191194
"""
192-
@attr Vector{<:Tuple{<:MPolyIdeal{<:MPolyRingElem}, Tuple{Int64, Int64, Int64}, String}} function singular_loci(w::WeierstrassModel)
195+
@attr Vector{<:Tuple{<:MPolyIdeal{<:MPolyRingElem}, Tuple{Int64, Int64, Int64}, String}} function singular_loci(w::WeierstrassModel; rng::AbstractRNG = Random.default_rng())
193196
@req (base_space(w) isa NormalToricVariety || base_space(w) isa FamilyOfSpaces) "Singular loci of Weierstrass model is currently only supported for toric varieties and families of spaces as base space"
194197
B = irrelevant_ideal(base_space(w))
195198
d_primes = factor(discriminant(w))
@@ -202,7 +205,7 @@ julia> length(singular_loci(w))
202205
g_order = valuation(g, p)
203206
ords = (f_order, g_order, d_order)
204207
I = ideal([p])
205-
kodaira_types[i] = (I, ords, _kodaira_type(I, ords, w))
208+
kodaira_types[i] = (I, ords, _kodaira_type(I, ords, w; rng))
206209
end
207210
sort!(kodaira_types, by = x -> (x[2][2], x[2][3]))
208211
return kodaira_types

experimental/FTheoryTools/src/auxiliary.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ _count_factors(poly::QQMPolyRingElem) = mapreduce(p -> p[end], +, absolute_prima
114114

115115
_string_from_factor_count(poly::QQMPolyRingElem, string_list::Vector{String}) = string_list[_count_factors(poly)]
116116

117-
function _kodaira_type(id::MPolyIdeal{<:MPolyRingElem}, ords::Tuple{Int64, Int64, Int64}, w::WeierstrassModel; rand_seed::Union{Int64, Nothing} = nothing)
117+
function _kodaira_type(id::MPolyIdeal{<:MPolyRingElem}, ords::Tuple{Int64, Int64, Int64}, w::WeierstrassModel; rng::AbstractRNG = Random.default_rng())
118118
f_ord = ords[1]
119119
g_ord = ords[2]
120120
d_ord = ords[3]
@@ -198,12 +198,10 @@ function _kodaira_type(id::MPolyIdeal{<:MPolyRingElem}, ords::Tuple{Int64, Int64
198198
# five times and see if we get agreement among all of the results
199199
num_gens = ngens(parent(f))
200200
gauge2s, f2s, g2s, d2s = [], [], [], []
201-
if rand_seed != nothing
202-
Random.seed!(rand_seed)
203-
end
201+
rng = MersenneTwister()
204202
for _ in 1:5
205-
coord_inds = randperm(num_gens)[1:end-2]
206-
rand_ints = rand(-100:100, num_gens - 2)
203+
coord_inds = randperm(rng, num_gens)[1:end-2]
204+
rand_ints = rand(rng, -100:100, num_gens - 2)
207205

208206
push!(gauge2s, evaluate(forget_decoration(gens(id)[1]), coord_inds, rand_ints))
209207
push!(f2s, evaluate(forget_decoration(f), coord_inds, rand_ints))

experimental/FTheoryTools/test/hypersurface_models.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# 1: Hypersurface models over concrete bases
33
#############################################################
44

5+
using Random
6+
our_rng = Random.Xoshiro(1234)
7+
58
B3 = projective_space(NormalToricVariety, 3)
69
ambient_space_of_fiber = weighted_projective_space(NormalToricVariety, [2,3,1])
710
set_coordinate_names(ambient_space_of_fiber, ["x", "y", "z"])
@@ -25,7 +28,7 @@ end
2528
@test_throws ArgumentError weierstrass_model(h)
2629
@test_throws ArgumentError global_tate_model(h)
2730
@test_throws ArgumentError discriminant(h)
28-
@test_throws ArgumentError singular_loci(h)
31+
@test_throws ArgumentError singular_loci(h; rng = our_rng)
2932
end
3033

3134
@testset "Saving and loading hypersurface models over concrete base space" begin

experimental/FTheoryTools/test/literature_models.jl

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# 1: Literature Tate model over concrete base
33
#############################################################
44

5+
using Random
6+
our_rng = Random.Xoshiro(1234)
7+
58
B3 = projective_space(NormalToricVariety, 3)
69
Kbar = anticanonical_divisor_class(B3)
710
w = torusinvariant_prime_divisors(B3)[1]
@@ -16,7 +19,7 @@ D = classes_of_tunable_sections_in_basis_of_Kbar_and_defining_classes(t1)
1619
@test parent(tate_section_a6(t1)) == cox_ring(base_space(t1))
1720
@test parent(tate_polynomial(t1)) == cox_ring(ambient_space(t1))
1821
@test parent(discriminant(t1)) == cox_ring(base_space(t1))
19-
@test length(singular_loci(t1)) == 2
22+
@test length(singular_loci(t1; rng = our_rng)) == 2
2023
@test dim(base_space(t1)) == 3
2124
@test dim(ambient_space(t1)) == 5
2225
@test is_base_space_fully_specified(t1) == true
@@ -97,7 +100,7 @@ w1 = literature_model(arxiv_id = "1208.2695", equation = "B.19", base_space = B2
97100
@test parent(weierstrass_section_g(w1)) == cox_ring(base_space(w1))
98101
@test parent(weierstrass_polynomial(w1)) == cox_ring(ambient_space(w1))
99102
@test parent(discriminant(w1)) == cox_ring(base_space(w1))
100-
@test length(singular_loci(w1)) == 1
103+
@test length(singular_loci(w1; rng = our_rng)) == 1
101104
@test dim(base_space(w1)) == 2
102105
@test dim(ambient_space(w1)) == 4
103106
@test is_base_space_fully_specified(w1) == true
@@ -160,7 +163,7 @@ t3 = literature_model(arxiv_id = "1109.3454", equation = "3.1")
160163
@test parent(tate_section_a6(t3)) == cox_ring(base_space(t3))
161164
@test parent(tate_polynomial(t3)) == cox_ring(ambient_space(t3))
162165
@test parent(discriminant(t3)) == cox_ring(base_space(t3))
163-
@test length(singular_loci(t3)) == 2
166+
@test length(singular_loci(t3; rng = our_rng)) == 2
164167
@test dim(base_space(t3)) == 3
165168
@test dim(ambient_space(t3)) == 5
166169
@test is_base_space_fully_specified(t3) == false
@@ -261,7 +264,7 @@ w2 = literature_model(arxiv_id = "1208.2695", equation = "B.19", completeness_ch
261264
@test parent(weierstrass_section_g(w2)) == cox_ring(base_space(w2))
262265
@test parent(weierstrass_polynomial(w2)) == cox_ring(ambient_space(w2))
263266
@test parent(discriminant(w2)) == cox_ring(base_space(w2))
264-
@test length(singular_loci(w2)) == 1
267+
@test length(singular_loci(w2; rng = our_rng)) == 1
265268
@test dim(base_space(w2)) == 2
266269
@test dim(ambient_space(w2)) == 4
267270
@test is_base_space_fully_specified(w2) == false
@@ -326,7 +329,7 @@ b2 = anticanonical_divisor(B2)
326329
w5 = literature_model(arxiv_id = "1507.05954", equation = "A.1", completeness_check = false, base_space = B2, defining_classes = Dict("s8" => b2, "a1" => b, "a2" => b, "a3" => b))
327330

328331
@testset "Test defining data for literature Weierstrass model over concrete base" begin
329-
@test length(singular_loci(w4)) == 1
332+
@test length(singular_loci(w4; rng = our_rng)) == 1
330333
@test dim(base_space(w4)) == 2
331334
@test dim(ambient_space(w4)) == 4
332335
@test is_base_space_fully_specified(w4) == true
@@ -344,7 +347,7 @@ b = torusinvariant_prime_divisors(B2)[1]
344347
w6 = literature_model(3, base_space = B2, defining_classes = Dict("b" => b), completeness_check = false)
345348

346349
@testset "Test defining data for literature model defined by model index" begin
347-
@test length(singular_loci(w6)) == 1
350+
@test length(singular_loci(w6; rng = our_rng)) == 1
348351
@test dim(base_space(w6)) == 2
349352
@test dim(ambient_space(w6)) == 4
350353
@test is_base_space_fully_specified(w6) == true
@@ -783,20 +786,20 @@ foah16_B3_weier = literature_model(arxiv_id = "1408.4808", equation = "3.203", t
783786
@test parent(explicit_model_sections(foah14_B3_weier)["s7"]) == cox_ring(base_space(foah14_B3_weier))
784787
@test parent(explicit_model_sections(foah15_B3_weier)["s7"]) == cox_ring(base_space(foah15_B3_weier))
785788
@test parent(explicit_model_sections(foah16_B3_weier)["s7"]) == cox_ring(base_space(foah16_B3_weier))
786-
@test [k[2:3] for k in singular_loci(foah1_B3_weier)] == [((0, 0, 1), "I_1")]
787-
@test [k[2:3] for k in singular_loci(foah2_B3_weier)] == [((0, 0, 1), "I_1")]
788-
@test [k[2:3] for k in singular_loci(foah3_B3_weier)] == [((0, 0, 1), "I_1")]
789-
@test [k[2:3] for k in singular_loci(foah4_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2")]
790-
@test [k[2:3] for k in singular_loci(foah5_B3_weier)] == [((0, 0, 1), "I_1")]
791-
@test [k[2:3] for k in singular_loci(foah6_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2")]
792-
@test [k[2:3] for k in singular_loci(foah7_B3_weier)] == [((0, 0, 1), "I_1")]
793-
@test [k[2:3] for k in singular_loci(foah8_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2")]
794-
@test [k[2:3] for k in singular_loci(foah9_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2")]
795-
@test [k[2:3] for k in singular_loci(foah10_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 3), "Split I_3")]
796-
@test [k[2:3] for k in singular_loci(foah11_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 3), "Split I_3")]
797-
@test [k[2:3] for k in singular_loci(foah12_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2")]
798-
@test [k[2:3] for k in singular_loci(foah13_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 4), "Split I_4")]
799-
@test [k[2:3] for k in singular_loci(foah14_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 3), "Split I_3")]
800-
@test [k[2:3] for k in singular_loci(foah15_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2")]
801-
@test [k[2:3] for k in singular_loci(foah16_B3_weier)] == [((0, 0, 1), "I_1"), ((0, 0, 3), "Split I_3"), ((0, 0, 3), "Split I_3"), ((0, 0, 3), "Split I_3")]
789+
@test [k[2:3] for k in singular_loci(foah1_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1")]
790+
@test [k[2:3] for k in singular_loci(foah2_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1")]
791+
@test [k[2:3] for k in singular_loci(foah3_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1")]
792+
@test [k[2:3] for k in singular_loci(foah4_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2")]
793+
@test [k[2:3] for k in singular_loci(foah5_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1")]
794+
@test [k[2:3] for k in singular_loci(foah6_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2")]
795+
@test [k[2:3] for k in singular_loci(foah7_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1")]
796+
@test [k[2:3] for k in singular_loci(foah8_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2")]
797+
@test [k[2:3] for k in singular_loci(foah9_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2")]
798+
@test [k[2:3] for k in singular_loci(foah10_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 3), "Split I_3")]
799+
@test [k[2:3] for k in singular_loci(foah11_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 3), "Split I_3")]
800+
@test [k[2:3] for k in singular_loci(foah12_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2")]
801+
@test [k[2:3] for k in singular_loci(foah13_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 4), "Split I_4")]
802+
@test [k[2:3] for k in singular_loci(foah14_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 3), "Split I_3")]
803+
@test [k[2:3] for k in singular_loci(foah15_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2"), ((0, 0, 2), "Non-split I_2")]
804+
@test [k[2:3] for k in singular_loci(foah16_B3_weier; rng = our_rng)] == [((0, 0, 1), "I_1"), ((0, 0, 3), "Split I_3"), ((0, 0, 3), "Split I_3"), ((0, 0, 3), "Split I_3")]
802805
end

0 commit comments

Comments
 (0)