  As a milestone for general-purpose computing machines, we demonstrate that
quantum processors can be programmed to efficiently simulate dynamics that are
not native to the hardware. Moreover, on noisy devices without error
correction, we show that simulation results are significantly improved when the
quantum program is compiled using modular gates instead of a restricted set of
standard gates. We demonstrate the general methodology by solving a cubic
interaction problem, which appears in nonlinear optics, gauge theories, as well
as plasma and fluid dynamics. To encode the nonnative Hamiltonian evolution, we
decompose the Hilbert space into a direct sum of invariant subspaces in which
the nonlinear problem is mapped to a finite-dimensional Hamiltonian simulation
problem. In a three-states example, the resultant unitary evolution is realized
by a product of ~20 standard gates, using which ~10 simulation steps can be
carried out on state-of-the-art quantum hardware before results are corrupted
by decoherence. In comparison, the simulation depth is improved by more than an
order of magnitude when the unitary evolution is realized as a single cubic
gate, which is compiled directly using optimal control. Alternatively,
parametric gates may also be compiled by interpolating control pulses. Modular
gates thus obtained provide high-fidelity building blocks for quantum
Hamiltonian simulations.
