LoginSignup
11
3

More than 5 years have passed since last update.

LaTeXで量子回路を描く(応用編)

Posted at

本記事は「LaTeXで量子回路を描く」の応用編です。
本記事では前回紹介しきれなかったqcircuitの機能や、Xy-picパッケージの機能等を利用したすごいカッコイイ量子回路の描き方を簡単に紹介します。

TL;DR

qcircuitパッケージですごいカッコイイ量子回路も描けます。

qcircuitによるすごいカッコイイ量子回路例

カッコイイ量子回路を描く

残念ながら上に掲載した量子回路はqcircuitの機能だけでは描くことが出来ません。
もしqcircuitのみの機能で描いた場合、次の量子回路が限界になると思います。

\documentclass[12pt,border={25pt 5pt 5pt 5pt}]{standalone}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[cmex10]{amsmath}

\usepackage{qcircuit}
\usepackage{braket}

\begin{document}

\Qcircuit @C=.7em @R=.7em {
  \lstick{\ket{+}} & \ctrl{1} & \gate{HZ_{\theta_1}} & \meter & \cw \\
  \lstick{\ket{+}} & \control \qw & \qw
    & \ctrl{1} & \gate{HZ_{\pm\theta_2}} \cwx & \meter & \cw & \\
  \lstick{\ket{+}} & \qw & \qw & \control \qw & \qw
    & \ctrl{1} & \gate{HZ_{\pm\theta_3}} \cwx & \meter
    \gategroup{1}{2}{2}{4}{.7em}{--}
    \gategroup{2}{4}{3}{6}{.7em}{--} \\
  & & & & &
}

\end{document}

qcircuitによるカッコイイ量子回路例

前回は説明していませんでしたが、量子回路のまとまりを図示したいときには\gategroupコマンドを利用できます。
引数は6つあり左上要素の行と列番号、右下要素の行と列番号、枠線の太さ、枠線の種類の全て指定する必要があります。
また最終行に&が5つあるのは線を下ろす\ctrl{1}の対象となる要素が必要となるためです。

上記2つの量子回路を比較すると、二重線(古典情報を表す)の角と波線(省略線)が違います。

すごいカッコイイ量子回路を描く

さてqcircuitパッケージの中身を見てみると1、実は単にXy-picのコマンドを定義しているだけであることが解ります。
そのため既存の定義を参考にして新しいコマンドを定義することが出来ます。

XY-picについては本記事の末尾に日本語の参考文献を挙げますのでそちらを参照して頂くことにして、最終的には次のようなLaTeXファイルで冒頭の回路を描くことが出来ます。

\documentclass[12pt,border={25pt 5pt 5pt 5pt}]{standalone}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[cmex10]{amsmath}

\usepackage{qcircuit}
\usepackage{braket}

% 角のついた二重線を引く
\newcommand{\cwcd}{*+<0em>{\xy ="i","i"+<-1pt,-1pt>;"i"+<1pt,-1pt> **\dir{-}, "i"+<1pt,-1pt>;"i"+<1pt,-3pt> **\dir{-} \endxy} \cw}
% 二重波線を引く
\newcommand{\qww}{\ar @{~} [0,1] \ar @{~} @<-2pt> [0,1] \ar @{~} @<+2pt> [0,-1] \ar @{~} [0,-1]}

\begin{document}

\Qcircuit @C=.7em @R=.7em {
  \lstick{\ket{+}} & \ctrl{1} & \gate{HZ_{\theta_1}} & \meter & \cwcd \\
  \lstick{\ket{+}} & \control \qw & \qw
    & \ctrl{1} & \gate{HZ_{\pm\theta_2}} \cwx & \meter & \cwcd & \\
  \lstick{\ket{+}} & \qw & \qw & \control \qw & \qw
    & \ctrl{1} & \gate{HZ_{\pm\theta_3}} \cwx & \meter \\
  & & & & & \qww
    \gategroup{1}{2}{2}{4}{.7em}{--}
    \gategroup{2}{4}{3}{6}{.7em}{--} &
}

\end{document}

また前回の記事の最後に記載した量子回路は次のようなLaTeXファイルを利用しました。

\documentclass[varwidth,12pt,border={30pt 5pt 5pt 5pt}]{standalone}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[cmex10]{amsmath}

\usepackage{qcircuit}
\usepackage{braket}

% サイズ調整のために透明なゲートを配置する
\newcommand{\ggate}[1]{*+<.6em>{\phantom{#1}} \POS ="i","i"+R; **\dir{-}; \qw}
% \lstickを左揃えにする
\newcommand{\lstickx}[1]{\lstick{\makebox[1.5em][l]{$#1$}}}
% 繰り返し表記のための矢印を配置する
\newcommand{\arrep}[1]{\ar @<6pt> @/^/[#1]|-{\mbox{ Repeat }}}

\begin{document}

\Qcircuit @C=.75em @R=.25em {
  \lstickx{\ket{\psi}_0} & \qw & \gate{\ket{0}} & \gate{H} & \ctrl{2} & \ctrl{1} & \ctrl{4} & \ctrl{3} & \gate{H} & \meter & \qw & \qw \\
  \lstickx{\ket{\psi}_1} & \qw & \ggate{\ket{0}} & \qw & \qw & \targ & \qw & \qw & \qw & \qw & \qw & \qw \\
  \lstickx{\ket{\psi}_2} & \qw & \ggate{\ket{0}} & \qw & \targ & \qw & \qw & \qw & \qw & \qw & \qw & \qw \\
  \lstickx{\ket{\psi}_3} & \qw & \ggate{\ket{0}} & \qw & \qw & \qw & \qw & \targ & \qw & \qw & \qw & \qw \\
  \lstickx{\ket{\psi}_4} & \qw & \ggate{\ket{0}} & \qw & \qw & \qw & \targ & \qw & \qw & \qw & \qw & \qw \\
  & & & & & & & & & & \arrep{lllllllll}
  \gategroup{1}{3}{5}{10}{.7em}{--}
}

\vspace{3ex}

\Qcircuit @C=.75em @R=.25em {
  \lstickx{\ket{\psi}_0} & \qw & \gate{\ket{0}} & \ggate{H} & \targ & \targ & \targ & \targ & \ggate{H} & \meter & \qw & \qw \\
  \lstickx{\ket{\psi}_1} & \qw & \ggate{\ket{0}} & \qw & \qw & \ctrl{-1} & \qw & \qw & \qw & \qw & \qw & \qw \\
  \lstickx{\ket{\psi}_2} & \qw & \ggate{\ket{0}} & \qw & \ctrl{-2} & \qw & \qw & \qw & \qw & \qw & \qw & \qw \\
  \lstickx{\ket{\psi}_3} & \qw & \ggate{\ket{0}} & \qw & \qw & \qw & \qw & \ctrl{-3} & \qw & \qw & \qw & \qw \\
  \lstickx{\ket{\psi}_4} & \qw & \ggate{\ket{0}} & \qw & \qw & \qw & \ctrl{-4} & \qw & \qw & \qw & \qw & \qw \\
  & & & & & & & & & & \arrep{lllllllll}
  \gategroup{1}{3}{5}{10}{.7em}{--}
}

\end{document}

表面符号の量子回路

ここでは2つの量子回路をきれいに並べるため、透明なゲートを配置する\ggateコマンドを定義して利用しています。
また\lstickxでは\lstickを左揃えにするため、\arrepでは繰り返しの矢印を表示するためにそれぞれコマンドを定義しています。

もっと奇妙な回路を描く

せっかくLaTeXを利用しているのですし、もっと奇妙な量子回路を描くこともできます。

\documentclass[12pt,border={30pt 5pt 30pt 5pt}]{standalone}

\usepackage[cmex10]{amsmath}

\usepackage{qcircuit}
\usepackage{braket}

% 参考にしました(http://d.hatena.ne.jp/zrbabbler/20160607/1465260507)
\DeclareFontFamily{U}{mipxmA}{}
\DeclareFontShape{U}{mipxmA}{m}{n}{<->s*[0.8]ipxm-r-u26}{}
\DeclareSymbolFont{mipxmA}{U}{mipxmA}{m}{n}
\DeclareMathSymbol{\Snowman}{\mathalpha}{mipxmA}{"03}
\DeclareMathSymbol{\Onsen}{\mathalpha}{mipxmA}{"68}

% \lstickを左揃えにする
\newcommand{\lstickx}[1]{\lstick{\makebox[1.5em][l]{$#1$}}}

\begin{document}

\Qcircuit @C=1em @R=.7em {
  \lstickx{\ket{0}} & \qw & \gate{H} & \qw & \rstick{\ket{+}} \qw \\
  \lstickx{\ket{\Snowman}} & \qw & \gate{\Onsen} & \qw  & \rstick{\ket{0}} \qw
}

\end{document}

qcircuitによるアレな量子回路例

Xy-pic参考文献


  1. kpsewhich qcircuit.styを実行することでqcircuitのパスが解ります。 

  2. 私の環境だとAdobe Reader以外を利用すると文字化けします。 

11
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
3