GroupsWithPropertyT/SL_orbit.jl

204 lines
5.6 KiB
Julia
Raw Normal View History

2017-06-22 15:18:26 +02:00
using ArgParse
2017-09-10 15:41:49 +02:00
using SCS.SCSSolver
2017-11-03 16:37:45 +01:00
# using Mosek
2017-06-22 15:18:26 +02:00
using Nemo
if VERSION >= v"0.6.0"
import Nemo.Generic.perm
end
2017-06-22 15:18:26 +02:00
using PropertyT
using Groups
2017-06-08 20:09:36 +02:00
###############################################################################
#
# Action of WreathProductElems on Nemo.MatElem
#
###############################################################################
2017-06-22 15:18:26 +02:00
function matrix_emb(MM::MatSpace, g::WreathProductElem)
2017-06-08 20:09:36 +02:00
parent(g).P.n == MM.cols == MM.rows || throw("No natural embedding of $(parent(g)) in ")
powers = [(elt == parent(elt)() ? 0: 1) for elt in g.n.elts]
elt = diagm([(-1)^(elt == parent(elt)() ? 0: 1) for elt in g.n.elts])
return MM(elt)*MM(Nemo.matrix_repr(g.p)')
end
2017-06-22 15:18:26 +02:00
function (g::WreathProductElem)(A::MatElem)
2017-06-08 20:09:36 +02:00
G = matrix_emb(parent(A), g)
inv_G = matrix_emb(parent(A), inv(g))
return G*A*inv_G
end
2017-06-22 15:18:26 +02:00
function (p::perm)(A::MatElem)
2017-06-09 22:03:35 +02:00
length(p.d) == A.r == A.c || throw("Can't act via $p on matrix of size ($(A.r), $(A.c))")
R = parent(A)
return p*A*inv(p)
2017-06-09 22:03:35 +02:00
end
2017-06-08 20:09:36 +02:00
###############################################################################
#
# Generating set
#
###############################################################################
function E(i::Int, j::Int, M::MatSpace, val=one(M.base_ring))
2017-06-08 20:09:36 +02:00
@assert i≠j
m = one(M)
m[i,j] = val
2017-06-08 20:09:36 +02:00
return m
end
function SLsize(n,p)
result = BigInt(1)
for k in 0:n-1
result *= p^n - p^k
end
return div(result, p-1)
end
function SL_generatingset(n::Int, X::Bool=false)
indexing = [(i,j) for i in 1:n for j in 1:n if i≠j]
G = MatrixSpace(ZZ, n, n)
if X
S = [E(i,j,G,v) for (i,j) in indexing for v in [1, 100]]
else
S = [E(i,j,G,v) for (i,j) in indexing for v in [1]]
end
S = vcat(S, [inv(x) for x in S])
return G, unique(S)
2017-06-08 20:09:36 +02:00
end
function SL_generatingset(n::Int, p::Int, X::Bool=false)
p == 0 && return SL_generatingset(n, X)
2017-06-08 20:09:36 +02:00
(p > 1 && n > 1) || throw("Both n and p should be positive integers!")
info("Size(SL($n,$p)) = $(SLsize(n,p))")
2017-06-22 15:18:26 +02:00
F = ResidueRing(ZZ, p)
G = MatrixSpace(F, n, n)
2017-06-08 20:09:36 +02:00
indexing = [(i,j) for i in 1:n for j in 1:n if i≠j]
S = [E(i, j, G) for (i,j) in indexing]
S = vcat(S, [inv(x) for x in S])
2017-06-08 20:09:36 +02:00
return G, unique(S)
end
###############################################################################
#
# Parsing command line
#
###############################################################################
2017-09-10 15:41:49 +02:00
function cpuinfo_physicalcores()
maxcore = -1
for line in eachline("/proc/cpuinfo")
if startswith(line, "core id")
maxcore = max(maxcore, parse(Int, split(line, ':')[2]))
end
end
maxcore < 0 && error("failure to read core ids from /proc/cpuinfo")
return maxcore + 1
end
2017-06-08 20:09:36 +02:00
function parse_commandline()
settings = ArgParseSettings()
@add_arg_table settings begin
"--tol"
2017-09-10 15:41:49 +02:00
help = "set numerical tolerance for the SDP solver"
2017-06-08 20:09:36 +02:00
arg_type = Float64
default = 1e-14
2017-06-08 20:09:36 +02:00
"--iterations"
help = "set maximal number of iterations for the SDP solver (default: 20000)"
arg_type = Int
default = 200000
2017-06-08 20:09:36 +02:00
"--upper-bound"
2017-09-10 15:41:49 +02:00
help = "Set an upper bound for the spectral gap"
2017-06-08 20:09:36 +02:00
arg_type = Float64
default = Inf
"--cpus"
2017-09-10 15:41:49 +02:00
help = "Set number of cpus used by solver"
2017-06-08 20:09:36 +02:00
arg_type = Int
required = false
"-N"
2017-09-10 15:41:49 +02:00
help = "Consider elementary matrices EL(N)"
2017-06-08 20:09:36 +02:00
arg_type = Int
default = 2
"-p"
2017-09-10 15:41:49 +02:00
help = "Matrices over field of p-elements (p=0 => over ZZ)"
2017-06-08 20:09:36 +02:00
arg_type = Int
default = 0
"--radius"
2017-09-10 15:41:49 +02:00
help = "Radius of ball B_r(e,S) to find solution over"
2017-06-08 20:09:36 +02:00
arg_type = Int
default = 2
"-X"
2017-09-10 15:41:49 +02:00
help = "Consider EL(N, ZZ⟨X⟩)"
action = :store_true
2017-06-08 20:09:36 +02:00
end
return parse_args(settings)
end
###############################################################################
#
# main
#
###############################################################################
function main()
parsed_args = parse_commandline()
2017-09-10 15:41:49 +02:00
if parsed_args["cpus"] nothing
if parsed_args["cpus"] > cpuinfo_physicalcores()
warn("Number of specified cores exceeds the physical core cound. Performance will suffer.")
end
BLAS.set_num_threads(parsed_args["cpus"])
end
2017-06-08 20:09:36 +02:00
N = parsed_args["N"]
p = parsed_args["p"]
if p == 0
if parsed_args["X"]
dirname = "oSL$(N)Z⟨X⟩"
else
dirname = "oSL$(N)Z"
end
2017-06-08 20:09:36 +02:00
else
2017-06-08 21:35:50 +02:00
dirname = "oSL$(N)_$p"
2017-06-08 20:09:36 +02:00
end
radius = parsed_args["radius"]
2017-06-08 21:44:20 +02:00
tol = parsed_args["tol"]
iterations = parsed_args["iterations"]
upper_bound = parsed_args["upper-bound"]
2017-06-08 20:09:36 +02:00
dirname = "$(dirname)_r$radius"
isdir(dirname) || mkdir(dirname)
2017-06-09 12:00:41 +02:00
logger = PropertyT.setup_logging(joinpath(dirname, "$(upper_bound)"))
2017-06-08 20:09:36 +02:00
2017-06-08 21:44:20 +02:00
info(logger, "Group: $dirname")
info(logger, "Iterations: $iterations")
info(logger, "Precision: $tol")
info(logger, "Upper bound: $upper_bound")
G, S = SL_generatingset(N, p, parsed_args["X"])
2017-06-08 20:09:36 +02:00
info(logger, G)
info(logger, "Symmetric generating set of size $(length(S))")
2017-09-10 15:41:49 +02:00
# info(logger, S)
2017-06-22 15:18:26 +02:00
AutS = WreathProduct(FiniteField(2,1, "a")[1], PermutationGroup(N))
2017-06-09 22:03:35 +02:00
# AutS = PermutationGroup(N)
2017-06-08 20:09:36 +02:00
2017-09-10 15:41:49 +02:00
solver = SCSSolver(eps=tol, max_iters=iterations, linearsolver=SCS.Direct)
2017-11-03 16:37:45 +01:00
# solver = Mosek.MosekSolver(
# MSK_DPAR_INTPNT_CO_TOL_REL_GAP=tol,
# MSK_IPAR_INTPNT_MAX_ITERATIONS=iterations,
# QUIET=false)
2017-06-08 20:09:36 +02:00
2017-06-08 21:35:27 +02:00
sett = Settings(dirname, N, G, S, AutS, radius, solver, upper_bound, tol)
2017-06-22 15:18:26 +02:00
PropertyT.check_property_T(sett)
2017-06-08 20:09:36 +02:00
end
main()