def standard_start_diagonal_cascade(gamma=0, tasks=0): r""" Does the path tracking to start a diagonal cascade in standard double precision. For this to work, the functions standard_diagonal_homotopy and standard_diagonal_cascade_solutions must be executed successfully. If *gamma* equals 0 on input, then a random gamma constant is generated, otherwise, the given complex *gamma* will be used in the homotopy. Multitasking is available, and activated by the *tasks* parameter. Returns the target (system and its corresponding) solutions. """ from phcpy.phcpy2c2 import py2c_create_standard_homotopy from phcpy.phcpy2c2 import py2c_create_standard_homotopy_with_gamma from phcpy.phcpy2c2 import py2c_solve_by_standard_homotopy_continuation from phcpy.phcpy2c2 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c2 import py2c_syscon_clear_standard_system from phcpy.phcpy2c2 import py2c_copy_standard_target_solutions_to_container from phcpy.phcpy2c2 import py2c_copy_standard_target_system_to_container from phcpy.interface import load_standard_solutions from phcpy.interface import load_standard_system if (gamma == 0): py2c_create_standard_homotopy() else: py2c_create_standard_homotopy_with_gamma(gamma.real, gamma.imag) py2c_solve_by_standard_homotopy_continuation(tasks) py2c_solcon_clear_standard_solutions() py2c_syscon_clear_standard_system() py2c_copy_standard_target_solutions_to_container() # from phcpy.phcpy2c2 import py2c_write_standard_target_system # print 'the standard target system :' # py2c_write_standard_target_system() py2c_copy_standard_target_system_to_container() tsys = load_standard_system() sols = load_standard_solutions() return (tsys, sols)
def standard_littlewood_richardson_homotopies( ndim, kdim, brackets, verbose=True, vrfcnd=False, minrep=True, tosqr=False, outputfilename="" ): r""" In n-dimensional space we consider k-dimensional planes, subject to intersection conditions represented by brackets. The parameters *ndim* and *kdim* give values for n and k respectively. The parameter *brackets* is a list of brackets. A bracket is a list of as many natural numbers (in the range 1..*ndim*) as *kdim*. The Littlewood-Richardson homotopies compute k-planes that meet the flags at spaces of dimensions prescribed by the brackets, in standard double precision. Four options are passed as Booleans: *verbose*: for adding extra output during computations, *vrfcnd*: for extra diagnostic verification of Schubert conditions, *minrep*: for a minimial representation of the problem formulation, *tosqr*: to square the overdetermined systems. On return is a 4-tuple. The first item of the tuple is the formal root count, sharp for general flags, then as second item the coordinates of the flags. The coordinates of the flags are stored row wise in a list of real and imaginary parts. The third and fourth item of the tuple on return are respectively the polynomial system that has been solved and its solutions. The length of the list of solution should match the root count. """ from phcpy.phcpy2c2 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c2 import py2c_schubert_standard_littlewood_richardson_homotopies as stlrhom from phcpy.interface import load_standard_solutions, load_standard_system py2c_solcon_clear_standard_solutions() nbc = len(brackets) cds = "" for bracket in brackets: for num in bracket: cds = cds + " " + str(num) # print 'the condition string :', cds (roco, sflags) = stlrhom( ndim, kdim, nbc, len(cds), cds, int(verbose), int(vrfcnd), int(minrep), int(tosqr), len(outputfilename), outputfilename, ) rflags = eval(sflags) flgs = [] for k in range(len(rflags) / 2): flgs.append(complex(rflags[2 * k], rflags[2 * k + 1])) fsys = load_standard_system() sols = load_standard_solutions() return (roco, flgs, fsys, sols)
def standard_double_cascade_step(dim, embsys, esols, tasks=0): r""" Given in *embsys* an embedded polynomial system and solutions with nonzero slack variables in *esols*, does one step in the homotopy cascade, with standard double precision arithmetic. The dimension of the solution set represented by *embsys* and *esols* is the value of *dim*. The number of tasks in multithreaded path tracking is given by *tasks*. The default zero value of *tasks* indicates no multithreading. The list on return contains witness points on lower dimensional solution components. """ from phcpy.phcpy2c2 import py2c_copy_standard_container_to_start_system from phcpy.phcpy2c2 import py2c_copy_standard_container_to_start_solutions from phcpy.phcpy2c2 import py2c_standard_cascade_homotopy from phcpy.phcpy2c2 import py2c_solve_by_standard_homotopy_continuation from phcpy.phcpy2c2 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c2 import py2c_copy_standard_target_solutions_to_container from phcpy.interface import store_standard_witness_set from phcpy.interface import load_standard_solutions store_standard_witness_set(len(embsys), dim, embsys, esols) py2c_copy_standard_container_to_start_system() py2c_copy_standard_container_to_start_solutions() py2c_standard_cascade_homotopy() py2c_solve_by_standard_homotopy_continuation(tasks) py2c_solcon_clear_standard_solutions() py2c_copy_standard_target_solutions_to_container() return load_standard_solutions()
def standard_start_diagonal_cascade(gamma=0, tasks=0): r""" Does the path tracking to start a diagonal cascade in standard double precision. For this to work, the functions standard_diagonal_homotopy and standard_diagonal_cascade_solutions must be executed successfully. If *gamma* equals 0 on input, then a random gamma constant is generated, otherwise, the given complex *gamma* will be used in the homotopy. Multitasking is available, and activated by the *tasks* parameter. Returns the target (system and its corresponding) solutions. """ from phcpy.phcpy2c2 import py2c_create_standard_homotopy from phcpy.phcpy2c2 import py2c_create_standard_homotopy_with_gamma from phcpy.phcpy2c2 import py2c_solve_by_standard_homotopy_continuation from phcpy.phcpy2c2 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c2 import py2c_syscon_clear_standard_system from phcpy.phcpy2c2 import py2c_copy_standard_target_solutions_to_container from phcpy.phcpy2c2 import py2c_copy_standard_target_system_to_container from phcpy.interface import load_standard_solutions from phcpy.interface import load_standard_system if(gamma == 0): py2c_create_standard_homotopy() else: py2c_create_standard_homotopy_with_gamma(gamma.real, gamma.imag) py2c_solve_by_standard_homotopy_continuation(tasks) py2c_solcon_clear_standard_solutions() py2c_syscon_clear_standard_system() py2c_copy_standard_target_solutions_to_container() # from phcpy.phcpy2c2 import py2c_write_standard_target_system # print 'the standard target system :' # py2c_write_standard_target_system() py2c_copy_standard_target_system_to_container() tsys = load_standard_system() sols = load_standard_solutions() return (tsys, sols)
def standard_solve(pols, silent=False, tasks=0): """ Calls the blackbox solver. On input in pols is a list of strings. By default, the solver will print to screen the computed root counts. To make the solver silent, set the flag silent to True. The number of tasks for multithreading is given by tasks. The solving happens in standard double precision arithmetic. """ from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system from phcpy.phcpy2c3 \ import py2c_syscon_initialize_number_of_standard_Laurentials from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c3 import py2c_solve_Laurent_system from phcpy.interface import load_standard_solutions py2c_syscon_clear_standard_Laurent_system() py2c_solcon_clear_standard_solutions() dim = len(pols) py2c_syscon_initialize_number_of_standard_Laurentials(dim) for ind in range(0, dim): pol = pols[ind] nchar = len(pol) py2c_syscon_store_standard_Laurential(nchar, dim, ind+1, pol) py2c_solve_Laurent_system(silent, tasks) return load_standard_solutions()
def standard_laursys_solve(pols, topdim=-1, \ filter=True, factor=True, tasks=0, verbose=True): """ Runs the cascades of homotopies on the Laurent polynomial system in pols in standard double precision. The default top dimension topdim is the number of variables in pols minus one. """ from phcpy.phcpy2c3 import py2c_standard_laursys_solve from phcpy.phcpy2c3 import py2c_copy_standard_laursys_witset from phcpy.solver import number_of_symbols from phcpy.interface import store_standard_laurent_system from phcpy.interface import load_standard_laurent_system from phcpy.interface import load_standard_solutions dim = number_of_symbols(pols) if(topdim == -1): topdim = dim - 1 fail = store_standard_laurent_system(pols, nbvar=dim) fail = py2c_standard_laursys_solve(tasks,topdim, \ int(filter),int(factor),int(verbose)) witsols = [] for soldim in range(0, topdim+1): fail = py2c_copy_standard_laursys_witset(soldim) witset = (load_standard_laurent_system(), load_standard_solutions()) witsols.append(witset) return witsols
def standard_solve(pols, silent=False, tasks=0): """ Calls the blackbox solver. On input in pols is a list of strings. By default, the solver will print to screen the computed root counts. To make the solver silent, set the flag silent to True. The number of tasks for multithreading is given by tasks. The solving happens in standard double precision arithmetic. """ from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system from phcpy.phcpy2c3 \ import py2c_syscon_initialize_number_of_standard_Laurentials from phcpy.phcpy2c3 import py2c_syscon_store_standard_Laurential from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c3 import py2c_solve_Laurent_system from phcpy.interface import load_standard_solutions py2c_syscon_clear_standard_Laurent_system() py2c_solcon_clear_standard_solutions() dim = len(pols) py2c_syscon_initialize_number_of_standard_Laurentials(dim) for ind in range(0, dim): pol = pols[ind] nchar = len(pol) py2c_syscon_store_standard_Laurential(nchar, dim, ind + 1, pol) py2c_solve_Laurent_system(silent, tasks) return load_standard_solutions()
def standard_laursys_solve(pols, topdim=-1, \ filter=True, factor=True, tasks=0, verbose=True): """ Runs the cascades of homotopies on the Laurent polynomial system in pols in standard double precision. The default top dimension topdim is the number of variables in pols minus one. """ from phcpy.phcpy2c3 import py2c_standard_laursys_solve from phcpy.phcpy2c3 import py2c_copy_standard_laursys_witset from phcpy.solver import number_of_symbols from phcpy.interface import store_standard_laurent_system from phcpy.interface import load_standard_laurent_system from phcpy.interface import load_standard_solutions dim = number_of_symbols(pols) if (topdim == -1): topdim = dim - 1 fail = store_standard_laurent_system(pols, nbvar=dim) fail = py2c_standard_laursys_solve(tasks,topdim, \ int(filter),int(factor),int(verbose)) witsols = [] for soldim in range(0, topdim + 1): fail = py2c_copy_standard_laursys_witset(soldim) witset = (load_standard_laurent_system(), load_standard_solutions()) witsols.append(witset) return witsols
def newton_laurent_step(system, solutions, precision='d', decimals=100): """ Applies one Newton step to the solutions of the Laurent system. For each solution, prints its last line of diagnostics. Four levels of precision are supported: d : standard double precision (1.1e-15 or 2^(-53)), dd : double double precision (4.9e-32 or 2^(-104)), qd : quad double precision (1.2e-63 or 2^(-209)). mp : arbitrary precision, where the number of decimal places in the working precision is determined by decimals. """ dim = number_of_symbols(system) if (precision == 'd'): from phcpy.interface import store_standard_laurent_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_laurent_system(system, nbvar=dim) store_standard_solutions(dim, solutions) from phcpy.phcpy2c3 import py2c_standard_Newton_Laurent_step py2c_standard_Newton_Laurent_step() result = load_standard_solutions() elif (precision == 'dd'): from phcpy.interface import store_dobldobl_laurent_system from phcpy.interface import store_dobldobl_solutions from phcpy.interface import load_dobldobl_solutions store_dobldobl_laurent_system(system, nbvar=dim) store_dobldobl_solutions(dim, solutions) from phcpy.phcpy2c3 import py2c_dobldobl_Newton_Laurent_step py2c_dobldobl_Newton_Laurent_step() result = load_dobldobl_solutions() elif (precision == 'qd'): from phcpy.interface import store_quaddobl_laurent_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions store_quaddobl_laurent_system(system, nbvar=dim) store_quaddobl_solutions(dim, solutions) from phcpy.phcpy2c3 import py2c_quaddobl_Newton_Laurent_step py2c_quaddobl_Newton_Laurent_step() result = load_quaddobl_solutions() elif (precision == 'mp'): from phcpy.interface import store_multprec_laurent_system from phcpy.interface import store_multprec_solutions from phcpy.interface import load_multprec_solutions store_multprec_laurent_system(system, decimals, nbvar=dim) store_multprec_solutions(dim, solutions) from phcpy.phcpy2c3 import py2c_multprec_Newton_Laurent_step py2c_multprec_Newton_Laurent_step(decimals) result = load_multprec_solutions() else: print('wrong argument for precision') return None for sol in result: strsol = sol.split('\n') print(strsol[-1]) return result
def newton_laurent_step(system, solutions, precision='d', decimals=100): """ Applies one Newton step to the solutions of the Laurent system. For each solution, prints its last line of diagnostics. Four levels of precision are supported: d : standard double precision (1.1e-15 or 2^(-53)), dd : double double precision (4.9e-32 or 2^(-104)), qd : quad double precision (1.2e-63 or 2^(-209)). mp : arbitrary precision, where the number of decimal places in the working precision is determined by decimals. """ if(precision == 'd'): from phcpy.interface import store_standard_laurent_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_laurent_system(system) store_standard_solutions(len(system), solutions) from phcpy.phcpy2c3 import py2c_standard_Newton_Laurent_step py2c_standard_Newton_Laurent_step() result = load_standard_solutions() elif(precision == 'dd'): from phcpy.interface import store_dobldobl_laurent_system from phcpy.interface import store_dobldobl_solutions from phcpy.interface import load_dobldobl_solutions store_dobldobl_laurent_system(system) store_dobldobl_solutions(len(system), solutions) from phcpy.phcpy2c3 import py2c_dobldobl_Newton_Laurent_step py2c_dobldobl_Newton_Laurent_step() result = load_dobldobl_solutions() elif(precision == 'qd'): from phcpy.interface import store_quaddobl_laurent_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions store_quaddobl_laurent_system(system) store_quaddobl_solutions(len(system), solutions) from phcpy.phcpy2c3 import py2c_quaddobl_Newton_Laurent_step py2c_quaddobl_Newton_Laurent_step() result = load_quaddobl_solutions() elif(precision == 'mp'): from phcpy.interface import store_multprec_laurent_system from phcpy.interface import store_multprec_solutions from phcpy.interface import load_multprec_solutions store_multprec_laurent_system(system, decimals) store_multprec_solutions(len(system), solutions) from phcpy.phcpy2c3 import py2c_multprec_Newton_Laurent_step py2c_multprec_Newton_Laurent_step(decimals) result = load_multprec_solutions() else: print('wrong argument for precision') return None for sol in result: strsol = sol.split('\n') print(strsol[-1]) return result
def standard_usolve(pol, mxi, eps): """ Applies the method of Durand-Kerner (aka Weierstrass) to the polynomial in the string pol, in standard double precision The maximum number of iterations is in mxi, the requirement on the accuracy in eps. """ from phcpy.phcpy2c3 import py2c_usolve_standard from phcpy.interface import store_standard_system, load_standard_solutions store_standard_system([pol]) nit = py2c_usolve_standard(mxi, eps) rts = load_standard_solutions() return (nit, rts)
def standard_littlewood_richardson_homotopies(ndim, kdim, brackets, \ verbose=True, vrfcnd=False, minrep=True, tosqr=False, outputfilename=''): r""" In n-dimensional space we consider k-dimensional planes, subject to intersection conditions represented by brackets. The parameters *ndim* and *kdim* give values for n and k respectively. The parameter brackets is a list of brackets. A bracket is a list of as many natural numbers (in the range 1..*ndim*) as *kdim*. The Littlewood-Richardson homotopies compute k-planes that meet the flags at spaces of dimensions prescribed by the brackets, in standard double precision. Four options are passed as Booleans: *verbose*: for adding extra output during computations, *vrfcnd*: for extra diagnostic verification of Schubert conditions, *minrep*: for a minimial representation of the problem formulation, *tosqr*: to square the overdetermined systems. On return is a 4-tuple. The first item of the tuple is the formal root count, sharp for general flags, then as second item the coordinates of the flags. The coordinates of the flags are stored row wise in a list of real and imaginary parts. The third and fourth item of the tuple on return are respectively the polynomial system that has been solved and its solutions. The length of the list of solution should match the root count. """ from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c3 \ import py2c_schubert_standard_littlewood_richardson_homotopies \ as stlrhom from phcpy.interface import load_standard_solutions, load_standard_system py2c_solcon_clear_standard_solutions() nbc = len(brackets) cds = '' for bracket in brackets: for num in bracket: cds = cds + ' ' + str(num) # print 'the condition string :', cds (roco, sflags) = stlrhom(ndim, kdim, nbc, len(cds), cds, \ int(verbose), int(vrfcnd), int(minrep), int(tosqr), \ len(outputfilename), outputfilename) rflags = eval(sflags) flgs = [] for k in range(len(rflags)//2): flgs.append(complex(rflags[2*k], rflags[2*k+1])) fsys = load_standard_system() sols = load_standard_solutions() return (roco, flgs, fsys, sols)
def standard_scale_solutions(nvar, sols, cffs): """ Scales the solutions in the list sols using the coefficients in cffs, using standard double precision arithmetic. The number of variables is given in the parameter nvar. If the sols are the solution of the polynomials in the output of standard_scale_system(pols), then the solutions on return will be solutions of the original polynomials in the list pols. """ from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions from phcpy.phcpy2c3 import py2c_scale_standard_solutions store_standard_solutions(nvar, sols) py2c_scale_standard_solutions(len(cffs), str(cffs)) return load_standard_solutions()
def ade_tuned_double_track(target, start, sols, pars, gamma=0, verbose=1): r""" Does path tracking with algorithm differentiation, in standard double precision, with tuned parameters in pars. On input are a target system, a start system with solutions. The *target* is a list of strings representing the polynomials of the target system (which has to be solved). The *start* is a list of strings representing the polynomials of the start system, with known solutions in *sols*. The *sols* is a list of strings representing start solutions. The *pars* is a tuple of 14 values for the path parameters. On return are the string representations of the solutions computed at the end of the paths. If *gamma* on input equals zero, then a random complex number is generated, otherwise the real and imaginary parts of *gamma* are used. """ from phcpy.phcpy2c3 import py2c_copy_standard_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_standard_container_to_start_system from phcpy.phcpy2c3 import py2c_ade_manypaths_d_pars from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_system(target) py2c_copy_standard_container_to_target_system() store_standard_system(start) py2c_copy_standard_container_to_start_system() dim = len(start) store_standard_solutions(dim, sols) if(gamma == 0): from random import uniform from cmath import exp, pi angle = uniform(0, 2*pi) gamma = exp(angle*complex(0, 1)) if(verbose > 0): print('random gamma constant :', gamma) if(verbose > 0): print('the path parameters :\n', pars) fail = py2c_ade_manypaths_d_pars(verbose, gamma.real, gamma.imag, \ pars[0], pars[1], pars[2], pars[3], pars[4], pars[5], pars[6], \ pars[7], pars[8], pars[9], pars[10], pars[11], pars[12], pars[13]) if(fail == 0): if(verbose > 0): print('Path tracking with AD was a success!') else: print('Path tracking with AD failed!') return load_standard_solutions()
def standard_double_track(target, start, sols, gamma=0, tasks=0): r""" Does path tracking with standard double precision. On input are a target system, a start system with solutions, optionally: a (random) gamma constant and the number of tasks. The *target* is a list of strings representing the polynomials of the target system (which has to be solved). The *start* is a list of strings representing the polynomials of the start system, with known solutions in sols. The *sols* is a list of strings representing start solutions. By default, a random *gamma* constant is generated, otherwise *gamma* must be a nonzero complex constant. The number of tasks in the multithreading is defined by *tasks*. The default zero value for *tasks* indicates no multithreading. On return are the string representations of the solutions computed at the end of the paths. """ from phcpy.phcpy2c3 import py2c_copy_standard_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_standard_container_to_start_system from phcpy.phcpy2c3 import py2c_copy_standard_container_to_start_solutions from phcpy.phcpy2c3 import py2c_create_standard_homotopy from phcpy.phcpy2c3 import py2c_create_standard_homotopy_with_gamma from phcpy.phcpy2c3 import py2c_solve_by_standard_homotopy_continuation from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c3 import py2c_copy_standard_target_solutions_to_container from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions from phcpy.solver import number_of_symbols dim = number_of_symbols(start) store_standard_system(target, nbvar=dim) py2c_copy_standard_container_to_target_system() store_standard_system(start, nbvar=dim) py2c_copy_standard_container_to_start_system() # py2c_clear_standard_homotopy() if(gamma == 0): py2c_create_standard_homotopy() else: py2c_create_standard_homotopy_with_gamma(gamma.real, gamma.imag) store_standard_solutions(dim, sols) py2c_copy_standard_container_to_start_solutions() py2c_solve_by_standard_homotopy_continuation(tasks) py2c_solcon_clear_standard_solutions() py2c_copy_standard_target_solutions_to_container() return load_standard_solutions()
def standard_deflate(system, solutions): """ The deflation method augments the given system with derivatives to restore the quadratic convergence of Newton's method at isolated singular solutions, in standard double precision. After application of deflation with default settings, the new approximate solutions are returned. """ from phcpy.phcpy2c3 import py2c_standard_deflate from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_system(system) store_standard_solutions(len(system), solutions) py2c_standard_deflate() result = load_standard_solutions() return result
def standard_double_track(target, start, sols, gamma=0, tasks=0): """ Does path tracking with standard double precision. On input are a target system, a start system with solutions, optionally: a (random) gamma constant and the number of tasks. The target is a list of strings representing the polynomials of the target system (which has to be solved). The start is a list of strings representing the polynomials of the start system, with known solutions in sols. The sols is a list of strings representing start solutions. By default, a random gamma constant is generated, otherwise gamma must be a nonzero complex constant. On return are the string representations of the solutions computed at the end of the paths. """ from phcpy.phcpy2c2 import py2c_copy_standard_container_to_target_system from phcpy.phcpy2c2 import py2c_copy_standard_container_to_start_system from phcpy.phcpy2c2 import py2c_copy_standard_container_to_start_solutions from phcpy.phcpy2c2 import py2c_create_standard_homotopy from phcpy.phcpy2c2 import py2c_create_standard_homotopy_with_gamma from phcpy.phcpy2c2 import py2c_solve_by_standard_homotopy_continuation from phcpy.phcpy2c2 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c2 import py2c_copy_standard_target_solutions_to_container from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions from phcpy.solver import number_of_symbols dim = number_of_symbols(start) store_standard_system(target, nbvar=dim) py2c_copy_standard_container_to_target_system() store_standard_system(start, nbvar=dim) py2c_copy_standard_container_to_start_system() # py2c_clear_standard_homotopy() if(gamma == 0): py2c_create_standard_homotopy() else: py2c_create_standard_homotopy_with_gamma(gamma.real, gamma.imag) store_standard_solutions(dim, sols) py2c_copy_standard_container_to_start_solutions() py2c_solve_by_standard_homotopy_continuation(tasks) py2c_solcon_clear_standard_solutions() py2c_copy_standard_target_solutions_to_container() return load_standard_solutions()
def standard_deflate(system, solutions): """ The deflation method augments the given system with derivatives to restore the quadratic convergence of Newton's method at isolated singular solutions, in standard double precision. After application of deflation with default settings, the new approximate solutions are returned. """ from phcpy.phcpy2c3 import py2c_standard_deflate from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions dim = number_of_symbols(system) store_standard_system(system, nbvar=dim) store_standard_solutions(dim, solutions) py2c_standard_deflate() result = load_standard_solutions() return result
def ade_double_track(target, start, sols, gamma=0, verbose=1): """ Does path tracking with algorithm differentiation, in standard double precision. On input are a target system, a start system with solutions. The target is a list of strings representing the polynomials of the target system (which has to be solved). The start is a list of strings representing the polynomials of the start system, with known solutions in sols. The sols is a list of strings representing start solutions. On return are the string representations of the solutions computed at the end of the paths. If gamma on input equals zero, then a random complex number is generated, otherwise the real and imaginary parts of gamma are used. """ from phcpy.phcpy2c2 import py2c_copy_standard_container_to_target_system from phcpy.phcpy2c2 import py2c_copy_standard_container_to_start_system from phcpy.phcpy2c2 import py2c_ade_manypaths_d from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_system(target) py2c_copy_standard_container_to_target_system() store_standard_system(start) py2c_copy_standard_container_to_start_system() dim = len(start) store_standard_solutions(dim, sols) if gamma == 0: from random import uniform from cmath import exp, pi angle = uniform(0, 2 * pi) gamma = exp(angle * complex(0, 1)) if verbose > 0: print "random gamma constant :", gamma fail = py2c_ade_manypaths_d(verbose, gamma.real, gamma.imag) if fail == 0: if verbose > 0: print "Path tracking with AD was a success!" else: print "Path tracking with AD failed!" return load_standard_solutions()
def random_linear_product_system(pols, tosolve=True): """ Given in pols a list of string representations of polynomials, returns a random linear-product system based on a supporting set structure and its solutions as well (if tosolve). """ from phcpy.phcpy2c3 import py2c_product_supporting_set_structure from phcpy.phcpy2c3 import py2c_product_random_linear_product_system from phcpy.phcpy2c3 import py2c_product_solve_linear_product_system from phcpy.interface import store_standard_system, load_standard_system from phcpy.interface import load_standard_solutions store_standard_system(pols) py2c_product_supporting_set_structure() py2c_product_random_linear_product_system() result = load_standard_system() if not tosolve: return result py2c_product_solve_linear_product_system() sols = load_standard_solutions() return (result, sols)
def ade_double_track(target, start, sols, gamma=0, verbose=1): """ Does path tracking with algorithm differentiation, in standard double precision. On input are a target system, a start system with solutions. The target is a list of strings representing the polynomials of the target system (which has to be solved). The start is a list of strings representing the polynomials of the start system, with known solutions in sols. The sols is a list of strings representing start solutions. On return are the string representations of the solutions computed at the end of the paths. If gamma on input equals zero, then a random complex number is generated, otherwise the real and imaginary parts of gamma are used. """ from phcpy.phcpy2c2 import py2c_copy_standard_container_to_target_system from phcpy.phcpy2c2 import py2c_copy_standard_container_to_start_system from phcpy.phcpy2c2 import py2c_ade_manypaths_d from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_system(target) py2c_copy_standard_container_to_target_system() store_standard_system(start) py2c_copy_standard_container_to_start_system() dim = len(start) store_standard_solutions(dim, sols) if(gamma == 0): from random import uniform from cmath import exp, pi angle = uniform(0, 2*pi) gamma = exp(angle*complex(0, 1)) if(verbose > 0): print 'random gamma constant :', gamma fail = py2c_ade_manypaths_d(verbose, gamma.real, gamma.imag) if(fail == 0): if(verbose > 0): print 'Path tracking with AD was a success!' else: print 'Path tracking with AD failed!' return load_standard_solutions()
def gpu_double_track(target, start, sols, gamma=0, verbose=1): r""" GPU accelerated path tracking with algorithm differentiation, in standard double precision. On input are a target system, a start system with solutions. The *target* is a list of strings representing the polynomials of the target system (which has to be solved). The *start* is a list of strings representing the polynomials of the start system, with known solutions in sols. The *sols* is a list of strings representing start solutions. On return are the string representations of the solutions computed at the end of the paths. If *gamma* on input equals zero, then a random complex number is generated, otherwise the real and imaginary parts of *gamma* are used. """ from phcpy.phcpy2c3 import py2c_copy_standard_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_standard_container_to_start_system from phcpy.phcpy2c3 import py2c_gpu_manypaths_d from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions store_standard_system(target) py2c_copy_standard_container_to_target_system() store_standard_system(start) py2c_copy_standard_container_to_start_system() dim = len(start) store_standard_solutions(dim, sols) if(gamma == 0): from random import uniform from cmath import exp, pi angle = uniform(0, 2*pi) gamma = exp(angle*complex(0, 1)) if(verbose > 0): print('random gamma constant :', gamma) fail = py2c_gpu_manypaths_d(2, verbose, gamma.real, gamma.imag) if(fail == 0): if(verbose > 0): print('Path tracking on the GPU was a success!') else: print('Path tracking on the GPU failed!') return load_standard_solutions()
def standard_littlewood_richardson_homotopies(ndim, kdim, brackets, \ verbose=True, vrfcnd=False, outputfilename='/tmp/output'): """ In n-dimensional space we consider k-dimensional planes, subject to intersection conditions represented by brackets. The parameters ndim and kdim give values for n and k respectively. The parameter brackets is a list of brackets. A bracket is a list of as many natural numbers (in the range 1..ndim) as kdim. The Littlewood-Richardson homotopies compute k-planes that meet the flags at spaces of dimensions prescribed by the brackets, in standard double precision. On return is a 4-tuple. The first item of the tuple is the formal root count, sharp for general flags, then as second item the coordinates of the flags. The coordinates of the flags are stored row wise in a list of real and imaginary parts. The third and fourth item of the tuple on return are respectively the polynomial system that has been solved and its solutions. The length of the list of solution should match the root count. """ from phcpy.phcpy2c2 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c2 \ import py2c_schubert_standard_littlewood_richardson_homotopies \ as stlrhom from phcpy.interface import load_standard_solutions, load_standard_system py2c_solcon_clear_standard_solutions() nbc = len(brackets) cds = '' for bracket in brackets: for num in bracket: cds = cds + ' ' + str(num) # print 'the condition string :', cds (roco, sflags) = stlrhom(ndim, kdim, nbc, len(cds), cds, int(verbose), \ int(vrfcnd), len(outputfilename), outputfilename) rflags = eval(sflags) flgs = [] for k in range(len(rflags) / 2): flgs.append(complex(rflags[2 * k], rflags[2 * k + 1])) fsys = load_standard_system() sols = load_standard_solutions() return (roco, flgs, fsys, sols)
def standard_littlewood_richardson_homotopies(ndim, kdim, brackets, \ verbose=True, vrfcnd=False, outputfilename='/tmp/output'): """ In n-dimensional space we consider k-dimensional planes, subject to intersection conditions represented by brackets. The parameters ndim and kdim give values for n and k respectively. The parameter brackets is a list of brackets. A bracket is a list of as many natural numbers (in the range 1..ndim) as kdim. The Littlewood-Richardson homotopies compute k-planes that meet the flags at spaces of dimensions prescribed by the brackets, in standard double precision. On return is a 4-tuple. The first item of the tuple is the formal root count, sharp for general flags, then as second item the coordinates of the flags. The coordinates of the flags are stored row wise in a list of real and imaginary parts. The third and fourth item of the tuple on return are respectively the polynomial system that has been solved and its solutions. The length of the list of solution should match the root count. """ from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c3 \ import py2c_schubert_standard_littlewood_richardson_homotopies \ as stlrhom from phcpy.interface import load_standard_solutions, load_standard_system py2c_solcon_clear_standard_solutions() nbc = len(brackets) cds = '' for bracket in brackets: for num in bracket: cds = cds + ' ' + str(num) # print 'the condition string :', cds (roco, sflags) = stlrhom(ndim, kdim, nbc, len(cds), cds, int(verbose), \ int(vrfcnd), len(outputfilename), outputfilename) rflags = eval(sflags) flgs = [] for k in range(len(rflags)/2): flgs.append(complex(rflags[2*k], rflags[2*k+1])) fsys = load_standard_system() sols = load_standard_solutions() return (roco, flgs, fsys, sols)
def m_homogeneous_start_system(pols, partition): """ For an m-homogeneous Bezout number of a polynomial system defined by a partition of the set of unknowns, one can define a linear-product system that has exactly as many regular solutions as the Bezount number. This linear-product system can then be used as start system in a homotopy to compute all isolated solutions of any polynomial system with the same m-homogeneous structure. This function returns a linear-product start system with random coefficients and its solutions for the given polynomials in pols and the partition. """ from phcpy.phcpy2c3 import py2c_product_m_homogeneous_start_system from phcpy.phcpy2c3 import py2c_product_solve_linear_product_system from phcpy.interface import store_standard_system, load_standard_system from phcpy.interface import load_standard_solutions store_standard_system(pols) py2c_product_m_homogeneous_start_system(len(partition), partition) result = load_standard_system() py2c_product_solve_linear_product_system() sols = load_standard_solutions() return (result, sols)
def standard_track(target, start, sols, filename="", verbose=False): """ Wraps the tracker for Pade continuation in standard double precision. On input are a target system, a start system with solutions, optionally: a string *filename* and the *verbose* flag. The *target* is a list of strings representing the polynomials of the target system (which has to be solved). The *start* is a list of strings representing the polynomials of the start system, with known solutions in *sols*. The *sols* is a list of strings representing start solutions. On return are the string representations of the solutions computed at the end of the paths. """ from phcpy.phcpy2c2 import py2c_copy_standard_container_to_target_system from phcpy.phcpy2c2 import py2c_copy_standard_container_to_start_system from phcpy.phcpy2c2 import py2c_copy_standard_container_to_start_solutions from phcpy.phcpy2c2 import py2c_create_standard_homotopy_with_gamma from phcpy.phcpy2c2 import py2c_clear_standard_homotopy from phcpy.phcpy2c2 import py2c_clear_standard_operations_data from phcpy.interface import store_standard_system from phcpy.interface import store_standard_solutions from phcpy.interface import load_standard_solutions from phcpy.solver import number_of_symbols from phcpy.phcpy2c2 import py2c_padcon_standard_track dim = number_of_symbols(start) store_standard_system(target, nbvar=dim) py2c_copy_standard_container_to_target_system() store_standard_system(start, nbvar=dim) py2c_copy_standard_container_to_start_system() store_standard_solutions(dim, sols) py2c_copy_standard_container_to_start_solutions() (regamma, imgamma) = get_homotopy_continuation_parameter(1) py2c_create_standard_homotopy_with_gamma(regamma, imgamma) nbc = len(filename) fail = py2c_padcon_standard_track(nbc, filename, int(verbose)) # py2c_clear_standard_homotopy() # py2c_clear_standard_operations_data() return load_standard_solutions()
def standard_random_coefficient_system(silent=False): """ Runs the polyhedral homotopies and returns a random coefficient system based on the contents of the cell container, in standard double precision arithmetic. For this to work, the mixed_volume function must be called first. """ from phcpy.phcpy2c3 import py2c_celcon_standard_random_coefficient_system from phcpy.phcpy2c3 import py2c_celcon_copy_into_standard_systems_container from phcpy.phcpy2c3 import py2c_celcon_standard_polyhedral_homotopy from phcpy.phcpy2c3 import py2c_celcon_number_of_cells from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c3 import py2c_celcon_solve_standard_start_system from phcpy.phcpy2c3 import py2c_celcon_track_standard_solution_path from phcpy.phcpy2c3 \ import py2c_celcon_copy_target_standard_solution_to_container py2c_celcon_standard_random_coefficient_system() py2c_celcon_copy_into_standard_systems_container() from phcpy.interface import load_standard_system, load_standard_solutions # py2c_syscon_write_system() result = load_standard_system() # print result py2c_celcon_standard_polyhedral_homotopy() nbcells = py2c_celcon_number_of_cells() py2c_solcon_clear_standard_solutions() for cell in range(1, nbcells+1): mixvol = py2c_celcon_solve_standard_start_system(cell) if not silent: print('system %d has %d solutions' % (cell, mixvol)) for j in range(1, mixvol+1): if not silent: print('-> tracking path %d out of %d' % (j, mixvol)) py2c_celcon_track_standard_solution_path(cell, j, 0) py2c_celcon_copy_target_standard_solution_to_container(cell, j) sols = load_standard_solutions() # print sols # newton_step(result, sols) return (result, sols)
def standard_random_coefficient_system(silent=False): """ Runs the polyhedral homotopies and returns a random coefficient system based on the contents of the cell container, in standard double precision arithmetic. For this to work, the mixed_volume function must be called first. """ from phcpy.phcpy2c3 import py2c_celcon_standard_random_coefficient_system from phcpy.phcpy2c3 import py2c_celcon_copy_into_standard_systems_container from phcpy.phcpy2c3 import py2c_celcon_standard_polyhedral_homotopy from phcpy.phcpy2c3 import py2c_celcon_number_of_cells from phcpy.phcpy2c3 import py2c_solcon_clear_standard_solutions from phcpy.phcpy2c3 import py2c_celcon_solve_standard_start_system from phcpy.phcpy2c3 import py2c_celcon_track_standard_solution_path from phcpy.phcpy2c3 \ import py2c_celcon_copy_target_standard_solution_to_container py2c_celcon_standard_random_coefficient_system() py2c_celcon_copy_into_standard_systems_container() from phcpy.interface import load_standard_system, load_standard_solutions # py2c_syscon_write_system() result = load_standard_system() # print result py2c_celcon_standard_polyhedral_homotopy() nbcells = py2c_celcon_number_of_cells() py2c_solcon_clear_standard_solutions() for cell in range(1, nbcells + 1): mixvol = py2c_celcon_solve_standard_start_system(cell) if not silent: print('system %d has %d solutions' % (cell, mixvol)) for j in range(1, mixvol + 1): if not silent: print('-> tracking path %d out of %d' % (j, mixvol)) py2c_celcon_track_standard_solution_path(cell, j, 0) py2c_celcon_copy_target_standard_solution_to_container(cell, j) sols = load_standard_solutions() # print sols # newton_step(result, sols) return (result, sols)