Derivation of $Z = \operatorname{Tr}e^{-\beta H + \mu N}$ I've never studied quantum statistical mechanics myself, but I've read that the partition function of a quantum system in the canonical ensemble is given by:
$$Z = \operatorname{Tr}e^{-\beta H}$$
where $H$ is the Hamiltonian of the system and $\beta$ the inverse temperature. I believe this formula is obtained as follows. If the system can be in any of state with energies $\{E_{n}\}$, the basic principle of statistical mechanics states that the partition function of the system is given by:
$$Z = \sum_{n}e^{-\beta E_{n}}$$
Thus, we can take $|n\rangle$ to be the eigenstate associated to the eigenvalue $E_{n}$, that is, $H|n\rangle = E_{n}|n\rangle$ so that:
$$\sum_{n}e^{-\beta E_{n}} = \sum_{n}\langle n | e^{-\beta H}|n\rangle = \operatorname{Tr}e^{-\beta H}$$
where I assumed the eigenstates $|n\rangle$ are normalized.
Question 1: Is this derivation correct?
Question 2: Can this reasoning be applied to deduce the partition function $\Xi$ in the grand-canonical ensemble too? In this case, the correct formula is:
$$\Xi = \operatorname{Tr}e^{-\beta H + \mu N}$$
where $N$ is the number operator. But I'm not sure how to do that. How can I adapt the previous reasoning to account for both eigenstates of $H$ and $N$?
 A: Q1: Correct.
Q2: If your problem conserves particle number, $\partial_t \langle \psi \vert N \vert \psi \rangle$=0, the particle number operator commutes with the Hamiltonian $[H,N]=0$ which implies that they have a common eigenbasis and one can still do the same method with the states $\vert n \rangle$. It becomes a bit more complicated if $H$ does not conserve the particle number, like in the BCS Hamiltonian. For example, you could then try to choose an eigenbasis of the operator $O=-\beta H + \mu N$, say $\lbrace \vert \alpha \rangle \rbrace$, and connect the quantum grand-canonical ensemble to the classical one as $$ \text{Tr } e^{-\beta H + \mu N} = \sum_\alpha \langle \alpha \vert e^{O} \vert \alpha \rangle = \sum_\alpha e^{\langle \alpha \vert O \vert \alpha \rangle} = \sum_\alpha e^{O_\alpha}.$$
The eigenvalues cannot be split into a $E$ part and a $N$ part uniquely and the direct connection to the classical version in this way is not possible. However, this is not necessary because one can also go to the macrocanonical ensemble from the canonical ensemble after the quantization, just by the condition that there should be some parameter that fixes the (average) particle number as $$\langle N \rangle = \frac{\partial}{\partial \mu} \log \Xi.$$ Just take this as a definition of $\mu$ and you find the grandcanonical potential from the canonical one. Note that a broken conservation law for a single pure state $\vert \psi \rangle$ does not mean that the total particle number in the macrocanonical ensemble has to depend on time. In fact, the particle number is then conserved on average, as opposed to exactly for each individual state.
