  An open fully connected system of qubits at nonzero temperature is driven
within a finite time interval along various paths in the space of its control
parameters. The driving leads across finite-size precursors of the first- and
second-order quantum phase transition from factorized to entangled ground-state
phases, aiming at the preparation of the complex ground state of the system at
the final parameter point with maximal fidelity. During the drive, the system
is coupled to a heat bath with a constant temperature, the dynamics being
determined in a nonpertubative way by the method of Hierarchical Equations of
Motion. It is shown that the presence of the heat bath in combination with
specific patterns of avoided crossings affecting the ground and excited states
in the parameter region around the quantum phase transition may considerably
improve the fidelity of preparation of the target ground state.
