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

Make BloqBuilder.join accept array-like of soquets #1509

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions qualtran/_infra/composite_bloq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,12 +1234,13 @@ def split(self, soq: Soquet) -> NDArray[Soquet]: # type: ignore[type-var]

return self.add(Split(dtype=soq.reg.dtype), reg=soq)

def join(self, soqs: NDArray[Soquet], dtype: Optional[QDType] = None) -> Soquet: # type: ignore[type-var]
def join(self, soqs: SoquetInT, dtype: Optional[QDType] = None) -> Soquet:
from qualtran.bloqs.bookkeeping import Join

try:
soqs = np.asarray(soqs)
(n,) = soqs.shape
except AttributeError:
except (AttributeError, ValueError):
raise ValueError("`join` expects a 1-d array of input soquets to join.") from None

if not all(soq.reg.bitsize == 1 for soq in soqs):
Expand Down
6 changes: 6 additions & 0 deletions qualtran/_infra/composite_bloq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ def test_util_convenience_methods():
assert len(cbloq.connections) == 1 + 10 + 1


def test_join_list():
bb = BloqBuilder()
qs = [bb.allocate() for _ in range(10)]
_ = bb.join(qs)


def test_util_convenience_methods_errors():
bb = BloqBuilder()

Expand Down
Loading