Skip to content
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

Open
y-vectorfield opened this issue Nov 25, 2023 · 3 comments
Open

イジング変数への変換関数を追加 #43

y-vectorfield opened this issue Nov 25, 2023 · 3 comments

Comments

@y-vectorfield
Copy link

チュートリアル3でイジング変数への変換が取り上げられていますが、複数の量子ビットを変換したい場合に1つずつ変換式を記載するのは煩雑な上に実装ミスを誘発するのではと思いました。よってget_ising(q)で量子ビット、量子ビット行列(symbols_list()で得た行列)をイジング変数または行列に変換出来る様にすると良いのではと思いました。

@derwind
Copy link
Contributor

derwind commented Nov 30, 2023

こんな感じでしょうか?

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)

@y-vectorfield
Copy link
Author

y-vectorfield commented Nov 30, 2023

@derwing さん、
イメージ通りの関数です。ありがとう御座います。
このアイディアを(テストも含めて)実装してPRを出してもよろしいでしょうか?

@derwind
Copy link
Contributor

derwind commented Dec 1, 2023

@y-vectorfield
ざっと書いただけなので、好きなように改造してもらって良いと思いますよ。今回は list[sympy.core.symbol.Symbol] は弾く実装にしましたが、人によっては [symbols(f"q{i}") for i in range(6)] とリストを使いたいかもしれないし、その辺使いやすいようにしていただければと思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants