Add custom operation conversion hook to cirq_optree_to_cbloq#1834
Merged
mpharrigan merged 3 commits intoquantumlib:mainfrom Apr 2, 2026
Merged
Add custom operation conversion hook to cirq_optree_to_cbloq#1834mpharrigan merged 3 commits intoquantumlib:mainfrom
mpharrigan merged 3 commits intoquantumlib:mainfrom
Conversation
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.
mpharrigan
approved these changes
Apr 1, 2026
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.