def track_sequence_of_pieri_systems(): """ Makes a sequence of Pieri systems and runs the path trackers on one path. """ from phcpy.trackers import track nbrows, nbcols, pvts = ask_inputs() answer = raw_input('Double indexing of variables ? (y/n) ') linear = (answer != 'y') dim = nbrows - nbcols planes = random_planes(nbrows, nbcols, pvts) start = start_pieri_system(nbrows, nbcols, pvts, planes, linear) startsols = solve_pieri_system(start) newpvts = update_pivots(nbrows, pvts) planes.append(random_matrix(nbrows, dim)) target = pieri_system(nbrows, nbcols, newpvts, planes, linear) sols = track(target, start, startsols) print '-> the solutions after track :' for sol in sols: print sol while True: answer = raw_input('Continue to next level ? (y/n) ') if(answer != 'y'): break else: pvts = [piv for piv in newpvts] newpvts = update_pivots(nbrows, pvts) if(pvts == newpvts): print '-> no extension of pivots possible: no next level' break start = start_pieri_system(nbrows, nbcols, pvts, planes, linear) print '-> the new start system :' for pol in start: print pol startsols = extend_solutions(sols, nbrows, pvts) print '-> the extended solutions :' for sol in startsols: print sol planes.append(random_matrix(nbrows, dim)) target = pieri_system(nbrows, nbcols, newpvts, planes, linear) print '-> the new target system :' for pol in target: print pol sols = track(target, start, startsols) print '-> the solutions after track :' for sol in sols: print sol answer = raw_input('Write system and solutions to file ? (y/n) ') if(answer == 'y'): write_to_file(target, sols, nbrows, nbcols)
def track_sequence_of_pieri_systems(): """ Makes a sequence of Pieri systems and runs the path trackers on one path. """ from phcpy.trackers import track nbrows, nbcols, pvts = ask_inputs() answer = raw_input('Double indexing of variables ? (y/n) ') linear = (answer != 'y') dim = nbrows - nbcols planes = random_planes(nbrows, nbcols, pvts) start = start_pieri_system(nbrows, nbcols, pvts, planes, linear) startsols = solve_pieri_system(start) newpvts = update_pivots(nbrows, pvts) planes.append(random_matrix(nbrows, dim)) target = pieri_system(nbrows, nbcols, newpvts, planes, linear) sols = track(target, start, startsols) print '-> the solutions after track :' for sol in sols: print sol while True: answer = raw_input('Continue to next level ? (y/n) ') if (answer != 'y'): break else: pvts = [piv for piv in newpvts] newpvts = update_pivots(nbrows, pvts) if (pvts == newpvts): print '-> no extension of pivots possible: no next level' break start = start_pieri_system(nbrows, nbcols, pvts, planes, linear) print '-> the new start system :' for pol in start: print pol startsols = extend_solutions(sols, nbrows, pvts) print '-> the extended solutions :' for sol in startsols: print sol planes.append(random_matrix(nbrows, dim)) target = pieri_system(nbrows, nbcols, newpvts, planes, linear) print '-> the new target system :' for pol in target: print pol sols = track(target, start, startsols) print '-> the solutions after track :' for sol in sols: print sol answer = raw_input('Write system and solutions to file ? (y/n) ') if (answer == 'y'): write_to_file(target, sols, nbrows, nbcols)
def findEmbeddings_dist(syst, interval): global prevSystem global usePrev global prevSolutions # i = 0 y1_left, y1_right, y4_left, y4_right = interval # print fileNamePref while True: if prevSystem and usePrev: sols = track(syst, prevSystem, prevSolutions, tasks=tasks_num) else: sols = solve(syst, verbose=0, tasks=tasks_num) result_real = [] for sol in sols: soldic = strsol2dict(sol) if is_real(sol, tolerance) and soldic['y1'].real>=y1_left and soldic['y1'].real<=y1_right and soldic['y4'].real>=y4_left and soldic['y4'].real<=y4_right: result_real.append(soldic) num_real = len(result_real) if num_real%2==0 and len(sols)==numAll: prevSystem = syst prevSolutions = sols return num_real
def cheater(mdim, pdim, qdeg, start, startsols): """ Generates a random Pieri problem of dimensions (mdim,pdim,qdeg) and solves it with a Cheater's homotopy, starting from the Pieri system in start, at the solutions in startsols. """ dim = mdim * pdim + qdeg * (mdim + pdim) planes = [random_complex_matrix(mdim + pdim, mdim) for _ in range(0, dim)] pols = make_pieri_system(mdim, pdim, qdeg, planes) from phcpy.trackers import track print('cheater homotopy with %d paths' % len(startsols)) sols = track(pols, start, startsols) for sol in sols: print(sol) verify(pols, sols)
def solve_real(mdim, pdim, start, sols): """ Solves a real instance of Pieri problem, for input planes of dimension mdim osculating a rational normal curve. On return are the planes of dimension pdim. """ from phcpy.schubert import real_osculating_planes from phcpy.schubert import make_pieri_system from phcpy.trackers import track oscplanes = real_osculating_planes(mdim, pdim, 0) target = make_pieri_system(mdim, pdim, 0, oscplanes, False) rtsols = track(target, start, sols) inplanes = [array(plane) for plane in oscplanes] outplanes = [solution_plane(mdim + pdim, pdim, sol) for sol in rtsols] return (inplanes, outplanes, target, rtsols)
def cheater(mdim, pdim, qdeg, start, startsols): """ Generates a random Pieri problem of dimensions (mdim,pdim,qdeg) and solves it with a Cheater's homotopy, starting from the Pieri system in start, at the solutions in startsols. """ dim = mdim*pdim + qdeg*(mdim+pdim) planes = [random_complex_matrix(mdim+pdim, mdim) for _ in range(0, dim)] pols = make_pieri_system(mdim, pdim, qdeg, planes) from phcpy.trackers import track print('cheater homotopy with %d paths' % len(startsols)) sols = track(pols, start, startsols) for sol in sols: print(sol) verify(pols, sols)
def solve_real(mdim, pdim, start, sols): """ Solves a real instance of Pieri problem, for input planes of dimension mdim osculating a rational normal curve. On return are the planes of dimension pdim. """ from phcpy.schubert import real_osculating_planes from phcpy.schubert import make_pieri_system from phcpy.trackers import track oscplanes = real_osculating_planes(mdim, pdim, 0) target = make_pieri_system(mdim, pdim, 0, oscplanes, False) rtsols = track(target, start, sols) inplanes = [array(plane) for plane in oscplanes] outplanes = [solution_plane(mdim+pdim, pdim, sol) for sol in rtsols] return (inplanes, outplanes, target, rtsols)
def test(precision="d"): """ Tests the numerical computation of a tropism. """ pols = ["x + x*y + y^3;", "x;"] from phcpy.solver import solve start = [ "x + (-5.89219623474258E-02 - 9.98262591883082E-01*i)*y^2" + " + ( 5.15275165825429E-01 + 8.57024797472965E-01*i)*x*y;", "x+(-9.56176913648087E-01 - 2.92789531586119E-01*i);", ] startsols = solve(start, silent=True) print "computed", len(startsols), "start solutions" from phcpy.tuning import order_endgame_extrapolator_set as set set(4) if precision == "d": from phcpy.trackers import standard_double_track as track elif precision == "dd": from phcpy.trackers import double_double_track as track elif precision == "qd": from phcpy.trackers import quad_double_track as track else: print "wrong level of precision" return sols = track(pols, start, startsols) print "the solutions at the end :" for sol in sols: print sol if precision == "d": print "size of the tropisms container :", standard_size() (wnd, dirs, errs) = standard_retrieve(len(sols), len(pols)) elif precision == "dd": print "size of the tropisms container :", dobldobl_size() (wnd, dirs, errs) = dobldobl_retrieve(len(sols), len(pols)) else: print "size of the tropisms container :", quaddobl_size() (wnd, dirs, errs) = quaddobl_retrieve(len(sols), len(pols)) print "the winding numbers :", wnd print "the directions :" for dir in dirs: print dir print "the errors :", errs
def find_more_points(self, num_points, return_complex=False): """ We find additional points on the variety. """ points = [] failure = 0 while (len(points) < num_points): phcsystem = self._system() phcsolutions = track(phcsystem, self._startsystem, self._startsol) # Parsing the output of solutions for sol in phcsolutions: solutiondict = strsol2dict(sol) point = [solutiondict[variable] for variable in self.varlist] if return_complex: points.append(tuple(point)) else: closeness = True for component in point: # choses the points we want if self._is_close(component.imag) \ and self._in_bounds(component.real): # sometimes phcpy gives more points than we # ask, thus the additional check if component == point[-1] \ and closeness \ and len(points) < num_points: points.append( tuple([ component.real for component in point ])) assert len(points) <= num_points failure = 0 else: closeness = False failure = failure + 1 if self._failure <= failure: raise RuntimeError( "equation has too many complex solutions in a row") self.points = points + self.points
def osculating_input(mdim, pdim, qdeg, start, startsols): """ Generates real mdim-planes osculating a rational normal curve and solves this Pieri problem using the system in start, with corresponding solutions in startsols. """ target_planes = real_osculating_planes(mdim, pdim, qdeg) # print 'real osculating planes :', target_planes target_system = make_pieri_system(mdim, pdim, qdeg, target_planes, False) print('the start system of length %d :' % len(start)) for pol in start: print(pol) print('the target system of length %d :' % len(target_system)) for pol in target_system: print(pol) from phcpy.trackers import track target_solutions = track(target_system, start, startsols) for sol in target_solutions: print(sol) verify(target_system, target_solutions)
def test_standard_polyhedral_homotopy(): """ Test on jumpstarting a polyhedral homotopy in standard precision. """ from phcpy.phcpy2c3 import py2c_syscon_clear_standard_system from phcpy.phcpy2c3 import py2c_syscon_clear_standard_Laurent_system from phcpy.trackers import track py2c_syscon_clear_standard_system() py2c_syscon_clear_standard_Laurent_system() qrt = random_trinomials() mixvol = mixed_volume(qrt) print('the mixed volume is', mixvol) (rqs, rsols) = random_coefficient_system() print('found %d solutions' % len(rsols)) newton_step(rqs, rsols) print('tracking to target...') pqr = permute_standard_system(qrt) qsols = track(pqr, rqs, rsols) newton_step(qrt, qsols)
def test(precision='d'): """ Tests the numerical computation of a tropism. """ pols = ['x + x*y + y^3;', 'x;'] from phcpy.solver import solve start = ['x + (-5.89219623474258E-02 - 9.98262591883082E-01*i)*y^2' \ + ' + ( 5.15275165825429E-01 + 8.57024797472965E-01*i)*x*y;', \ 'x+(-9.56176913648087E-01 - 2.92789531586119E-01*i);'] startsols = solve(start, verbose=False) print('computed', len(startsols), 'start solutions') from phcpy.tuning import order_endgame_extrapolator_set as set set(4) if precision == 'd': from phcpy.trackers import standard_double_track as track elif precision == 'dd': from phcpy.trackers import double_double_track as track elif precision == 'qd': from phcpy.trackers import quad_double_track as track else: print('wrong level of precision') return sols = track(pols, start, startsols) print('the solutions at the end :') for sol in sols: print(sol) if precision == 'd': print('size of the tropisms container :', standard_size()) (wnd, dirs, errs) = standard_retrieve(len(sols), len(pols)) elif precision == 'dd': print('size of the tropisms container :', dobldobl_size()) (wnd, dirs, errs) = dobldobl_retrieve(len(sols), len(pols)) else: print('size of the tropisms container :', quaddobl_size()) (wnd, dirs, errs) = quaddobl_retrieve(len(sols), len(pols)) print('the winding numbers :', wnd) print('the directions :') for dir in dirs: print(dir) print('the errors :', errs)
def findEmbeddings(syst): global prevSystem global usePrev global prevSolutions i = 0 while True: if prevSystem and usePrev: sols = track(syst, prevSystem, prevSolutions, tasks=tasks_num) else: sols = solve(syst, verbose=0, tasks=tasks_num) result_real = [] for sol in sols: soldic = strsol2dict(sol) if is_real(sol, tolerance): result_real.append(soldic) num_real = len(result_real) if num_real%4==0 and len(sols)==numAll: prevSystem = syst prevSolutions = sols return num_real elif numAllowedMissing and len(sols)==numAll: print 'The number of real embeddings was not divisible by 4. ', return num_real elif numAllowedMissing and len(sols)>=numAll-numAllowedMissing: print 'Continuing although there were '+str(numAll-len(sols))+' solutions missing. ', return num_real else: usePrev = False i += 1 # print 'PHC failed, trying again: '+str(i) if i>=3: print 'PHC failed 3 times', return -1
Illustration of a mixed volume computation, polyhedral homotopies and the path tracking in double precision. First we construct a random coefficient start system, computing the mixed volume and running polyhedral homotopies. Then we use the constructed start system g and corresponding start solutions sols to solve the original system f. Finally, we verify the solutions with one Newton step on each computed solution, in double double precision. """ f = ['x^3*y + x*y^2 - 8;', 'x*y - 3;'] print 'the polynomials in the target system :' for pol in f: print pol from phcpy.solver import mixed_volume as mv from phcpy.solver import random_coefficient_system as rcs print 'the mixed volume :', mv(f) (g, gsols) = rcs() print 'the polynomials in the start system :' for pol in g: print pol print 'number of start solutions :', len(gsols) from phcpy.trackers import standard_double_track as track fsols = track(f, g, gsols) from phcpy.solver import newton_step for sol in fsols: print sol print 'one Newton step in double double precision...' nsols = newton_step(f, fsols, precision='dd') for sol in nsols: print sol
#GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program. If not, see <https://www.gnu.org/licenses/>. import sys import ast import os from phcpy.trackers import track try: from phcpy import _number_of_cores_ as tasks_num except: tasks_num = 2 syst2 = ast.literal_eval(sys.argv[1]) #syst = ast.literal_eval(sys.argv[2]) #sols = ast.literal_eval(sys.argv[3]) pref = sys.argv[3] filePrev = sys.argv[2] with open(filePrev, 'r') as fPrev: syst, sols = [ast.literal_eval(line) for line in fPrev] file = open( os.path.dirname(os.path.realpath(__file__)) + '/../tmp/' + pref + 'track.txt', 'w') sol = track(syst2, syst, sols, tasks=tasks_num) file.write(str(sol))