Background
So let's presume I have $N$ density matrices and their corresponding Hamiltonian of each. Let the temperature of each $i$'th density matrix $\rho_i$ be $T_i$ of Hamiltonian $H_i$. Note, all the $i$ Hamiltonians are indistinguishable (where $I$ is a dummy index). We define
$$\beta_i = \frac{1}{k_b T_i}$$
Let's say these density matrices are put in physical contact and reach thermal equilibrium:
$$ \frac{N}{\beta_f} = \sum_{i}^N \frac{1}{\beta_i}$$
where the $f$ subscript represents the quantity after thermal equilibrium.
Now the below will be the partition of this ensemble of density matrices:
$$ Z_f = \text{Tr } e^{- \beta_f \rho_f H_f}$$
Even though this is attaining thermal equilibrium is irreversible process it can be approximated by infinitely many reversible ones given by unitary evolution under which the partition function is invariant.
Therefore:
$$ \text{Tr } e^{-\sum_{k}^N \beta_k \rho_k H_k} = \text{Tr } e^{- \beta_f \rho_f H_f}$$
where,
$$ H_f = H_1 \oplus H_2 \oplus \dots H_N $$
and
$$\sum_{k}^N \beta_k \rho_k H_k = \beta_1 \rho_1 H_1 \oplus \beta_2 \rho_2 H_2 \oplus \dots \beta_N \rho_N H_N$$
Taylor expanding:
$$ \text{Tr } ( I_i - \sum_{k}^N \beta_k \rho_k H_k +\frac{( \sum_{k}^N \beta_k \rho_k H_k)^2}{2!} + \dots) $$ $$= \text{Tr } I_f - \beta_f \rho_f H_f - \frac{(\beta_f \rho_f H_f)^2}{2!} + \dots $$
Note: the mismatch of the first term is the identity of different Hilbert spaces.
Now, taking derivatives:
$$ \text{Tr } \frac{\partial }{\partial \beta_j} \Big ( I - \sum_{k}^N \beta_k \rho_k H_k +\frac{( \sum_{k}^N \beta_k \rho_k H_k)^2}{2!} + \dots \Big )_{G.M,N} $$ $$= \text{Tr } \frac{\partial }{\partial \beta_j} \Big (I_f - \beta_f \rho_f H_f + \dots \Big )_{G.M,N} $$
Using this one can determine $\rho_f$
Question
How does one completely solve for all $\beta_i$? In the sense given intial conditions I can go to final conditions. So how does one go from final to initial? What is the matrix whose inverse is required?
Also does the above calculation mean once someone starts with a mixed state density matrix the $2$'nd law of thermodynamics forbids getting rid of the "classical probabilities"?