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

Qiskitで DeprecationWarning に遭遇した話

Posted at

DeprecationWarning

小ネタです。
qiskitで以下のような回路をコーディング中に、警告文が出てきました。
(少しぼかしてますが)

    angle_y = np.arcsin(x_in)
    for i in range(nqubit):
      angle_y_index = angle_y[i]
      circuit_in.ry(angle_y_index,i)

/usr/local/lib/python3.6/dist-packages/qiskit/circuit/instruction.py:84: DeprecationWarning: Gate param type <class 'numpy.ndarray'> is being deprecated as of 0.16.0, and will be removed no earlier than 3 months after that release date. Considering creating your own Gate subclass with the method validate_parameter to allow this param type.

何が問題だったか

どうやら、qiskitのryゲートでは回転角度にnp.array型を禁止することを予定しているようです。
回転角度はスカラーですから、確かにnp.arrayのような配列を使う必要はありませんね。
解決方法としては、 np.float でスカラーにキャストしてやればいいみたいです。

    angle_y = np.arcsin(x_in)
    for i in range(nqubit):
      angle_y_index = np.float(angle_y[i]) #cast
      circuit_in.ry(angle_y_index,i)

結論

Warningはちゃんと気にしておこう。。

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