File: detector.py

package info (click to toggle)
pyscript 0.6.1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,428 kB
  • ctags: 1,175
  • sloc: python: 10,146; makefile: 67
file content (86 lines) | stat: -rw-r--r-- 2,156 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env pyscript

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

"""
A quantum circuit diagram of a detection setup in optical quantum computing.
"""

# import the pyscript libraries
from pyscript import *

# set up the default units for the diagram
defaults.units=UNITS['cm']

# define some helpful LaTeX macros
defaults.tex_head=r"""
\documentclass{article}
\pagestyle{empty}

\newcommand{\ket}[1]{\mbox{$|#1\rangle$}}
\newcommand{\bra}[1]{\mbox{$\langle #1|$}}
\newcommand{\braket}[2]{\mbox{$\langle #1|#2\rangle$}}
\newcommand{\ketbra}[2]{\mbox{|#1$\rangle\langle #2|$}}
\newcommand{\op}[1]{\mbox{\boldmath $\hat{#1}$}}
\begin{document}
"""

# import helpful objects from the optics and quantumcircuits libraries
from pyscript.lib.optics import BS
from pyscript.lib.quantumcircuits import detector, classicalpath

# distance between the two "rails" of the quantum circuit
h = 1.7

# define the phase plate
pp2 = P(2,0)
phase = Rectangle(width=.1, height=.4, c=pp2, bg=Color(.8) )

# define the beam splitter
pp = P(1.5,0)
bs = Rectangle(width=.1, height=1, c=pp, bg=Color(1) ).rotate(-45, pp)

# define detectors
d1 = detector()(c=P(1.5+h/2.,0))
d2 = detector()(c=P(1.5,-h/2.)).rotate(90, P(1.5,-h/2.))

# render the diagram
render(
    # the rails of the quantum circuit
    Path(P(1.5,h/2.), P(1.5,-h/2.)),
    Path(P(3.5,h), P(0,h), P(-.5,h/2.), P(0,0), P(1.5+h/2.,0)),

    # the state at one output port
    TeX(r'$\ket{p}$', s=P(1.5,h/2.)),

    # beam splitter and label
    bs,
    TeX(r'$\omega$', se=bs.n),

    # labels of paths through system
    TeX('$a$', sw=P(.1,h+.1)),
    TeX('$b$', sw=P(.1,0.1)),
    TeX('$c$', w=P(1.6,h/2.4)),

    # phase plate and label
    phase,
    TeX(r'$\lambda$', s=phase.n+P(0,.1)),

    # detectors and label
    d1,
    d2,
    TeX('$y$', w=d1.e),
    TeX('$x$', n=d2.e),
    
    # box highlighting part of the circuit
    Rectangle(width=h+.6, height=h+1, dash=Dash(2), e=d1.e+P(.4,0)),
    
    # the input state
    Dot(P(-.5,h/2.), r=.05),
    TeX(r'$\ket{\psi}$', e=P(-.5,h/2.)),

    # the output file name
    file="detector.eps",
    )

# vim: expandtab shiftwidth=4: