  We calculate the first two moments and full probability distribution of the
work performed on a system of bosonic particles in a two-mode Bose-Hubbard
Hamiltonian when the self-interaction term is varied instantaneously or with a
finite-time ramp. In the instantaneous case, we show how the irreversible work
scales differently depending on whether the system is driven to the Josephson
or Fock regime of the bosonic Josephson junction. In the finite-time case, we
use optimal control techniques to substantially decrease the irreversible work
to negligible values. Our analysis can be implemented in present-day
experiments with ultracold atoms and we show how to relate the work statistics
to that of the population imbalance of the two modes.
