def __init__(self, verbosity=0, confl_limit=None, threads=None): r""" Constuct a new CryptoMiniSat instance. See the documentation class for the description of inputs. EXAMPLES:: sage: from sage.sat.solvers.cryptominisat import CryptoMiniSat sage: solver = CryptoMiniSat(threads=1) # optional - cryptominisat """ if threads is None: from sage.parallel.ncpus import ncpus threads = ncpus() if confl_limit is None: from sys import maxint confl_limit = maxint try: from pycryptosat import Solver except ImportError: from sage.misc.package import PackageNotFoundError raise PackageNotFoundError("cryptominisat") self._solver = Solver(verbose=int(verbosity), confl_limit=int(confl_limit), threads=int(threads)) self._nvars = 0 self._clauses = []
def __init__(self): r""" Construct the single instance of class Parallelism (singleton model). TESTS:: sage: par = Parallelism() sage: par Number of processes for parallelization: - linbox computations: 1 - tensor computations: 1 Test of the singleton character:: sage: Parallelism() is par True The test suite is passed:: sage: TestSuite(par).run() """ self._default = ncpus( ) # default number of proc. used in parallelizations self._nproc = { 'tensor': 1, 'linbox': 1 } # dict. of number of processes to be used
def points_modulo_primes(X, primes): r""" Return a list of rational points modulo all `p` in primes, computed parallelly. """ normalized_input = [] for p in primes_list: normalized_input.append(((X, p, ), {})) p_iter = p_iter_fork(ncpus()) points_pair = list(p_iter(parallel_function, normalized_input)) points_pair.sort() return [pair[1] for pair in points_pair]
def set(self, nproc=None): r""" Changes the status of the parallelism in tensorial computations. If not argument is given, the number of processors will set to the maximum of cores found. EXAMPLE :: sage: from sage.tensor.modules.parallel_utilities import TensorParallelCompute sage: print TensorParallelCompute() Number of cpu used = 1 sage: TensorParallelCompute().set(4) sage: print TensorParallelCompute() Number of cpu used = 4 sage: TensorParallelCompute().set(1) """ self._nproc = ncpus() if nproc is None else nproc self._use_paral = True if self._nproc != 1 else False
def set(self,nproc=None): r""" Changes the status of the parallelism in tensorial computations. If not argument is given, the number of processors will set to the maximum of cores found. EXAMPLE :: sage: from sage.tensor.modules.parallel_utilities import TensorParallelCompute sage: print TensorParallelCompute() Number of cpu used = 1 sage: TensorParallelCompute().set(4) sage: print TensorParallelCompute() Number of cpu used = 4 sage: TensorParallelCompute().set(1) """ self._nproc = ncpus() if nproc is None else nproc self._use_paral = True if self._nproc!=1 else False
def lift_all_points(): r""" Returns list of all rational points lifted parallely. """ normalized_input = [] points = modulo_points.pop() # remove the list of points corresponding to largest prime len_modulo_points.pop() for point in points: normalized_input.append(( (point, ), {})) p_iter = p_iter_fork(ncpus()) points_satisfying = list(p_iter(parallel_function_combination, normalized_input)) lifted_points = set() for pair in points_satisfying: L = pair[1] for point in L: lifted_points.add(X(tuple(point))) return list(lifted_points)
def __init__(self, verbosity=0, confl_limit=None, threads=None): r""" Construct a new CryptoMiniSat instance. See the documentation class for the description of inputs. EXAMPLES:: sage: from sage.sat.solvers.cryptominisat import CryptoMiniSat sage: solver = CryptoMiniSat(threads=1) # optional - pycryptosat """ if threads is None: from sage.parallel.ncpus import ncpus threads = ncpus() if confl_limit is None: from sys import maxsize confl_limit = maxsize self._solver = Solver(verbose=int(verbosity), confl_limit=int(confl_limit), threads=int(threads)) self._nvars = 0 self._clauses = []
def points_modulo_primes(X, primes): r""" Return a list of rational points modulo all p in primes parallel implementation """ normalized_input = [] for p in primes: normalized_input.append((( X, p, ), {})) p_iter = p_iter_fork(ncpus()) points_pair = list(p_iter(parallel_function, normalized_input)) points_pair.sort() modulo_points = [] for pair in points_pair: modulo_points.append(pair[1]) return modulo_points
def reset(self): r""" Put the singleton object ``Parallelism()`` in the same state as immediately after its creation. EXAMPLES: State of ``Parallelism()`` just after its creation:: sage: Parallelism() Number of processes for parallelization: - linbox computations: 1 - tensor computations: 1 sage: Parallelism().get_default() # random (depends on the computer) 8 Changing some values:: sage: Parallelism().set_default(6) sage: Parallelism().set() sage: Parallelism() Number of processes for parallelization: - linbox computations: 6 - tensor computations: 6 sage: Parallelism().get_default() 6 Back to the initial state:: sage: Parallelism().reset() sage: Parallelism() Number of processes for parallelization: - linbox computations: 1 - tensor computations: 1 sage: Parallelism().get_default() # random (depends on the computer) 8 """ self._default = ncpus() for field in self._nproc: self._nproc[field] = 1
def set_default(self, nproc=None): r""" Set the default number of processes to be launched in parallel computations. INPUT: - ``nproc`` -- (default: ``None``) default number of processes; if ``None``, the number of processes will be set to the total number of cores found on the computer. EXAMPLES: A priori the default number of process for parallelization is the total number of cores found on the computer:: sage: Parallelism().get_default() # random (depends on the computer) 8 Changing it thanks to ``set_default``:: sage: Parallelism().set_default(nproc=4) sage: Parallelism().get_default() 4 Setting it back to the total number of cores available on the computer:: sage: Parallelism().set_default() sage: Parallelism().get_default() # random (depends on the computer) 8 """ if nproc is None: self._default = ncpus() else: if not isinstance(nproc,(int,Integer)): raise TypeError("nproc must be integer") self._default = nproc
def reset(self): r""" Put the singleton object ``Parallelism()`` in the same state as immediately after its creation. EXAMPLE: State of ``Parallelism()`` just after its creation:: sage: Parallelism() Number of processes for parallelization: - tensor computations: 1 sage: Parallelism().get_default() # random (depends on the computer) 8 Changing some values:: sage: Parallelism().set_default(6) sage: Parallelism().set() sage: Parallelism() Number of processes for parallelization: - tensor computations: 6 sage: Parallelism().get_default() 6 Back to the initial state:: sage: Parallelism().reset() sage: Parallelism() Number of processes for parallelization: - tensor computations: 1 sage: Parallelism().get_default() # random (depends on the computer) 8 """ self._default = ncpus() for field in self._nproc: self._nproc[field] = 1
def __init__(self): r""" Construct the single instance of class Parallelism (singleton model). TEST:: sage: par = Parallelism() sage: par Number of processes for parallelization: - tensor computations: 1 Test of the singleton character:: sage: Parallelism() is par True The test suite is passed:: sage: TestSuite(par).run() """ self._default = ncpus() # default number of proc. used in parallelizations self._nproc = {'tensor' : 1} # dict. of number of processes to be used
def calc_herm_modforms(**kwargs): kwargs = kwargs.copy() from sage.parallel.ncpus import ncpus for key,value in { "D": -3, "HermWeight": 6, "B_cF": 7, "task_limit": ncpus(), }.items(): if not key in kwargs: kwargs[key] = value print "Calculating Hermitian modular forms with %r" % kwargs import algo modforms = algo.herm_modform_space__parallel(**kwargs) assert modforms import utils utils.save( modforms, "herm_modforms__D%i_k%i_B%i__%i.sobj" % (kwargs["D"], kwargs["HermWeight"], kwargs["B_cF"], modforms.degree()) ) print modforms sys.exit(0)
def best_simultaneous_convergents_upto(v, Q, start=1, verbose=False): r""" Return a list of all best simultaneous diophantine approximations p,q of vector ``v`` at distance ``|qv-p|<=1/Q`` such that `1<=q<Q^d`. INPUT: - ``v`` -- list of real numbers - ``Q`` -- real number, Q>1 - ``start`` -- integer (default: ``1``), starting value to check - ``verbose`` -- boolean (default: ``False``) EXAMPLES:: sage: from slabbe.diophantine_approx import best_simultaneous_convergents_upto sage: best_simultaneous_convergents_upto([e,pi], 2) [((3, 3, 1), 3.549646778303845)] sage: best_simultaneous_convergents_upto([e,pi], 4) [((19, 22, 7), 35.74901433260719)] sage: best_simultaneous_convergents_upto([e,pi], 36, start=4**2) [((1843, 2130, 678), 203.23944293852406)] sage: best_simultaneous_convergents_upto([e,pi], 204, start=36**2) [((51892, 59973, 19090), 266.16775098010373), ((113018, 130618, 41577), 279.18598227531174)] sage: best_simultaneous_convergents_upto([e,pi], 280, start=204**2) [((114861, 132748, 42255), 412.7859137824949), ((166753, 192721, 61345), 749.3634909055199)] sage: best_simultaneous_convergents_upto([e,pi], 750, start=280**2) [((446524, 516060, 164267), 896.4734658499202), ((1174662, 1357589, 432134), 2935.314937919726)] sage: best_simultaneous_convergents_upto([e,pi], 2936, start=750**2) [((3970510, 4588827, 1460669), 3654.2989332956854), ((21640489, 25010505, 7961091), 6257.014011585661)] TESTS:: sage: best_simultaneous_convergents_upto([e,pi], 102300.1, start=10^9) # not tested (1 min) [((8457919940, 9775049397, 3111494861), 194686.19839453633)] """ from slabbe.diophantine_approx_pyx import good_simultaneous_convergents_upto from sage.parallel.decorate import parallel from sage.parallel.ncpus import ncpus step = ncpus() @parallel def F(shift): return good_simultaneous_convergents_upto(v, Q, start + shift, step=step) shifts = range(step) goods = [] for (arg, kwds), output in F(shifts): if output == 'NO DATA': print( "problem with v={}, Q={}, start={}, shift={}" " because output={}".format(v, Q, start, arg[0], output)) else: goods.extend(output) if not goods: raise ValueError( "Did not find an approximation p,q to v={} s.t. |p-qv|<=1/Q" " where Q={}".format(v, Q)) goods.sort() bests = [] best_error_inv = 0 # keep only the best ones for q in goods: q_v = [q * a for a in v] frac_q_v = [a - floor(a) for a in q_v] error = max((a if a < .5 else 1 - a) for a in frac_q_v) error_inv = 1. / error.n(digits=50) if verbose: print "q={}, error_inv={}, best_error_inv={}".format( q, error_inv, best_error_inv) if error_inv > best_error_inv: p = [round(a) for a in q_v] p.append(q) bests.append((tuple(p), error_inv)) best_error_inv = error_inv return bests
def func(Z, p): Xp = Z.change_ring(GF(p)) L = Xp.rational_points() return [list(t) for t in L] %time from sage.parallel.ncpus import ncpus from sage.parallel.use_fork import p_iter_fork P.<x,y,z,q>=ProjectiveSpace(QQ,3) Y=P.subscheme([x^2-3^2*y^2+z*q,x+z+4*q]) normalized_input = [] for q in primes(1,30): normalized_input.append(((Y, q, ), {})) # LL = func(Y,q) p_iter = p_iter_fork(ncpus()) points_pair = list(p_iter(func, normalized_input)) points_pair.sort() #print points_pair modulo_points = [] for pair in points_pair: modulo_points.append(pair[1]) #print modulo_points