div_con.py :  » Language-Interface » PyScript » pyscript-0.6.1 » doc » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » PyScript 
PyScript » pyscript 0.6.1 » doc » examples » div_con.py
#!/usr/bin/env pyscript

# $Id: div_con.py,v 1.3 2006/02/14 14:23:09 paultcochrane Exp $

"""
Example usage of the qi (quantum information) library.  Output is of a
divide-and-conquer scheme of quantum gates.
"""

# import relevant pyscript libraries
from pyscript import *
from pyscript.lib.qi import *

# assemble one set of quantum gates and wires together
g1 = Assemble(
        Gate(Boxed(TeX(r'$\mathcal{E}_1$'), height=1.5)), 1.5,
        Gate(Boxed(TeX(r'$\mathcal{E}_2$'), height=1.5)), 2.5,
        Gate(Boxed(TeX(r'$\mathcal{E}_3$'), height=1.5)), 1.5,
        wires=[QWire, QWire, QWire],
        )

# assemble another set of quantum gates
g21 = Assemble(Gate(Boxed(TeX(r'$\mathcal{E}_1$'), height=1.5)), 1.5,
        wires=[QWire, QWire, QWire],
        )
g22 = Assemble(Gate(Boxed(TeX(r'$\mathcal{E}_2$'), height=1.5)), 2.5,
        wires=[QWire, QWire, QWire],
        )
g23 = Assemble(Gate(Boxed(TeX(r'$\mathcal{E}_3$'), height=1.5)), 1.5,
        wires=[QWire, QWire, QWire],
        )

# and assemble a third set of quantum gates together
g31 = Assemble(Gate(Boxed(TeX(r'$\mathcal{E}_1$'), height=1.5)), 1.5,
        wires=[QWire, QWire],
        )
g32 = Assemble(Gate(Boxed(TeX(r'$\mathcal{E}_2$'), height=1.5)), 1.5,
        wires=[QWire, QWire],
        )
g33 = Assemble(Gate(Boxed(TeX(r'$\mathcal{E}_3$'), height=1.5)), 1.5,
        wires=[QWire, QWire],
        )

# define some TeX objects for later reuse
m1 = TeX(r'\Large $\le$')
m2 = TeX(r'\Large $+$')
m3 = TeX(r'\Large $+$')
m4 = TeX(r'\Large $=$')
m5 = TeX(r'\Large $+$')
m6 = TeX(r'\Large $+$')

# align all the gate and TeX objects
Align(g1, m1, m2, m3, m4, m5, m6, g31, g32, g33, 
        a1="e", a2="w", angle=90)

# distribute the objects equally along a line
divnconk = Distribute(
        g1,
        m1,
        g21, m2, g22,
        m3, g23,
        m4,
        g31, m5, g32, m6, g33,
        a1="e", a2="w", p1=P(0,0), p2=P(15,0),
        )

# define some labels
t1 = TeX(r'\Large (by chaining)', n=P(g22.s.x, divnconk.s.y-.2))
        
t2 = TeX(r'\Large (by stability)', n=P(g32.s.x, divnconk.s.y-.2))

# append the labels to the object for the diagram
divnconk.append(t1,t2).scale(.7)

# render the diagram
render(
        # object to render
        divnconk,

        # output file name
        file="div_con.eps"
        )

# vim: expandtab shiftwidth=4:
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.