Пример #1
0
def quaddobl_pade_approximants(pols, sols, idx=1, numdeg=2, dendeg=2, \
    nbr=4, verbose=True):
    r"""
    Computes Pade approximants based on the series in quad double 
    precision for the polynomials in *pols*, where the leading 
    coefficients of the series are the solutions in *sols*.
    On entry are the following seven parameters:

    *pols*: a list of string representations of polynomials,

    *sols*: a list of solutions of the polynomials in *pols*,

    *idx*: index of the series parameter, by default equals 1,

    *numdeg*: the degree of the numerator,

    *dendeg*: the degree of the denominator,

    *nbr*: number of steps with Newton's method,

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c3 \
        import py2c_quaddobl_Pade_approximant as Pade_approximants
    from phcpy.phcpy2c3 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c3 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c3 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print("the polynomials :")
        for pol in pols:
            print(pol)
        print("Number of variables :", nbsym)
    store_quaddobl_system(pols, nbvar=nbsym)
    store_quaddobl_solutions(nbsym, sols)
    fail = Pade_approximants(idx, numdeg, dendeg, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print("An error occurred in the Pade constructor.")
        else:
            print("Computed %d Pade approximants." % size)
    result = []
    for k in range(1, size + 1):
        py2c_syspool_copy_to_quaddobl_container(k)
        sersol = load_quaddobl_system()
        substsersol = substitute_symbol(sersol, idx)
        result.append(make_fractions(substsersol))
    py2c_syspool_quaddobl_clear()
    return result
Пример #2
0
def initialize_quaddobl_solution(nvar, sol):
    """
    A quad double precision path tracker with a generator is
    initialized with a start solution sol in a number of
    variables equal to the value of nvar.
    """
    from phcpy.phcpy2c2 import py2c_initialize_quaddobl_solution
    from phcpy.interface import store_quaddobl_solutions
    store_quaddobl_solutions(nvar, [sol])
    return py2c_initialize_quaddobl_solution(1)
Пример #3
0
def initialize_quaddobl_solution(nvar, sol):
    r"""
    A quad double precision path tracker with a generator is
    initialized with a start solution *sol* in a number of
    variables equal to the value of *nvar*.
    """
    from phcpy.phcpy2c3 import py2c_initialize_quaddobl_solution
    from phcpy.interface import store_quaddobl_solutions
    store_quaddobl_solutions(nvar, [sol])
    return py2c_initialize_quaddobl_solution(1)
Пример #4
0
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
Пример #5
0
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
Пример #6
0
def quaddobl_set_solution(nvar, sol, verbose=False):
    r"""
    Sets the start solution in *sol* for the step-by-step run of
    the series-Pade tracker, in quad double precision.
    If verbose, then extra output is written.
    The number of variables is in *nvar*.
    """
    from phcpy.phcpy2c3 import py2c_padcon_initialize_quaddobl_solution
    from phcpy.interface import store_quaddobl_solutions
    store_quaddobl_solutions(nvar, [sol])
    return py2c_padcon_initialize_quaddobl_solution(1, int(verbose))
Пример #7
0
def quaddobl_newton_series(pols, sols, idx=1, maxdeg=4, nbr=4, verbose=True):
    r"""
    Computes series in quad double precision for the polynomials
    in *pols*, where the leading coefficients are the solutions in *sols*.
    On entry are the following five parameters:

    *pols*: a list of string representations of polynomials,

    *sols*: a list of solutions of the polynomials in *pols*,

    *idx*: index of the series parameter, by default equals 1,

    *maxdeg*: maximal degree of the series,

    *nbr*: number of steps with Newton's method,

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c2 import py2c_quaddobl_Newton_series as newton
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c2 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print "the polynomials :"
        for pol in pols:
            print pol
        print "Number of variables :", nbsym
    store_quaddobl_system(pols, nbvar=nbsym)
    store_quaddobl_solutions(nbsym, sols)
    fail = newton(idx, maxdeg, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print "An error occurred in the execution of Newton's method."
        else:
            print "Computed %d series solutions." % size
    result = []
    for k in range(1, size+1):
        py2c_syspool_copy_to_quaddobl_container(k)
        sersol = load_quaddobl_system()
        result.append(substitute_symbol(sersol, idx))
    py2c_syspool_quaddobl_clear()
    return result
Пример #8
0
def quaddobl_scale_solutions(nvar, sols, cffs):
    """
    Scales the solutions in the list sols using the coefficients in cffs,
    using quad 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
    quaddobl_scale_system(pols), then the solutions on return will be
    solutions of the original polynomials in the list pols.
    """
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import load_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_scale_quaddobl_solutions
    store_quaddobl_solutions(nvar, sols)
    py2c_scale_quaddobl_solutions(len(cffs), str(cffs))
    return load_quaddobl_solutions()
Пример #9
0
def quaddobl_scale_solutions(nvar, sols, cffs):
    """
    Scales the solutions in the list sols using the coefficients in cffs,
    using quad 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
    quaddobl_scale_system(pols), then the solutions on return will be
    solutions of the original polynomials in the list pols.
    """
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import load_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_scale_quaddobl_solutions
    store_quaddobl_solutions(nvar, sols)
    py2c_scale_quaddobl_solutions(len(cffs), str(cffs))
    return load_quaddobl_solutions()
Пример #10
0
def quaddobl_newton_series(pols, sols, idx=1, nbr=4, verbose=True):
    r"""
    Computes series in quad double precision for the polynomials
    in *pols*, where the leading coefficients are the solutions in *sols*.
    On entry are the following five parameters:

    *pols*: a list of string representations of polynomials,

    *sols*: a list of solutions of the polynomials in *pols*,

    *idx*: index of the series parameter, by default equals 1,

    *nbr*: number of steps with Newton's method,

    *verbose*: whether to write intermediate output to screen or not.

    On return is a list of lists of strings.  Each lists of strings
    represents the series solution for the variables in the list *pols*.
    """
    from phcpy.solver import number_of_symbols
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system, load_quaddobl_system
    from phcpy.phcpy2c2 import py2c_quaddobl_Newton_series as newton
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_size as poolsize
    from phcpy.phcpy2c2 import py2c_syspool_copy_to_quaddobl_container
    from phcpy.phcpy2c2 import py2c_syspool_quaddobl_clear
    nbsym = number_of_symbols(pols)
    if verbose:
        print "the polynomials :"
        for pol in pols:
            print pol
        print "Number of variables :", nbsym
    store_quaddobl_system(pols, nbvar=nbsym)
    store_quaddobl_solutions(nbsym, sols)
    fail = newton(idx, nbr, int(verbose))
    size = (-1 if fail else poolsize())
    if verbose:
        if size == -1:
            print "An error occurred in the execution of Newton's method."
        else:
            print "Computed %d series solutions." % size
    result = []
    for k in range(1, size+1):
        py2c_syspool_copy_to_quaddobl_container(k)
        sersol = load_quaddobl_system()
        result.append(substitute_symbol(sersol, idx))
    py2c_syspool_quaddobl_clear()
    return result
Пример #11
0
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()
Пример #12
0
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()
Пример #13
0
def quaddobl_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 quad double precision.
    After application of deflation with default settings,
    the new approximate solutions are returned.
    """
    from phcpy.phcpy2c3 import py2c_quaddobl_deflate
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import load_quaddobl_solutions
    store_quaddobl_system(system)
    store_quaddobl_solutions(len(system), solutions)
    py2c_quaddobl_deflate()
    result = load_quaddobl_solutions()
    return result
Пример #14
0
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.phcpy2c2 import py2c_copy_quaddobl_container_to_target_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_system
    from phcpy.phcpy2c2 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()
Пример #15
0
def quaddobl_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 quad double precision.
    After application of deflation with default settings,
    the new approximate solutions are returned.
    """
    from phcpy.phcpy2c3 import py2c_quaddobl_deflate
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import load_quaddobl_solutions
    dim = number_of_symbols(system)
    store_quaddobl_system(system, nbvar=dim)
    store_quaddobl_solutions(dim, solutions)
    py2c_quaddobl_deflate()
    result = load_quaddobl_solutions()
    return result
Пример #16
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.phcpy2c2 import py2c_copy_quaddobl_container_to_target_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_solutions
    from phcpy.phcpy2c2 import py2c_create_quaddobl_homotopy
    from phcpy.phcpy2c2 import py2c_create_quaddobl_homotopy_with_gamma
    from phcpy.phcpy2c2 import py2c_solve_by_quaddobl_homotopy_continuation
    from phcpy.phcpy2c2 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.phcpy2c2 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()
Пример #17
0
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.phcpy2c2 import py2c_copy_quaddobl_container_to_target_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_system
    from phcpy.phcpy2c2 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()
Пример #18
0
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.phcpy2c2 import py2c_copy_quaddobl_container_to_target_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_system
    from phcpy.phcpy2c2 import py2c_copy_quaddobl_container_to_start_solutions
    from phcpy.phcpy2c2 import py2c_create_quaddobl_homotopy_with_gamma
    from phcpy.phcpy2c2 import py2c_clear_quaddobl_homotopy
    from phcpy.phcpy2c2 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.phcpy2c2 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()
    (regamma, imgamma) = get_homotopy_continuation_parameter(1)
    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_homotopy()
    # py2c_clear_quaddobl_operations_data()
    return load_quaddobl_solutions()
Пример #19
0
def quaddobl_monodromy_breakup(embsys, esols, dim, \
    islaurent=0, verbose=True, nbloops=0):
    r"""
    Applies the monodromy breakup algorithm in quad double precision
    to factor the *dim*-dimensional algebraic set represented by the embedded
    system *embsys* and its solutions *esols*.
    If the embedded polynomial system is a Laurent system,
    then islaurent must equal one, the default is zero.
    If *verbose* is False, then no output is written.
    If *nbloops* equals zero, then the user is prompted to give
    the maximum number of loops.
    """
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_to_mute
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_to_verbose
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_assign_labels
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_monodromy
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_sampler
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_Laurent_sampler
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_trace_grid_diagnostics
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_trace_slice
    from phcpy.phcpy2c3 import py2c_factor_store_quaddobl_gammas
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_track_paths
    from phcpy.phcpy2c3 import py2c_factor_store_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_factor_restore_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_factor_new_quaddobl_slices
    from phcpy.phcpy2c3 import py2c_factor_swap_quaddobl_slices
    from phcpy.phcpy2c3 import py2c_factor_permutation_after_quaddobl_loop
    from phcpy.phcpy2c3 import py2c_factor_number_of_quaddobl_components
    from phcpy.phcpy2c3 import py2c_factor_update_quaddobl_decomposition
    from phcpy.phcpy2c3 import py2c_solcon_write_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import store_quaddobl_laurent_system
    if(verbose):
        print('... applying monodromy factorization with quad doubles ...')
        py2c_factor_set_quaddobl_to_verbose()
    else:
        py2c_factor_set_quaddobl_to_mute()
    deg = len(esols)
    nvar = len(embsys)
    if(verbose):
        print('dim =', dim)
    store_quaddobl_solutions(nvar, esols)
    if(islaurent == 1):
        store_quaddobl_laurent_system(embsys)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_Laurent_sampler(dim)
    else:
        store_quaddobl_system(embsys)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_sampler(dim)
    if(verbose):
        py2c_solcon_write_quaddobl_solutions()
    if(nbloops == 0):
        strnbloops = input('give the maximum number of loops : ')
        nbloops = int(strnbloops)
    py2c_factor_initialize_quaddobl_monodromy(nbloops, deg, dim)
    py2c_factor_store_quaddobl_solutions()
    if(verbose):
        print('... initializing the grid ...')
    for i in range(1, 3):
        py2c_factor_set_quaddobl_trace_slice(i)
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_factor_store_quaddobl_solutions()
        py2c_factor_restore_quaddobl_solutions()
        py2c_factor_swap_quaddobl_slices()
    (err, dis) = py2c_factor_quaddobl_trace_grid_diagnostics()
    if(verbose):
        print('The diagnostics of the trace grid :')
        print('  largest error on the samples :', err)
        print('  smallest distance between the samples :', dis)
    for i in range(1, nbloops+1):
        if(verbose):
            print('... starting loop %d ...' % i)
        py2c_factor_new_quaddobl_slices(dim, nvar)
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_solcon_clear_quaddobl_solutions()
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_factor_store_quaddobl_solutions()
        sprm = py2c_factor_permutation_after_quaddobl_loop(deg)
        if(verbose):
            perm = eval(sprm)
            print('the permutation :', perm)
        nb0 = py2c_factor_number_of_quaddobl_components()
        done = py2c_factor_update_quaddobl_decomposition(deg, len(sprm), sprm)
        nb1 = py2c_factor_number_of_quaddobl_components()
        if(verbose):
            print('number of factors : %d -> %d' % (nb0, nb1))
            deco = decomposition(deg, 'qd')
            print('decomposition :', deco)
        if(done == 1):
            break
        py2c_factor_restore_quaddobl_solutions()
Пример #20
0
def quaddobl_monodromy_breakup(embsys, esols, dim, \
    islaurent=0, verbose=True, nbloops=0):
    r"""
    Applies the monodromy breakup algorithm in quad double precision
    to factor the *dim*-dimensional algebraic set represented by the embedded
    system *embsys* and its solutions *esols*.
    If the embedded polynomial system is a Laurent system,
    then islaurent must equal one, the default is zero.
    If *verbose* is False, then no output is written.
    If *nbloops* equals zero, then the user is prompted to give
    the maximum number of loops.
    """
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_to_mute
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_to_verbose
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_assign_labels
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_monodromy
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_sampler
    from phcpy.phcpy2c3 import py2c_factor_initialize_quaddobl_Laurent_sampler
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_trace_grid_diagnostics
    from phcpy.phcpy2c3 import py2c_factor_set_quaddobl_trace_slice
    from phcpy.phcpy2c3 import py2c_factor_store_quaddobl_gammas
    from phcpy.phcpy2c3 import py2c_factor_quaddobl_track_paths
    from phcpy.phcpy2c3 import py2c_factor_store_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_factor_restore_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_factor_new_quaddobl_slices
    from phcpy.phcpy2c3 import py2c_factor_swap_quaddobl_slices
    from phcpy.phcpy2c3 import py2c_factor_permutation_after_quaddobl_loop
    from phcpy.phcpy2c3 import py2c_factor_number_of_quaddobl_components
    from phcpy.phcpy2c3 import py2c_factor_update_quaddobl_decomposition
    from phcpy.phcpy2c3 import py2c_solcon_write_quaddobl_solutions
    from phcpy.phcpy2c3 import py2c_solcon_clear_quaddobl_solutions
    from phcpy.interface import store_quaddobl_solutions
    from phcpy.interface import store_quaddobl_system
    from phcpy.interface import store_quaddobl_laurent_system
    if (verbose):
        print('... applying monodromy factorization with quad doubles ...')
        py2c_factor_set_quaddobl_to_verbose()
    else:
        py2c_factor_set_quaddobl_to_mute()
    deg = len(esols)
    nvar = len(embsys)
    if (verbose):
        print('dim =', dim)
    store_quaddobl_solutions(nvar, esols)
    if (islaurent == 1):
        store_quaddobl_laurent_system(embsys)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_Laurent_sampler(dim)
    else:
        store_quaddobl_system(embsys)
        py2c_factor_quaddobl_assign_labels(nvar, deg)
        py2c_factor_initialize_quaddobl_sampler(dim)
    if (verbose):
        py2c_solcon_write_quaddobl_solutions()
    if (nbloops == 0):
        strnbloops = input('give the maximum number of loops : ')
        nbloops = int(strnbloops)
    py2c_factor_initialize_quaddobl_monodromy(nbloops, deg, dim)
    py2c_factor_store_quaddobl_solutions()
    if (verbose):
        print('... initializing the grid ...')
    for i in range(1, 3):
        py2c_factor_set_quaddobl_trace_slice(i)
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_factor_store_quaddobl_solutions()
        py2c_factor_restore_quaddobl_solutions()
        py2c_factor_swap_quaddobl_slices()
    (err, dis) = py2c_factor_quaddobl_trace_grid_diagnostics()
    if (verbose):
        print('The diagnostics of the trace grid :')
        print('  largest error on the samples :', err)
        print('  smallest distance between the samples :', dis)
    for i in range(1, nbloops + 1):
        if (verbose):
            print('... starting loop %d ...' % i)
        py2c_factor_new_quaddobl_slices(dim, nvar)
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_solcon_clear_quaddobl_solutions()
        py2c_factor_store_quaddobl_gammas(nvar)
        py2c_factor_quaddobl_track_paths(islaurent)
        py2c_factor_store_quaddobl_solutions()
        sprm = py2c_factor_permutation_after_quaddobl_loop(deg)
        if (verbose):
            perm = eval(sprm)
            print('the permutation :', perm)
        nb0 = py2c_factor_number_of_quaddobl_components()
        done = py2c_factor_update_quaddobl_decomposition(deg, len(sprm), sprm)
        nb1 = py2c_factor_number_of_quaddobl_components()
        if (verbose):
            print('number of factors : %d -> %d' % (nb0, nb1))
            deco = decomposition(deg, 'qd')
            print('decomposition :', deco)
        if (done == 1):
            break
        py2c_factor_restore_quaddobl_solutions()