Example #1
0
def test_monitored_track():
    """
    Often the number of paths to track can be huge
    and waiting on the outcome of track() without knowing
    how many paths that have been tracked so far can be annoying.
    This script illustrates how one can monitor the progress
    of the path tracking.  We must use the same gamma constant
    with each call of track.
    """
    from random import uniform
    from cmath import pi, exp

    angle = uniform(0, 2 * pi)
    ourgamma = exp(complex(0, 1) * angle)
    from phcpy.solver import total_degree_start_system, newton_step

    quadrics = ["x**2 + 4*y**2 - 4;", "2*y**2 - x;"]
    (startsys, startsols) = total_degree_start_system(quadrics)
    targetsols = []
    for ind in range(0, len(startsols)):
        print "tracking path", ind + 1, "...",
        endsol = track(quadrics, startsys, [startsols[ind]], gamma=ourgamma)
        print "found solution\n", endsol[0]
        targetsols.append(endsol[0])
    print "tracked", len(targetsols), "paths, running newton_step..."
    newton_step(quadrics, targetsols)
Example #2
0
 def _start_system(self):
     """
     We first set up a start system so phcpy doesn't have to create
     a new one everytime.
     """
     phcsystem = self._system()
     startsystem, startsol = total_degree_start_system(phcsystem)
     return startsystem, startsol
Example #3
0
def test_next_track(precision="d", decimals=80):
    """
    Tests the step-by-step tracking of a solution path.
    Three 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 multiprecision with as many decimal places
    in the working precision as the value set by decimals.
    """
    from phcpy.solver import total_degree_start_system

    quadrics = ["x**2 + 4*y**2 - 4;", "2*y**2 - x;"]
    (startsys, startsols) = total_degree_start_system(quadrics)
    print "the first start solution :\n", startsols[0]
    if precision == "d":
        initialize_standard_tracker(quadrics, startsys)
        initialize_standard_solution(2, startsols[0])
        while True:
            sol = next_standard_solution()
            print "the next solution :\n", sol
            answer = raw_input("continue ? (y/n) ")
            if answer != "y":
                break
    elif precision == "dd":
        initialize_dobldobl_tracker(quadrics, startsys)
        initialize_dobldobl_solution(2, startsols[0])
        while True:
            sol = next_dobldobl_solution()
            print "the next solution :\n", sol
            answer = raw_input("continue ? (y/n) ")
            if answer != "y":
                break
    elif precision == "qd":
        initialize_quaddobl_tracker(quadrics, startsys)
        initialize_quaddobl_solution(2, startsols[0])
        while True:
            sol = next_quaddobl_solution()
            print "the next solution :\n", sol
            answer = raw_input("continue ? (y/n) ")
            if answer != "y":
                break
    elif precision == "mp":
        initialize_multprec_tracker(quadrics, startsys, decimals)
        initialize_multprec_solution(2, startsols[0])
        while True:
            sol = next_multprec_solution()
            print "the next solution :\n", sol
            answer = raw_input("continue ? (y/n) ")
            if answer != "y":
                break
    else:
        print "wrong argument for precision"
Example #4
0
def test_next_track(precision='d', decimals=80):
    """
    Tests the step-by-step tracking of a solution path.
    Three 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 multiprecision with as many decimal places
    in the working precision as the value set by decimals.
    """
    from phcpy.solver import total_degree_start_system
    quadrics = ['x**2 + 4*y**2 - 4;', '2*y**2 - x;']
    (startsys, startsols) = total_degree_start_system(quadrics)
    print 'the first start solution :\n', startsols[0]
    if(precision == 'd'):
        initialize_standard_tracker(quadrics, startsys)
        initialize_standard_solution(2, startsols[0])
        while True:
            sol = next_standard_solution()
            print 'the next solution :\n', sol
            answer = raw_input('continue ? (y/n) ')
            if(answer != 'y'):
                break
    elif(precision == 'dd'):
        initialize_dobldobl_tracker(quadrics, startsys)
        initialize_dobldobl_solution(2, startsols[0])
        while True:
            sol = next_dobldobl_solution()
            print 'the next solution :\n', sol
            answer = raw_input('continue ? (y/n) ')
            if(answer != 'y'):
                break
    elif(precision == 'qd'):
        initialize_quaddobl_tracker(quadrics, startsys)
        initialize_quaddobl_solution(2, startsols[0])
        while True:
            sol = next_quaddobl_solution()
            print 'the next solution :\n', sol
            answer = raw_input('continue ? (y/n) ')
            if(answer != 'y'):
                break
    elif(precision == 'mp'):
        initialize_multprec_tracker(quadrics, startsys, decimals)
        initialize_multprec_solution(2, startsols[0])
        while True:
            sol = next_multprec_solution()
            print 'the next solution :\n', sol
            answer = raw_input('continue ? (y/n) ')
            if(answer != 'y'):
                break
    else:
        print 'wrong argument for precision'
Example #5
0
def test_next_track(precision='d', decimals=80):
    """
    Tests the step-by-step tracking of a solution path.
    Three 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 multiprecision with as many decimal places
    in the working precision as the value set by decimals.
    """
    from phcpy.solver import total_degree_start_system
    quadrics = ['x**2 + 4*y**2 - 4;', '2*y**2 - x;']
    (startsys, startsols) = total_degree_start_system(quadrics)
    print('the first start solution :\n', startsols[0])
    if(precision == 'd'):
        initialize_standard_tracker(quadrics, startsys)
        initialize_standard_solution(2, startsols[0])
        while True:
            sol = next_standard_solution()
            print('the next solution :\n', sol)
            answer = input('continue ? (y/n) ')
            if(answer != 'y'):
                break
    elif(precision == 'dd'):
        initialize_dobldobl_tracker(quadrics, startsys)
        initialize_dobldobl_solution(2, startsols[0])
        while True:
            sol = next_dobldobl_solution()
            print('the next solution :\n', sol)
            answer = input('continue ? (y/n) ')
            if(answer != 'y'):
                break
    elif(precision == 'qd'):
        initialize_quaddobl_tracker(quadrics, startsys)
        initialize_quaddobl_solution(2, startsols[0])
        while True:
            sol = next_quaddobl_solution()
            print('the next solution :\n', sol)
            answer = input('continue ? (y/n) ')
            if(answer != 'y'):
                break
    elif(precision == 'mp'):
        initialize_multprec_tracker(quadrics, startsys, decimals)
        initialize_multprec_solution(2, startsols[0])
        while True:
            sol = next_multprec_solution()
            print('the next solution :\n', sol)
            answer = input('continue ? (y/n) ')
            if(answer != 'y'):
                break
    else:
        print('wrong argument for precision')
Example #6
0
def test_monitored_track():
    """
    Often the number of paths to track can be huge
    and waiting on the outcome of track() without knowing
    how many paths that have been tracked so far can be annoying.
    This script illustrates how one can monitor the progress
    of the path tracking.  We must use the same gamma constant
    with each call of track.
    """
    from random import uniform
    from cmath import pi, exp
    angle = uniform(0, 2*pi)
    ourgamma = exp(complex(0, 1)*angle)
    from phcpy.solver import total_degree_start_system, newton_step
    quadrics = ['x**2 + 4*y**2 - 4;', '2*y**2 - x;']
    (startsys, startsols) = total_degree_start_system(quadrics)
    targetsols = []
    for ind in range(0, len(startsols)):
        print 'tracking path', ind+1, '...',
        endsol = track(quadrics, startsys, [startsols[ind]], gamma=ourgamma)
        print 'found solution\n', endsol[0]
        targetsols.append(endsol[0])
    print 'tracked', len(targetsols), 'paths, running newton_step...'
    newton_step(quadrics, targetsols)