Text this: Robust quantum compilation and circuit optimisation via energy minimisation