-
Notifications
You must be signed in to change notification settings - Fork 33
/
plain_sieve.py
executable file
·109 lines (87 loc) · 3.08 KB
/
plain_sieve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
# -*- coding: utf-8 -*-
####
#
# Copyright (C) 2018-2021 Team G6K
#
# This file is part of G6K. G6K is free software:
# you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation,
# either version 2 of the License, or (at your option) any later version.
#
# G6K is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with G6K. If not, see <http://www.gnu.org/licenses/>.
#
####
"""
Plain Sieve Command Line Client
"""
from __future__ import absolute_import
import logging
import pickle as pickler
from collections import OrderedDict
from g6k.siever import Siever
from g6k.utils.cli import parse_args, run_all
from g6k.utils.stats import SieveTreeTracer
from g6k.utils.util import load_svpchallenge_and_randomize, db_stats
from g6k.utils.util import sanitize_params_names, print_stats, output_profiles, db_stats
import six
def plain_sieve_kernel(arg0, params=None, seed=None):
# Pool.map only supports a single parameter
if params is None and seed is None:
n, params, seed = arg0
else:
n = arg0
alg = params.pop("alg")
reserved_n = n
params = params.new(reserved_n=reserved_n, otf_lift=False)
A, _ = load_svpchallenge_and_randomize(n, s=0, seed=seed)
g6k = Siever(A, params, seed=seed)
tracer = SieveTreeTracer(g6k, root_label=("plain-sieve", n), start_clocks=True)
g6k.initialize_local(0, 0, n)
g6k(alg=alg, tracer=tracer)
tracer.exit()
return tracer.trace
def plain_sieve():
"""
Run a a plain sieve in the full dimension directly.
"""
description = plain_sieve.__doc__
args, all_params = parse_args(description)
stats = run_all(
plain_sieve_kernel,
list(all_params.values()),
lower_bound=args.lower_bound,
upper_bound=args.upper_bound,
step_size=args.step_size,
trials=args.trials,
workers=args.workers,
seed=args.seed,
)
inverse_all_params = OrderedDict([(v, k) for (k, v) in six.iteritems(all_params)])
inverse_all_params = OrderedDict([(v, k) for (k, v) in six.iteritems(all_params)])
stats = sanitize_params_names(stats, inverse_all_params)
fmt = "{name:50s} :: n: {n:2d}, cputime {cputime:7.4f}s, walltime: {walltime:7.4f}s, |db|: 2^{avg_max:.2f}"
profiles = print_stats(
fmt,
stats,
("cputime", "walltime", "avg_max"),
extractf={"avg_max": lambda n, params, stat: db_stats(stat)[0]},
)
output_profiles(args.profile, profiles)
if args.pickle:
pickler.dump(
stats,
open(
"plain-sieve-%d-%d-%d-%d.sobj"
% (args.lower_bound, args.upper_bound, args.step_size, args.trials),
"wb",
),
)
if __name__ == "__main__":
plain_sieve()