コード例 #1
0
def server(r, servercolor=color.rgb(0.5, 0.5, 0.8)):
    c = canvas.canvas()
    c.fill(path.circle(0, 0, r), [servercolor, trafo.scale(1, 0.5)])
    h = 2 * r
    p = path.path(path.moveto(-r, 0), path.lineto(-r, -h),
                  path.arc(0, -h, r, 180, 0), path.lineto(r, 0),
                  path.arcn(0, 0, r, 0, 180), path.closepath())
    c.fill(p, [servercolor, trafo.scale(1, 0.5).translated(0, -0.08 * r)])
    return c
コード例 #2
0
def read(size, color):
    size = size * 0.25
    cread = canvas.canvas()
    cread.fill(path.circle(0, 0, 0.35), [color, trafo.scale(size)])
    p = path.path(path.moveto(0.8, 0),
                  path.curveto(0.2, 0.5, -0.2, 0.5, -0.8, 0),
                  path.curveto(-0.2, -0.5, 0.2, -0.5, 0.8, 0),
                  path.closepath())
    cread.stroke(p, [color, style.linewidth.thick, trafo.scale(size)])
    return cread
コード例 #3
0
ファイル: refactoring.py プロジェクト: punkdit/fibonacci
def manifold(x, y, labels, count):

    if count in [0, 2]:
        c.stroke(path.line(x-r0, y, x+r1+r0, y), st_curve)
    else:
        extra = list(st_curve)
        #if count==3:
        #    extra.append(trafo.scale(x=x, y=y, sx=1, sy=-1))
        Turtle(x-0.85*r0, y, pi/2).\
            fwd(0.3).\
            right(0.25*pi, 0.4).left(0.50*pi, 0.73).left(0.88*pi, 0.15).\
            fwd(0.55).\
            right(0.88*pi, 0.15).right(0.50*pi, 0.73).\
            left(0.25*pi, 0.52).goto(x+r1+r0, y).\
            stroke(extra)

    if count==0:
        c.text(x+r1+r0, y-0.2, "$f$", northwest)
    else:
        c.text(x+r1+r0, y-0.2, "$R^{a_1a_2}_{b_1}f$", northwest)

    c.text(x+(r0+r1)/2, y+0.7, "$f'$", southwest)

    if count == 0:
        Turtle(x, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*r1).stroke(st_target+[trafo.scale(x=x, y=y, sx=1, sy=-1)])
    elif count == 3:
        Turtle(x-0.05, y, 0.90*pi).left(0.30*pi, 0.8).left(0.3*pi, 2.8).\
            stroke(st_target+[trafo.scale(x=x, y=y, sx=1, sy=-1)])
    else:
        Turtle(x+r0, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*(r1-r0)).stroke(st_target)

    for i in range(3):
        _x = [x, x+r0, x+r1][i]
        p = path.circle(_x, y, 0.08)
        c.fill(p, [white])
        c.stroke(p)
        ydelta = -0.25
        xdelta = 0.00
        if count==3  and labels[i]=="a_2":
            ydelta = -0.35
            xdelta = +0.1
        if count==3  and labels[i]=="a_1":
            xdelta = -0.1
            ydelta = +0.3
        c.text(_x+xdelta, y+ydelta, r"$\scriptstyle %s$"%labels[i], center)

    x1 = x+(r0+r1)/2.
    c.text(x1, y-0.2, "...", north)

    c.fill(path.rect(x1-0.4, y-0.1, 0.8, 0.2), [white])
    c.stroke(path.line(x1-0.4, y, x1+0.4, y), [green, style.linewidth.THick]+st_dotted)

    c.stroke(path.circle(x+r0/2, y, r0), [trafo.scale(x=x+r0/2, y=y, sx=1.0, sy=0.8)])

    c.text(x, y+0.3*h, "$b_1$", southeast)
コード例 #4
0
ファイル: refactoring.py プロジェクト: punkdit/fibonacci
def manifold(x, y, labels):

    global count
    if count in [0, 2]:
        c.stroke(path.line(x-r0, y, x+r1+r0, y), st_curve)
    else:
        extra = list(st_curve)
        if count==3:
            extra.append(trafo.scale(x=x, y=y, sx=1, sy=-1))
        Turtle(x-0.85*r0, y, pi/2).\
            fwd(0.3).\
            right(0.25*pi, 0.4).left(0.50*pi, 0.73).left(0.88*pi, 0.15).\
            fwd(0.55).\
            right(0.88*pi, 0.15).right(0.50*pi, 0.73).left(0.25*pi, 0.4).goto(x+r1+r0, y).\
            stroke(extra)

#    st_target = st_curve+st_dashed
    st_target = [red, style.linewidth.THick, deco.earrow(size=0.2)]
    if count == 0:
        Turtle(x, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*r1).stroke(st_target)
    elif count == 3:
        Turtle(x-0.05, y, 0.90*pi).left(0.30*pi, 0.8).left(0.3*pi, 2.8).stroke(st_target)
    else:
        Turtle(x+r0, y, 3*pi/4).left(0.95*pi/2, 2**0.5/2*(r1-r0)).stroke(st_target)

    for i in range(3):
        _x = [x, x+r0, x+r1][i]
        p = path.circle(_x, y, 0.08)
        c.fill(p, [white])
        c.stroke(p)
        ydelta = 0.25
        xdelta = 0.00
        if count==1  and labels[i]=="a":
            ydelta = -0.35
            xdelta = +0.1
        if count==3  and labels[i]=="a":
            ydelta = -0.35
            xdelta = -0.1
        c.text(_x+xdelta, y+ydelta, r"$\scriptstyle %s$"%labels[i], south)

    c.text(x+(r0+r1)/2., y-0.2, "...", north)

    c.stroke(path.circle(x+r0/2, y, r0), [trafo.scale(x=x+r0/2, y=y, sx=1.0, sy=0.8)])

    if count in [0, 3]:
        c.text(x+r0, y+0.3*h, "$\omega$", southwest)
    else:
        c.text(x+r0, y+0.3*h, "$f(\omega)$", southwest)

    count += 1
コード例 #5
0
ファイル: skein.py プロジェクト: punkdit/fibonacci
def circ(x, y, txt):
    p = path.circle(x, y, 0.5*r0)
    st_scale = [trafo.scale(x=x, y=y, sx=1., sy=sy)]
    c.fill(p, st_scale+[shade2])
    c.stroke(p, st_scale)
    c.fill(path.circle(x, y-sy*0.5*r0, 0.05))
    c.text(x-0.5*r0, y+0.5*r0, txt, center)
コード例 #6
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
def ellipse(x, y, radius, sx=1., sy=1., color=None, extra=[], arrow=None):
    p = path.circle(x, y, radius)
    t = trafo.scale(sx=sx, sy=sy)
    if color:
        c.fill(p, [t, shade]+extra)
    c.stroke(p, [t]+extra)
    if arrow is not None:
        c.stroke(p, [t]+extra+[deco.earrow(size=arrow)])
コード例 #7
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
def slice(x, y):
    p = path.circle(x, y, 1.)
    t = trafo.scale(1., 0.3, x, y)
    c.fill(p, [shade, t])
    c.stroke(p, [t])

    hole(x-0.5, y, 0.07, '')
    hole(x, y, 0.07, '')
    hole(x+0.5, y, 0.07, '')
コード例 #8
0
ファイル: skein.py プロジェクト: punkdit/fibonacci
def ucirc():
    x1, y1 = x-dx*r, y-r
    st_scale = [trafo.scale(x=x1, y=y1, sx=1., sy=sy)]

    c.fill(path.circle(x1, y1, 0.5*r0), st_scale+[shade0])
    c.stroke(path.path(path.arc(x1, y1, 0.5*r0, 180., 0.)), st_scale)
    x2, y2 = x1-0.5*dx*sy*r0, y1-0.5*sy*r0
    c.stroke(path.line(x, y, x2, y2))
    c.fill(path.circle(x2, y2, 0.05))
    c.text(x2-0.5*r0, y2-0.5*r0, "${c}$", southeast)
コード例 #9
0
ファイル: refactoring.py プロジェクト: punkdit/fibonacci
def manifold(x, y, labels):

    global count

    p = path.circle(x+r0/2, y, r0)
    extra = [trafo.scale(x=x+r0/2, y=y, sx=1.0, sy=0.8)]
    c.fill(p, extra+[shade])
    c.stroke(p, extra)

    if count in [0, 2]:
        c.stroke(path.line(x-0.5*r0, y, x+r0+0.5*r0, y), st_curve)
    else:
        extra = list(st_curve)
        if count==3:
            extra.append(trafo.scale(x=x, y=y, sx=1, sy=-1))
        Turtle(x-0.85*r0+0.3, y, pi/2).\
            right(0.25*pi, 0.4).left(0.50*pi, 0.73).left(0.88*pi, 0.15).\
            fwd(0.55).\
            right(0.88*pi, 0.15).right(0.50*pi, 0.73).left(0.25*pi, 0.4).\
            stroke(extra)

    for i in range(2):
        _x = [x, x+r0][i]
        p = path.circle(_x, y, 0.08)
        c.fill(p, [white])
        c.stroke(p)
        ydelta = 0.25
        xdelta = 0.00
        if count==1  and labels[i]=="a":
            ydelta = -0.35
            xdelta = +0.1
        if count==3  and labels[i]=="a":
            ydelta = -0.35
            xdelta = -0.1
        c.text(_x+xdelta, y+ydelta, r"$\scriptstyle %s$"%labels[i], south)

    c.text(x+1.5*r0, y-0.6, r"$\scriptstyle \hat{c}$", center)
    c.text(x+1.7*r0, y, r"$\bigr)$", center)
    c.text(x-0.9*r0, y, r"$\H\bigl($", center)

    count += 1
コード例 #10
0
ファイル: modular.py プロジェクト: punkdit/fibonacci
def surface(x, y, r, fill=shade, mark=False, orient=None):
    p = path.circle(x, y, r)
    if fill is not None:
        c.fill(p, [fill])
    c.stroke(p)
    if orient == True:
        c.stroke(p, [deco.earrow()])
    elif orient == False:
        c.stroke(p, [deco.earrow(), trafo.scale(x=x, y=y, sx=1, sy=-1)])
    if mark:
        p = path.circle(x, y-r, 0.06)
        c.fill(p)
コード例 #11
0
def write(size, color):
    size = size * 0.3
    cwrite = canvas.canvas()
    p = path.path(path.moveto(-0.2, 0.8), path.lineto(0.2, 0.8),
                  path.lineto(0.2, 0), path.lineto(0, -0.2),
                  path.lineto(-0.2, 0), path.lineto(-0.2, 0.8),
                  path.closepath(), path.moveto(0, 0.8), path.lineto(0, 0.05),
                  path.moveto(-0.2, 0), path.arcn(-0.1, 0, 0.1, 180, 20),
                  path.arcn(0.1, 0, 0.1, 160, 0))
    cwrite.stroke(
        p, [color,
            trafo.scale(size).rotated(-30).translated(0, -0.4 * size)])
    return cwrite
コード例 #12
0
def file(c, size=1, xoff=0, yoff=0, attrs=[], title=''):
    w = 3
    h = 2.1
    fold = 0.6
    outline = path.path(path.moveto(0, 0), path.lineto(w, 0),
                        path.lineto(w, h - fold), path.lineto(w - fold, h),
                        path.lineto(0, h), path.closepath())
    foldpath = path.path(path.moveto(w - fold, h),
                         path.lineto(w - fold, h - fold),
                         path.lineto(w, h - fold))
    c1 = canvas.canvas()
    c1.stroke(outline, attrs)
    d = deformer.smoothed(0.2)
    c1.stroke(d.deform(foldpath), attrs)
    c1.stroke(path.rect(0.1 * w, 0.3 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.45 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.6 * h, 0.6 * w, 0.1 * h))
    c1.stroke(path.rect(0.1 * w, 0.75 * h, 0.6 * w, 0.1 * h))
    c1.text(0.1, 0.1, r'\sffamily ' + title, [trafo.scale(0.7)])
    myattrs = [trafo.translate(xoff, yoff), trafo.scale(size)]
    myattrs.extend(attrs)
    c.insert(c1, myattrs)
コード例 #13
0
ファイル: hexagon.py プロジェクト: punkdit/fibonacci
def tetra(x, y, count=None, subcount=None, rev=1, back=True, front=True, reflect=False):

    if back:
        circle(x, y, r, shade)

    rr = 1.0*r
    if subcount is not None:
        ps = []
        for i in range(3):
            theta1 = rev*2*(i+subcount)*pi/3
            if i==0:
                # start of curve
                x1, y1 = x+rr*sin(theta1), y+rr*cos(theta1)
                ps.append((x1, y1))
            if i==1:
                x1, y1 = x+0.7*r*sin(theta1), y+0.7*r*cos(theta1)
                ps.append((x1, y1))
            else:
                x1, y1 = x+0.4*r*sin(theta1), y+0.4*r*cos(theta1)
                ps.append((x1, y1))
            if i==2:
                # end of curve
                x1, y1 = x+1.0*rr*sin(theta1), y+1.0*rr*cos(theta1)
                ps.append((x1, y1))
        c.stroke(path.path(
            path.moveto(*ps[0]),
            path.lineto(*ps[1]),
            path.lineto(*ps[2]), 
            path.lineto(*ps[3]), 
            path.lineto(*ps[4])), 
            st_curve+[deformer.smoothed(0.6)])

    if front:
        for theta1 in [0., 2*pi/3, 4*pi/3]:
            x1, y1 = x+0.5*r*sin(theta1), y+0.5*r*cos(theta1)
            circle(x1, y1, r0, white)

    if count is not None:

        assert 0<=count<=2
        s = 0.86*r
        r1 = 2.4*r0
        extra = []
        #c.text(x, y, count)
        if reflect:
            #count = [0, 1, 2][count]
            extra.append(trafo.scale(x=x, y=y, sx=-1, sy=1))
        extra += [trafo.rotate(-count*120, x=x, y=y)]
        t = Turtle(x1, y1-r1, -pi/2).right(pi, r1).fwd(s).right(pi, r1).fwd(s)
        t.stroke(extra)
        t.stroke(extra+[deco.earrow()])
コード例 #14
0
ファイル: drawer.py プロジェクト: AntipovDen/XdivK
def draw_drop(x, y, r, c):
    c.fill(path.circle(x, y - 3 * r, r), [color.cmyk.RoyalBlue])
    c.stroke(path.circle(x, y - 3 * r, r))

    triangle = path.line(
        x, y, x + sqrt(8) * r / 3, y - 8 * r / 3) << path.line(
            x + sqrt(8) * r / 3, y - 8 * r / 3, x - sqrt(8) * r / 3,
            y - 8 * r / 3)
    triangle.append(path.closepath())
    c.fill(triangle, [color.cmyk.RoyalBlue])
    c.stroke(
        path.line(x - sqrt(8) * r / 3, y -
                  8 * r / 3, x, y) << path.line(x, y, x + sqrt(8) * r / 3, y -
                                                8 * r / 3))

    c.fill(path.circle(x - 0.5 * r, (y - 3 * r) / 2, 0.2 * r),
           [color.rgb.white, trafo.scale(sx=1, sy=2)])
コード例 #15
0
    c.fill(p, [clientcolor, trafo.translate(0, -1.3*r)])
    return c

random.seed(812357)

arrowcolor = color.grey(0.5)

text.set(text.LatexRunner)                                                                           
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}')
unit.set(xscale=1.3)

c = canvas.canvas()
pos = [(0, 1), (sin(2*pi/3), cos(2*pi/3)), (-sin(2*pi/3), cos(2*pi/3))]
for x, y in pos:
    c.insert(server(0.3), [trafo.translate(1.5*x, 1.5*y)])
    c.insert(client(), [trafo.scale(0.5).translated(3*x, 3*y+0.15)])
    c.stroke(path.line(2.7*x, 2.7*y, 1.9*x, 1.9*y),
               [arrowcolor, deco.earrow.large, deco.barrow.large, style.linewidth.THick])
pos.append(pos[0])
fak = 0.3
for (x1, y1), (x2,y2) in zip(pos[:-1], pos[1:]):
    c.stroke(path.line(1.5*x1+fak*(x2-x1), 1.5*y1+fak*(y2-y1),
                       1.5*x2-fak*(x2-x1), 1.5*y2-fak*(y2-y1)), 
               [arrowcolor, deco.earrow.Large, deco.barrow.Large, style.linewidth.THIck])

dy = 0.8
dx = 1.5
versionoff = 1.5
cf = canvas.canvas()
hueoff = 0.17
nr_revisions = 0
コード例 #16
0
 def __init__(self, label, color=None):
     super(RibosomeBindingSite, self).__init__(label, color)
     c = circle(1, 1, 1)
     c = c.transformed(trafo.scale(sx=1.5, sy=0.8))
     self._path = c
コード例 #17
0
ファイル: braid.py プロジェクト: punkdit/thesis2015
c.stroke(path.line(0.0, -0.2, 0., H), [deco.earrow()])
c.stroke(path.line(-0.2, 0., W, 0), [deco.earrow()])
my = 0.25
c.stroke(path.line(-0.2, -my*0.2, 0.9*W, my*W), [deco.earrow()])

x0, y0 = 0.3*W, 0.3*H
x1, y1 = x0+0.3*W, y0+my*0.3*W


#t = Turtle(x0, y0, pi/4)
#t.penup().fwd(0.2).pendown()
#theta, r = 0.25*pi, 2.0
#t.right(theta, r).right(0.8*pi, 0.2).right(theta, r)
#t.fwd(0.1).stroke([deco.earrow()])

tr = trafo.scale(x=0.5*W, y=0.3*H, sx=1.3, sy=1.5)

c.fill(path.circle(x0, y0, 0.06), [tr])
c.fill(path.circle(x1, y1, 0.06), [tr])

def loop(x0, y0, r1, theta0, theta1, tpy):
    t = Turtle(x0, y0, theta0)
    #theta = 0.55*pi
    theta = theta1
    r2 = 2*r1*sin(theta - 0.5*pi)
    t.penup().fwd(0.1*r1).pendown()
    t.fwd(0.9*r1).right(theta).fwd(r2).right(theta).fwd(0.9*r1) 
    t.stroke([deco.earrow(), 
        deformer.smoothed(4.0), style.linewidth.Thick,
        color.transparency(tpy), tr])
コード例 #18
0
ファイル: trellis.py プロジェクト: punkdit/surface2015
x, y = 0.0, 4.0


def lines(x, y, lines):
    lines = lines.split("~")
    h = 0.4
    y += 0.5 * h * len(lines)
    for line in lines:
        c.text(x, y, line, center)
        y -= h


c.stroke(path.circle(2.5, 1.7, 3))

c.fill(path.circle(x, y + 0.2, 1.5), [trafo.scale(x=x, y=y, sx=1.4, sy=1), white])
c.stroke(path.circle(x, y + 0.2, 1.5), [trafo.scale(x=x, y=y, sx=1.4, sy=1)])
lines(x, y, "AI:~dynamic programming~belief propagation~neural nets")

x, y = 5, 2
c.fill(path.circle(x, y + 0.2, 1.5), [white])
c.stroke(path.circle(x, y + 0.2, 1.5))
lines(x, y, "computation~process~efficiency~physicality")

x, y = 0, 0
c.fill(path.circle(x, y + 0.2, 1.5), [white])
c.stroke(path.circle(x, y + 0.2, 1.5))
lines(x, y, "reductionism~homomorphism~representation~semantics~models")

c.text(2.5, 1.7, "?", [trafo.scale(5, 5)] + center)
コード例 #19
0
g = pyx.graph.graphxy(width=figwidth, height=figheight, 
		      x=pyx.graph.axis.linear(min=nmin, max=nmax, title=r'$\log n_\mathrm{gas}$'),
		      y=pyx.graph.axis.linear(min=tmin, max=tmax, title=r'$\log T$'),
		      )

from pyx.style import linestyle, linewidth
from pyx.color import transparency
from pyx.graph.style import line
from pyx.graph import data
from pyx.trafo import rotate, scale
line.defaultlineattrs += [linewidth.thick, transparency(0.2)]
# Free-fall time < 1.e5 years
g.plot(data.function("x(y) = 5.31"), [line([linestyle.dashed])])
xx, yy = g.pos(5.6, 3.8)
g.text(xx, yy, r"\(t_\mathrm{ff} = 10^5\,\mathrm{yr}\)", [scale(0.7), rotate(90)])
# Plot contours of Jeans instability
for MJeans in (0.0, 1.0): 
    g.plot(data.function("y(x) = 0.491 + 0.6667*MJeans + 0.333*(x-3.0)", 
			 context=locals()), 
	   [line([linestyle.solid, linewidth.Thick])])
ang = N.arctan2(0.3333*(nmax-nmin), (tmax-tmin))*180.0/N.pi
x, y = g.pos(1.6, 0.8)
g.text(x, y, r"\(M_J = 10~M_\odot\)", [scale(0.7), rotate(ang)])
x, y = g.pos(3.6, 0.8)
g.text(x, y, r"\(M_J = 1~M_\odot\)", [scale(0.7), rotate(ang)])

# Plot contours of equilibrium T
execdir = os.path.dirname(sys.argv[0])
for Av, D in [
    [0.0, 0.3],
コード例 #20
0
ファイル: modular.py プロジェクト: punkdit/fibonacci
        p = path.circle(x, y-r, 0.06)
        c.fill(p)

r = 1.0

surface(x+0, y, r)
surface(x-0.6*r, y, 0.1*r, fill=white)
surface(x+0.0*r, y, 0.1*r, fill=white)
surface(x+0.6*r, y, 0.1*r, fill=white)

c.text(x-0.6*r, y+0.2, "$a$", south)
c.text(x,       y+0.2, "$b$", south)
c.text(x+0.6*r, y+0.2, "$c$", south)
c.text(x+0.9*r, y-0.6, "${d}$", northwest)

c.stroke(path.circle(x-0.3*r, y, 0.6*r), [trafo.scale(1., 1.1, x, y)])
c.stroke(path.circle(x+0.3*r, y, 0.6*r), [trafo.scale(1., 1.1, x, y)])

c.text(x-1.5*r, y, r"$\H\Bigl($", center)
c.text(x+1.3*r, y, r"$\Bigr)$", center)

x += 4.0*r
y -= 3.0*r

surface(x-0.7*r, y, 0.6*r)
surface(x+0.7*r, y, 0.6*r)
labels = "aybc"
for i, x0 in enumerate([x-0.9*r, x-0.5*r, x+0.5*r, x+0.9*r]):
    surface(x0, y, 0.1*r, fill=white)
    if i==1:
        c.text(x0, y+0.13, "$%s$"%labels[i], south)
コード例 #21
0
 def __init__(self, label, color=None):
     super(RibosomeBindingSite, self).__init__(label, color)
     c = circle(1, 1, 1)
     c = c.transformed(trafo.scale(sx=1.5, sy=0.8))
     self._path = c
コード例 #22
0
from pyx import canvas, color, deformer, path, text, trafo, unit

text.set(text.LatexRunner)
text.preamble(r'''\usepackage[scaled=0.85,lining]{FiraMono}
                  \usepackage[utf8]{inputenc}''')
pistring = '3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852'
char_per_line = 25
pistring = ' '.join(
    [pistring[n * char_per_line:(n + 1) * char_per_line] for n in range(10)])
unit.set(xscale=1.45)

c = canvas.canvas()
dx = 0.3
h = 4
w = 6.5
p = path.rect(-dx, -dx, w + 2 * dx, h + 2 * dx)
p = deformer.smoothed(0.5).deform(p)
c.fill(p, [color.grey(0.5), trafo.translate(0.05, -0.05)])
c.fill(p, [color.grey(0.9)])
c.text(0, 0, r'\noindent\texttt{{{}}}'.format(pistring),
       [text.valign.bottom, text.parbox(5)])
c.text(0.5 * w, 0.5 * h, r'\Huge $\pi$', [
    text.halign.center, text.valign.middle,
    color.hsb(0.66, 0.8, 1),
    color.transparency(0.2),
    trafo.scale(5.8)
])

c.writePDFfile()
コード例 #23
0
def ellipse(r, scaley, fillcolor):
    ce = canvas.canvas()
    ce.fill(path.circle(0, 0, r), [trafo.scale(1, scaley), fillcolor])
    return ce
コード例 #24
0
ファイル: pentagon.py プロジェクト: punkdit/fibonacci
def ellipse(x, y, r, sy):
    c.stroke(path.circle(x, y, r), [trafo.scale(x=x, y=y, sx=1., sy=sy)])
コード例 #25
0
def slepc(Gx, Gz, Hx, Hz, Rx, Rz, Pxt, Qx, Pz, Tx, **kw):

    name = argv.get("name", "ex3.tmp.c")
    print("slepc: name=%s"%name)

    r = len(Rx)
    n = 2**r
    assert (r<40), "ugh"

    #code = Code("body.h")
    code = Code()

    code.append("#define DIMS (%d)"%n)

    code.append("static void matmult(PetscScalar *py, const PetscScalar *px, long nx)")
    code.begin()
    code.append("assert(DIMS == %d);"%n)
    code.append("assert(nx == %d);"%n)
    code.append("memset(py, 0, sizeof(PetscScalar)*nx);")

    offset = argv.get("offset", None)

    mz = len(Gz)
    t = None
    #excite = argv.excite
    #if excite is None:
    excite = kw.get("excite") or argv.excite

    if excite is not None:
        print("excite:", excite)
        if type(excite) is tuple:
            t = Tx[excite[0]]
            for i in range(1, len(excite)):
                t = (t + Tx[excite[i]])%2
        else:
            assert type(excite) in (int, int)
            t = Tx[excite]
        print("t:", shortstr(t))
        Gzt = dot2(Gz, t)
        print("Gzt:", shortstr(Gzt))

    weights = kw.get("weights")
    if weights is not None:
        assert len(weights)==len(Gx)

    RR = dot2(Gz, Rx.transpose())

    PxtQx = dot2(Pxt, Qx)
    gxs = [getnum(dot2(gx, PxtQx)) for gx in Gx]
    gxs.sort()
    uniq_gxs = list(set(gxs))
    uniq_gxs.sort()

    code.append("long v;")
    code.append("int k;")
    code.append("struct timeval t0, t1;")
    code.append("gettimeofday(&t0, NULL);")
    code.append("for(v=0; v<%d; v++)"%n)
    code.begin()
    code.append("double pxv = px[v];")
    if n >= 128:
        code.append(r'if((v+1) %% %d == 0)' % (n//128))
        code.begin()
        code.append("gettimeofday(&t1, NULL);")
        code.append("long delta = t1.tv_sec-t0.tv_sec;")
        code.append("if(delta>1)")
        code.append('{printf("[%lds]", delta);fflush(stdout);}')
        code.append('t0 = t1;')
        code.end()
    code.append("k = 0;")
    for i, row in enumerate(RR):
        if t is not None and Gzt[i]==1:
            code.append("k += (countbits_fast(v&%s)+1) %% 2;" % getnum(row))
        else:
            code.append("k += countbits_fast(v&%s) %% 2;" % getnum(row))
    cutoff = argv.cutoff
    if cutoff is not None:
        code.append("if(k>%d) continue; // <-------- continue" % cutoff)
    else:
        code.append("if(k>cutoff) continue; // <-------- continue")
    code.append("py[v] += pxv * (%d - 2*k);" % mz)

    if weights is None:
        for gx in uniq_gxs:
            s = '+'.join(['pxv']*gxs.count(gx))
            code.append("py[v^%s] += %s;" % (gx, s))
    else:
        gxs = [getnum(dot2(gx, PxtQx)) for gx in Gx]
        for i, gx in enumerate(gxs):
            code.append("py[v^%s] += %s*pxv;" % (gx, weights[i]))

    code.end()
    code.end()

    if name is None:
        return

    s = code.output()

    src = open("ex3.c").read()
    match = '\n#include "body.h"\n'
    assert match in src
    src = src.replace(match, s)
    assert name and name.endswith(".c")
    f = open(name, 'w')
    tag = hash(src)
    print(("hash(src):", tag))
    f.write(src)
    f.close()

    import socket
    host = socket.gethostname()
    if host == "bucket":
        cmd = "gcc MATCH.c -O3 -o MATCH -I/home/simon/local/petsc/arch-linux2-c-debug/include -I/home/simon/local/petsc/include/petsc/mpiuni -I/home/simon/local/petsc/include -I/home/simon/local/slepc-3.7.1/include -I/home/simon/local/slepc-3.7.1/arch-linux2-c-debug/include/ -L/home/simon/local/petsc/arch-linux2-c-debug/lib -L/home/simon/local/slepc-3.7.1/arch-linux2-c-debug/lib -lpetsc -lslepc"
    elif host == "hero":
        cmd = "gcc MATCH.c -O3 -o MATCH -I/usr/include/openmpi -I/usr/include/petsc -I/usr/include/slepc -lpetsc -lslepc -lmpi"
    else:
        cmd = "gcc -O3 MATCH.c -I/suphys/sburton/include/ -o MATCH -lpetsc -L$PETSC_DIR/$PETSC_ARCH/lib -L$SLEPC_DIR/$PETSC_ARCH/lib -lslepc"

    cmd = cmd.replace("MATCH.c", name)
    stem = name[:-2]
    cmd = cmd.replace("MATCH", stem)

    rval = os.system(cmd)
    assert rval == 0
    #print("exec:", hash(open(stem).read()))

    nev = argv.get("nev", 1)
    cmd = "./%s -eps_nev %d -eps_ncv %d -eps_largest_real" 

    if argv.plot:
        cmd += " -eps_view_vectors binary:evec.bin "

    cmd = cmd%(stem, nev, max(2*nev, 4))
    eps_tol = argv.get("eps_tol", 1e-4)
    if eps_tol is not None:
        cmd += " -eps_tol %s "%eps_tol

    #cmd += " -eps_type arnoldi -info -eps_monitor -eps_tol 1e-3"
    print(cmd)
    #rval = os.system(cmd)
    #assert rval == 0
    f = os.popen(cmd)
    s = f.read()
    #print(s)
    lines = s.split('\n')
    vals = []
    for line in lines:
        line = line.strip()
        flds = line.split()
        #print("parse", flds)
        try:
            a, b = flds
            a = float(a)
            b = float(b)
            vals.append(a)
        except:
            pass

    if not argv.plot:
        print(("vals:", vals))
        return vals

    assert argv.plot.endswith(".pdf")

    s = open("evec.bin").read()
    sz = 8*2**r

    if len(s)==sz+8:
        s = s[8:]
    elif len(s)==sz+16:
        s = s[16:]
    #elif len(s)==2*(sz+16): # got two vectors
    #    s = s[16:16+sz] # pick the first vector
    elif len(s)%(sz+16) == 0:
        count = len(s)/(sz+16)
#        s = s[16:16+sz] # pick the first vector
        ev_idx = argv.get("ev_idx", 0)
        s = s[16+ev_idx*(16+sz):(ev_idx+1)*(16+sz)]
    else:
        assert 0, "sz=%d but s=%s"%(sz, len(s))

    vec0 = numpy.fromstring(s, dtype=">d")
    assert len(vec0)==2**r

    assert excite is None

    print("graphing...")
    gz, n = Gz.shape
    xdata = []
    lookup = {}
    GzRxt = dot2(Gz, Rx.transpose())
    for i, v in enumerate(genidx((2,)*r)):
        v = array2(v)
        lookup[v.tobytes()] = i
        syndrome = dot2(GzRxt, v)
        value = gz - 2*syndrome.sum()
        xdata.append(value)

    pdata = {}
    ndata = {}
    my = 20. # mul y
    EPSILON = argv.get("EPSILON", 1e-6)

    def yfunc(y):
        y = log2(abs(y))
        y = int(round(my*y))
        return y

    for i in range(len(vec0)):
        x = xdata[i] # integer
        y = vec0[i]
        if abs(y) < EPSILON:
            continue
        if y > 0.:
            y = yfunc(y)
            pdata[x, y] = pdata.get((x, y), 0) + 1
        else:
            y = yfunc(y)
            ndata[x, y] = ndata.get((x, y), 0) + 1

    from pyx import graph, canvas, path, trafo, color, deco, text
    
    north = [text.halign.boxcenter, text.valign.top]
    northeast = [text.halign.boxright, text.valign.top]
    northwest = [text.halign.boxleft, text.valign.top]
    south = [text.halign.boxcenter, text.valign.bottom]
    southeast = [text.halign.boxright, text.valign.bottom]
    southwest = [text.halign.boxleft, text.valign.bottom]
    east = [text.halign.boxright, text.valign.middle]
    west = [text.halign.boxleft, text.valign.middle]
    center = [text.halign.boxcenter, text.valign.middle]
    
    c = canvas.canvas()
    sx = 0.4
    sy = 1.4
    tr = trafo.scale(sx, sy)

    green = color.rgb(0.2,0.6,0.2)
    brown = color.rgb(0.8,0.2,0.2)
    grey = color.rgb(0.4,0.4,0.4)
    lgrey = color.rgb(0.8,0.8,0.8)

    W = 2*gz
    H = log2(EPSILON)
    dy = 0.5 * 1.2/my

    X0 = -gz
    Y0 = 0.

    def showp(gx, radius):
        v = dot2(gx, PxtQx)
        syndrome = dot2(GzRxt, v)
        x = gz - 2*syndrome.sum()
        i = lookup[v.tobytes()]
        #print syndrome, syndrome.sum(), vec0[i]
        y = (1./my)*yfunc(vec0[i]) + 0.5*dy
        #y = 0.5*dy + log2(abs(vec0[i]))
        c.fill(path.circle(-x*sx, y*sy, radius), [lgrey])

    showp(zeros2(n), 0.8)
    for gx in Gx:
        showp(gx, 0.4)

    for gx0 in Gx:
      for gx1 in Gx:
        gx = (gx0+gx1)%2
        if gx.sum()==0:
            continue
        showp(gx, 0.2)

    for i in range(0, gz+1):
        x, y = X0+2*i, Y0
        c.stroke(path.line(x, y, x, y+H), [tr, grey])
        if i%2 == 0:
            c.text(x*sx, y*sy + 0.2, "%d"%i, south)

    c.stroke(path.line(X0, Y0, X0+1.0*W+3.5, Y0), [tr, deco.earrow(size=0.5)])
    c.stroke(path.line(X0, Y0, X0, Y0+1.0*H-0.5), [tr, deco.earrow(size=0.5)])

    y = 1.0
    i = 0
    while y > EPSILON:

        x = X0*sx
        y1 = sy*(1./my)*yfunc(y)
        c.stroke(path.line(x, y1, x-0.1, y1))

        c.text(x-0.3, y1, "%d"%i, east)

        y /= 2.
        i -= 1

    R = 0.15
    for key, value in list(pdata.items()):
        x, y = key
        y = y/my
        x = -x
        value = 1 + math.log(value)
        r = R*value
        #c.stroke(path.circle(x, y, r))
        #c.stroke(path.line(x, y, x+r, y), [brown, tr])
        c.fill(path.rect(x, y, r, dy), [brown, tr])

    for key, value in list(ndata.items()):
        x, y = key
        y = y/my
        x = -x
        value = 1 + math.log(value)
        r = R*value
        #c.stroke(path.circle(x, y, r))
        #c.stroke(path.line(x-r, y, x, y), [green, tr])
        c.fill(path.rect(x-r, y, r, dy), [green, tr])

    c.writePDFfile(argv.plot)


    if 0:
        print("graph..")
    
        g = graph.graphxy(
            width=16,
            x=graph.axis.linear(reverse=True),
            y=graph.axis.linear())
            #y=graph.axis.log(min=0.8*vec0.min(), max=1.2*vec0.max()))
    
        g.plot(graph.data.values(x=xdata, y=ydata))
        g.writePDFfile(argv.plot)
コード例 #26
0
ファイル: tqft.py プロジェクト: punkdit/fibonacci
x = 0.
y = 0.
m = 0.1*w
m0 = m/2
r = 0.3*w

c.fill(path.rect(x-m0, y-m0, 2*m0+w, 2*m0+h), [shade])
c.stroke(path.rect(x, y, w, h))

p = path.path(
    path.moveto(x+r, y-m), 
    path.lineto(x+r, y),
    path.arc(x, y, r, 0, 90),
    path.lineto(x-m, y+r), 
)
c.stroke(p, g_curve+[trafo.scale(1.0, 1.3, x=x, y=y-m)])

c.stroke(path.line(x+0.5*w, y-m, x+0.5*w, y+h+m), g_curve)

r = 0.2*w
p = path.path(
    path.moveto(x+w+m, y+0.5*h+r), 
    path.lineto(x+w, y+0.5*h+r), 
    path.arc(x+w, y+0.5*h, r, 90, 270),
    path.lineto(x+w+m, y+0.5*h-r), 
)
c.stroke(p, g_curve+[trafo.scale(1.4, 1.0, x=x+1.*w+m, y=y+0.5*h)])


x += w + 6*m
コード例 #27
0
ファイル: poster.py プロジェクト: punkdit/fibonacci
x = m + 2*dw

y = 20*dr

c.text(x, y,
r"""Braiding with Fibonacci anyons
can realize universal quantum computing, so
we don't expect to be able to simulate
every instance in a reasonable amount of time.
Instead we bound the compute time, and any
instance that exceeds this bound is considered
``missing'' data:""",
[text.parbox(dw-2*m),])

y -= 18*dr
try:
    c.insert(epsfile.epsfile(x, y, "qip/fibonacci.eps", width=(dw-2*m)))
except IOError, e:
    print e


# -------------------------------------------------------------------


the_can = canvas.canvas()
the_can.insert(c, [trafo.scale(SCALE)])

the_can.writeEPSfile("poster")
the_can.writePDFfile("poster")

コード例 #28
0
ファイル: graphs.py プロジェクト: punkdit/bruhat
def render():
    graphs = list(desargues_graph())

    hexa = graphs[0]
    deca = graphs[1]

    graph = graphs[0]
    graphs[0].draw(None, "desargues_0")
    graphs[1].draw(None, "desargues_1")

    G = graph.get_autos()
    print("|G| =", len(G))

    isoms = graph.get_isoms()
    print("isoms =", len(isoms))

    if 0:
        top = graph.valence
        vecs = list(graph.get_inteigs(-top))
        assert len(vecs) == 1
        nvec = vecs[0]

        for pvec in graph.get_inteigs(2):
            break
        vec = (pvec * nvec)
        graph.draw(vec, "desargues_1_n2")

        for pvec in graph.get_inteigs(1):
            break
        vec = (pvec * nvec)
        graph.draw(vec, "desargues_1_n1")

    if 0:
        for val in [3, 2, 1]:
            for pvec in graph.get_inteigs(val):
                break
            graph.draw(pvec, "desargues_0_%d" % val)

            nvec = iter(graph.get_inteigs(-val)).__next__()
            graph.draw(nvec, "desargues_0_n%d" % val)

    if 0:
        for val in [2, 1]:
            nnz = None
            if val == 1:
                nnz = 8
            vec = iter(hexa.get_inteigs(val, nnz)).__next__()
            orbit = hexa.get_orbit(vec)
            print("orbit:", len(orbit))
            for i, pvec in enumerate(orbit):
                name = "desargues_hexa_v%d_i%d" % (val, i)
                print('%s.svg<img src="%s.svg"><br>' % (name, name))
                hexa.draw(pvec, name)

            vec = iter(deca.get_inteigs(val, nnz)).__next__()
            orbit = deca.get_orbit(vec)
            print("orbit:", len(orbit))
            for i, pvec in enumerate(orbit):
                name = "desargues_deca_v%d_i%d" % (val, i)
                print('%s.svg<img src="%s.svg"><br>' % (name, name))
                deca.draw(pvec, name)

            vec = iter(hexa.get_inteigs(-val, nnz)).__next__()
            orbit = hexa.get_orbit(vec)
            print("orbit:", len(orbit))
            for i, pvec in enumerate(orbit):
                name = "desargues_hexa_vn%d_i%d" % (val, i)
                print('%s.svg<img src="%s.svg"><br>' % (name, name))
                hexa.draw(pvec, name)

            vec = iter(deca.get_inteigs(-val, nnz)).__next__()
            orbit = deca.get_orbit(vec)
            print("orbit:", len(orbit))
            for i, pvec in enumerate(orbit):
                name = "desargues_deca_vn%d_i%d" % (val, i)
                print('%s.svg<img src="%s.svg"><br>' % (name, name))
                deca.draw(pvec, name)

    if 1:
        vec = iter(deca.get_inteigs(2)).__next__()
        orbit = deca.get_orbit(vec)
        print("orbit:", len(orbit))

        # show an equation here
        #svecs = [orbit[i] for i in [5, 7, 19, 15, 3]]
        #coefs = [1, -1, 1, -1, 1] # sum with these coefs to get zero
        svecs = [orbit[i] for i in [5, 19, 3, 7, 15]]
        symbols = "++=+ "

        c = pyx.canvas.canvas()
        x, y = 0., 0.
        r = 0.43
        dx = 8.0 * r
        #u = dict((i, 0) for i in deca.nodes)
        for idx in range(5):
            vec = svecs[idx]
            #vec = coefs[idx]*vec
            #u = u+vec
            deca.draw(vec, None, c, [trafo.scale(r, r), trafo.translate(x, y)])
            c.text(x + 0.5 * dx, y, symbols[idx], center)
            x += dx

        # should be zero
        #deca.draw(u, None, c, [trafo.scale(r, r), trafo.translate(x, y)])

        name = "output/desargues_deca_v2_4_1"
        c.writeSVGfile(name)
        c.writePDFfile(name)