Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

Controlled Hamiltonian simulation not explicitly implemented

Open ejbobrow opened this issue 1 year ago • 3 comments

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.

ejbobrow avatar Sep 19 '24 20:09 ejbobrow

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

anurudhp avatar Sep 19 '24 20:09 anurudhp

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.

ejbobrow avatar Sep 19 '24 20:09 ejbobrow

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.

anurudhp avatar Sep 19 '24 21:09 anurudhp

Controlled toffoli was added in #1552 . Is this issue resolved now?

mpharrigan avatar Mar 26 '25 18:03 mpharrigan

It looks like adding controlled Toffoli now lets .t_complexity() work when controlling just the GQSP part of the Hamiltonian simulation, as in hamiltonian_simulation_by_gqsp._hubbard_time_evolution_by_gqsp().gqsp.controlled().t_complexity().

However, controlling the entire Hamiltonian simulation still doesn't work, probably because controlled AND isn't implemented: hamiltonian_simulation_by_gqsp._hubbard_time_evolution_by_gqsp().controlled().t_complexity() gives DecomposeTypeError: Could not build call graph for C[And]: And is atomic.

It seems like this is coming from default control for the Hamiltonian Simulation bloq also adding controls to the prepare/prepare† flanking the GQSP, which I think isn't technically necessary since the prepare/prepare† will cancel if a controlled GQSP in the middle doesn't activate.

ejbobrow avatar Mar 26 '25 20:03 ejbobrow

@ejbobrow yep you're right, we need a manual override for controlled HamiltonianSimulationByGQSP. This will be fixed by #1605

anurudhp avatar Mar 26 '25 21:03 anurudhp