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?

[2025/09版] Qiskitを使っていたら「NameError: name 'Aer' is not defined」と出た

Posted at

はじめに

こんにちは、ユーゴです。今回は、思いつきで始めた量子コンピュータのフレームワークであるQiskitを使っていた時に起きたエラーと、その対処法を紹介します。

問題

以下のようにqiskitのAerを使用した時、エラーが出る。

from qiskit import QuantumCircuit, Aer

原因&解決

qiskit.Aerは廃止された。
代わりに、qiskit_aer.AerSimulatorを使用する。

以下のような感じで使えます。

from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator

qc = QuantumCircuit(1,1)
qc.x(0)
qc.measure(0,0)

simulator = AerSimulator()
result = simulator.run(qc).result()
print(result.get_counts(0))

公式リファレンスは中々見つからないので、リポジトリの方で使い方を確認するのが早いです。
https://github.com/Qiskit/qiskit-aer

余談

本記事は、下書きから発掘した少し古いネタでした。下書き整理のために、今回公開した次第です。
qiskitは頻繁に仕様が変わるので、ChatGPTだとかなり古い情報が出てきます。公式リファレンスも追うようにしましょう!

それにしても、やはりQiskitの最新版に対応する記事は少ないですね...

まとめ

いかがだったでしょうか。今回は、qiskitで起きたAerがない問題について、qiskit-aerのAerSimulatorを紹介しました。

このように、量子コンピューティングに関するネタから、Unity, AWS, Splunkなど、幅広いネタを取り扱っていきます!
ぜひお役に立てましたら、いいね・フォロー等よろしくお願いします!

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?