I want to find a matrix $S$ with a fixed diagonal $d$ whose inverse matches $P$ on all of its off-diagonal elements.
You can assume $S$ and $P$ are positive definite, and $d>0$ (all elements of $d$ are positive).
Where this problem arises is in the following optimization:
$$\max_{S ~ s.t. ~ diag(S)=d} ~ -S \circ P + \ln | S |$$
where $\circ$ is a matrix dot product operator (multiply corresponding elements and add it all up). If it weren't for the condition that $diag(S)=d$, the solution to the maximization would be $S=P^{-1}$. However, because of the condition, we need $S^{-1}$ to match $P$ on all the off diagonal elements, while still keeping its diagonal equal to $d$.
The only solution I can think of is to just do the optimization numerically (via gradient descent or Convex Optimization / Semidefinite Programming), which is too costly computationally.