Skip to content

Conversation

@austingmhuang
Copy link
Contributor

@austingmhuang austingmhuang commented Jun 4, 2025

Context:
In this PR, we add smart default mappings to certain operators that have exact or highly similar equivalents in Qualtran. We don't add smart defaults when the mapping would not be very similar, instead opting to let users use a custom mapping instead due to the differences.

There are a few mappings that would make sense to have but are not supported. We outline them below and with some brief reasoning.

qml.TrotterProduct/TrotterizedQFunc: qt.TrotterizedUnitary can only trotterize Bloqs that meet certain technical requirements, of which ToBloq cannot achieve.
qml.StatePrep: Unclear which StatePrep to map to
qml.PrepSelPrep: Maps to qt.LCUBlockEncoding but unclear how to map the inner Select and Prep
qml.Qubitization: There doesn't exist a factory function that produces a generic enough qt.QubitizationWalkOperator

Description of the Change:
Added smart default mappings

Benefits:
Easy to use mappings

Possible Drawbacks:

Related GitHub Issues:

Copy link
Contributor

@obliviateandsurrender obliviateandsurrender left a comment

Choose a reason for hiding this comment

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

Approving conditional on minor comments.

Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
@austingmhuang austingmhuang force-pushed the pl_qualtran_prototype branch from a9fbc84 to f3969b3 Compare June 20, 2025 19:46
@austingmhuang austingmhuang requested a review from a team as a code owner June 20, 2025 19:46
@austingmhuang austingmhuang force-pushed the pl_qualtran_prototype branch 2 times, most recently from ec8ab75 to bbea644 Compare June 20, 2025 19:53
@austingmhuang austingmhuang merged commit 2ae2f5b into pl_qualtran_prototype Jun 20, 2025
5 of 6 checks passed
@austingmhuang austingmhuang deleted the pl_qualtran_mapper branch June 20, 2025 20:03
github-merge-queue bot pushed a commit that referenced this pull request Jun 20, 2025
…rcuits and operators to Qualtran bloqs (#7197)

**Context:**
We implement the adapter class `ToBloq` and a user-facing function
`to_bloq` that converts a PennyLane Operator or QNode to a Qualtran
bloq/cbloq.

In this PR, we specifically target the ability to convert PennyLane
decompositions to their Qualtran equivalent. When a PennyLane Operator
is wrapped with the ToBloq class or is wrapped with `qml.to_bloq(...,
map_ops=False)`, `decompose_bloq()` will return the PennyLane
decomposition. This enables us to use functions in Qualtran, such as
`draw_musical_score`, `call_graph()` and many more.

Important to note that calling `to_bloq()` on basic gates that have
**direct** equivalents (e.g. Hadamard, RX...) will **always** return the
Qualtran equivalent, even if `map_ops=False`. We do this because in
order for some Qualtran functionality to work properly, it needs to see
exactly `qt.Hadamard()` rather than `qml.ToBloq(qml.Hadamard())`; if for
some reason, someone really wants to use the wrapped bloq, they can
always call `qml.ToBloq()` on the operator directly to "force" the
wrapping.

We also implement the outlines for more bespoke functionality, namely
implementing `_get_op_call_graph()` for QPE and expanding
`_map_to_bloq()` to have a default and custom mapping options. We
further expand on these functionalities in the wrapper PR (#7536) and
the mapper PR (#7604).

**Description of the Change:**
Implementation of the `ToBloq` class, `to_bloq()` function, and
`_map_to_bloq()` function. Also includes stubs for
`_get_op_call_graph()`. There is also a number of tests for all the
functions, including those that verify that the "round-trip" works, and
that the decompositions are accurate.

**Benefits:**
PL ops and qnodes can be translated to Bloqs, which can then be used
as-is for deeper analysis in Qualtran.

**Related GitHub Issues:**
[[sc-87435](https://app.shortcut.com/xanaduai/story/87435)]
[sc-89901]

---------

Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
Co-authored-by: Soran Jahangiri <40344468+soranjh@users.noreply.github.com>
Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants