Skip to content

Bloqify syntax basics#1839

Merged
mpharrigan merged 2 commits intoquantumlib:mainfrom
mpharrigan:2024-06/bloqify
Apr 13, 2026
Merged

Bloqify syntax basics#1839
mpharrigan merged 2 commits intoquantumlib:mainfrom
mpharrigan:2024-06/bloqify

Conversation

@mpharrigan
Copy link
Copy Markdown
Collaborator

"tracing style" bloq construction. This is the basics. More syntactic sugar, docs, and examples to follow.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the @bloqify decorator, which provides a function-based syntax for constructing CompositeBloq objects. To support this, BloqBuilder and CompositeBloq have been updated to include a bloq_key for better tracking and debugging. Additionally, the finalize method now supports a 'loose' mode that automatically converts missing THRU registers to LEFT registers. Review feedback highlights a potential performance issue where bloqified functions are re-traced on every call and suggests preserving exception context when re-raising BloqError to aid debugging.

Comment on lines +172 to +173
f = self._prep_qstackframe(self._bound_kvs(*args, **kwargs))
return bb.add(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation of __call__ triggers a full trace of the bloqified function every time it is called as a sub-bloq. This can lead to significant performance overhead, especially when bloqified functions are used within loops or nested deep in a hierarchy. Consider caching the resulting CompositeBloq based on the classical arguments provided to the function to avoid redundant tracing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fundamental trade-off of using the tracing approach. We can't cache based on arguments, as the behavior is liable to change based on things like the data type "hidden" in the QVar objects (unlike the traditional qlt.Bloq which demands the developer list the classical parameters)

Comment thread qualtran/_infra/composite_bloq.py Outdated
@mpharrigan mpharrigan merged commit bd97492 into quantumlib:main Apr 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant