def test(): """ Runs a test on algebraic sets. """ from phcpy.phcpy2c3 import py2c_set_seed py2c_set_seed(234798272) test_diaghom('d')
def eqs(ip): #x1 -> omega_s #x2 -> ns #x3 -> np eq1 = "{0:+.16f}*x1{1:+.16f}*x2{2:+.16f}*x3{3:+.16f};" .format((-gi - gs)/(gi*xs**2), -alpha**2 + 1, -2*alpha + 2, (-ei*gs + es*gi + 2*gs*omega_p_chosen)/(gi*xs**2)) eq2 = "{0:.16f}*x1^2{1:+.16f}*x1*x2{2:+.16f}*x1*x3{3:+.16f}*x1{4:+.16f}*x2^2{5:+.16f}*x2*x3{6:+.16f}*x2{7:+.16f}*x3^2{8:+.16f}*x3{9:+.16f};" .format(xs**(-4), (-4*alpha - 2)/xs**2, -4/xs**2, -2*es/xs**4, 4*alpha**2 + 4*alpha + 1, 8*alpha + 4, (4*alpha*es + 2*es)/xs**2, -alpha + 4, 4*es/xs**2, (4*es**2 + gs**2)/(4*xs**4)) eq3 = "{0:.16f}*x1^2*x2^2{1:+.16f}*x1*x2^3{2:+.16f}*x1*x2^2*x3{3:+.16f}*x1*x2^2{4:+.16f}*x1*x2*x3^2{5:+.16f}*x1*x2*x3{6:+.16f}*x2^4{7:+.16f}*x2^3*x3{8:+.16f}*x2^3{9:+.16f}*x2^2*x3^2{10:+.16f}*x2^2*x3{11:+.16f}*x2^2{12:+.16f}*x2*x3^3{13:+.16f}*x2*x3^2{14:+.16f}*x2*x3{15:+.16f}*x3^4{16:+.16f}*x3^3{17:+.16f}*x3^2{18:+.16f}*x3;" .format(4.0/xs**4, 1.0*(-16.0*alpha - 8.0)/xs**2, 1.0*(8.0*alpha - 8.0)/xs**2, -8.0*es/xs**4, 4.0/xs**2, 1.0*(4.0*ep - 4.0*omega_p_chosen)/(xp**2*xs**2), 16.0*alpha**2 + 16.0*alpha + 4.0, -16.0*alpha**2 + 8.0*alpha + 8.0, 1.0*(16.0*alpha*es + 8.0*es)/xs**2, 4.0*alpha**2 - 16.0*alpha, 1.0*(-8.0*alpha*ep*xs**2 - 8.0*alpha*es*xp**2 + 8.0*alpha*omega_p_chosen*xs**2 - 4.0*ep*xs**2 + 8.0*es*xp**2 + 4.0*omega_p_chosen*xs**2)/(xp**2*xs**2), 1.0*(4.0*es**2 + 1.0*gs**2)/xs**4, 4.0*alpha - 4.0, 1.0*(4.0*alpha*ep*xs**2 - 4.0*alpha*omega_p_chosen*xs**2 - 4.0*ep*xs**2 - 4.0*es*xp**2 + 4.0*omega_p_chosen*xs**2)/(xp**2*xs**2), 1.0*(-4.0*ep*es + 4.0*es*omega_p_chosen + 1.0*gs)/(xp**2*xs**2), 1.00000000000000, 1.0*(2.0*ep - 2.0*omega_p_chosen)/xp**2, 1.0*(1.0*ep**2 - 2.0*ep*omega_p_chosen + 1.0*omega_p_chosen**2 + 0.25)/xp**4, -1.0*ip) f = [eq1, eq2, eq3] #seeding random number generator for reproducible results py2c_set_seed(130683) s = solve(f,silent=True) ns = len(s) #number of solutions R = [] for k in range(ns): d = strsol2dict(s[k]) x123 = np.array([d['x1'], d['x2'], d['x3']]) real = np.real(x123) imag = np.fabs(np.imag(x123)) sol = np.empty((real.size + imag.size,), dtype=real.dtype) sol[0::2] = real sol[1::2] = imag if np.allclose(imag, np.zeros(3)): if real[1] > 1e-7: R.append((sol[0], sol[2], sol[4], ip)) return R
def test(): """ Solves the systems and tests on their number of solutions. """ from phcpy.phcpy2c3 import py2c_set_seed py2c_set_seed(834798272) from phcpy import solver print('\nsolving a random binomial system...') pols = binomials() sols = solver.solve(pols) assert len(sols) == 20 print('test on binomial system passed') print('\nsolving the cyclic 7-roots problem...') pols = cyclic7() sols = solver.solve(pols) assert len(sols) == 924 print('test on cyclic 7-roots passed') print('\nsolving the benchmark problem D1...') pols = sysd1() sols = solver.solve(pols) assert len(sols) == 48 print('test on benchmark problem D1 passed') print('\nsolving a generic 5-point 4-bar design problem...') pols = fbrfive4() sols = solver.solve(pols) assert len(sols) == 36 print('test on 4-bar system passed') print('\ncomputing all Nash equilibria...') pols = game4two() sols = solver.solve(pols) assert len(sols) == 9 print('test on Nash equilibria for 4 players passed') print('\nsolving a problem in magnetism...') pols = katsura6() sols = solver.solve(pols) assert len(sols) == 64 print('test on a problem in magnetism passed') print('\nsolving a neural network model...') pols = noon3() sols = solver.solve(pols) assert len(sols) == 21 print('test on a neural network model passed') print('\nsolving a mechanical design problem...') pols = rps10() sols = solver.solve(pols) assert len(sols) == 1024 print('test on RPS serial chains problem passed') print('\nsolving a fully real Stewart-Gough platform...') pols = stewgou40() sols = solver.solve(pols) assert len(sols) == 40 print('test on real Stewart-Gough platform passed') print('\ncomputing all tangent lines to 4 spheres...') pols = tangents() sols = solver.solve(pols) assert len(sols) == 6 print('test on multiple tangent lines to spheres passed')
def test(): """ Fixes a seed for the random number generators before running the test on the cascade homotopies. """ from phcpy.phcpy2c3 import py2c_set_seed py2c_set_seed(234798272) # test_cascade() test_run_cascade()
def test(): """ Sets the seed for the random number generators to a fixed number and then runs a test. """ from phcpy.phcpy2c3 import py2c_set_seed py2c_set_seed(234798272) # test_monodromy() # test_decompose() test_solve()
def main(): """ Excerpt from the user manual of phcpy. """ from phcpy.phcpy2c3 import py2c_set_seed py2c_set_seed(2019) p = ['x^2 + y - 3;', 'x + 0.125*y^2 - 1.5;'] print('constructing a total degree start system ...') from phcpy.solver import total_degree_start_system as tds q, qsols = tds(p) print('number of start solutions :', len(qsols)) from phcpy.trackers import initialize_standard_tracker from phcpy.trackers import initialize_standard_solution from phcpy.trackers import next_standard_solution initialize_standard_tracker(p, q, False) # True) # initialize_standard_tracker(p, q, True) from phcpy.solutions import strsol2dict import matplotlib.pyplot as plt plt.ion() fig = plt.figure() for k in range(len(qsols)): if(k == 0): axs = fig.add_subplot(221) elif(k == 1): axs = fig.add_subplot(222) elif(k == 2): axs = fig.add_subplot(223) elif(k == 3): axs = fig.add_subplot(224) startsol = qsols[k] initialize_standard_solution(len(p),startsol) dictsol = strsol2dict(startsol) xpoints = [dictsol['x']] ypoints = [dictsol['y']] for k in range(300): ns = next_standard_solution() dictsol = strsol2dict(ns) xpoints.append(dictsol['x']) ypoints.append(dictsol['y']) tval = dictsol['t'].real # tval = eval(dictsol['t'].lstrip().split(' ')[0]) if(tval == 1.0): break print(ns) xre = [point.real for point in xpoints] yre = [point.real for point in ypoints] axs.set_xlim(min(xre)-0.3, max(xre)+0.3) axs.set_ylim(min(yre)-0.3, max(yre)+0.3) dots, = axs.plot(xre,yre,'r-') fig.canvas.draw() fig.canvas.draw() ans = input('hit return to exit')