We consider a quantum system with a time-independent Hamiltonian parametrized by a set of unknown parameters $\alpha$. The system is prepared in a general quantum state by an evolution operator that depends on a set of unknown parameters $P$. After the preparation, the system evolves in time, and it is characterized by a time-dependent observable ${\cal O}(t)$. We show that it is possible to obtain closed-form expressions for the gradients of the distance between ${\cal O}(t)$ and a calculated observable with respect to $\alpha$, $P$ and all elements of the system density matrix, whether for pure or mixed states. These gradients can be used in projected gradient descent to infer $\alpha$, $P$ and the relevant density matrix from dynamical observables. We combine this approach with random phase wave function approximation to obtain closed-form expressions for gradients that can be used to infer population distributions from averaged time-dependent observables in problems with a large number of quantum states participating in dynamics. The approach is illustrated by determining the temperature of molecular gas (initially, in thermal equilibrium at room temperature) from the laser-induced time-dependent molecular alignment.