-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
イジング変数への変換関数を追加 #43
Comments
こんな感じでしょうか? from __future__ import annotations
from tytan import (
symbols,
symbols_list,
symbols_define,
symbols_nbit,
Compile,
sampler,
Auto_array
)
import numpy as np
def get_ising(q):
"""量子ビットをイジング変数に変換する
Args:
q (sympy.core.symbol.Symbol | np.ndarray): 量子ビットまたはそのリスト
Returns:
sympy.core.add.Add | np.ndarray: 対応するイジング変数
Raises:
ValueError: サポートしていない型の変数が `q` として与えられた。
"""
import sympy as sp
if isinstance(q, sp.core.symbol.Symbol) or isinstance(q, np.ndarray):
return 2*q - 1
else:
raise ValueError(f"{type(q)} is not supported.")
# 使用例
q = symbols_list(6)
q6 = symbols("q6")
ising_list = get_ising(q)
ising_var = get_ising(q6) |
@derwing さん、 |
@y-vectorfield |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
チュートリアル3でイジング変数への変換が取り上げられていますが、複数の量子ビットを変換したい場合に1つずつ変換式を記載するのは煩雑な上に実装ミスを誘発するのではと思いました。よってget_ising(q)で量子ビット、量子ビット行列(symbols_list()で得た行列)をイジング変数または行列に変換出来る様にすると良いのではと思いました。
The text was updated successfully, but these errors were encountered: