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
177 stars 44 forks source link

Controlled Hamiltonian simulation not explicitly implemented #1413

Open ejbobrow opened 1 month ago

ejbobrow commented 1 month ago

This is more of a feature request, but it looks like HamiltonianSimulationByGQSP doesn't have its own explicit control and uses the defaults for .controlled(). This gives errors like DecomposeTypeError: Could not build call graph for C[Toffoli]: Toffoli is atomic when trying to do resource counting with .t_complexity() or get_cost_value().

Maybe this could be extended by allowing for additional control in QubitizationWalkOperator with ControlledViaAnd and controlling the rotations in GeneralizedQSP.

anurudhp commented 1 month ago

Hi, thanks for reporting this! Could you share the bloq example you used?

ejbobrow commented 1 month ago

For example, the Hubbard bloq example hamiltonian_simulation_by_gqsp._hubbard_time_evolution_by_gqsp().controlled().t_complexity() gives call graph errors like DecomposeTypeError: Could not build call graph for C[C[Ry(2.214297435588181)]]: Could not build call graph for C[Ry(2.214297435588181)]: Ry(2.214297435588181) is atomic.

anurudhp commented 1 month ago

Thanks. This issue is actually because of #878, so adding controlled versions of rotation gates and toffoli etc. will solve this issue.

I think there shouldn't be a need to provide a custom controlled versions for HamiltonianSimulationByGQSP or GQSP.