Tomographer
v5.4
Tomographer C++ Framework Documentation
|
The tomorun
executable has several figures of merit built into the program: the trace distance, the purified distance, or the fidelity to any reference state, as well as the expectation value of an observable. If you wish to produce a histogram of a different figure of merit which can't be cast into one of these, you have the following options.
I. Use the Python module, which allows you to specify any custom figure of merit given as a Python callable;
II. Write a small, special-purpose C++ program which does exactly what you need, in which you can code your custom figure of merit;
III. Modify the source of the tomorun
program itself, to add your new figure of merit.
Option I is the simplest, and should be your default choice; options II and III require a bit more work.
Option II may be easier if you have a very special purpose which might not warrant inclusion into the generic tomorun
program. You can simply combine the required tools into a new special-purpose program. This is not difficult, and there are already examples ready—see Creating a custom tomorun-like program.
In the following we describe the necessary steps for Option III.
We'll illustrate these steps with a simple example: the two-norm distance (aka. the Hilbert-Schmidt distance) to any reference state, defined by \( d_\mathrm{HS}(\rho,\rho_{\mathrm{Ref}}) = \Vert \rho-\rho_{\mathrm{Ref}}\Vert_2 \), with \( \Vert A\Vert_2 = \mathrm{tr}\left(A^\dagger A\right) \).
First, you should write the code which calculates the figure of merit, complying to a ValueCalculator Interface type interface. Your new class should in particular have a method getValue(const MatrixType & T)
taking as argument an Eigen matrix type which will be a matrix square root (see T Parameterization) of the quantum state rho for which the function should calculate the figure of merit.
You should do this in a new header file, that's the easiest.
For our example, we can get inspired by the code for, e.g., Tomographer::DenseDM::TSpace::TrDistToRefCalculator defined in tspacefigofmerit.h. For example, let's create a file called "hs_dist.h"
inside the "tomorun/"
directory of the tomographer project:
The part about needownoperatornew.h and Tomographer::Tools::NeedOwnOperatorNew is to make sure that the object, when created, is aligned in memory. This is needed because the object has a Eigen member (rho_ref) which must be aligned in memory for vectorized operations (see Eigen's docs for alignment issues, there's a lot on that). In the Tomographer project, the Tomographer::Tools::NeedOwnOperatorNew virtual base makes sure that the necessary operator new()
is defined so that objects are aligned in memory when allocated.
tomorun
programIn order to integrate a new figure of merit into the tomorun
program, one simply has to declare it in the "tomorun/tomorun_figofmerit.h"
header file.
All you have to do is (1) Write a class which describes how to create the value calculator for this figure of merit, what help text to display, and the option name; and (2) add this class to the list of known figures of merit (at the bottom of the file).
For (1), in our example, we might define the class HsDistFigureOfMerit as follows. (Also, we need to add #include "hs_dist.h"
at the top of the file.)
Finally, for (2), you have to insert your class name (here HsDistFigureOfMerit) into the TomorunFiguresOfMerit tuple at the bottom of the file, in order to make the program aware of this new figure of merit.
Recompile tomorun (and fix any build issues etc.). You may now use your custom figure of merit with the option "--value-type=HS-dist"
or "--value-type=HS-dist:varname"
. Notice that it also appears in the help text when you run "tomorun --help"