Skip to content

Commit

Permalink
Fix multi-dimensional ArrayVar declaration (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmshaffer authored Jun 5, 2024
1 parent 90c2bbd commit 62ab4c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/autoqasm/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from collections.abc import Iterable
from typing import Any, List, Union, get_args

import numpy as np
import oqpy
import oqpy.base
from braket.circuits import FreeParameterExpression
Expand Down Expand Up @@ -114,7 +115,7 @@ def __init__(
if not isinstance(init_expression, Iterable):
raise errors.InvalidArrayDeclaration("init_expression must be an iterable type.")

dimensions = [len(init_expression)]
dimensions = np.shape(init_expression)
super(ArrayVar, self).__init__(
init_expression=init_expression,
*args,
Expand Down
6 changes: 3 additions & 3 deletions test/unit_tests/autoqasm/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,9 @@ def declare_array():
def test_array_supports_multidimensional_arrays():
@aq.main
def declare_array():
aq.ArrayVar([[1, 2], [3, 4]])
a = aq.ArrayVar([[1, 2, 3], [4, 5, 6]]) # noqa: F841

expected = """OPENQASM 3.0;
array[int[32], 2, 2] a = {{1, 2}, {3, 4}};"""
array[int[32], 2, 3] a = {{1, 2, 3}, {4, 5, 6}};"""

declare_array.build().to_ir() == expected
assert declare_array.build().to_ir() == expected

0 comments on commit 62ab4c5

Please sign in to comment.