  Quantum error correcting codes (QECCs) are the means of choice whenever
quantum systems suffer errors, e.g., due to imperfect devices, environments, or
faulty channels. By now, a plethora of families of codes is known, but there is
no universal approach to finding new or optimal codes for a certain task and
subject to specific experimental constraints. In particular, once found, a QECC
is typically used in very diverse contexts, while its resilience against errors
is captured in a single figure of merit, the distance of the code. This does
not necessarily give rise to the most efficient protection possible given a
certain known error or a particular application for which the code is employed.
In this paper, we investigate the loss channel, which plays a key role in
quantum communication, and in particular in quantum key distribution over long
distances. We develop a numerical set of tools that allows to optimize an
encoding specifically for recovering lost particles both deterministically and
probabilistically, where some knowledge about what was lost is available, and
demonstrate its capabilities. This allows us to arrive at new codes ideal for
the distribution of entangled states in this particular setting, and also to
investigate if encoding in qudits or allowing for non-deterministic correction
proves advantageous compared to known QECCs. While we here focus on the case of
losses, our methodology is applicable whenever the errors in a system can be
characterized by a known linear map.
