quantumlib / Qualtran

Qᴜᴀʟᴛʀᴀɴ is a Python library for expressing and analyzing Fault Tolerant Quantum algorithms.
https://qualtran.readthedocs.io/en/latest/
Apache License 2.0
134 stars 35 forks source link

Deprecate reflection bloq in favour of ReflectionUsingPrepare #1008

Closed fdmalone closed 1 month ago

fdmalone commented 1 month ago

Pulled from #998 and builds on #1002, removes the Reflection bloq (which was actually incorrect) in favour of ReflectionUsingPrepare. There's an open issue in that, some reflections in the chemistry bloqs are multiply controlled, but ReflectionUsingPrepare only allows a single control.

I added an intermediate identity prepare oracle as input for ReflectionUsingPrepare, which will also be needed for the $|G\rangle$ state (bloq) for block encodings.

fdmalone commented 1 month ago

Fixes #966

fdmalone commented 1 month ago

Related #978 (added ReflectionUsingPrepare auto doc.)

tanujkhattar commented 1 month ago

MultiControlPauli supports cvs so it shouldn't be very hard to add support for cvs to ReflectionUsingPrepare since we only need to control the MultiControlPauli and the prepare / prepare^{\dagger} simply passes through. Do you want to do this right as part of this PR itself?

fdmalone commented 1 month ago

@tanujkhattar Is there a simple way to allow for multiple controls on the reflection (just updating control_val -> control_vals?) I wasn't sure of the significance of the control register which looks to be used for phasing if specified rather than just adding performing the control.

fdmalone commented 1 month ago

Yeah I'll do it now.

tanujkhattar commented 1 month ago

Basically, we could always just allocate a new qubit for a "phase target" and do MultiControlPauli(controls=reflection_controls + selection_controls, target=phase_target). The optimization to save an allocation when the control qubit is specified is really just a convenience method.

fdmalone commented 1 month ago

SGTM

fdmalone commented 1 month ago

MultiControlPauli supports cvs so it shouldn't be very hard to add support for cvs to ReflectionUsingPrepare since we only need to control the MultiControlPauli and the prepare / prepare^{\dagger} simply passes through. Do you want to do this right as part of this PR itself?

ehhh, this is getting complicated because ReflectionUsingPrepare is a SpecializedSingleQubitControlledGate. I wasn't following this too closely, is it much work to adapt this or should we merge and follow up?

An alternative could be adding an And gate + an ancilla and feed this into the reflection to keep things singly-controlled. WDYT @tanujkhattar

tanujkhattar commented 1 month ago

I think it's fine doing it as a follow up. We can merge this address the multi control in a follow up