Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoyaYasuda committed Jun 16, 2023
1 parent 342a9ed commit 14c5ef6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions tytan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .symbol import symbols, symbols_list, symbols_define
from .symbol import symbols, symbols_list, symbols_define, symbols_nbit
from .compile import Compile
from . import sampler
from .auto_array import Auto_array

# from tytan import * 用
__all__ = ['symbols', 'symbols_list', 'symbols_define', 'Compile', 'sampler', 'Auto_array']
__all__ = ['symbols', 'symbols_list', 'symbols_define', 'symbols_nbit', 'Compile', 'sampler', 'Auto_array']
2 changes: 1 addition & 1 deletion tytan/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.8"
__version__ = "0.0.9"
25 changes: 15 additions & 10 deletions tytan/auto_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import itertools
import numpy as np
import pandas as pd
from sympy import Symbol as sympy_Symbol

"""
量子ビットの添字を検出して結果を多次元配列に変換して返す
Expand Down Expand Up @@ -166,17 +167,21 @@ def get_image(self, format_txt):


return image, subs

#nbitを解析して値を得る
def get_nbit_value(self, expr):

#nbit式中のシンボル抽出
symbols = list(expr.atoms(sympy_Symbol))
#print(symbols)

#nbit式中のシンボルに結果を戻す
tmp = [(symbols[i], self.a[f'{symbols[i]}']) for i in range(len(symbols))]
ans = expr.subs(tmp)











#余計な少数0をなくして返す
return float(ans)




11 changes: 11 additions & 0 deletions tytan/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,15 @@ def symbols_define(shape, format_txt=None):
# print(f'defined global : {first_command} to {final_command}')


def symbols_nbit(start, stop, format_txt, num=8):
#生成
q = symbols_list(num, format_txt=format_txt)

#式
ret = 0
for n in range(num):
#係数を規格化してから量子ビットをかけたい
ret += (start + (stop - start)) * 2**(num - n - 1) / 2**num * q[n]

return ret

0 comments on commit 14c5ef6

Please sign in to comment.