0
0

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 5 years have passed since last update.

Qiskit作業ログ

Last updated at Posted at 2020-05-28

Qiskitのインストール

リンクを参考に, まずはQiskitのインストール.

仮想環境を作ってQiskitのインストール(ついでにpipもupgrade)
$ python -m venv qiskit
$ pip install --upgrade pip
$ pip install qiskit

自分のアカウントから"Copy Token"でAPIキーを入手.
以下をpythonで行い、ローカル環境にAPIキーを登録.

APIキーの登録
from qiskit import IBMQ
IBMQ.save_account('自分のAPIキー')

これで, ~/.qiskit/qiskitrcにAPIキーの情報が登録される.

Qiskitの事始め

Quantum Native Dojoに従って, チュートリアルを進める.

自分のアカウント情報のロード
from qiskit import IBMQ, QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute, Aer
from qiskit.qasm import pi
from qiskit.tools.visualization import plot_histogram, circuit_drawer
import numpy as np

provider = IBMQ.load_account()

以下のwarningが出てくるが、問題無いようなので進める.

WARNINGメッセージ
~/.pyenv/versions/3.8.1/lib/python3.8/site-packages/qiskit/providers/ibmq/ibmqfactory.py:192: UserWarning: Timestamps in IBMQ backend properties, jobs, and job results are all now in local time instead of UTC.
  warnings.warn('Timestamps in IBMQ backend properties, jobs, and job results '
histogramをプロットする
plot_histogram(result.get_counts(qc))

以下のエラーが出たので, pip install matplotlib

ImportError
~/.pyenv/versions/3.8.1/lib/python3.8/site-packages/qiskit/visualization/counts_visualization.py", line 104, in plot_histogram
    raise ImportError('Must have Matplotlib installed.')

エラーは消えたが描画できない。
python上で, 一から書いていけばplot_histogram(result.get_counts(qc)).show())で描画される。
保存するのが手っ取り早そうなので、とりあえず以下で対処。

plotの保存(Figとして格納されている)
fig = plot_histogram(result.get_counts(qc))
fig.savefig("example01.png")
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?