def CZGate(c=P(0, 0), controlDist=1.0, direction="up", side=0.5):
    """
    Controlled Z gate

    @param controlDist: distance to the control
    @type controlDist: float

    @param direction: in which direction is the control?  up/down
    @type direction: string

    @param side: length of the box side
    @type side: float
    """
    if direction is "up":
        return Group(
            Circle(c=c + P(0, controlDist), r=0.065, bg=Color("black")),
            Path(c + P(0, side / 2.), c + P(0, controlDist)),
            Rectangle(width=side, height=side, c=c, bg=Color("white")),
            TeX(r'Z', c=c))
    elif direction is "down":
        return Group(
            Circle(c=c - P(0, controlDist), r=0.65, bg=Color("black")),
            Path(c - P(0, side / 2.), c - P(0, controlDist)),
            Rectangle(width=side, height=side, c=c, bg=Color("white")),
            TeX(r'Z', c=c))
def Rail(w=P(0, 0), length=1.0, labelIn=None, labelOut=None, buff=0.05):
    """
    A Rail of a quantum circuit diagram

    @param length: length of the rail
    @type length: float

    @param labelIn: input label
    @type labelIn: string

    @param labelOut: output label
    @type labelOut: string

    @param buff: buffer of space between the end of the rail and the label
    @type buff: float
    """
    if labelIn is not None and labelOut is not None:
        return Group(Path(w + P(0, 0), w + P(length, 0)),
                     TeX(labelIn, e=w - P(buff, 0)),
                     TeX(labelOut, w=w + P(buff + length, 0)))
    elif labelIn is not None and labelOut is None:
        return Group(Path(w + P(0, 0), w + P(length, 0)),
                     TeX(labelIn, e=w - P(buff, 0)))
    elif labelIn is None and labelOut is not None:
        return Group(Path(w + P(0, 0), w + P(length, 0)),
                     TeX(labelOut, w=w + P(buff + length, 0)))
    else:
        return Group(Path(w + P(0, 0), w + P(length, 0)))
def ZGate(c=P(0, 0), side=0.5):
    """
    Z gate

    @param side: length of the box side
    @type side: float
    """
    return Group(Rectangle(width=side, height=side, c=c, bg=Color("white")),
                 TeX(r'Z', c=c))
Example #4
0
    def __init__(self, text, **options):
        Group.__init__(self, **options)

        # set up tex width ... this relies on latex notion of
        # a point being accurate ... adjust for tex_scale too
        width_pp = int(self.width / float(self.iscale) * defaults.units)

        t = TeX(r'\begin{minipage}{%dpt}%s\end{minipage}' % (width_pp, text),
                fg=self.fg,
                iscale=self.iscale)

        # use this for alignment as the latex bounding box may be smaller
        # than the full width
        a = Area(width=self.width, height=0)

        Align(t, a, a1=self.align, a2=self.align, space=0)

        self.append(a, t)
Example #5
0
 def __init__(self, tex, **options):
     Gate.__init__(self, Circled(TeX(tex)), **options)