Esempio n. 1
0
def quaddobl_real_sweep(pols, sols, par='s', start=0.0, target=1.0):
    r"""
    A real sweep homotopy is a family of n equations in n+1 variables,
    where one of the variables is the artificial parameter s which moves
    from 0.0 to 1.0.  The last equation can then be of the form

    (1 - s)*(lambda - L[0]) + s*(lambda - L[1]) = 0 so that,

    at s = 0, the natural parameter lambda has the value L[0], and

    at s = 1, the natural parameter lambda has the value L[1].

    Thus: as s moves from 0 to 1, lambda goes from L[0] to L[1].

    All solutions in the list *sols* must have then the value L[0]
    for the variable lambda.
    The sweep stops when the target value for s is reached
    or when a singular solution is encountered.
    Computations happen in quad double precision.
    """
    from phcpy.interface import store_quaddobl_solutions as storesols
    from phcpy.interface import store_quaddobl_system as storesys
    nvar = len(pols) + 1
    storesys(pols, nbvar=nvar)
    storesols(nvar, sols)
    print 'done storing system and solutions ...'
    from phcpy.interface import load_quaddobl_solutions as loadsols
    from phcpy.phcpy2c2 \
    import py2c_sweep_define_parameters_symbolically as define
    from phcpy.phcpy2c2 \
    import py2c_sweep_set_quaddobl_start as set_start
    from phcpy.phcpy2c2 \
    import py2c_sweep_set_quaddobl_target as set_target
    (nbq, nbp) = (len(pols), 1)
    pars = [par]
    parnames = ' '.join(pars)
    nbc = len(parnames)
    print 'defining the parameters ...'
    define(nbq, nvar, nbp, nbc, parnames)
    set_start(nbp, str([start, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))
    set_target(nbp, str([target, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))
    from phcpy.phcpy2c2 import py2c_sweep_quaddobl_real_run as run
    run()
    result = loadsols()
    return result
Esempio n. 2
0
def quaddobl_real_sweep(pols, sols, par='s', start=0.0, target=1.0):
    r"""
    A real sweep homotopy is a family of n equations in n+1 variables,
    where one of the variables is the artificial parameter s which moves
    from 0.0 to 1.0.  The last equation can then be of the form

    (1 - s)*(lambda - L[0]) + s*(lambda - L[1]) = 0 so that,

    at s = 0, the natural parameter lambda has the value L[0], and

    at s = 1, the natural parameter lambda has the value L[1].

    Thus: as s moves from 0 to 1, lambda goes from L[0] to L[1].

    All solutions in the list *sols* must have then the value L[0]
    for the variable lambda.
    The sweep stops when the target value for s is reached
    or when a singular solution is encountered.
    Computations happen in quad double precision.
    """
    from phcpy.interface import store_quaddobl_solutions as storesols
    from phcpy.interface import store_quaddobl_system as storesys
    nvar = len(pols) + 1
    storesys(pols, nbvar=nvar)
    storesols(nvar, sols)
    # print 'done storing system and solutions ...'
    from phcpy.interface import load_quaddobl_solutions as loadsols
    from phcpy.phcpy2c2 \
    import py2c_sweep_define_parameters_symbolically as define
    from phcpy.phcpy2c2 \
    import py2c_sweep_set_quaddobl_start as set_start
    from phcpy.phcpy2c2 \
    import py2c_sweep_set_quaddobl_target as set_target
    (nbq, nbp) = (len(pols), 1)
    pars = [par]
    parnames = ' '.join(pars)
    nbc = len(parnames)
    # print 'defining the parameters ...'
    define(nbq, nvar, nbp, nbc, parnames)
    set_start(nbp, str([start, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))
    set_target(nbp, str([target, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))
    from phcpy.phcpy2c2 import py2c_sweep_quaddobl_real_run as run
    run()
    result = loadsols()
    return result
Esempio n. 3
0
def quaddobl_complex_sweep(pols, sols, nvar, pars, start, target):
    r"""
    For the polynomials in the list of strings *pols*
    and the solutions in *sols* for the values in the list *start*,
    a sweep through the parameter space will be performed
    in quad double precision to the target values of
    the parameters in the list *target*.
    The number of variables in the polynomials and the solutions
    must be the same and be equal to the value of *nvar*.
    The list of symbols in *pars* contains the names of the variables
    in the polynomials *pols* that serve as parameters.
    The size of the lists *pars*, *start*, and *target* must be same.
    """
    from phcpy.interface import store_quaddobl_solutions as storesols
    from phcpy.interface import store_quaddobl_system as storesys
    storesys(pols, nbvar=nvar)
    storesols(nvar, sols)
    from phcpy.interface import load_quaddobl_solutions as loadsols
    from phcpy.phcpy2c2 \
    import py2c_sweep_define_parameters_symbolically as define
    from phcpy.phcpy2c2 \
    import py2c_sweep_set_quaddobl_start as set_start
    from phcpy.phcpy2c2 \
    import py2c_sweep_set_quaddobl_target as set_target
    from phcpy.phcpy2c2 import py2c_sweep_quaddobl_complex_run as run
    (nbq, nbp) = (len(pols), len(pars))
    parnames = ' '.join(pars)
    nbc = len(parnames)
    define(nbq, nvar, nbp, nbc, parnames)
    print 'setting the start and the target ...'
    set_start(nbp, str(start))
    set_target(nbp, str(target))
    print 'calling run in quad double precision ...'
    run(0, 0.0, 0.0)
    result = loadsols()
    return result
Esempio n. 4
0
def quaddobl_complex_sweep(pols, sols, nvar, pars, start, target):
    """
    For the polynomials in the list of strings pols
    and the solutions in sols for the values in the list start,
    a sweep through the parameter space will be performed
    in quad double precision to the target values of
    the parameters in the list target.
    The number of variables in the polynomials and the solutions
    must be the same and be equal to the value of nvar.
    The list of symbols in pars contains the names of the variables
    in the polynomials pols that serve as parameters.
    The size of the lists pars, start, and target must be same.
    """
    from phcpy.interface import store_quaddobl_solutions as storesols
    from phcpy.interface import store_quaddobl_system as storesys
    storesys(pols, nbvar=nvar)
    storesols(nvar, sols)
    from phcpy.interface import load_quaddobl_solutions as loadsols
    from phcpy.phcpy2c3 \
    import py2c_sweep_define_parameters_symbolically as define
    from phcpy.phcpy2c3 \
    import py2c_sweep_set_quaddobl_start as set_start
    from phcpy.phcpy2c3 \
    import py2c_sweep_set_quaddobl_target as set_target
    from phcpy.phcpy2c3 import py2c_sweep_quaddobl_complex_run as run
    (nbq, nbp) = (len(pols), len(pars))
    parnames = ' '.join(pars)
    nbc = len(parnames)
    define(nbq, nvar, nbp, nbc, parnames)
    print('setting the start and the target ...')
    set_start(nbp, str(start))
    set_target(nbp, str(target))
    print('calling run in quad double precision ...')
    run(0, 0.0, 0.0)
    result = loadsols()
    return result
Esempio n. 5
0
def standard_complex_sweep(pols, sols, nvar, pars, start, target):
    r"""
    For the polynomials in the list of strings *pols*
    and the solutions in *sols* for the values in the list *start*,
    a sweep through the parameter space will be performed
    in standard double precision to the target values of
    the parameters in the list *target*.
    The number of variables in the polynomials and the solutions
    must be the same and be equal to the value of *nvar*.
    The list of symbols in *pars* contains the names of the variables
    in the polynomials *pols* that serve as parameters.
    The size of the lists *pars*, *start*, and *target* must be same.
    """
    from phcpy.interface import store_standard_solutions as storesols
    from phcpy.interface import store_standard_system as storesys
    storesys(pols, nbvar=nvar)
    storesols(nvar, sols)
    from phcpy.interface import load_standard_solutions as loadsols
    from phcpy.phcpy2c2 \
    import py2c_sweep_define_parameters_symbolically as define
    from phcpy.phcpy2c2 \
    import py2c_sweep_set_standard_start as set_start
    from phcpy.phcpy2c2 \
    import py2c_sweep_set_standard_target as set_target
    from phcpy.phcpy2c2 import py2c_sweep_standard_complex_run as run
    (nbq, nbp) = (len(pols), len(pars))
    parnames = ' '.join(pars)
    nbc = len(parnames)
    define(nbq, nvar, nbp, nbc, parnames)
    print 'setting the start and the target ...'
    set_start(nbp, str(start))
    set_target(nbp, str(target))
    print 'calling run in standard double precision ...'
    run(0, 0.0, 0.0)
    result = loadsols()
    return result
Esempio n. 6
0
def standard_complex_sweep(pols, sols, nvar, pars, start, target):
    """
    For the polynomials in the list of strings pols
    and the solutions in sols for the values in the list start,
    a sweep through the parameter space will be performed
    in standard double precision to the target values of
    the parameters in the list target.
    The number of variables in the polynomials and the solutions
    must be the same and be equal to the value of nvar.
    The list of symbols in pars contains the names of the variables
    in the polynomials pols that serve as parameters.
    The size of the lists pars, start, and target must be same.
    """
    from phcpy.interface import store_standard_solutions as storesols
    from phcpy.interface import store_standard_system as storesys
    storesys(pols, nbvar=nvar)
    storesols(nvar, sols)
    from phcpy.interface import load_standard_solutions as loadsols
    from phcpy.phcpy2c3 \
    import py2c_sweep_define_parameters_symbolically as define
    from phcpy.phcpy2c3 \
    import py2c_sweep_set_standard_start as set_start
    from phcpy.phcpy2c3 \
    import py2c_sweep_set_standard_target as set_target
    from phcpy.phcpy2c3 import py2c_sweep_standard_complex_run as run
    (nbq, nbp) = (len(pols), len(pars))
    parnames = ' '.join(pars)
    nbc = len(parnames)
    define(nbq, nvar, nbp, nbc, parnames)
    print('setting the start and the target ...')
    set_start(nbp, str(start))
    set_target(nbp, str(target))
    print('calling run in standard double precision ...')
    run(0, 0.0, 0.0)
    result = loadsols()
    return result
Esempio n. 7
0
def quaddobl_diagonal_solver(dim, dm1, sys1, sols1, dm2, sys2, sols2, \
    tasks=0, verbose=True):
    r"""
    Runs the diagonal homotopies in quad double precision
    to intersect two witness sets stored in (*sys1*, *sols1*) and
    (*sys2*, *sols2*), of respective dimensions *dm1* and *dm2*.
    The ambient dimension equals *dim*.
    Multitasking is available, and is activated by the *tasks* parameter.
    Returns the last system in the cascade and its solutions.
    If *verbose*, then the solver runs in interactive mode, printing
    intermediate results to screen and prompting the user to continue.
    """
    from phcpy.phcpy2c2 import py2c_quaddobl_collapse_diagonal
    from phcpy.interface import store_quaddobl_solutions as storesols
    from phcpy.interface import load_quaddobl_solutions as loadsols
    from phcpy.interface import load_quaddobl_system as loadsys
    from phcpy.phcpy2c2 import py2c_extrinsic_top_diagonal_dimension
    from phcpy.solutions import filter_vanishing
    from phcpy.sets import drop_coordinate_from_quaddobl_solutions
    from phcpy.sets import drop_variable_from_quaddobl_polynomials
    from phcpy.cascades import quad_double_cascade_step
    topdim = py2c_extrinsic_top_diagonal_dimension(dim + dm1, dim + dm2, dm1,
                                                   dm2)
    kdm = len(sys1) - dm1
    topdiagdim = top_diagonal_dimension(kdm, dm1, dm2)
    if verbose:
        print 'the top dimension :', topdim, 'dim :', dim
        print 'number of slack variables at the top :', topdiagdim
    quaddobl_diagonal_homotopy(dm1, sys1, sols1, dm2, sys2, sols2)
    if verbose:
        print 'defining the start solutions'
    quaddobl_diagonal_cascade_solutions(dm1, dm2)
    if verbose:
        print 'starting the diagonal cascade'
    (topsys, startsols) = quaddobl_start_diagonal_cascade()
    if verbose:
        print 'the system solved in the start of the cascade :'
        for pol in topsys:
            print pol
        print 'the solutions after starting the diagonal cascade :'
        for sol in startsols:
            print sol
        raw_input('hit enter to continue')
    for k in range(topdiagdim, 0, -1):
        endsols = quad_double_cascade_step(k, topsys, startsols)
        if verbose:
            print 'after running cascade step %d :' % k
            for sol in endsols:
                print sol
        endsolsf1 = filter_vanishing(endsols, 1.0e-8)
        if verbose:
            print 'computed', len(endsolsf1), 'solutions'
            raw_input('hit enter to continue')
        slack = 'zz' + str(k)
        nbvar = len(topsys)
        endsolsf2 = drop_coordinate_from_quaddobl_solutions\
            (endsolsf1, nbvar, slack)
        if verbose:
            print 'after dropping the slack coordinate from the solutions :'
            for sol in endsolsf2:
                print sol
            raw_input('hit enter to continue')
        nextsys = drop_variable_from_quaddobl_polynomials(topsys, slack)
        if verbose:
            print 'after dropping the variable', slack, 'from the system :'
            for pol in nextsys:
                print pol
        (topsys, startsols) = (nextsys[:-1], endsolsf2)
    storesols(len(topsys), startsols)
    # py2c_quaddobl_collapse_diagonal(topdim - 2*dim, 0)
    py2c_quaddobl_collapse_diagonal(0, 0)
    result = (loadsys(), loadsols())
    return result
Esempio n. 8
0
from phcpy.phcpy2c \
import py2c_read_standard_start_system_from_file as read_start
cyc10tarfile = DIR + '/cyclic10.target'
cyc10stafile = DIR + '/cyclic10.start'
fail = read_target(len(cyc10tarfile), cyc10tarfile)
from phcpy.interface import load_standard_system as loadsys
from phcpy.interface import load_standard_solutions as loadsols
cyc10 = loadsys()
print 'the cyclic 10-roots problem :'
for pol in cyc10:
    print pol
fail = read_start(len(cyc10stafile), cyc10stafile)
cyc10q = loadsys()
print 'a start system for the cyclic 10-roots problem :'
for pol in cyc10q:
    print pol
cyc10qsols = loadsols()
print 'number of start solutions :', len(cyc10qsols)
print 'the first solution :'
print cyc10qsols[0]
print 'calling the path tracker...'
if(GPU == 0):
    from phcpy.trackers import ade_double_track
    cyc10sols = ade_double_track(cyc10,cyc10q,cyc10qsols,verbose=0)
else:
    from phcpy.trackers import gpu_double_track
    cyc10sols = gpu_double_track(cyc10,cyc10q,cyc10qsols,verbose=0)
print 'number of solutions :', len(cyc10sols)
for sol in cyc10sols:
    print sol
Esempio n. 9
0
from phcpy.phcpy2c \
import py2c_read_standard_start_system_from_file as read_start
cyc10tarfile = DIR + '/cyclic10.target'
cyc10stafile = DIR + '/cyclic10.start'
fail = read_target(len(cyc10tarfile), cyc10tarfile)
from phcpy.interface import load_standard_system as loadsys
from phcpy.interface import load_standard_solutions as loadsols
cyc10 = loadsys()
print 'the cyclic 10-roots problem :'
for pol in cyc10:
    print pol
fail = read_start(len(cyc10stafile), cyc10stafile)
cyc10q = loadsys()
print 'a start system for the cyclic 10-roots problem :'
for pol in cyc10q:
    print pol
cyc10qsols = loadsols()
print 'number of start solutions :', len(cyc10qsols)
print 'the first solution :'
print cyc10qsols[0]
print 'calling the path tracker...'
if (GPU == 0):
    from phcpy.trackers import ade_double_track
    cyc10sols = ade_double_track(cyc10, cyc10q, cyc10qsols, verbose=0)
else:
    from phcpy.trackers import gpu_double_track
    cyc10sols = gpu_double_track(cyc10, cyc10q, cyc10qsols, verbose=0)
print 'number of solutions :', len(cyc10sols)
for sol in cyc10sols:
    print sol
Esempio n. 10
0
def quaddobl_diagonal_solver(dim, dm1, sys1, sols1, dm2, sys2, sols2, \
    tasks=0, verbose=True):
    r"""
    Runs the diagonal homotopies in quad double precision
    to intersect two witness sets stored in (*sys1*, *sols1*) and
    (*sys2*, *sols2*), of respective dimensions *dm1* and *dm2*.
    The ambient dimension equals *dim*.
    Multitasking is available, and is activated by the *tasks* parameter.
    Returns the last system in the cascade and its solutions.
    If *verbose*, then the solver runs in interactive mode, printing
    intermediate results to screen and prompting the user to continue.
    """
    from phcpy.phcpy2c2 import py2c_quaddobl_collapse_diagonal
    from phcpy.interface import store_quaddobl_solutions as storesols
    from phcpy.interface import load_quaddobl_solutions as loadsols
    from phcpy.interface import load_quaddobl_system as loadsys
    from phcpy.phcpy2c2 import py2c_extrinsic_top_diagonal_dimension
    from phcpy.solutions import filter_vanishing
    from phcpy.sets import drop_coordinate_from_quaddobl_solutions
    from phcpy.sets import drop_variable_from_quaddobl_polynomials
    from phcpy.cascades import quad_double_cascade_step
    topdim = py2c_extrinsic_top_diagonal_dimension(dim+dm1, dim+dm2, dm1, dm2)
    kdm = len(sys1) - dm1
    topdiagdim = top_diagonal_dimension(kdm, dm1, dm2)
    if verbose:
        print 'the top dimension :', topdim, 'dim :', dim
        print 'number of slack variables at the top :', topdiagdim 
    quaddobl_diagonal_homotopy(dm1, sys1, sols1, dm2, sys2, sols2)
    if verbose:
        print 'defining the start solutions'
    quaddobl_diagonal_cascade_solutions(dm1, dm2)
    if verbose:
        print 'starting the diagonal cascade'
    (topsys, startsols) = quaddobl_start_diagonal_cascade()
    if verbose:
        print 'the system solved in the start of the cascade :'
        for pol in topsys:
            print pol
        print 'the solutions after starting the diagonal cascade :'
        for sol in startsols:
            print sol
        raw_input('hit enter to continue')
    for k in range(topdiagdim, 0, -1):
        endsols = quad_double_cascade_step(k, topsys, startsols)
        if verbose:
            print 'after running cascade step %d :' % k
            for sol in endsols:
                print sol
        endsolsf1 = filter_vanishing(endsols, 1.0e-8)
        if verbose:
            print 'computed', len(endsolsf1), 'solutions'
            raw_input('hit enter to continue')
        slack = 'zz' + str(k)
        nbvar = len(topsys)
        endsolsf2 = drop_coordinate_from_quaddobl_solutions\
            (endsolsf1, nbvar, slack)
        if verbose:
            print 'after dropping the slack coordinate from the solutions :'
            for sol in endsolsf2:
                print sol
            raw_input('hit enter to continue')
        nextsys = drop_variable_from_quaddobl_polynomials(topsys, slack)
        if verbose:
            print 'after dropping the variable', slack, 'from the system :'
            for pol in nextsys:
                print pol
        (topsys, startsols) = (nextsys[:-1], endsolsf2)
    storesols(len(topsys), startsols)
    # py2c_quaddobl_collapse_diagonal(topdim - 2*dim, 0)
    py2c_quaddobl_collapse_diagonal(0, 0)
    result = (loadsys(), loadsols())
    return result