<commit_before>using DZOptimization: BFGSOptimizer, normalize_columns!
using MultiFloats: Float64x2, Float64x3
using UUIDs: uuid4

push!(LOAD_PATH, @__DIR__)
using PCREO: run!, spherical_riesz_gradient_norm,
    spherical_riesz_hessian_spectral_gap,
    convex_hull_facets, parallel_facet_distance
using PCREOSymmetry: POLYHEDRAL_POINT_GROUPS, symmetrized_riesz_functors


function constrain_sphere!(points)
    normalize_columns!(points)
    return true
end


function generate_and_save_configuration(
        group::Function, orbits::Vector{Function}, num_points::Int)

    initial_points = normalize_columns!(randn(3, num_points))

    f1, g1! = symmetrized_riesz_functors(Float64, group, orbits)
    opt1 = BFGSOptimizer(f1, g1!, constrain_sphere!, initial_points, 1.0e-6)
    run!(opt1)

    f2, g2! = symmetrized_riesz_functors(Float64x2, group, orbits)
    opt2 = BFGSOptimizer(Float64x2, f2, g2!, constrain_sphere!, opt1)
    run!(opt2)

    f3, g3! = symmetrized_riesz_functors(Float64x3, group, orbits)
    opt3 = BFGSOptimizer(Float64x3, f3, g3!, constrain_sphere!, opt2)
    run!(opt3)

    num_full_points = (num_points * length(f3.group) +
                       length(f3.external_points))
    full_points = Matrix{Float64x3}(undef, 3, num_full_points)
    k = 0
    for g in f3.group
        for col in eachcol(opt3.current_point)
            full_points[:,k+=1] .= g * col
        end
    end
    for point in f3.external_points
        full_points[:,k+=1] .= point
    end
    @assert k == num_full_points

    c2 = spherical_riesz_hessian_spectral_gap(full_points)
    if c2 < 1.0
        c1 = Float64(spherical_riesz_gradient_norm(full_points))
        facets = convex_hull_facets(Float64.(full_points))
        c3 = Float64(parallel_facet_distance(full_points, facets))
        prefix = "PCREO-03-$(lpad(num_full_points, 4, '0'))"
        filename = "$prefix-$(uuid4()).csv"
        open(joinpath("D:\\Data\\PCREOSymmetry", filename), "w+") do io
            println(io, 3)
            println(io, num_full_points)
            println(io, opt3.current_objective_value[])
            println(io, '"', group, '"')
            if !isempty(orbits)<commit_msg>remove hardcoded path from PCREOSearch<commit_after>using DZOptimization: BFGSOptimizer, normalize_columns!
using MultiFloats: Float64x2, Float64x3
using UUIDs: uuid4

push!(LOAD_PATH, @__DIR__)
using PCREO: run!, spherical_riesz_gradient_norm,
    spherical_riesz_hessian_spectral_gap,
    convex_hull_facets, parallel_facet_distance
using PCREOSymmetry: POLYHEDRAL_POINT_GROUPS, symmetrized_riesz_functors


function constrain_sphere!(points)
    normalize_columns!(points)
    return true
end


function generate_and_save_configuration(
        group::Function, orbits::Vector{Function}, num_points::Int)

    initial_points = normalize_columns!(randn(3, num_points))

    f1, g1! = symmetrized_riesz_functors(Float64, group, orbits)
    opt1 = BFGSOptimizer(f1, g1!, constrain_sphere!, initial_points, 1.0e-6)
    run!(opt1)

    f2, g2! = symmetrized_riesz_functors(Float64x2, group, orbits)
    opt2 = BFGSOptimizer(Float64x2, f2, g2!, constrain_sphere!, opt1)
    run!(opt2)

    f3, g3! = symmetrized_riesz_functors(Float64x3, group, orbits)
    opt3 = BFGSOptimizer(Float64x3, f3, g3!, constrain_sphere!, opt2)
    run!(opt3)

    num_full_points = (num_points * length(f3.group) +
                       length(f3.external_points))
    full_points = Matrix{Float64x3}(undef, 3, num_full_points)
    k = 0
    for g in f3.group
        for col in eachcol(opt3.current_point)
            full_points[:,k+=1] .= g * col
        end
    end
    for point in f3.external_points
        full_points[:,k+=1] .= point
    end
    @assert k == num_full_points

    c2 = spherical_riesz_hessian_spectral_gap(full_points)
    if c2 < 1.0
        c1 = Float64(spherical_riesz_gradient_norm(full_points))
        facets = convex_hull_facets(Float64.(full_points))
        c3 = Float64(parallel_facet_distance(full_points, facets))
        prefix = "PCREO-03-$(lpad(num_full_points, 4, '0'))"
        filename = "$prefix-$(uuid4()).csv"
        open(filename, "w+") do io
            println(io, 3)
            println(io, num_full_points)
            println(io, opt3.current_objective_value[])
            println(io, '"', group, '"')
            if !isempty(orbits)
{'fraction_non_alphanumeric': 0.10783410138248847, 'fraction_numerical': 0.035023041474654376, 'mean_word_length': 3.657725321888412, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2712971', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1522, 'n_words': 282}