1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

美しい量子回路の描き方

Last updated at Posted at 2022-05-17

IBM qiskit を使えば、量子回路を描くことができることはよく知られています。
しかし、ソースコードに縛られて自由な図を描けない、数式を含んだ図を描けない等の不都合があります。

そこで、美しい量子回路を描く作業を試行錯誤してみました。
Web ページや PowerPoint スライドに綺麗に貼り付けることができる SVG 形式を作成することを目指しました。

使用するツール一覧

  • LaTeX, dvipdfm, LaTeX の qcircuit パッケージ
    Debian 系列の Linux であれば、texlive-full パッケージをインストールするだけですべて揃います。
  • Inkscape

回路を記述

qcircuit という TeX パッケージを使って記述します。
サンプルとして、以下のような図だけの文書を作成しました。

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

\usepackage[T1]{fontenc}
\usepackage[cmex10]{amsmath}
\usepackage{qcircuit}
\usepackage{braket}

\begin{document}

\Qcircuit @C=1em @R=.7em {
  \lstick{x_0} & \gate{H} & \gate{X} & \ctrl{1} & \gate{X} & \gate{H} & \qw & \meter \\
  \lstick{x_1} & \gate{H} & \gate{X} & \ctrl{1} & \gate{X} & \gate{H} & \qw & \meter \\
  \lstick{x_2} & \gate{H} & \gate{X} & \ctrl{1} & \gate{X} & \gate{H} & \qw & \meter \\
  \lstick{x_3} & \gate{H} & \gate{X} & \ctrl{1} & \gate{X} & \gate{H} & \qw & \meter \\
  \lstick{z}   & \qw      & \qw      & \targ    & \qw      & \qw      & \qw & \qw
}
\end{document}

LaTeX で pdf ファイルを作成

説明するまでもありませんが、
TeX ファイルから pdf ファイルを生成することができます。

$ platex sample.tex
$ dvipdfm sample.dvi

svg に変換

  1. pdf を Inkscape にドラッグアンドドロップして開きます。
    インポートダイアログで「Poppler/Cairo をインポート」を選択します。
    import.jpg

  2. インポート出来たら図を選択した状態で、ドキュメントのプロパティを開きます。
    inkscape.jpg

  3. ページサイズを描画全体または選択オブジェクトに合わせるボタンを押します。
    docproperty.jpg

  4. そのまま、ファイルメニューから名前を付けて保存で、svg 形式で保存します。

  5. 最後に svg をブラウザ等で開いて確認します。

完成

最終的にこのような SVG 画像が出来ます。
(ここに貼り付けている画像はPNGですが、実際には美しいSVG画像です。)
 
sample.png

(参考)NGだった方法

  • PowerPoint を使う方法
    Mac の PowerPoint を使えば、pdf を図として貼り付けることができます。PowerPoint だけで使うのならばこれで十分です。その図を今度は Windows の PowerPoint を使って svg 形式でエクスポートすることができます。しかし、図がビットマップ画像に変換されてしまうようです。

  • Inkscape の pdf インポート画面で内部インポートを行う方法
    フォントが Inkscape で置き換えられて、図が崩れてしまいました。dvipdfm を使ってフォントが埋め込まれた pdf を作成することができればよいかと考えましたが、やり方が分かりませんでした。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?