Skip to content

Add custom operation conversion hook to cirq_optree_to_cbloq#1834

Merged
mpharrigan merged 3 commits intoquantumlib:mainfrom
wjhuggins:flasq-op-conversion-hook
Apr 2, 2026
Merged

Add custom operation conversion hook to cirq_optree_to_cbloq#1834
mpharrigan merged 3 commits intoquantumlib:mainfrom
wjhuggins:flasq-op-conversion-hook

Conversation

@wjhuggins
Copy link
Copy Markdown
Collaborator

Adds a backward-compatible hook that lets callers provide a custom Operation -> Bloq conversion function. This is needed by the FLASQ library to perform custom analysis as we convert cirq optrees to bloqs. For example, calculating the Manhattan distance between the two qubits involved in a two-qubit gate.

The new parameter defaults to None, so all existing callers are unaffected. When provided, it replaces the default extraction logic for each operation in the circuit.

All existing cirq_interop tests pass unchanged and a new test was added for this new functionality.

Adds a backward-compatible hook that lets callers provide a custom
Operation -> Bloq conversion function. This is needed by the FLASQ
library (qualtran-flasq) to wrap multi-qubit operations with
BloqWithSpanInfo for span-based cost analysis, without relying on
the private _extract_bloq_from_op function.

The new parameter defaults to None, so all existing callers are
unaffected. When provided, it replaces the default extraction logic
for each operation in the circuit.

All existing cirq_interop tests pass unchanged.
@wjhuggins wjhuggins requested a review from mpharrigan April 1, 2026 20:22
@wjhuggins wjhuggins marked this pull request as ready for review April 1, 2026 20:37
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 an optional op_conversion_method parameter to the cirq_optree_to_cbloq function, allowing for custom conversion of Cirq operations into Bloqs. Additionally, it updates the function's docstrings, fixes a string formatting error, and adds a test case to verify the new parameter's functionality. I have no feedback to provide.

@mpharrigan mpharrigan enabled auto-merge (squash) April 2, 2026 22:08
@mpharrigan mpharrigan merged commit b35999e into quantumlib:main Apr 2, 2026
9 checks passed
@wjhuggins wjhuggins deleted the flasq-op-conversion-hook branch April 9, 2026 21:25
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.

2 participants