  We provide a general method to calculate and maximize the purity of a qubit
interacting with an anisotropic non-Markovian environment. Counter to
intuition, we find that the purity is often maximized by preparing and storing
the qubit in a superposition of non-interacting eigenstates. For a model
relevant to decoherence of a heavy-hole spin qubit in a quantum dot or for a
singlet-triplet qubit for two electrons in a double quantum dot, we show that
preparation of the qubit in its non-interacting ground state can actually be
the worst choice to maximize purity. We further give analytical results for
spin-echo envelope modulations of arbitrary spin components of a hole spin in a
quantum dot, going beyond a standard secular approximation. We account for
general dynamics in the presence of a pure-dephasing process and identify a
crossover timescale at which it is again advantageous to initialize the qubit
in the non-interacting ground state. Finally, we consider a general two-axis
dynamical decoupling sequence and determine initial conditions that maximize
purity, minimizing leakage to the environment.
