def ade_tuned_quad_double_track(target, start, sols, pars, gamma=0, verbose=1): r""" Does path tracking with algorithm differentiation, in quad double precision, with tuned path parameters. 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 tuned 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_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_ade_manypaths_qd_pars from phcpy.interface import store_quaddobl_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions store_quaddobl_system(target) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start) py2c_copy_quaddobl_container_to_start_system() dim = len(start) store_quaddobl_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_qd_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_quaddobl_solutions()
def quad_double_track(target, start, sols, gamma=0, tasks=0): r""" Does path tracking with quad 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_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_solutions from phcpy.phcpy2c3 import py2c_create_quaddobl_homotopy from phcpy.phcpy2c3 import py2c_create_quaddobl_homotopy_with_gamma from phcpy.phcpy2c3 import py2c_solve_by_quaddobl_homotopy_continuation from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions from phcpy.phcpy2c3 import py2c_copy_quaddobl_target_solutions_to_container from phcpy.interface import store_quaddobl_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions from phcpy.solver import number_of_symbols dim = number_of_symbols(start) store_quaddobl_system(target, nbvar=dim) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start, nbvar=dim) py2c_copy_quaddobl_container_to_start_system() # py2c_clear_quaddobl_homotopy() if(gamma == 0): py2c_create_quaddobl_homotopy() else: py2c_create_quaddobl_homotopy_with_gamma(gamma.real, gamma.imag) store_quaddobl_solutions(dim, sols) py2c_copy_quaddobl_container_to_start_solutions() py2c_solve_by_quaddobl_homotopy_continuation(tasks) py2c_solcon_clear_quaddobl_solutions() py2c_copy_quaddobl_target_solutions_to_container() return load_quaddobl_solutions()
def quaddobl_set_homotopy(target, start, verbose=False): """ Initializes the homotopy with the target and start system for a step-by-step run of the series-Pade tracker, in quad double precision. If verbose, then extra output is written. Returns the failure code of the homotopy initializer. """ from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.interface import store_quaddobl_system from phcpy.solver import number_of_symbols dim = number_of_symbols(start) store_quaddobl_system(target, nbvar=dim) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start, nbvar=dim) py2c_copy_quaddobl_container_to_start_system() from phcpy.phcpy2c3 import py2c_padcon_quaddobl_initialize_homotopy return py2c_padcon_quaddobl_initialize_homotopy(int(verbose))
def initialize_quaddobl_tracker(target, start, fixedgamma=True): """ Initializes a path tracker with a generator for a target and start system given in quad double precision. If fixedgamma, then gamma will be a fixed default value, otherwise, a random complex constant for gamma is generated. """ from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_initialize_quaddobl_homotopy from phcpy.interface import store_quaddobl_system store_quaddobl_system(target) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start) py2c_copy_quaddobl_container_to_start_system() if fixedgamma: return py2c_initialize_quaddobl_homotopy(1) else: return py2c_initialize_quaddobl_homotopy(0)
def quad_double_track(target, start, sols, gamma=0, tasks=0): """ Does path tracking with quad 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.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_solutions from phcpy.phcpy2c3 import py2c_create_quaddobl_homotopy from phcpy.phcpy2c3 import py2c_create_quaddobl_homotopy_with_gamma from phcpy.phcpy2c3 import py2c_solve_by_quaddobl_homotopy_continuation from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions from phcpy.phcpy2c3 import py2c_copy_quaddobl_target_solutions_to_container from phcpy.interface import store_quaddobl_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions from phcpy.solver import number_of_symbols dim = number_of_symbols(start) store_quaddobl_system(target, nbvar=dim) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start, nbvar=dim) py2c_copy_quaddobl_container_to_start_system() # py2c_clear_quaddobl_homotopy() if (gamma == 0): py2c_create_quaddobl_homotopy() else: py2c_create_quaddobl_homotopy_with_gamma(gamma.real, gamma.imag) store_quaddobl_solutions(dim, sols) py2c_copy_quaddobl_container_to_start_solutions() py2c_solve_by_quaddobl_homotopy_continuation(tasks) py2c_solcon_clear_quaddobl_solutions() py2c_copy_quaddobl_target_solutions_to_container() return load_quaddobl_solutions()
def initialize_quaddobl_tracker(target, start, fixedgamma=True): r""" Initializes a path tracker with a generator for a *target* and *start* system given in quad double precision. If *fixedgamma*, then gamma will be a fixed default value, otherwise, a random complex constant for gamma is generated. """ from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_initialize_quaddobl_homotopy from phcpy.interface import store_quaddobl_system store_quaddobl_system(target) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start) py2c_copy_quaddobl_container_to_start_system() if fixedgamma: return py2c_initialize_quaddobl_homotopy(1) else: return py2c_initialize_quaddobl_homotopy(0)
def quaddobl_set_parameter_homotopy(hom, idx, verbose=False): """ Initializes the homotopy with the polynomials in hom for a step-by-step run of the series-Pade tracker, in quad double precision. The value idx gives the index of the continuation parameter and is the index of one of the variables in the homotopy hom. If verbose, then extra output is written. Returns the failure code of the homotopy initializer. """ from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system from phcpy.interface import store_quaddobl_system from phcpy.solver import number_of_symbols dim = number_of_symbols(hom) store_quaddobl_system(hom, nbvar=dim) py2c_copy_quaddobl_container_to_target_system() from phcpy.phcpy2c3 \ import py2c_padcon_quaddobl_initialize_parameter_homotopy vrb = int(verbose) return py2c_padcon_quaddobl_initialize_parameter_homotopy(idx, vrb)
def quaddobl_diagonal_homotopy(dim1, sys1, esols1, dim2, sys2, esols2): r""" Defines a diagonal homotopy to intersect the witness sets defined by (*sys1*, *esols1*) and (*sys2*, *esols2*), respectively of dimensions *dim1* and *dim2*. The systems *sys1* and *sys2* are assumed to be square and with as many slack variables as the dimension of the solution sets. The data is stored in quad double precision. """ from phcpy.interface import store_quaddobl_system as storesys from phcpy.interface import store_quaddobl_solutions as storesols from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_target_solutions from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_solutions from phcpy.phcpy2c3 import py2c_quaddobl_diagonal_homotopy from phcpy.phcpy2c3 import py2c_syscon_number_of_symbols from phcpy.phcpy2c3 import py2c_syscon_string_of_symbols from phcpy.phcpy2c3 import py2c_diagonal_symbols_doubler storesys(sys1) symbols = py2c_syscon_string_of_symbols() nbsymbs = py2c_syscon_number_of_symbols() print('number of symbols :', nbsymbs) print('names of variables :', symbols) storesols(len(sys1), esols1) if(dim1 >= dim2): py2c_copy_quaddobl_container_to_target_system() py2c_copy_quaddobl_container_to_target_solutions() else: py2c_copy_quaddobl_container_to_start_system() py2c_copy_quaddobl_container_to_start_solutions() storesys(sys2) storesols(len(sys2), esols2) if(dim1 >= dim2): py2c_copy_quaddobl_container_to_start_system() py2c_copy_quaddobl_container_to_start_solutions() else: py2c_copy_quaddobl_container_to_target_system() py2c_copy_quaddobl_container_to_target_solutions() if(dim1 >= dim2): py2c_quaddobl_diagonal_homotopy(dim1, dim2) else: py2c_quaddobl_diagonal_homotopy(dim2, dim1) py2c_diagonal_symbols_doubler(nbsymbs-dim1, dim1, len(symbols), symbols)
def gpu_quad_double_track(target, start, sols, gamma=0, verbose=1): """ GPU accelerated path tracking with algorithm differentiation, in quad 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_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_gpu_manypaths_qd from phcpy.interface import store_quaddobl_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions store_quaddobl_system(target) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start) py2c_copy_quaddobl_container_to_start_system() dim = len(start) store_quaddobl_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_qd(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_quaddobl_solutions()
def gpu_quad_double_track(target, start, sols, gamma=0, verbose=1): r""" GPU accelerated path tracking with algorithmic differentiation, in quad 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_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_gpu_manypaths_qd from phcpy.interface import store_quaddobl_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions store_quaddobl_system(target) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start) py2c_copy_quaddobl_container_to_start_system() dim = len(start) store_quaddobl_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_qd(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_quaddobl_solutions()
def quaddobl_track(target, start, sols, filename="", verbose=False): """ Wraps the tracker for Pade continuation in quad 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.phcpy2c3 import py2c_copy_quaddobl_container_to_target_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_system from phcpy.phcpy2c3 import py2c_copy_quaddobl_container_to_start_solutions from phcpy.phcpy2c3 import py2c_create_quaddobl_homotopy_with_gamma from phcpy.phcpy2c3 import py2c_clear_quaddobl_operations_data from phcpy.interface import store_quaddobl_system from phcpy.interface import store_quaddobl_solutions from phcpy.interface import load_quaddobl_solutions from phcpy.solver import number_of_symbols from phcpy.phcpy2c3 import py2c_padcon_quaddobl_track dim = number_of_symbols(start) store_quaddobl_system(target, nbvar=dim) py2c_copy_quaddobl_container_to_target_system() store_quaddobl_system(start, nbvar=dim) py2c_copy_quaddobl_container_to_start_system() store_quaddobl_solutions(dim, sols) py2c_copy_quaddobl_container_to_start_solutions() (regamma, imgamma) = get_homotopy_continuation_parameter(1) py2c_create_quaddobl_homotopy_with_gamma(regamma, imgamma) nbc = len(filename) fail = py2c_padcon_quaddobl_track(nbc, filename, int(verbose)) # py2c_clear_quaddobl_operations_data() return load_quaddobl_solutions()