Skip to content

Commit

Permalink
fix _interpret_as_qtype for inner tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Nov 27, 2023
1 parent cb57c3e commit a777336
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion qlasskit/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ def interpret_as_qtype(
out: Union[str, int, List[bool]], qtype, out_len: Optional[int] = None
) -> Any:
out = list(reversed(format_outcome(out, out_len)))

def _getsize(x):
if hasattr(x, "BIT_SIZE"):
return x.BIT_SIZE
elif len(get_args(x)) > 0:
size = 0
for x in get_args(x):
size += _getsize(x)
return size
else:
return 1


def _interpret(out, qtype, out_len):
if hasattr(qtype, "from_bool"):
Expand All @@ -113,7 +125,7 @@ def _interpret(out, qtype, out_len):
idx_s = 0
values = []
for x in get_args(qtype):
len_a = x.BIT_SIZE if hasattr(x, "BIT_SIZE") else 1
len_a = _getsize(x)
values.append(_interpret(out[idx_s : idx_s + len_a], x, len_a))
idx_s += len_a

Expand Down

0 comments on commit a777336

Please sign in to comment.