Qualtran
Qualtran copied to clipboard
Controlled Hamiltonian simulation not explicitly implemented
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.
Hi, thanks for reporting this! Could you share the bloq example you used?
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.
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.
Controlled toffoli was added in #1552 . Is this issue resolved now?
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 yep you're right, we need a manual override for controlled HamiltonianSimulationByGQSP. This will be fixed by #1605