Assertion on List of Tuple of Tuple access
Closed this issue · 1 comments
dakk commented
@qlassf
def oracle(io_list: Parameter[List[Tuple[Tuple[bool, bool], bool]]], f: bool) -> bool:
v = True
for io in io_list:
v = v and (io[0][0] and io[0][1]) == io[1]
return v
ttable = [(False, False), (True, False), (False, True), (True, True)]
tt = list(map(lambda e: (e, e[0] or e[1]), ttable))
oracle.bind(io_list=ttable)
Raises:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[74], [line 1](vscode-notebook-cell:?execution_count=74&line=1)
----> [1](vscode-notebook-cell:?execution_count=74&line=1) q_algo = Grover(oracle.bind(io_list=ttable))
File [~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:110](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:110), in UnboundQlassf.bind(self, **kwargs)
[106](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:106) raise Exception("original_f is not available in python notebooks!")
[108](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:108) original_f = orig
--> [110](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:110) return self._do_translate(fun_ast, original_f)
File [~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:295](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:295), in QlassF.from_function.<locals>._do_translate(fun_ast, original_f)
[293](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:293) def _do_translate(fun_ast, original_f):
[294](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:294) fun = ast2ast(fun_ast.body[0])
--> [295](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:295) fun_name, args, fun_ret, exps = translate_ast(fun, types, defs)
[297](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:297) exps = bool_optimizer.apply(exps)
[299](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/qlassfun.py:299) # Return the qlassf object
File [~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_ast.py:49](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_ast.py:49), in translate_ast(fun, types, defs)
[47](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_ast.py:47) exps = []
[48](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_ast.py:48) for stmt in fun.body:
---> [49](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_ast.py:49) s_exps, env = translate_statement(stmt, env, ret_.ttype)
[50](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_ast.py:50) exps.append(s_exps)
[52](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_ast.py:52) exps_flat = flatten(exps)
File [~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_statement.py:58](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_statement.py:58), in translate_statement(stmt, env, ret_type)
...
---> [73](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_expression.py:73) if sn.split(".")[0] not in env:
[74](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_expression.py:74) raise exceptions.UnboundException(sn, env)
[76](https://file+.vscode-resource.vscode-cdn.net/home/dakk/~/.pyenv/versions/3.10.13/envs/qlasskit_310-env/lib/python3.10/site-packages/qlasskit-0.1.20-py3.10.egg/qlasskit/ast2logic/t_expression.py:76) # Get the inner type
AttributeError: 'NoneType' object has no attribute 'split'
dakk commented
I fixed for List of Tuple; List of Tuple of Tuple is not necessary right now (wontfix for now).
def test_list_of_tuple_of_tuple2(self):
f = (
"def oracle(io_list: Parameter[List[Tuple[bool, bool, bool]]], f: bool) -> bool:\n"
"\tv = True\n"
"\tfor io in io_list:\n"
"\t\tv = v and (io[0] or io[1]) == io[2]\n"
"\treturn v"
)
qf = qlassf(f, to_compile=COMPILATION_ENABLED, compiler=self.compiler)
ttable = [(False, False), (True, False), (False, True), (True, True)]
tt = list(map(lambda e: (e[0], e[1], e[0] or e[1]), ttable))
qfb = qf.bind(io_list=tt)