This MR is essentially cherry-picking !768 (merged) and is needed for Phys!354 (merged).
Ping @sakar @mschille